From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OVTYNjjX62m5UzkAWB0awg (envelope-from ) for ; Fri, 24 Apr 2026 16:48:56 -0400 Received: by simark.ca (Postfix, from userid 112) id DD7221E0BA; Fri, 24 Apr 2026 16:48:56 -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 2A1F51E093 for ; Fri, 24 Apr 2026 16:48:56 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id C672B4B920F3 for ; Fri, 24 Apr 2026 20:48:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C672B4B920F3 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by sourceware.org (Postfix) with ESMTPS id AE7BE4B920E3 for ; Fri, 24 Apr 2026 20:45:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE7BE4B920E3 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 AE7BE4B920E3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777063538; cv=none; b=brLrfZplNLc7XbGcJU9v5Dy/weCcD17DEfwOGAhFeCHNL4w3rjQws6P1oAsQalOsckwwEkyNsLoKEpX/sP1vcaABdAOolC2l52HfBET4qcyiO/rwPob1qBA/hwYO9d7tduPsH1qBjO6FoPDWEktpX2kOPpepxEx5V8tqxx+UCmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777063538; c=relaxed/simple; bh=/gGFpbFw1pd/4vjYT2JjjbwBgQkmr9H8RXtZPq0el6U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Lj8c2d1Xyh6CrlyrGHYvDCM47e6YcGLwM5hPT+yoMzj/DD0N091lBy2ro5tMZo526y31OXgjhhpNCuiMCPUJeI2REMDKz05v/yDAbRabmITLx5Ur9tcjwS4AOjq9thY39DEapC3JVw8DUecEbBl9HmL/u+yX+1Nh1s54JyHiiys= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE7BE4B920E3 Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-488e1a8ac40so101104305e9.2 for ; Fri, 24 Apr 2026 13:45:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777063537; x=1777668337; 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=OPoDyAOqucK92jIqd/joDAUDSrE0Qf4paJ8TsrCXYd4=; b=GaITZkLkgbLtyRW08ayFUW2zXsXeVjTCdQ0tYt3GlDkC5EBNwCeUWXz9kqfWK47HQA XQ9LJHbC8E2L1oMVVJeNyFIIIKKt3GD7ibWh+tPgDm9kJ2RHuhuBb6HzFY5gGtd1r0gP ty4OYa5t6Yq2m1RJKSIWtJYhpE6nBQR3dz5j2UoKzWfugCiiiBues27BPD0Zjsw0qwsW Ojy12CKvKsoAoBo8x63xH+HIEAn160JRUVL4wKopQznsD3e/ak/tHND7l2EoHuZBwEC8 0Kd80r56JR6HJ1xjjDp01yp0uZPED5NHw+UX3mD6PNALYW/5NOoLWH4N19OB8oFzpOSX hcVA== X-Gm-Message-State: AOJu0YzHFaqrxLI5ptPcZjJ7vOJzhb0RBhOBZaEPDspiWAuKZZTqdVXj OIfck8s9CoxHNy+0skm1m7oFBfwL7DtwAcBIZBvWUymVVxEwFUZGIjDgsJOAfZvX X-Gm-Gg: AeBDiev0y4kcp0/aY9KyVbEwHBG+1UwBbIJHdkoFJ3Ru0rhfRD4uZgBhtxFYeixUtXK aPu8ZkF1zhAzNRWHl3BRSAZrTwO3MLPbYt1XgptoYz85SwvFkpx29ClHcz8NDrA2hrABPdTOlLb Z+mQVLX8DV7ZExh/jh2k+qf3Z7fpgtV4KA+nch2spKZqIp4/V7Qc2ckV5Ndqv9KDFZTN/Zr9KHa yKguN8JE6tPwBA8KGSmi0smbGSbb2KUMnz1AeHXoUmGG7HmnsNR/yi2XyOvnixPFwwWCjApPu/F UaeoSz4uWJRkd98jgONU+0Uunb+dUdBmqzxbnmXhrsV4BdGkdcwB6sBLDvOLrCYF8i+XMe9vUnj ssQuMO+R8X3FtYLpCoCTftW0qssuSstXcC73eFv+dVZX4o7t6JCoinCbMwyl/mNlpTZGIpJW//+ g9DKHryMsj88wfOnA9tZwXCHofm/z5ffOE X-Received: by 2002:a05:600c:8b2e:b0:488:b749:8482 with SMTP id 5b1f17b1804b1-488fb7469b3mr493066705e9.4.1777063537252; Fri, 24 Apr 2026 13:45:37 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:7315:8865:c664:fc06]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-43fe4e3a341sm67567662f8f.24.2026.04.24.13.45.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Apr 2026 13:45:36 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [pushed 08/28] Windows gdb+gdbserver: Move suspending thread to when returning event Date: Fri, 24 Apr 2026 21:44:48 +0100 Message-ID: <20260424204508.1343973-9-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 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. Approved-By: Tom Tromey Change-Id: Ifd6889a8afc041fad33cd1c4500e38941da6781b commit-id:c4d2c92e --- gdb/aarch64-windows-nat.c | 1 - gdb/windows-nat.c | 11 +++++------ gdb/x86-windows-nat.c | 1 - gdbserver/win32-low.cc | 5 +++++ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gdb/aarch64-windows-nat.c b/gdb/aarch64-windows-nat.c index d43ee6f13fe..871531bb93a 100644 --- a/gdb/aarch64-windows-nat.c +++ b/gdb/aarch64-windows-nat.c @@ -185,7 +185,6 @@ aarch64_windows_nat_target::fill_thread_context (windows_thread_info *th) if (context->ContextFlags == 0) { - th->suspend (); context->ContextFlags = WindowsContext::all; CHECK (get_thread_context (th->h, context)); } diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 30b07221b62..468f451595d 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -710,12 +710,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 ([&] () @@ -1191,6 +1185,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/gdb/x86-windows-nat.c b/gdb/x86-windows-nat.c index 5b0f7066fba..baa6b969e99 100644 --- a/gdb/x86-windows-nat.c +++ b/gdb/x86-windows-nat.c @@ -111,7 +111,6 @@ x86_windows_nat_target::fill_thread_context (windows_thread_info *th) { if (context->ContextFlags == 0) { - th->suspend (); context->ContextFlags = WindowsContext::all; CHECK (get_thread_context (th->h, context)); } diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc index bf55183f705..d78de17ff19 100644 --- a/gdbserver/win32-low.cc +++ b/gdbserver/win32-low.cc @@ -1188,6 +1188,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.53.0