From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QLoBMjLg+WkolRYAWB0awg (envelope-from ) for ; Tue, 05 May 2026 08:18:58 -0400 Received: by simark.ca (Postfix, from userid 112) id BB8041E067; Tue, 05 May 2026 08:18:58 -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 82D861E067 for ; Tue, 05 May 2026 08:18:57 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D91794BA901E for ; Tue, 5 May 2026 12:18:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D91794BA901E Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) by sourceware.org (Postfix) with ESMTPS id 01DAB4BA543C for ; Tue, 5 May 2026 12:18:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01DAB4BA543C 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 01DAB4BA543C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777983507; cv=none; b=gZftwVxg2h9Uuq3KufhLxN7MfTbo6qKjIXBhxAaMmzA0pGCYU9bHLhcjl67MkIYUPGjhQB1jAJZ8TwbXXiLzGv2JBl97NM5fXivGXCbsYGsQW/4lwZmrd7a41/ESUPm3DwHYBf6pgmlJ/9GMsvc4clCMMUU1YMOsTygZTDIFC5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777983507; c=relaxed/simple; bh=ce59jN3KvZhbsDm6tlxs5d0tgS8xqmONvgGHXVIVvrQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=aJzVk1i4G3Hi33pqE3PKqVO1lsI3cSZoyS3ZnHV3NWnLkw3q8PVLm9mIDmklLjgPk33/Xk17ViA4vJ/ofT4CIHwfgCrprX66IHjaoHaevWaj6QofpUk4cLquMuKxN6Kg4La6vaD3vfyIla/1Pitvs4rd8smEYO5P4Wegs74qQmo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01DAB4BA543C Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4852a9c6309so42103275e9.0 for ; Tue, 05 May 2026 05:18:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777983505; x=1778588305; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PbH+fK1c8qia/aWNdmSoSbwI1TjcVulPmMYc8+Ye/XE=; b=CcAoTw4guGjRXH2OuqERzywcwrT/Cts6ahZ3nUzFwI6L6Ygx+6+ZeZpoy039XZvZX7 IgD+h1jw3o4MyDL0WOXz/Z3wOxBdrkZyWuD88eEQRwCCP9Wwm6zsbVPEPMSlCAMQWzgp o/1RVaDcnWLNXaVmRYD4R1FRaG9hZB01Tbz1UvFEczuohJb4CFAEeylC5QpOwTjSgwhA yUXPP3BNBSsEk/Rya6fKZaBPvf40sB8O9vNhWyKN0Ky2wvHUxhTHBiOnoKEXBimYTtrV ZH6FDA6Z1y1wOd5USlV4YIhDg9IGiOjJ9m18GOdODU5b8cvZ8xWVqeAmKh3XGRAFPIgd L4VQ== X-Gm-Message-State: AOJu0Yy1v1lUy9hl0+jIq1XYfS08xgXg+icmnhWndxQ+vggEDKNCc0rd g4ZmEzuTOTX9Z8ZSMT7M48e0PesvWzjxX3uZNgmmZsjoaAwTHWAIJ8P2wjMP7w== X-Gm-Gg: AeBDievw0Ip6QRIOAXExkcRxesaam9sReCyahlJQOYhNSG4s5tjwSF3HQI5FcYZ/Y2p HMrceWFcRj1AX3WXJ7bofVfrVi9UUyOhBH/zXtluOoo6WE10I4lRq2Ju5X2XGtvBK50R7TOtVZA IrKwpWa7J5GlJZe/u3O+wayVogf1mwKTNj5ZE4uMdrCtdN0vMQ7pYrofSXMgkaLa/Fnn1BavUMz ngM8fSQ4XeCxrP/oxb9kBZZHfSDqceBvyvIoWuZo4kBhiqsqZDMQj6Tx+S4C+Jpqb+qN+0h1DYs 04OqXxowTuRjKwVHUJUM/G0PDQUT3AAF2yS5SrvaoMUyjq6B9xO0teAmRQmYm4u6bHyEcNM3IjS oyjMvgjWe9iQZFRezg9gOW4LufJLfzGEN2KGtZausj1ZCGAe1IlC5ljc6gNVZZ9mVrFB2KvCd+4 H5FT+Lc/wo5I1N7VooohWTaafh/46Lpd/z X-Received: by 2002:a05:600c:46d0:b0:488:79a3:f04c with SMTP id 5b1f17b1804b1-48d18cee7a2mr44245725e9.27.1777983505343; Tue, 05 May 2026 05:18:25 -0700 (PDT) Received: from localhost ([2001:8a0:facb:a800:d362:b803:ffc5:8f78]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-48a8ebc4201sm558480365e9.15.2026.05.05.05.18.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 May 2026 05:18:24 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH] Windows gdb: Avoid hang second attach/run Date: Tue, 5 May 2026 13:18:23 +0100 Message-ID: <20260505121823.1442331-1-pedro@palves.net> X-Mailer: git-send-email 2.53.0 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 gdb.base/attach.exp starts a second inferior and tries to attach the second inferior to the same process that inferior 1 is already debugging. The point is to make sure that the backend errors out when it tries to attach to a process that is already being debugged. windows_nat_target::attach and windows_nat_target::create_inferior both hang in this situation, because they call into do_synchronously, which hangs because the 'process_thread' thread is blocked in WaitForDebugEvent. E.g.: attach 4420 FAIL: gdb.base/attach.exp: do_attach_failure_tests: fail to attach again (timeout) Until the Windows backend is taught to debug multiple processes, which will probably require having one process_thread thread per inferior, detect the situation and error out before GDB hangs. This results in the following progression in gdb.base/attach.exp: -FAIL: gdb.base/attach.exp: do_attach_failure_tests: fail to attach again (timeout) -FAIL: gdb.base/attach.exp: do_attach_failure_tests: set confirm off (timeout) -FAIL: gdb.base/attach.exp: do_attach_failure_tests: switch to inferior 1 (timeout) -FAIL: gdb.base/attach.exp: do_attach_failure_tests: exit after attach failures (timeout) -FAIL: gdb.base/attach.exp: do_attach_failure_tests: gdb_breakpoint: set breakpoint at main (timeout) -FAIL: gdb.base/attach.exp: do_attach_failure_tests: stop at main (timeout) +PASS: gdb.base/attach.exp: do_attach_failure_tests: fail to attach again +PASS: gdb.base/attach.exp: do_attach_failure_tests: set confirm off +PASS: gdb.base/attach.exp: do_attach_failure_tests: switch to inferior 1 +PASS: gdb.base/attach.exp: do_attach_failure_tests: exit after attach failures +PASS: gdb.base/attach.exp: do_attach_failure_tests: stop at main There are still other failures not addressed by this patch. Tests that launch a second program with "run" exist, but are normally gated by allow_multi_inferior_tests. Change-Id: I55b4438795439673c49fa55f55ddf0191f4f0ea8 commit-id: 1caa5be0 --- gdb/testsuite/gdb.base/attach.exp | 4 ++++ gdb/windows-nat.c | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gdb/testsuite/gdb.base/attach.exp b/gdb/testsuite/gdb.base/attach.exp index bffdfd9b1aa..a4e7d72ef94 100644 --- a/gdb/testsuite/gdb.base/attach.exp +++ b/gdb/testsuite/gdb.base/attach.exp @@ -175,6 +175,10 @@ proc_with_prefix do_attach_failure_tests {} { # Response expected when using gdbserver. pass "$test" } + -re -wrap "Can only debug one process at a time\\." { + # Response expected on Windows. + pass "$test" + } } # To ensure the target is still alive and working after this, try to run diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index a9647e90bb8..6b2a5d30132 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2010,14 +2010,24 @@ set_process_privilege (const char *privilege, BOOL enable) return ret; } +/* Throw an error if we're already debugging a Windows process. We + can only debug one at a time currently. */ + +static void +ensure_only_one_process () +{ + if (windows_process->process_id != 0) + error (_("Can only debug one process at a time.")); +} + /* Attach to process PID, then initialize for debugging it. */ void windows_nat_target::attach (const char *args, int from_tty) { - DWORD pid; + ensure_only_one_process (); - pid = parse_pid_to_attach (args); + DWORD pid = parse_pid_to_attach (args); if (set_process_privilege (SE_DEBUG_NAME, TRUE) < 0) warning ("Failed to get SE_DEBUG_NAME privilege\n" @@ -2369,6 +2379,8 @@ windows_nat_target::detach (inferior *inf, int from_tty) switch_to_no_thread (); detach_inferior (inf); + windows_process->process_id = 0; + maybe_unpush_target (); } @@ -2811,6 +2823,8 @@ windows_nat_target::create_inferior (const char *exec_file, DWORD flags = 0; const std::string &inferior_tty = current_inferior ()->tty (); + ensure_only_one_process (); + if (!exec_file) error (_("No executable specified, use `target exec'.")); @@ -3120,6 +3134,7 @@ windows_nat_target::mourn_inferior () CHECK (CloseHandle (windows_process->handle)); windows_process->open_process_used = 0; } + windows_process->process_id = 0; inf_child_target::mourn_inferior (); } base-commit: 8c0ac471835ec86a67c5b42713d9f138f31e4014 -- 2.53.0