From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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__ -- 2.40.0