From patchwork Fri Dec 1 16:27:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 81156 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 46EF8384F983 for ; Fri, 1 Dec 2023 16:32:55 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 07616386182E for ; Fri, 1 Dec 2023 16:32:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07616386182E Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 07616386182E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701448323; cv=none; b=u1Kf5RcvJjB5CTKklTXS1STt90oUazj3SqZNUYT6v8xP/9PkJsjynzkZihPJ1Agfzs+Kvt3lR7ExEKxczthLTQ8LnCVZ1TTCQKl8F2T0byRCWVtF/VzguYAYfCrAyfW3jqoR/IyLVBvmqdEw3+k0y/7zpDOzQSPr5TQpGItnngs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701448323; c=relaxed/simple; bh=l3qD/yMsCxZlDeV3t7cIz6HXBOb086Bl+KNamBlR31U=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NkyWWaPSkcm09tdcMUVQfJSwk3MfAR3bdmOKSezoo/XTETD1L1O9vrUpSr2DDEDoZEn0W2CNccyShlmqDzfpGiTifSBHHSIXNRmD8OGUTdEMT/AgxK/kuk4NiaczUfeH6Nt9R7H9JTmjl7T1/NM2LSP89wePjvMTpBC7dZ3hVnE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smarchi-efficios.internal.efficios.com (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (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 ESMTPSA id 19EF21E1A8; Fri, 1 Dec 2023 11:32:00 -0500 (EST) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Luis Machado , John Baldwin , "Aktemur, Tankut Baris" , Simon Marchi , John Baldwin Subject: [PATCH 22/24] gdb: migrate arm to gdbarch_pseudo_register_read_value Date: Fri, 1 Dec 2023 11:27:35 -0500 Message-ID: <20231201162751.741751-23-simon.marchi@efficios.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231201162751.741751-1-simon.marchi@efficios.com> References: <20231201162751.741751-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3496.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, 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.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 Make arm use the "newer" gdbarch_pseudo_register_read_value. This fixes reading pseudo registers in non-current frames on that architecture. Change-Id: Ic4d3d5d96957a4addfa3443c7b567dc4a31794a9 Reviewed-By: John Baldwin Approved-by: Luis Machado --- gdb/arm-tdep.c | 76 +++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index 85fd37ba73a0..36ca867da5c2 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -9816,61 +9816,73 @@ arm_neon_quad_read (struct gdbarch *gdbarch, readable_regcache *regcache, return REG_VALID; } -/* Read the contents of the MVE pseudo register REGNUM and store it - in BUF. */ +/* Read the contents of a NEON quad register, by reading from two double + registers, and return it as a value. QUAD_REG_INDEX is the index of the quad + register, in [0, 15]. */ -static enum register_status -arm_mve_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache, - int regnum, gdb_byte *buf) +static value * +arm_neon_quad_read_value (gdbarch *gdbarch, frame_info_ptr next_frame, + int pseudo_reg_num, int quad_reg_index) +{ + std::string raw_reg_name = string_printf ("d%d", quad_reg_index << 1); + int double_regnum + = user_reg_map_name_to_regnum (gdbarch, raw_reg_name.c_str (), + raw_reg_name.length ()); + + return pseudo_from_concat_raw (next_frame, pseudo_reg_num, double_regnum, + double_regnum + 1); +} + +/* Read the contents of the MVE pseudo register REGNUM and return it as a + value. */ +static value * +arm_mve_pseudo_read_value (gdbarch *gdbarch, frame_info_ptr next_frame, + int pseudo_reg_num) { arm_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); /* P0 is the first 16 bits of VPR. */ - return regcache->raw_read_part (tdep->mve_vpr_regnum, 0, 2, buf); + return pseudo_from_raw_part (next_frame, pseudo_reg_num, + tdep->mve_vpr_regnum, 0); } -static enum register_status -arm_pseudo_read (struct gdbarch *gdbarch, readable_regcache *regcache, - int regnum, gdb_byte *buf) +static value * +arm_pseudo_read_value (gdbarch *gdbarch, frame_info_ptr next_frame, + const int pseudo_reg_num) { - const int num_regs = gdbarch_num_regs (gdbarch); - char name_buf[4]; - gdb_byte reg_buf[8]; - int offset, double_regnum; arm_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - gdb_assert (regnum >= num_regs); + gdb_assert (pseudo_reg_num >= gdbarch_num_regs (gdbarch)); - if (is_q_pseudo (gdbarch, regnum)) + if (is_q_pseudo (gdbarch, pseudo_reg_num)) { /* Quad-precision register. */ - return arm_neon_quad_read (gdbarch, regcache, - regnum - tdep->q_pseudo_base, buf); + return arm_neon_quad_read_value (gdbarch, next_frame, pseudo_reg_num, + pseudo_reg_num - tdep->q_pseudo_base); } - else if (is_mve_pseudo (gdbarch, regnum)) - return arm_mve_pseudo_read (gdbarch, regcache, regnum, buf); + else if (is_mve_pseudo (gdbarch, pseudo_reg_num)) + return arm_mve_pseudo_read_value (gdbarch, next_frame, pseudo_reg_num); else { - enum register_status status; + int s_reg_index = pseudo_reg_num - tdep->s_pseudo_base; - regnum -= tdep->s_pseudo_base; /* Single-precision register. */ - gdb_assert (regnum < 32); + gdb_assert (s_reg_index < 32); /* s0 is always the least significant half of d0. */ + int offset; if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) - offset = (regnum & 1) ? 0 : 4; + offset = (s_reg_index & 1) ? 0 : 4; else - offset = (regnum & 1) ? 4 : 0; + offset = (s_reg_index & 1) ? 4 : 0; - xsnprintf (name_buf, sizeof (name_buf), "d%d", regnum >> 1); - double_regnum = user_reg_map_name_to_regnum (gdbarch, name_buf, - strlen (name_buf)); + std::string raw_reg_name = string_printf ("d%d", s_reg_index >> 1); + int double_regnum + = user_reg_map_name_to_regnum (gdbarch, raw_reg_name.c_str (), + raw_reg_name.length ()); - status = regcache->raw_read (double_regnum, reg_buf); - if (status == REG_VALID) - memcpy (buf, reg_buf + offset, 4); - return status; + return pseudo_from_raw_part (next_frame, pseudo_reg_num, double_regnum, + offset); } } @@ -10905,7 +10917,7 @@ arm_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) if (tdep->have_s_pseudos || have_mve || have_pacbti) { set_gdbarch_num_pseudo_regs (gdbarch, num_pseudos); - set_gdbarch_pseudo_register_read (gdbarch, arm_pseudo_read); + set_gdbarch_pseudo_register_read_value (gdbarch, arm_pseudo_read_value); set_gdbarch_deprecated_pseudo_register_write (gdbarch, arm_pseudo_write); }