]> 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>
Fri, 24 Apr 2026 20:28:44 +0000 (21:28 +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/aarch64-windows-nat.c
gdb/nat/windows-nat.h
gdb/windows-nat.c
gdb/windows-nat.h
gdb/x86-windows-nat.c

index 4ae2c758f157fa35303d5b0433d86a5784e7f093..c375bbf2ddd9f36dc2b0c95bded5a1420f5d200d 100644 (file)
@@ -29,6 +29,8 @@ using namespace windows_nat;
 struct aarch64_windows_per_inferior : public windows_per_inferior
 {
   aarch64_debug_reg_state dr_state;
+
+  void invalidate_thread_context (windows_thread_info *th) override;
 };
 
 struct aarch64_windows_nat_target final
@@ -181,8 +183,20 @@ aarch64_windows_nat_target::fill_thread_context (windows_thread_info *th)
 {
   CONTEXT *context = &th->context;
 
-  context->ContextFlags = WindowsContext<decltype(context)>::all;
-  CHECK (get_thread_context (th->h, context));
+  if (context->ContextFlags == 0)
+    {
+      context->ContextFlags = WindowsContext<decltype(context)>::all;
+      CHECK (get_thread_context (th->h, context));
+    }
+}
+
+/* See windows-nat.h.  */
+
+void
+aarch64_windows_per_inferior::invalidate_thread_context (windows_thread_info *th)
+{
+  CONTEXT *context = &th->context;
+  context->ContextFlags = 0;
 }
 
 /* See windows-nat.h.  */
index 97c8c6cc43d4cefc3ef5ae6bd43398a48e319b0e..24ef6cc3f9c6bee2ac466de7dda7bac3c35eae42 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 ff23791e5a844ef1b5e7a8614062829ccc91689a..e8df5e053e624f0701ddfd494db4b4b3de7870a6 100644 (file)
@@ -287,11 +287,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_thread_context (th);
          break;
        case DONT_SUSPEND:
-         th->reload_context = true;
          th->suspended = -1;
+         invalidate_thread_context (th);
          break;
        }
     }
@@ -400,12 +400,7 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r)
   if (th == NULL)
     return;
 
-  if (th->reload_context)
-    {
-      fill_thread_context (th);
-
-      th->reload_context = false;
-    }
+  fill_thread_context (th);
 
   if (r < 0)
     for (r = 0; r < gdbarch_num_regs (regcache->arch()); r++)
@@ -938,10 +933,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;
     }
 
index a686c5b667940b7d2728ff17502bbb0417ee8f31..aa90dfd37d3165112881fe32b863a576ebb6fb5c 100644 (file)
@@ -55,6 +55,9 @@ struct windows_per_inferior : public windows_nat::windows_process_info
   void handle_unload_dll () override;
   bool handle_access_violation (const EXCEPTION_RECORD *rec) override;
 
+  /* Invalidate the thread context.  */
+  virtual void invalidate_thread_context (windows_thread_info *th) = 0;
+
   int windows_initialization_done = 0;
 
   std::vector<std::unique_ptr<windows_thread_info>> thread_list;
index 5a82a2e0e362784820f233c906d7d21297559b51..d76b89b186a97789e9f24aa445b7a0af91400b24 100644 (file)
@@ -47,6 +47,8 @@ struct x86_windows_per_inferior : public windows_per_inferior
   /* The function to use in order to determine whether a register is
      a segment register or not.  */
   segment_register_p_ftype *segment_register_p = nullptr;
+
+  void invalidate_thread_context (windows_thread_info *th) override;
 };
 
 struct x86_windows_nat_target final : public x86_nat_target<windows_nat_target>
@@ -107,8 +109,22 @@ x86_windows_nat_target::fill_thread_context (windows_thread_info *th)
 {
   x86_windows_process.with_context (th, [&] (auto *context)
     {
-      context->ContextFlags = WindowsContext<decltype(context)>::all;
-      CHECK (get_thread_context (th->h, context));
+      if (context->ContextFlags == 0)
+       {
+         context->ContextFlags = WindowsContext<decltype(context)>::all;
+         CHECK (get_thread_context (th->h, context));
+       }
+    });
+}
+
+/* See nat/windows-nat.h.  */
+
+void
+x86_windows_per_inferior::invalidate_thread_context (windows_thread_info *th)
+{
+  x86_windows_process.with_context (th, [&] (auto *context)
+    {
+      context->ContextFlags = 0;
     });
 }
 
@@ -170,7 +186,6 @@ x86_windows_nat_target::fetch_one_register (struct regcache *regcache,
                                            windows_thread_info *th, int r)
 {
   gdb_assert (r >= 0);
-  gdb_assert (!th->reload_context);
 
   char *context_ptr = x86_windows_process.with_context (th, [] (auto *context)
     {