From patchwork Mon Feb 12 20:01:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 85624 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 7EFFB385842B for ; Mon, 12 Feb 2024 20:02:36 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by sourceware.org (Postfix) with ESMTPS id 863D63858C52 for ; Mon, 12 Feb 2024 20:02:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 863D63858C52 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 863D63858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707768123; cv=none; b=xGzX8hgpEe0pkOeeWA6Ubhp2gbzKnSLiFPWjRbk6owm/TeVnEWSnzSkX1QJyL80MAWA25JDK5lI+tzx1lcZi89jVM1K3HM4sgqye44JkhHsNyw/RYSY1BWJ2HlvrSF00vW36wEHMYOdxLVlAiWEBw24uzul6XRqy/+0GljpvseA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707768123; c=relaxed/simple; bh=cR62Y+z8bHzfaBMvtEzs8EzeSbLukVRPtp30HVRkpDs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=wUzZl5Yi9N3QjOCcsKlDCSLY7g3C633UUovfXGkcUsUlT5buWKrm4WTQw0mmZbz8uSutwHUYllwP4XM9BW9B20fXXziUVePUDef7mtsFqRPgcLDWpibQ3VjcD0Nz3GE/tCFaFuKsl8EY4oY+byJu17tKuCoqZsRbn8oev1qyPaI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-410ee8ed659so6905005e9.2 for ; Mon, 12 Feb 2024 12:02:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707768120; x=1708372920; 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=KapWfptXrV3wfhaSW56DaoG7vaRrSClxhM+pJa20Ia8=; b=ryK9dPPp06pP0IuZOWJIoJtz1RQew9PSTAgo+3XMZ1roOQzsTsPP+qLSN+oa5E7GI7 QcFfCmpgCGjoDlWTKsc/iMlkZSRvGRXuh5xlGeSw5qcKHX/mNfdZCYLFkCXKcfV6Tg0B 5l8a1WI4dihn/6moB8flPcsWMRGyhjltVytv4+lZaR2Vwkog9NhN9+RzmMO37n3d3Sjg sKT9C8BRsSYMsQXtwXovCAPrCtIKAs8vnGA7AzSnArvspRZjDY4fH93NyFYGhIBFPovn 7k8VeoiZ7/91WgcG+m0MqPXSwWJItGT4VCY2QqP0ylf53nZGAKOAsq/Ocl0wjL1BDW2L tQxw== X-Gm-Message-State: AOJu0YzKOZ3CCpPe4l8OHtzgHxsOBEmWEcbAHHfHbiry6zb43973h5tu DvXrMTHb8IkYBEuA9vCSbrrK7NyG/csLWJGUM3VB/0nepcTZCCysfdWdmULMT3w= X-Google-Smtp-Source: AGHT+IGPiMw4MPw2BGxI4ekAub7FnK5mKAppfQSFRDbYiLcDI8Sti0J4wyx2KS+ZPYjA7DQj8iIlEg== X-Received: by 2002:a7b:c342:0:b0:40f:dc50:aea5 with SMTP id l2-20020a7bc342000000b0040fdc50aea5mr6722824wmj.22.1707768119969; Mon, 12 Feb 2024 12:01:59 -0800 (PST) Received: from localhost ([2001:8a0:f923:4f00:6d21:130f:e0dc:ea4b]) by smtp.gmail.com with UTF8SMTPSA id q18-20020a7bce92000000b00410c04e5455sm5035611wmj.20.2024.02.12.12.01.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Feb 2024 12:01:59 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 1/3] Fix "run" failure with GDBserver Date: Mon, 12 Feb 2024 20:01:51 +0000 Message-ID: <20240212200153.882582-2-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.1 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, 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 If starting the inferior process with "run" (vRun packet) fails, GDBserver throws an error that escapes all the way to the top level. When an error escapes all the way like that, GDBserver interprets it as a disconnection, and either goes back to waiting for a new GDB connection, or exits, if --once was specified. E.g., with the testcase program added by this commit, we see: On GDB side: ... (gdb) tar extended-remote :999 ... Remote debugging using :9999 (gdb) r Starting program: Running ".../gdb.base/run-fail-twice/run-fail-twice.nox" on the remote target failed (gdb) On GDBserver side: $ gdbserver --once --multi :9999 Remote debugging from host 127.0.0.1, port 34344 bash: line 1: .../gdb.base/run-fail-twice/run-fail-twice.nox: Permission denied bash: line 1: exec: .../gdb.base/run-fail-twice/run-fail-twice.nox: cannot execute: Permission denied gdbserver: During startup program exited with code 126. $ # gdbserver exited This is wrong, as we've connected with extended-remote/--multi. GDBserver should just report an error to vCont, and continue connected to GDB, waiting for other commands. This commit fixes GDBserver by catching the error locally in handle_v_run. Change-Id: Ib386f267522603f554b52a885b15229c9639e870 --- gdb/testsuite/gdb.base/run-fail-twice.exp | 67 +++++++++++++++++++++++ gdbserver/server.cc | 10 +++- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/run-fail-twice.exp diff --git a/gdb/testsuite/gdb.base/run-fail-twice.exp b/gdb/testsuite/gdb.base/run-fail-twice.exp new file mode 100644 index 00000000000..2fda5c9fde5 --- /dev/null +++ b/gdb/testsuite/gdb.base/run-fail-twice.exp @@ -0,0 +1,67 @@ +# Copyright 2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test doing a "run" that fails, and then another "run". + +# The purpose of this testcase is to test the "run" command. If we +# cannot use it, then there is no point in running this testcase. +require !use_gdb_stub + +standard_testfile + +if {[build_executable "failed to build" $testfile $srcfile {debug}]} { + return -1 +} + +proc test_run {testname} { + gdb_run_cmd + gdb_test_multiple "" $testname { + -re -wrap "During startup program exited with code 126\\." { + # What we get on GNU/Linux. + pass $gdb_test_name + } + -re -wrap "Error creating process.*" { + # What we get on Windows. + pass $gdb_test_name + } + -re -wrap "Running .* on the remote target failed" { + # What we get with older GDBserver and other remote + # targets. + pass $gdb_test_name + } + } +} + +proc_with_prefix test {} { + global gdb_prompt binfile + + clean_restart $binfile + + gdb_test_no_output "set confirm off" + + gdb_remote_download host $binfile $binfile.nox + remote_exec target "chmod \"a-x\" $binfile.nox" + gdb_test "exec-file $binfile.nox" \ + "" \ + "exec-file \$binfile.nox" + gdb_test "set remote exec-file $binfile.nox" \ + "" \ + "set remote exec-file \$binfile.nox" + + test_run "bad run 1" + test_run "bad run 2" +} + +test diff --git a/gdbserver/server.cc b/gdbserver/server.cc index e02cdb83b51..0967b194376 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3025,7 +3025,15 @@ handle_v_run (char *own_buf) free_vector_argv (program_args); program_args = new_argv; - target_create_inferior (program_path.get (), program_args); + try + { + target_create_inferior (program_path.get (), program_args); + } + catch (const gdb_exception_error &exception) + { + sprintf (own_buf, "E.%s", exception.what ()); + return; + } if (cs.last_status.kind () == TARGET_WAITKIND_STOPPED) { From patchwork Mon Feb 12 20:01:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 85625 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 25399385841B for ; Mon, 12 Feb 2024 20:02:38 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by sourceware.org (Postfix) with ESMTPS id 89C6B3858408 for ; Mon, 12 Feb 2024 20:02:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89C6B3858408 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 89C6B3858408 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707768126; cv=none; b=l7lhY99oymua6Cz//u1cikETLPIkNWwdLTBGrv6jcIJOAYUgTh5eAyZrEp0Zeb4aNRPgq4EDUdJ7V1d/Y4JwagPwddUUdOOJyYZ/WZM0iC9oqowggPaA2YS+tIp2zgjAkXU8JSbNz0jDg6OmkXfU8ZfFIsa4ilEkJjsehic/hbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707768126; c=relaxed/simple; bh=npKzAsmaw3x6tTGTgMR75Y5cKY+DZE7n4pDmo5uQxpM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Rrj3wdb4adoyNej2u/JYcP9JJWPHxfc/bBCka35bFLje5AaPEyAOZDRYgPrMgZ3ctSFuKd4R4FOtckop8hkheFW+izUL6rAG5lDyF9MjOY2PVGJmXI0PJdePC4jQ+XcgcqK0XwqbBlgBujH7KFRS4azPdcfPrGQ/xfWo7lHksmE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-33b65b2e43eso2591589f8f.1 for ; Mon, 12 Feb 2024 12:02:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707768122; x=1708372922; 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=MTunuHjteKGK+MDkUrXHDgFED6l2f8cD60d695yhjEc=; b=SvsjPW589SGjopBHrNYi5JN8ZNU93jCIGoWR25DBvGMbw/sQEBFIx2/ZO60Ov9ogRP 6qQJqairFEmdspPK9oh1I8+DWYRhVk0q6VBxR0Xgu7F6DF2xoMQZpda0e7YCWbIsbZUY tP+iShUiA8l5Njh7h6ixFpChVUriSW0Qon0pPj8Jfogb3/q1PhFdtPpHAKB2WMmmwTC9 e/1QtBZ61f9y4dsDGf2WcN/g0URHI1+iOTH3kr5Q1fc6BB+a3ulzUNUH7pn37mLKVygV ekxd7O7+tDLaGobSxXcJefhAl6R7FFmHLnoRGemsi8yHcP3L/6r2rOP1sLa0Kxp1zjQI nE9g== X-Gm-Message-State: AOJu0YxORYJxuHTZFfOop+B9Tt79zVryfCoE9OKVIcKMwR2UDwOYeKik +4ALKa4vGIKSa3T+S8Cnkb/r7S+6ACsxewzIOcu+P12g82ntJqBt7oRMwffeayc= X-Google-Smtp-Source: AGHT+IFn2i/MQE3wY//X7SoBAkBIJnI//NJBZEPKzxfUsq3Zb7/APDWHQUom+FVTq93BafE2unuKNA== X-Received: by 2002:adf:f9cd:0:b0:33b:8782:b526 with SMTP id w13-20020adff9cd000000b0033b8782b526mr1490643wrr.59.1707768121957; Mon, 12 Feb 2024 12:02:01 -0800 (PST) Received: from localhost ([2001:8a0:f923:4f00:6d21:130f:e0dc:ea4b]) by smtp.gmail.com with UTF8SMTPSA id y8-20020a5d4708000000b0033b507b0abdsm7590001wrq.32.2024.02.12.12.02.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Feb 2024 12:02:01 -0800 (PST) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/3] Improve vRun error reporting Date: Mon, 12 Feb 2024 20:01:52 +0000 Message-ID: <20240212200153.882582-3-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.3 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 After the previous commit, if starting the inferior process with "run" (vRun packet) fails, GDBserver reports an error using the "E." verbose error packet. On the GDB side, however, GDB doesn't yet do anything with verbose error strings when handling vRun errors. This commit fixes that. This makes remote debugging output the same as native output, when possible, another small step in the "local/remote parity" project. E.g., before, against GNU/Linux GDBserver: (gdb) run Starting program: .../gdb.base/run-fail-twice/run-fail-twice.nox Running ".../gdb.base/run-fail-twice/run-fail-twice.nox" on the remote target failed After, against GNU/Linux GDBserver (same as native): (gdb) run Starting program: .../gdb.base/run-fail-twice/run-fail-twice.nox During startup program exited with code 126. Change-Id: Ib386f267522603f554b52a885b15229c9639e870 --- gdb/remote.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index b58dbd4cb66..dca5add260a 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2400,6 +2400,19 @@ add_packet_config_cmd (const unsigned int which_packet, const char *name, } } +/* Strings that starts with "E.", are verbose error messages, like + "E.ERROR_MESSAGE". If BUF is such an error message, return a + pointer to message after the period. Otherwise return NULL. */ + +static const char * +verbose_error_message (const char *buf) +{ + if (buf[0] == 'E' && buf[1] == '.') + return buf + 2; + else + return nullptr; +} + static enum packet_result packet_check_result (const char *buf) { @@ -2415,7 +2428,7 @@ packet_check_result (const char *buf) /* Always treat "E." as an error. This will be used for more verbose error messages, such as E.memtypes. */ - if (buf[0] == 'E' && buf[1] == '.') + if (verbose_error_message (buf) != nullptr) return PACKET_ERROR; /* The packet may or may not be OK. Just assume it is. */ @@ -10502,7 +10515,13 @@ remote_target::extended_remote_run (const std::string &args) case PACKET_UNKNOWN: return -1; case PACKET_ERROR: - if (remote_exec_file[0] == '\0') + /* If we have a verbose error message, print just that. This + makes remote debugging output the same as native output, when + possible. */ + if (const char *msg = verbose_error_message (rs->buf.data ()); + msg != nullptr) + error (("%s"), msg); + else if (remote_exec_file[0] == '\0') error (_("Running the default executable on the remote target failed; " "try \"set remote exec-file\"?")); else 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)