I ran into a problem when I tried to debug a c++ console project in Codeblocks
Debugging went fine until I included <ncurses.h> and I included the library with -lncurses
I took a code sample from another stackoverflow page if someone would want to give it a try. This code sample compiles and runs fine but when I try to debug it, it closes the console window when I execute the line: w = initscr();
#include <stdlib.h>
#include <curses.h>
//#include <locale.h>
#include <ctype.h>
#include <unistd.h>
int main( void ) {
WINDOW *w;
int c;
/* This is optional. This tells the C libraries to use user's locale settings. */
// setlocale( LC_ALL, "" );
/* Initialize curses. */
w = initscr();
if ( w == NULL ) {
fprintf( stderr, "Error initializing curses library.\n" );
return EXIT_FAILURE;
}
raw(); /* Terminal in raw mode, no buffering */
noecho(); /* Disable echoing */
//nonl(); /* Disable newline/return mapping */
keypad( w, FALSE ); /* FALSE: CSI codes, TRUE: curses codes for keys */
timeout(1);
printw( "Press Q to quit.\n" );
do {
c = getch();
if ( isprint( c ) ) {
printw( " Received character '%c' ", c );
}
usleep( 100000 );
printw( "." );
} while ( c != 'Q' );
/* Done. */
endwin();
return EXIT_SUCCESS;
}
The build log looks fine to me:
-------------- Clean: Debug in keyboard (compiler: GNU GCC Compiler)---------------
Cleaned "keyboard - Debug"
-------------- Build: Debug in keyboard (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -g -I/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -DCB_VERSION="\\\"Code::Blocks Release 20.03 rev 11997 2020-04-18, 19:47:24\\\"" -I/usr/include -c /home/data/VBOX/VBOX_DATA/CodeBlocks/keyboard/main.cpp -o obj/Debug/main.o
g++ -L/usr/lib/ -o bin/Debug/keyboard obj/Debug/main.o -L/usr/lib/x86_64-linux-gnu -pthread -lwx_gtk3u_xrc-3.0 -lwx_gtk3u_html-3.0 -lwx_gtk3u_qa-3.0 -lwx_gtk3u_adv-3.0 -lwx_gtk3u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0 -lncurses
Output file is bin/Debug/keyboard with size 23.88 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
The last lines from the debugger window:
Debugger name and version: GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 200
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor intel
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> directory /home/data/VBOX/VBOX_DATA/CodeBlocks/keyboard/
[debug]Source directories searched: /home/data/VBOX/VBOX_DATA/CodeBlocks/keyboard:$cdir:$cwd
[debug]>>>>>>cb_gdb:
[debug]> tty /dev/pts/0
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: /home/data/VBOX/VBOX_DATA/CodeBlocks/keyboard/bin/Debug/keyboard
[debug][Thread debugging using libthread_db enabled]
[debug]Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".
[debug][Inferior 1 (process 20484) exited with code 01]
[debug]>>>>>>cb_gdb:
[Inferior 1 (process 20484) exited with code 01]
[debug]> quit
Debugger finished with status 0
What could be wrong here?