I need a way to detect places, where a specific function is called. E.g.:
myPrint():
main.c, line 28
utils.c, line 89
The point is, I need only function calls, not definitions or declarations. And I need it not only for "simple" C-like identifiers, but even for class methods, functions defined in namespaces etc., because I'll use this program mainly for C++.
My attempts
GTags - Detects identifiers pretty well, but there's no way to differentiate function calls from definitions etc.
CScope - good for C, but fails sometimes with C++
objdump
+addr2line
- described more in detail below
I'm now trying to use objdump
with addr2line
this way:
objdump --disassemble-all binary | grep 'nameOfFunction'
Output looks like this:
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>
And then I take the number from the first column and try to get the physical location in a code like this:
addr2line -e binary 5834c3
Sometimes it finds the function call correctly, sometimes it finds something completely different (I guess some kind of reference etc.).
And so, my question is - is it possible to detect which findings are function calls? I see, that there is callq
in the output, but I'm not completely sure it's only function call in the code.