__builtin_return_address为索引> 0返回null吗? [英] __builtin_return_address returns null for index >0?

查看:80
本文介绍了__builtin_return_address为索引> 0返回null吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取调用者函数的返回地址.我正在使用 __ 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 GCC 和特定于处理器(也可以在某些版本中使用://clang.llvm.org/"rel =" nofollow noreferrer>在 some 处理器上使用 some -缺少优化的clang ),并记录为

__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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆