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. */