binutils-gdb/gdb/testsuite/gdb.server
Sergio Durigan Junior 87215ad165 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.
2017-08-23 17:28:02 -04:00
..
connect-stopped-target.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
connect-stopped-target.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
connect-with-no-symbol-file.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
connect-with-no-symbol-file.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
connect-without-multi-process.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
connect-without-multi-process.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ext-attach.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ext-attach.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ext-restart.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ext-run.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
ext-wrapper.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
file-transfer.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
no-thread-db.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
no-thread-db.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
non-existing-program.exp Share fork_inferior et al with gdbserver 2017-06-07 19:56:09 -04:00
normal.c Fix PR remote/21852: Remote run without specifying a local binary crashes GDB 2017-08-23 17:28:02 -04:00
run-without-local-binary.exp Fix PR remote/21852: Remote run without specifying a local binary crashes GDB 2017-08-23 17:28:02 -04:00
server-exec-info.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
server-kill.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
server-kill.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
server-mon.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
server-run.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
server.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
solib-list-lib.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
solib-list-main.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
solib-list.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
transfer.txt
unittest.exp GDBserver self tests 2017-08-18 09:20:43 +01:00
wrapper.c update copyright year range in GDB files 2017-01-01 10:52:34 +04:00
wrapper.exp update copyright year range in GDB files 2017-01-01 10:52:34 +04:00