Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [pushed 03/28] Windows gdb: Eliminate reload_context
Date: Fri, 24 Apr 2026 21:44:43 +0100	[thread overview]
Message-ID: <20260424204508.1343973-4-pedro@palves.net> (raw)
In-Reply-To: <20260424204508.1343973-1-pedro@palves.net>

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 | 18 ++++++++++++++++--
 gdb/nat/windows-nat.h     |  4 ----
 gdb/windows-nat.c         | 16 ++++------------
 gdb/windows-nat.h         |  3 +++
 gdb/x86-windows-nat.c     | 21 ++++++++++++++++++---
 5 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/gdb/aarch64-windows-nat.c b/gdb/aarch64-windows-nat.c
index 4ae2c758f15..c375bbf2ddd 100644
--- a/gdb/aarch64-windows-nat.c
+++ b/gdb/aarch64-windows-nat.c
@@ -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.  */
diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h
index 97c8c6cc43d..24ef6cc3f9c 100644
--- a/gdb/nat/windows-nat.h
+++ b/gdb/nat/windows-nat.h
@@ -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;
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index ff23791e5a8..e8df5e053e6 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -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;
     }
 
diff --git a/gdb/windows-nat.h b/gdb/windows-nat.h
index a686c5b6679..aa90dfd37d3 100644
--- a/gdb/windows-nat.h
+++ b/gdb/windows-nat.h
@@ -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;
diff --git a/gdb/x86-windows-nat.c b/gdb/x86-windows-nat.c
index 5a82a2e0e36..d76b89b186a 100644
--- a/gdb/x86-windows-nat.c
+++ b/gdb/x86-windows-nat.c
@@ -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)
     {
-- 
2.53.0


  parent reply	other threads:[~2026-04-24 20:46 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24 20:44 [pushed 00/28] Windows non-stop prep Pedro Alves
2026-04-24 20:44 ` [pushed 01/28] Windows gdb+gdbserver: New find_thread, replaces thread_rec(DONT_INVALIDATE_CONTEXT) Pedro Alves
2026-04-24 20:44 ` [pushed 02/28] Windows gdb: handle_output_debug_string return type Pedro Alves
2026-04-24 20:44 ` Pedro Alves [this message]
2026-04-24 20:44 ` [pushed 04/28] Windows gdb+gdbserver: Eliminate thread_rec(INVALIDATE_CONTEXT) calls Pedro Alves
2026-04-24 20:44 ` [pushed 05/28] Windows gdb+gdbserver: Eliminate DONT_SUSPEND Pedro Alves
2026-04-24 20:44 ` [pushed 06/28] Windows gdb+gdbserver: Eliminate windows_process_info::thread_rec Pedro Alves
2026-04-24 20:44 ` [pushed 07/28] Windows gdb: Simplify windows_nat_target::wait Pedro Alves
2026-04-26 12:52   ` Hannes Domani
2026-04-27 12:09     ` [pushed/ob] Restore windows_nat_target::wait is_sw_breakpoint change Pedro Alves
2026-04-24 20:44 ` [pushed 08/28] Windows gdb+gdbserver: Move suspending thread to when returning event Pedro Alves
2026-04-24 20:44 ` [pushed 09/28] Windows gdb: Introduce continue_last_debug_event_main_thread Pedro Alves
2026-04-24 20:44 ` [pushed 10/28] Windows gdb: Introduce windows_continue_flags Pedro Alves
2026-04-24 20:44 ` [pushed 11/28] Windows gdb: Factor code out of windows_nat_target::windows_continue Pedro Alves
2026-04-24 20:44 ` [pushed 12/28] Windows gdb: Pending stop and current_event Pedro Alves
2026-04-24 20:44 ` [pushed 13/28] Windows gdb+gdbserver: Elim desired_stop_thread_id / rework pending_stops Pedro Alves
2026-04-24 20:44 ` [pushed 14/28] Windows gdb+gdbserver: Introduce get_last_debug_event_ptid Pedro Alves
2026-04-24 20:44 ` [pushed 15/28] Windows gdb: Can't pass signal to thread other than last stopped thread Pedro Alves
2026-04-24 20:44 ` [pushed 16/28] Windows gdbserver: Fix scheduler-locking Pedro Alves
2026-04-24 20:44 ` [pushed 17/28] Windows gdb: Enable "set scheduler-locking on" Pedro Alves
2026-04-27 12:57   ` [pushed] Mention Windows scheduler-locking in NEWS (Re: [pushed 17/28] Windows gdb: Enable "set scheduler-locking on") Pedro Alves
2026-04-24 20:44 ` [pushed 18/28] Windows gdbserver: Eliminate soft-interrupt mechanism Pedro Alves
2026-04-24 20:44 ` [pushed 19/28] Windows gdb+gdbserver: Make current_event per-thread state Pedro Alves
2026-04-24 20:45 ` [pushed 20/28] Windows gdb+gdbserver: Make last_sig " Pedro Alves
2026-04-24 20:45 ` [pushed 21/28] Windows gdb+gdbserver: Make siginfo_er " Pedro Alves
2026-04-24 20:45 ` [pushed 22/28] Add backpointer from windows_thread_info to windows_process_info Pedro Alves
2026-04-24 20:45 ` [pushed 23/28] Windows gdb+gdbserver: Share $_siginfo reading code Pedro Alves
2026-04-24 20:45 ` [pushed 24/28] Windows gdb+gdbserver: Eliminate struct pending_stop Pedro Alves
2026-04-24 20:45 ` [pushed 25/28] Windows gdb: Change serial_event management Pedro Alves
2026-04-24 20:45 ` [pushed 26/28] Windows gdb: cygwin_set_dr => windows_set_dr, etc Pedro Alves
2026-04-24 20:45 ` [pushed 27/28] Windows gdb: Move debug macros to windows-nat.h Pedro Alves
2026-04-24 20:45 ` [pushed 28/28] Windows gdb: Avoid writing debug registers if watchpoint hit pending Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260424204508.1343973-4-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox