Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding printf to the starting of all functions in a file

Tags:

python

c

perl

I have some very large C files, having lots of functions. I need to trace the execution path at run time. There is no way I can trace it through debugging as its a hypervisor code currently running over qemu and doing a lot of binary translations.

Can anyone point me to some script in Perl or Python which can add a printf at the starting of all functions and the text could be something like "I am in < function name >"?

like image 354
g__k Avatar asked Jun 20 '10 08:06

g__k


People also ask

What does printf do in C++?

C++ printf is a formatting function that is used to print a string to stdout. The basic idea to call printf in C++ is to provide a string of characters that need to be printed as it is in the program. The printf in C++ also contains a format specifier that is replaced by the actual value during execution.

How does the printf function work?

The printf function (the name comes from “print formatted”) prints a string on the screen using a “format string” that includes the instructions to mix several strings and produce the final string to be printed on the screen.

How does printf work in assembly?

Printf in Assembly To call printf from assembly language, you just pass the format string in rdi as usual for the first argument, pass any format specifier arguments in the next argument register rsi, then rdx, etc.

How do I print a printf string?

We can print the string using %s format specifier in printf function. It will print the string from the given starting address to the null '\0' character. String name itself the starting address of the string. So, if we give string name it will print the entire string.


1 Answers

Just pass -finstrument-functions to gcc when compiling. See the gcc(1) man page for details.

like image 121
Ignacio Vazquez-Abrams Avatar answered Oct 23 '22 11:10

Ignacio Vazquez-Abrams