diff options
author | Andrew Burgess <aburgess@redhat.com> | 2021-11-12 10:30:27 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2021-12-22 15:02:02 +0000 |
commit | 5b0a3d62423236100bac1e77f7cc084ad9ce0271 (patch) | |
tree | 20b00bb936aa1c35f8281ddceba9d47e6d9543c3 /gdb/thread.c | |
parent | 85adb21d04edea0c7b0408a9660d5a9a5aca9ae2 (diff) | |
download | gdb-5b0a3d62423236100bac1e77f7cc084ad9ce0271.zip gdb-5b0a3d62423236100bac1e77f7cc084ad9ce0271.tar.gz gdb-5b0a3d62423236100bac1e77f7cc084ad9ce0271.tar.bz2 |
gdb: add threads debugging switch
Add new commands:
set debug threads on|off
show debug threads
Prints additional debug information relating to thread creation and
deletion.
GDB already announces when threads are created of course.... most of
the time, but sometimes threads are added silently, in which case this
debug message is the only mechanism to see the thread being added.
Also, though GDB does announce when a thread exits, it doesn't
announce when the thread object is deleted, I've added a debug message
for that.
Additionally, having message printed through the debug system will
cause the messages to be nested to an appropriate depth when other
debug sub-systems are turned on (especially things like `infrun` and
`lin-lwp`).
Diffstat (limited to 'gdb/thread.c')
-rw-r--r-- | gdb/thread.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gdb/thread.c b/gdb/thread.c index 6c792ec..ebaed1c 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -49,6 +49,19 @@ #include "inline-frame.h" #include "stack.h" +/* See gdbthread.h. */ + +bool debug_threads = false; + +/* Implement 'show debug threads'. */ + +static void +show_debug_threads (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("Thread debugging is \"%s\".\n"), value); +} + /* Definition of struct thread_info exported to gdbthread.h. */ /* Prototypes for local functions. */ @@ -234,6 +247,9 @@ new_thread (struct inferior *inf, ptid_t ptid) { thread_info *tp = new thread_info (inf, ptid); + threads_debug_printf ("creating a new thread object, inferior %d, ptid %s", + inf->num, ptid.to_string ().c_str ()); + inf->thread_list.push_back (*tp); /* A thread with this ptid should not exist in the map yet. */ @@ -251,6 +267,10 @@ add_thread_silent (process_stratum_target *targ, ptid_t ptid) inferior *inf = find_inferior_ptid (targ, ptid); + threads_debug_printf ("add thread to inferior %d, ptid %s, target %s", + inf->num, ptid.to_string ().c_str (), + targ->shortname ()); + /* We may have an old thread with the same id in the thread list. If we do, it must be dead, otherwise we wouldn't be adding a new thread with the same id. The OS is reusing this id --- delete @@ -302,6 +322,13 @@ thread_info::thread_info (struct inferior *inf_, ptid_t ptid_) /* See gdbthread.h. */ +thread_info::~thread_info () +{ + threads_debug_printf ("thread %s", this->ptid.to_string ().c_str ()); +} + +/* See gdbthread.h. */ + bool thread_info::deletable () const { @@ -434,6 +461,9 @@ delete_thread_1 (thread_info *thr, bool silent) { gdb_assert (thr != nullptr); + threads_debug_printf ("deleting thread %s, silent = %d", + thr->ptid.to_string ().c_str (), silent); + set_thread_exited (thr, silent); if (!thr->deletable ()) @@ -2192,6 +2222,14 @@ Show printing of thread events (such as thread start and exit)."), NULL, show_print_thread_events, &setprintlist, &showprintlist); + add_setshow_boolean_cmd ("threads", class_maintenance, &debug_threads, _("\ +Set thread debugging."), _("\ +Show thread debugging."), _("\ +When on messages about thread creation and deletion are printed."), + nullptr, + show_debug_threads, + &setdebuglist, &showdebuglist); + create_internalvar_type_lazy ("_thread", &thread_funcs, NULL); create_internalvar_type_lazy ("_gthread", >hread_funcs, NULL); } |