【发布时间】:2014-08-27 12:12:41
【问题描述】:
我有一个共享的 obj 文件,比如 a.so,我想查看一个特定的函数(比如 fname)是否被内联。我尝试了以下 4 种方法并得到了不同的答案:
1) nm a.so | grep fname
-> 这不会给出任何暗示该函数是内联的 o/p。 请让我知道这是否足以检查函数是否内联。
2) objdump -d a.so | grep fname
->this 没有给出任何暗示该函数是内联的 o/p。如果我在这里的结论有误,请纠正我。
3) objdump -W a.so
-> 对于函数 fname,这给了我下面的 o/p,最后一行写着“声明为内联但被忽略”
DW_AT_name : (indirect string, offset: 0x10411): fname
DW_AT_decl_file : 246
DW_AT_decl_line : 40
DW_AT_prototyped : 1
DW_AT_inline : 2 (declared as inline but ignored)
4) pfunct -G a.so | grep fname
->这个 dwarves 实用程序显示函数 fname,暗示该函数没有内联。
现在前两种方式意味着函数是内联的,而其余两种方式则相反。谁能解释一下:
1) Why are there differences in the above 4 ways ?
2) Are there any known issues with objdump and pfunct ?
3) Also let me know the best way to check if a function is inlined or not.
任何帮助将不胜感激。谢谢!!!
【问题讨论】:
-
一个函数可能在某些地方被内联,而在其他地方没有被内联。 .so 中是否调用了您的函数?
-
是的,该函数是静态的,并且只在该 .c 文件中的一处调用
-
这个共享的 obj 文件是用调试信息编译的吗?如果不是,那么一个成功的内联函数将没有任何证据表明它曾经是一个函数。
-
yes .so 用调试信息编译
-
Also let me know the best way to check if a function is inlined or not.--- 如果检查gdb下的代码怎么办?您可以创建一个测试程序并在gdb下运行它。