From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id D0D263856DC6; Tue, 3 May 2022 14:04:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0D263856DC6 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: add some additional thread status debug output X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: ba951afb99912da01a6e8434126b8fac7aa75107 X-Git-Newrev: 1f9d9e321ca0416d970a8a4ae94df69de0e22d14 Message-Id: <20220503140401.D0D263856DC6@sourceware.org> Date: Tue, 3 May 2022 14:04:01 +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: Tue, 03 May 2022 14:04:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1f9d9e321ca0= 416d970a8a4ae94df69de0e22d14 commit 1f9d9e321ca0416d970a8a4ae94df69de0e22d14 Author: Andrew Burgess Date: Thu Apr 21 15:09:17 2022 +0100 gdb: add some additional thread status debug output =20 While working on this patch: =20 https://sourceware.org/pipermail/gdb-patches/2022-January/185109.html =20 I found it really useful to print the executing/resumed status of all threads (or all threads in a particular inferior) at various places (e.g. when a new inferior is started, when GDB attaches, etc). =20 This debug was originally part of the above patch, but I wanted to rewrite this as a separate patch and move the code into a new function in infrun.h, which is what this patch does. =20 Unless 'set debug infrun on' is in effect, then there should be no user visible changes after this commit. Diff: --- gdb/infcmd.c | 19 ++++++++----------- gdb/infrun.c | 3 +++ gdb/infrun.h | 26 ++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 53c9e3d0afe..e909d4d4c81 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -238,6 +238,9 @@ post_create_inferior (int from_tty) /* Be sure we own the terminal in case write operations are performed. = */=20 target_terminal::ours_for_output (); =20 + infrun_debug_show_threads ("threads in the newly created inferior", + current_inferior ()->non_exited_threads ()); + /* If the target hasn't taken care of this already, do it now. Targets which need to access registers during to_open, to_create_inferior, or to_attach should do it earlier; but many @@ -454,6 +457,9 @@ run_command_1 (const char *args, int from_tty, enum run= _how run_how) shouldn't refer to run_target again. */ run_target =3D NULL; =20 + infrun_debug_show_threads ("immediately after create_process", + current_inferior ()->non_exited_threads ()); + /* We're starting off a new process. When we get out of here, in non-stop mode, finish the state of all threads of that process, but leave other threads alone, as they may be stopped in internal @@ -2589,17 +2595,8 @@ attach_command (const char *args, int from_tty) shouldn't refer to attach_target again. */ attach_target =3D NULL; =20 - if (debug_infrun) - { - infrun_debug_printf ("immediately after attach:"); - for (thread_info *thread : inferior->non_exited_threads ()) - infrun_debug_printf (" thread %s, executing =3D %d, resumed =3D %d, " - "state =3D %s", - thread->ptid.to_string ().c_str (), - thread->executing (), - thread->resumed (), - thread_state_string (thread->state)); - } + infrun_debug_show_threads ("immediately after attach", + current_inferior ()->non_exited_threads ()); =20 /* Enable async mode if it is supported by the target. */ if (target_can_async_p ()) diff --git a/gdb/infrun.c b/gdb/infrun.c index 531d398d7b8..02c98b50c8c 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -5063,6 +5063,9 @@ stop_all_threads (const char *reason, inferior *inf) INFRUN_SCOPED_DEBUG_START_END ("reason=3D%s, inf=3D%d", reason, inf !=3D nullptr ? inf->num : -1); =20 + infrun_debug_show_threads ("non-exited threads", + all_non_exited_threads ()); + scoped_restore_current_thread restore_thread; =20 /* Enable thread events on relevant targets. */ diff --git a/gdb/infrun.h b/gdb/infrun.h index 9685f3a9775..0c7c55eabec 100644 --- a/gdb/infrun.h +++ b/gdb/infrun.h @@ -48,6 +48,32 @@ extern bool debug_infrun; #define INFRUN_SCOPED_DEBUG_ENTER_EXIT \ scoped_debug_enter_exit (debug_infrun, "infrun") =20 +/* A infrun debug helper routine to print out all the threads in the set + THREADS (which should be a range type that returns thread_info* + objects). + + The TITLE is a string that is printed before the list of threads. + + Output is only produced when 'set debug infrun on'. */ + +template +static inline void +infrun_debug_show_threads (const char *title, ThreadRange threads) +{ + if (debug_infrun) + { + infrun_debug_printf ("%s:", title); + for (thread_info *thread : threads) + infrun_debug_printf (" thread %s, executing =3D %d, resumed =3D %d, " + "state =3D %s", + thread->ptid.to_string ().c_str (), + thread->executing (), + thread->resumed (), + thread_state_string (thread->state)); + } +} + + /* Nonzero if we want to give control to the user when we're notified of shared library events by the dynamic linker. */ extern int stop_on_solib_events;