I wrote the following C++ program in Emacs named check_emacs_debug.cpp

#include <iostream>

int main()
    for(int i = 0; i < 10; ++i) //Breakpoint
        int num;
        std::cout << "Enter a number: ";
        std::cin >> num;
        std::cout << "You entered: " << num << '\n';

    return 0;

To compile I used the command C-u M-x compile<return> followed by g++ -g check_emacs_debug.cpp -o check_emacs_debug.

To debug I used the command M-x gdb<return> followed by gdb -i=mi check_emacs_debug.exe

I have two problems while debugging

  1. The program accepts input only once while debugging. The next 9 times it ignores std::cin and shows (gdb). The line Enter a number: is printed only once.
  2. The debugger accepts input in the top-left frame named gud-check_emacs_debug.exe. It does not accept input/output from the input/output of check_emacs_debug.exe frame at the bottom right corner.

I am on Windows 10 with gdb 7.8.1 and GNU Emacs 25.1.1 (x86_64-w64-mingw32)

Any help would be appreciated.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.