diff options
author | Pedro Alves <pedro@palves.net> | 2023-05-08 21:36:28 +0100 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2024-05-08 00:39:55 +0100 |
commit | c151e663fad2297d1cf21ce4e4143dc5a3eb0f96 (patch) | |
tree | dadd9b181c6628f30e0a3da2937de90cd6ec84e1 | |
parent | 78ef7c48d1d0c8199cb55e8c6f6a3e6ff09ee59f (diff) | |
download | binutils-c151e663fad2297d1cf21ce4e4143dc5a3eb0f96.zip binutils-c151e663fad2297d1cf21ce4e4143dc5a3eb0f96.tar.gz binutils-c151e663fad2297d1cf21ce4e4143dc5a3eb0f96.tar.bz2 |
Windows gdb+gdbserver: Eliminate thread_rec(INVALIDATE_CONTEXT) calls
Replace thread_rec(INVALIDATE_CONTEXT) calls with find_thread, and
invalidate_context / suspend calls in the spots that might need those.
I don't know why does the INVALIDATE_CONTEXT implementation in GDB
avoid suspending the event thread:
case INVALIDATE_CONTEXT:
if (ptid.lwp () != current_event.dwThreadId)
th->suspend ();
Checks for a global "current_event" get in the way of non-stop support
later in the series, as each thread will have its own "last debug
event". Regardless, it should be fine to suspend the event thread.
As a data point, the GDBserver implementation always suspends. So
this patch does not try to avoid suspending the event thread on the
native side either.
Change-Id: I8d2f0a749d23329956e62362a7007189902dddb5
-rw-r--r-- | gdb/nat/windows-nat.h | 2 | ||||
-rw-r--r-- | gdb/windows-nat.c | 38 | ||||
-rw-r--r-- | gdbserver/win32-low.cc | 8 |
3 files changed, 26 insertions, 22 deletions
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 41921aa..0e2093e 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -103,8 +103,6 @@ enum thread_disposition_type { /* Invalidate the context, but do not suspend the thread. */ DONT_SUSPEND, - /* Invalidate the context and suspend the thread. */ - INVALIDATE_CONTEXT }; /* A single pending stop. See "pending_stops" for more diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 3888ab6..f53a45f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -547,11 +547,6 @@ windows_per_inferior::thread_rec { switch (disposition) { - case INVALIDATE_CONTEXT: - if (ptid.lwp () != current_event.dwThreadId) - th->suspend (); - invalidate_context (th); - break; case DONT_SUSPEND: th->suspended = -1; invalidate_context (th); @@ -724,8 +719,7 @@ windows_fetch_one_register (struct regcache *regcache, void windows_nat_target::fetch_registers (struct regcache *regcache, int r) { - windows_thread_info *th - = windows_process.thread_rec (regcache->ptid (), INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (regcache->ptid ()); /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -737,6 +731,7 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r) { if (th->wow64_context.ContextFlags == 0) { + th->suspend (); th->wow64_context.ContextFlags = CONTEXT_DEBUGGER_DR; CHECK (Wow64GetThreadContext (th->h, &th->wow64_context)); } @@ -746,6 +741,7 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r) { if (th->context.ContextFlags == 0) { + th->suspend (); th->context.ContextFlags = CONTEXT_DEBUGGER_DR; CHECK (GetThreadContext (th->h, &th->context)); } @@ -770,11 +766,23 @@ windows_store_one_register (const struct regcache *regcache, { gdb_assert (r >= 0); - char *context_ptr = (char *) &th->context; + DWORD context_flags; + char *context_ptr; + #ifdef __x86_64__ if (windows_process.wow64_process) - context_ptr = (char *) &th->wow64_context; + { + context_flags = th->wow64_context.ContextFlags; + context_ptr = (char *) &th->wow64_context; + } + else #endif + { + context_flags = th->context.ContextFlags; + context_ptr = (char *) &th->context; + } + + gdb_assert (context_flags != 0); struct gdbarch *gdbarch = regcache->arch (); i386_gdbarch_tdep *tdep = gdbarch_tdep<i386_gdbarch_tdep> (gdbarch); @@ -807,8 +815,7 @@ windows_store_one_register (const struct regcache *regcache, void windows_nat_target::store_registers (struct regcache *regcache, int r) { - windows_thread_info *th - = windows_process.thread_rec (regcache->ptid (), INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (regcache->ptid ()); /* Check if TH exists. Windows sometimes uses a non-existent thread id in its events. */ @@ -1544,7 +1551,8 @@ windows_nat_target::get_windows_debug_event *ourstatus = stop->status; ptid_t ptid (windows_process.current_event.dwProcessId, thread_id); - windows_process.thread_rec (ptid, INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (ptid); + windows_process.invalidate_context (th); return ptid; } @@ -1765,8 +1773,7 @@ windows_nat_target::get_windows_debug_event && windows_process.windows_initialization_done) { ptid_t ptid = ptid_t (current_event->dwProcessId, thread_id, 0); - windows_thread_info *th - = windows_process.thread_rec (ptid, INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (ptid); th->stopped_at_software_breakpoint = true; th->pc_adjusted = false; } @@ -1804,8 +1811,7 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, if (ourstatus->kind () != TARGET_WAITKIND_EXITED && ourstatus->kind () != TARGET_WAITKIND_SIGNALLED) { - windows_thread_info *th - = windows_process.thread_rec (result, INVALIDATE_CONTEXT); + windows_thread_info *th = windows_process.find_thread (result); if (th != nullptr) { diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index 5d3ad38..b693da5 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -463,8 +463,8 @@ child_fetch_inferior_registers (struct regcache *regcache, int r) { int regno; windows_thread_info *th - = windows_process.thread_rec (current_thread_ptid (), - INVALIDATE_CONTEXT); + = windows_process.find_thread (current_thread_ptid ()); + win32_require_context (th); if (r == -1 || r > NUM_REGS) child_fetch_inferior_registers (regcache, NUM_REGS); else @@ -479,8 +479,8 @@ child_store_inferior_registers (struct regcache *regcache, int r) { int regno; windows_thread_info *th - = windows_process.thread_rec (current_thread_ptid (), - INVALIDATE_CONTEXT); + = windows_process.find_thread (current_thread_ptid ()); + win32_require_context (th); if (r == -1 || r == 0 || r > NUM_REGS) child_store_inferior_registers (regcache, NUM_REGS); else |