0

I'm trying to port software to a microcontroller (so I can't step through the code with e.g. gdb) and it crashes unpleasantly. To identify the reason for this, I want to insert a 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 already some script to do this?

1
  • Be sure you don't add a line to a block without {}s in it, like a 1-line for loop. Commented Apr 25, 2013 at 19:29

1 Answer 1

2

It still requires a fair bit of setup but you can make tracking down the location of a crash a bit less painful by defining a macro which prints file/line and dotting that through your 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}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.