3

I've been having a tough time entering input with gdb using XCode or Eclipse. Every time the debugger hits std::cin, it looks like its waiting for input, but fails to accept it. I've scoured the internet for more information, but am having trouble finding anything.

What do I need to do to get cin to work with gdb? For reference, I'm using XCode 3.2.2 and Eclipse Galileo.

Thanks!

-Carlos Nunez

1
  • What is your gdb version and environment? It works for me on Cygwin with GNU gdb 6.8.0.20080328-cvs (cygwin special) Commented Apr 20, 2010 at 7:04

2 Answers 2

1

I guess there is a bug in GCC related to the usage of std::cin and setting/unsetting breakpoints. I did a minimal example:

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[])
{
    string option = "x";
    while (option != "q")
    {
        cout << endl 
        << "0 = Stop" << endl
        << "1 = Play" << endl
        << "q = Quit" << endl;

        getline(cin, option);
        cout << "You choosed " << option << endl;
    }
}   

This code works perfectly until you set or activate a breakpoint (at least using the XCode wrapper). From then on stdin buffer is broken and every getline() retrieves the last input even though you don't type a key, entering a endless loop.

I don't know how to work arround it... :-(

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

2 Comments

Works perfectly for me with g++ and gdb on windows - I can set breakpoints and still perform console input. Looks like an XCode issue.
No, I've just tried it out of XCode, using Mac Terminal alone and I got the same result. Maybe the problem is related to the Apple DGB distribution: GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009)
-2

Programming C++ using XCode can sometimes be a pain. Try including your source code so that we can see what's wrong.

1 Comment

Perhaps this sounds like something that should have been a comment instead of an answer.

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.