From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/3] gdbserver/qXfer::threads, prepare_to_access_memory=>target_pause_all
Date: Wed, 30 Mar 2022 13:43:17 +0100 [thread overview]
Message-ID: <20220330124319.2804582-2-pedro@palves.net> (raw)
In-Reply-To: <20220330124319.2804582-1-pedro@palves.net>
handle_qxfer_threads_proper needs to pause all threads even if the
target can read memory when threads are running, so use
target_pause_all instead, which is what the Linux implementation of
prepare_to_access_memory uses. (Only Linux implements this hook.)
A following patch will make the Linux backend be able to access memory
when threads are running, and thus will also make
prepare_to_access_memory do nothing, which would cause testsuite
regressions without this change.
Change-Id: I127fec7246b7c45b60dfa7341e781606bf54b5da
---
gdbserver/server.cc | 51 ++++++++++++++-------------------------------
1 file changed, 16 insertions(+), 35 deletions(-)
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 8e53f226d3c..60d0c2be17a 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -1695,47 +1695,28 @@ handle_qxfer_threads_worker (thread_info *thread, struct buffer *buffer)
static bool
handle_qxfer_threads_proper (struct buffer *buffer)
{
- client_state &cs = get_client_state ();
-
- scoped_restore_current_thread restore_thread;
- scoped_restore save_current_general_thread
- = make_scoped_restore (&cs.general_thread);
-
buffer_grow_str (buffer, "<threads>\n");
- process_info *error_proc = find_process ([&] (process_info *process)
- {
- /* The target may need to access memory and registers (e.g. via
- libthread_db) to fetch thread properties. Prepare for memory
- access here, so that we potentially pause threads just once
- for all accesses. Note that even if someday we stop needing
- to pause threads to access memory, we will need to be able to
- access registers, or other ptrace accesses like
- PTRACE_GET_THREAD_AREA. */
-
- /* Need to switch to each process in turn, because
- prepare_to_access_memory prepares for an access in the
- current process pointed to by general_thread. */
- switch_to_process (process);
- cs.general_thread = current_thread->id;
-
- int res = prepare_to_access_memory ();
- if (res == 0)
- {
- for_each_thread (process->pid, [&] (thread_info *thread)
- {
- handle_qxfer_threads_worker (thread, buffer);
- });
+ /* The target may need to access memory and registers (e.g. via
+ libthread_db) to fetch thread properties. Even if don't need to
+ stop threads to access memory, we still will need to be able to
+ access registers, and other ptrace accesses like
+ PTRACE_GET_THREAD_AREA that require a paused thread. Pause all
+ threads here, so that we pause each thread at most once for all
+ accesses. */
+ if (non_stop)
+ target_pause_all (true);
- done_accessing_memory ();
- return false;
- }
- else
- return true;
+ for_each_thread ([&] (thread_info *thread)
+ {
+ handle_qxfer_threads_worker (thread, buffer);
});
+ if (non_stop)
+ target_unpause_all (true);
+
buffer_grow_str0 (buffer, "</threads>\n");
- return error_proc == nullptr;
+ return true;
}
/* Handle qXfer:threads:read. */
--
2.26.2
next prev parent reply other threads:[~2022-03-30 12:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-30 12:43 [PATCH 0/3] gdbserver/linux: access memory while threads are running without pausing Pedro Alves
2022-03-30 12:43 ` Pedro Alves [this message]
2022-03-30 12:43 ` [PATCH 2/3] gdbserver/linux: Access memory even if threads are running Pedro Alves
2022-03-30 13:22 ` Lancelot SIX
2022-03-31 11:39 ` Pedro Alves
2022-04-04 14:34 ` Pedro Alves
2022-03-30 12:43 ` [PATCH 3/3] gdbserver: Eliminate prepare_to_access_memory Pedro Alves
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=20220330124319.2804582-2-pedro@palves.net \
--to=pedro@palves.net \
--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).