14

I have an ncurses program that I'd like to interactively debug using CLion. The problem is that when I run the program in CLion to debug it, the inbuilt console where the program is run doesn't display the output of the ncurses program properly.

I'd like to have the program run in my systems terminal so I can see the output properly whilst debugging the program with CLions debugger.

Is there any way to do this?

CS Student
  • 1,613
  • 6
  • 24
  • 40

2 Answers2

8

The best way to accomplish this is to use GDB now it can be really frustrating to get started so Ill show you how I accomplished it in linux

  1. open a terminal and go to your project debug file and type gdbserver localhost:1234 ./myFile
  2. open clion to myFile project and in the upper right corner you should see a build all (or your projects name) click it and go to "edit configurations"
  3. in the upper left corner you should see a plus sign, click it and press "GDB remote debug"
  4. then in "target remote" type tcp:127.0.0.1:1234
  5. Next in "path mappings" press the plus and type /location/to/file/myFile (same file as in 1.) in both Remote and Location
  6. Press OK and in the upper right corner select the name of the configuration that you just made and press debug

you might need to try to restart the gdbserver one more time for this to work but if you did all the steps above you should see a debug prompt come up and on the terminal you should see your project running.

There are some limitations with this for example you always have to run gdbserver localhost:1234 ./myFile command on your terminal for it to work.

Some Video/documentation that helped me:

I hope this helped :)

GlacierSG
  • 469
  • 4
  • 14
  • Is there anyway to attach the debugger to a process when it starts up? I'm having my `ncurses` project run in an xterm window at startup. – ZeroPhase Oct 10 '17 at 19:55
  • I recommend using port 2159, which is the official port for GDB remote debugging. – DBX12 Jan 02 '18 at 11:37
3

In other debuggers, you would do this by running the ncurses application in a terminal, and attaching the debugger to the process using ncurses.

Doing that avoids interference between ncurses (which changes the terminal I/O modes) and the debugger's command-line.

The attach feature is a recently released feature of the CLions debugger:

Further reading:

Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105