[fpc-pascal] How to get a full backtrace in code?

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Apr 10 16:39:09 CEST 2008


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/





More information about the fpc-pascal mailing list