From: "Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>
To: Pedro Alves <pedro@palves.net>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: RE: [PATCH] gdbserver: try selecting a thread first to access memory
Date: Tue, 18 Jul 2023 13:36:57 +0000 [thread overview]
Message-ID: <IA0PR11MB73074B28C433B3E94A68E47AC438A@IA0PR11MB7307.namprd11.prod.outlook.com> (raw)
In-Reply-To: <90f33e9c-a586-a94a-3584-5288ce14d410@palves.net>
On Tuesday, July 18, 2023 3:09 PM, Pedro Alves wrote:
> On 2023-06-20 09:35, Tankut Baris Aktemur via Gdb-patches wrote:
> > Since commit
> >
> > commit 7f8acedeebe295fc8cc1d11ed971cbfc1942618c
> > Author: Pedro Alves <pedro@palves.net>
> > Date: Tue Apr 5 13:57:11 2022 +0100
> >
> > gdbserver: track current process as well as current thread
> >
> > gdbserver switches to a process, rather than a thread, before
> > processing a memory access request coming from the GDB side. This
> > switch sets current_thread to null. Some memory accesses on certain
> > targets, however, may require having a thread context. Therefore, try
> > switching to the selected thread first. If this fails for a reason
> > (e.g. the thread has exited), switch to the process.
>
> The reason I liked always selecting a process (with thread == null), is
> that it made the corner case be the case that runs all the time. I.e., any
> target backend that incorrectly assumes there's always a thread selected,
> is immediately exposed to the problem scenario and is forced to fix it.
> Trying to select the thread first loses that.
I'll refer to this comment below as [1].
> If the access is for a thread-specific address space, and the thread exited,
> what is supposed to happen? Is the backend supposed to error out in that
> scenario? Or will it misbehave?
I'd expect the memory access at the target side to error out. Gdbserver would
then convert this to an 'E' response.
> How do you tell what address space the access is targeting? Are you encoding
> that in the address, or do you have more changes to gdbserver, and maybe
> RSP extensions?
Currently we're encoding the address space in the address (upper 3 bits).
> I'm wondering whether we should have something like:
>
> if ((aspace_thread_specific (...) && set_desired_thread ())
> || set_desired_process ())
> res = read_inferior_memory (memaddr, myaddr, len);
> else
> res = 1;
I believe `aspace_thread_specific` would have to be a target-specific
logic. What you referred to in the comment [1] above, i.e. "immediately
exposed to the problem scenario and is forced to fix it", would be caught
and the target would fix the problem by implementing `aspace_thread_specific`
appropriately. This makes sense to me. An alternative would be that
the target calls `set_desired_thread` itself, before accessing the memory,
if it detects that the request is thread-specific. I don't see any low-target
using `set_desired_thread` ever in the gdbserver codebase, though. So, it
might be considered a breakage of abstraction. Hence, your suggestion looks
favorable.
Thanks
-Baris
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
next prev parent reply other threads:[~2023-07-18 13:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-20 8:35 Tankut Baris Aktemur
2023-07-18 13:09 ` Pedro Alves
2023-07-18 13:36 ` Aktemur, Tankut Baris [this message]
2023-07-18 14:03 ` Pedro Alves
2023-07-18 14:23 ` Aktemur, Tankut Baris
2023-08-01 13:20 ` [PATCH v2] gdbserver: select a thread, if necessary, to access memory (was: [PATCH] gdbserver: try selecting a thread first to access memory) Tankut Baris Aktemur
2023-11-21 19:45 ` Aktemur, Tankut Baris
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=IA0PR11MB73074B28C433B3E94A68E47AC438A@IA0PR11MB7307.namprd11.prod.outlook.com \
--to=tankut.baris.aktemur@intel.com \
--cc=gdb-patches@sourceware.org \
--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).