Author Topic: Debugging problem in a console application with ncurses library  (Read 18990 times)

bvgd

  • Guest
I have tried to compile and debug a pure-C console application using ncurses library (Linux Ubuntu 8.04 plattform).

There is no problem with BUILD and RUN commands; the application works; but I can't debug it.

When I try to start debugging, the console window is opened and I see a message "Error opening terminal: unknown" on it; the console window closes.

In Debugger logging window I see:

Building to ensure sources are up-to-date
Build succeeded
Selecting target:
Debug
Adding source dir: /home/user/CB/ncurses1/
Adding source dir: /home/user/CB/ncurses1/
Adding file: bin/Debug/ncurses1
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb 6.8-debian
At /home/user/CB/ncurses1/main.c:55
Continuing...
Program exited with code 01.
Debugger finished with status 0


Note: main.c:55 contains a first call of a ncurses-library routine:
      init_ncurses();  /* Start curses mode   */

Is it known how to debug such project with ncurses library?

Thanks!

Ubuntu 8.04
Code::Blocks 8.02, Build: Feb 27 2008, 21:58:34 - wx2.8.7 (Linux, unicode)
« Last Edit: July 21, 2008, 08:36:51 pm by bvgd »

fmel

  • Guest
Re: Debugging problem in a console application with ncurses library
« Reply #1 on: May 23, 2009, 05:17:57 am »
I'm having the same problem, but have discovered that the problem only occurs when the first ncurses call is made.  You can put some code in front of the ncurses initialization and run in debug and the terminal runs fine until you step into the ncurses init call:

main()
{
    printf("Hello\n");      // Debug will show this line
    int myvar = 1;         // You can watch this variable too
    Initscr();                 // But as soon as you step into this line, term error occurs
    .....

Anyone have any ideas?

chepaz

  • Guest
Re: Debugging problem in a console application with ncurses library
« Reply #2 on: July 20, 2010, 05:43:32 pm »
Ok, i don't expect too much from an 1 year old thread ;)

I run into exactly the same problem. I tryed different terminals but it does't work. Hopefuly pushing this thread up again would give an answer. Running my program directly in gdb works, within codeblocks... same as above.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Debugging problem in a console application with ncurses library
« Reply #3 on: July 20, 2010, 06:48:15 pm »
C::B version?
Do you have checked Project -> properties -> build targets -> Pause when executable ends?
What is the type of the project Project -> properties -> build targets -> Type?

I've done a simple test and it works fine!

Steps I've taken:
1. create console project
2. copy the code from ncurses' tutorial
3. add ncurses to the linking options
4. hit f9 run the app or f4 to run to cursor (both works)

System: gentoo linux amd64 + debugger branch...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

lamko

  • Guest
Re: Debugging problem in a console application with ncurses library
« Reply #4 on: August 06, 2011, 02:17:49 pm »
Bug is still in version 10.05.

To answer the questions :
pause when application ends is set
type is set to console application.

Someone any idee don't like gdb much, I want to get this working in code::blocks

by the way I'm using ubuntu 10.04 64 bit.

workaround :

start codeblocks from the console not from the gnome-panel
« Last Edit: August 06, 2011, 02:30:20 pm by lamko »

Offline Freem

  • Almost regular
  • **
  • Posts: 218
Re: Debugging problem in a console application with ncurses library
« Reply #5 on: August 10, 2011, 02:17:53 pm »
The versionning system of Code::Blocks is the same as Ubuntu's one:
The first number is the 2 last digits of the year, the  last one is the month's number.

All of this mean that you use a version of May 2010.
The post before you with the bug corrected is dated from July 20, 2010.

Try to use a nightly build, this problem is probably resolved there.
They are quite stable, and supported.

Look there: http://forums.codeblocks.org/index.php/topic,15023.0.html

Offline tjareson

  • Single posting newcomer
  • *
  • Posts: 5
Re: Debugging problem in a console application with ncurses library
« Reply #6 on: November 15, 2011, 05:35:20 am »
Hello,

has anybody tried, if this problem is solved in a version > 10.05 ?

I'm using 10.05 and have the same problem. Workaround helps, but the problem is more the time it takes until one gets the idea that the debugging itself causes this problem.
(drove me nuts for almost an hour...)


Cheers
Tjareson

Offline Krice

  • Almost regular
  • **
  • Posts: 173
Re: Debugging problem in a console application with ncurses library
« Reply #7 on: June 18, 2025, 01:13:50 pm »
This is a bit old topic, but still seems to be valid, because I have the same problem in Fedora. Changing terminal doesn't seem to fix it, same problem with gnome's default or xterm which I'm using for this project. Code::Blocks shows this error:

Code
Set variable: LD_LIBRARY_PATH=.:
Starting debugger: /usr/bin/gdb -nx -fullname -quiet  -args /home/krice/projects/saladir/bin/Debug/saladir
Setting SHELL to '/bin/sh'
done
Setting breakpoints
Debugger name and version: GNU gdb (Fedora Linux) 16.3-1.fc42
Error opening terminal: unknown.
[Inferior 1 (process 7216) exited with code 01]
Debugger finished with status 0

I've tried to find answers to this, but looks like no one has solved this in... about 20 years? ps. Running in normal mode works, only debugging fails.

Offline Bug Killer

  • Multiple posting newcomer
  • *
  • Posts: 25
    • Railroad modelling hardware and software
Re: Debugging problem in a console application with ncurses library
« Reply #8 on: June 18, 2025, 03:02:51 pm »
What is the value of the environment variable TERM of the terminal session ?

Offline Krice

  • Almost regular
  • **
  • Posts: 173
Re: Debugging problem in a console application with ncurses library
« Reply #9 on: June 19, 2025, 12:37:12 pm »
What is the value of the environment variable TERM of the terminal session ?

How do you check that? By the way, the problem seems to be curses, if I try a SDL2 project then debugging works. I think I read somewhere that when debugging curses programs people have to run two terminal instances, one for curses and another for gdb, but that is on command line.

Offline Krice

  • Almost regular
  • **
  • Posts: 173
Re: Debugging problem in a console application with ncurses library
« Reply #10 on: June 20, 2025, 12:38:08 pm »
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?

Offline Bug Killer

  • Multiple posting newcomer
  • *
  • Posts: 25
    • Railroad modelling hardware and software
Re: Debugging problem in a console application with ncurses library
« Reply #11 on: Yesterday at 12:25:09 pm »
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
Second temminal :

Code
$ gdb -tui myprogram
(gdb) target remote localhost:1234
(gdb)

Offline Krice

  • Almost regular
  • **
  • Posts: 173
Re: Debugging problem in a console application with ncurses library
« Reply #12 on: Yesterday at 12:48:31 pm »
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.

Offline Bug Killer

  • Multiple posting newcomer
  • *
  • Posts: 25
    • Railroad modelling hardware and software
Re: Debugging problem in a console application with ncurses library
« Reply #13 on: Yesterday at 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.

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.
« Last Edit: Yesterday at 03:39:08 pm by Bug Killer »