diff options
author | Sergio Durigan Junior <sergiodj@redhat.com> | 2018-01-29 12:29:21 -0500 |
---|---|---|
committer | Sergio Durigan Junior <sergiodj@redhat.com> | 2018-01-29 13:04:51 -0500 |
commit | 69ab5edb4d601611ba7b4d05e56689d4b60ca3b1 (patch) | |
tree | 118cc77de2bd058f0f1e6a18bc213a0e40d67e8e | |
parent | c32b891ab6a558745a9eaa045069febd327b0db4 (diff) | |
download | gdb-69ab5edb4d601611ba7b4d05e56689d4b60ca3b1.zip gdb-69ab5edb4d601611ba7b4d05e56689d4b60ca3b1.tar.gz gdb-69ab5edb4d601611ba7b4d05e56689d4b60ca3b1.tar.bz2 |
Don't call "detach_inferior" on "remote_follow_fork"
This patch fixes a regression that has been introduced by:
commit bc09b0c14fb713a9aec25e09b78499f3bc2441b5
Date: Fri Jan 19 11:48:11 2018 -0500
Make linux_nat_detach/thread_db_detach use the inferior parameter
It is possible to trigger this failure with gdb.base/foll-fork.exp (in
which case a bunch of ERROR's will be printed), but one can also use
the test below.
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, we see a segmentation fault:
# ./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 no 'inferior' associated with it, which means that
'inf == NULL'.
The proper fix here is to not call "detach_inferior" when doing remote
follow-fork, because we don't have an inferior to detach on the host
side.
Before bc09b0c1, that call was already a nop (exit_inferior_1 bails
out early if you pass it a NULL inferior), except that it printed
"Inferior PID detached" when "set print inferior-events" is on. Since
native debugging doesn't call detach_inferior in this case, removing
the call from remote aligns remote debugging output with native
debugging output further.
This has been regtested using BuildBot and no regressions were found.
gdb/ChangeLog:
2018-01-29 Sergio Durigan Junior <sergiodj@redhat.com>
* remote.c (remote_follow_fork): Don't call "detach_inferior".
-rw-r--r-- | gdb/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/remote.c | 1 |
2 files changed, 4 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c422005..12c1874 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2018-01-29 Sergio Durigan Junior <sergiodj@redhat.com> + + * remote.c (remote_follow_fork): Don't call "detach_inferior". + 2018-01-28 Simon Marchi <simon.marchi@ericsson.com> * dwarf2read.c (free_dwo_files): Add forward-declaration. diff --git a/gdb/remote.c b/gdb/remote.c index 5ac84df..74d18f7 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -5206,7 +5206,6 @@ remote_follow_fork (struct target_ops *ops, int follow_child, child_pid = ptid_get_pid (child_ptid); remote_detach_pid (child_pid); - detach_inferior (child_pid); } } return 0; |