gdb 管道重定向错误:(gdb) 在 fd 0 上检测到挂起

Posted

技术标签:

【中文标题】gdb 管道重定向错误:(gdb) 在 fd 0 上检测到挂起【英文标题】:gdb pipe redirection Error: (gdb) Hangup detected on fd 0 【发布时间】:2011-11-14 12:48:37 【问题描述】:

求助,怎么解决?我无法将命令从标准输入重定向到 gdb。

我得到这个错误:

charmae@charmae-pc:~/workspace/AVT$ echo "list" | gdb a.out
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/charmae/workspace/AVT/a.out...done.
(gdb) Hangup detected on fd 0
error detected on stdin

【问题讨论】:

【参考方案1】:

另一种效果很好的技术是使用 here-document 将输入重定向到 gdb:

gdb -quiet -nx << EndOfInput
thread apply all bt
quit
EndOfInput

这使得编写一个控制 gdb 的脚本而不必使用临时文件成为可能。它似乎完全避免了“检测到挂断”消息。

【讨论】:

【参考方案2】:

如果您的目标是在 gdb 启动时执行命令“list”,那么最简单的方法是使用 .gdbinit 启动文件。例如:

$ 回声列表 > .gdbinig $ gdb a.out

如果您希望 gdb 在运行 .gdbinit 中列出的命令后退出,请执行以下操作:

$ 回声退出 >> .gdbinit

【讨论】:

我的目标是修复上面显示的错误。我正在我的 java 程序和 gdb 之间做一些管道,但我坚持下去了。 这个例子的问题是你正在关闭标准输入。如果你能保持管道打开,gdb 会很高兴。例如,(这是一个可怕的 hack),您可以执行“tail -f input-file | gdb”,然后让 jave 程序写入输入文件。 耶!我能够在我的 java 程序和 gdb 之间运行管道。进程 p = Runtime.getRuntime().exec("gdb a.out --interpreter=console");

以上是关于gdb 管道重定向错误:(gdb) 在 fd 0 上检测到挂起的主要内容,如果未能解决你的问题,请参考以下文章

liunx 系统配置及服务管理 重定向管道

IO重定向及管道

如何使用GDB重定向到其他位置?

标准I/O重定向和管道

如何将多个输入从文件重定向到在gdb中调试的二进制文件?

标准IO重定向和管道