I have a script that starts a server, then bunch of clients, then I need to foreground the server back, so I could test something. For some reason the server quickly quits, as if per some signal, so I wanted to inspect it with gdb.
The problem is, foregrounded gdb gets detached upon executing run
command. Here's an example in plain sh
(--nh
is for gdb to ignore config):
$ cat test.sh
#!/bin/sh -m
gdb --nh -q /bin/test &
sleep 1
fg
$ ./test.sh
Reading symbols from /bin/test...(no debugging symbols found)...done.
gdb --nh -q /bin/test
(gdb) r
Starting program: /usr/bin/test
$ ps aux | grep gdb
constan+ 11418 1.5 0.3 104928 28200 pts/1 Tl 16:52 0:00 gdb --nh -q /bin/test
constan+ 11470 0.0 0.0 12100 2452 pts/1 S+ 16:52 0:00 grep gdb
You can see, it got detached from the shell, and hangs there in list of processes.
With zsh
and bash
I'm additionally often getting the following errors:
[setting tty state failed in terminal_inferior: Input/output error]
[tcsetpgrp failed in terminal_inferior: Inappropriate ioctl for device]
…and gdb does not appear in process list. But sometimes (not very often) behavior in zsh
and bash
is the same as with sh
, i.e. there's no errors, and gdb gets detached.
All in all, what's going on with gdb?