public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [AArch64] Fix pseudo-register numbering in the presence of unexpected additional registers
@ 2022-09-21 17:53 Luis Machado
  2022-10-03 13:16 ` Luis Machado
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Machado @ 2022-09-21 17:53 UTC (permalink / raw)
  To: gdb-patches

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.

But given the pseudo-register numbers are above the number of real registers,
we need to setup/account for the real registers first before going ahead 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.

This is in preparation to supporting pointer authentication for bare metal
aarch64 (QEMU).
---
 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 7229b53838e..f94e810f904 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -3598,8 +3598,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   tdep->jb_elt_size = 8;
   tdep->vq = vq;
   tdep->pauth_reg_base = first_pauth_regnum;
-  tdep->ra_sign_state_regnum = (feature_pauth == NULL) ? -1
-				: ra_sign_state_offset + num_regs;
+  tdep->ra_sign_state_regnum = -1;
   tdep->mte_reg_base = first_mte_regnum;
   tdep->tls_regnum = tls_regnum;
 
@@ -3698,6 +3697,18 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
 
+  /* Fetch the updated number of registers after we're done adding all
+     entries from features we don't explicitly care about.  This is the case
+     for bare metal debugging stubs that include a lot of system registers.  */
+  num_regs = 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 = ra_sign_state_offset + num_regs;
+
   /* Add standard register aliases.  */
   for (i = 0; i < ARRAY_SIZE (aarch64_register_aliases); i++)
     user_reg_add (gdbarch, aarch64_register_aliases[i].name,
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [AArch64] Fix pseudo-register numbering in the presence of unexpected additional registers
  2022-09-21 17:53 [PATCH] [AArch64] Fix pseudo-register numbering in the presence of unexpected additional registers Luis Machado
@ 2022-10-03 13:16 ` Luis Machado
  2022-10-28 11:11   ` Luis Machado
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Machado @ 2022-10-03 13:16 UTC (permalink / raw)
  To: gdb-patches

On 9/21/22 18:53, Luis Machado via Gdb-patches wrote:
> 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.
> 
> But given the pseudo-register numbers are above the number of real registers,
> we need to setup/account for the real registers first before going ahead 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.
> 
> This is in preparation to supporting pointer authentication for bare metal
> aarch64 (QEMU).
> ---
>   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 7229b53838e..f94e810f904 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -3598,8 +3598,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>     tdep->jb_elt_size = 8;
>     tdep->vq = vq;
>     tdep->pauth_reg_base = first_pauth_regnum;
> -  tdep->ra_sign_state_regnum = (feature_pauth == NULL) ? -1
> -				: ra_sign_state_offset + num_regs;
> +  tdep->ra_sign_state_regnum = -1;
>     tdep->mte_reg_base = first_mte_regnum;
>     tdep->tls_regnum = tls_regnum;
>   
> @@ -3698,6 +3697,18 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>   
>     tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
>   
> +  /* Fetch the updated number of registers after we're done adding all
> +     entries from features we don't explicitly care about.  This is the case
> +     for bare metal debugging stubs that include a lot of system registers.  */
> +  num_regs = 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 = ra_sign_state_offset + num_regs;
> +
>     /* Add standard register aliases.  */
>     for (i = 0; i < ARRAY_SIZE (aarch64_register_aliases); i++)
>       user_reg_add (gdbarch, aarch64_register_aliases[i].name,

Pushed now.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [AArch64] Fix pseudo-register numbering in the presence of unexpected additional registers
  2022-10-03 13:16 ` Luis Machado
@ 2022-10-28 11:11   ` Luis Machado
  0 siblings, 0 replies; 3+ messages in thread
From: Luis Machado @ 2022-10-28 11:11 UTC (permalink / raw)
  To: gdb-patches

Hi,

On 10/3/22 14:16, Luis Machado wrote:
> On 9/21/22 18:53, Luis Machado via Gdb-patches wrote:
>> 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.
>>
>> But given the pseudo-register numbers are above the number of real registers,
>> we need to setup/account for the real registers first before going ahead 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.
>>
>> This is in preparation to supporting pointer authentication for bare metal
>> aarch64 (QEMU).
>> ---
>>   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 7229b53838e..f94e810f904 100644
>> --- a/gdb/aarch64-tdep.c
>> +++ b/gdb/aarch64-tdep.c
>> @@ -3598,8 +3598,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>>     tdep->jb_elt_size = 8;
>>     tdep->vq = vq;
>>     tdep->pauth_reg_base = first_pauth_regnum;
>> -  tdep->ra_sign_state_regnum = (feature_pauth == NULL) ? -1
>> -                : ra_sign_state_offset + num_regs;
>> +  tdep->ra_sign_state_regnum = -1;
>>     tdep->mte_reg_base = first_mte_regnum;
>>     tdep->tls_regnum = tls_regnum;
>> @@ -3698,6 +3697,18 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
>>     tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
>> +  /* Fetch the updated number of registers after we're done adding all
>> +     entries from features we don't explicitly care about.  This is the case
>> +     for bare metal debugging stubs that include a lot of system registers.  */
>> +  num_regs = 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 = ra_sign_state_offset + num_regs;
>> +
>>     /* Add standard register aliases.  */
>>     for (i = 0; i < ARRAY_SIZE (aarch64_register_aliases); i++)
>>       user_reg_add (gdbarch, aarch64_register_aliases[i].name,
> 
> Pushed now.

I'd like to push this patch to both gdb 12 and gdb 11. Does that sound reasonable?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-28 11:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 17:53 [PATCH] [AArch64] Fix pseudo-register numbering in the presence of unexpected additional registers Luis Machado
2022-10-03 13:16 ` Luis Machado
2022-10-28 11:11   ` Luis Machado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).