From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1585) id A6AE43858D38; Mon, 3 Oct 2022 13:15:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6AE43858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664802941; bh=ZQdzvjl/kuZX9rpv7U3myo0CtmxHGNnFdVynOcV1jtE=; h=From:To:Subject:Date:From; b=MBFgwQ8HeBoSs5qMy/ULW3mV5Avhw+cjAoqwWAQk816ArxK4yg5Go4MP5WM1BHTZ1 c3wKfD78J41LVNxJcS952qysLCMbUZ50UnkoSAuzlSM3+8dzmp233MJTozrzAviR04 CgT3CfCn8aufAm0+7di/FYKtC2wzq1660a9dQjb8= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Luis Machado To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [AArch64] Fix pseudo-register numbering in the presence of unexpected additional registers X-Act-Checkin: binutils-gdb X-Git-Author: Luis Machado X-Git-Refname: refs/heads/master X-Git-Oldrev: 907b52f4ceb6d15b00a0ac5fc7a7029f8a80b97d X-Git-Newrev: 1ba3a3222039eb2576d29c9fd3af444f59fa51d2 Message-Id: <20221003131541.A6AE43858D38@sourceware.org> Date: Mon, 3 Oct 2022 13:15:41 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1ba3a3222039= eb2576d29c9fd3af444f59fa51d2 commit 1ba3a3222039eb2576d29c9fd3af444f59fa51d2 Author: Luis Machado Date: Fri Sep 9 10:30:53 2022 +0100 [AArch64] Fix pseudo-register numbering in the presence of unexpected a= dditional registers =20 When using AArch64 GDB with the QEMU debugging stub (in user mode), we = get additional system registers that GDB doesn't particularly care about, so it doesn't number those explicitly. =20 But given the pseudo-register numbers are above the number of real regi= sters, we need to setup/account for the real registers first before going ahea= d and numbering the pseudo-registers. This has to happen at the end of aarch64_gdbarch_init, after the call to tdesc_use_registers, as that updates the total number of real registers. =20 This is in preparation to supporting pointer authentication for bare me= tal aarch64 (QEMU). Diff: --- gdb/aarch64-tdep.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index d0387044934..76e039a7d5f 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -3598,8 +3598,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struc= t gdbarch_list *arches) tdep->jb_elt_size =3D 8; tdep->vq =3D vq; tdep->pauth_reg_base =3D first_pauth_regnum; - tdep->ra_sign_state_regnum =3D (feature_pauth =3D=3D NULL) ? -1 - : ra_sign_state_offset + num_regs; + tdep->ra_sign_state_regnum =3D -1; tdep->mte_reg_base =3D first_mte_regnum; tdep->tls_regnum =3D tls_regnum; =20 @@ -3698,6 +3697,18 @@ aarch64_gdbarch_init (struct gdbarch_info info, stru= ct gdbarch_list *arches) =20 tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data)); =20 + /* Fetch the updated number of registers after we're done adding all + entries from features we don't explicitly care about. This is the ca= se + for bare metal debugging stubs that include a lot of system registers= . */ + num_regs =3D gdbarch_num_regs (gdbarch); + + /* With the number of real registers updated, setup the pseudo-registers= and + record their numbers. */ + + /* Pointer authentication pseudo-registers. */ + if (tdep->has_pauth ()) + tdep->ra_sign_state_regnum =3D ra_sign_state_offset + num_regs; + /* Add standard register aliases. */ for (i =3D 0; i < ARRAY_SIZE (aarch64_register_aliases); i++) user_reg_add (gdbarch, aarch64_register_aliases[i].name,