From patchwork Fri Apr 19 15:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 88747 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 9B1E03844744 for ; Fri, 19 Apr 2024 15:15:45 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by sourceware.org (Postfix) with ESMTPS id 9BBC03849AE8 for ; Fri, 19 Apr 2024 15:14:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BBC03849AE8 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 9BBC03849AE8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713539644; cv=none; b=TG/LELcQoOz2KClllh6ttoZGqGZ6EkBMnZhIsYHh45JWx3yB+u3WBQBfyqg1/1S9CMh8xI88s7mQY5yhMrTqi4pWkWH0RgXToQG0F/Tg/LzmB0MZX+ttHCA8dGDmwAoiKvCm1E/1EiYVhJviWnEBLMhmu8P40j3i7kdRf7+5Dhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713539644; c=relaxed/simple; bh=NYHaXGe685prUsveuwIrTm7tU1PFws8zQdEdsukwfgM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=FCfR2UPnNV2QgmfRVvuHqG2GfNEQfCmmiGf5DEH0W8wP71klDK1DQzJQ/bgQNKSSPuFFxOfuwFK/rabKQOXl9iC/HYZVyHOiSYpHx3mi5lW8/pviQ0rOMAUypwteKSFFOytA4o7tFTvlCZsgwy6PwjzkF4TYuEg9huVXOaJSLk4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-419c8c314d4so2560495e9.0 for ; Fri, 19 Apr 2024 08:14:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713539640; x=1714144440; 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=z+6mVsoR+YRDsQk5fTTG99oznTAZPszt3Rwfx9KY+vU=; b=hMFlaV7Tv5mdoy0glCC18AN2zBQ4VkowMUXI6NIntYq9oiNho3+z/86+eh70CCPQzb EBB+uyKosDKeNfyrwqfjySZ/IuWfCVuxUpjH0h5qXOJGi5WFVomTwCBCH8p717gunrdX aZeW4mzE/6LQ9Kc2SW2BeAai03acurgHupPypJK1UkVsT3cSbr0Q4H0/fe2r4IL+URyA AnZ9zYJObCL9Z9kZmhwTzOsGn1G1iKyDPTLz4zXatxOXRJjvp/flnqlQu3WDHGg5y/dD wozGoj/DVbipum+bbbF9C5mn3HlNO8zav2uhYKreXFYOs44JmU6uW3vXyAmUkA6vZ/+e nhdw== X-Gm-Message-State: AOJu0YyU0JUbX+hSYq1XzfFuw7eijo8T1lTbggpAZksw4CFtneTF7Rk5 WEB0p3ox1/x1uMSlFjDWY92CLZagygMKzWhU4r8N+xMxJs7ZxL5iqa+m4SLS X-Google-Smtp-Source: AGHT+IHIE7Yrv6ZwRcyEI0e5lr+WSrq7x+FS1Ydgni0J+SHNnFJYXuOuGT43zFn3BsxLEv4GGJDj+g== X-Received: by 2002:a05:600c:3acd:b0:419:b36:7e43 with SMTP id d13-20020a05600c3acd00b004190b367e43mr1494331wms.7.1713539639536; Fri, 19 Apr 2024 08:13:59 -0700 (PDT) Received: from localhost ([2001:8a0:f93d:b900:2438:d637:5572:c30a]) by smtp.gmail.com with UTF8SMTPSA id r18-20020a05600c35d200b00418d434ae4esm6795860wmq.10.2024.04.19.08.13.58 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Apr 2024 08:13:59 -0700 (PDT) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 05/12] Fix "run" failure handling with GDBserver Date: Fri, 19 Apr 2024 16:13:35 +0100 Message-ID: <20240419151342.1592474-6-pedro@palves.net> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240419151342.1592474-1-pedro@palves.net> References: <20240419151342.1592474-1-pedro@palves.net> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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 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.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 c7d5cc1c1b0..b170da44f6a 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -3427,7 +3427,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) {