From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id weKBDb/W62kyVDkAWB0awg (envelope-from ) for ; Fri, 24 Apr 2026 16:46:55 -0400 Received: by simark.ca (Postfix, from userid 112) id 2EF7F1E0BA; Fri, 24 Apr 2026 16:46:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 45A101E093 for ; Fri, 24 Apr 2026 16:46:54 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D97254BB24D2 for ; Fri, 24 Apr 2026 20:46:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D97254BB24D2 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by sourceware.org (Postfix) with ESMTPS id 4C4104B920F5 for ; Fri, 24 Apr 2026 20:45:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C4104B920F5 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4C4104B920F5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777063519; cv=none; b=QJWqSRdUhhB4aWjmfNEQJGxxhzcIDzkKQ7IAxH6Mqga0Q3AjoHLOiUJ7X9bSMJdhCe3BtmTjWyZsIJpMZgp+OECQwWSW9yVqPTR3Fs5niM3C9QyZRIGcQHkX5c9w9c6sUMInWPPocBJ3vJDloYqjxEdhfZkRIByaPI6WTiwRgHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777063519; c=relaxed/simple; bh=Tz63FphAvz7UVvVeoQ94BTFqoD+Q0XOQsWAKaRk8sNY=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=lJ4euk5GkBwRE+Cx4eMzHwPre1SblEFRFofPDCq8WQdI+sIYCmaif/SzY8kunPuI61OpTuAcuiW1tW+k2dOf4bkMnaXhTjBKccaGW6+Cs1uYerdb6PXp6E33y+hf+DyThno2BUsoDUpSn8UGOBB/4GeQTpVIvP5IYWRKhpHXCBc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4C4104B920F5 Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-488d2079582so96382185e9.2 for ; Fri, 24 Apr 2026 13:45:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777063518; x=1777668318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=hbSiSmi6c80zqFwh+LRAyj0yAwi0z+PSv+fbqXH56ZU=; b=eczCdA950LaT9KY92x1YTYg7S5mXvdH2PzzCnJxBlFWW/ylGrzRQIpwKw+0yCMbXpR xTk4LUkAEdVKdplw2tgBXoR8fEkVVLuvw+N8u3IPUzqCg9mPttx/KTMKM8vkVl/5vQ15 Uc+tJEo9vj1cqL9ewkyeeE6AjFzhcmDNxQfokFLT1Hfk0GpRJ1Zq/bm1m+EyPe8lkaU5 mUp0+bBLCTOUSfAVRBdV/zlYwiTV/ECVcxs14UF4IDrkC/3SqF5GjKoofs2x7kZralD0 xXXsHQt8+B0TFntMVs9I3FsMZWAWLhBimVaFjvU7LfaQGsXWjuQ4/AhBY5zbKuKwDoB9 UzqQ== X-Gm-Message-State: AOJu0YzBApdNn/N+3evV3ynXFBZeC5mQh+b0j9f8zwf1WKxptTMgBRJe 1eyMGn4ufn1zXnn/u/PCnk5Sm2WFE4GD7r51BGcW91+xFk+nzsRB7Wk4aOUliP7l X-Gm-Gg: AeBDietfks9592pNloPvwapPB7Da6FYne57BaBdToPMhGJIO7KXD0FLqZBPOAqerpsY ibm7L8mrSSxxfQi3OsQGvmt1ITCn6R9TiHpJdPXaFJiJL584iRdIACpR2KrrmxnEjdkt0mPH3mh gtN96WjAgL3U/ZRwGRv5Bbv2w/tPNGw0brJLnp7QC/9tVGsrmnmMnvpG4iXfb12NvCeaYdlRgzr OTD/ZflDGmGDlxTGEv+iR2L6m7/JoMzSipLku1bVRD6kagn7sVFUvcOf0v18wLMbWgxS6FUhS7W KFLmLINd9i3Qm1ChOMVm9ubhw0jOytFYveBVs9d4XdEV0iJzrKG2JiGDObC9j6NGeQs2joPQtky CrVPSZGpW38bhXPlmLvYXYsQoO6XqwBg0hwnSICbXUeicGkBYl2L4Si6Fpxl5M0kKgaQZujoX3A o2er7TBLW62bH/tuEn9yFJP8/QISM9ACWn X-Received: by 2002:a05:6000:3104:b0:441:1e41:194 with SMTP id ffacd0b85a97d-4411e410216mr30769370f8f.17.1777063517663; Fri, 24 Apr 2026 13:45:17 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:7315:8865:c664:fc06]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-4411c9f4f03sm32427695f8f.1.2026.04.24.13.45.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Apr 2026 13:45:17 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [pushed 03/28] Windows gdb: Eliminate reload_context Date: Fri, 24 Apr 2026 21:44:43 +0100 Message-ID: <20260424204508.1343973-4-pedro@palves.net> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260424204508.1343973-1-pedro@palves.net> References: <20260424204508.1343973-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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 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::all; - CHECK (get_thread_context (th->h, context)); + if (context->ContextFlags == 0) + { + context->ContextFlags = WindowsContext::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> 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 @@ -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::all; - CHECK (get_thread_context (th->h, context)); + if (context->ContextFlags == 0) + { + context->ContextFlags = WindowsContext::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