aboutsummaryrefslogtreecommitdiff
path: root/gdbserver
diff options
context:
space:
mode:
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2021-12-13 12:22:48 +0100
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>2021-12-13 12:22:48 +0100
commit24583e45efc823c1a9ea009dfddc36f9b74dcbcd (patch)
treeac00cde441192c880eee0f36a7e4346e0ba53c58 /gdbserver
parentf24791b72e764ada576901c0e866bf7768773a16 (diff)
downloadgdb-24583e45efc823c1a9ea009dfddc36f9b74dcbcd.zip
gdb-24583e45efc823c1a9ea009dfddc36f9b74dcbcd.tar.gz
gdb-24583e45efc823c1a9ea009dfddc36f9b74dcbcd.tar.bz2
gdbserver: replace direct assignments to current_thread
Replace the direct assignments to current_thread with switch_to_thread. Use scoped_restore_current_thread when appropriate. There is one instance remaining in linux-low.cc's wait_for_sigstop. This will be handled in a separate patch. Regression-tested on X86-64 Linux using the native-gdbserver and native-extended-gdbserver board files.
Diffstat (limited to 'gdbserver')
-rw-r--r--gdbserver/inferiors.cc10
-rw-r--r--gdbserver/linux-low.cc113
-rw-r--r--gdbserver/linux-x86-low.cc6
-rw-r--r--gdbserver/mem-break.cc15
-rw-r--r--gdbserver/netbsd-low.cc2
-rw-r--r--gdbserver/proc-service.cc7
-rw-r--r--gdbserver/regcache.cc10
-rw-r--r--gdbserver/remote-utils.cc5
-rw-r--r--gdbserver/server.cc13
-rw-r--r--gdbserver/target.cc4
-rw-r--r--gdbserver/thread-db.cc14
-rw-r--r--gdbserver/tracepoint.cc8
-rw-r--r--gdbserver/win32-low.cc6
13 files changed, 77 insertions, 136 deletions
diff --git a/gdbserver/inferiors.cc b/gdbserver/inferiors.cc
index d44e40a..b6cf100 100644
--- a/gdbserver/inferiors.cc
+++ b/gdbserver/inferiors.cc
@@ -41,7 +41,7 @@ add_thread (ptid_t thread_id, void *target_data)
all_threads.push_back (new_thread);
if (current_thread == NULL)
- current_thread = new_thread;
+ switch_to_thread (new_thread);
return new_thread;
}
@@ -99,7 +99,7 @@ remove_thread (struct thread_info *thread)
discard_queued_stop_replies (ptid_of (thread));
all_threads.remove (thread);
if (current_thread == thread)
- current_thread = NULL;
+ switch_to_thread (nullptr);
free_one_thread (thread);
}
@@ -129,7 +129,7 @@ clear_inferiors (void)
clear_dlls ();
- current_thread = NULL;
+ switch_to_thread (nullptr);
}
struct process_info *
@@ -215,7 +215,7 @@ void
switch_to_thread (process_stratum_target *ops, ptid_t ptid)
{
gdb_assert (ptid != minus_one_ptid);
- current_thread = find_thread_ptid (ptid);
+ switch_to_thread (find_thread_ptid (ptid));
}
/* See gdbthread.h. */
@@ -233,7 +233,7 @@ switch_to_process (process_info *proc)
{
int pid = pid_of (proc);
- current_thread = find_any_thread_of_pid (pid);
+ switch_to_thread (find_any_thread_of_pid (pid));
}
/* See gdbsupport/common-inferior.h. */
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index 8788804..373bacb 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -430,14 +430,10 @@ linux_process_target::low_new_fork (process_info *parent, process_info *child)
void
linux_process_target::arch_setup_thread (thread_info *thread)
{
- struct thread_info *saved_thread;
-
- saved_thread = current_thread;
- current_thread = thread;
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (thread);
low_arch_setup ();
-
- current_thread = saved_thread;
}
int
@@ -672,7 +668,7 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
/* Delete the execing process and all its threads. */
mourn (proc);
- current_thread = NULL;
+ switch_to_thread (nullptr);
/* Create a new process/lwp/thread. */
proc = add_linux_process (event_pid, 0);
@@ -712,15 +708,14 @@ linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
CORE_ADDR
linux_process_target::get_pc (lwp_info *lwp)
{
- struct thread_info *saved_thread;
struct regcache *regcache;
CORE_ADDR pc;
if (!low_supports_breakpoints ())
return 0;
- saved_thread = current_thread;
- current_thread = get_lwp_thread (lwp);
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (get_lwp_thread (lwp));
regcache = get_thread_regcache (current_thread, 1);
pc = low_get_pc (regcache);
@@ -728,26 +723,22 @@ linux_process_target::get_pc (lwp_info *lwp)
if (debug_threads)
debug_printf ("pc is 0x%lx\n", (long) pc);
- current_thread = saved_thread;
return pc;
}
void
linux_process_target::get_syscall_trapinfo (lwp_info *lwp, int *sysno)
{
- struct thread_info *saved_thread;
struct regcache *regcache;
- saved_thread = current_thread;
- current_thread = get_lwp_thread (lwp);
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (get_lwp_thread (lwp));
regcache = get_thread_regcache (current_thread, 1);
low_get_syscall_trapinfo (regcache, sysno);
if (debug_threads)
debug_printf ("get_syscall_trapinfo sysno %d\n", *sysno);
-
- current_thread = saved_thread;
}
void
@@ -762,7 +753,6 @@ linux_process_target::save_stop_reason (lwp_info *lwp)
{
CORE_ADDR pc;
CORE_ADDR sw_breakpoint_pc;
- struct thread_info *saved_thread;
#if USE_SIGTRAP_SIGINFO
siginfo_t siginfo;
#endif
@@ -774,8 +764,8 @@ linux_process_target::save_stop_reason (lwp_info *lwp)
sw_breakpoint_pc = pc - low_decr_pc_after_break ();
/* breakpoint_at reads from the current thread. */
- saved_thread = current_thread;
- current_thread = get_lwp_thread (lwp);
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (get_lwp_thread (lwp));
#if USE_SIGTRAP_SIGINFO
if (ptrace (PTRACE_GETSIGINFO, lwpid_of (current_thread),
@@ -888,7 +878,6 @@ linux_process_target::save_stop_reason (lwp_info *lwp)
}
lwp->stop_pc = pc;
- current_thread = saved_thread;
return true;
}
@@ -1644,7 +1633,6 @@ linux_process_target::thread_still_has_status_pending (thread_info *thread)
&& (lp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT
|| lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT))
{
- struct thread_info *saved_thread;
CORE_ADDR pc;
int discard = 0;
@@ -1652,8 +1640,8 @@ linux_process_target::thread_still_has_status_pending (thread_info *thread)
pc = get_pc (lp);
- saved_thread = current_thread;
- current_thread = thread;
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (thread);
if (pc != lp->stop_pc)
{
@@ -1682,8 +1670,6 @@ linux_process_target::thread_still_has_status_pending (thread_info *thread)
}
#endif
- current_thread = saved_thread;
-
if (discard)
{
if (debug_threads)
@@ -1971,10 +1957,8 @@ linux_process_target::low_get_thread_area (int lwpid, CORE_ADDR *addrp)
bool
linux_process_target::maybe_move_out_of_jump_pad (lwp_info *lwp, int *wstat)
{
- struct thread_info *saved_thread;
-
- saved_thread = current_thread;
- current_thread = get_lwp_thread (lwp);
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (get_lwp_thread (lwp));
if ((wstat == NULL
|| (WIFSTOPPED (*wstat) && WSTOPSIG (*wstat) != SIGTRAP))
@@ -2015,7 +1999,6 @@ linux_process_target::maybe_move_out_of_jump_pad (lwp_info *lwp, int *wstat)
debug_printf ("Checking whether LWP %ld needs to move out of "
"the jump pad...it does\n",
lwpid_of (current_thread));
- current_thread = saved_thread;
return true;
}
@@ -2088,7 +2071,6 @@ linux_process_target::maybe_move_out_of_jump_pad (lwp_info *lwp, int *wstat)
"jump pad...no\n",
lwpid_of (current_thread));
- current_thread = saved_thread;
return false;
}
@@ -2179,8 +2161,8 @@ dequeue_one_deferred_signal (struct lwp_info *lwp, int *wstat)
bool
linux_process_target::check_stopped_by_watchpoint (lwp_info *child)
{
- struct thread_info *saved_thread = current_thread;
- current_thread = get_lwp_thread (child);
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (get_lwp_thread (child));
if (low_stopped_by_watchpoint ())
{
@@ -2188,8 +2170,6 @@ linux_process_target::check_stopped_by_watchpoint (lwp_info *child)
child->stopped_data_address = low_stopped_data_address ();
}
- current_thread = saved_thread;
-
return child->stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
}
@@ -2269,7 +2249,7 @@ linux_process_target::filter_event (int lwpid, int wstat)
child_ptid = ptid_t (lwpid, lwpid);
child = add_lwp (child_ptid);
child->stopped = 1;
- current_thread = child->thread;
+ switch_to_thread (child->thread);
}
/* If we didn't find a process, one of two things presumably happened:
@@ -2548,7 +2528,7 @@ linux_process_target::wait_for_event_filtered (ptid_t wait_ptid,
*wstatp = event_child->status_pending;
event_child->status_pending_p = 0;
event_child->status_pending = 0;
- current_thread = event_thread;
+ switch_to_thread (event_thread);
return lwpid_of (event_thread);
}
@@ -2676,7 +2656,7 @@ linux_process_target::wait_for_event_filtered (ptid_t wait_ptid,
gdb_sigmask (SIG_SETMASK, &prev_mask, NULL);
- current_thread = event_thread;
+ switch_to_thread (event_thread);
return lwpid_of (event_thread);
}
@@ -2807,7 +2787,7 @@ linux_process_target::stabilize_threads ()
return;
}
- thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
stabilizing_threads = 1;
@@ -2849,8 +2829,6 @@ linux_process_target::stabilize_threads ()
stabilizing_threads = 0;
- current_thread = saved_thread;
-
if (debug_threads)
{
thread_stuck = find_thread ([this] (thread_info *thread)
@@ -3560,7 +3538,7 @@ linux_process_target::wait_1 (ptid_t ptid, target_waitstatus *ourstatus,
select_event_lwp (&event_child);
/* current_thread and event_child must stay in sync. */
- current_thread = get_lwp_thread (event_child);
+ switch_to_thread (get_lwp_thread (event_child));
event_child->status_pending_p = 0;
w = event_child->status_pending;
@@ -3897,7 +3875,6 @@ linux_process_target::stuck_in_jump_pad (thread_info *thread)
void
linux_process_target::move_out_of_jump_pad (thread_info *thread)
{
- struct thread_info *saved_thread;
struct lwp_info *lwp = get_thread_lwp (thread);
int *wstat;
@@ -3910,8 +3887,8 @@ linux_process_target::move_out_of_jump_pad (thread_info *thread)
gdb_assert (lwp->stopped);
/* For gdb_breakpoint_here. */
- saved_thread = current_thread;
- current_thread = thread;
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (thread);
wstat = lwp->status_pending_p ? &lwp->status_pending : NULL;
@@ -3940,8 +3917,6 @@ linux_process_target::move_out_of_jump_pad (thread_info *thread)
}
else
lwp_suspended_inc (lwp);
-
- current_thread = saved_thread;
}
static bool
@@ -4017,9 +3992,9 @@ linux_process_target::install_software_single_step_breakpoints (lwp_info *lwp)
struct thread_info *thread = get_lwp_thread (lwp);
struct regcache *regcache = get_thread_regcache (thread, 1);
- scoped_restore save_current_thread = make_scoped_restore (&current_thread);
+ scoped_restore_current_thread restore_thread;
- current_thread = thread;
+ switch_to_thread (thread);
std::vector<CORE_ADDR> next_pcs = low_get_next_pcs (regcache);
for (CORE_ADDR pc : next_pcs)
@@ -4067,7 +4042,6 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step,
int signal, siginfo_t *info)
{
struct thread_info *thread = get_lwp_thread (lwp);
- struct thread_info *saved_thread;
int ptrace_request;
struct process_info *proc = get_thread_process (thread);
@@ -4123,8 +4097,8 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step,
return;
}
- saved_thread = current_thread;
- current_thread = thread;
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (thread);
/* This bit needs some thinking about. If we get a signal that
we must report while a single-step reinsert is still pending,
@@ -4248,7 +4222,6 @@ linux_process_target::resume_one_lwp_throw (lwp_info *lwp, int step,
of coercing an 8 byte integer to a 4 byte pointer. */
(PTRACE_TYPE_ARG4) (uintptr_t) signal);
- current_thread = saved_thread;
if (errno)
perror_with_name ("resuming thread");
@@ -4445,7 +4418,6 @@ bool
linux_process_target::thread_needs_step_over (thread_info *thread)
{
struct lwp_info *lwp = get_thread_lwp (thread);
- struct thread_info *saved_thread;
CORE_ADDR pc;
struct process_info *proc = get_thread_process (thread);
@@ -4526,8 +4498,8 @@ linux_process_target::thread_needs_step_over (thread_info *thread)
return false;
}
- saved_thread = current_thread;
- current_thread = thread;
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (thread);
/* We can only step over breakpoints we know about. */
if (breakpoint_here (pc) || fast_tracepoint_jump_here (pc))
@@ -4544,7 +4516,6 @@ linux_process_target::thread_needs_step_over (thread_info *thread)
" GDB breakpoint at 0x%s; skipping step over\n",
lwpid_of (thread), paddress (pc));
- current_thread = saved_thread;
return false;
}
else
@@ -4556,14 +4527,10 @@ linux_process_target::thread_needs_step_over (thread_info *thread)
/* We've found an lwp that needs stepping over --- return 1 so
that find_thread stops looking. */
- current_thread = saved_thread;
-
return true;
}
}
- current_thread = saved_thread;
-
if (debug_threads)
debug_printf ("Need step over [LWP %ld]? No, no breakpoint found"
" at 0x%s\n",
@@ -4576,9 +4543,7 @@ void
linux_process_target::start_step_over (lwp_info *lwp)
{
struct thread_info *thread = get_lwp_thread (lwp);
- struct thread_info *saved_thread;
CORE_ADDR pc;
- int step;
if (debug_threads)
debug_printf ("Starting step-over on LWP %ld. Stopping all threads\n",
@@ -4602,16 +4567,17 @@ linux_process_target::start_step_over (lwp_info *lwp)
shouldn't care about. */
pc = get_pc (lwp);
- saved_thread = current_thread;
- current_thread = thread;
-
- lwp->bp_reinsert = pc;
- uninsert_breakpoints_at (pc);
- uninsert_fast_tracepoint_jumps_at (pc);
+ bool step = false;
+ {
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (thread);
- step = single_step (lwp);
+ lwp->bp_reinsert = pc;
+ uninsert_breakpoints_at (pc);
+ uninsert_fast_tracepoint_jumps_at (pc);
- current_thread = saved_thread;
+ step = single_step (lwp);
+ }
resume_one_lwp (lwp, step, 0, NULL);
@@ -4624,12 +4590,12 @@ linux_process_target::finish_step_over (lwp_info *lwp)
{
if (lwp->bp_reinsert != 0)
{
- struct thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
if (debug_threads)
debug_printf ("Finished step over.\n");
- current_thread = get_lwp_thread (lwp);
+ switch_to_thread (get_lwp_thread (lwp));
/* Reinsert any breakpoint at LWP->BP_REINSERT. Note that there
may be no breakpoint to reinsert there by now. */
@@ -4650,7 +4616,6 @@ linux_process_target::finish_step_over (lwp_info *lwp)
}
step_over_bkpt = null_ptid;
- current_thread = saved_thread;
return true;
}
else
diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc
index 58ca4ba..4955bd3 100644
--- a/gdbserver/linux-x86-low.cc
+++ b/gdbserver/linux-x86-low.cc
@@ -991,7 +991,7 @@ x86_linux_read_description (void)
void
x86_target::update_xmltarget ()
{
- struct thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
/* Before changing the register cache's internal layout, flush the
contents of the current valid caches back to the threads, and
@@ -1002,12 +1002,10 @@ x86_target::update_xmltarget ()
int pid = proc->pid;
/* Look up any thread of this process. */
- current_thread = find_any_thread_of_pid (pid);
+ switch_to_thread (find_any_thread_of_pid (pid));
low_arch_setup ();
});
-
- current_thread = saved_thread;
}
/* Process qSupported query, "xmlRegisters=". Update the buffer size for
diff --git a/gdbserver/mem-break.cc b/gdbserver/mem-break.cc
index 8f2688e..406594c 100644
--- a/gdbserver/mem-break.cc
+++ b/gdbserver/mem-break.cc
@@ -1501,13 +1501,12 @@ delete_single_step_breakpoints (struct thread_info *thread)
if (bp->type == single_step_breakpoint
&& ((struct single_step_breakpoint *) bp)->ptid == ptid_of (thread))
{
- struct thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
- current_thread = thread;
+ switch_to_thread (thread);
*bp_link = bp->next;
release_breakpoint (proc, bp);
bp = *bp_link;
- current_thread = saved_thread;
}
else
{
@@ -1603,11 +1602,10 @@ uninsert_single_step_breakpoints (struct thread_info *thread)
reinsert breakpoint. */
if (bp->raw->refcount == 1)
{
- struct thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
- current_thread = thread;
+ switch_to_thread (thread);
uninsert_raw_breakpoint (bp->raw);
- current_thread = saved_thread;
}
}
}
@@ -1709,11 +1707,10 @@ reinsert_single_step_breakpoints (struct thread_info *thread)
if (bp->raw->refcount == 1)
{
- struct thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
- current_thread = thread;
+ switch_to_thread (thread);
reinsert_raw_breakpoint (bp->raw);
- current_thread = saved_thread;
}
}
}
diff --git a/gdbserver/netbsd-low.cc b/gdbserver/netbsd-low.cc
index ada92c1..3c9dadd 100644
--- a/gdbserver/netbsd-low.cc
+++ b/gdbserver/netbsd-low.cc
@@ -310,7 +310,7 @@ netbsd_wait (ptid_t ptid, struct target_waitstatus *ourstatus,
}
if (find_thread_ptid (ptid_t (pid)))
- current_thread = find_thread_ptid (wptid);
+ switch_to_thread (find_thread_ptid (wptid));
if (code == TRAP_LWP && pst.pe_report_event == PTRACE_LWP_CREATE)
{
diff --git a/gdbserver/proc-service.cc b/gdbserver/proc-service.cc
index 4724151..8f3f77f 100644
--- a/gdbserver/proc-service.cc
+++ b/gdbserver/proc-service.cc
@@ -105,20 +105,17 @@ ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
{
#ifdef HAVE_REGSETS
struct lwp_info *lwp;
- struct thread_info *reg_thread, *saved_thread;
struct regcache *regcache;
lwp = find_lwp_pid (ptid_t (lwpid));
if (lwp == NULL)
return PS_ERR;
- reg_thread = get_lwp_thread (lwp);
- saved_thread = current_thread;
- current_thread = reg_thread;
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (get_lwp_thread (lwp));
regcache = get_thread_regcache (current_thread, 1);
gregset_info ()->fill_function (regcache, gregset);
- current_thread = saved_thread;
return PS_OK;
#else
return PS_ERR;
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 312f14e..304be0d 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -49,14 +49,13 @@ get_thread_regcache (struct thread_info *thread, int fetch)
if (fetch && regcache->registers_valid == 0)
{
- struct thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
- current_thread = thread;
+ switch_to_thread (thread);
/* Invalidate all registers, to prevent stale left-overs. */
memset (regcache->register_status, REG_UNAVAILABLE,
regcache->tdesc->reg_defs.size ());
fetch_inferior_registers (regcache, -1);
- current_thread = saved_thread;
regcache->registers_valid = 1;
}
@@ -83,11 +82,10 @@ regcache_invalidate_thread (struct thread_info *thread)
if (regcache->registers_valid)
{
- struct thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
- current_thread = thread;
+ switch_to_thread (thread);
store_inferior_registers (regcache, -1);
- current_thread = saved_thread;
}
regcache->registers_valid = 0;
diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index 8202365..ae1a85f 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -1099,7 +1099,6 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
case TARGET_WAITKIND_SYSCALL_ENTRY:
case TARGET_WAITKIND_SYSCALL_RETURN:
{
- struct thread_info *saved_thread;
const char **regp;
struct regcache *regcache;
@@ -1182,7 +1181,7 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
buf += strlen (buf);
- saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
switch_to_thread (the_target, ptid);
@@ -1273,8 +1272,6 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status)
buf += strlen (buf);
current_process ()->dlls_changed = false;
}
-
- current_thread = saved_thread;
}
break;
case TARGET_WAITKIND_EXITED:
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 27e2aba..54ca95e 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1294,7 +1294,7 @@ handle_detach (char *own_buf)
cs.last_status.set_exited (0);
cs.last_ptid = ptid_t (pid);
- current_thread = NULL;
+ switch_to_thread (nullptr);
}
else
{
@@ -1722,8 +1722,7 @@ handle_qxfer_threads_proper (struct buffer *buffer)
{
client_state &cs = get_client_state ();
- scoped_restore save_current_thread
- = make_scoped_restore (&current_thread);
+ scoped_restore_current_thread restore_thread;
scoped_restore save_current_general_thread
= make_scoped_restore (&cs.general_thread);
@@ -2258,7 +2257,7 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
if (strcmp ("qSymbol::", own_buf) == 0)
{
- struct thread_info *save_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
/* For qSymbol, GDB only changes the current thread if the
previous current thread was of a different process. So if
@@ -2267,15 +2266,15 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
exec in a non-leader thread. */
if (current_thread == NULL)
{
- current_thread
+ thread_info *any_thread
= find_any_thread_of_pid (cs.general_thread.pid ());
+ switch_to_thread (any_thread);
/* Just in case, if we didn't find a thread, then bail out
instead of crashing. */
if (current_thread == NULL)
{
write_enn (own_buf);
- current_thread = save_thread;
return;
}
}
@@ -2298,8 +2297,6 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
if (current_thread != NULL)
the_target->look_up_symbols ();
- current_thread = save_thread;
-
strcpy (own_buf, "OK");
return;
}
diff --git a/gdbserver/target.cc b/gdbserver/target.cc
index aa3d424..bfafb7c 100644
--- a/gdbserver/target.cc
+++ b/gdbserver/target.cc
@@ -35,7 +35,7 @@ set_desired_thread ()
client_state &cs = get_client_state ();
thread_info *found = find_thread_ptid (cs.general_thread);
- current_thread = found;
+ switch_to_thread (found);
return (current_thread != NULL);
}
@@ -101,7 +101,7 @@ prepare_to_access_memory (void)
return 1;
}
- current_thread = thread;
+ switch_to_thread (thread);
cs.general_thread = ptid_of (thread);
return 0;
diff --git a/gdbserver/thread-db.cc b/gdbserver/thread-db.cc
index 9a70cdf..01e8357 100644
--- a/gdbserver/thread-db.cc
+++ b/gdbserver/thread-db.cc
@@ -388,7 +388,6 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
psaddr_t addr;
td_err_e err;
struct lwp_info *lwp;
- struct thread_info *saved_thread;
struct process_info *proc;
struct thread_db *thread_db;
@@ -411,8 +410,8 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
if (!lwp->thread_known)
return TD_NOTHR;
- saved_thread = current_thread;
- current_thread = thread;
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (thread);
if (load_module != 0)
{
@@ -435,7 +434,6 @@ thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset,
addr = (char *) addr + offset;
}
- current_thread = saved_thread;
if (err == TD_OK)
{
*address = (CORE_ADDR) (uintptr_t) addr;
@@ -788,7 +786,7 @@ disable_thread_event_reporting (struct process_info *proc)
if (td_ta_clear_event_p != NULL)
{
- struct thread_info *saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
td_thr_events_t events;
switch_to_process (proc);
@@ -797,8 +795,6 @@ disable_thread_event_reporting (struct process_info *proc)
in any events anymore. */
td_event_fillset (&events);
(*td_ta_clear_event_p) (thread_db->thread_agent, &events);
-
- current_thread = saved_thread;
}
}
}
@@ -894,8 +890,8 @@ thread_db_notice_clone (struct thread_info *parent_thr, ptid_t child_ptid)
/* find_one_thread calls into libthread_db which accesses memory via
the current thread. Temporarily switch to a thread we know is
stopped. */
- scoped_restore restore_current_thread
- = make_scoped_restore (&current_thread, parent_thr);
+ scoped_restore_current_thread restore_thread;
+ switch_to_thread (parent_thr);
if (!find_one_thread (child_ptid))
warning ("Cannot find thread after clone.");
diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
index c01973b..f176ab2 100644
--- a/gdbserver/tracepoint.cc
+++ b/gdbserver/tracepoint.cc
@@ -3975,18 +3975,14 @@ gdb_agent_about_to_close (int pid)
if (!maybe_write_ipa_not_loaded (buf))
{
- struct thread_info *saved_thread;
-
- saved_thread = current_thread;
+ scoped_restore_current_thread restore_thread;
/* Find any thread which belongs to process PID. */
- current_thread = find_any_thread_of_pid (pid);
+ switch_to_thread (find_any_thread_of_pid (pid));
strcpy (buf, "close");
run_inferior_command (buf, strlen (buf) + 1);
-
- current_thread = saved_thread;
}
}
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index cc981d3..6f6fcef 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -1102,7 +1102,7 @@ get_child_debug_event (DWORD *continue_status,
*ourstatus = stop->status;
current_event = stop->event;
ptid = debug_event_ptid (&current_event);
- current_thread = find_thread_ptid (ptid);
+ switch_to_thread (find_thread_ptid (ptid));
return 1;
}
@@ -1152,7 +1152,7 @@ get_child_debug_event (DWORD *continue_status,
child_delete_thread (current_event.dwProcessId,
current_event.dwThreadId);
- current_thread = get_first_thread ();
+ switch_to_thread (get_first_thread ());
return 1;
case CREATE_PROCESS_DEBUG_EVENT:
@@ -1264,7 +1264,7 @@ get_child_debug_event (DWORD *continue_status,
ourstatus->set_spurious ();
}
else
- current_thread = find_thread_ptid (ptid);
+ switch_to_thread (find_thread_ptid (ptid));
return 1;
}