From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oBMJL2IyK2g2NyoAWB0awg (envelope-from ) for ; Mon, 19 May 2025 09:30:10 -0400 Received: by simark.ca (Postfix, from userid 112) id BE5271E11C; Mon, 19 May 2025 09:30:10 -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 B96C71E102 for ; Mon, 19 May 2025 09:30:09 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E8783858C31 for ; Mon, 19 May 2025 13:30:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E8783858C31 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by sourceware.org (Postfix) with ESMTPS id 707B63858D20 for ; Mon, 19 May 2025 13:24:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 707B63858D20 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 707B63858D20 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=1747661040; cv=none; b=Sn0iHtlP1ZbotU9oXzZFgIslhOeZd73Y3ukbht/HbPCXca1N7Px6ntjqo7Kuo1d6LQepsnDx3YfHNTxO17S5Znd62vppi3HwH3tjE3JJ+KV/CwyUVe2vuvvevPaXAsixc+9WqdwX/X90YS5uDWN/qbioBxdC/wDl1jwU/p/kRnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747661040; c=relaxed/simple; bh=zQiR+eEKMbl5RkBnIWXA0IGI8psAMvy9Ww4K2ei+ukU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=TRTOhKHMOCB7VjAalJaXi0ce64Hk0t15eBZqnYmD1bZcQrfiligRG1jTGyy7xZqqDa9rkXQsJMXCABe5jcVAR/xLhxaIJs80XcIdsG0Txo33y08OUroNKJonV2B3a/evo11dj0yrbP6fdxbSX2D1GtOAS0vqhfWmzAW+8+Sm9ck= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 707B63858D20 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-442eb5d143eso43506785e9.0 for ; Mon, 19 May 2025 06:24:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747661039; x=1748265839; 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=23X5MRaCPIODgsBxn18mthid2neGxHOAD8iVbeB6IxQ=; b=Kq8I3HsObbl9QuKKuXe2tv2HsH2rudkjcj6W0DtapR2jT1lAcgVVBEVdtjpqsFQbGd lzK5v8Ut+AmmGDrpmmoSRB2eEBylSr3AIDUuUGp5J6mt4EdWEHDzo7RYYpt+nMmDRZ0b A3lgOYk4cpIgiOk3W63EMauMtcC6ZtLlqmYzbfL7sCOodeNHFsnnzZoS1Rl81g/3IgZF Z2OlkjPy/BampiwDSKgdm12S9Occ9uCNky6Xp0ssuegik7lW1YZPvM/mP10DX3arrH6E WtafwKWJIu+MN4giG1ejUO4XTg6BZs7eiiX/I4v2t+IAKrGdzs25pKVg/bmG09P19Liq ZdGA== X-Gm-Message-State: AOJu0YyFLT4NXVYYEPkqWgW+NoERTKJ7Wctdpyi/3lgCLPtfIyJSV/hd IOlDhuSQdE1wBQYB1C6ma0QseJOwE6r0dNN2JW0j23lmNg9c0v5y0+S7+/5j38Ym X-Gm-Gg: ASbGnctFeg0F7p/Fw7xvhRKHERei+a1MmNnFZKFPoccy5Z+wsNLooRCQ+7h6BrkDFtB pfdsW60nqjQFgGWAvoyuQXaK2FiI/Bk3BlObWRyZXA91srCNn3JYVrzsymj46VileVhgctginvu yDfagmEG+uy3AlA1CfnRkvkC6XScrvqoOiBV610uOEt58DCKOtThnHmV9aqDxVzkkGfg95sJ6zC qwrEuPsK/ozwLrXXAOOph+3DL23r8B36Z2BbtzQyZ7UzCUAGVYMjJpMKSV5t4jgYja46ucewLfC pLfvS1cjRZzCjosWcFpgpsN9K28bVgYhnfuALFcdQuoV0rPxKAuL7tC3s8L9nQ== X-Google-Smtp-Source: AGHT+IH1ZZLqxF4ygkcc3dy6wpq1K5vhwqYySMHV9nW2KzahwuwcMlhEj8C4uhCMOdxzwwy8VvKJKg== X-Received: by 2002:a05:6000:3107:b0:3a3:7675:90c with SMTP id ffacd0b85a97d-3a376750bfbmr1431759f8f.26.1747661038970; Mon, 19 May 2025 06:23:58 -0700 (PDT) Received: from localhost ([2001:8a0:4fe9:b400:8d90:6f0d:36bf:32df]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3a3622b8a3esm11885401f8f.14.2025.05.19.06.23.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 May 2025 06:23:58 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 15/47] Windows gdb+gdbserver: Move suspending thread to when returning event Date: Mon, 19 May 2025 14:22:36 +0100 Message-ID: <20250519132308.3553663-16-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 The current code suspends a thread just before calling GetThreadContext. You can only call GetThreadContext if the thread is suspended. But, after WaitForDebugEvent, all threads are implicitly suspended. So I don't think we even needed to call SuspendThread explictly at all before our GetThreadContext calls. However, suspending threads when we're about to present a stop to gdb simplifies adding non-stop support later. This way, the windows SuspendThread state corresponds to whether a thread is suspended or resumed from the core's perspective. Curiously, I noticed that Wine's winedbg does something similar: https://github.com/wine-mirror/wine/blob/234943344f7495d1e072338f0e06fa2d5cbf0aa1/programs/winedbg/gdbproxy.c#L651 This makes it much easier to reason about a thread's suspend state, and simplifies adding non-stop mode later on. Change-Id: Ifd6889a8afc041fad33cd1c4500e38941da6781b --- gdb/windows-nat.c | 12 +++++------- gdbserver/win32-low.cc | 5 +++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 9b8bb66d700..61bccb365d0 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -702,7 +702,6 @@ windows_nat_target::fetch_registers (struct regcache *regcache, int r) { if (context->ContextFlags == 0) { - th->suspend (); context->ContextFlags = WindowsContext::all; CHECK (get_thread_context (th->h, context)); } @@ -1229,12 +1228,6 @@ windows_nat_target::windows_continue (DWORD continue_status, int id, th->resume (); } - else - { - /* When single-stepping a specific thread, other threads must - be suspended. */ - th->suspend (); - } std::optional err; do_synchronously ([&] () @@ -1713,6 +1706,11 @@ windows_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, th->stopped_at_software_breakpoint = true; th->pc_adjusted = false; } + + /* All-stop, suspend all threads until they are + explicitly resumed. */ + for (auto &thr : windows_process.thread_list) + thr->suspend (); } return result; diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index c99248d37cb..a23a41b9c02 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -1194,6 +1194,11 @@ win32_process_target::wait (ptid_t ptid, target_waitstatus *ourstatus, OUTMSG2 (("Child Stopped with signal = %d \n", ourstatus->sig ())); maybe_adjust_pc (); + + /* All-stop, suspend all threads until they are explicitly + resumed. */ + for_each_thread (suspend_one_thread); + return debug_event_ptid (&windows_process.current_event); } default: -- 2.49.0