void __builtin_return_address (unsigned int level); Returns the return address of the current function, or of one of its callers. Where
level argument is a constant literal indicating the number of frames to scan up the call stack. The
level must range from 0 to 63. A value of 0 yields the return address of the current function, a value of 1 yields the return address of the caller of the current function and so on.
Notes:
- When the top of the stack is reached, the function will return 0.
- The level must range from 0 to 63, otherwise a warning message will be issued and the compilation will halt.
- When functions are inlined, the return address corresponds to that of the function that is returned to.
- Compiler optimization may affect expected return value due to introducing extra stack frames or fewer stack frames than expected due to optimizations such as inlining.
__builtin_return_address(0) yields the address to which the current function will return. __builtin_return_address(1) yields the address to which the caller will return, and so on up the stack.
Return probes operates by replacing the return address in the stack (or in a known register, such as the lr register for ppc - what else can you do with a system with 100's of registers :) ). This may cause __builtin_return_address(0), when invoked from return-probed function, to return the address of the return-probes trampoline. There has been concern that this will break something.
__builtin_return_address is used entirely for tracing, profiling, and error reporting.