]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Windows gdb: Eliminate reload_context
authorPedro Alves <pedro@palves.net>
Tue, 30 Apr 2024 14:33:58 +0000 (15:33 +0100)
committerPedro Alves <pedro@palves.net>
Mon, 9 Jun 2025 17:09:12 +0000 (18:09 +0100)
We don't need reload_context, because we can get the same information
out of th->context.ContextFlags.  If ContextFlags is zero, then we
need to fetch the context out of the inferior thread.  This is what
gdbserver does too.

Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: Ied566037c81383414c46c77713bdd1aec6377b23

gdb/nat/windows-nat.h
gdb/windows-nat.c

index 902508b0aeac887dd657bb2280ef6842bd69d981..71560930e845dcc8a958c6e28f3d22c70ef5d71b 100644 (file)
@@ -90,10 +90,6 @@ struct windows_thread_info
      the thread.  */
   bool debug_registers_changed = false;
 
-  /* Nonzero if CONTEXT is invalidated and must be re-read from the
-     inferior thread.  */
-  bool reload_context = false;
-
   /* True if this thread is currently stopped at a software
      breakpoint.  This is used to offset the PC when needed.  */
   bool stopped_at_software_breakpoint = false;
index d48c9b25121b7b78a3cedd97af3fc1e8061ddddd..21835dbff154fef6aa5fa1c8e65ebcd5c397dd40 100644 (file)
@@ -100,6 +100,8 @@ struct windows_per_inferior : public windows_process_info
   void handle_unload_dll () override;
   bool handle_access_violation (const EXCEPTION_RECORD *rec) override;
 
+  void invalidate_context (windows_thread_info *th);
+
   int windows_initialization_done = 0;
 
   std::vector<std::unique_ptr<windows_thread_info>> thread_list;
@@ -520,7 +522,18 @@ windows_per_inferior::find_thread (ptid_t ptid)
   return nullptr;
 }
 
-/* See nat/windows-nat.h.  */
+/* Invalidate TH's context.  */
+
+void
+windows_per_inferior::invalidate_context (windows_thread_info *th)
+{
+#ifdef __x86_64__
+  if (windows_process.wow64_process)
+    th->wow64_context.ContextFlags = 0;
+  else
+#endif
+    th->context.ContextFlags = 0;
+}
 
 windows_thread_info *
 windows_per_inferior::thread_rec (ptid_t ptid,
@@ -535,11 +548,11 @@ windows_per_inferior::thread_rec (ptid_t ptid,
        case INVALIDATE_CONTEXT:
          if (ptid.lwp () != current_event.dwThreadId)
            th->suspend ();
-         th->reload_context = true;
+         invalidate_context (th);
          break;
        case DONT_SUSPEND:
-         th->reload_context = true;
          th->suspended = -1;
+         invalidate_context (th);
          break;
        }
     }
@@ -641,18 +654,13 @@ windows_nat_target::delete_thread (ptid_t ptid, DWORD exit_code,
    and supplies its value to the given regcache.
 
    This function assumes that R is non-negative.  A failed assertion
-   is raised if that is not true.
-
-   This function assumes that TH->RELOAD_CONTEXT is not set, meaning
-   that the windows_thread_info has an up-to-date context.  A failed
-   assertion is raised if that assumption is violated.  */
+   is raised if that is not true.  */
 
 static void
 windows_fetch_one_register (struct regcache *regcache,
                            windows_thread_info *th, int r)
 {
   gdb_assert (r >= 0);
-  gdb_assert (!th->reload_context);
 
   char *context_ptr = windows_process.with_context (th, [] (auto *context)
     {
@@ -721,16 +729,14 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r)
   if (th == NULL)
     return;
 
-  if (th->reload_context)
-    {
-      windows_process.with_context (th, [&] (auto *context)
-       {
-         context->ContextFlags = WindowsContext<decltype(context)>::all;
-         CHECK (get_thread_context (th->h, context));
-       });
-
-      th->reload_context = false;
-    }
+   windows_process.with_context (th, [&] (auto *context)
+     {
+       if (context->ContextFlags == 0)
+        {
+          context->ContextFlags = WindowsContext<decltype(context)>::all;
+          CHECK (get_thread_context (th->h, context));
+        }
+     });
 
   if (r < 0)
     for (r = 0; r < gdbarch_num_regs (regcache->arch()); r++)
@@ -1450,10 +1456,7 @@ windows_nat_target::get_windows_debug_event
       *ourstatus = stop->status;
 
       ptid_t ptid (windows_process.current_event.dwProcessId, thread_id);
-      windows_thread_info *th
-       = windows_process.thread_rec (ptid, INVALIDATE_CONTEXT);
-      th->reload_context = true;
-
+      windows_process.thread_rec (ptid, INVALIDATE_CONTEXT);
       return ptid;
     }