c - printf debugging to trace a function -
i'm trying port software microcontroller (so can't step through code e.g. gdb) , crashes unpleasantly. identify reason this, want insert printf()
before every statement, echoing said statement, e.g.
void foo(int c) { bar(); for(int i=0; i<c; ++c) { baz(i); } very_long_function(&with, &arguments, \ on->several(lines)); }
would become
void foo(int c) { printf("bar();\n"); bar(); printf("for(int i=0; i<c; ++c)\n"); for(int i=0; i<c; ++c) { printf("baz(i)\n"); baz(i); } printf("very_long_function(&with, &arguments, \ on->several(lines));\n"); very_long_function(&with, &arguments, \ on->several(lines)); }
is there script this?
it still requires fair bit of setup can make tracking down location of crash bit less painful defining macro prints file/line , dotting through code
#define fl printf("file %s, line %u\n", __file__, __line__); void foo(int c) { fl bar(); fl for(int i=0; i<c; ++c) { fl baz(i); } fl very_long_function(&with, &arguments, \ on->several(lines)); fl}