无法用gdb输入输入。帮帮我! [英] Cannot enter input with gdb. Help!

查看:170
本文介绍了无法用gdb输入输入。帮帮我!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用XCode或Eclipse进行gdb输入的时间一直很艰难。每当调试器点击 std :: cin 时,它看起来像在等待输入,但不能接受它。我在互联网上搜索了更多信息,但无法找到任何东西。



我需要做些什么才能让 cin 与gdb一起使用?作为参考,我使用XCode 3.2.2和Eclipse Galileo。



谢谢!

-Carlos Nunez

解决方案

我猜想GCC中存在一个与std :: cin的使用和设置/取消设置断点有关的错误。我做了一个简单的例子:

  #include< iostream> 
#include< string>
使用namespace std;

int main(int argc,char * argv [])
{
string option =x;
while(option!=q)
{
cout<< endl
<< 0 =停止<< endl
<< 1 =播放<< endl
<< q =退出<< ENDL;

getline(cin,option);
cout<< 您选择了<<选项<< ENDL;




$ b $ p
$ b

直到你设置或激活一个断点(至少使用XCode包装器)。从那时开始,stdin缓冲区被破坏,每一个getline()都会检索最后一个输入,即使你没有输入一个键,输入一个无限循环。



知道如何在周围工作......: - (


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

解决方案

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

这篇关于无法用gdb输入输入。帮帮我!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆