现在的位置: 首页 > 综合 > 正文

gdb 重定向标准输出 — 调试ncurse比较有用

2013年12月10日 ⁄ 综合 ⁄ 共 1300字 ⁄ 字号 评论关闭

默认情况下,程序的标准输出在gdb窗口。 有时候这样调试会比较麻烦。

gdb提供了重定向的方法。

4.1 GDB
Start up GDB as usual in some text window. Then choose another window in which your curses application
will run, and determine the device name for that latter window (which we will call the “execution
window”). To do this, run the Unix tty command in that window. Let’s suppose for example that the output
of the command is “/dev/pts/10”. Then within GDB issue the command

(gdb) tty /dev/pts/10

We must then do one more thing before issuing the run command to GDB. Go to the execution window,
and type

sleep 10000

Unix’s sleep command has the shell go inactive for the given amount of time, in this example 10,000
seconds. This is needed so that any input we type in that window will be sure to go to our program, rather
than to the shell.

Now go back to GDB and execute run as usual. Remember, whenever your program reaches points at which
it will read from the keyboard, you will have to go to the execution window and type there (and you will see
the output from the program there too). When you are done, type ctrl-C in the execution window, so as to
kill the sleep command and make the shell usable again.

Note that if something goes wrong and your program finishes prematurely, that execution window may
retain some of the nonstandard terminal settings, e.g. cbreak mode. To fix this, go to that window and type
ctrl-j, then the word ‘reset’, then ctrl-j again.

 

对ddd来说,更方便了。

4.2 DDD
Things are much simpler in DDD. Just click on View | Execution Window, and a new window will pop up
to serve as the execution window.

抱歉!评论已关闭.