简体   繁体   中英

gdb does not stop when piping the command

When running the usual way, gdb stops as expected:

(gdb) break main
(gdb) run
Starting program ...
Breakpoint 1, main ...

when running while piping, gdb never stops:

(gdb) run | cat
Starting program: /home/sds/z | cat
...
During startup program exited normally.
(gdb)

How do I debug program behavior when piping?

my setup:

$ gdb --version
GNU gdb (GDB) Amazon Linux (7.6.1-64.33.amzn1)
$ uname -a
Linux datasci-1 4.4.19-29.55.amzn1.x86_64 #1 SMP Mon Aug 29 23:29:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ gcc --version
gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9)

same problem on the most recent fully updated ubuntu (16.10).

While input and output redirection work, you cannot use pipes to pass the output of the program you are debugging to another program; if you attempt this, GDB is likely to wind up debugging the wrong program.

https://www.sourceware.org/gdb/onlinedocs/gdb.html

Based on another answer :

(gdb) run > >(cat)

See Process Substitution .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM