From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0FY6Iwjby2WAGR0AWB0awg (envelope-from ) for ; Tue, 13 Feb 2024 16:11:36 -0500 Received: by simark.ca (Postfix, from userid 112) id 7E2A21E0D2; Tue, 13 Feb 2024 16:11:36 -0500 (EST) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 622451E030 for ; Tue, 13 Feb 2024 16:11:34 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5ACCC3857BB0 for ; Tue, 13 Feb 2024 21:11:33 +0000 (GMT) Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by sourceware.org (Postfix) with ESMTPS id C726E3857C52 for ; Tue, 13 Feb 2024 21:11:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C726E3857C52 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 C726E3857C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707858674; cv=none; b=lgbuyqONrnd/HF/6Jz4bRK+2z09GhszMN2zMjgIsqQZ8AVCBsgRxaDlYrsqLuFV52dpIQoTpsTsFzd6UzSQzRc/ZiE3fw95tLs7M+/WmyKunOvGDxbQ9tHTOQzu8HcfDvw0dLZpQTzcrHpIBx8ds5QAmrCHIrPGQ8v7ePYOwZrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707858674; c=relaxed/simple; bh=eOvipxXwY7Xtei+ybQcYUuQFnym3F8mr8JHKMUgjDOI=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=wuL/DKZluZSUCW2RAH7Rdgy/pF3aNxAkoXa4amry8dkAYYSeyywQtLgpjUpKR5gltOVhSt5sq7ywtzxa20ILPHu1yPmDIbh8tlGPiyXd7f/2/UAxlowZUfYVZvdNSjGZToTiPeX4zAT8miq6u5b0umtMBMRQcGsKjCIXgw4Nui0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-411d231ea71so4852665e9.1 for ; Tue, 13 Feb 2024 13:11:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707858670; x=1708463470; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CUqbyejXfc6nGhMT9YEhZkDQ0PROIelSuPzMZ3oxTBQ=; b=gGrQjX965xfm9xTKI/Swu3v9iXO9QQqZAq8nkTaDtGxYYNELiBehV1Hgyv6d5JXzWv 0I3+Mkn5CkchYE6N0NCN7ycH8LrH7uR/HnNDZWukBZbsiT9YoZU8Ldy3il/mCVThvizy Aumeqr5854QWy5718yjOvOKkW6XVO0zvf5oRtVTyhUJf5eohHAi4yc9EXNJ1Xha4+Y4d V0Y2lNZci+C9j9OVL3/jVm6AHP33LzI3bQMwKifC+cwpeJXuGbvvg5d1t7g/Rd0MEDRa 0VC7564fJ4KHTLFjFHLoRJWjQJp0LqUkyfsEQq9j8LKbYXgaEIOc5Hx0oQgfsNthEIzl kHzw== X-Gm-Message-State: AOJu0YxuQz5aQvDwSpxSO8ksqsQhS3PcTsXXjZNEL7w+oKcQBUCDBMbh dR2uSDZ1Rzhm3WGxfi+YquqVTraL5ROFDi2vfVkP9Tn0atZqv4fl X-Google-Smtp-Source: AGHT+IHw+HAeNvGUlZSm8N5DLpToMiq+mgHyaJ+n1B0QHCnX26tt0hy61BK79qlOhEWBeThN8ww7Ow== X-Received: by 2002:a05:600c:3511:b0:411:ba7c:99a with SMTP id h17-20020a05600c351100b00411ba7c099amr720501wmq.38.1707858670183; Tue, 13 Feb 2024 13:11:10 -0800 (PST) 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 b13-20020a05600c11cd00b00410dd253008sm6485392wmi.42.2024.02.13.13.11.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 13 Feb 2024 13:11:09 -0800 (PST) Message-ID: Date: Tue, 13 Feb 2024 21:11:07 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] Fix "run" failure with GDBserver Content-Language: en-US To: Lancelot SIX Cc: gdb-patches@sourceware.org References: <20240212200153.882582-1-pedro@palves.net> <20240212200153.882582-2-pedro@palves.net> <20240213151701.lomtqogce7tuceu5@khazad-dum> From: Pedro Alves In-Reply-To: <20240213151701.lomtqogce7tuceu5@khazad-dum> 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, 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+public-inbox=simark.ca@sourceware.org On 2024-02-13 15:19, Lancelot SIX wrote: > Hi Pedro, Hi! > > On Mon, Feb 12, 2024 at 08:01:51PM +0000, Pedro Alves wrote: >> --- >> 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 >> > > Looks like you forgot the gdb/testsuite/gdb.base/run-fail-twice.c file? Indeed... Added now. > >> diff --git a/gdb/testsuite/gdb.base/run-fail-twice.exp b/gdb/testsuite/gdb.base/run-fail-twice.exp >> + >> +# 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 I've switched this to: require target_can_use_run_cmd >> + >> +standard_testfile >> + >> +if {[build_executable "failed to build" $testfile $srcfile {debug}]} { >> + return -1 >> +} >> + >> +proc test_run {testname} { >> + gdb_run_cmd I switched to calling "run" directly, as that's what we're testing anyhow. >> + 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" \ > > Couldn't you use gdb_test_no_output and remove the 2nd argument? I can! And I did. > >> + "" \ >> + "exec-file \$binfile.nox" >> + gdb_test "set remote exec-file $binfile.nox" \ >> + "" \ > > Same here. > Ditto. Here's the updated patch. ---- 8< ---- >From 04b71816555898fa804a76aa0412b1bad1dc9692 Mon Sep 17 00:00:00 2001 From: Pedro Alves Subject: [PATCH] Fix "run" failure with GDBserver 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.c | 20 +++++++ gdb/testsuite/gdb.base/run-fail-twice.exp | 63 +++++++++++++++++++++++ gdbserver/server.cc | 10 +++- 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/run-fail-twice.c create mode 100644 gdb/testsuite/gdb.base/run-fail-twice.exp diff --git a/gdb/testsuite/gdb.base/run-fail-twice.c b/gdb/testsuite/gdb.base/run-fail-twice.c new file mode 100644 index 00000000000..fddf841eb3e --- /dev/null +++ b/gdb/testsuite/gdb.base/run-fail-twice.c @@ -0,0 +1,20 @@ +/* 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 . */ + +int +main (int argc, char **argv) +{ + return 0; +} 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..676fc486fbf --- /dev/null +++ b/gdb/testsuite/gdb.base/run-fail-twice.exp @@ -0,0 +1,63 @@ +# 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". + +require target_can_use_run_cmd + +standard_testfile + +if {[build_executable "failed to build" $testfile $srcfile {debug}]} { + return -1 +} + +proc test_run {testname} { + gdb_test_multiple "run" $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 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_no_output \ + "exec-file $binfile.nox" \ + "exec-file \$binfile.nox" + gdb_test_no_output \ + "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 74c7763d777..14a19bc1882 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3428,7 +3428,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) { base-commit: a16034bf6417dc2259fef43fd5bcc2dd1dac562f -- 2.43.0