[fpc-pascal] Debug info at runtime?
Serguei TARASSOV
serge at arbinada.com
Wed May 27 11:41:19 CEST 2015
I answered myself :) Hope this helps someone.
Here is an example how to get N-2 calling procedure
Warning: code seeking debugging info is slow so be aware to use it in loops.
Make sure to compile with
-gl (not requierd but show file and line numbers info)
-gs (show proc name after address)
var
i: Longint;
PrevBP: Pointer;
CallerFrame, CallerAddr, BP: Pointer;
CallerName: string = '';
begin
// get N-2 caller proc name
BP := get_frame;
PrevBP := BP - 1;
i := 0;
while BP > PrevBP do
begin
CallerAddr := get_caller_addr(BP);
CallerFrame := get_caller_frame(BP);
if (CallerAddr = nil) or (CallerFrame = nil) then
break;
if i = 2 then
begin
CallerName := BackTraceStrFunc(CallerAddr);
break;
end;
PrevBP := BP;
BP := CallerFrame;
Inc(i);
end;
...
CallerName should contains something like
$0043EF0A TSCRIPTSTEST__TESTPARSER, line 749 of ScriptsTest.pas
Regards,
Serguei
On 26/05/2015 19:30, Serguei TARASSOV wrote:
> Hi All,
>
> How is possible to get some debug information at runtime?
> Assuming, the program compiled with required debug information/symbols.
>
> I.e. how to get actual call stack state and called procedures names
> within the procedure or method?
>
> Regards,
> Serguei
More information about the fpc-pascal
mailing list