AV when accessing UserSession

delphi package - automated exception handling
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

..... update please
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

Still working on madCodeHook <sigh>. But should get to this soon.
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

This is now 6 weeks.....

Will it ever be fixed?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

It's been unlucky timing, me busy with urgent madCodeHook support requests.

Anyway, your issue is almost at the top of my list now, I might actually get to it tomorrow.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

Ok, the solution is pretty simple:

1) Copy madIWSupport.pas/dfm and mad.inc into your project folder, and remove the write protection flag.
2) Comment out the line "handled := AApplication <> nil".

Done. It seems that in earlier IW versions the last parameter to "TIWServerControllerBase.DoException" was "var handled: boolean". And now in the latest version instead it seems to be something like "httpRequest: THttpRequest".

If the IW guys want to offer an official exception callback, basically all I need is a way to hook/overwrite TIWServerControllerBase.DoException. You can send them madIWSupport.pas, that should make it pretty easy for them to see what they could to help me get rid of the nasty hack. Or just send them the whole test project you attached to this thread here, together with madIWSupport.pas/dfm + mad.inc. Then they can test it all with the madExcept non-commercial edition. They could then just send me an updated madIWSupport.pas/dfm file which would work with their new exception callback logic.
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

Sorry but this did not fix it.

I completed the tasks you advised. Did a rebuild. Did not fix it.

I deleted all madIWSupport.dcu on my system.

Renamed all madIWSupport.pas/dfm exceptthe one in my project dir.

Did a rebuild. Still did not fix it.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

Can you set a breakpoint in madIWSupport.pas. Does it reach the line before the commented out line?

(Not sure what to say, it definitely fixed it for me.)
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

I did try but it did not get to the break point.
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

Hmmmm... Do any breakpoints work at all in madIWSupport.pas? You may have to edit the options in mad.inc to make breakpoints work. It needs to be "{$D+}{$L+}".

FWIW, I've tested with Tokyo 10.2 and the latest IW version.
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

It was very early (my time) when I last responded.

I set "{$D+}{$L+}" to get breakpoints working...

At not time in my testing did I get an error at the line "// handled := AApplication <> nil;" when it is commented or not commented.

The problem occurs when accessing UserSession in the procedure AddCommandLineHeaderInfo. Evaluating UserSession returns "Access violation at 017086FF accessing 000000A4".

In the procedure AddCommandLineHeaderInfo UserSession is correctly exposed and I can accessed all variables and objects
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

Hmmmm... And this is with the test project you attached here? Or with your real project? To make sure we test the same thing: Which exact Delphi version are you using, and 32bit or 64bit compilation? And I assume you're using the latest IW version?
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

This is with a real project.
Delphi XE
Latest version of IW
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

Could you please double check with the test project you attached to this thread? That's the best way to ensure we're testing the same thing. Thanks.
ZSL
Posts: 54
Joined: Thu Mar 31, 2016 11:23 pm

Re: AV when accessing UserSession

Post by ZSL »

Same with the app I sent you.

In the TIWServerControllerBaseDoExceptionCallbackNew function execution gets to "HandleException(etNormal, AException, nil, true, Esp, Ebp, nil, esIntraweb, AApplication, 0, @bugReport);" then traces into "AddCommandLineHeaderInfo".

When it gets to the the line "exceptIntf.BugReportHeader['User #'] := UserSession.gv_UID;" of "AddCommandLineHeaderInfo".

Never get to process the line " exceptIntf.BugReportHeader['Site ID'] := UserSession.gv_SID;"

Does not output "User #" line to bugreport.txt

Also, after processing "HandleException(etNormal, AException, nil, true, Esp, Ebp, nil, esIntraweb, AApplication, 0, @bugReport);" the variable bugReport is always empty
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: AV when accessing UserSession

Post by madshi »

Interestingly, I wasn't able to reproduce this in Delphi Tokyo 10.2, but I *am* able to reproduce it in Delphi XE. I'm not sure where the difference is coming from.

When the crash occurs, in your ServerController.pas it seems "WebApplication" is nil. So "WebApplication.Data" crashes, of course. So please change the function "UserSession" to:

Code: Select all

function UserSession: TIWUserSession;
begin
  if WebApplication <> nil then
    Result := TIWUserSession(WebApplication.Data)
  else
    Result := nil;
end;
Of course then in UserSessionInit.pas you also need to change the code like this:

Code: Select all

procedure AddCommandLineHeaderInfo(const exceptIntf: IMEException; var handled: boolean);
begin
  exceptIntf.BugReportHeader['Product'] := 'Test';
  if UserSession <> nil then
  begin
    exceptIntf.BugReportHeader['User #'] := UserSession.gv_UID;
    exceptIntf.BugReportHeader['Site ID'] := UserSession.gv_SID;
  end;
end;
I've no idea why WebApplication is nil in this situation. But I'm not an IntraWeb expert, so maybe you know.
Post Reply