#1 2025-08-13 16:37:46

spenov
Member
Registered: 2025-08-13
Posts: 1

How to get the call stack for an exception.

I'm trying to get the module name and line number from an address, but I'm getting incorrect results.

Here is an example of the procedure I'm using to obtain the call stack.

function DumpExceptionCallStack_mormot(E: Exception):string;
var
   I, FC:Integer;
   Frames:PCodePointer;
   log: TSynLog;
begin
   Frames:=ExceptFrames;
   FC:=ExceptFrameCount;
   log := GlobalCurrentHandleExceptionSynLog;
   log.Writer.AddCRAndIndent;
   Result:='Exception class: '+E.ClassName+LineEnding+
           'Message: '+E.Message+LineEnding+
           'FrameCount='+IntToStr(FC)+LineEnding+
           'Stacktrace:'+LineEnding;
   log.Writer.AddString(Result);
   log.Writer.AddCRAndIndent;
   TDebugFile.Log(log.Writer, PtrUInt(ExceptAddr), {notcode=}true, {symbol=}false);
   log.Writer.AddCRAndIndent;
   for I:=0 to FC-1 do begin
      TDebugFile.Log(log.Writer, PtrUInt(Frames[I]), {notcode=}true, {symbol=}false);
      log.Writer.AddCRAndIndent;
   end;
end;

Could it be that I'm passing the address incorrectly?

In the forum post, I provided a more detailed description of the data I'm getting and attached a test project.
https://forum.lazarus.freepascal.org/in … 034.0.html

Offline

Board footer

Powered by FluxBB