From patchwork Thu Jul 6 17:23:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 72265 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 64E03386C5BD for ; Thu, 6 Jul 2023 17:27:05 +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 3CD8A3857C66 for ; Thu, 6 Jul 2023 17:26:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CD8A3857C66 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 E9FB81A84BA9 for ; Thu, 6 Jul 2023 13:26:29 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v2 1/4] *-fbsd-nat: Handle null inferior in read_description. Date: Thu, 6 Jul 2023 10:23:34 -0700 Message-Id: <20230706172337.39099-2-jhb@FreeBSD.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230706172337.39099-1-jhb@FreeBSD.org> References: <20230706172337.39099-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]); Thu, 06 Jul 2023 13:26:30 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.1 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..38fb093f139 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 this->beneath ()->read_description (); + 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..43e83ff2485 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 this->beneath ()->read_description (); + 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..a2255c3c26b 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 this->beneath ()->read_description (); + #ifdef PT_GETXSTATE_INFO if (!xsave_probed) { From patchwork Thu Jul 6 17:23:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 72264 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 F2E2F3853D26 for ; Thu, 6 Jul 2023 17:27:04 +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 D431A3858D33 for ; Thu, 6 Jul 2023 17:26:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D431A3858D33 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 81D021A84C72 for ; Thu, 6 Jul 2023 13:26:30 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v2 2/4] *-linux-nat: Handle null inferior in read_description. Date: Thu, 6 Jul 2023 10:23:35 -0700 Message-Id: <20230706172337.39099-3-jhb@FreeBSD.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230706172337.39099-1-jhb@FreeBSD.org> References: <20230706172337.39099-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]); Thu, 06 Jul 2023 13:26:30 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.1 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 | 4 ++++ 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, 22 insertions(+) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index ecb2eeb9540..eeb9761bfe5 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 this->beneath ()->read_description (); + 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..8a7cc95f2a4 100644 --- a/gdb/mips-linux-nat.c +++ b/gdb/mips-linux-nat.c @@ -458,6 +458,10 @@ mips_linux_nat_target::read_description () if (have_dsp < 0) { + /* Assume no DSP if there is no inferior to inspect with ptrace. */ + if (inferior_ptid == null_ptid) + return _MIPS_SIM == _ABIO32 ? tdesc_mips_linux : tdesc_mips64_linux; + int tid = get_ptrace_pid (inferior_ptid); errno = 0; diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c index 55dcda9f525..d14aba694e5 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 this->beneath ()->read_description (); + 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..9492cb68079 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 this->beneath ()->read_description (); + 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..8f54e9f6322 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 this->beneath ()->read_description (); + 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..ca4eaf5b645 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 this->beneath ()->read_description (); + tid = inferior_ptid.pid (); #ifdef __x86_64__ From patchwork Thu Jul 6 17:23:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 72262 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 8F6CB385B800 for ; Thu, 6 Jul 2023 17:26:47 +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 E0A043858C2D for ; Thu, 6 Jul 2023 17:26:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0A043858C2D 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 1BD881A84E1C for ; Thu, 6 Jul 2023 13:26:31 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v2 3/4] Add a have_native_target helper function for use with require. Date: Thu, 6 Jul 2023 10:23:36 -0700 Message-Id: <20230706172337.39099-4-jhb@FreeBSD.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230706172337.39099-1-jhb@FreeBSD.org> References: <20230706172337.39099-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]); Thu, 06 Jul 2023 13:26:31 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.1 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 | 14 ++++++++++++++ 2 files changed, 15 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 b4900ae25a6..0a7c593672a 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -9807,6 +9807,20 @@ 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 {} { + gdb_test_multiple "help target native" "" { + -re -wrap "Undefined target command.*" { + return 0 + } + -re -wrap "Native process.*" { + return 1 + } + } + return 0 +} + # Handle include file $srcdir/$subdir/FILE. proc include_file { file } { From patchwork Thu Jul 6 17:23:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 72263 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 0F44E385DC13 for ; Thu, 6 Jul 2023 17:26:48 +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 E06293858C74 for ; Thu, 6 Jul 2023 17:26:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E06293858C74 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 A932D1A84E2C for ; Thu, 6 Jul 2023 13:26:31 -0400 (EDT) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v2 4/4] Test that native targets can read a tdesc without a process attached. Date: Thu, 6 Jul 2023 10:23:37 -0700 Message-Id: <20230706172337.39099-5-jhb@FreeBSD.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230706172337.39099-1-jhb@FreeBSD.org> References: <20230706172337.39099-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]); Thu, 06 Jul 2023 13:26:31 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.103.1 at mail.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-12.1 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"