User forums > Help
Debugging problem in a console application with ncurses library
Krice:
It seems like you need to add envinronment variable for (any) IDE which is TERM=xterm so I did that (Settings-environment-environment variables) and now the debugger runs, but it doesn't open a terminal window of the program, it's like the program just runs in the background somewhere (alt+tab doesn't show it either). Someone had fixed this in Eclipse by enabling "Use external console for inferior (open a new console window for input/output)". Is this possible in Code::Blocks, to open an "external" console window?
Bug Killer:
The best way I know to debug a ncurses program is to start it with gdbserver then debug it with gdb as a remote target. So, I have the ncurses program on a terminal and debuging on another.
First terminal :
--- Code: ---$ gdbserver myprogram localhost:1234
--- End code ---
Second temminal :
--- Code: ---$ gdb -tui myprogram
(gdb) target remote localhost:1234
(gdb)
--- End code ---
Krice:
It's even easier if you run gdb from the command line, but you need to copy data files etc. to where the executable file is, if it needs them (or set the working directory from gdb I guess). I can run gdb from command line and debug the program that way, I'm just wondering if it's even possible to debug ncurses programs within Code::Blocks. It has to be some kind of gdb issue, because running without gdb works. It's a mess. I don't know why TERM=xterm removes the error message when running, but doesn't show the executable's console window.
Bug Killer:
It appears that by default C::B runs a console application in a xterm terminal. If xterm is not installed the program is not displayed.
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /home/cdf24/Documents/CodeBlocks/nctest/
Adding source dir: /home/cdf24/Documents/CodeBlocks/nctest/
Adding file: /home/cdf24/Documents/CodeBlocks/nctest/bin/Debug/nctest
Changing directory to: /home/cdf24/Documents/CodeBlocks/nctest/.
Set variable: LD_LIBRARY_PATH=.:
Starting debugger: /usr/bin/gdb -nx -fullname -quiet -args /home/cdf24/Documents/CodeBlocks/nctest/bin/Debug/nctest
Setting SHELL to '/bin/sh'
done
Setting breakpoints
Failed to execute terminal command: 'xterm -T 'Program Console' -e sleep 80012477' (exit code: -1)
Debugger name and version: GNU gdb (AlmaLinux) 14.2-4.el9
At /home/cdf24/Documents/CodeBlocks/nctest/main.cpp:9
Continuing...
You can change the default terminal for gnome-terminal in the drop list.
The message "warning: GDB: Failed to set controlling terminal: Operation not permitted" can be safely ignored.
Krice:
--- Quote from: Bug Killer on June 21, 2025, 03:25:31 pm ---It appears that by default C::B runs a console application in a xterm terminal. If xterm is not installed the program is not displayed.
--- End quote ---
Not true. It runs whatever is set in the options for terminal, in Fedora it runs default gnome terminal. I have xterm installed and I'm using it because gnome terminal doesn't have correct 16 EGA colors for the project I'm programming (and I can also set it to 80x24 size which is typical for roguelikes). I think gnome terminal has less than 16 colors in fact, because some text doesn't show when running ncurses project which is using 16 colors. So, if someone has a solution for this I'm waiting, but it's not critical, because you can run your program with gdb from command line and get stack trace in case of crash etc.
Navigation
[0] Message Index
[*] Previous page
Go to full version