Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: Greg Savin <greg.savin@sifive.com>
Cc: gdb-patches@sourceware.org, Andrew Burgess <andrew.burgess@embecosm.com>
Subject: Re: [PATCH] RISC-V: support for vector register accesses via ptrace() in RISC-V Linux native
Date: Wed, 9 Aug 2023 10:21:00 +0100 (BST)	[thread overview]
Message-ID: <alpine.DEB.2.21.2308091008500.25915@angie.orcam.me.uk> (raw)
In-Reply-To: <20230803230110.904724-1-greg.savin@sifive.com>

On Thu, 3 Aug 2023, Greg Savin via Gdb-patches wrote:

> +static unsigned long
> +safe_read_vlenb ()
> +{
> +  /* Surrounding the attempt here to read VLENB CSR to have a signal handler set up
> +     to trap illegal instruction condition (SIGILL), and if a trap happens during this call,
> +     get control back within this function and return 0 in that case.
> +   */
> +  unsigned long vlenb = 0;
> +  struct sigaction our_action = { 0 };
> +  struct sigaction original_action;
> +  int sysresult;
> +
> +
> +  our_action.sa_handler = sigill_guard;
> +
> +  sysresult = sigaction (SIGILL, &our_action, &original_action);
> +  if (sysresult != 0)
> +    {
> +      perror
> +	("Error installing temporary SIGILL handler in safe_read_vlenb()");
> +    }
> +
> +  if (SIGSETJMP (sigill_guard_jmp_buf, 1) == 0)
> +    {
> +    asm ("csrr %0, vlenb":"=r" (vlenb));
> +    }
> +  else
> +    {
> +      /* Must've generated an illegal instruction condition; we'll figure this means
> +         no vector unit is present */
> +      vlenb = 0;
> +    }

 I find it weird that you trap SIGILL and try to execute a vector 
instruction in the debugger to determine whether `ptrace' can be used to 
access the vector state in the debuggee.  Why?

 The usual way is to try to use `ptrace' itself to determine whether the 
OS has support for it in the first place and then can access the vector 
state.  You can then return the contents of the register retrieved if 
successful.

  Maciej

  parent reply	other threads:[~2023-08-09  9:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03 23:01 Greg Savin via Gdb-patches
2023-08-04  0:21 ` John Baldwin
2023-08-08 22:50   ` [PATCH v2] " Greg Savin via Gdb-patches
2023-08-11 14:27     ` Andrew Burgess via Gdb-patches
2023-08-11 16:41       ` Greg Savin via Gdb-patches
2023-08-09  9:21 ` Maciej W. Rozycki [this message]
2023-08-09 18:11   ` [PATCH] " Greg Savin via Gdb-patches
2023-08-09 23:09     ` Maciej W. Rozycki
2023-08-10 10:35       ` Andy Chiu via Gdb-patches
2023-08-10 11:40         ` Maciej W. Rozycki
2023-08-10 13:55           ` Maciej W. Rozycki
2023-08-10 17:23             ` Andy Chiu via Gdb-patches
2023-08-10 21:08               ` Palmer Dabbelt
2023-08-10 21:21               ` Maciej W. Rozycki
2023-08-11 11:28                 ` Andy Chiu via Gdb-patches
2023-08-10 14:05           ` Andy Chiu via Gdb-patches
2023-08-10 20:51             ` Maciej W. Rozycki
2025-07-30 10:52 Sameer Natu

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=alpine.DEB.2.21.2308091008500.25915@angie.orcam.me.uk \
    --to=macro@orcam.me.uk \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=greg.savin@sifive.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