I am trying to debug the following C code with eclipse-Juno-CDT, and cygwin-gcc (cygwin version=1.7.16, gcc version=3.4.4, gdb version=7.5.50), on 64bit windows. The code works fine in normal mode. Initially debugger was not running, because the source file was not found. Then I searched around and added the path mapping information (from /cygdrive/c to C:\). Now it is running but with the following problems:
-
I have put a breakpoint before the “hello c 1” line, and then single stepping. But nothing gets printed on the console.
-
after single stepping on the last line (“exit”), I get the error: “No source available for _cygwin_exit_return() at …”
// stdio.h and stdlib.h are included, but when I put a #include the code // they dont show up, so I deleted those lines in this code fragment. int main(void) { int a=10; int b=5; // breakpoint on this line, single step after this printf("hello c 1\n"); // these outputs are not printed in console // fflush(stdout); printf("A=%d, B=%d\n", a, b); // but debugger shows the correct values in data window // fflush(stdout); return EXIT_SUCCESS; // error on this line }
Added later: After some more debugging, I figured that even after the exit-error, if I do a “continue”, then I am getting the lines on the console after the program terminates. So I added extra “fflush(stdout)” lines, and now I can see the outputs when they are being printed.
But how to fix the exit-error problem? Also, editing the file to add fflush to see debug outputs is a pain – is there a way to avoid this? Can somebody help me with this very basic problem, or point me to a place where the solution is given? Thanks in advance.
While logically a C program begins at
int main()and ends when that function returns, environments (like Windows or Cygwin) frequently add pre- and post-code, for initializing / breaking down memory management, opening / closing standard streams, and other such bookkeeping. An executable compiled with Cygwin, after returning fromint main(), switches to a cleanup function_cygwin_exit_return(), provided by the Cygwin runtime – for which you don’t have sources, so your debugger complains.As for getting the output immediately, you could use an unbuffered output stream.
Option one, use
fprintf( stderr, ... )(sincestderris by definition unbuffered). This, however, also affects the non-debugging behaviour of your program.Option two: