public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Luis Machado <luis.machado@arm.com>,
	Andrew Burgess <aburgess@redhat.com>,
	gdb-patches@sourceware.org, pedro@palves.net
Cc: marcan@marcan.st
Subject: Re: [PATCH] aarch64: Check for valid inferior thread/regcache before reading pauth registers
Date: Fri, 17 Mar 2023 13:15:49 -0400	[thread overview]
Message-ID: <6aa8edc2-81f7-b08a-805f-9a20185995d2@simark.ca> (raw)
In-Reply-To: <5ce96222-d665-5129-8d65-27c6933a6623@arm.com>

> ... despite the call to switch_to_no_thread in switch_to_inferior_no_thread from do_target_wait_1
> in the backtrace above, the call to ps_xfer_memory sets inferior_ptid momentarily before reading
> memory:
> 
> 
> static ps_err_e
> ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr,
>                 gdb_byte *buf, size_t len, int write)
> {
>   scoped_restore_current_inferior restore_inferior;
>   set_current_inferior (ph->thread->inf);
> 
>   scoped_restore_current_program_space restore_current_progspace;
>   set_current_program_space (ph->thread->inf->pspace);
> 
>   scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
>   inferior_ptid = ph->thread->ptid;
> 
>   CORE_ADDR core_addr = ps_addr_to_core_addr (addr);
> 
>   int ret;
>   if (write)
>     ret = target_write_memory (core_addr, buf, len);
>   else
>     ret = target_read_memory (core_addr, buf, len);
>   return (ret == 0 ? PS_OK : PS_ERR);
> }
> 
> 
> Maybe this shouldn't happen, or maybe it is just an unfortunate state to be in. But this
> prevents the use of target_has_registers to guard against the lack of registers, since,
> although current_thread_ is still nullptr, inferior_ptid is valid and is not null_ptid.
It's needed to set inferior_ptid here because it's how we communicate to
the targets which inferior / thread we want to read or write memory
from.  And we can't set current_thread_ to the the correponding
thread_info *, because it does not exist at this point (we are in the
process of creating it).  And the problem is that
aarch64_remove_non_address_bits assumes there is a current_thread_.  Can
we change aarch64_remove_non_address_bits to get the regcache using the
ptid?

  get_thread_regcache (current_inferior ()->process_target (), inferior_ptid);

Simon


  reply	other threads:[~2023-03-17 17:15 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16 10:39 Luis Machado
2023-03-16 15:49 ` Andrew Burgess
2023-03-16 23:15   ` Luis Machado
2023-03-17 17:15     ` Simon Marchi [this message]
2023-03-17 17:25       ` Luis Machado
2023-03-17 17:29         ` Simon Marchi
2023-03-17 17:38           ` Luis Machado
2023-03-20 20:06     ` Andrew Burgess
2023-03-22 10:26       ` Luis Machado
2023-03-23 10:56 ` [PATCH, v2] " Luis Machado
2023-03-23 18:25   ` Kevin Buettner
2023-03-23 18:27     ` Luis Machado
2023-03-23 18:32       ` Luis Machado
2023-03-23 18:39         ` Kevin Buettner
2023-03-24  6:28           ` Luis Machado
2023-03-24  8:19   ` Luis Machado
2023-03-24 13:42     ` 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=6aa8edc2-81f7-b08a-805f-9a20185995d2@simark.ca \
    --to=simark@simark.ca \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@arm.com \
    --cc=marcan@marcan.st \
    --cc=pedro@palves.net \
    /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).