Search code examples
ceclipseeclipse-cdt

Can't continue stepping in debug mode when reaching "printf" in eclipse


I am trying to debug c in eclipse with the next code:

void print_clause(SAT_clause * c) {
    int l_index;
    printf("(");
    for (l_index = 0; l_index < c->literal_count; l_index++) {
        print_literal(c->literal_arr[l_index]);
        if(l_index != c->literal_count - 1){
            printf(" v ");
        }
    }
    printf(")");
}

but each time I get to the "printf("(");" (the first print in this function) I get the next message in the console :
(*stopped,reason="end-stepping-range"... and than I can't step anymore. I assume this is dbg message that eclipse doesn't parse very well. I read somewhere that I need to add \n in the end of the printf function - that did work but I need the printf without the \n in the end. If I run in release mode - the printing is OK.
What am I doing wrong and how can I continue stepping after the printf ?

UPDATE Ok - I found out what is causing this behavior (but I still have a problem) - it is because of this link : printf not printing on console . I added the setbuf(stdout, NULL); for enable printing in debug but than I can't step. Still if I remove this setbuf(stdout, NULL); I can't see the printf in debug mode because of the buffer (but I can continue stepping). any suggestions ?


Solution

  • If you follow the links and answers listed where you link to, you endup on: https://bugs.eclipse.org/bugs/show_bug.cgi?id=173732 classified as "WON't FIX".

    So, if this really bothers you, my suggestion is to use something else than Eclipse CDT on Windows, or switch to a POSIX system (Unix/Linux/BSD/Solaris...) on which Eclipse CDT will behave correctly.

    Another suggestion would be to try and fix Eclipse CDT, but I'm guessing it's not easy to do otherwise they would have done so themselves already. It seems that Windows itself lacks the "pseudo-terminal" functionality that CDT relies on for its console.

    Something I could think of to fix this in Eclipse CDT: inject your own c-runtime debug lib with unbuffered stdout when in debug mode. I suppose this could be done with the Windows equivalent of LD_PRELOAD (though I have no idea what this looks like in Windows world or even if it is feasible).