views:

193

answers:

2

Hi, all.

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

A: 

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

flopex
Wonder why they mark me -1.
flopex
Perhaps this sounds like something that should have been a comment instead of an answer.
clahey
A: 

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... :-(

Pasky
Works perfectly for me with g++ and gdb on windows - I can set breakpoints and still perform console input. Looks like an XCode issue.
anon
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)
Pasky