Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging ncurses application with gdb

Tags:

c

input

gdb

ncurses

I'm trying to debug my ncurses application, using gdb. I use tty command to redirect program's I/O to another terminal. Output works like a charm, but I'm having problems with input. I'm using getch() function to retrieve symbols in my app. So, for instance, if I do in my gdb session:

tty /dev/pts/5

I get my output in another tab of my terminal window (gnome-terminal). My gdb sessions is getting stuck, waiting for input, but when I press any key within my /dev/pts/5 I get it printed out, but the app itself does not except it as an input symbol. When running without gdb everything works fine, I'm also using noecho(), so symbols should not be displayed. So, what's the problem? Is it possible to somehow handle input from redirected terminal?

like image 781
Xentatt Avatar asked Aug 15 '12 07:08

Xentatt


1 Answers

You can attach to your process to debug from a different terminal instead of trying to run the application from within gdb.

Run your process as normal. When it is blocked for user input, find its process ID, and then attach to it with gdb from a different window:

gdb -p <PID>

Your problem is due to the program still expecting its interactive input to be coming from your gdb session.

like image 85
jxh Avatar answered Sep 30 '22 04:09

jxh