PDA

View Full Version : How to get stack trace for the last exception?


alexu
28-Mar-2006, 11:21 PM
I want to get a stack trace for some of the handled exception as well. I can see that the data is available somewhere inside, since ShowLastExceptionData() can show it, but how do I get it?

Having something like GetCurrentCallStack() would be enough if it gives the call stack for the last exception, not the current one.

Thank you

Alex

admin
30-Mar-2006, 03:07 PM
Hi,

alexu wrote:
> I want to get a stack trace for some of the handled exception as well. I
> can see that the data is available somewhere inside, since
> ShowLastExceptionData() can show it, but how do I get it?
>
> Having something like GetCurrentCallStack() would be enough if it gives
> the call stack for the last exception, not the current one.
>
> Thank you
>
> Alex

Try to use the following code:



try
// Your code here...
except
GetCurrentCallStack()
end;



--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

alexu
30-Mar-2006, 04:33 PM
That is exactly what I have implemented for now. But it does not work properly.
It does not get the "extra" information if exception happened inside several nested procedures. In the case below the exception will be raised inside AnotherProcedure(), but the call stack will not contain calls to the Execute() and AnotherProcedure() it will only show the "current" call stack (just like it should :)

try
Execute;
except
GetCurrentCallStack;
end;

procedure Execute
begin
AnotherProcedure;
end;

procedure AnotherProcedure;
begin
i = StringToInt( 'AAAA' );
end;

admin
31-Mar-2006, 04:05 PM
Hi,

alexu wrote:
> That is exactly what I have implemented for now. But it does not work
> properly.
> It does not get the "extra" information if exception happened inside
> several nested procedures. In the case below the exception will be
> raised inside AnotherProcedure(), but the call stack will not contain
> calls to the Execute() and AnotherProcedure() it will only show the
> "current" call stack (just like it should :)
>
> [...]

I'm sorry but this is its currently limit!

--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

JimHanson
03-Apr-2006, 10:06 PM
This is a serious limitation.

I used to have exactly this feature with Exception Magic. It worked great, and was crucial for letting me get a stack trace on demand.

Eurekalog really needs this. Because it lacks this, more than 70% of the real problems in the field cannot be traced.

Help us o Sir Eureka!

admin
04-Apr-2006, 10:20 AM
Hi,

JimHanson wrote:
> This is a serious limitation.
>
> I used to have exactly this feature with Exception Magic. It worked
> great, and was crucial for letting me get a stack trace on demand.
>
> Eurekalog really needs this. Because it lacks this, more than 70% of
> the real problems in the field cannot be traced.
>
> Help us o Sir Eureka!

I don't understand why it's so important.

EurekaLog shows automatically the full multi-thread unhandled exception
call-stack.

It did not shows only handled exceptions call-stack.

--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

alexu
04-Apr-2006, 04:18 PM
Here is scenario where it is very important

We have a SOAP server application, which has no GUI and runs as a windows service. Every WebXXX method is framed by try...except block, in the except..end block we create a friendly XML and return it to the calling application. We never have an unhandled exception. So the code looks like

procedure WebMethod: string
begin
try
Internal_Proc1;
Internal_Proc2;
... etc
Internal_ProcX;
Result := CreateResponseXML;
except
on e: exception do begin
Result := CreateErrorResponse( e.Message )
LogErrorDetails( e )
end;
end;
end;

Because we trap all the exception EurekaLog never gets called, but we still want to log full stack track. Each Internal_Proc1, 2, ..X is big and complicated procedure with 1000s lines of code underneath and each could call 100s other functions, so it is important for us to know what exact sequence of calls lead to the exception.

The open-source Project JEDI (Jcl) has a function called JclLastExceptStackListToStrings(), which is exactly what we need in this case. Get all information about last exception into the log.

JCL requires full debug info to be turned on, and this is the problem for us. Thats why we paid for EurekaLog - so our executables stay small, but we still want all the functionality!

Please let us know if you can help ;)

JimHanson
04-Apr-2006, 08:59 PM
Hello!

I am really surprised Eurekalog is missing this feature. Every other stack tracer I have used with Delphi has this feature:

-Jedi tool (as mentioned in post above)
-Madshi MadExcept
-Exception Magic


Let us know the scoop in Eureka land!

All the plumbing is there, so this feature must be in reach.

admin
06-Apr-2006, 08:16 AM
Hi,

alexu wrote:
> Here is scenario where it is very important
>
> We have a SOAP server application, which has no GUI and runs as a
> windows service. Every WebXXX method is framed by try...except block,
> in the except..end block we create a friendly XML and return it to the
> calling application. We never have an unhandled exception.
>
> [...]
>
> JCL requires full debug info to be turned on, and this is the problem
> for us. Thats why we paid for EurekaLog - so our executables stay
> small, but we still want all the functionality!
>
> Please let us know if you can help ;)

Yes, I understand.

Let me thinking on... :)

--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

admin
11-Apr-2006, 11:27 AM
Hi,

alexu wrote:
> Here is scenario where it is very important
>
> We have a SOAP server application, which has no GUI and runs as a
> windows service. Every WebXXX method is framed by try...except block,
> in the except..end block we create a friendly XML and return it to the
> calling application. We never have an unhandled exception. So the code
> looks like
>
> [...]

I have just released the last EurekaLog 5.1.4 RC 4 with the following
new routines:

1)...New "CallStackToStrings" procedure added (to convert any EurekaLog
call-stack into a simple text representation);
2)...New "GetLastExceptionCallStack" function added (to obtain the last
handled/unhandled exception call-stack);
3)...New "GetCallStackByLevels" function added (to obtain a call-stack
subset working on the calls levels);

Try them and came back to me with your opinion, OK? :)

Download it at: http://www.eurekalog.com/login.php

--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

JimHanson
12-Apr-2006, 02:30 PM
Cool!

Will check out.

Thank you!

alexu
12-Apr-2006, 10:16 PM
It is getting warmer! Thank you for the quick implementation. As far as I can tell grabbing the stack trace of the last exception works great. Though there are few small things that need to be addressed.

We use password protection for .elf files and with the password protection turned "ON" CallStackToStrings() returns encrypted data. It generates a problem for us – we can no longer save this data into our internal log, because it will be unreadable for the human beings. The encrypted data belongs in the .elf file, so the EurekaLog viewer can deal with decryption.

The ideal solution from my point of view would be

1. Add new function CallStackToStringsUnencrypted() and let developers like us to deal with encryption in his code.
2. Add new function SaveLastExceptionCallStack() that would grab the last exception call stack and save it to the current .elf file with all encryption/etc. So it looks just like the unhandled exception data.

This would give everyone 2 different options and it should be enough to cover every possible scenario.

Thank you for your fast responses again! Great job !

alex

JimHanson
17-Apr-2006, 06:04 PM
Any word on these:


1. Add new function CallStackToStringsUnencrypted() and let developers like us to deal with encryption in his code.

2. Add new function SaveLastExceptionCallStack() that would grab the last exception call stack and save it to the current .elf file with all encryption/etc.
So it looks just like the unhandled exception data.


It seems to me this is needed, because without these functions we have to introduce a new log file (e.g. we end up with TWO logs: the Eureka native elf and then our own as well, which is a big hassle)

admin
19-Apr-2006, 05:07 PM
Hi,

alexu wrote:
> It is getting warmer! Thank you for the quick implementation. As far as
> I can tell grabbing the stack trace of the last exception works great.
> Though there are few small things that need to be addressed.
>
> [...]
>
> Thank you for your fast responses again! Great job !
>
> alex

But if your final scope is only obtain that EurekaLog catches "handled
exceptions", then why not uses following code:



uses
ExceptionLog; // Required unit.

....
try
// Your code here...
except
StandardEurekaNotify(ExceptObject, ExceptAddr); // Call EurekaLog.
end;
....



--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

alexu
19-Apr-2006, 10:50 PM
It sounded like it should be enough for us and I just tried this call - unfortunatelly it does not work properly

It sets focus to the application that calls it. We have application running in the background, exception happens and we call StandardEurekaNotify() - then our application takes the input focus from the user. Not good.

So this is still an open issue. Fixing StandardEurekaNotify() would be great, giving us other options would work too...

Thank you

Alex

admin
22-Apr-2006, 03:36 PM
Hi,

alexu wrote:
> It sounded like it should be enough for us and I just tried this call -
> unfortunatelly it does not work properly
>
> It sets focus to the application that calls it. We have application
> running in the background, exception happens and we call
> StandardEurekaNotify() - then our application takes the input focus
> from the user. Not good.
>
> So this is still an open issue. Fixing StandardEurekaNotify() would be
> great, giving us other options would work too...
>
> Thank you
>
> Alex

I have just released the last EurekaLog 5.1.4 RC 6 at:
http://www.eurekalog.com/login.php

Now the application is restored only if is required the "exception/send dialog"
showing or the screenshot capturing.

Can you try with it, please?

I'm waiting for your feedback ASAP, ok? :)


--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

alexu
25-Apr-2006, 07:05 PM
Thank you for the fast response again. We tried the latest build. It does not have the focusing problem. This one is fixed :)

Unfortunately I found that there is another issue with using StandardEurekaNotify().

Here is scenario:

One of our applications is a GUI app that has a mix of handled/unhandled exceptions. Handled ones are presented to the user as nice custom dialog box with possible steps to resolve, etc. Unhandled exceptions are presented in the regular way – error message boxes with “OK” button.

EurekaLog configured to “Show Exception Dialog” = TRUE, so user gets message box for the unhandled exception.

Now every time we call StandardEurekaNotify() the exception dialog box pops up. Even though at the moment I might have a “handled” exception – user still get the message box!

The bottom line, the following code should never show any message boxes to the user, no matter what are the EurekaLog settings. Current version will show 100 message boxes :)

try
raise Exception.Create( ‘Test Exception’ );
except
for I := 0 to 100 do
StandardEurekaNotify()
end;

alexu
25-Apr-2006, 07:08 PM
> The bottom line, the following code should never show any message boxes to > the user, no matter what are the EurekaLog settings.

Let me rephrase it – there should be a way to make this code not to show any messages.

You should probably keep the current StandardEurekaNotify() behavior since it does work “by design”. But we still need a way to silently log incoming exception

Alex

admin
26-Apr-2006, 09:02 AM
Hi,

alexu wrote:
>> The bottom line, the following code should never show any message
> boxes to > the user, no matter what are the EurekaLog settings.
>
> Let me rephrase it – there should be a way to make this code not to
> show any messages.
>
> You should probably keep the current StandardEurekaNotify() behavior
> since it does work “by design”. But we still need a way to silently log
> incoming exception
>
> Alex

You can simply deactivate and activate the MessageBox showing inside a
Try/Finally block.



uses
ExceptionLog, ECore;

procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
try
raise Exception.Create('Test Exception');
except
for i := 1 to 1 do
begin
// Set the exception dialog as hide...
with CurrentEurekaLogOptions do
ExceptionDialogOptions :=
(ExceptionDialogOptions - [edoShowExceptionDialog]);
try
StandardEurekaNotify(ExceptObject, ExceptAddr);
finally
// Set the exception dialog as NOT hide...
with CurrentEurekaLogOptions do
ExceptionDialogOptions :=
(ExceptionDialogOptions + [edoShowExceptionDialog]);
end;
end;
end;
end;



--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

alexu
26-Apr-2006, 05:58 PM
Hmm. Interesting solution. I have implemented it and will do some testing today/tomorrow. Thanks :)

Btw, how can set the stack trace encryption password at runtime? I do not see any related properties CurrentEurekaLogOptions

admin
27-Apr-2006, 08:50 AM
Hi,

alexu wrote:
> Hmm. Interesting solution. I have implemented it and will do some
> testing today/tomorrow. Thanks :)
>
> Btw, how can set the stack trace encryption password at runtime? I do
> not see any related properties CurrentEurekaLogOptions

You should use the OnPasswordRequest event.
See here: http://www.eurekalog.com/docs/passwordrequesthowto.html

--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!

alexu
28-Apr-2006, 12:01 AM
Thank you for your help !

admin
28-Apr-2006, 05:41 AM
Hi,

alexu wrote:
> Thank you for your help !

You're welcome.

--
Best regards...

Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!