14

I've been trying to use Eclipse CDT to do some c++ examples, i can run them just fine with the run command, but whenever i try to Debug, the console window freezes up, I'm able to input, but the program doesn't continue.

When I debug, i get the following output on the console window (no breakpoints, but breaks on main because of default settings):

Hello, world
put your name: 15^running

The continue button is disabled and doesn't do anything when I input something and hit enter. The 15 is a random number, sometimes its 16, 20 etc.

If I run the program under eclipse I get the input prompt just fine:

Hello, world
put your name: test
Hello test

this is the code I try to debug:

#include <iostream>
#include <string>

int main() {
    std::cout << "Hello, world" << std::endl;
    std::string name;
    std::cout << "put your name: ";
    std::cin >> name;
    std::cout << "Hello " + name << std::endl;
    return 0;
}

My path var:
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Program Files\Java\jdk1.6.0_14\bin;C:\MinGW\bin

Eclipse version: Helios Service Release 2
CDT version: 7.0.2
OS: windows xp
GDB version: GNU gdb (GDB) 7.2

How can I debug this small example under CDT, without issues?

3 Answers 3

12
+125

15^running looks as a result record from gdb's Machine Interface. Normally it shouldn't appear in the Eclipse console.

I recommend trying a different Create Process Launcher. It can be changed in the following way:

  1. In Main menu choose "Run" -> "Debug Configurations...".

  2. In the opened "Debug Configurations" window shown below click "Select other..." opposite "Using GDB (DSF) Create Process Launcher".

    enter image description here

  3. In the opened "Select Preferred Launcher" window shown below check "Use configuration specific settings", select "Standard Create Process Launcher" in the list below and click OK.

    enter image description here

  4. Now go to the Debugger tab in the "Debug Configurations" window, select debugger, e.g. "MinGW gdb" and click Apply.

    enter image description here

With the Standard Create Process Launcher I am able to debug your program although "put your name:" is printed only after I type something and hit Enter, because the output stream is not flushed.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for this - this was the problem I was having on linux as well, when trying to debug mozilla using gdb + eclipse.
1

Try having a look at this http://www.cprogramming.com/gdbtutorial.html and see if that helps. Like can you press CTRL-C to break?

Also Cannot enter input with gdb. Help! might be a pointer although related to apple.

1 Comment

I got a little further now, i think its a problem with the windows console not popping up. i'm looking at codelite right now, seems to perform a bit better at debugging.
0

the following is from the Eclipse website's FAQ:

http://wiki.eclipse.org/CDT/User/FAQ#Eclipse_console_does_not_show_output_on_Windows

Eclipse console does not show output on Windows In Eclipse CDT on Windows, standard output of the program being run or debugged is fully buffered, because it is not connected to a Windwos console, but to a pipe. See bug 173732 for more details. Either add fflush calls after every printf or add the following lines in the start of the main function:

setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);

Seems like an expected bug on windows.

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.