3

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

  1. GTags - Detects identifiers pretty well, but there's no way to differentiate function calls from definitions etc.

  2. CScope - good for C, but fails sometimes with C++

  3. 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.

Community
  • 1
  • 1
Eenoku
  • 2,741
  • 4
  • 32
  • 64
  • Have you tried [clang-tags](http://ffevotte.github.io/clang-tags/)? – Leon Sep 02 '16 at 09:17
  • @Leon I haven't, but now, when I took a look at it, it seems, that it only looks for "references", which means definitions and calls, not only calls. Do you know, how to look for calls only? – Eenoku Sep 02 '16 at 09:43
  • It seems to annotate references so that you can distinguish between a definition and a call. – Leon Sep 02 '16 at 09:47
  • @Leon As we can see in [this example](http://ffevotte.github.io/clang-tags/#text-2-3-2) , `void display ()` is listed within references. – Eenoku Sep 02 '16 at 09:53
  • Yes, but the comment on the right hints that it is a definition (not in a good format, however). – Leon Sep 02 '16 at 09:54
  • All you want is the location (file/line/column) of function calls (method calls, constructors, destructors, overload operator invocations, ...)? Nothing else? – Ira Baxter Sep 02 '16 at 10:03
  • @Leon Oh, I thought the comment is not a part of the output itself :-) – Eenoku Sep 02 '16 at 10:17
  • @IraBaxter Yes, exactly. Nothing else is needed :-) – Eenoku Sep 02 '16 at 10:18

0 Answers0