From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by sourceware.org (Postfix) with ESMTPS id 79A313857C52 for ; Tue, 13 Feb 2024 21:14:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79A313857C52 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 79A313857C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707858845; cv=none; b=P6jwv+XS1mjlLYV5LLfpzLMCICKamKwojx9rlRQmy0GGXZhPqRSG2qcmIZ6s/t6pUIkBOJhCGmbtnGg601e5+DSSuoVQPdvGh1i0p8ya4tfKUMH9iWmRW18s0WQjMsl2QKXtpsvJOooSZ58hqL0Or/go+m0JhrpYYlJVkE9Noy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707858845; c=relaxed/simple; bh=e0K8OGYR2nR5wq+UvzOgmTVUzqze7iUYs1emqgndpu8=; h=Message-ID:Date:MIME-Version:Subject:From:To; b=uAlj6emXAOCcoEPQ8H4ZkvCALDQizizicXj6pHA22b/60fgTesj8vuptNRQGgYpTTkMVRQMioQ4+DekFhkyLVnGGXb5XwO2+HvOsiKdYCsrjQ9cpZQOW0n/q4n1d+rtnMNkm1qW6gKXiuxymVZt0ps3GCooDvvEBobuEkXdbTVI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-33b18099411so2811456f8f.0 for ; Tue, 13 Feb 2024 13:14:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707858842; x=1708463642; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=blZW75aLACsS8JRNgNPlnS42F/k11v+kGc0MlNmhefY=; b=SKKfp6thOlSissy4c6GzbspUy5tk1bLEc6wJpOI6g3N8n9KTL5/W2GoAfAekjQvLcG kY7RJQ3DeuvfZYTkqvKixQLN6UgEp8tPai6hnnRMiu80cs+8UcM+XUdQ2U+ODQ8tK9Qv KAY5RLLxlV6RgJWuTAJyXhhzRpBis1HeYuO66LXW9DwHLQHQI8u8wh2QUUefxNGBkj2U QsJxB3fus87HVkB3wG5vOrie6AdunAEUDIQOmU1tdeeVOnaKDqfaLf7SOxiwGt9Beh3y 1mdOFDPtwYQ5U3CoT1kYNXv7bJ2nsoaSJNkPwsFH6RVUEBNXHFV1iGkQA8ekIPva0xzd CXgA== X-Forwarded-Encrypted: i=1; AJvYcCVOEKwIkQCEZAsBX9Js55ahRzlxRY26ajaWrfVNHXR7+wPc+/JbHJ8vZuL5OKnjeWy+ixQE+Eu6RRrxQDcGx3cdeo5ota8twxst+Q== X-Gm-Message-State: AOJu0YxVnLYCsx3TG/0H+P6mFddd1wiZWQn0m/vu5QPIgA7hVLJL/1+g avn07yh/uwIoDB9QRVa2hP5wGglYyKHNOtdp7Q1uFDPVI4opiUzqVrHGgXmsysA= X-Google-Smtp-Source: AGHT+IGcEjqXTzEHe1YogJe68NKRaecVlWocFzsubV4GZ2/4Up9nQBcssvRDytCCfqVNg7ZRRXP7eA== X-Received: by 2002:a5d:4ecb:0:b0:33b:5b4c:a089 with SMTP id s11-20020a5d4ecb000000b0033b5b4ca089mr308983wrv.58.1707858842137; Tue, 13 Feb 2024 13:14:02 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCV+tOGBNAk8FIOJvXQ/abW0kyc7PM/Creff6wJXzbci/ykulx2Cmzv4S7BHgC4qmy+Bb1Pf0xUv7OucOmK61H//LnsEKkSe2oylWg== Received: from ?IPV6:2001:8a0:f923:4f00:2e64:674e:6775:d96d? ([2001:8a0:f923:4f00:2e64:674e:6775:d96d]) by smtp.gmail.com with ESMTPSA id l13-20020a056000022d00b0033b1b1da2adsm10501830wrz.99.2024.02.13.13.14.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Feb 2024 13:14:01 -0800 (PST) Message-ID: Date: Tue, 13 Feb 2024 21:14:00 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/3] Windows: Fix run/attach hang after bad run/attach Content-Language: en-US From: Pedro Alves To: Hannes Domani , "gdb-patches@sourceware.org" References: <20240212200153.882582-1-pedro@palves.net> <20240212200153.882582-4-pedro@palves.net> <226037012.2325520.1707768883883@mail.yahoo.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.2 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 List-Id: On 2024-02-13 12:20, Pedro Alves wrote: > On 2024-02-12 20:14, Hannes Domani wrote: > >> The same problem also exists in the !__CYGWIN__ branch, I ran into this >> multiple times already. > > Wow, the #ifdef region is so long that I didn't notice this particular code was Cygwin-only. > > I had put "Windows" in the subject as I thought I was fixing native Windows too... > > I'll go fix the !__CYGWIN__ branches too. > Here's an updated version that now handles the !__CYGWIN__ branch too. I confirmed manually that I saw the hangs on MinGW gdb without the fix, and that both the "attach" and "run" hangs go away with this version patch (the previous version still hanged with "run"). ---- 8< ---- >From af5cae1e2c0bf2cac2c5178d45f70eae5795cf8f Mon Sep 17 00:00:00 2001 From: Pedro Alves Subject: [PATCH] Windows: Fix run/attach hang after bad run/attach 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, 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 7f3044fc61d..5c47dd40738 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 ()) @@ -2664,12 +2664,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) @@ -2790,16 +2793,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); base-commit: a16034bf6417dc2259fef43fd5bcc2dd1dac562f -- 2.43.0