2

我需要一种方法来检测调用特定函数的位置。例如:

myPrint():
main.c, line 28
utils.c, line 89

关键是,我只需要函数调用,而不是定义或声明。而且我不仅需要它用于“简单”的类 C 标识符,甚至用于类方法、命名空间中定义的函数等,因为我将把这个程序主要用于 C++。


我的尝试

  1. GTags - 很好地检测标识符,但无法区分函数调用和定义等。

  2. CScope - 适用于 C,但有时会在 C++ 中失败

  3. objdump+ addr2line- 下面更详细地描述

我现在正在尝试以objdump这种addr2line方式使用:

objdump --disassemble-all binary | grep 'nameOfFunction'

输出如下所示:

5834c3: e8 e8 79 00 00          callq  58aeb0 <_ZN7espreso14IterSolverBase24Solve_RegCG_singular_domERNS_10ClusterCPUERSt6vectorIS3_IdSaIdEESaIS5_EE>
58bef4: e8 57 45 00 00          callq  590450 <_ZZN7espreso14IterSolverBase24Solve_RegCG_singular_domERNS_10ClusterCPUERSt6vectorIS3_IdSaIdEESaIS5_EEENKUliE_clEi>
58bf43: e8 08 45 00 00          callq  590450 <_ZZN7espreso14IterSolverBase24Solve_RegCG_singular_domERNS_10ClusterCPUERSt6vectorIS3_IdSaIdEESaIS5_EEENKUliE_clEi>
58bf7c: e8 cf 44 00 00          callq  590450 <_ZZN7espreso14IterSolverBase24Solve_RegCG_singular_domERNS_10ClusterCPUERSt6vectorIS3_IdSaIdEESaIS5_EEENKUliE_clEi>

然后我从第一列中取出数字并尝试在如下代码中获取物理位置:

addr2line -e binary 5834c3

有时它会正确地找到函数调用,有时它会找到完全不同的东西(我猜是某种参考等)。

所以,我的问题是——是否有可能检测出哪些发现是函数调用?我明白callq了,输出中有,但我不完全确定它只是代码中的函数调用。

4

0 回答 0