简体   繁体   中英

Cannot enter input in cgdb on Linux Ubuntu 14.04

Here is my very simple program that I am trying to debug with cgdb. Problem is once I get to the "scanf" line, it prompts for an input, but once I press enter after entering the input (2 in the example below) it seems to enter into an infinite loop. It works fine in gdb though.

#include <cstdio>
using namespace std;

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

Here is the execution trace in terminal:

Type "apropos word" to search for commands related to "word"... Reading symbols from test...done.

(gdb) start

Temporary breakpoint 1 at 0x400585: file test.cpp, line 7. Starting program: /home/Alex/Desktop/test

Temporary breakpoint 1, main () at test.cpp:7

(gdb) next

2 (this is my input)

Infinite loop starts here.

According to the info page of cgdb, you need to either:

  • start the program on one terminal, and attach to it with CGDB from another terminal
  • or pass arguments using the tty window

To invoke the tty window, hit 'T' in command mode (escape)

Extracted from the info page:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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