/* Multi-process/thread control for GDB, the GNU debugger.
- Copyright (C) 1986-2021 Free Software Foundation, Inc.
+ Copyright (C) 1986-2022 Free Software Foundation, Inc.
Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA.
#include "annotate.h"
#include "cli/cli-decode.h"
#include "cli/cli-option.h"
-#include "gdb_regex.h"
+#include "gdbsupport/gdb_regex.h"
#include "cli/cli-utils.h"
#include "thread-fsm.h"
#include "tid-parse.h"
#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. */
{
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. */
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
/* 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
{
global_thread_step_over_chain_enqueue (struct thread_info *tp)
{
infrun_debug_printf ("enqueueing thread %s in global step over chain",
- target_pid_to_str (tp->ptid).c_str ());
+ tp->ptid.to_string ().c_str ());
gdb_assert (!thread_is_in_step_over_chain (tp));
global_thread_step_over_list.push_back (*tp);
global_thread_step_over_chain_remove (struct thread_info *tp)
{
infrun_debug_printf ("removing thread %s from global step over chain",
- target_pid_to_str (tp->ptid).c_str ());
+ tp->ptid.to_string ().c_str ());
gdb_assert (thread_is_in_step_over_chain (tp));
auto it = global_thread_step_over_list.iterator_to (*tp);
{
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 ())
return target_thread_name (thread);
}
+/* 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. */
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);
}