public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Luis Machado <luis.machado@arm.com>
To: Koudai Iwahori <koudai@google.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] AArch64 pauth: Fix internal error when target supports extra regs
Date: Tue, 4 Oct 2022 10:27:30 +0100	[thread overview]
Message-ID: <5f2703cf-c2f3-493a-e756-e0546f117aed@arm.com> (raw)
In-Reply-To: <20220928025057.188075-1-koudai@google.com>

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


  reply	other threads:[~2022-10-04  9:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-28  2:50 Koudai Iwahori
2022-10-04  9:27 ` Luis Machado [this message]
2022-10-05  2:07   ` Koudai Iwahori
2022-10-05  2:07     ` Koudai Iwahori
2022-10-05  8:52     ` Luis Machado

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5f2703cf-c2f3-493a-e756-e0546f117aed@arm.com \
    --to=luis.machado@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=koudai@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).