Delphi gets stack trace after exception

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

    // ...

    // History of stack, ignore esp frame
    asm
        mov walker, ebp
    end;

    // assume return address is present above ebp
    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.

+5
source share
2 answers

OnException. , . , , . , MadExcept, EurekaLog .., , RTL.

Delphi SysUtils.Exception StackTrace StackInfo, OnException, , Embarcadero NOT . , , Exception . JclDebug, , , JCL .

+12

, , , , ( ) OnException.

OnException. , . , , . , . OnException, .

madExcept , RTL, . . . , .. , RTL.

, . , , , , x86, - , madExcept .

. , JclDebug. madExcept .

+3

All Articles