[fpc-pascal] Get all caller adresses of a procedure/function
Rainer Stratmann
RainerStratmann at t-online.de
Mon Aug 6 21:18:20 CEST 2012
Am Monday 06 August 2012 20:15:53 schrieb Martin:
>
> You can probably reuse sone code from the system unit.
>
> below is a copy of dump_stack from fpc. It gets all the addresses
>
>
> {$ifdef FPC_HAS_FEATURE_CONSOLEIO}
> Procedure dump_stack(var f : text;bp : Pointer);
> var
> i : Longint;
> prevbp : Pointer;
> is_dev : boolean;
> caller_frame,
> caller_addr : Pointer;
> Begin
> {$ifdef FPC_HAS_FEATURE_EXCEPTIONS}
> try
> {$endif FPC_HAS_FEATURE_EXCEPTIONS}
> prevbp:=bp-1;
> i:=0;
> is_dev:=do_isdevice(textrec(f).Handle);
> while bp > prevbp Do
> Begin
> caller_addr := get_caller_addr(bp);
> caller_frame := get_caller_frame(bp);
> if (caller_addr=nil) then
> break;
> Writeln(f,BackTraceStrFunc(caller_addr));
> if (caller_frame=nil) then
> break;
> Inc(i);
> If ((i>max_frame_dump) and is_dev) or (i>256) Then
> break;
> prevbp:=bp;
> bp:=caller_frame;
> End;
> {$ifdef FPC_HAS_FEATURE_EXCEPTIONS}
> except
> { prevent endless dump if an exception occured }
> end;
> {$endif FPC_HAS_FEATURE_EXCEPTIONS}
> End;
I do not understand this ...
What is the content of the stack?
Which file 'f'?
Is it read from or write to file 'f'?
More information about the fpc-pascal
mailing list