From patchwork Wed Jan 15 16:42:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciaran Woodward X-Patchwork-Id: 104845 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 8CEE43851A8C for ; Wed, 15 Jan 2025 16:43:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CEE43851A8C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=xmos1.onmicrosoft.com header.i=@xmos1.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-xmos1-onmicrosoft-com header.b=k4q90mNf X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on20720.outbound.protection.outlook.com [IPv6:2a01:111:f403:260e::720]) by sourceware.org (Postfix) with ESMTPS id 7A92D3851A81 for ; Wed, 15 Jan 2025 16:42:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A92D3851A81 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=xmos.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xmos.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7A92D3851A81 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:260e::720 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1736959378; cv=pass; b=E+9saKJn7W6N+cntXpWfkcBGzalAJrdp8hJkYSQfdCXVpne1n8Yp1v92r32iVtvkPmYdSCWyBSST6GB6SYIsJP7CwoIaOkMCIgtSRbhuHbO1h3nKzo6kSd99iAH77w2V1vt0lIyquElS/MV5vuvwknwBx65FLfTb+O3qvg+kNuM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1736959378; c=relaxed/simple; bh=TRJAQWVtf3IzPxanGUplpOlV3TEyLzuSYxetyD5SfBE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=QxCDWgzHPUacK2XsrKBntIT0+25qb3vv+v52o2/w2LRZtOxC0Zzxd+jwi0d1QcT+hoAX3tiTIC2zD1bhy2fooPLHfDsDBfD5VhohYBeGhQIiua6rTWnAo5QZ1yDUZnH9O8Pf1XceFWCukrtL0SGIKevgIad2DXcApQUMGo85J2E= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A92D3851A81 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kcw38eQfi4QPMAA+ve67kjCtn+0UGF73OlpEcrA8rgqSf/vC4SlQGbRo3mX+msqSz7BvPexYq6/AaKaXzNGfyB7+9rnsbgTQSurZocXFJw82P2lLmtsZRb1veBHueWixnL3IM/mcnC8CdrSKTS9cVXzO0ryl2n413EVTSrLSqYUd3JH2NMHKCg87FZ9WjteEsL0RajWTsxCoC+2umZKiY3CVTTleYEKFwC8pwu7yy9nzkTnzyc4RSWMkgOgETJIxtwjqcZiEnOBJinuuqoEF6ZtZc34YHAg0d0dUPH9qS95NgiMgEcz6VOGrYuHXEkJAMuPoEoul33A8MapK0onvEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ha6hrIuqJ5AcjyXSOnGVl/E9HuM80pWwRM+GV0fFh9o=; b=JHtFTaeXIVLcCaGQaQ815CNSoewxlUqrSw8gLaznpGeocZB2XXW+70mDqSlBZEl5Vp8q835yatO/9iVDgeAhYElKT2erkfLQo0McJR5Rh6u+MyMYxPJrAHssG8rnV/73eYNFuZTCAVIkHY8Y2ffLSJIvSEzBGizStYjxH4BeuQPuB+hvMRtXg9gM2jb305pEzSbVnugVK75/tAjlM8ERNWypC/yn9lVaUftBUTnv7nAzwr+lrTR3nvmoM2wPdnATQmMuO7nRnY6BrEvTw8xmUB8KJ0Y7TqQldyYt9EakShwp7bnvOqY9jysCn5R+LPor2OF9kFeSdnby4+WqDtZWIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=xmos.com; dmarc=pass action=none header.from=xmos.com; dkim=pass header.d=xmos.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xmos1.onmicrosoft.com; s=selector2-xmos1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ha6hrIuqJ5AcjyXSOnGVl/E9HuM80pWwRM+GV0fFh9o=; b=k4q90mNfQFNezzUcpJ0ZKbPiz9PvgSUv2XRz7L3ImDVQqmFYMT/AqFx8lNPhAi9jJrJ8Z+51GJXW8YdecBvQEcdfAgB4reWFSSDLC1AXrmeebje8e9+QQeRQtO+ODQNdX/Z6mIrePQTx9I1t27XA6tgVmAajWrmcmnAEKjzZMJk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=xmos.com; Received: from PAXPR09MB5583.eurprd09.prod.outlook.com (2603:10a6:102:280::6) by AS8PR09MB6140.eurprd09.prod.outlook.com (2603:10a6:20b:5bd::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.13; Wed, 15 Jan 2025 16:42:55 +0000 Received: from PAXPR09MB5583.eurprd09.prod.outlook.com ([fe80::a234:3031:e3c0:bab9]) by PAXPR09MB5583.eurprd09.prod.outlook.com ([fe80::a234:3031:e3c0:bab9%4]) with mapi id 15.20.8335.015; Wed, 15 Jan 2025 16:42:54 +0000 From: Ciaran Woodward To: gdb-patches@sourceware.org Cc: tom@tromey.com, aburgess@redhat.com, Ciaran Woodward Subject: [PATCH v2 1/1] gdb/riscv: Add command to switch between numeric & abi register names Date: Wed, 15 Jan 2025 16:42:32 +0000 Message-Id: <20250115164232.13090-1-ciaranwoodward@xmos.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: DX0P273CA0096.AREP273.PROD.OUTLOOK.COM (2603:1086:300:5c::17) To PAXPR09MB5583.eurprd09.prod.outlook.com (2603:10a6:102:280::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR09MB5583:EE_|AS8PR09MB6140:EE_ X-MS-Office365-Filtering-Correlation-Id: 56613936-6de6-41a4-8e19-08dd3583a8ce X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: H121PC1Ln9sr7WZ/oEOEwsUV8Z3t0nojfnf/5ZAkNfRDIsPwrM6eA3Jvxk/MNoZOfDOGFpdiimI/jAWUBZL7MW2WuYJn9zX5fwpE3pFKcL61dT5KkqT/IMuciTVI5v3bkZcQ4kDlGvKSGmrNrpxmKcw2lJYOb+eeZrQ/ooZhg+Mpd2v42HZwhPESTQaKo6Us34+ZFEjTyr3tpNmZ9/k0yTzKPy/b2VLysP4LyOO4aMySohpiWxZyS/5MNETZa3jJFqTBn4XRBuAaji3uz5wKp5dndo+StWU0ukgSECbNxF22cWCnsvwacx+35rBnjCYTML0CDc5DCFxhz6Rvqt43r0Er5S7p4PKaywz9/vTGn4OS4YvJHDcSZrEBLvdwXD1e3hBJ/BRy3/CHuEe7+npiohskL4Fl5nT6B8r2aivvNStfO6YKdfBadPBd1Z1uvUGVbgQLb2Orfw9oPKxCBceXNrVYo4m6xfiJYnslwU/TIEr8M1R4nV4WuiLUNDmL44DC6KH0Ijr8C7eFqzt83GMiKJ+q4NzAk1iylofIEuv2GiNMGUw8pelbAsDrltF5GwEbI6CY2WT1+IQBJuAr6OK99OwyuC9Q6w5HvtAY78t/CBMwEr6ApFIu7L+U2rqtia3JmWIS2Yvzd6M0D90jm/LZk5GwYo8rMUaoMUjaXGQaNMtYVdnSt6l79loRtDS+jY5kN92uGIbFRMY5pUBd/WOkymP87INA9PmB2fH9SslVgAi2WMmJg7zmewZpqXc64Zq6CIdLGVLDxYAeY10fjsfwfy2ydWtXKiOO7e+wXSVrxisFSPdya4ijLe/1A070tD5BVR/MDhTKP/HPDBAano7UOqo68/rbx5ij9AYYOZlQ/rmVT0xcu4QIsrywROvKRnrBW9nnwZ21ueA+YmXwLJaU135ZZlIez5I+bMdrgDtqyvzyc58Qtj9nMQ8OOi84juZntmVNYVPedYlGtx/Qzsc/lRIv/07jA6Z9jrMJw9TwHltxblxzSBzuPwBuYN4f69ndKaysycFI43zxDFkW+XVvioLEwY9aBfKT5LA1kJoB96Ii9zrhHpfpD7hfLqJ0hLC1KqGnkri2uLU/nLO82ZY6ArHO3nJcfAof1lZihZ8U85ovOpQaRNfdAb6B3BvaM4laE+h0x+6MggDQD9aJBefGqV6FOHEFFEtM3LwRM9wg07AGlt3H9+KX8FjjkCFXvH/kbkACtf6vvtXmavC3kYNEpeVcmdFYoQdOZ7eOzg+zrpBwtigzt8FfkX//hEbswnPe5xnT7TqswwmzFR7Nr3xxZk52lMDwAkH+KIEz4XGsmLrkj2hzo7Ax+dl/vFQLSzzO+AL1D6nBTq7pgjxp1VEPVcVM7a2Giz8urbNs/Dlfwfqo2dAc4fv8xYXq7n5RaKCWBKu+mvvstowjUBVznNPsNG72mGfdzZMTg9zd4bGwmmwi01dUOjcY5zmyFlygTZXM X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR09MB5583.eurprd09.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(52116014)(376014)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5u+GQAp171QSpph/jLZfGfyFB7GKku7yOh7N3kJmP3rpZ4IB7XxhMuSh9l537CJmay0X+/h8VreVTQ+bDgSKAaJmeC+qorRHA6u+ntKFqzlS3oPO7vrHErWnuyzMDgidiyA1fVdoHO1FA93R/ugFiJBBgQzE9KQJ4yKtTLIGX+Z9fEs7x2xW1QfUkNer7hDPvfrel6lHrxT1FkfibBb0nyrbv2SDUSigPv6bsZJYl1dL6WyFqhv56VObZhtw9YyVbU1Lm9tSZtKz5yX92OehECH6/3c5/OpP1A8ikDtf90dFUxjEk1CIMddfzVi8TDzZvhV64Fye9yKk3WnBp7jUnSScKoXSxmq3WbMQ3T/41CLtTZIkmtr0EgZ4hvwHCuxTxVP6txeyl5LrQJSX8U4CwAvYFzYoqPsv87gTTX43yapZYhOEja3T+xuHycCMJVrZm5g8EBIOevGO6KUOEnz4ovODIeTWcCUVE8NOO7P4NtqdeGxAqyucRxiOx4hEeZt2YtkXgMYyqPUavP+ldW8IPuJmJz2TBSHTXeGfsQRjqWvnoYPfraF4rDTdDHcOkE7Rb779uPaKgLimUTOloUEUB7oI5a2EJJ0olBxfcxBYSd8qHdYi2DGOpSJI9gyiTckiLcBZh7g7/94Z/kLB+Hk4a5tinmgHC2temSyOQff+qRS7n0udMk8EjPTvP6d9Jm0/tgfd8byjVJRCaxaYtjQ0+tCP7pGZhSAz0YXI6QJX0FIqbctpIepOc6chiijE1kvGcocJqKQloMkyJXmnN4AlWHWg5aPEbndvYVVg6dmqIObJab//k2oMhlL52fsDdZVHCUVilY3sWEvpfwbC/mEKoweZF8BsdS89d+UJjKdEaAIjcxxHagJjCQ3MFeYBCUxAA69XVQ0EYnJ1am+3JHjZV/l/NVbdcDYPIqJRF+xuZSPplwF9GswsvwRrPn+5vr5HIVHz3ng4g5lDYg5f+9eggrBwA8J6qJb9e1vK7SiI4HXSYU81YwupZfAh+Z+gdq9CABZiS05PiYDgfbLmRBnSISiCe7lv2v8mw1CxoKU++RImxexBscbIDVJvxExrvRKwRgtfnLroSfuM6qjrP7F1JZjWVCBrwCGv2Yh8zTUlxMiaI71amW7Mfln4qMpIjFlASyFil/Nae0tee254JQ/7hhV11siiuJ0VqK2TSNIMbhxqbYox7sJXxSJFD/ACQlFZZZEYr+IxYIyYKE1jQrOERFufVaxvCK3mp2e6YsVIm1TUxNVyJgpcG7jQbloGD7YbyUq4YgHCEU6fPA/spF9PA+hcGgxXMCQ7pOU7h9noq3RMPOV3QaSPkCvUgSHfcAv+zT81A+rO5X+eO2dxtuKKMH8Y/Ejr/Fy8kztW1sG8XbYnyZiVsv0WuvPIHCbahrBnvmJw0b1ZIGEoBO07BpcBuzCWydNGOZOoRz2iuI8/cLUMWeW2oYBTQP8sadUPr2h//71eolCzdfWuPg7uhD3mGEidvrkSfKDLjelaq2GVvTflCTF+amdyR8bfKGt2rHQvJPRUwo4J05LPj1O9TuA4xkzn32sqkFw/ellV0r1xxTm0UwqR8Z5RPRlL15l34gRaABmzpxjXOytSs1KFzaGcHw== X-OriginatorOrg: xmos.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56613936-6de6-41a4-8e19-08dd3583a8ce X-MS-Exchange-CrossTenant-AuthSource: PAXPR09MB5583.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Jan 2025 16:42:54.8415 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 975ecfb1-4080-42d2-a01d-4a4d0707a539 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: YBK3U6nADX5IWtmdx+MCvyCru9Hd+BnzBrluwgO4KPXhLoshS4jMZGaINES7nU5KYj31ZuTvLJ25iAW90WrZJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR09MB6140 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, 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 In RISC-V, the general registers can be shown in their abi form (e.g. sp, a0) or their numeric form (e.g. x2, x10). Depending on context/preference, someone may prefer to see one form over the other. The disassembler already supports this configuration, which can be changed using the 'set disassembler-options numeric' command. This commit adds a new set/show command to change gdb's preference: 'set riscv numeric-registers-names on/off'. If on, 'info registers' and other situations will print the numeric register names, rather than the abi versions. The alias generation has been modified so that the abi versions are still available for access if specifically requested such as 'print $ra'. This was done by changing the behaviour of the code which adds the aliases: all register names will be added as aliases, even if the name is the primary one. There is also no functional downside to adding aliases which are surplus-to-requirement, since they will be ignored if there is a 'true' register with the same name. --- Thanks very much for the reviews, I believe I have addressed all raised issues - let me know if there is anything else. gdb/NEWS | 6 ++++ gdb/doc/gdb.texinfo | 24 ++++++++++++++ gdb/riscv-tdep.c | 78 ++++++++++++++++++++++++++++++++------------- 3 files changed, 85 insertions(+), 23 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 86831120d5c..f2d914a2751 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -32,6 +32,12 @@ maintenance check psymtabs maintenance check symtabs Renamed from maintenance check-symtabs +set riscv numeric-register-names on|off +show riscv numeric-register-names + Controls whether GDB refers to risc-v registers by their numeric names + (e.g 'x1') or their abi names (e.g. 'ra'). + Defaults to 'off', matching the old behaviour (abi names). + * Python API ** New class gdb.Color for dealing with colors. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index f519812cc92..8d1afef3e39 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -26465,6 +26465,7 @@ all uses of @value{GDBN} with the architecture, both native and cross. * Sparc64:: * S12Z:: * AMD GPU:: @acronym{AMD GPU} architectures +* RISC-V:: @end menu @node AArch64 @@ -27428,6 +27429,29 @@ was not attached. @end enumerate + +@node RISC-V +@subsection RISC-V +@cindex RISC-V support + +When @value{GDBN} is debugging a RISC-V architecture, it provides the +following special commands: + +@table @code +@item set riscv numeric-register-names +@kindex set riscv numeric-register-names +This command controls whether @value{GDBN} displays RISC-V register names using +their numeric or abi names. When @samp{on}, @value{GDBN} displays registers +by their numeric names (e.g. @samp{x1}). When @samp{off}, @value{GDBN} +displays registers by their abi names (e.g. @samp{ra}). The default is +@samp{off}. + +@item show riscv numeric-register-names +Show whether @value{GDBN} will refer to registers by their numeric names. + +@end table + + @node Controlling GDB @chapter Controlling @value{GDBN} diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 200a20abb65..3eed8409159 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -134,6 +134,11 @@ static const char *riscv_feature_name_vector = "org.gnu.gdb.riscv.vector"; /* The current set of options to be passed to the disassembler. */ static std::string riscv_disassembler_options; +/* When true, prefer to show register names in their numeric form (eg. x28). + When false, show them in their abi form (eg. t3). */ + +static bool numeric_register_names = false; + /* Cached information about a frame. */ struct riscv_unwind_cache @@ -226,11 +231,9 @@ struct riscv_register_feature /* Look in FEATURE for a register with a name from this classes names list. If the register is found then register its number with - TDESC_DATA and add all its aliases to the ALIASES list. - PREFER_FIRST_NAME_P is used when deciding which aliases to create. */ + TDESC_DATA and add all its aliases to the ALIASES list. */ bool check (struct tdesc_arch_data *tdesc_data, const struct tdesc_feature *feature, - bool prefer_first_name_p, std::vector *aliases) const; }; @@ -265,7 +268,6 @@ bool riscv_register_feature::register_info::check (struct tdesc_arch_data *tdesc_data, const struct tdesc_feature *feature, - bool prefer_first_name_p, std::vector *aliases) const { for (const char *name : this->names) @@ -276,14 +278,12 @@ riscv_register_feature::register_info::check { /* We know that the target description mentions this register. In RISCV_REGISTER_NAME we ensure that GDB - always uses the first name for each register, so here we - add aliases for all of the remaining names. */ - int start_index = prefer_first_name_p ? 1 : 0; - for (int i = start_index; i < this->names.size (); ++i) + always refers to the register by its user-configured name. + Here, we add aliases for all possible names, so that + the user can refer to the register by any of them. */ + for (int i = 0; i < this->names.size (); ++i) { const char *alias = this->names[i]; - if (alias == name && !prefer_first_name_p) - continue; aliases->emplace_back (alias, (void *) &this->regnum); } return true; @@ -342,6 +342,8 @@ struct riscv_xreg_feature : public riscv_register_feature const char *register_name (int regnum) const { gdb_assert (regnum >= RISCV_ZERO_REGNUM && regnum <= m_registers.size ()); + if (numeric_register_names && (regnum <= RISCV_ZERO_REGNUM + 31)) + return m_registers[regnum].names[1]; return m_registers[regnum].names[0]; } @@ -360,7 +362,7 @@ struct riscv_xreg_feature : public riscv_register_feature bool seen_an_optional_reg_p = false; for (const auto ® : m_registers) { - bool found = reg.check (tdesc_data, feature_cpu, true, aliases); + bool found = reg.check (tdesc_data, feature_cpu, aliases); bool is_optional_reg_p = (reg.regnum >= RISCV_ZERO_REGNUM + 16 && reg.regnum < RISCV_ZERO_REGNUM + 32); @@ -444,6 +446,8 @@ struct riscv_freg_feature : public riscv_register_feature gdb_assert (regnum >= RISCV_FIRST_FP_REGNUM && regnum <= RISCV_LAST_FP_REGNUM); regnum -= RISCV_FIRST_FP_REGNUM; + if (numeric_register_names && (regnum <= 31)) + return m_registers[regnum].names[1]; return m_registers[regnum].names[0]; } @@ -469,7 +473,7 @@ struct riscv_freg_feature : public riscv_register_feature are missing this is not fatal. */ for (const auto ® : m_registers) { - bool found = reg.check (tdesc_data, feature_fpu, true, aliases); + bool found = reg.check (tdesc_data, feature_fpu, aliases); bool is_ctrl_reg_p = reg.regnum > RISCV_LAST_FP_REGNUM; @@ -543,7 +547,7 @@ struct riscv_virtual_feature : public riscv_register_feature /* We don't check the return value from the call to check here, all the registers in this feature are optional. */ for (const auto ® : m_registers) - reg.check (tdesc_data, feature_virtual, true, aliases); + reg.check (tdesc_data, feature_virtual, aliases); return true; } @@ -583,7 +587,7 @@ struct riscv_csr_feature : public riscv_register_feature /* We don't check the return value from the call to check here, all the registers in this feature are optional. */ for (const auto ® : m_registers) - reg.check (tdesc_data, feature_csr, true, aliases); + reg.check (tdesc_data, feature_csr, aliases); return true; } @@ -683,7 +687,7 @@ struct riscv_vector_feature : public riscv_register_feature /* Check all of the vector registers are present. */ for (const auto ® : m_registers) { - if (!reg.check (tdesc_data, feature_vector, true, aliases)) + if (!reg.check (tdesc_data, feature_vector, aliases)) return false; } @@ -736,6 +740,18 @@ show_use_compressed_breakpoints (struct ui_file *file, int from_tty, "to %s.\n"), value); } +/* The show callback for 'show riscv numeric-register-names'. */ + +static void +show_numeric_register_names (struct ui_file *file, int from_tty, + struct cmd_list_element *c, + const char *value) +{ + gdb_printf (file, + _("Displaying registers with their numeric names is %s.\n"), + value); +} + /* The set and show lists for 'set riscv' and 'show riscv' prefixes. */ static struct cmd_list_element *setriscvcmdlist = NULL; @@ -918,17 +934,18 @@ riscv_register_name (struct gdbarch *gdbarch, int regnum) if (name[0] == '\0') return name; - /* We want GDB to use the ABI names for registers even if the target - gives us a target description with the architectural name. For - example we want to see 'ra' instead of 'x1' whatever the target - description called it. */ + /* We want GDB to use the user-configured names for registers even + if the target gives us a target description with something different. + For example, we want to see 'ra' if numeric_register_names is false, + or 'x1' if numeric_register_names is true - regardless of what the + target description called it. */ if (regnum >= RISCV_ZERO_REGNUM && regnum < RISCV_FIRST_FP_REGNUM) return riscv_xreg_feature.register_name (regnum); - /* Like with the x-regs we prefer the abi names for the floating point - registers. If the target doesn't have floating point registers then - the tdesc_register_name call above should have returned an empty - string. */ + /* Like with the x-regs we refer to the user configuration for the + floating point register names. If the target doesn't have floating + point registers then the tdesc_register_name call above should have + returned an empty string. */ if (regnum >= RISCV_FIRST_FP_REGNUM && regnum <= RISCV_LAST_FP_REGNUM) { gdb_assert (riscv_has_fp_regs (gdbarch)); @@ -4836,4 +4853,19 @@ this option can be used."), show_use_compressed_breakpoints, &setriscvcmdlist, &showriscvcmdlist); + + add_setshow_boolean_cmd ("numeric-register-names", no_class, + &numeric_register_names, + _("\ +Set displaying registers with numeric names instead of abi names."), _("\ +Show whether registers are displayed with numeric names instead of abi names."), + _("\ +When enabled, registers will be shown with their numeric names (such as x28)\n\ +instead of their abi names (such as t0).\n\ +Also consider using the 'set disassembler-options numeric' command for the\n\ +equivalent change in the disassembler output."), + NULL, + show_numeric_register_names, + &setriscvcmdlist, + &showriscvcmdlist); }