Hi all,
Is there anyway for me to output a call stack at run-time?
Thanks,
Dominique.

Mailing lists / lazarus / 2008-08
7 messages · 4 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi all,
Is there anyway for me to output a call stack at run-time?
Thanks,
Dominique.
Dominique Louis wroteHi 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/
Thanks for the example.
Dominique.
An embedded and charset-unspecified text was scrubbed... Name: not available
Url: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080827/8dcdbb13/attachment.pl
Mattias G?rtner wroteYes, 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/
See:
http://wiki.lazarus.freepascal.org/Lazarus_Faq#How_can_I_see_debug_output.3F
Vincent
Vincent Snijders wrote
Very nice! Thanks for the link Vincent.
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/