GDB has problems with getting commands piped to STDIN - Linux

This is a discussion on GDB has problems with getting commands piped to STDIN - Linux ; Hi, I'm trying to pipe commands to gdb but I get the following messages: Hangup detected on fd 0 error detected on stdin I should add that the piping is happening from a PHP script (don't ask . I used ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: GDB has problems with getting commands piped to STDIN

  1. GDB has problems with getting commands piped to STDIN

    Hi,

    I'm trying to pipe commands to gdb but I get the following messages:

    Hangup detected on fd 0
    error detected on stdin

    I should add that the piping is happening from a PHP script (don't
    ask . I used open_proc to spawn a gdb process and then fwrite /
    fgets to send commands and read the output they cause gdb to produce.

    To make sure this is not a PHP problem I already tested the following:

    1. I have been flushing to ensure the command reaches gdb.
    2. I also closed the pipe before to read the output gdb should have
    produced (for those familiar with using bash from a php script).
    3. I also added sleep commands for up to 3 seconds to make sure there
    would be any problem of timing.
    4. I finally successfully tested using proc_open for a bash process
    and sending / reading commands the same way

    Also of interest, when on my command line, a simple
    gdb xxx << EOF
    bt
    EOF

    shows that the pipe is working for gdb.

    After a lot of searches on newsgroup, it seems that gdb has / used to
    have a problem reading piped commands even in the shell.

    Can someone point in a direction to investigate, I'm really running
    out of possibilities.

    Thanks!


  2. Re: GDB has problems with getting commands piped to STDIN

    > I'm trying to pipe commands to gdb ...

    gdb is unreasonable unless stdin is a tty or pty.
    A plain pipe does not work well, as you discovered.

    If the gdb commandline arguments -x and/or -batch
    are not sufficient, then probably you must use a pty.

    --

  3. Re: GDB has problems with getting commands piped to STDIN

    On 2007-04-22, John Reiser wrote:
    [...]
    > If the gdb commandline arguments -x and/or -batch
    > are not sufficient, then probably you must use a pty.
    >


    I'm using gdb -batch -x /dev/stdin to start the gdb from within
    my process, and it works fine.


    --
    Minds, like parachutes, function best when open

  4. Re: GDB has problems with getting commands piped to STDIN

    Thanks to both, turns out the -batch and -x /dev/stdin options do not
    change a thing even when testing on a bash command line

    echo "bt" | gdb --batch -x /dev/stdin
    -bash: echo: write error: Broken pipe

    I'm looking into compiling gdb with the following patch
    http://sourceware.org/ml/gdb-patches.../msg00106.html
    but now my compilation fails because, after a ./configure and a make,
    "no termcap library found"
    /etc/termcap is there and I'm using a fedora core 6 system. A quick
    search through the Makefile and configure.in didn't show any TERMCAP
    or termcap entries I could tinker with...

    still looking


    On Apr 24, 4:27 am, Andrei Voropaev wrote:
    > On 2007-04-22, John Reiser wrote:
    > [...]
    >
    > > If the gdb commandline arguments -x and/or -batch
    > > are not sufficient, then probably you must use a pty.

    >
    > I'm using gdb -batch -x /dev/stdin to start the gdb from within
    > my process, and it works fine.
    >
    > --
    > Minds, like parachutes, function best when open




  5. Re: GDB has problems with getting commands piped to STDIN

    Thanks to both

    I think my previous reply got lost so here we go again

    the above-mentioned options do not work (I tested on a bash fc6 shell)

    echo "bt" | gdb - batch -x /dev/stdin

    I'm working on recompiling gdb with a patch
    http://sourceware.org/ml/gdb-patches.../msg00106.html

    however, after a ./configure and a make I am now dealing with a "no
    termcap library found"
    Of course, /etc/termcap is there and my tinkering with the
    configure.in and Makefile didn't lead me to find any spot where I
    could be inserting this information by hand


    still working on it

    On Apr 24, 4:27 am, Andrei Voropaev wrote:
    > On 2007-04-22, John Reiser wrote:
    > [...]
    >
    > > If the gdb commandline arguments -x and/or -batch
    > > are not sufficient, then probably you must use a pty.

    >
    > I'm using gdb -batch -x /dev/stdin to start the gdb from within
    > my process, and it works fine.
    >
    > --
    > Minds, like parachutes, function best when open




  6. Re: GDB has problems with getting commands piped to STDIN

    > Thanks to both, turns out the -batch and -x /dev/stdin options do not
    > change a thing even when testing on a bash command line
    >
    > echo "bt" | gdb --batch -x /dev/stdin
    > -bash: echo: write error: Broken pipe


    Are two minus signs (" --batch ") the same as one (" -batch ")?

    You did not specify an executable or a core file:
    $ echo "bt" | gdb -batch -x /dev/stdin foo core.11665
    (no debugging symbols found)
    Using host libthread_db library "/lib/libthread_db.so.1".
    (no debugging symbols found)
    Core was generated by `./foo'.
    Program terminated with signal 11, Segmentation fault.

    warning: svr4_current_sos: Can't read pathname for load map: Input/output error

    (no debugging symbols found)
    (no debugging symbols found)
    #0 0x08048369 in main ()
    #0 0x08048369 in main ()

    $ echo "bt" | gdb -batch -x /dev/stdin
    No stack.

    $ gdb --version
    GNU gdb Red Hat Linux (6.3.0.0-1.84rh)

    --

  7. Re: GDB has problems with getting commands piped to STDIN

    ok couple of things to answer your questions up front;
    1. yes, I used -batch in one word (question through email) without
    space between the - and bash
    2. I also tried --batch
    3. I was just trying to get a message from gdb so I used bt without
    even loading a process image

    Now for the fun part:

    # echo "file prog" | gdb -batch -x /dev/stdin
    -bash: echo: write error: Broken pipe
    # echo "file prog" | gdb -batch -x /dev/stdin
    # echo "file prog" | gdb -batch -x /dev/stdin
    # echo "file prog" | gdb -batch -x /dev/stdin
    -bash: echo: write error: Broken pipe

    so this is a timing issue with the piping??? weird

    Just FYI here's my version
    # gdb --version
    GNU gdb Red Hat Linux (6.5-15.fc6rh)



    On Apr 25, 11:37 pm, John Reiser wrote:
    > > Thanks to both, turns out the -batch and -x /dev/stdin options do not
    > > change a thing even when testing on a bash command line

    >
    > > echo "bt" | gdb --batch -x /dev/stdin
    > > -bash: echo: write error: Broken pipe

    >
    > Are two minus signs (" --batch ") the same as one (" -batch ")?
    >
    > You did not specify an executable or a core file:
    > $ echo "bt" | gdb -batch -x /dev/stdin foo core.11665
    > (no debugging symbols found)
    > Using host libthread_db library "/lib/libthread_db.so.1".
    > (no debugging symbols found)
    > Core was generated by `./foo'.
    > Program terminated with signal 11, Segmentation fault.
    >
    > warning: svr4_current_sos: Can't read pathname for load map: Input/output error
    >
    > (no debugging symbols found)
    > (no debugging symbols found)
    > #0 0x08048369 in main ()
    > #0 0x08048369 in main ()
    >
    > $ echo "bt" | gdb -batch -x /dev/stdin
    > No stack.
    >
    > $ gdb --version
    > GNU gdb Red Hat Linux (6.3.0.0-1.84rh)
    >
    > --




+ Reply to Thread