[fpc-pascal] How to get a full backtrace in code?
Vincent Snijders
vsnijders at quicknet.nl
Thu Apr 10 16:55:12 CEST 2008
Mattias Gaertner schreef:
> On Thu, 10 Apr 2008 16:39:09 +0200
> Graeme Geldenhuys <graemeg.lists at gmail.com> 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
More information about the fpc-pascal
mailing list