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) {