Debugging ncurses application with gdb

北城余情 提交于 2019-12-13 13:01:51

问题


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?


回答1:


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.




回答2:


Maybe it's a bit late to answer, but hope this helps: It took some time to figure out how to debug ncurses applications, finally i made a very comfy way with the help of gdbserver and tmux.

This way I/O of gdb and the application are completely separated:

debug.sh (the script that starts debugging):

#!/bin/bash
tmux splitw -h -p 50 "gdbserver :12345 ./yourapplication"
tmux selectp -t 0
gdb -x debug.gdb

debug.gdb (one-liner gdb scriptfile for comfort):

target remote localhost:12345

So this way, application starts up on right side, gdb on left waiting to hit continue or any other usual gdb stuff :)

Once you exit, tmux automatically closes the gdbserver (therefore right panel as well) and that's all :)



来源:https://stackoverflow.com/questions/11965328/debugging-ncurses-application-with-gdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!