From patchwork Fri Apr 19 15:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 88742 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 4FA763846420 for ; Fri, 19 Apr 2024 15:14:59 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by sourceware.org (Postfix) with ESMTPS id E3D543849AE1 for ; Fri, 19 Apr 2024 15:13:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3D543849AE1 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 E3D543849AE1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713539642; cv=none; b=Y/WmmhUHF6WADvDqvMgBFj6083AwNKfPvV4SdHd8imoPvbLB7MkvlYe4tgFzZuulIMYi90c81mAP97t8pkj0crnJx+r2tlLyy7F09QTxP8lN5WfZ7cdWHfbjFsVnb6FMvAOj2ay+Fb931PfMgFBDaz0zcTQoPAatSKfTRZQvn+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713539642; c=relaxed/simple; bh=CqrsICX3sAsU9wy7N37YAmMKHejumn8iEoQCjPe78DE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Vy4+oCfZ3rtk7rRvKziETAZRwaDOqgVOHLqqXM6MmDHxHAWJnGNMe2DXgtklXfp61eXb9XH1oAji5ZO32QzAU6Gh2YCyKev/OXl43Lnq3YXenME4S/6xX3N7jN9UQwMKh0FbrfSEo/g/rGQnz0S/mih0rTmVIJ33elpu2B24nGE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2d8b4778f5fso21071691fa.3 for ; Fri, 19 Apr 2024 08:13:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713539636; x=1714144436; 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=9pLeGk4n+kUdJvnn3ymntfohQ2apkb9XfUbfn2Zf0o4=; b=YuzotUWoBmcsxDJBCQXSpJWbDdlfndo34HxvlfBm7nYy8Qaw4SoHe2vXTOVlKWmiHh KbKPaB2O1YfQNZwS23V19hMGh4yh4EULczJEu2RM6UghPFlyVZsCATStYf9DIA9C2LrR dY+QEOBKNJjbyifc/8l0edROzX8YU4zm0UQDubzTsObOMMGFCkO1gR2uO8TWjd/uqcWx yuBHwkFVWB3LUZzjRL1Dk+uPSk7fch14yxXF41ypXdyTGW3T6Xw64Xkn5+8WhuOiNmeC ErL0YeUkY3kOyzx2DUxT0R0X/JKX9UlbFXSOloCX8G1kqLg1BovxNbc1jBcsBvqVNxDc SM0g== X-Gm-Message-State: AOJu0YykwrU8H2tviOZlYeNybZ/2DANThn0gL5Ui0tsNnVivMyiXtmK6 QbH0zVIJ4AYoFdJCKhJGBWKw072TJj7mIgYJtMGX7ZVdNxVVIujMAbTSIf8T X-Google-Smtp-Source: AGHT+IEWi9Cly9kUFglYiZahkxAcDUZgIw73e7w1h1/JJLSAAK5smcLrYUzNlVCD9w2C6sqGk+zg1g== X-Received: by 2002:a05:651c:794:b0:2da:7944:9525 with SMTP id g20-20020a05651c079400b002da79449525mr1362378lje.49.1713539636022; Fri, 19 Apr 2024 08:13:56 -0700 (PDT) Received: from localhost ([2001:8a0:f93d:b900:2438:d637:5572:c30a]) by smtp.gmail.com with UTF8SMTPSA id a12-20020a056000188c00b00347eb354b30sm4775053wri.84.2024.04.19.08.13.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Apr 2024 08:13:55 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 04/12] Windows: Fix run/attach hang after bad run/attach Date: Fri, 19 Apr 2024 16:13:34 +0100 Message-ID: <20240419151342.1592474-5-pedro@palves.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240419151342.1592474-1-pedro@palves.net> References: <20240419151342.1592474-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 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 On Cygwin, gdb.base/attach.exp exposes that an "attach" after a previously failed "attach" hangs: (gdb) PASS: gdb.base/attach.exp: do_attach_failure_tests: attach to digits-starting nonsense is prohibited attach 0 Can't attach to process 0 (error 2: The system cannot find the file specified.) (gdb) PASS: gdb.base/attach.exp: do_attach_failure_tests: attach to nonexistent process is prohibited attach 10644 FAIL: gdb.base/attach.exp: do_attach_failure_tests: first attach (timeout) The problem is that windows_nat_target::attach always returns success even if the attach fails. When we return success, the helper thread begins waiting for events (which will never come), and thus the next attach deadlocks on the do_synchronously call within windows_nat_target::attach. "run" has the same problem, which is exposed by the new gdb.base/run-fail-twice.exp testcase added in a following patch: (gdb) run Starting program: .../gdb.base/run-fail-twice/run-fail-twice.nox Error creating process .../gdb.base/run-fail-twice/run-fail-twice.nox, (error 6: The handle is invalid.) (gdb) PASS: gdb.base/run-fail-twice.exp: test: bad run 1 run Starting program: .../gdb.base/run-fail-twice/run-fail-twice.nox FAIL: gdb.base/run-fail-twice.exp: test: bad run 2 (timeout) The problem here is the same, except that this time it is windows_nat_target::create_inferior that returns the incorrect result. This commit fixes both the "attach" and "run" paths, and the latter both the Cygwin and MinGW paths. The tests mentioned above now pass on Cygwin. Confirmed the fixes manually for MinGW GDB. Change-Id: I15ec9fa279aff269d4982b00f4ea7c25ae917239 --- gdb/windows-nat.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index a53b6a6e053..d61ed95a7fb 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2059,7 +2059,7 @@ windows_nat_target::attach (const char *args, int from_tty) if (!ok) err = (unsigned) GetLastError (); - return true; + return ok; }); if (err.has_value ()) @@ -2784,12 +2784,15 @@ windows_nat_target::create_inferior (const char *exec_file, windows_init_thread_list (); do_synchronously ([&] () { - if (!create_process (nullptr, args, flags, w32_env, - inferior_cwd != nullptr ? infcwd : nullptr, - disable_randomization, - &si, &pi)) + BOOL ok = create_process (nullptr, args, flags, w32_env, + inferior_cwd != nullptr ? infcwd : nullptr, + disable_randomization, + &si, &pi); + + if (!ok) ret = (unsigned) GetLastError (); - return true; + + return ok; }); if (w32_env) @@ -2910,16 +2913,18 @@ windows_nat_target::create_inferior (const char *exec_file, windows_init_thread_list (); do_synchronously ([&] () { - if (!create_process (nullptr, /* image */ - args, /* command line */ - flags, /* start flags */ - w32env, /* environment */ - inferior_cwd, /* current directory */ - disable_randomization, - &si, - &pi)) + BOOL ok = create_process (nullptr, /* image */ + args, /* command line */ + flags, /* start flags */ + w32env, /* environment */ + inferior_cwd, /* current directory */ + disable_randomization, + &si, + &pi); + if (!ok) ret = (unsigned) GetLastError (); - return true; + + return ok; }); if (tty != INVALID_HANDLE_VALUE) CloseHandle (tty);