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.
For only 5-6 files I would manually go in and add a PRINT("name of function") macro in each function and then define that to either output the string, or nothing
You could use ctags to analyse the files and build this automatically but unless you have 100s of files it would be quicker to just do it by hand
You don't state the compiler you are using, but gcc has a very handy switch:
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:
Etrace is a tool designed for exploiting this to create call traces, see http://ndevilla.free.fr/etrace/
you can use macros like this
and then replace all your
{
,}
with begin and end macros (__func__ is a macro which return function name and is defined in C99 there are also other equvalent macros for other compilers)I would recommend you using a debugger, like GBD. That way you can even run your program "step by step" and analyze such conditions. I don't see a reason to print something in every function.
If vim is your favourite editor you can install this plugin: http://www.vim.org/scripts/script.php?script_id=213 and customize the related template. Can be useful for a lot of differents tasks. (It works for the new functions that you will define, that is not your case but might be useful for future use)