From patchwork Tue May 7 23:42:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 89680 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DB8338449C1 for ; Tue, 7 May 2024 23:43:55 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by sourceware.org (Postfix) with ESMTPS id D70E43858C50 for ; Tue, 7 May 2024 23:42:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D70E43858C50 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 D70E43858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125381; cv=none; b=hz59QCyuF0wAR+tjAXZ302zAIzdU4jEV9dp8Qvu51CnLBoOd/9iNEEUcV13YxVM+nbP70Zeo9F9vZblNSMKIsdR4m5mKwN5hSJC0sDjaHV2JRhJO8BaiBHQAajMzcLXo4vsqB2Y0Jto6s6hi/xFlK6W4EbAVmCdEblg3oV4xgkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715125381; c=relaxed/simple; bh=tuqmfMtuU2QSCbvyk0n1TVR3jXf9iKoGz45Lh6WAT3E=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kX+5q+NHFAF5w1d30zAXTAkQFQR9Ysl5OAoPeJ5LS8UPaykIZ8SX8GA91xDnoSQ7VIp6nfl+xBvjtQDxEx6QKx0v8/MsQJSe/zzRVYBwnNG1CFwljy5mgocqztIaCLLjSU+F8/hjz4Uv4wYdajCA1sb1nXD/ZvSQpZt0DTkUYTA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-34d8d11a523so1791163f8f.2 for ; Tue, 07 May 2024 16:42:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715125375; x=1715730175; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p8tRaaQoXqFa8FXzeYUKm7XujlPcS3CLCXkSff0te5Y=; b=XkYdpfvUiOKnHsokb/JlV93i0pIQnnk9uz/7suKREizTCCFi9xS7177ZuNs+XUQE5j gTcXFnuHECSBCaSKWk8IU7IkqDC3Q4JOJJ7P6UHN1n+evTVERuElOUXrKpnxaSP4d2P7 u1U790voznxSZRqclwErI/StvAt10SXnjlalIfD28widapAHovwwPCJeZ7HFVoKHiwHU Yw/A+a9bJloNjUC1oX+Mbh25fbwBXZV/wVVF6/7SREhM4ruDvX1VOAaR4d4jOYYMdNxe YKnKvnF/mbXd8vaIM9EqaMW9o4krnoyjciUeo9/T99iQyFbA6yQOTajj+b6gN9a2dLdG JyfA== X-Gm-Message-State: AOJu0Yy6fy9smeOR5jSWPLYFnhrY5DVGIVEscAawO8V1h1vrFhPq1Ub1 YXFsmlBuZ0PHgT4K6qBmY5ewMab4CWIv8NMcXaOUO0RmxJ0v1m1FiCbh33IT X-Google-Smtp-Source: AGHT+IHBnUA8NZtkVBQ2ovH4/l8Q3LCKKYpDmhqvZzpuGpQ3LJX82BsFz2gf71h6ID75hW6iHTr4Rw== X-Received: by 2002:adf:fc8d:0:b0:34d:98eb:4cb with SMTP id ffacd0b85a97d-34fca243e4cmr770634f8f.33.1715125375476; Tue, 07 May 2024 16:42:55 -0700 (PDT) Received: from localhost ([2001:8a0:f908:4900:2dd1:1a0d:2b75:dc42]) by smtp.gmail.com with UTF8SMTPSA id da11-20020a056000196b00b00349ff2e0345sm14067233wrb.70.2024.05.07.16.42.54 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 May 2024 16:42:55 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 05/34] Windows gdb: Eliminate reload_context Date: Wed, 8 May 2024 00:42:04 +0100 Message-ID: <20240507234233.371123-6-pedro@palves.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240507234233.371123-1-pedro@palves.net> References: <20240507234233.371123-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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+patchwork=sourceware.org@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. Change-Id: Ied566037c81383414c46c77713bdd1aec6377b23 --- gdb/nat/windows-nat.h | 4 ---- gdb/windows-nat.c | 42 +++++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 7d336346a86..41921aa653b 100644 --- a/gdb/nat/windows-nat.h +++ b/gdb/nat/windows-nat.h @@ -84,10 +84,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 4ffbeaaf7e4..3888ab6a02c 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -98,6 +98,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> thread_list; @@ -523,6 +525,18 @@ windows_per_inferior::find_thread (ptid_t ptid) return nullptr; } + +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, thread_disposition_type disposition) @@ -536,11 +550,11 @@ windows_per_inferior::thread_rec 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; } } @@ -642,18 +656,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 = (char *) &th->context; #ifdef __x86_64__ @@ -723,21 +732,23 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r) if (th == NULL) return; - if (th->reload_context) - { #ifdef __x86_64__ - if (windows_process.wow64_process) + if (windows_process.wow64_process) + { + if (th->wow64_context.ContextFlags == 0) { th->wow64_context.ContextFlags = CONTEXT_DEBUGGER_DR; CHECK (Wow64GetThreadContext (th->h, &th->wow64_context)); } - else + } + else #endif + { + if (th->context.ContextFlags == 0) { th->context.ContextFlags = CONTEXT_DEBUGGER_DR; CHECK (GetThreadContext (th->h, &th->context)); } - th->reload_context = false; } if (r < 0) @@ -1533,10 +1544,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; }