[fpc-pascal] Debug info at runtime?
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)
CallerFrame, CallerAddr, BP: Pointer;
CallerName: string = '';
// get N-2 caller proc name
BP := get_frame;
PrevBP := BP - 1;
i := 0;
while BP > PrevBP do
CallerAddr := get_caller_addr(BP);
CallerFrame := get_caller_frame(BP);
if (CallerAddr = nil) or (CallerFrame = nil) then
if i = 2 then
CallerName := BackTraceStrFunc(CallerAddr);
PrevBP := BP;
BP := CallerFrame;
CallerName should contains something like
$0043EF0A TSCRIPTSTEST__TESTPARSER, line 749 of ScriptsTest.pas
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?
More information about the fpc-pascal