I am working on embedded code and for now totally reliant on prints from within functions to figure out the flow of execution (there is no stack trace functionality available).
It often happens that I put a bunch of print statements, build my code and run it only to realize I should've put prints in a dozen other places too. And then start the hour long process again.
Is there an easy way to take my 5 or 6 c files that I want to analyze and run some tool that will go in and add a print statement in each function? (this will obviously have to be after the variable declarations as this is in C)
Even better would be to have a print each time there is an if/ else or switch/ case ..basically any conditional statements.
You don't state the compiler you are using, but gcc has a very handy switch:
-finstrument-functions
which inserts a special call at each function entry and exit. You could compile only the relevant files with this tweak, no need to modify the source code.
The calls are made to two functions you should create:
void __cyg_profile_func_enter (void *this_fn,
void *call_site);
void __cyg_profile_func_exit (void *this_fn,
void *call_site);
Etrace is a tool designed for exploiting this to create call traces, see http://ndevilla.free.fr/etrace/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With