diff options
author | Sergio Durigan Junior <sergiodj@redhat.com> | 2017-08-22 08:52:44 -0400 |
---|---|---|
committer | Sergio Durigan Junior <sergiodj@redhat.com> | 2017-08-23 17:28:02 -0400 |
commit | 87215ad1651ca3094d813eae06233fd7259b37e5 (patch) | |
tree | 5209b68c0f32d118625392055949a5f1eaa621aa /gdb/testsuite/gdb.server | |
parent | aab921adcb656e4eefcc7d0f14241f3d7504400e (diff) | |
download | gdb-87215ad1651ca3094d813eae06233fd7259b37e5.zip gdb-87215ad1651ca3094d813eae06233fd7259b37e5.tar.gz gdb-87215ad1651ca3094d813eae06233fd7259b37e5.tar.bz2 |
Fix PR remote/21852: Remote run without specifying a local binary crashes GDB
There is an assertion that is triggering when we start GDB and
instruct it to debug a remote inferior, but don't provide a local
binary, like:
./gdb -nx -q --data-directory=data-directory -ex "tar ext :1234" \
-ex "set remote exec-file /bin/ls" -ex r
In this case, when calling exec_file_locate_attach to locate the
inferior, GDB is incorrectly resetting the breakpoints without a
thread/inferior even running, which causes an assertion to be
triggered:
binutils-gdb/gdb/thread.c:1609: internal-error: scoped_restore_current_thread::scoped_restore_current_thread(): Assertion `tp != NULL' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n)
This happens because add_current_inferior_and_thread (on remote.c) is
breaking an invariant: making inferior_ptid point to a non-existing
thread and then calling common code, which in this case is
breakpoint_re_set. The fix is to make sure that inferior_ptid points
to null_ptid if there is no thread present.
A testcase is provided. Regtested on buildbot.
gdb/ChangeLog:
2017-08-23 Pedro Alves <palves@redhat.com>
PR remote/21852
* remote.c (add_current_inferior_and_thread): Set inferior_ptid
to null_ptid and switch to thread without reading the registers
after adding the inferior.
gdb/testsuite/ChangeLog:
2017-08-23 Sergio Durigan Junior <sergiodj@redhat.com>
PR remote/21852
* gdb.server/normal.c: New file, copied from gdb.base.
* gdb.server/run-without-local-binary.exp: New file.
Diffstat (limited to 'gdb/testsuite/gdb.server')
-rw-r--r-- | gdb/testsuite/gdb.server/normal.c | 24 | ||||
-rw-r--r-- | gdb/testsuite/gdb.server/run-without-local-binary.exp | 62 |
2 files changed, 86 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.server/normal.c b/gdb/testsuite/gdb.server/normal.c new file mode 100644 index 0000000..f0eb154 --- /dev/null +++ b/gdb/testsuite/gdb.server/normal.c @@ -0,0 +1,24 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2013-2017 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* This test is just a normal return 0. */ + +int +main (int argc, char *argv[]) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.server/run-without-local-binary.exp b/gdb/testsuite/gdb.server/run-without-local-binary.exp new file mode 100644 index 0000000..07bb828 --- /dev/null +++ b/gdb/testsuite/gdb.server/run-without-local-binary.exp @@ -0,0 +1,62 @@ +# Copyright 2017 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +load_lib gdbserver-support.exp + +if {[skip_gdbserver_tests]} { + return +} + +standard_testfile normal.c + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +# Test running GDB without providing a local binary for it. In order +# to do that, we unset GDBFLAGS before running GDB. We also start +# gdbserver "by hand". For more details about this test, see PR +# remote/21852. +save_vars { GDBFLAGS } { + set GDBFLAGS "" + gdb_exit + gdb_start + + gdb_test_no_output "set remote exec-file $binfile" \ + "set remote exec-file" + + # Make sure we're disconnected, in case we're testing with an + # extended-remote board, therefore already connected. + gdb_test "disconnect" ".*" "disconnect" + + # Let's start gdbserver in extended-remote mode now. We cannot + # use gdbserver_start_extended here because it starts gdbserver, + # then GDB *with* a local binary, and the connect both. + set res [gdbserver_start "--multi" ""] + set gdbserver_protocol [lindex $res 0] + if { [string first "extended-" $gdbserver_protocol] != 0} { + set gdbserver_protocol "extended-$gdbserver_protocol" + } + set gdbserver_gdbport [lindex $res 1] + set use_gdb_stub 0 + + gdb_test "target ${gdbserver_protocol} ${gdbserver_gdbport}" \ + "Remote debugging using $gdbserver_gdbport" \ + "connect to gdbserver" + + gdb_test "run" \ + "\\\[Inferior $decimal \\\(process $decimal\\\) exited normally\\\]" \ + "run test program until the end" +} |