[GDBServer] Send SIGINT using process group ID

Message ID 1463003507-13094-2-git-send-email-nchen@mozilla.com
State New, archived
Headers

Commit Message

Jim Chen May 11, 2016, 9:51 p.m. UTC
  Hi,

linux_request_interrupt is supposed to send SIGINT to the process group,
but it passes the process ID to kill() instead of the process group ID,
which may not be the same as the process ID. The patch calls getpgid
first to get the process group ID.

Patch tested on arm-linux.

gdb/gdbserver:

2016-05-11  Jim Chen  <nchen@mozilla.com>

	* linux-low.c (linux_request_interrupt): Use process group ID for
	sending SIGINT
---
 gdb/gdbserver/linux-low.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Pedro Alves May 18, 2016, 12:10 p.m. UTC | #1
On 05/11/2016 10:51 PM, Jim Chen wrote:
> Hi,
> 
> linux_request_interrupt is supposed to send SIGINT to the process group,
> but it passes the process ID to kill() instead of the process group ID,
> which may not be the same as the process ID. 
> The patch calls getpgid
> first to get the process group ID.
> 
> Patch tested on arm-linux.

Can you expand on the use case you see this happening on, please?
I can imagine some, but I'd like to hear it from you.

Some have expressed desire to _not_ send the SIGINT to the whole
process group, which may make sense when you're attached to a
process rather than having started it.  IIRC, there's a bug filed in 
bugzilla about this.

Looking at the code, not-sending-to-process-group-when-attached
is what native GNU/Linux does too (inflow.c:pass_signal).

Seems like "c&" -> "interrupt" doesn't consider "attach" either,
as inf-ptrace.c:inf_ptrace_interrupt sends the SIGINT
to the process, and like gdbserver, assumes the inferior's
PID is the process group id.

Thanks,
Pedro Alves
  
Jim Chen May 19, 2016, 4:01 p.m. UTC | #2
The use case was attaching, like you mentioned, on Android. And I just 
found PR/18945 [1], which describes the problem. I now see that my patch 
is not a good solution either because on Android, the pgid is the zygote 
process, and all running apps on the system belong to that group.

Seems like the best solution is to handle attaching separately? Or maybe 
send SIGINT to the process first, and if that fails, send it to the 
process group, in order to address the original bug of a dead main 
thread when pausing?

Thanks,
Jim

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=18945

On 5/18/2016 8:10 AM, Pedro Alves wrote:
> On 05/11/2016 10:51 PM, Jim Chen wrote:
>> Hi,
>>
>> linux_request_interrupt is supposed to send SIGINT to the process group,
>> but it passes the process ID to kill() instead of the process group ID,
>> which may not be the same as the process ID.
>> The patch calls getpgid
>> first to get the process group ID.
>>
>> Patch tested on arm-linux.
>
> Can you expand on the use case you see this happening on, please?
> I can imagine some, but I'd like to hear it from you.
>
> Some have expressed desire to _not_ send the SIGINT to the whole
> process group, which may make sense when you're attached to a
> process rather than having started it.  IIRC, there's a bug filed in
> bugzilla about this.
>
> Looking at the code, not-sending-to-process-group-when-attached
> is what native GNU/Linux does too (inflow.c:pass_signal).
>
> Seems like "c&" -> "interrupt" doesn't consider "attach" either,
> as inf-ptrace.c:inf_ptrace_interrupt sends the SIGINT
> to the process, and like gdbserver, assumes the inferior's
> PID is the process group id.
>
> Thanks,
> Pedro Alves
>
  

Patch

diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 8e1e2fc..a282ca1 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -5745,17 +5745,17 @@  linux_look_up_symbols (void)
 
 static void
 linux_request_interrupt (void)
 {
   extern unsigned long signal_pid;
 
   /* Send a SIGINT to the process group.  This acts just like the user
      typed a ^C on the controlling terminal.  */
-  kill (-signal_pid, SIGINT);
+  kill (-getpgid(signal_pid), SIGINT);
 }
 
 /* Copy LEN bytes from inferior's auxiliary vector starting at OFFSET
    to debugger memory starting at MYADDR.  */
 
 static int
 linux_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len)
 {