2

Help, how do i fix this? I am unable to redirect command from stdin to gdb.

I get this error:

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

2 Answers 2

2

Another technique that works nicely is to redirect input to gdb using a here-document:

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

This makes it possible to write a script which controls gdb without having to use temporary files. It seems to avoid the "Hangup detected" message completely.

0

If your goal is to execute the command "list" when gdb starts up, the easiest way to do that is to use a .gdbinit startup file. For example:

$ echo list > .gdbinig
$ gdb a.out

If you want gdb to exit after running the commands listed in .gdbinit, do:

$ echo quit >> .gdbinit
3
  • My goal is to fix the error shown above.. I'm doing some piping between my java program and gdb, and i'm stuck with it.
    – charmae
    Commented Nov 14, 2011 at 14:30
  • The problem with the example is that you are closing stdin. If you can keep the pipe open, gdb will be happy. For example, (this is a terrible hack), you could do "tail -f input-file | gdb", and then have the jave program write to input-file. Commented Nov 14, 2011 at 15:00
  • 1
    Yey! I was able to run pipes between my java program and gdb. Process p = Runtime.getRuntime().exec("gdb a.out --interpreter=console");
    – charmae
    Commented Nov 14, 2011 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.