aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@redhat.com>2017-08-22 08:52:44 -0400
committerSergio Durigan Junior <sergiodj@redhat.com>2017-08-23 17:28:02 -0400
commit87215ad1651ca3094d813eae06233fd7259b37e5 (patch)
tree5209b68c0f32d118625392055949a5f1eaa621aa /gdb/remote.c
parentaab921adcb656e4eefcc7d0f14241f3d7504400e (diff)
downloadgdb-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/remote.c')
-rw-r--r--gdb/remote.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index ff59a0f..2249533 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -3831,19 +3831,16 @@ add_current_inferior_and_thread (char *wait_status)
{
struct remote_state *rs = get_remote_state ();
int fake_pid_p = 0;
- ptid_t ptid;
inferior_ptid = null_ptid;
/* Now, if we have thread information, update inferior_ptid. */
- ptid = get_current_thread (wait_status);
+ ptid_t curr_ptid = get_current_thread (wait_status);
- if (!ptid_equal (ptid, null_ptid))
+ if (curr_ptid != null_ptid)
{
if (!remote_multi_process_p (rs))
fake_pid_p = 1;
-
- inferior_ptid = ptid;
}
else
{
@@ -3851,14 +3848,17 @@ add_current_inferior_and_thread (char *wait_status)
(such as kill) won't work. This variable serves (at least)
double duty as both the pid of the target process (if it has
such), and as a flag indicating that a target is active. */
- inferior_ptid = magic_null_ptid;
+ curr_ptid = magic_null_ptid;
fake_pid_p = 1;
}
- remote_add_inferior (fake_pid_p, ptid_get_pid (inferior_ptid), -1, 1);
+ remote_add_inferior (fake_pid_p, ptid_get_pid (curr_ptid), -1, 1);
- /* Add the main thread. */
- add_thread_silent (inferior_ptid);
+ /* Add the main thread and switch to it. Don't try reading
+ registers yet, since we haven't fetched the target description
+ yet. */
+ thread_info *tp = add_thread_silent (curr_ptid);
+ switch_to_thread_no_regs (tp);
}
/* Print info about a thread that was found already stopped on