2011-11-14 31 views
2

幫助,我該如何解決這個問題?我無法將命令從stdin重定向到gdb。gdb管道重定向錯誤:(gdb)在fd上檢測到掛機0

我得到這個錯誤:

[email protected]:~/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 

回答

0

如果你的目標是執行命令「列表」時啓動gdb,做到這一點的最簡單的方法是使用一個.gdbinit啓動文件。例如:

 
$ echo list > .gdbinig 
$ gdb a.out 

如果你想用gdb退出運行在.gdbinit列出的命令後,執行:

 
$ echo quit >> .gdbinit 
+0

我的目標是修復上面顯示的錯誤..我正在做我的Java程序和gdb之間的管道,我堅持下去。 – Chinwei

+0

該示例的問題是您正在關閉stdin。如果你能保持管道暢通,gdb會很高興。例如(這是一個可怕的黑客攻擊),你可以做「tail -f input-file | gdb」,然後讓jave程序寫入輸入文件。 –

+1

Yey!我能夠在我的java程序和gdb之間運行管道。 進程p = Runtime.getRuntime()。exec(「gdb a.out --interpreter = console」); – Chinwei

2

的作品很好地是使用輸入重定向到GDB的另一項技術在此文檔:

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

這使得有可能寫控制GDB,而無需使用臨時文件的腳本。它似乎完全避免了「掛斷檢測」消息。