public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] AArch64 pauth: Fix internal error when target supports extra regs
@ 2022-09-28  2:50 Koudai Iwahori
  2022-10-04  9:27 ` Luis Machado
  0 siblings, 1 reply; 4+ messages in thread
From: Koudai Iwahori @ 2022-09-28  2:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Koudai Iwahori

GDB crashes in aarch64_pseudo_register_type() when target supports pauth
and extra registers.
When the target supports pauth, GDB keeps a pseudo register `RA_STATE`
and aarch64_gdbarch_tdep::ra_sign_state_regnum has the integer index of
the register.
aarch64_gdbarch_tdep::ra_sign_state_regnum is initialized to
(# of reg) + (# of pseudo reg) right after GDB checking if the target
supports the core/fpu/sve registers.
However, the number of registers is updated in tdesc_use_registers() if
the target can provide extra registers.
In such cases, ra_sign_state_regnum does not have the right value and
internal_error() in aarch64_pseudo_register_type() fires.
I added ra_sign_state_pseudo_regnum field to aarch64_gdbarch_tdep for
storing the pseudo register number and added get_ra_sign_state_regnum
member function.
---
 gdb/aarch64-tdep.c | 23 ++++++++++++-----------
 gdb/aarch64-tdep.h |  8 +++++++-
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 7229b53838e..87335ad22ae 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -254,7 +254,8 @@ aarch64_frame_unmask_lr (aarch64_gdbarch_tdep *tdep,
 {
   if (tdep->has_pauth ()
       && frame_unwind_register_unsigned (this_frame,
-					 tdep->ra_sign_state_regnum))
+					 tdep->get_ra_sign_state_regnum (
+						get_frame_arch (this_frame))))
     {
       int cmask_num = AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base);
       CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame, cmask_num);
@@ -542,7 +543,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
 
 	  if (tdep->has_pauth () && cache != nullptr)
 	    {
-	      int regnum = tdep->ra_sign_state_regnum;
+	      int regnum = tdep->get_ra_sign_state_regnum (gdbarch);
 	      cache->saved_regs[regnum].set_value (ra_state_val);
 	    }
 	}
@@ -882,7 +883,7 @@ aarch64_analyze_prologue_test (void)
 
       if (tdep->has_pauth ())
 	{
-	  int regnum = tdep->ra_sign_state_regnum;
+	  int regnum = tdep->get_ra_sign_state_regnum (gdbarch);
 	  SELF_CHECK (cache.saved_regs[regnum].is_value ());
 	}
     }
@@ -1137,7 +1138,8 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
       lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
 
       if (tdep->has_pauth ()
-	  && cache->saved_regs[tdep->ra_sign_state_regnum].is_value ())
+	  && cache->saved_regs[tdep->get_ra_sign_state_regnum (gdbarch)]
+		.is_value ())
 	lr = aarch64_frame_unmask_lr (tdep, this_frame, lr);
 
       return frame_unwind_got_constant (this_frame, prev_regnum, lr);
@@ -1344,7 +1346,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
   /* Init pauth registers.  */
   if (tdep->has_pauth ())
     {
-      if (regnum == tdep->ra_sign_state_regnum)
+      if (regnum == tdep->get_ra_sign_state_regnum (gdbarch))
 	{
 	  /* Initialize RA_STATE to zero.  */
 	  reg->how = DWARF2_FRAME_REG_SAVED_VAL_EXP;
@@ -2255,7 +2257,7 @@ aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
   if (tdep->has_pauth ())
     {
       if (reg == AARCH64_DWARF_RA_SIGN_STATE)
-	return tdep->ra_sign_state_regnum;
+	return tdep->get_ra_sign_state_regnum (gdbarch);
     }
 
   return -1;
@@ -2662,7 +2664,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
   /* RA_STATE is used for unwinding only.  Do not assign it a name - this
      prevents it from being read by methods such as
      mi_cmd_trace_frame_collected.  */
-  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
+  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
     return "";
 
   internal_error (__FILE__, __LINE__,
@@ -2698,7 +2700,7 @@ aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
       && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM)
     return aarch64_vnv_type (gdbarch);
 
-  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
+  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
     return builtin_type (gdbarch)->builtin_uint64;
 
   internal_error (__FILE__, __LINE__,
@@ -2732,7 +2734,7 @@ aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
 	   && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM)
     return group == all_reggroup || group == vector_reggroup;
   /* RA_STATE is used for unwinding only.  Do not assign it to any groups.  */
-  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
+  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
     return 0;
 
   return group == all_reggroup;
@@ -3598,8 +3600,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_pseudo_regnum = ra_sign_state_offset;
   tdep->mte_reg_base = first_mte_regnum;
   tdep->tls_regnum = tls_regnum;
 
diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
index d8513023c37..acb69b2dc40 100644
--- a/gdb/aarch64-tdep.h
+++ b/gdb/aarch64-tdep.h
@@ -94,7 +94,13 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base
   }
 
   int pauth_reg_base = 0;
-  int ra_sign_state_regnum = 0;
+  int ra_sign_state_pseudo_regnum = -1;
+
+  int get_ra_sign_state_regnum (gdbarch *gdbarch) const
+  {
+    gdb_assert (ra_sign_state_pseudo_regnum >= 0);
+    return ra_sign_state_pseudo_regnum + gdbarch_num_regs (gdbarch);
+  }
 
   /* Returns true if the target supports pauth.  */
   bool has_pauth () const
-- 
2.37.3.998.g577e59143f-goog


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

* Re: [PATCH] AArch64 pauth: Fix internal error when target supports extra regs
  2022-09-28  2:50 [PATCH] AArch64 pauth: Fix internal error when target supports extra regs Koudai Iwahori
@ 2022-10-04  9:27 ` Luis Machado
  2022-10-05  2:07   ` Koudai Iwahori
  0 siblings, 1 reply; 4+ messages in thread
From: Luis Machado @ 2022-10-04  9:27 UTC (permalink / raw)
  To: Koudai Iwahori, gdb-patches

Hi,

This should be addressed by https://sourceware.org/pipermail/gdb-patches/2022-October/192272.html.

Could you please give it a try? It was pushed yesterday.

Out of curiosity, are you using user-mode QEMU? You mentioned extra registers, and those are usually
provided by emulators.

On 9/28/22 03:50, Koudai Iwahori via Gdb-patches wrote:
> GDB crashes in aarch64_pseudo_register_type() when target supports pauth
> and extra registers.
> When the target supports pauth, GDB keeps a pseudo register `RA_STATE`
> and aarch64_gdbarch_tdep::ra_sign_state_regnum has the integer index of
> the register.
> aarch64_gdbarch_tdep::ra_sign_state_regnum is initialized to
> (# of reg) + (# of pseudo reg) right after GDB checking if the target
> supports the core/fpu/sve registers.
> However, the number of registers is updated in tdesc_use_registers() if
> the target can provide extra registers.
> In such cases, ra_sign_state_regnum does not have the right value and
> internal_error() in aarch64_pseudo_register_type() fires.
> I added ra_sign_state_pseudo_regnum field to aarch64_gdbarch_tdep for
> storing the pseudo register number and added get_ra_sign_state_regnum
> member function.
> ---
>   gdb/aarch64-tdep.c | 23 ++++++++++++-----------
>   gdb/aarch64-tdep.h |  8 +++++++-
>   2 files changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index 7229b53838e..87335ad22ae 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -254,7 +254,8 @@ aarch64_frame_unmask_lr (aarch64_gdbarch_tdep *tdep,
>   {
>     if (tdep->has_pauth ()
>         && frame_unwind_register_unsigned (this_frame,
> -					 tdep->ra_sign_state_regnum))
> +					 tdep->get_ra_sign_state_regnum (
> +						get_frame_arch (this_frame))))
>       {
>         int cmask_num = AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base);
>         CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame, cmask_num);
> @@ -542,7 +543,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
>   
>   	  if (tdep->has_pauth () && cache != nullptr)
>   	    {
> -	      int regnum = tdep->ra_sign_state_regnum;
> +	      int regnum = tdep->get_ra_sign_state_regnum (gdbarch);
>   	      cache->saved_regs[regnum].set_value (ra_state_val);
>   	    }
>   	}
> @@ -882,7 +883,7 @@ aarch64_analyze_prologue_test (void)
>   
>         if (tdep->has_pauth ())
>   	{
> -	  int regnum = tdep->ra_sign_state_regnum;
> +	  int regnum = tdep->get_ra_sign_state_regnum (gdbarch);
>   	  SELF_CHECK (cache.saved_regs[regnum].is_value ());
>   	}
>       }
> @@ -1137,7 +1138,8 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
>         lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
>   
>         if (tdep->has_pauth ()
> -	  && cache->saved_regs[tdep->ra_sign_state_regnum].is_value ())
> +	  && cache->saved_regs[tdep->get_ra_sign_state_regnum (gdbarch)]
> +		.is_value ())
>   	lr = aarch64_frame_unmask_lr (tdep, this_frame, lr);
>   
>         return frame_unwind_got_constant (this_frame, prev_regnum, lr);
> @@ -1344,7 +1346,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
>     /* Init pauth registers.  */
>     if (tdep->has_pauth ())
>       {
> -      if (regnum == tdep->ra_sign_state_regnum)
> +      if (regnum == tdep->get_ra_sign_state_regnum (gdbarch))
>   	{
>   	  /* Initialize RA_STATE to zero.  */
>   	  reg->how = DWARF2_FRAME_REG_SAVED_VAL_EXP;
> @@ -2255,7 +2257,7 @@ aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>     if (tdep->has_pauth ())
>       {
>         if (reg == AARCH64_DWARF_RA_SIGN_STATE)
> -	return tdep->ra_sign_state_regnum;
> +	return tdep->get_ra_sign_state_regnum (gdbarch);
>       }
>   
>     return -1;
> @@ -2662,7 +2664,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>     /* RA_STATE is used for unwinding only.  Do not assign it a name - this
>        prevents it from being read by methods such as
>        mi_cmd_trace_frame_collected.  */
> -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
> +  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
>       return "";
>   
>     internal_error (__FILE__, __LINE__,
> @@ -2698,7 +2700,7 @@ aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>         && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM)
>       return aarch64_vnv_type (gdbarch);
>   
> -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
> +  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
>       return builtin_type (gdbarch)->builtin_uint64;
>   
>     internal_error (__FILE__, __LINE__,
> @@ -2732,7 +2734,7 @@ aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>   	   && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM)
>       return group == all_reggroup || group == vector_reggroup;
>     /* RA_STATE is used for unwinding only.  Do not assign it to any groups.  */
> -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
> +  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
>       return 0;
>   
>     return group == all_reggroup;
> @@ -3598,8 +3600,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_pseudo_regnum = ra_sign_state_offset;
>     tdep->mte_reg_base = first_mte_regnum;
>     tdep->tls_regnum = tls_regnum;
>   
> diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
> index d8513023c37..acb69b2dc40 100644
> --- a/gdb/aarch64-tdep.h
> +++ b/gdb/aarch64-tdep.h
> @@ -94,7 +94,13 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base
>     }
>   
>     int pauth_reg_base = 0;
> -  int ra_sign_state_regnum = 0;
> +  int ra_sign_state_pseudo_regnum = -1;
> +
> +  int get_ra_sign_state_regnum (gdbarch *gdbarch) const
> +  {
> +    gdb_assert (ra_sign_state_pseudo_regnum >= 0);
> +    return ra_sign_state_pseudo_regnum + gdbarch_num_regs (gdbarch);
> +  }
>   
>     /* Returns true if the target supports pauth.  */
>     bool has_pauth () const


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

* Re: [PATCH] AArch64 pauth: Fix internal error when target supports extra regs
  2022-10-04  9:27 ` Luis Machado
@ 2022-10-05  2:07   ` Koudai Iwahori
  2022-10-05  8:52     ` Luis Machado
  0 siblings, 1 reply; 4+ messages in thread
From: Koudai Iwahori @ 2022-10-05  2:07 UTC (permalink / raw)
  To: Luis Machado; +Cc: gdb-patches

Hi Luis,

It worked, thank you!
I'm using OpenOCD. OpenOCD provides registers like ELR_EL1.



On Tue, Oct 4, 2022 at 5:27 PM Luis Machado <luis.machado@arm.com> wrote:

> Hi,
>
> This should be addressed by
> https://sourceware.org/pipermail/gdb-patches/2022-October/192272.html.
>
> Could you please give it a try? It was pushed yesterday.
>
> Out of curiosity, are you using user-mode QEMU? You mentioned extra
> registers, and those are usually
> provided by emulators.
>
> On 9/28/22 03:50, Koudai Iwahori via Gdb-patches wrote:
> > GDB crashes in aarch64_pseudo_register_type() when target supports pauth
> > and extra registers.
> > When the target supports pauth, GDB keeps a pseudo register `RA_STATE`
> > and aarch64_gdbarch_tdep::ra_sign_state_regnum has the integer index of
> > the register.
> > aarch64_gdbarch_tdep::ra_sign_state_regnum is initialized to
> > (# of reg) + (# of pseudo reg) right after GDB checking if the target
> > supports the core/fpu/sve registers.
> > However, the number of registers is updated in tdesc_use_registers() if
> > the target can provide extra registers.
> > In such cases, ra_sign_state_regnum does not have the right value and
> > internal_error() in aarch64_pseudo_register_type() fires.
> > I added ra_sign_state_pseudo_regnum field to aarch64_gdbarch_tdep for
> > storing the pseudo register number and added get_ra_sign_state_regnum
> > member function.
> > ---
> >   gdb/aarch64-tdep.c | 23 ++++++++++++-----------
> >   gdb/aarch64-tdep.h |  8 +++++++-
> >   2 files changed, 19 insertions(+), 12 deletions(-)
> >
> > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> > index 7229b53838e..87335ad22ae 100644
> > --- a/gdb/aarch64-tdep.c
> > +++ b/gdb/aarch64-tdep.c
> > @@ -254,7 +254,8 @@ aarch64_frame_unmask_lr (aarch64_gdbarch_tdep *tdep,
> >   {
> >     if (tdep->has_pauth ()
> >         && frame_unwind_register_unsigned (this_frame,
> > -                                      tdep->ra_sign_state_regnum))
> > +                                      tdep->get_ra_sign_state_regnum (
> > +                                             get_frame_arch
> (this_frame))))
> >       {
> >         int cmask_num = AARCH64_PAUTH_CMASK_REGNUM
> (tdep->pauth_reg_base);
> >         CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame,
> cmask_num);
> > @@ -542,7 +543,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
> >
> >         if (tdep->has_pauth () && cache != nullptr)
> >           {
> > -           int regnum = tdep->ra_sign_state_regnum;
> > +           int regnum = tdep->get_ra_sign_state_regnum (gdbarch);
> >             cache->saved_regs[regnum].set_value (ra_state_val);
> >           }
> >       }
> > @@ -882,7 +883,7 @@ aarch64_analyze_prologue_test (void)
> >
> >         if (tdep->has_pauth ())
> >       {
> > -       int regnum = tdep->ra_sign_state_regnum;
> > +       int regnum = tdep->get_ra_sign_state_regnum (gdbarch);
> >         SELF_CHECK (cache.saved_regs[regnum].is_value ());
> >       }
> >       }
> > @@ -1137,7 +1138,8 @@ aarch64_prologue_prev_register (struct frame_info
> *this_frame,
> >         lr = frame_unwind_register_unsigned (this_frame,
> AARCH64_LR_REGNUM);
> >
> >         if (tdep->has_pauth ()
> > -       && cache->saved_regs[tdep->ra_sign_state_regnum].is_value ())
> > +       && cache->saved_regs[tdep->get_ra_sign_state_regnum (gdbarch)]
> > +             .is_value ())
> >       lr = aarch64_frame_unmask_lr (tdep, this_frame, lr);
> >
> >         return frame_unwind_got_constant (this_frame, prev_regnum, lr);
> > @@ -1344,7 +1346,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch
> *gdbarch, int regnum,
> >     /* Init pauth registers.  */
> >     if (tdep->has_pauth ())
> >       {
> > -      if (regnum == tdep->ra_sign_state_regnum)
> > +      if (regnum == tdep->get_ra_sign_state_regnum (gdbarch))
> >       {
> >         /* Initialize RA_STATE to zero.  */
> >         reg->how = DWARF2_FRAME_REG_SAVED_VAL_EXP;
> > @@ -2255,7 +2257,7 @@ aarch64_dwarf_reg_to_regnum (struct gdbarch
> *gdbarch, int reg)
> >     if (tdep->has_pauth ())
> >       {
> >         if (reg == AARCH64_DWARF_RA_SIGN_STATE)
> > -     return tdep->ra_sign_state_regnum;
> > +     return tdep->get_ra_sign_state_regnum (gdbarch);
> >       }
> >
> >     return -1;
> > @@ -2662,7 +2664,7 @@ aarch64_pseudo_register_name (struct gdbarch
> *gdbarch, int regnum)
> >     /* RA_STATE is used for unwinding only.  Do not assign it a name -
> this
> >        prevents it from being read by methods such as
> >        mi_cmd_trace_frame_collected.  */
> > -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
> > +  if (tdep->has_pauth () && p_regnum ==
> tdep->ra_sign_state_pseudo_regnum)
> >       return "";
> >
> >     internal_error (__FILE__, __LINE__,
> > @@ -2698,7 +2700,7 @@ aarch64_pseudo_register_type (struct gdbarch
> *gdbarch, int regnum)
> >         && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM)
> >       return aarch64_vnv_type (gdbarch);
> >
> > -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
> > +  if (tdep->has_pauth () && p_regnum ==
> tdep->ra_sign_state_pseudo_regnum)
> >       return builtin_type (gdbarch)->builtin_uint64;
> >
> >     internal_error (__FILE__, __LINE__,
> > @@ -2732,7 +2734,7 @@ aarch64_pseudo_register_reggroup_p (struct gdbarch
> *gdbarch, int regnum,
> >          && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM)
> >       return group == all_reggroup || group == vector_reggroup;
> >     /* RA_STATE is used for unwinding only.  Do not assign it to any
> groups.  */
> > -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
> > +  if (tdep->has_pauth () && p_regnum ==
> tdep->ra_sign_state_pseudo_regnum)
> >       return 0;
> >
> >     return group == all_reggroup;
> > @@ -3598,8 +3600,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_pseudo_regnum = ra_sign_state_offset;
> >     tdep->mte_reg_base = first_mte_regnum;
> >     tdep->tls_regnum = tls_regnum;
> >
> > diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
> > index d8513023c37..acb69b2dc40 100644
> > --- a/gdb/aarch64-tdep.h
> > +++ b/gdb/aarch64-tdep.h
> > @@ -94,7 +94,13 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base
> >     }
> >
> >     int pauth_reg_base = 0;
> > -  int ra_sign_state_regnum = 0;
> > +  int ra_sign_state_pseudo_regnum = -1;
> > +
> > +  int get_ra_sign_state_regnum (gdbarch *gdbarch) const
> > +  {
> > +    gdb_assert (ra_sign_state_pseudo_regnum >= 0);
> > +    return ra_sign_state_pseudo_regnum + gdbarch_num_regs (gdbarch);
> > +  }
> >
> >     /* Returns true if the target supports pauth.  */
> >     bool has_pauth () const
>
>

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

* Re: [PATCH] AArch64 pauth: Fix internal error when target supports extra regs
  2022-10-05  2:07   ` Koudai Iwahori
@ 2022-10-05  8:52     ` Luis Machado
  0 siblings, 0 replies; 4+ messages in thread
From: Luis Machado @ 2022-10-05  8:52 UTC (permalink / raw)
  To: Koudai Iwahori; +Cc: gdb-patches

Hi Koudai,

On 10/5/22 03:07, Koudai Iwahori wrote:
> Hi Luis,
> 
> It worked, thank you!

Thanks for testing.

> I'm using OpenOCD. OpenOCD provides registers like ELR_EL1.

That's good to know. It is always useful to get some feedback from OpenOCD.

> 
> 
> 
> On Tue, Oct 4, 2022 at 5:27 PM Luis Machado <luis.machado@arm.com <mailto:luis.machado@arm.com>> wrote:
> 
>     Hi,
> 
>     This should be addressed by https://sourceware.org/pipermail/gdb-patches/2022-October/192272.html <https://sourceware.org/pipermail/gdb-patches/2022-October/192272.html>.
> 
>     Could you please give it a try? It was pushed yesterday.
> 
>     Out of curiosity, are you using user-mode QEMU? You mentioned extra registers, and those are usually
>     provided by emulators.
> 
>     On 9/28/22 03:50, Koudai Iwahori via Gdb-patches wrote:
>      > GDB crashes in aarch64_pseudo_register_type() when target supports pauth
>      > and extra registers.
>      > When the target supports pauth, GDB keeps a pseudo register `RA_STATE`
>      > and aarch64_gdbarch_tdep::ra_sign_state_regnum has the integer index of
>      > the register.
>      > aarch64_gdbarch_tdep::ra_sign_state_regnum is initialized to
>      > (# of reg) + (# of pseudo reg) right after GDB checking if the target
>      > supports the core/fpu/sve registers.
>      > However, the number of registers is updated in tdesc_use_registers() if
>      > the target can provide extra registers.
>      > In such cases, ra_sign_state_regnum does not have the right value and
>      > internal_error() in aarch64_pseudo_register_type() fires.
>      > I added ra_sign_state_pseudo_regnum field to aarch64_gdbarch_tdep for
>      > storing the pseudo register number and added get_ra_sign_state_regnum
>      > member function.
>      > ---
>      >   gdb/aarch64-tdep.c | 23 ++++++++++++-----------
>      >   gdb/aarch64-tdep.h |  8 +++++++-
>      >   2 files changed, 19 insertions(+), 12 deletions(-)
>      >
>      > diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
>      > index 7229b53838e..87335ad22ae 100644
>      > --- a/gdb/aarch64-tdep.c
>      > +++ b/gdb/aarch64-tdep.c
>      > @@ -254,7 +254,8 @@ aarch64_frame_unmask_lr (aarch64_gdbarch_tdep *tdep,
>      >   {
>      >     if (tdep->has_pauth ()
>      >         && frame_unwind_register_unsigned (this_frame,
>      > -                                      tdep->ra_sign_state_regnum))
>      > +                                      tdep->get_ra_sign_state_regnum (
>      > +                                             get_frame_arch (this_frame))))
>      >       {
>      >         int cmask_num = AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base);
>      >         CORE_ADDR cmask = frame_unwind_register_unsigned (this_frame, cmask_num);
>      > @@ -542,7 +543,7 @@ aarch64_analyze_prologue (struct gdbarch *gdbarch,
>      >
>      >         if (tdep->has_pauth () && cache != nullptr)
>      >           {
>      > -           int regnum = tdep->ra_sign_state_regnum;
>      > +           int regnum = tdep->get_ra_sign_state_regnum (gdbarch);
>      >             cache->saved_regs[regnum].set_value (ra_state_val);
>      >           }
>      >       }
>      > @@ -882,7 +883,7 @@ aarch64_analyze_prologue_test (void)
>      >
>      >         if (tdep->has_pauth ())
>      >       {
>      > -       int regnum = tdep->ra_sign_state_regnum;
>      > +       int regnum = tdep->get_ra_sign_state_regnum (gdbarch);
>      >         SELF_CHECK (cache.saved_regs[regnum].is_value ());
>      >       }
>      >       }
>      > @@ -1137,7 +1138,8 @@ aarch64_prologue_prev_register (struct frame_info *this_frame,
>      >         lr = frame_unwind_register_unsigned (this_frame, AARCH64_LR_REGNUM);
>      >
>      >         if (tdep->has_pauth ()
>      > -       && cache->saved_regs[tdep->ra_sign_state_regnum].is_value ())
>      > +       && cache->saved_regs[tdep->get_ra_sign_state_regnum (gdbarch)]
>      > +             .is_value ())
>      >       lr = aarch64_frame_unmask_lr (tdep, this_frame, lr);
>      >
>      >         return frame_unwind_got_constant (this_frame, prev_regnum, lr);
>      > @@ -1344,7 +1346,7 @@ aarch64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
>      >     /* Init pauth registers.  */
>      >     if (tdep->has_pauth ())
>      >       {
>      > -      if (regnum == tdep->ra_sign_state_regnum)
>      > +      if (regnum == tdep->get_ra_sign_state_regnum (gdbarch))
>      >       {
>      >         /* Initialize RA_STATE to zero.  */
>      >         reg->how = DWARF2_FRAME_REG_SAVED_VAL_EXP;
>      > @@ -2255,7 +2257,7 @@ aarch64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
>      >     if (tdep->has_pauth ())
>      >       {
>      >         if (reg == AARCH64_DWARF_RA_SIGN_STATE)
>      > -     return tdep->ra_sign_state_regnum;
>      > +     return tdep->get_ra_sign_state_regnum (gdbarch);
>      >       }
>      >
>      >     return -1;
>      > @@ -2662,7 +2664,7 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
>      >     /* RA_STATE is used for unwinding only.  Do not assign it a name - this
>      >        prevents it from being read by methods such as
>      >        mi_cmd_trace_frame_collected.  */
>      > -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
>      > +  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
>      >       return "";
>      >
>      >     internal_error (__FILE__, __LINE__,
>      > @@ -2698,7 +2700,7 @@ aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
>      >         && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM)
>      >       return aarch64_vnv_type (gdbarch);
>      >
>      > -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
>      > +  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
>      >       return builtin_type (gdbarch)->builtin_uint64;
>      >
>      >     internal_error (__FILE__, __LINE__,
>      > @@ -2732,7 +2734,7 @@ aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
>      >          && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM)
>      >       return group == all_reggroup || group == vector_reggroup;
>      >     /* RA_STATE is used for unwinding only.  Do not assign it to any groups.  */
>      > -  if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum)
>      > +  if (tdep->has_pauth () && p_regnum == tdep->ra_sign_state_pseudo_regnum)
>      >       return 0;
>      >
>      >     return group == all_reggroup;
>      > @@ -3598,8 +3600,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_pseudo_regnum = ra_sign_state_offset;
>      >     tdep->mte_reg_base = first_mte_regnum;
>      >     tdep->tls_regnum = tls_regnum;
>      >
>      > diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h
>      > index d8513023c37..acb69b2dc40 100644
>      > --- a/gdb/aarch64-tdep.h
>      > +++ b/gdb/aarch64-tdep.h
>      > @@ -94,7 +94,13 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base
>      >     }
>      >
>      >     int pauth_reg_base = 0;
>      > -  int ra_sign_state_regnum = 0;
>      > +  int ra_sign_state_pseudo_regnum = -1;
>      > +
>      > +  int get_ra_sign_state_regnum (gdbarch *gdbarch) const
>      > +  {
>      > +    gdb_assert (ra_sign_state_pseudo_regnum >= 0);
>      > +    return ra_sign_state_pseudo_regnum + gdbarch_num_regs (gdbarch);
>      > +  }
>      >
>      >     /* Returns true if the target supports pauth.  */
>      >     bool has_pauth () const
> 


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

end of thread, other threads:[~2022-10-05  8:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28  2:50 [PATCH] AArch64 pauth: Fix internal error when target supports extra regs Koudai Iwahori
2022-10-04  9:27 ` Luis Machado
2022-10-05  2:07   ` Koudai Iwahori
2022-10-05  8:52     ` 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).