Sign in Join

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

Mailing lists / lazarus / 2008-08

Listing out a call stack...

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys
to Dominique Louis
Dominique Louis wrote
Hi all, Is there anyway for me to output a call stack at run-time?
----------------------------------------------------
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...

Regards,
- Graeme -

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

Reply by email

Dominique Louis
to Graeme Geldenhuys
Graeme Geldenhuys wrote 35 lines
---------------------------------------------------- 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.

Reply by email

Graeme Geldenhuys
to Mattias Gärtner
Mattias G?rtner wrote
Yes, it's called the same (DumpStack) and uses Debugln instead of writeln, so it works even without -WG under windows. And it caches backtraces, which makes it much faster.

Where does Debugln send it's data to under Windows (with GUI (-WG) enabled)? Or does it silently ignore output?

Regards,
- Graeme -

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

Reply by email

Vincent Snijders
to Graeme Geldenhuys
Graeme Geldenhuys wrote 8 lines
On Wed, Aug 27, 2008 at 10:42 AM, Mattias G?rtner wrote: > Yes, it's called the same (DumpStack) and uses Debugln instead of writeln, so it > works even without -WG under windows. And it caches backtraces, which makes it > much faster. Where does Debugln send it's data to under Windows (with GUI (-WG) enabled)? Or does it silently ignore output?

See:
http://wiki.lazarus.freepascal.org/Lazarus_Faq#How_can_I_see_debug_output.3F

Vincent

Reply by email