gdb

gdb attach to an argument passed by a pipe failed


I can use

gdb attach 45432

to debug a process. However, when I use

echo 45432 |xargs gdb attach

the gdb attached successfully, but then print

(gdb) quit
A debugging session is active.
Inferior 1 [process 45432] will be detached.

Actually I use ps -ef with some greps to get that 45432. So how can I deal with the problem?


Solution

  • Looks like you need to run xargs with --open-tty option. This worked for me:

    echo 45432 | xargs --open-tty gdb -p
    

    See man xargs:

       -o, --open-tty
              Reopen stdin as /dev/tty in the child process before exe‐
              cuting the command.  This is useful if you want xargs to
              run an interactive application.