I want to instrument my code directly by pre-processing source files with sed/awk. I cannot use other methods like debugger traces or gcc option -finstrument-functions
. In this last case, the addresses are rebased in some way I cannot manage and I miss the correspondence with the symbol table. Other methods presented here (ptrace, etrace, callgraph, etc) or here work well on a simple example, but not in my real project.
The problem is that when processing big open source projects, the writing standards of functions differ, not only between C and C++ files, but often in the same file. The {
may be at the end of the argument list, or on the other line, structures or assignment may use a starting {
, making simple function parsing false.
So the solution presented in the above links that insert a macro in the beginning of the function definition does not work in general, and it is not feasible to correct by hand kilo lines of code (KLOC).
sed 's/^{/{ENTRY/'
So, how to target reliably functions definitions in C/C++ code with regular expressions usable in sed or awk? Possibly by using a part of the gcc precompiler code? I am looking for something possibly off-the -shelf please.