From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 70C483858409; Thu, 13 Jan 2022 10:13:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70C483858409 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 extra debug information to attach_command X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 1ffce3f87dc6e62d49b5aaa0bc29c6d4cfbc6db6 X-Git-Newrev: 993248f4439271d7d5d3b504b851043af7495c25 Message-Id: <20220113101328.70C483858409@sourceware.org> Date: Thu, 13 Jan 2022 10:13:28 +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, 13 Jan 2022 10:13:28 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D993248f44392= 71d7d5d3b504b851043af7495c25 commit 993248f4439271d7d5d3b504b851043af7495c25 Author: Andrew Burgess Date: Tue Jan 11 17:31:16 2022 +0000 gdb: add some extra debug information to attach_command =20 While working on another patch I wanted to add some extra debug information to the attach_command function. This required me to add a new function to convert the thread_info::state variable to a string. =20 The new debug might be useful to others, and the state to string function might be useful in other locations, so I thought I'd merge it. Diff: --- gdb/gdbthread.h | 4 ++++ gdb/infcmd.c | 12 ++++++++++++ gdb/thread.c | 20 ++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 5350a42f1bb..9921dae7a71 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -1003,4 +1003,8 @@ extern void thread_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty, const qcs_flags &flags); =20 +/* Return a string representation of STATE. */ + +extern const char *thread_state_string (enum thread_state state); + #endif /* GDBTHREAD_H */ diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 8bf58018bdd..9f4ed8bff13 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2541,6 +2541,18 @@ 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)); + } + /* Set up the "saved terminal modes" of the inferior based on what modes we are starting it with. */ target_terminal::init (); diff --git a/gdb/thread.c b/gdb/thread.c index 8a7d142bab5..c43f6613145 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -2050,6 +2050,26 @@ thread_name (thread_info *thread) return target_thread_name (thread); } =20 +/* See gdbthread.h. */ + +const char * +thread_state_string (enum thread_state state) +{ + switch (state) + { + case THREAD_STOPPED: + return "STOPPED"; + + case THREAD_RUNNING: + return "RUNNING"; + + case THREAD_EXITED: + return "EXITED"; + } + + gdb_assert_not_reached ("unknown thread state"); +} + /* Return a new value for the selected thread's id. Return a value of 0 if no thread is selected. If GLOBAL is true, return the thread's global number. Otherwise return the per-inferior number. */