[fpc-pascal] Get all caller adresses of a procedure/function

Sven Barth pascaldragon at googlemail.com
Mon Aug 6 19:34:23 CEST 2012


On 06.08.2012 19:28, Rainer Stratmann wrote:
> Am Monday 06 August 2012 18:43:04 schrieb Martin:
>>> How to get all caller adresses of p1 in a program before p1 is executed?
>>>
>>> For example p1 is called from 20 different places in a program.
>>> Then I need the 20 caller adresses.
>>
>> At run time, or design time?
>
> At runtime.
> I ment the (memory) caller adresses.
>
> If p1 is executed I can get the caller adress with the rtl function:
>
> get_caller_addr( get_frame );
>
> But I want to scan the whole program before all p1's are called by the program
> to get all caller adresses of p1.
>
> May be I write an own scan program to find all calling places which calls p1.
>
> For that I need the memory adress where the program starts. And the length.
>

You know that scanning the binary code for calls is platform dependant? 
So you'd need to write that code for every CPU you want to support. Also 
this is much harder to do for CISC CPUs like x86 than for RISC CPUs 
(ARM, MIPS, etc), because the former have variable length opcodes. So 
you'd basically need to write a full blown dissembler...

Maybe it would be more interesting to know why you need this beforehand?

Regards,
Sven



More information about the fpc-pascal mailing list