c++ - 无法在 Linux Ubuntu 14.04 上的 cgdb 中输入输入

标签 c++ cgdb

这是我尝试使用 cgdb 调试的非常简单的程序。问题是一旦我到达“scanf”行,它会提示输入,但是一旦我输入输入后按回车键(下例中的 2),它似乎进入了无限循环。它在 gdb 中运行良好。

#include <cstdio>
using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    printf("%d\n", n);
    return 0;
}

这是终端中的执行轨迹:

键入“apropos word”以搜索与“word”相关的命令... 从测试中读取符号...完成。

(gdb) 开始

0x400585 处的临时断点 1:文件 test.cpp,第 7 行。 启动程序:/home/Alex/Desktop/test

临时断点1,main() at test.cpp:7

(gdb) 下一个

2(这是我的输入)

无限循环从这里开始。

最佳答案

根据cgdb的info page,你需要:

  • 在一个终端上启动程序,并从另一个终端使用 CGDB 附加到它
  • 或使用 tty 窗口传递参数

要调用 tty 窗口,请在命令模式下按“T”(转义)

摘自信息页:

Sending I/O to the program being debugged

This technique is similar to getting in and out of "GDB mode". The tty window is not visible by default. This is because it is only needed if the user wishes to send data to the program being debugged. To display the tty window, hit `T' while in command mode.

关于c++ - 无法在 Linux Ubuntu 14.04 上的 cgdb 中输入输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32707278/

相关文章:

c++ - 对std::vector的emplace_back感到困惑

c++ - 分解 D3DXMatrixLookAtLH 矩阵

linux - 如何使 "next"在 cgdb 中工作

colors - 如何在带有TUI或CGDB的GDB中使用颜色?

c++ - 访问 Google Test 参数化测试用例 (`TEST_P` 中的测试信息)

c++ - 如何删除在函数中创建的动态数组

C++ 变量模板。这是UB?

gdb - 执行当前行而不继续

gdb - 在GDB中执行行

c++ - 使用 cgdb 调试——只想调试我的代码