Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLion run program in separate system terminal

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?

like image 222
CS Student Avatar asked Mar 29 '16 10:03

CS Student


2 Answers

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:

  • Debugging with GDB at 33:35 (Video by JetBrain)
  • GDB documentation on Jetbrain

I hope this helped :)

like image 169
GlacierSG Avatar answered Nov 20 '22 03:11

GlacierSG


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:

  • More power to debug: Attach to local process (January 20, 2016)
  • CLion 1.2 roadmap (August 31, 2015)
  • Debugging in CLion (May 8, 2015 )
  • CLion answers frequently asked questions (September 16, 2014)
  • Debugging ncurses application with gdb
  • Using GNU's GDB Debugger: Debugging Ncurses Programs
like image 32
Thomas Dickey Avatar answered Nov 20 '22 03:11

Thomas Dickey