From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org, Simon Marchi <simon.marchi@ericsson.com>
Subject: [Regression] Segfault on native-extended-gdbserver + fork (was: Re: [PATCH v2 3/3] Make linux_nat_detach/thread_db_detach use the inferior parameter)
Date: Sun, 28 Jan 2018 06:32:00 -0000 [thread overview]
Message-ID: <87efmaebo3.fsf_-_@redhat.com> (raw)
In-Reply-To: <20180119161628.21611-3-simon.marchi@polymtl.ca> (Simon Marchi's message of "Fri, 19 Jan 2018 11:16:28 -0500")
On Friday, January 19 2018, Simon Marchi wrote:
> From: Simon Marchi <simon.marchi@ericsson.com>
>
> No changes in v2.
>
> This patch makes these two functions actually use the inferior parameter
> added by the previous patch, instead of reading inferior_ptid. I chose
> these two, because they are the one actually used when I detach on my
> GNU/Linux system, so they were easy to test.
>
> I took the opportunity to pass the inferior being detached to
> inf_ptrace_detach_success, so it could use it too. From there, it made
> sense to add an overload of detach_inferior that takes the inferior
> directly rather than the pid, to avoid having to pass inf->pid only for
> the callee to look up the inferior structure by pid.
Hey Simon,
While working on something else, I noticed a regression introduced by
this patch. Consider the following example program:
#include <unistd.h>
int
main (int argc, char *argv[])
{
fork ();
return 0;
}
When running it under gdbserver:
# ./gdb/gdbserver/gdbserver --multi --once :2345
And debugging it under GDB:
# ./gdb/gdb -q -batch -ex 'set remote exec-file ./a.out' -ex 'tar extended-remote :2345' -ex r ./a.out
Starting program:
...
[Detaching after fork from child process 16102.]
Segmentation fault (core dumped)
The problem happens on inferior.c:detach_inferior:
void
detach_inferior (inferior *inf)
{
/* Save the pid, since exit_inferior_1 will reset it. */
int pid = inf->pid;
^^^^^^^^^
exit_inferior_1 (inf, 0);
if (print_inferior_events)
printf_unfiltered (_("[Inferior %d detached]\n"), pid);
}
When this code is called from remote.c:remote_follow_fork, the PID is
valid but there is not 'inferior' associated with it, which means that
'inf == NULL'.
I've been thinking about the proper fix to this, and arrived at the
patch attached (without a ChangeLog entry; will add that if the patch
seems OK for you). Since we will still want to print inferior events
even if 'inf == NULL', I've duplicated the print on the "detach_inferior
(int pid)" version. Other than that, the patch is basically restoring
the old behaviour of just skipping the detach procedure if there's no
inferior object.
I'm running a regression test on BuildBot to make sure no regressions
are introduced. I was going to write a testcase to exercise this
scenario, but we already have one, gdb.base/foll-vfork.exp. The
failures were marked as ERROR's by dejagnu, which may explain why they
were missed...? Not sure. Oh, and this regression is not present in
the 8.1 branch.
WDYT?
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 38b7369275..94432a92b1 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -272,7 +272,15 @@ detach_inferior (inferior *inf)
void
detach_inferior (int pid)
{
- detach_inferior (find_inferior_pid (pid));
+ inferior *inf = find_inferior_pid (pid);
+
+ if (inf != NULL)
+ detach_inferior (inf);
+ else
+ {
+ if (print_inferior_events)
+ printf_unfiltered (_("[Inferior %d detached]\n"), pid);
+ }
}
void
next prev parent reply other threads:[~2018-01-28 6:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-19 16:16 [PATCH v2 1/3] Remove args from target detach Simon Marchi
2018-01-19 16:16 ` [PATCH v2 2/3] Pass inferior down to target_detach and to_detach Simon Marchi
2018-01-19 16:16 ` [PATCH v2 3/3] Make linux_nat_detach/thread_db_detach use the inferior parameter Simon Marchi
2018-01-28 6:32 ` Sergio Durigan Junior [this message]
2018-01-28 16:50 ` [Regression] Segfault on native-extended-gdbserver + fork Simon Marchi
2018-01-29 16:01 ` Pedro Alves
2018-01-29 16:25 ` Simon Marchi
2018-01-29 16:58 ` Pedro Alves
2018-01-29 17:04 ` Simon Marchi
2018-01-29 17:31 ` Pedro Alves
2018-01-29 17:36 ` Pedro Alves
[not found] ` <87mv0w8tnr.fsf@redhat.com>
2018-01-29 17:36 ` Sergio Durigan Junior
2018-01-29 17:47 ` Pedro Alves
2018-01-29 18:06 ` Sergio Durigan Junior
2018-01-19 16:35 ` [PATCH v2 1/3] Remove args from target detach Pedro Alves
2018-01-19 16:57 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87efmaebo3.fsf_-_@redhat.com \
--to=sergiodj@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@ericsson.com \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox