Bug 26116 - gdbserver with zsh as the shell hangs at startup when .zshenv forks
Summary: gdbserver with zsh as the shell hangs at startup when .zshenv forks
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: server (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-14 02:49 UTC by Simon Marchi
Modified: 2024-04-22 12:44 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Marchi 2020-06-14 02:49:04 UTC
When using zsh as the shell and a command that forks in ~/.zshenv, like `/bin/echo` here (plain `echo` is the shell builtin, which doesn't fork):

$ cat ~/.zshenv 
echo Before
/bin/echo Hello
echo After

... gdbserver hangs at startup

$ SHELL=zsh ./gdbserver localhost:9000 /bin/ls 
Before
Hello
<hangs here>

Note that when using a similar bash feature, the BASH_ENV environment variable, it doesn't hang:

$ SHELL=bash BASH_ENV=~/.zshenv ./gdbserver localhost:9000 /bin/ls 
Before
Hello
After
Process /bin/ls created; pid = 745096
Listening on port 9000

It's also possible that the issue is in zsh, but I haven't dug enough to understand what's happening exactly.
Comment 1 dajiang0055 2020-12-04 06:23:04 UTC
I had the same problem with tcsh. 
It seems that gdbserver hangs in sigsuspend() and wait for SIGTRAP.
Comment 2 ridiculous_fish 2021-05-05 02:14:01 UTC
fish shell is also seeing this - see https://github.com/fish-shell/fish-shell/issues/7957

My investigation got as far as follows: gdbserver forks in preparation for exec'ing the shell. Before exec, it requests ptrace on itself (in `linux_ptrace_fun`). This causes signals to be delivered to gdbserver before the inferior shell; however gdbserver does not then arrange for the signal to be delivered to the shell so it is dropped. fish (and presumably zsh) relies on SIGCHLD to reap processes, so fish ends up hanging.