public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdbserver: try selecting a thread first to access memory
@ 2023-06-20  8:35 Tankut Baris Aktemur
  2023-07-18 13:09 ` Pedro Alves
  0 siblings, 1 reply; 7+ messages in thread
From: Tankut Baris Aktemur @ 2023-06-20  8:35 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-11-21 19:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20  8:35 [PATCH] gdbserver: try selecting a thread first to access memory Tankut Baris Aktemur
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

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).