문제

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?

도움이 되었습니까?

해결책

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}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top