[Lazarus] Listing out a call stack...

Dominique Louis dominique at savagesoftware.com.au
Tue Aug 26 21:46:53 CEST 2008


Graeme Geldenhuys wrote:
> ----------------------------------------------------
> procedure DumpStack;
> Var
>   Message : String;
>   i : longint;
> begin
>   writeln(' Stack trace:');
> //  Dump_Stack(StdOut, get_frame);
> 
>   Writeln(stdout,'An unhandled exception occurred at
> $',HexStr(Ptrint(ExceptAddr),sizeof(PtrInt)*2),' :');
>   if ExceptObject is exception then
>    begin
>      Message:=Exception(ExceptObject).ClassName+' :
> '+Exception(ExceptObject).Message;
>      Writeln(stdout,Message);
>    end
>   else
>    Writeln(stdout,'Exception object ',ExceptObject.ClassName,' is not
> of class Exception.');
>   Writeln(stdout,BackTraceStrFunc(ExceptAddr));
>   if (ExceptFrameCount>0) then
>     begin
>       for i:=0 to ExceptFrameCount-1 do
>         Writeln(stdout,BackTraceStrFunc(ExceptFrames[i]));
>     end;
>   Writeln(stdout,'');
> end;
> ----------------------------------------------------
> 
> Please note that the above needs stdout to be available, so Windows
> applications must be compiler without gui option enabled (-WG must not
> be specified).
> 
> I think there is such a function in LCLProc unit as well...

Thanks for the example.

Dominique.



More information about the Lazarus mailing list