2

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).

sds
  • 58,617
  • 29
  • 161
  • 278
  • It seems piping output like that may not work right with gdb... what about redirecting with `>` to a fifo instead? – Dmitri Mar 03 '17 at 16:30
  • thanks, fifo work, but it still seems wrong for gdb to behave this way. is this a known bug? – sds Mar 03 '17 at 16:36

2 Answers2

0

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

vinod maverick
  • 670
  • 4
  • 14
  • could you please substantiate the claim that "GDB is likely to wind up debugging the wrong program"? – sds Mar 03 '17 at 19:40
0

Based on another answer:

(gdb) run > >(cat)

See Process Substitution.

Community
  • 1
  • 1
sds
  • 58,617
  • 29
  • 161
  • 278