Bug 26575 - When remotely debugging process that forks, interrupt(ctrl-c) is always sent to group process
Summary: When remotely debugging process that forks, interrupt(ctrl-c) is always sent ...
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: remote (show other bugs)
Version: unknown
: P2 critical
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-04 06:55 UTC by Matic Kres
Modified: 2020-09-04 06:55 UTC (History)
0 users

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 Matic Kres 2020-09-04 06:55:18 UTC
My setup goes like this:
1. I run my application, let's call it app "Parent" with pid 2052
2. This app then forks, let's call this child app "Child" with pid 2053
3. I start gdb server like so: gdbserver localhost:1234 --attach 2052   (attach to app "Parent")
4. On some other machiene I connect to gdb server like so: target remote xxx.xxx.xxx.xxx:1234
5. I send command "c" to start the "Parent" application
6. I press "ctrl-c" to stop the application -> now "Parent" application stops, but "Child" application recieves SIGINT which causes it to exit.

I have create strace recording on gdbserver and saw that interrupt sends:
"kill(-2052, SIGINT) = 0"
command which causes that Interrupt is sent to group instead of process I am attached to.

I have also tried connecting to "Child" application:
1. same
2. same
3. gdbserver localhost:1234 --attach 2053
4. same
5. I send command "c" to start the "Child" application
6. I press "ctrl-c" to stop the application -> neither "Child" or "Parent" application recieves SIGINT signal, "Child" application stays in running

From strace recording we can see that interrupt was sent to group process that does not exist(pid of child application):
"kill(-2053, SIGINT) = -1 ESRCH (No such process)"

Most likely this is the point of failure:
https://github.com/bminor/binutils-gdb/blob/master/gdbserver/linux-low.cc#L5717
As we can see interrupt is always send to the group process(because of "-").

Interesting fact is that this issue only occurs when I am connected to GDB remotely, I assume that when I connect directly to gdb(not gdbserver) this code is called upon interrupt:
https://github.com/bminor/binutils-gdb/blob/master/gdb/inflow.c#L590

My thoughts:
What I would expect is that interrupt should be sent only the process that I am debugging, regardless of it's group.