2

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?

Hi-Angel
  • 4,933
  • 8
  • 63
  • 86
  • FTR, though the question still holds, but I figured out the local situation with server — it turned out to be as simple as that I had to pass its job id to `fg`. I thought it might be the same with gdb, but doesn't seem so. – Hi-Angel Apr 27 '18 at 14:43
  • Isn't /usr/bin/test a program different from /bin/test? – rostamn739 Apr 29 '18 at 08:31
  • @rostamn739 that would be weird, because both `/bin` and `/usr/bin` supposed to be in $PATH, which would result in weird conflicts. FWIW though, on my Archlinux `/bin` isn't in $PATH, but it's because here `/bin` is a symlink to `/usr/bin`. – Hi-Angel Apr 29 '18 at 20:18

0 Answers0