[fpc-pascal] get_caller_frame

Sven Barth pascaldragon at googlemail.com
Thu Nov 21 07:41:01 CET 2019

Am 20.11.2019 um 23:52 schrieb Ryan Joseph via fpc-pascal:
>> On Nov 20, 2019, at 1:56 AM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> It returns the address of the caller's frame pointer. See also https://www.freepascal.org/docs-html/rtl/system/get_caller_frame.html
>> It's mainly used in context of raising exceptions with the help of a second function. See here: https://freepascal.org/docs-html/current/ref/refse112.html#x227-24900017.1
> I guess I don't know what a frame pointer is. I thought it meant a pointer to the current stack frame and so I was curious if the RTL could include a way to copy the stack with the pointer and restore it later. Is that not how it works?
No. On x86 it's essentially the content of the EBP/RBP register which is 
(assuming no optimizations are done) essentially the ESP/RSP register of 
the calling function. This is only used by the exception handling to 
have the exception appear to be raised somewhere else.

The exception handling itself does not need it. The generic mechanism 
for example is a stack of exception frames (both except- and 
finally-blocks) and the exception handling code calls the handlers from 
top to bottom (thus executing explicit destructors (bla.Free) and 
implicit reference count decreases) before restoring the state using 
LongJmp (which also restores the original stack pointer register). The 
SEH and PSABIEH mechanisms that FPC supports work in a similar way (e.g. 
the SEH on Win32 is a single linked list).


More information about the fpc-pascal mailing list