I am trying to figure out how to get a stack trace after an exception in Delphi. However, when I try to read the stack in the Application.OnException event using the function below, the stack already seems to be cleared and replaced by throwing procedures.
function GetStackReport: AnsiString;
var
retaddr, walker: ^pointer;
begin
asm
mov walker, ebp
end;
while Cardinal(walker^) <> 0 do begin
retaddr := walker;
Inc(retaddr);
result := result + AddressInfo(Cardinal(retaddr^));
walker := walker^;
end;
end;
Here are the results I get:
001A63E3: TApplication.HandleException (Forms)
00129072: StdWndProc (Classes)
001A60B0: TApplication.ProcessMessage (Forms)
This is clearly not what I am looking for, although it is correct. I would like to get a stack, as it was before the exception was thrown, or, in other words, the contents before (after that, too) the OnException call.
Is there any way to do this?
I know that I am inventing the wheel because the people at madExcept / Eurekalog / jclDebug have already done this, but I would like to know how to do it.
source
share