From patchwork Fri May 26 17:57:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 70169 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 6CBE838555B9 for ; Fri, 26 May 2023 17:58:16 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 1B3C83857711 for ; Fri, 26 May 2023 17:58:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B3C83857711 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from ralph.baldwin.net (c-98-35-126-114.hsd1.ca.comcast.net [98.35.126.114]) by mail.baldwin.cx (Postfix) with ESMTPSA id B83D61A84BA9 for ; Fri, 26 May 2023 13:57:56 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 1/4] *-fbsd-nat: Handle null inferior in read_description. Date: Fri, 26 May 2023 10:57:39 -0700 Message-Id: <20230526175742.66885-2-jhb@FreeBSD.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230526175742.66885-1-jhb@FreeBSD.org> References: <20230526175742.66885-1-jhb@FreeBSD.org> MIME-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Fri, 26 May 2023 13:57:57 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KHOP_HELO_FCRDNS, SPF_HELO_PASS, SPF_SOFTFAIL, 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.29 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 Sender: "Gdb-patches" Don't invoke ptrace in the target read_description method if there is not an active inferior to query via ptrace. Instead, use the default register set for the architecture. Previously the native target could report an error from a failed ptrace operation when fetching a tdesc without an attached process. For example on FreeBSD/amd64: (gdb) target native Done. Use the "run" command to start a process. (gdb) unset tdesc filename Couldn't get registers: Operation not permitted. --- gdb/aarch64-fbsd-nat.c | 3 +++ gdb/amd64-fbsd-nat.c | 3 +++ gdb/arm-fbsd-nat.c | 3 +++ gdb/i386-fbsd-nat.c | 3 +++ 4 files changed, 12 insertions(+) diff --git a/gdb/aarch64-fbsd-nat.c b/gdb/aarch64-fbsd-nat.c index 709f5162ce0..29b58e5ff4a 100644 --- a/gdb/aarch64-fbsd-nat.c +++ b/gdb/aarch64-fbsd-nat.c @@ -120,6 +120,9 @@ aarch64_fbsd_nat_target::store_registers (struct regcache *regcache, const struct target_desc * aarch64_fbsd_nat_target::read_description () { + if (inferior_ptid == null_ptid) + return nullptr; + aarch64_features features; features.tls = have_regset (inferior_ptid, NT_ARM_TLS)? 1 : 0; return aarch64_read_description (features); diff --git a/gdb/amd64-fbsd-nat.c b/gdb/amd64-fbsd-nat.c index bae267f230f..adbd85571a5 100644 --- a/gdb/amd64-fbsd-nat.c +++ b/gdb/amd64-fbsd-nat.c @@ -310,6 +310,9 @@ amd64_fbsd_nat_target::read_description () struct reg regs; int is64; + if (inferior_ptid == null_ptid) + return nullptr; + if (ptrace (PT_GETREGS, inferior_ptid.pid (), (PTRACE_TYPE_ARG3) ®s, 0) == -1) perror_with_name (_("Couldn't get registers")); diff --git a/gdb/arm-fbsd-nat.c b/gdb/arm-fbsd-nat.c index 5181281b27d..cf22fc6cce9 100644 --- a/gdb/arm-fbsd-nat.c +++ b/gdb/arm-fbsd-nat.c @@ -93,6 +93,9 @@ arm_fbsd_nat_target::read_description () const struct target_desc *desc; bool tls = false; + if (inferior_ptid == null_ptid) + return this->beneath ()->read_description (); + #ifdef PT_GETREGSET tls = have_regset (inferior_ptid, NT_ARM_TLS) != 0; #endif diff --git a/gdb/i386-fbsd-nat.c b/gdb/i386-fbsd-nat.c index 927771e8b20..26ae420949e 100644 --- a/gdb/i386-fbsd-nat.c +++ b/gdb/i386-fbsd-nat.c @@ -315,6 +315,9 @@ i386_fbsd_nat_target::read_description () #endif static int xmm_probed; + if (inferior_ptid == null_ptid) + return nullptr; + #ifdef PT_GETXSTATE_INFO if (!xsave_probed) { From patchwork Fri May 26 17:57:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 70170 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 207E03855587 for ; Fri, 26 May 2023 17:58:22 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id D7820385770A for ; Fri, 26 May 2023 17:57:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7820385770A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from ralph.baldwin.net (c-98-35-126-114.hsd1.ca.comcast.net [98.35.126.114]) by mail.baldwin.cx (Postfix) with ESMTPSA id 5A3A71A84C54 for ; Fri, 26 May 2023 13:57:57 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 2/4] *-linux-nat: Handle null inferior in read_description. Date: Fri, 26 May 2023 10:57:40 -0700 Message-Id: <20230526175742.66885-3-jhb@FreeBSD.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230526175742.66885-1-jhb@FreeBSD.org> References: <20230526175742.66885-1-jhb@FreeBSD.org> MIME-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Fri, 26 May 2023 13:57:57 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KHOP_HELO_FCRDNS, SPF_HELO_PASS, SPF_SOFTFAIL, 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.29 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 Sender: "Gdb-patches" Don't invoke ptrace in the target read_description method if there is not an active inferior to query via ptrace. Instead, use the default register set for the architecture. Previously the native target could report an error from a failed ptrace operation when fetching a tdesc without an attached process. For example on Linux x86-64: (gdb) target native Done. Use the "run" command to start a process. (gdb) unset tdesc filename Couldn't get CS register: No such process. --- gdb/aarch64-linux-nat.c | 3 +++ gdb/arm-linux-nat.c | 3 +++ gdb/mips-linux-nat.c | 3 +++ gdb/ppc-linux-nat.c | 3 +++ gdb/riscv-linux-nat.c | 3 +++ gdb/s390-linux-nat.c | 3 +++ gdb/x86-linux-nat.c | 3 +++ 7 files changed, 21 insertions(+) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index ecb2eeb9540..62f8825b9c8 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -785,6 +785,9 @@ aarch64_linux_nat_target::read_description () gdb_byte regbuf[ARM_VFP3_REGS_SIZE]; struct iovec iovec; + if (inferior_ptid == null_ptid) + return nullptr; + tid = inferior_ptid.pid (); iovec.iov_base = regbuf; diff --git a/gdb/arm-linux-nat.c b/gdb/arm-linux-nat.c index ef3fa008adf..70c6bc684fa 100644 --- a/gdb/arm-linux-nat.c +++ b/gdb/arm-linux-nat.c @@ -531,6 +531,9 @@ ps_get_thread_area (struct ps_prochandle *ph, const struct target_desc * arm_linux_nat_target::read_description () { + if (inferior_ptid == null_ptid) + return this->beneath ()->read_description (); + CORE_ADDR arm_hwcap = linux_get_hwcap (); if (have_ptrace_getregset == TRIBOOL_UNKNOWN) diff --git a/gdb/mips-linux-nat.c b/gdb/mips-linux-nat.c index 972b5db8e76..1fa0e8c479c 100644 --- a/gdb/mips-linux-nat.c +++ b/gdb/mips-linux-nat.c @@ -454,6 +454,9 @@ mips_linux_nat_target::register_u_offset (struct gdbarch *gdbarch, const struct target_desc * mips_linux_nat_target::read_description () { + if (inferior_ptid == null_ptid) + return _MIPS_SIM == _ABIO32 ? tdesc_mips_linux : tdesc_mips64_linux; + static int have_dsp = -1; if (have_dsp < 0) diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c index 42885deb45e..2f4799aa73a 100644 --- a/gdb/ppc-linux-nat.c +++ b/gdb/ppc-linux-nat.c @@ -1941,6 +1941,9 @@ ppc_linux_nat_target::auxv_parse (const gdb_byte **readptr, const struct target_desc * ppc_linux_nat_target::read_description () { + if (inferior_ptid == null_ptid) + return ppc_linux_match_description (ppc_linux_no_features); + int tid = inferior_ptid.pid (); if (have_ptrace_getsetevrregs) diff --git a/gdb/riscv-linux-nat.c b/gdb/riscv-linux-nat.c index 8be4a5ac3e5..5d325e633da 100644 --- a/gdb/riscv-linux-nat.c +++ b/gdb/riscv-linux-nat.c @@ -201,6 +201,9 @@ fill_fpregset (const struct regcache *regcache, prfpregset_t *fpregs, const struct target_desc * riscv_linux_nat_target::read_description () { + if (inferior_ptid == null_ptid) + return nullptr; + const struct riscv_gdbarch_features features = riscv_linux_read_features (inferior_ptid.pid ()); return riscv_lookup_target_description (features); diff --git a/gdb/s390-linux-nat.c b/gdb/s390-linux-nat.c index fc3917d30be..7d3b3cfe78b 100644 --- a/gdb/s390-linux-nat.c +++ b/gdb/s390-linux-nat.c @@ -987,6 +987,9 @@ s390_linux_nat_target::auxv_parse (const gdb_byte **readptr, const struct target_desc * s390_linux_nat_target::read_description () { + if (inferior_ptid == null_ptid) + return nullptr; + int tid = inferior_ptid.pid (); have_regset_last_break diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index fd2145244cc..87862b89eab 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -115,6 +115,9 @@ x86_linux_nat_target::read_description () static uint64_t xcr0; uint64_t xcr0_features_bits; + if (inferior_ptid == null_ptid) + return nullptr; + tid = inferior_ptid.pid (); #ifdef __x86_64__ From patchwork Fri May 26 17:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 70171 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 85B9238498E0 for ; Fri, 26 May 2023 17:58:24 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [IPv6:2607:f138:0:13::2]) by sourceware.org (Postfix) with ESMTPS id C55E23858289 for ; Fri, 26 May 2023 17:57:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C55E23858289 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from ralph.baldwin.net (c-98-35-126-114.hsd1.ca.comcast.net [98.35.126.114]) by mail.baldwin.cx (Postfix) with ESMTPSA id EAC031A84C5E for ; Fri, 26 May 2023 13:57:57 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 3/4] Add a have_native_target helper function for use with require. Date: Fri, 26 May 2023 10:57:41 -0700 Message-Id: <20230526175742.66885-4-jhb@FreeBSD.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230526175742.66885-1-jhb@FreeBSD.org> References: <20230526175742.66885-1-jhb@FreeBSD.org> MIME-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Fri, 26 May 2023 13:57:58 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KHOP_HELO_FCRDNS, SPF_HELO_PASS, SPF_SOFTFAIL, 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.29 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 Sender: "Gdb-patches" Move logic from auto-connect-native-target.exp into this helper. --- .../gdb.base/auto-connect-native-target.exp | 18 +----------------- gdb/testsuite/lib/gdb.exp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/gdb/testsuite/gdb.base/auto-connect-native-target.exp b/gdb/testsuite/gdb.base/auto-connect-native-target.exp index 002a6d61126..0586cd4baf4 100644 --- a/gdb/testsuite/gdb.base/auto-connect-native-target.exp +++ b/gdb/testsuite/gdb.base/auto-connect-native-target.exp @@ -22,23 +22,7 @@ if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { return -1 } -# Whether this GDB is configured with a "native" target. -set have_native 0 - -set test "help target native" -gdb_test_multiple $test $test { - -re "Undefined target command.*$gdb_prompt $" { - set have_native 0 - } - -re "Native process.*$gdb_prompt $" { - set have_native 1 - } -} - -if { !$have_native } { - unsupported "no \"target native\" support." - return -} +require have_native_target # Returns the topmost target pushed on the target stack. TEST is used # as test message. diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 133d914aff8..128c0779b69 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -9739,6 +9739,23 @@ gdb_caching_proc have_compile_and_link_flag { flag } { additional_flags=$flag] } +# Return 1 if this GDB is configured with a "native" target. + +gdb_caching_proc have_native_target {} { + global gdb_prompt + + set test "help target native" + gdb_test_multiple $test $test { + -re "Undefined target command.*$gdb_prompt $" { + return 0 + } + -re "Native process.*$gdb_prompt $" { + return 1 + } + } + return 0 +} + # Handle include file $srcdir/$subdir/FILE. proc include_file { file } { From patchwork Fri May 26 17:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 70172 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 13F6E3853D08 for ; Fri, 26 May 2023 17:58:41 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail.baldwin.cx (bigwig.baldwin.cx [66.216.25.90]) by sourceware.org (Postfix) with ESMTPS id 209783857717 for ; Fri, 26 May 2023 17:58:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 209783857717 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=FreeBSD.org Received: from ralph.baldwin.net (c-98-35-126-114.hsd1.ca.comcast.net [98.35.126.114]) by mail.baldwin.cx (Postfix) with ESMTPSA id 857AA1A84C6B for ; Fri, 26 May 2023 13:57:58 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH 4/4] Test that native targets can read a tdesc without a process attached. Date: Fri, 26 May 2023 10:57:42 -0700 Message-Id: <20230526175742.66885-5-jhb@FreeBSD.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230526175742.66885-1-jhb@FreeBSD.org> References: <20230526175742.66885-1-jhb@FreeBSD.org> MIME-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.4 (mail.baldwin.cx [0.0.0.0]); Fri, 26 May 2023 13:57:58 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, KHOP_HELO_FCRDNS, SPF_HELO_PASS, SPF_SOFTFAIL, 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.29 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 Sender: "Gdb-patches" This ensures that 'unset tdesc filename' does not generate any output on a "bare" native target inferior without an attached process. --- .../gdb.base/native-target-noproc-tdesc.exp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 gdb/testsuite/gdb.base/native-target-noproc-tdesc.exp diff --git a/gdb/testsuite/gdb.base/native-target-noproc-tdesc.exp b/gdb/testsuite/gdb.base/native-target-noproc-tdesc.exp new file mode 100644 index 00000000000..820d9941c71 --- /dev/null +++ b/gdb/testsuite/gdb.base/native-target-noproc-tdesc.exp @@ -0,0 +1,27 @@ +# Copyright 2023 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 "unset tdesc filename" without an attached process on native +# targets. + +clean_restart + +require have_native_target + +# Manually attach the native target +gdb_test "target native" "Done. Use the \"run\" command to start a process." + +# Load a default target description +gdb_test_no_output "unset tdesc filename"