[Regression] Segfault on native-extended-gdbserver + fork

Message ID 8bbb4b6c-46eb-21c3-dad8-327bea8485fd@redhat.com
State New, archived
Headers

Commit Message

Pedro Alves Jan. 29, 2018, 4:58 p.m. UTC
  On 01/29/2018 04:25 PM, Simon Marchi wrote:

> It's true that it's a bit of a lie to say "[Inferior PID detached]" if there never actually was an inferior for that PID.  Since we never print "[Inferior PID detached]" on native in that case, I am fine with removing the call from remote.c.  Sergio, that would fix the crash you found I think?

A tangent:

We should probably change that message from:

 [Inferior PID detached]

to something like:

 [Inferior ID (process PID) detached]

I.e.:
 [Inferior 24822 detached]
vs:
 [Inferior 1 (process 24822) detached]

In patch form, something like this:

From 6c1db47bc19669d9c84024d09f8a63b5eb78b6c2 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 29 Jan 2018 16:41:25 +0000
Subject: [PATCH] change output

---
 gdb/inferior.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Simon Marchi Jan. 29, 2018, 5:03 p.m. UTC | #1
On 2018-01-29 11:58, Pedro Alves wrote:
> On 01/29/2018 04:25 PM, Simon Marchi wrote:
> 
>> It's true that it's a bit of a lie to say "[Inferior PID detached]" if 
>> there never actually was an inferior for that PID.  Since we never 
>> print "[Inferior PID detached]" on native in that case, I am fine with 
>> removing the call from remote.c.  Sergio, that would fix the crash you 
>> found I think?
> 
> A tangent:
> 
> We should probably change that message from:
> 
>  [Inferior PID detached]
> 
> to something like:
> 
>  [Inferior ID (process PID) detached]
> 
> I.e.:
>  [Inferior 24822 detached]
> vs:
>  [Inferior 1 (process 24822) detached]
> 
> In patch form, something like this:
> 
> From 6c1db47bc19669d9c84024d09f8a63b5eb78b6c2 Mon Sep 17 00:00:00 2001
> From: Pedro Alves <palves@redhat.com>
> Date: Mon, 29 Jan 2018 16:41:25 +0000
> Subject: [PATCH] change output
> 
> ---
>  gdb/inferior.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/inferior.c b/gdb/inferior.c
> index 38b7369275b..2986b510314 100644
> --- a/gdb/inferior.c
> +++ b/gdb/inferior.c
> @@ -234,7 +234,8 @@ exit_inferior (int pid)
>    exit_inferior_1 (inf, 0);
> 
>    if (print_inferior_events)
> -    printf_unfiltered (_("[Inferior %d exited]\n"), pid);
> +    printf_unfiltered (_("[Inferior %d (%s) exited]\n"),
> +		       inf->num, target_pid_to_str (ptid_t (pid)));
>  }
> 
>  void
> @@ -264,7 +265,8 @@ detach_inferior (inferior *inf)
>    exit_inferior_1 (inf, 0);
> 
>    if (print_inferior_events)
> -    printf_unfiltered (_("[Inferior %d detached]\n"), pid);
> +    printf_unfiltered (_("[Inferior %d (%s) detached]\n"),
> +		       inf->num, target_pid_to_str (ptid_t (pid)));
>  }
> 
>  /* See inferior.h.  */

Agreed.  Though I don't think Sergio's original patch is needed if we 
instead remove the detach_inferior call in remote.c, so your patch 
shouldn't be based on his.

Simon
  
Pedro Alves Jan. 29, 2018, 5:31 p.m. UTC | #2
On 01/29/2018 05:03 PM, Simon Marchi wrote:
> On 2018-01-29 11:58, Pedro Alves wrote:
>> On 01/29/2018 04:25 PM, Simon Marchi wrote:
>>
>>> It's true that it's a bit of a lie to say "[Inferior PID detached]" if there never actually was an inferior for that PID.  Since we never print "[Inferior PID detached]" on native in that case, I am fine with removing the call from remote.c.  Sergio, that would fix the crash you found I think?
>>
>> A tangent:
>>
>> We should probably change that message from:
>>
>>  [Inferior PID detached]
>>
>> to something like:
>>
>>  [Inferior ID (process PID) detached]
>>
>> I.e.:
>>  [Inferior 24822 detached]
>> vs:
>>  [Inferior 1 (process 24822) detached]
>>
>> In patch form, something like this:
>>

> Agreed.  Though I don't think Sergio's original patch is needed if we instead remove the detach_inferior call in remote.c, so your patch shouldn't be based on his.

Yeah, my patch was a tangent / orthogonal to his regression fix.
It was against master.  I was thinking more about the whole
effort to enable "set print inferior-events" on by default
that Sergio is working on in context of:
<https://sourceware.org/ml/gdb-patches/2018-01/msg00531.html>

Thanks,
Pedro Alves
  
Pedro Alves Jan. 29, 2018, 5:36 p.m. UTC | #3
On 01/29/2018 05:31 PM, Pedro Alves wrote:
> On 01/29/2018 05:03 PM, Simon Marchi wrote:
>> On 2018-01-29 11:58, Pedro Alves wrote:

>> Agreed.  Though I don't think Sergio's original patch is needed if we instead remove the detach_inferior call in remote.c, so your patch shouldn't be based on his.
> 
> Yeah, my patch was a tangent / orthogonal to his regression fix.
> It was against master.  I was thinking more about the whole
> effort to enable "set print inferior-events" on by default
> that Sergio is working on in context of:
> <https://sourceware.org/ml/gdb-patches/2018-01/msg00531.html>
> 

And now that I reread that url, I remember that I was actually
proposing to drop the print from within exit_inferior.  Otherwise,
we'd end up with (with both that url's patch and the patch I
just posted):

 ~~
 [Inferior 1 (process 2629) exited normally]
 [Inferior 1 (process 2629) exited]
 ~~

which is the sort of redundancy I was talking about.

Likely we'll end up doing the same to detach_inferior
too.  So I'll just forget this patch for now, as it'll
probably end up unnecessary.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/inferior.c b/gdb/inferior.c
index 38b7369275b..2986b510314 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -234,7 +234,8 @@  exit_inferior (int pid)
   exit_inferior_1 (inf, 0);
 
   if (print_inferior_events)
-    printf_unfiltered (_("[Inferior %d exited]\n"), pid);
+    printf_unfiltered (_("[Inferior %d (%s) exited]\n"),
+		       inf->num, target_pid_to_str (ptid_t (pid)));
 }
 
 void
@@ -264,7 +265,8 @@  detach_inferior (inferior *inf)
   exit_inferior_1 (inf, 0);
 
   if (print_inferior_events)
-    printf_unfiltered (_("[Inferior %d detached]\n"), pid);
+    printf_unfiltered (_("[Inferior %d (%s) detached]\n"),
+		       inf->num, target_pid_to_str (ptid_t (pid)));
 }
 
 /* See inferior.h.  */