Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-04

How to get a full backtrace in code?

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I'm trying to create a default exception handler dialog for fpGUI. It should display the error message and when the user clicks on the 'Details' button, it should show the full backtrace. For some reason the backtrace I get is much smaller compared to the one if I don't handle exceptions at all (and the program crashes).

Currently I'm simply outputting to the console, until I get this right, which should then output to a Memo component. Here is my code to output a backtrace... called by my default exception handler (try...except block).

procedure DumpStack;
begin
   writeln(' Stack trace:');
   Dump_Stack(StdOut, get_frame);
end;

... which gives the following output to the console.....

$ ./tutoradmin.exe
exception at 0809DAAA:
Unknown parameter HELLO.
Stack trace:
$080578F3 TFPGAPPLICATION__HANDLEEXCEPTION, line 981 of /home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas $08057A05 TFPGAPPLICATION__RUNMESSAGELOOP, line 1010 of /home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas $080570A1 TFPGAPPLICATION__RUN, line 848 of
/home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas $080ED713 MAINPROC, line 70 of tutoradmin.lpr
$080ED57D main, line 79 of tutoradmin.lpr
$080ED54D

.... Now if I remove the try...except block and let FPC handle the exception (and the program terminates), I get the following output to the console. As you can see, it's a lot more detailed. How do I generate this myself, so I can display this in a Memo component.

$ ./tutoradmin.exe
An unhandled exception occurred at $0809DA3A :
EFBLError : Unknown parameter HELLO
$0809DA3A TFBLPARAMDSQL__CHECKPARAMNAME, line 630 of FBLParamDsql.pas $0809E134 TFBLPARAMDSQL__PARAMBYNAMEASSTRING, line 723 of FBLParamDsql.pas
$0808D97D TTIQUERYFBL__SETPARAMASSTRING, line 442 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Options/tiQueryFBL.pas $081332B4 TVISLEARNERSCHEDULEGRID_READ__SETUPPARAMS, line 569 of /home/graemeg/programming/MasterMaths/M2Browser_v3/Source/LearnerVisitors.inc $0807C0A5 TVISOWNEDQRYSELECTABS__EXECUTE, line 393 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitorDB.pas $08078B4D TTIVISITED__EXECUTEVISITOR, line 459 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitor.pas $080791DD TTIVISITED__TOUCHMETHODEXECUTEVISITOR, line 586 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitor.pas $0807880B TTIVISITED__ITERATERECURSE, line 409 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitor.pas $08078EAA TTIVISITED__ITERATETOPDOWNRECURSE, line 522 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitor.pas $08079E01 TTIVISITED__ITERATEASSIGNTOUCHED, line 806 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitor.pas $0807A344 TTIVISITORMANAGER__EXECUTEVISITORS, line 906 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitor.pas $0807A79C TTIVISITORMANAGER__PROCESSVISITORS, line 981 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitor.pas $0807C4E3 TTIOBJECTVISITORMANAGER__EXECUTE, line 446 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitorDB.pas $0807C531 TTIOBJECTVISITORMANAGER__EXECUTE, line 455 of /home/graemeg/programming/3rdParty/tiOPF2/Source/Core/tiVisitorDB.pas $0811AB6F TLEARNERSCHEDULEGRID__READ, line 526 of /home/graemeg/programming/MasterMaths/M2Browser_v3/Source/Learner.inc $0811259B TLEARNERMAINTFORM__LOADLEARNERSCHEDULEGRID, line 941 of frm_learnermaint.pas
$08112498 TLEARNERMAINTFORM__LOADTAB, line 914 of frm_learnermaint.pas

Regards,
- Graeme -

_______________________________________________________ fpGUI - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Mattias Gaertner
to Graeme Geldenhuys
Show quoted text 40 lines
Hi, I'm trying to create a default exception handler dialog for fpGUI. It should display the error message and when the user clicks on the 'Details' button, it should show the full backtrace. For some reason the backtrace I get is much smaller compared to the one if I don't handle exceptions at all (and the program crashes). Currently I'm simply outputting to the console, until I get this right, which should then output to a Memo component. Here is my code to output a backtrace... called by my default exception handler (try...except block). procedure DumpStack; begin writeln(' Stack trace:'); Dump_Stack(StdOut, get_frame); end; ... which gives the following output to the console..... $ ./tutoradmin.exe exception at 0809DAAA: Unknown parameter HELLO. Stack trace: $080578F3 TFPGAPPLICATION__HANDLEEXCEPTION, line 981 of /home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas $08057A05 TFPGAPPLICATION__RUNMESSAGELOOP, line 1010 of /home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas $080570A1 TFPGAPPLICATION__RUN, line 848 of /home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas $080ED713 MAINPROC, line 70 of tutoradmin.lpr $080ED57D main, line 79 of tutoradmin.lpr $080ED54D .... Now if I remove the try...except block and let FPC handle the exception (and the program terminates), I get the following output to the console. As you can see, it's a lot more detailed. How do I generate this myself, so I can display this in a Memo component.

Increase Max_Frame_Dump.

Mattias

Reply by email

Vincent Snijders
to Mattias Gaertner
Mattias Gaertner wrote 45 lines
On Thu, 10 Apr 2008 16:39:09 +0200 Graeme Geldenhuys wrote: > Hi, > > I'm trying to create a default exception handler dialog for fpGUI. It > should display the error message and when the user clicks on the > 'Details' button, it should show the full backtrace. For some reason > the backtrace I get is much smaller compared to the one if I don't > handle exceptions at all (and the program crashes). > > Currently I'm simply outputting to the console, until I get this > right, which should then output to a Memo component. Here is my code > to output a backtrace... called by my default exception handler > (try...except block). > > procedure DumpStack; > begin > writeln(' Stack trace:'); > Dump_Stack(StdOut, get_frame); > end; > > ... which gives the following output to the console..... > > $ ./tutoradmin.exe > exception at 0809DAAA: > Unknown parameter HELLO. > Stack trace: > $080578F3 TFPGAPPLICATION__HANDLEEXCEPTION, line 981 of > /home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas > $08057A05 TFPGAPPLICATION__RUNMESSAGELOOP, line 1010 of > /home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas > $080570A1 TFPGAPPLICATION__RUN, line 848 of > /home/graemeg/programming/fpGUI/src/corelib/fpgfx.pas > $080ED713 MAINPROC, line 70 of tutoradmin.lpr > $080ED57D main, line 79 of tutoradmin.lpr > $080ED54D > > > .... Now if I remove the try...except block and let FPC handle the > exception (and the program terminates), I get the following output to > the console. As you can see, it's a lot more detailed. How do I > generate this myself, so I can display this in a Memo component. Increase Max_Frame_Dump.

You created a stack trace from the current frame (in the exception handler). To get the stack trace from the point that the exception occured, you need to use ExceptionFrames. See LCLProc.DumpExceptionBackTrace for an example.

Vincent

Reply by email

Graeme Geldenhuys
to Vincent Snijders
Vincent Snijders wrote 8 lines
> > Increase Max_Frame_Dump. You created a stack trace from the current frame (in the exception handler). To get the stack trace from the point that the exception occured, you need to use ExceptionFrames. See LCLProc.DumpExceptionBackTrace for an example.

Thanks guys, I'll give your suggestions a try.

Regards,
- Graeme -

_______________________________________________________ fpGUI - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email