简体   繁体   English

无法调试eclipse helios cdt上的小程序使用windows下的mingw / gdb,控制台冻结

[英]can't debug small program on eclipse helios cdt using mingw/gdb under windows, console freezes

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. 我一直在尝试使用Eclipse CDT做一些c ++示例,我可以使用run命令运行它们,但每当我尝试调试时,控制台窗口冻结,我能够输入,但程序没有继续。

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. 15是随机数,有时是16,20等。

If I run the program under eclipse I get the input prompt just fine: 如果我在eclipse下运行程序,我得到输入提示就好了:

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: 我的路径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 Eclipse版本:Helios Service Release 2
CDT version: 7.0.2 CDT版本:7.0.2
OS: windows xp 操作系统:windows xp
GDB version: GNU gdb (GDB) 7.2 GDB版本:GNU gdb(GDB)7.2

How can I debug this small example under CDT, without issues? 如何在CDT下调试这个小例子而没有问题?

15^running looks as a result record from gdb's Machine Interface . 15^running看起来是来自gdb的机器接口的结果记录。 Normally it shouldn't appear in the Eclipse console. 通常它不应出现在Eclipse控制台中。

I recommend trying a different Create Process Launcher. 我建议尝试使用其他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". 在下面显示的打开的“调试配置”窗口中,单击“使用GDB(DSF)创建进程启动器”对话框中的“选择其他...”。

    在此输入图像描述

  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. 在下面显示的打开的“选择首选启动器”窗口中,选中“使用配置特定设置”,在下面的列表中选择“标准创建过程启动器”,然后单击“确定”。

    在此输入图像描述

  4. Now go to the Debugger tab in the "Debug Configurations" window, select debugger, eg "MinGW gdb" and click Apply. 现在转到“Debug Configurations”窗口中的Debugger选项卡,选择debugger,例如“MinGW gdb”,然后单击Apply。

    在此输入图像描述

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. 使用标准创建进程启动器,我能够调试您的程序,虽然“输入您的名字:”仅在我键入内容并按Enter后打印,因为输出流未刷新。

Try having a look at this http://www.cprogramming.com/gdbtutorial.html and see if that helps. 试着看看这个http://www.cprogramming.com/gdbtutorial.html ,看看是否有帮助。 Like can you press CTRL-C to break? 就像你可以按CTRL-C打破?

Also Cannot enter input with gdb. 无法使用gdb输入输入。 Help! 救命! might be a pointer although related to apple. 可能是指针虽然与苹果有关。

the following is from the Eclipse website's FAQ: 以下内容来自Eclipse网站的FAQ:

http://wiki.eclipse.org/CDT/User/FAQ#Eclipse_console_does_not_show_output_on_Windows 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. Eclipse控制台在Windows上不显示输出在Windows上的Eclipse CDT中,正在运行或调试的程序的标准输出是完全缓冲的,因为它没有连接到Windwos控制台,而是连接到管道。 See bug 173732 for more details. 有关更多详细信息,请参阅错误173732。 Either add fflush calls after every printf or add the following lines in the start of the main function: 在每个printf之后添加fflush调用或在main函数的开头添加以下行:

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

Seems like an expected bug on windows. 看起来像是Windows上的预期错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM