0

I am new in a company, working with C source code which almost lacks any kind of tracing mechanism. I would like to know whether or not the application passes through a certain file and where (which function). I could do this using breakpoints, but the concerned file contains a huge lot of functions.

Therefore I'm looking for some kind of tool, that I can attach to the application, and that gives an output of following kind:

-- Main.c (main_function())

---- submain.c (submain_function())

...

From that, I then could deduce where (which filename, which function) the application is passing.

Does anybody know whether or not such a tool exists? Thanks

Community
  • 1
  • 1
Dominique
  • 16,450
  • 15
  • 56
  • 112

2 Answers2

1

If you're on linux, gdb might come handy.

You can compile the code using -g or -g3 option with gcc, then run the binary using gdb ./<executable_name>, set a breakpoint on desired function in any of the source files and check the call.

While stepping through the application, it will show the filename and line number of the executing instruction.

Note: Please check this and this for a detailed understanding.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
0

I assume you develop on Linux. Then you could also customize the GCC compiler, in particular using MELT (a lispy domain specific language to extend GCC), to have the compiler add some logging at many places. For that you'll need to insert a new GCC "optimization" pass doing such a job, and most importantly, you'll need to understand some details about GCC internal representations (Gimple, Tree-s, Basic blocks, ...)

However, that would probably require more than a week of work from your part. Unless your code base is really big (at least half a million of lines) that might not worth the effort

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547