From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YPA0DCUyK2i1NioAWB0awg (envelope-from ) for ; Mon, 19 May 2025 09:29:09 -0400 Received: by simark.ca (Postfix, from userid 112) id 2F53E1E11C; Mon, 19 May 2025 09:29:09 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 819351E102 for ; Mon, 19 May 2025 09:29:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2837A3858289 for ; Mon, 19 May 2025 13:29:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2837A3858289 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by sourceware.org (Postfix) with ESMTPS id ACB39385841C for ; Mon, 19 May 2025 13:23:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACB39385841C 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 ACB39385841C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661021; cv=none; b=qnvbzmDeztuZA3XNC5WLB2Twi9QNpI/9eoD9f7JJ1wCaMMbelHyOX8ZOqYRNkP5QjVXRyHVc0fa2I85FECaRCmc9NIzZ9wOebKXhWSLpH21oGfrCOtIU72rDJVzRZXOaF3PSqG0C/6NNxV3OIdQFySnd0xPXt3FOu+YNmFXdhrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661021; c=relaxed/simple; bh=ljcVOU/gSHENBw5IzwLXlYuvJ8CnKMcRqIFirgXmO/A=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=l/toBFKV1CEyidZWQ0kCpHa22TUkPQGKtjszGO6nevDc/Kd5tMXpSX8TuETILiJ4PeJmokDUMbgarFcBeUlSQOJAG+AQF7fm3KL74/vMGEJgaOPnc5Tgk+6FW3zXI6x00rheMG9ozPmJDK8fdtz9fG6EHBiUpcv6hblFRreDat8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACB39385841C Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-442ea95f738so35110395e9.3 for ; Mon, 19 May 2025 06:23:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747661020; x=1748265820; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SBBXC3gZmgmnhsSm0ld9sfkZHzCWAQInuFzXgLTFeHQ=; b=FTXLlk3FSfL76bAEDQ5FB2i8Csy2cISaKZhR2S3A/0MzmTE8U8Zgbk5ZIi/1aDn38G OLq4chDMn6BrSGSBBL/Rxta6eMSvrexgUmTPqbt+EmRh7YpWpc4cs1Q+2cQn4xtLxpTU GGN9eqhdx39Tan1f5FAtpB8chUqhNzeUNgze0NMk0lyLITdFHIF/rRt/qZad+YbIYA8z p7ZYPVfrpHyYd5h+U3IyARJEXUqcZYl3BN1wVf0R+pHBLQ6JZ1P2fVx5MUyIp8TRcVi0 S8E0Doyuo+XvyPtePuRydFDqerhq/2TBKTLp37l5mQCCN2SAxD1fub7dhEbL9JSr8Tac Hm0A== X-Gm-Message-State: AOJu0YwNDAsKTq+uTG3XMK1VENoZ59cVtlIYdrL0V2DbU73XTAbUIStq uaaIyhBrQ7hc3w3S/22FZkX6HLUqGIGWUjedlpml3luKJT1HjjIYpqeGs+x8EpP2 X-Gm-Gg: ASbGncsTkmvBj4ZPGm+NAYjcUrWQqOM3T7bgKXk3rIHB159pc0wq+NeDlpa+02BhDHl rDs73FilaEqHxSjDEXo37bjZPSRW0TRfOuvVZw+fhBZF56N5Lw1Mv5kVwqADzV5fYQmhCdgao7E PCmBk4evDvro5OK/wvdZjr2GR6bSTMqdldzLGbGiZR1CKJJWaAzpSkLKAnGHOaewJvnQieQhU1P W8U4JCfgTM4Wy1zw92IvDO4sG9lrWcI7gfwYYqaJNd9uVY9LD1QoJzfHDmLa62EEr5Dx49zbQJx GdlxApBX681+CISent90PBwX+4uZ/aR+WK5VRBlr4mEUCpSSnE9sxVaUf2rK05BG3Y0CaJtgmA= = X-Google-Smtp-Source: AGHT+IHDz5Fg7MXDwXOWqXWkUulbDIDUGwx2F8QfAsHI1zEy1Hl5nkQitMZNWZgNLsAVV4dyoQFXMw== X-Received: by 2002:a05:600c:1e87:b0:43d:585f:ebf5 with SMTP id 5b1f17b1804b1-442fd60b4c2mr108696305e9.1.1747661020051; Mon, 19 May 2025 06:23:40 -0700 (PDT) Received: from localhost (bl20-181-249.dsl.telepac.pt. [2.81.181.249]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-442f33804d9sm211092295e9.12.2025.05.19.06.23.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 May 2025 06:23:39 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 10/47] Windows gdb: Eliminate reload_context Date: Mon, 19 May 2025 14:22:31 +0100 Message-ID: <20250519132308.3553663-11-pedro@palves.net> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250519132308.3553663-1-pedro@palves.net> References: <20250519132308.3553663-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/nat/windows-nat.h | 4 ---- gdb/windows-nat.c | 49 +++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/gdb/nat/windows-nat.h b/gdb/nat/windows-nat.h index 902508b0aea..71560930e84 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 e9389169ab3..4a10cf962a9 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -101,6 +101,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; @@ -516,7 +518,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, @@ -531,11 +544,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; } } @@ -637,18 +650,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) { @@ -717,16 +725,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::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::all; + CHECK (get_thread_context (th->h, context)); + } + }); if (r < 0) for (r = 0; r < gdbarch_num_regs (regcache->arch()); r++) @@ -1446,10 +1452,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; } -- 2.49.0