From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 089E13858C54; Thu, 14 Apr 2022 19:23:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 089E13858C54 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdbserver/qXfer::threads, prepare_to_access_memory=>target_pause_all X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: 1a7c41d5ece7d0d1aa77d8019ee46f03181854fa X-Git-Newrev: 330d63093c562a4b221835832c5e4f767dc623c3 Message-Id: <20220414192309.089E13858C54@sourceware.org> Date: Thu, 14 Apr 2022 19:23:09 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2022 19:23:09 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D330d63093c56= 2a4b221835832c5e4f767dc623c3 commit 330d63093c562a4b221835832c5e4f767dc623c3 Author: Pedro Alves Date: Tue Mar 29 12:57:17 2022 +0100 gdbserver/qXfer::threads, prepare_to_access_memory=3D>target_pause_all =20 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.) =20 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. =20 Change-Id: I127fec7246b7c45b60dfa7341e781606bf54b5da Diff: --- gdbserver/server.cc | 51 ++++++++++++++++---------------------------------= -- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 9f52d6e63fe..e43a40a9b1f 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -1691,47 +1691,28 @@ handle_qxfer_threads_worker (thread_info *thread, s= truct buffer *buffer) static bool handle_qxfer_threads_proper (struct buffer *buffer) { - client_state &cs =3D get_client_state (); - - scoped_restore_current_thread restore_thread; - scoped_restore save_current_general_thread - =3D make_scoped_restore (&cs.general_thread); - buffer_grow_str (buffer, "\n"); =20 - process_info *error_proc =3D 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 =3D current_thread->id; - - int res =3D prepare_to_access_memory (); - if (res =3D=3D 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); =20 - done_accessing_memory (); - return false; - } - else - return true; + for_each_thread ([&] (thread_info *thread) + { + handle_qxfer_threads_worker (thread, buffer); }); =20 + if (non_stop) + target_unpause_all (true); + buffer_grow_str0 (buffer, "\n"); - return error_proc =3D=3D nullptr; + return true; } =20 /* Handle qXfer:threads:read. */