From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdbserver: try selecting a thread first to access memory
Date: Tue, 20 Jun 2023 10:35:19 +0200 [thread overview]
Message-ID: <20230620083519.1295801-1-tankut.baris.aktemur@intel.com> (raw)
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.
Regression-tested on X86_64 Linux using the unix, native-gdbserver,
and native-extended-gdbserver board files.
---
gdbserver/server.cc | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index c57270175b4..0344fba32a7 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1072,7 +1072,10 @@ gdb_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
/* (assume no half-trace half-real blocks for now) */
}
- if (set_desired_process ())
+ /* Some memory accesses may require having a thread context.
+ Attempt switching to the selected thread first, with a fall-back
+ option to a process. */
+ if (set_desired_thread () || set_desired_process ())
res = read_inferior_memory (memaddr, myaddr, len);
else
res = 1;
@@ -1093,7 +1096,10 @@ gdb_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
{
int ret;
- if (set_desired_process ())
+ /* Some memory accesses may require having a thread context.
+ Attempt switching to the selected thread first, with a
+ fall-back option to a process. */
+ if (set_desired_thread () || set_desired_process ())
ret = target_write_memory (memaddr, myaddr, len);
else
ret = EIO;
--
2.25.1
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 reply other threads:[~2023-06-20 8:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-20 8:35 Tankut Baris Aktemur [this message]
2023-07-18 13:09 ` Pedro Alves
2023-07-18 13:36 ` Aktemur, Tankut Baris
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=20230620083519.1295801-1-tankut.baris.aktemur@intel.com \
--to=tankut.baris.aktemur@intel.com \
--cc=gdb-patches@sourceware.org \
/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).