__builtin_return_address为索引> 0返回null吗? [英] __builtin_return_address returns null for index >0?
问题描述
我想获取调用者函数的返回地址.我正在使用 __ builtin_return_address()
函数,但如果索引值大于0,则会返回 NULL
.
I want to get the return address of the caller function. I'm using __builtin_return_address()
funtion, but if I give index value greater than 0 it is returning NULL
.
请帮助我解决这个问题,或者告诉我其他任何获得相同功能的功能.
Please help me with this or tell me any other function to get the same.
推荐答案
请参见有关相关问题的答案.
__ builtin_return_address
是
__builtin_return_address
is GCC and processor specific (also available in some versions of Clang on some processors with some -lack of- optimizations), and documented as
在某些机器上,可能无法确定除当前函数以外的任何函数的返回地址
On some machines it may be impossible to determine the return address of any function other than the current one
编译器可能会优化功能(例如,使用 -fomit-frame-pointer
进行编译时,或针对尾随呼叫,或通过功能内联),而没有相关信息.
The compiler might optimize a function (e.g. when it is compiled with -fomit-frame-pointer
, or for tail-calls, or by function inlining) without the relevant information.
因此您可能会得到 NULL
,因为该信息不可用!
So probably you are getting NULL
because the information is not available!
这篇关于__builtin_return_address为索引> 0返回null吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!