From patchwork Mon Feb 12 20:01:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 85626 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 62B9A3858404 for ; Mon, 12 Feb 2024 20:02:50 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by sourceware.org (Postfix) with ESMTPS id 2D5793858C30 for ; Mon, 12 Feb 2024 20:02:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D5793858C30 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 2D5793858C30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707768127; cv=none; b=a8OnVOuT9npD+VkSs60j72/HazLweHv2TCDZSlaCBJC/zyasvAf6g4r+ZhK/mILCSX/r9XW3rNJa7WGPmG6urE+j8NMD67EZYyCDfU30CNLm4sVnZ/C7+sbxtAACd3UuzwB/DHwOA6rQCCNZGMmRvCrQcMd8+KzYaCdeop7fEuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707768127; c=relaxed/simple; bh=2beDgmigtf8Lp8JZuSOQQ4h/OyYmKZzsb5FZtaBnvAs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=lfRfHdLVrTIdXoPQ/g2uXuaUIglav3Z3Cc/IBCFdZLu/XYgmhv80rHZC1zcX5pQpxZNupU34JHG1csj6u0lGGzBhWK+n5xXdN39iJMMuUoCjo11OLy97teBT1C861Bm/Jg+/4jl475pLxI+Dwlxeg+jNA2noe4tHu7bWE9GzJes= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-411b56f983cso112775e9.0 for ; Mon, 12 Feb 2024 12:02:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707768124; x=1708372924; 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=pHagBCPi4KyEHnFa0Po2PmBSk9jE3naH62o5JCM7crc=; b=EqXeQEbigryaAeeC35868bZk5aUSgvp7Pi2DmIhPaBaH0E7JZAQwkulQskCfCWyb5x V4F6BuslqQrcfPjnnTun/iPCej4PbPWvtttyUjapHtXtW8MCd6y7oxPBhl4p/sEFWt41 8g/ACUlB9RvSdDEQhE7dhq9MlBbDfm0MVbQRfnX0c9W5Gi9Xr6c2RukOqeChTVCBqOL7 bGg8B/rF+9Q0G32u/ntYiaw7OM8Upx8xIJkCiJ9LHkqRlUJm9P63Sty9y9If7UmeaDJs fF4TFCHRAu1B0uF3lySiBQ9/+5xbIql9KneXrfyNmCaRcOhIJF2OsCOaw5atBYFLC8B/ cPYA== X-Gm-Message-State: AOJu0YwCkLfaznXvPatV1u2K7MkXeSGcrEzlhimILQybvsc/Ka9GH/Pl 6XIwHsRT8Qa+zN1lurwt0J7pdCeBRa+WSSmsADPmfhUnzGGFZ0hoQoRscAjrEXU= X-Google-Smtp-Source: AGHT+IG01/5bdgjA/dfhqN+76wefgc8KlU2QV1RkiDwaKluFYLnMOgVgSaQHsbfxG/Zeuw3e0EpPnw== X-Received: by 2002:a05:600c:46c9:b0:410:7980:72a3 with SMTP id q9-20020a05600c46c900b00410798072a3mr5867514wmo.35.1707768124537; Mon, 12 Feb 2024 12:02:04 -0800 (PST) Received: from localhost ([2001:8a0:f923:4f00:6d21:130f:e0dc:ea4b]) by smtp.gmail.com with UTF8SMTPSA id o16-20020a5d58d0000000b0033afe816977sm7587789wrf.66.2024.02.12.12.02.03 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Feb 2024 12:02:04 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 3/3] Windows: Fix run/attach hang after bad run/attach Date: Mon, 12 Feb 2024 20:01:53 +0000 Message-ID: <20240212200153.882582-4-pedro@palves.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212200153.882582-1-pedro@palves.net> References: <20240212200153.882582-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 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, T_SCC_BODY_TEXT_LINE 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 a 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: (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. The tests mentioned above now pass on Cygwin. Change-Id: I15ec9fa279aff269d4982b00f4ea7c25ae917239 --- gdb/windows-nat.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index b446afd72d8..5d2e23600e3 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -2043,7 +2043,7 @@ windows_nat_target::attach (const char *args, int from_tty) if (!ok) err = (unsigned) GetLastError (); - return true; + return ok; }); if (err.has_value ()) @@ -2642,12 +2642,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)