1 /* Multi-process/thread control for GDB, the GNU debugger.
3 Copyright (C) 1986-2018 Free Software Foundation, Inc.
5 Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 #include "gdbthread.h"
36 #include <sys/types.h>
41 #include "cli/cli-decode.h"
42 #include "gdb_regex.h"
43 #include "cli/cli-utils.h"
44 #include "thread-fsm.h"
45 #include "tid-parse.h"
47 #include "common/gdb_optional.h"
49 /* Definition of struct thread_info exported to gdbthread.h. */
51 /* Prototypes for local functions. */
53 struct thread_info *thread_list = NULL;
54 static int highest_thread_num;
56 /* True if any thread is, or may be executing. We need to track this
57 separately because until we fully sync the thread list, we won't
58 know whether the target is fully stopped, even if we see stop
59 events for all known threads, because any of those threads may have
60 spawned new threads we haven't heard of yet. */
61 static int threads_executing;
63 static int thread_alive (struct thread_info *);
65 /* RAII type used to increase / decrease the refcount of each thread
66 in a given list of threads. */
68 class scoped_inc_dec_ref
71 explicit scoped_inc_dec_ref (const std::vector<thread_info *> &thrds)
74 for (thread_info *thr : m_thrds)
78 ~scoped_inc_dec_ref ()
80 for (thread_info *thr : m_thrds)
85 const std::vector<thread_info *> &m_thrds;
90 inferior_thread (void)
92 struct thread_info *tp = find_thread_ptid (inferior_ptid);
97 /* Delete the breakpoint pointed at by BP_P, if there's one. */
100 delete_thread_breakpoint (struct breakpoint **bp_p)
104 delete_breakpoint (*bp_p);
110 delete_step_resume_breakpoint (struct thread_info *tp)
113 delete_thread_breakpoint (&tp->control.step_resume_breakpoint);
117 delete_exception_resume_breakpoint (struct thread_info *tp)
120 delete_thread_breakpoint (&tp->control.exception_resume_breakpoint);
123 /* See gdbthread.h. */
126 delete_single_step_breakpoints (struct thread_info *tp)
129 delete_thread_breakpoint (&tp->control.single_step_breakpoints);
132 /* Delete the breakpoint pointed at by BP_P at the next stop, if
136 delete_at_next_stop (struct breakpoint **bp)
140 (*bp)->disposition = disp_del_at_next_stop;
145 /* See gdbthread.h. */
148 thread_has_single_step_breakpoints_set (struct thread_info *tp)
150 return tp->control.single_step_breakpoints != NULL;
153 /* See gdbthread.h. */
156 thread_has_single_step_breakpoint_here (struct thread_info *tp,
157 const address_space *aspace,
160 struct breakpoint *ss_bps = tp->control.single_step_breakpoints;
162 return (ss_bps != NULL
163 && breakpoint_has_location_inserted_here (ss_bps, aspace, addr));
166 /* See gdbthread.h. */
169 thread_cancel_execution_command (struct thread_info *thr)
171 if (thr->thread_fsm != NULL)
173 thread_fsm_clean_up (thr->thread_fsm, thr);
174 thread_fsm_delete (thr->thread_fsm);
175 thr->thread_fsm = NULL;
180 clear_thread_inferior_resources (struct thread_info *tp)
182 /* NOTE: this will take care of any left-over step_resume breakpoints,
183 but not any user-specified thread-specific breakpoints. We can not
184 delete the breakpoint straight-off, because the inferior might not
185 be stopped at the moment. */
186 delete_at_next_stop (&tp->control.step_resume_breakpoint);
187 delete_at_next_stop (&tp->control.exception_resume_breakpoint);
188 delete_at_next_stop (&tp->control.single_step_breakpoints);
190 delete_longjmp_breakpoint_at_next_stop (tp->global_num);
192 bpstat_clear (&tp->control.stop_bpstat);
194 btrace_teardown (tp);
196 thread_cancel_execution_command (tp);
199 /* Set the TP's state as exited. */
202 set_thread_exited (thread_info *tp, int silent)
204 /* Dead threads don't need to step-over. Remove from queue. */
205 if (tp->step_over_next != NULL)
206 thread_step_over_chain_remove (tp);
208 if (tp->state != THREAD_EXITED)
210 observer_notify_thread_exit (tp, silent);
212 /* Tag it as exited. */
213 tp->state = THREAD_EXITED;
215 /* Clear breakpoints, etc. associated with this thread. */
216 clear_thread_inferior_resources (tp);
221 init_thread_list (void)
223 struct thread_info *tp, *tpnext;
225 highest_thread_num = 0;
230 for (tp = thread_list; tp; tp = tpnext)
233 if (tp->deletable ())
236 set_thread_exited (tp, 1);
240 threads_executing = 0;
243 /* Allocate a new thread of inferior INF with target id PTID and add
244 it to the thread list. */
246 static struct thread_info *
247 new_thread (struct inferior *inf, ptid_t ptid)
249 thread_info *tp = new thread_info (inf, ptid);
251 if (thread_list == NULL)
255 struct thread_info *last;
257 for (last = thread_list; last->next != NULL; last = last->next)
266 add_thread_silent (ptid_t ptid)
268 struct thread_info *tp;
269 struct inferior *inf = find_inferior_ptid (ptid);
270 gdb_assert (inf != NULL);
272 tp = find_thread_ptid (ptid);
274 /* Found an old thread with the same id. It has to be dead,
275 otherwise we wouldn't be adding a new thread with the same id.
276 The OS is reusing this id --- delete it, and recreate a new
279 /* In addition to deleting the thread, if this is the current
280 thread, then we need to take care that delete_thread doesn't
281 really delete the thread if it is inferior_ptid. Create a
282 new template thread in the list with an invalid ptid, switch
283 to it, delete the original thread, reset the new thread's
284 ptid, and switch to it. */
286 if (inferior_ptid == ptid)
288 tp = new_thread (inf, null_ptid);
290 /* Make switch_to_thread not read from the thread. */
291 tp->state = THREAD_EXITED;
292 switch_to_thread (null_ptid);
294 /* Now we can delete it. */
295 delete_thread (ptid);
297 /* Now reset its ptid, and reswitch inferior_ptid to it. */
299 tp->state = THREAD_STOPPED;
300 switch_to_thread (ptid);
302 observer_notify_new_thread (tp);
308 /* Just go ahead and delete it. */
309 delete_thread (ptid);
312 tp = new_thread (inf, ptid);
313 observer_notify_new_thread (tp);
319 add_thread_with_info (ptid_t ptid, private_thread_info *priv)
321 struct thread_info *result = add_thread_silent (ptid);
323 result->priv.reset (priv);
325 if (print_thread_events)
326 printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
328 annotate_new_thread ();
333 add_thread (ptid_t ptid)
335 return add_thread_with_info (ptid, NULL);
338 private_thread_info::~private_thread_info () = default;
340 thread_info::thread_info (struct inferior *inf_, ptid_t ptid_)
341 : ptid (ptid_), inf (inf_)
343 gdb_assert (inf_ != NULL);
345 this->global_num = ++highest_thread_num;
346 this->per_inf_num = ++inf_->highest_thread_num;
348 /* Nothing to follow yet. */
349 memset (&this->pending_follow, 0, sizeof (this->pending_follow));
350 this->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
351 this->suspend.waitstatus.kind = TARGET_WAITKIND_IGNORE;
354 thread_info::~thread_info ()
359 /* Add TP to the end of the step-over chain LIST_P. */
362 step_over_chain_enqueue (struct thread_info **list_p, struct thread_info *tp)
364 gdb_assert (tp->step_over_next == NULL);
365 gdb_assert (tp->step_over_prev == NULL);
370 tp->step_over_prev = tp->step_over_next = tp;
374 struct thread_info *head = *list_p;
375 struct thread_info *tail = head->step_over_prev;
377 tp->step_over_prev = tail;
378 tp->step_over_next = head;
379 head->step_over_prev = tp;
380 tail->step_over_next = tp;
384 /* Remove TP from step-over chain LIST_P. */
387 step_over_chain_remove (struct thread_info **list_p, struct thread_info *tp)
389 gdb_assert (tp->step_over_next != NULL);
390 gdb_assert (tp->step_over_prev != NULL);
394 if (tp == tp->step_over_next)
397 *list_p = tp->step_over_next;
400 tp->step_over_prev->step_over_next = tp->step_over_next;
401 tp->step_over_next->step_over_prev = tp->step_over_prev;
402 tp->step_over_prev = tp->step_over_next = NULL;
405 /* See gdbthread.h. */
408 thread_step_over_chain_next (struct thread_info *tp)
410 struct thread_info *next = tp->step_over_next;
412 return (next == step_over_queue_head ? NULL : next);
415 /* See gdbthread.h. */
418 thread_is_in_step_over_chain (struct thread_info *tp)
420 return (tp->step_over_next != NULL);
423 /* See gdbthread.h. */
426 thread_step_over_chain_enqueue (struct thread_info *tp)
428 step_over_chain_enqueue (&step_over_queue_head, tp);
431 /* See gdbthread.h. */
434 thread_step_over_chain_remove (struct thread_info *tp)
436 step_over_chain_remove (&step_over_queue_head, tp);
439 /* Delete thread PTID. If SILENT, don't notify the observer of this
442 delete_thread_1 (ptid_t ptid, int silent)
444 struct thread_info *tp, *tpprev;
448 for (tp = thread_list; tp; tpprev = tp, tp = tp->next)
449 if (tp->ptid == ptid)
455 set_thread_exited (tp, silent);
457 if (!tp->deletable ())
459 /* Will be really deleted some other time. */
464 tpprev->next = tp->next;
466 thread_list = tp->next;
471 /* Delete thread PTID and notify of thread exit. If this is
472 inferior_ptid, don't actually delete it, but tag it as exited and
473 do the notification. If PTID is the user selected thread, clear
476 delete_thread (ptid_t ptid)
478 delete_thread_1 (ptid, 0 /* not silent */);
482 delete_thread_silent (ptid_t ptid)
484 delete_thread_1 (ptid, 1 /* silent */);
488 find_thread_global_id (int global_id)
490 struct thread_info *tp;
492 for (tp = thread_list; tp; tp = tp->next)
493 if (tp->global_num == global_id)
499 static struct thread_info *
500 find_thread_id (struct inferior *inf, int thr_num)
502 struct thread_info *tp;
504 for (tp = thread_list; tp; tp = tp->next)
505 if (tp->inf == inf && tp->per_inf_num == thr_num)
511 /* Find a thread_info by matching PTID. */
514 find_thread_ptid (ptid_t ptid)
516 struct thread_info *tp;
518 for (tp = thread_list; tp; tp = tp->next)
519 if (tp->ptid == ptid)
525 /* See gdbthread.h. */
528 find_thread_by_handle (struct value *thread_handle, struct inferior *inf)
530 return target_thread_handle_to_thread_info
531 (value_contents_all (thread_handle),
532 TYPE_LENGTH (value_type (thread_handle)),
537 * Thread iterator function.
539 * Calls a callback function once for each thread, so long as
540 * the callback function returns false. If the callback function
541 * returns true, the iteration will end and the current thread
542 * will be returned. This can be useful for implementing a
543 * search for a thread with arbitrary attributes, or for applying
544 * some operation to every thread.
546 * FIXME: some of the existing functionality, such as
547 * "Thread apply all", might be rewritten using this functionality.
551 iterate_over_threads (int (*callback) (struct thread_info *, void *),
554 struct thread_info *tp, *next;
556 for (tp = thread_list; tp; tp = next)
559 if ((*callback) (tp, data))
570 struct thread_info *tp;
572 for (tp = thread_list; tp; tp = tp->next)
578 /* Return the number of non-exited threads in the thread list. */
581 live_threads_count (void)
584 struct thread_info *tp;
586 ALL_NON_EXITED_THREADS (tp)
593 valid_global_thread_id (int global_id)
595 struct thread_info *tp;
597 for (tp = thread_list; tp; tp = tp->next)
598 if (tp->global_num == global_id)
605 ptid_to_global_thread_id (ptid_t ptid)
607 struct thread_info *tp;
609 for (tp = thread_list; tp; tp = tp->next)
610 if (tp->ptid == ptid)
611 return tp->global_num;
617 global_thread_id_to_ptid (int global_id)
619 struct thread_info *thread = find_thread_global_id (global_id);
624 return minus_one_ptid;
628 in_thread_list (ptid_t ptid)
630 struct thread_info *tp;
632 for (tp = thread_list; tp; tp = tp->next)
633 if (tp->ptid == ptid)
636 return 0; /* Never heard of 'im. */
639 /* Finds the first thread of the inferior given by PID. If PID is -1,
640 return the first thread in the list. */
643 first_thread_of_process (int pid)
645 struct thread_info *tp, *ret = NULL;
647 for (tp = thread_list; tp; tp = tp->next)
648 if (pid == -1 || ptid_get_pid (tp->ptid) == pid)
649 if (ret == NULL || tp->global_num < ret->global_num)
656 any_thread_of_process (int pid)
658 struct thread_info *tp;
660 gdb_assert (pid != 0);
662 /* Prefer the current thread. */
663 if (ptid_get_pid (inferior_ptid) == pid)
664 return inferior_thread ();
666 ALL_NON_EXITED_THREADS (tp)
667 if (ptid_get_pid (tp->ptid) == pid)
674 any_live_thread_of_process (int pid)
676 struct thread_info *curr_tp = NULL;
677 struct thread_info *tp;
678 struct thread_info *tp_executing = NULL;
680 gdb_assert (pid != 0);
682 /* Prefer the current thread if it's not executing. */
683 if (ptid_get_pid (inferior_ptid) == pid)
685 /* If the current thread is dead, forget it. If it's not
686 executing, use it. Otherwise, still choose it (below), but
687 only if no other non-executing thread is found. */
688 curr_tp = inferior_thread ();
689 if (curr_tp->state == THREAD_EXITED)
691 else if (!curr_tp->executing)
695 ALL_NON_EXITED_THREADS (tp)
696 if (ptid_get_pid (tp->ptid) == pid)
704 /* If both the current thread and all live threads are executing,
705 prefer the current thread. */
709 /* Otherwise, just return an executing thread, if any. */
713 /* Return true if TP is an active thread. */
715 thread_alive (struct thread_info *tp)
717 if (tp->state == THREAD_EXITED)
719 if (!target_thread_alive (tp->ptid))
724 /* See gdbthreads.h. */
729 struct thread_info *tp, *tmp;
731 ALL_THREADS_SAFE (tp, tmp)
733 if (!thread_alive (tp))
734 delete_thread (tp->ptid);
738 /* See gdbthreads.h. */
741 delete_exited_threads (void)
743 struct thread_info *tp, *tmp;
745 ALL_THREADS_SAFE (tp, tmp)
747 if (tp->state == THREAD_EXITED)
748 delete_thread (tp->ptid);
752 /* Disable storing stack temporaries for the thread whose id is
756 disable_thread_stack_temporaries (void *data)
758 ptid_t *pd = (ptid_t *) data;
759 struct thread_info *tp = find_thread_ptid (*pd);
763 tp->stack_temporaries_enabled = 0;
764 VEC_free (value_ptr, tp->stack_temporaries);
770 /* Enable storing stack temporaries for thread with id PTID and return a
771 cleanup which can disable and clear the stack temporaries. */
774 enable_thread_stack_temporaries (ptid_t ptid)
776 struct thread_info *tp = find_thread_ptid (ptid);
780 gdb_assert (tp != NULL);
782 tp->stack_temporaries_enabled = 1;
783 tp->stack_temporaries = NULL;
784 data = XNEW (ptid_t);
786 c = make_cleanup (disable_thread_stack_temporaries, data);
791 /* Return non-zero value if stack temporaies are enabled for the thread
795 thread_stack_temporaries_enabled_p (ptid_t ptid)
797 struct thread_info *tp = find_thread_ptid (ptid);
802 return tp->stack_temporaries_enabled;
805 /* Push V on to the stack temporaries of the thread with id PTID. */
808 push_thread_stack_temporary (ptid_t ptid, struct value *v)
810 struct thread_info *tp = find_thread_ptid (ptid);
812 gdb_assert (tp != NULL && tp->stack_temporaries_enabled);
813 VEC_safe_push (value_ptr, tp->stack_temporaries, v);
816 /* Return 1 if VAL is among the stack temporaries of the thread
817 with id PTID. Return 0 otherwise. */
820 value_in_thread_stack_temporaries (struct value *val, ptid_t ptid)
822 struct thread_info *tp = find_thread_ptid (ptid);
824 gdb_assert (tp != NULL && tp->stack_temporaries_enabled);
825 if (!VEC_empty (value_ptr, tp->stack_temporaries))
830 for (i = 0; VEC_iterate (value_ptr, tp->stack_temporaries, i, v); i++)
838 /* Return the last of the stack temporaries for thread with id PTID.
839 Return NULL if there are no stack temporaries for the thread. */
842 get_last_thread_stack_temporary (ptid_t ptid)
844 struct value *lastval = NULL;
845 struct thread_info *tp = find_thread_ptid (ptid);
847 gdb_assert (tp != NULL);
848 if (!VEC_empty (value_ptr, tp->stack_temporaries))
849 lastval = VEC_last (value_ptr, tp->stack_temporaries);
855 thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid)
857 struct inferior *inf;
858 struct thread_info *tp;
860 /* It can happen that what we knew as the target inferior id
861 changes. E.g, target remote may only discover the remote process
862 pid after adding the inferior to GDB's list. */
863 inf = find_inferior_ptid (old_ptid);
864 inf->pid = ptid_get_pid (new_ptid);
866 tp = find_thread_ptid (old_ptid);
869 observer_notify_thread_ptid_changed (old_ptid, new_ptid);
872 /* See gdbthread.h. */
875 set_resumed (ptid_t ptid, int resumed)
877 struct thread_info *tp;
878 int all = ptid == minus_one_ptid;
880 if (all || ptid_is_pid (ptid))
882 for (tp = thread_list; tp; tp = tp->next)
883 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
884 tp->resumed = resumed;
888 tp = find_thread_ptid (ptid);
889 gdb_assert (tp != NULL);
890 tp->resumed = resumed;
894 /* Helper for set_running, that marks one thread either running or
898 set_running_thread (struct thread_info *tp, int running)
902 if (running && tp->state == THREAD_STOPPED)
904 tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
908 /* If the thread is now marked stopped, remove it from
909 the step-over queue, so that we don't try to resume
910 it until the user wants it to. */
911 if (tp->step_over_next != NULL)
912 thread_step_over_chain_remove (tp);
919 set_running (ptid_t ptid, int running)
921 struct thread_info *tp;
922 int all = ptid == minus_one_ptid;
925 /* We try not to notify the observer if no thread has actually changed
926 the running state -- merely to reduce the number of messages to
927 frontend. Frontend is supposed to handle multiple *running just fine. */
928 if (all || ptid_is_pid (ptid))
930 for (tp = thread_list; tp; tp = tp->next)
931 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
933 if (tp->state == THREAD_EXITED)
936 if (set_running_thread (tp, running))
942 tp = find_thread_ptid (ptid);
943 gdb_assert (tp != NULL);
944 gdb_assert (tp->state != THREAD_EXITED);
945 if (set_running_thread (tp, running))
949 observer_notify_target_resumed (ptid);
953 is_thread_state (ptid_t ptid, enum thread_state state)
955 struct thread_info *tp;
957 tp = find_thread_ptid (ptid);
959 return tp->state == state;
963 is_stopped (ptid_t ptid)
965 return is_thread_state (ptid, THREAD_STOPPED);
969 is_exited (ptid_t ptid)
971 return is_thread_state (ptid, THREAD_EXITED);
975 is_running (ptid_t ptid)
977 return is_thread_state (ptid, THREAD_RUNNING);
981 is_executing (ptid_t ptid)
983 struct thread_info *tp;
985 tp = find_thread_ptid (ptid);
987 return tp->executing;
991 set_executing (ptid_t ptid, int executing)
993 struct thread_info *tp;
994 int all = ptid == minus_one_ptid;
996 if (all || ptid_is_pid (ptid))
998 for (tp = thread_list; tp; tp = tp->next)
999 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
1000 tp->executing = executing;
1004 tp = find_thread_ptid (ptid);
1006 tp->executing = executing;
1009 /* It only takes one running thread to spawn more threads.*/
1011 threads_executing = 1;
1012 /* Only clear the flag if the caller is telling us everything is
1014 else if (minus_one_ptid == ptid)
1015 threads_executing = 0;
1018 /* See gdbthread.h. */
1021 threads_are_executing (void)
1023 return threads_executing;
1027 set_stop_requested (ptid_t ptid, int stop)
1029 struct thread_info *tp;
1030 int all = ptid == minus_one_ptid;
1032 if (all || ptid_is_pid (ptid))
1034 for (tp = thread_list; tp; tp = tp->next)
1035 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
1036 tp->stop_requested = stop;
1040 tp = find_thread_ptid (ptid);
1042 tp->stop_requested = stop;
1045 /* Call the stop requested observer so other components of GDB can
1046 react to this request. */
1048 observer_notify_thread_stop_requested (ptid);
1052 finish_thread_state (ptid_t ptid)
1054 struct thread_info *tp;
1056 int any_started = 0;
1058 all = ptid == minus_one_ptid;
1060 if (all || ptid_is_pid (ptid))
1062 for (tp = thread_list; tp; tp = tp->next)
1064 if (tp->state == THREAD_EXITED)
1066 if (all || ptid_get_pid (ptid) == ptid_get_pid (tp->ptid))
1068 if (set_running_thread (tp, tp->executing))
1075 tp = find_thread_ptid (ptid);
1077 if (tp->state != THREAD_EXITED)
1079 if (set_running_thread (tp, tp->executing))
1085 observer_notify_target_resumed (ptid);
1089 finish_thread_state_cleanup (void *arg)
1091 ptid_t *ptid_p = (ptid_t *) arg;
1095 finish_thread_state (*ptid_p);
1098 /* See gdbthread.h. */
1101 validate_registers_access (void)
1103 /* No selected thread, no registers. */
1104 if (inferior_ptid == null_ptid)
1105 error (_("No thread selected."));
1107 /* Don't try to read from a dead thread. */
1108 if (is_exited (inferior_ptid))
1109 error (_("The current thread has terminated"));
1111 /* ... or from a spinning thread. FIXME: This isn't actually fully
1112 correct. It'll allow an user-requested access (e.g., "print $pc"
1113 at the prompt) when a thread is not executing for some internal
1114 reason, but is marked running from the user's perspective. E.g.,
1115 the thread is waiting for its turn in the step-over queue. */
1116 if (is_executing (inferior_ptid))
1117 error (_("Selected thread is running."));
1120 /* See gdbthread.h. */
1123 can_access_registers_ptid (ptid_t ptid)
1125 /* No thread, no registers. */
1126 if (ptid == null_ptid)
1129 /* Don't try to read from a dead thread. */
1130 if (is_exited (ptid))
1133 /* ... or from a spinning thread. FIXME: see validate_registers_access. */
1134 if (is_executing (ptid))
1141 pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread)
1143 return (pc >= thread->control.step_range_start
1144 && pc < thread->control.step_range_end);
1147 /* Helper for print_thread_info. Returns true if THR should be
1148 printed. If REQUESTED_THREADS, a list of GDB ids/ranges, is not
1149 NULL, only print THR if its ID is included in the list. GLOBAL_IDS
1150 is true if REQUESTED_THREADS is list of global IDs, false if a list
1151 of per-inferior thread ids. If PID is not -1, only print THR if it
1152 is a thread from the process PID. Otherwise, threads from all
1153 attached PIDs are printed. If both REQUESTED_THREADS is not NULL
1154 and PID is not -1, then the thread is printed if it belongs to the
1155 specified process. Otherwise, an error is raised. */
1158 should_print_thread (const char *requested_threads, int default_inf_num,
1159 int global_ids, int pid, struct thread_info *thr)
1161 if (requested_threads != NULL && *requested_threads != '\0')
1166 in_list = number_is_in_list (requested_threads, thr->global_num);
1168 in_list = tid_is_in_list (requested_threads, default_inf_num,
1169 thr->inf->num, thr->per_inf_num);
1174 if (pid != -1 && ptid_get_pid (thr->ptid) != pid)
1176 if (requested_threads != NULL && *requested_threads != '\0')
1177 error (_("Requested thread not found in requested process"));
1181 if (thr->state == THREAD_EXITED)
1187 /* Like print_thread_info, but in addition, GLOBAL_IDS indicates
1188 whether REQUESTED_THREADS is a list of global or per-inferior
1192 print_thread_info_1 (struct ui_out *uiout, const char *requested_threads,
1193 int global_ids, int pid,
1194 int show_global_ids)
1196 struct thread_info *tp;
1197 ptid_t current_ptid;
1198 const char *extra_info, *name, *target_id;
1199 struct inferior *inf;
1200 int default_inf_num = current_inferior ()->num;
1202 update_thread_list ();
1203 current_ptid = inferior_ptid;
1206 /* For backward compatibility, we make a list for MI. A table is
1207 preferable for the CLI, though, because it shows table
1209 gdb::optional<ui_out_emit_list> list_emitter;
1210 gdb::optional<ui_out_emit_table> table_emitter;
1212 if (uiout->is_mi_like_p ())
1213 list_emitter.emplace (uiout, "threads");
1218 for (tp = thread_list; tp; tp = tp->next)
1220 if (!should_print_thread (requested_threads, default_inf_num,
1221 global_ids, pid, tp))
1229 if (requested_threads == NULL || *requested_threads == '\0')
1230 uiout->message (_("No threads.\n"));
1232 uiout->message (_("No threads match '%s'.\n"),
1237 table_emitter.emplace (uiout, show_global_ids ? 5 : 4,
1238 n_threads, "threads");
1240 uiout->table_header (1, ui_left, "current", "");
1241 uiout->table_header (4, ui_left, "id-in-tg", "Id");
1242 if (show_global_ids)
1243 uiout->table_header (4, ui_left, "id", "GId");
1244 uiout->table_header (17, ui_left, "target-id", "Target Id");
1245 uiout->table_header (1, ui_left, "frame", "Frame");
1246 uiout->table_body ();
1249 /* We'll be switching threads temporarily. */
1250 scoped_restore_current_thread restore_thread;
1252 ALL_THREADS_BY_INFERIOR (inf, tp)
1256 if (!should_print_thread (requested_threads, default_inf_num,
1257 global_ids, pid, tp))
1260 ui_out_emit_tuple tuple_emitter (uiout, NULL);
1262 if (!uiout->is_mi_like_p ())
1264 if (tp->ptid == current_ptid)
1265 uiout->field_string ("current", "*");
1267 uiout->field_skip ("current");
1269 uiout->field_string ("id-in-tg", print_thread_id (tp));
1272 if (show_global_ids || uiout->is_mi_like_p ())
1273 uiout->field_int ("id", tp->global_num);
1275 /* For the CLI, we stuff everything into the target-id field.
1276 This is a gross hack to make the output come out looking
1277 correct. The underlying problem here is that ui-out has no
1278 way to specify that a field's space allocation should be
1279 shared by several fields. For MI, we do the right thing
1282 target_id = target_pid_to_str (tp->ptid);
1283 extra_info = target_extra_thread_info (tp);
1284 name = tp->name ? tp->name : target_thread_name (tp);
1286 if (uiout->is_mi_like_p ())
1288 uiout->field_string ("target-id", target_id);
1290 uiout->field_string ("details", extra_info);
1292 uiout->field_string ("name", name);
1296 std::string contents;
1298 if (extra_info && name)
1299 contents = string_printf ("%s \"%s\" (%s)", target_id,
1301 else if (extra_info)
1302 contents = string_printf ("%s (%s)", target_id, extra_info);
1304 contents = string_printf ("%s \"%s\"", target_id, name);
1306 contents = target_id;
1308 uiout->field_string ("target-id", contents.c_str ());
1311 if (tp->state == THREAD_RUNNING)
1312 uiout->text ("(running)\n");
1315 /* The switch below puts us at the top of the stack (leaf
1317 switch_to_thread (tp->ptid);
1318 print_stack_frame (get_selected_frame (NULL),
1319 /* For MI output, print frame level. */
1320 uiout->is_mi_like_p (),
1324 if (uiout->is_mi_like_p ())
1326 const char *state = "stopped";
1328 if (tp->state == THREAD_RUNNING)
1330 uiout->field_string ("state", state);
1333 core = target_core_of_thread (tp->ptid);
1334 if (uiout->is_mi_like_p () && core != -1)
1335 uiout->field_int ("core", core);
1338 /* This end scope restores the current thread and the frame
1339 selected before the "info threads" command, and it finishes the
1340 ui-out list or table. */
1343 if (pid == -1 && requested_threads == NULL)
1345 if (uiout->is_mi_like_p ()
1346 && inferior_ptid != null_ptid)
1348 int num = ptid_to_global_thread_id (inferior_ptid);
1350 gdb_assert (num != 0);
1351 uiout->field_int ("current-thread-id", num);
1354 if (inferior_ptid != null_ptid && is_exited (inferior_ptid))
1355 uiout->message ("\n\
1356 The current thread <Thread ID %s> has terminated. See `help thread'.\n",
1357 print_thread_id (inferior_thread ()));
1358 else if (thread_list != NULL && inferior_ptid == null_ptid)
1359 uiout->message ("\n\
1360 No selected thread. See `help thread'.\n");
1364 /* See gdbthread.h. */
1367 print_thread_info (struct ui_out *uiout, char *requested_threads, int pid)
1369 print_thread_info_1 (uiout, requested_threads, 1, pid, 0);
1372 /* Implementation of the "info threads" command.
1374 Note: this has the drawback that it _really_ switches
1375 threads, which frees the frame cache. A no-side
1376 effects info-threads command would be nicer. */
1379 info_threads_command (const char *arg, int from_tty)
1381 int show_global_ids = 0;
1384 && check_for_argument (&arg, "-gid", sizeof ("-gid") - 1))
1386 arg = skip_spaces (arg);
1387 show_global_ids = 1;
1390 print_thread_info_1 (current_uiout, arg, 0, -1, show_global_ids);
1393 /* See gdbthread.h. */
1396 switch_to_thread_no_regs (struct thread_info *thread)
1398 struct inferior *inf = thread->inf;
1400 set_current_program_space (inf->pspace);
1401 set_current_inferior (inf);
1403 inferior_ptid = thread->ptid;
1404 stop_pc = ~(CORE_ADDR) 0;
1407 /* Switch to no thread selected. */
1410 switch_to_no_thread ()
1412 if (inferior_ptid == null_ptid)
1415 inferior_ptid = null_ptid;
1416 reinit_frame_cache ();
1417 stop_pc = ~(CORE_ADDR) 0;
1420 /* Switch from one thread to another. */
1423 switch_to_thread (thread_info *thr)
1425 gdb_assert (thr != NULL);
1427 if (inferior_ptid == thr->ptid)
1430 switch_to_thread_no_regs (thr);
1432 reinit_frame_cache ();
1434 /* We don't check for is_stopped, because we're called at times
1435 while in the TARGET_RUNNING state, e.g., while handling an
1437 if (thr->state != THREAD_EXITED
1439 stop_pc = regcache_read_pc (get_thread_regcache (thr->ptid));
1442 /* See gdbthread.h. */
1445 switch_to_thread (ptid_t ptid)
1447 if (ptid == null_ptid)
1448 switch_to_no_thread ();
1450 switch_to_thread (find_thread_ptid (ptid));
1454 restore_selected_frame (struct frame_id a_frame_id, int frame_level)
1456 struct frame_info *frame = NULL;
1459 /* This means there was no selected frame. */
1460 if (frame_level == -1)
1462 select_frame (NULL);
1466 gdb_assert (frame_level >= 0);
1468 /* Restore by level first, check if the frame id is the same as
1469 expected. If that fails, try restoring by frame id. If that
1470 fails, nothing to do, just warn the user. */
1472 count = frame_level;
1473 frame = find_relative_frame (get_current_frame (), &count);
1476 /* The frame ids must match - either both valid or both outer_frame_id.
1477 The latter case is not failsafe, but since it's highly unlikely
1478 the search by level finds the wrong frame, it's 99.9(9)% of
1479 the time (for all practical purposes) safe. */
1480 && frame_id_eq (get_frame_id (frame), a_frame_id))
1482 /* Cool, all is fine. */
1483 select_frame (frame);
1487 frame = frame_find_by_id (a_frame_id);
1490 /* Cool, refound it. */
1491 select_frame (frame);
1495 /* Nothing else to do, the frame layout really changed. Select the
1496 innermost stack frame. */
1497 select_frame (get_current_frame ());
1499 /* Warn the user. */
1500 if (frame_level > 0 && !current_uiout->is_mi_like_p ())
1502 warning (_("Couldn't restore frame #%d in "
1503 "current thread. Bottom (innermost) frame selected:"),
1505 /* For MI, we should probably have a notification about
1506 current frame change. But this error is not very
1507 likely, so don't bother for now. */
1508 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1512 scoped_restore_current_thread::~scoped_restore_current_thread ()
1514 /* If an entry of thread_info was previously selected, it won't be
1515 deleted because we've increased its refcount. The thread represented
1516 by this thread_info entry may have already exited (due to normal exit,
1517 detach, etc), so the thread_info.state is THREAD_EXITED. */
1518 if (m_thread != NULL
1519 /* If the previously selected thread belonged to a process that has
1520 in the mean time exited (or killed, detached, etc.), then don't revert
1521 back to it, but instead simply drop back to no thread selected. */
1523 switch_to_thread (m_thread);
1526 switch_to_no_thread ();
1527 set_current_inferior (m_inf);
1530 /* The running state of the originally selected thread may have
1531 changed, so we have to recheck it here. */
1532 if (inferior_ptid != null_ptid
1534 && is_stopped (inferior_ptid)
1535 && target_has_registers
1537 && target_has_memory)
1538 restore_selected_frame (m_selected_frame_id, m_selected_frame_level);
1540 if (m_thread != NULL)
1541 m_thread->decref ();
1545 scoped_restore_current_thread::scoped_restore_current_thread ()
1548 m_inf = current_inferior ();
1550 if (inferior_ptid != null_ptid)
1552 thread_info *tp = find_thread_ptid (inferior_ptid);
1553 struct frame_info *frame;
1555 gdb_assert (tp != NULL);
1557 m_was_stopped = tp->state == THREAD_STOPPED;
1559 && target_has_registers
1561 && target_has_memory)
1563 /* When processing internal events, there might not be a
1564 selected frame. If we naively call get_selected_frame
1565 here, then we can end up reading debuginfo for the
1566 current frame, but we don't generally need the debuginfo
1568 frame = get_selected_frame_if_set ();
1573 m_selected_frame_id = get_frame_id (frame);
1574 m_selected_frame_level = frame_relative_level (frame);
1583 /* See gdbthread.h. */
1586 show_thread_that_caused_stop (void)
1588 return highest_thread_num > 1;
1591 /* See gdbthread.h. */
1594 show_inferior_qualified_tids (void)
1596 return (inferior_list->next != NULL || inferior_list->num != 1);
1599 /* See gdbthread.h. */
1602 print_thread_id (struct thread_info *thr)
1604 char *s = get_print_cell ();
1606 if (show_inferior_qualified_tids ())
1607 xsnprintf (s, PRINT_CELL_SIZE, "%d.%d", thr->inf->num, thr->per_inf_num);
1609 xsnprintf (s, PRINT_CELL_SIZE, "%d", thr->per_inf_num);
1613 /* If true, tp_array_compar should sort in ascending order, otherwise
1614 in descending order. */
1616 static bool tp_array_compar_ascending;
1618 /* Sort an array for struct thread_info pointers by thread ID (first
1619 by inferior number, and then by per-inferior thread number). The
1620 order is determined by TP_ARRAY_COMPAR_ASCENDING. */
1623 tp_array_compar (const thread_info *a, const thread_info *b)
1625 if (a->inf->num != b->inf->num)
1627 if (tp_array_compar_ascending)
1628 return a->inf->num < b->inf->num;
1630 return a->inf->num > b->inf->num;
1633 if (tp_array_compar_ascending)
1634 return (a->per_inf_num < b->per_inf_num);
1636 return (a->per_inf_num > b->per_inf_num);
1639 /* Apply a GDB command to a list of threads. List syntax is a whitespace
1640 seperated list of numbers, or ranges, or the keyword `all'. Ranges consist
1641 of two numbers seperated by a hyphen. Examples:
1643 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
1644 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
1645 thread apply all p x/i $pc Apply x/i $pc cmd to all threads. */
1648 thread_apply_all_command (const char *cmd, int from_tty)
1650 tp_array_compar_ascending = false;
1652 && check_for_argument (&cmd, "-ascending", strlen ("-ascending")))
1654 cmd = skip_spaces (cmd);
1655 tp_array_compar_ascending = true;
1658 if (cmd == NULL || *cmd == '\000')
1659 error (_("Please specify a command following the thread ID list"));
1661 update_thread_list ();
1663 int tc = live_threads_count ();
1666 /* Save a copy of the thread list and increment each thread's
1667 refcount while executing the command in the context of each
1668 thread, in case the command is one that wipes threads. E.g.,
1669 detach, kill, disconnect, etc., or even normally continuing
1670 over an inferior or thread exit. */
1671 std::vector<thread_info *> thr_list_cpy;
1672 thr_list_cpy.reserve (tc);
1677 ALL_NON_EXITED_THREADS (tp)
1679 thr_list_cpy.push_back (tp);
1682 gdb_assert (thr_list_cpy.size () == tc);
1685 /* Increment the refcounts, and restore them back on scope
1687 scoped_inc_dec_ref inc_dec_ref (thr_list_cpy);
1689 std::sort (thr_list_cpy.begin (), thr_list_cpy.end (), tp_array_compar);
1691 scoped_restore_current_thread restore_thread;
1693 for (thread_info *thr : thr_list_cpy)
1694 if (thread_alive (thr))
1696 switch_to_thread (thr->ptid);
1697 printf_filtered (_("\nThread %s (%s):\n"),
1698 print_thread_id (thr),
1699 target_pid_to_str (inferior_ptid));
1701 execute_command (cmd, from_tty);
1706 /* Implementation of the "thread apply" command. */
1709 thread_apply_command (const char *tidlist, int from_tty)
1711 const char *cmd = NULL;
1712 tid_range_parser parser;
1714 if (tidlist == NULL || *tidlist == '\000')
1715 error (_("Please specify a thread ID list"));
1717 parser.init (tidlist, current_inferior ()->num);
1718 while (!parser.finished ())
1720 int inf_num, thr_start, thr_end;
1722 if (!parser.get_tid_range (&inf_num, &thr_start, &thr_end))
1724 cmd = parser.cur_tok ();
1730 error (_("Please specify a command following the thread ID list"));
1732 if (tidlist == cmd || !isalpha (cmd[0]))
1733 invalid_thread_id_error (cmd);
1735 scoped_restore_current_thread restore_thread;
1737 parser.init (tidlist, current_inferior ()->num);
1738 while (!parser.finished () && parser.cur_tok () < cmd)
1740 struct thread_info *tp = NULL;
1741 struct inferior *inf;
1742 int inf_num, thr_num;
1744 parser.get_tid (&inf_num, &thr_num);
1745 inf = find_inferior_id (inf_num);
1747 tp = find_thread_id (inf, thr_num);
1749 if (parser.in_star_range ())
1753 warning (_("Unknown inferior %d"), inf_num);
1754 parser.skip_range ();
1758 /* No use looking for threads past the highest thread number
1759 the inferior ever had. */
1760 if (thr_num >= inf->highest_thread_num)
1761 parser.skip_range ();
1763 /* Be quiet about unknown threads numbers. */
1770 if (show_inferior_qualified_tids () || parser.tid_is_qualified ())
1771 warning (_("Unknown thread %d.%d"), inf_num, thr_num);
1773 warning (_("Unknown thread %d"), thr_num);
1777 if (!thread_alive (tp))
1779 warning (_("Thread %s has terminated."), print_thread_id (tp));
1783 switch_to_thread (tp->ptid);
1785 printf_filtered (_("\nThread %s (%s):\n"), print_thread_id (tp),
1786 target_pid_to_str (inferior_ptid));
1787 execute_command (cmd, from_tty);
1791 /* Switch to the specified thread. Will dispatch off to thread_apply_command
1792 if prefix of arg is `apply'. */
1795 thread_command (const char *tidstr, int from_tty)
1799 if (inferior_ptid == null_ptid)
1800 error (_("No thread selected"));
1802 if (target_has_stack)
1804 struct thread_info *tp = inferior_thread ();
1806 if (is_exited (inferior_ptid))
1807 printf_filtered (_("[Current thread is %s (%s) (exited)]\n"),
1808 print_thread_id (tp),
1809 target_pid_to_str (inferior_ptid));
1811 printf_filtered (_("[Current thread is %s (%s)]\n"),
1812 print_thread_id (tp),
1813 target_pid_to_str (inferior_ptid));
1816 error (_("No stack."));
1820 ptid_t previous_ptid = inferior_ptid;
1822 thread_select (tidstr, parse_thread_id (tidstr, NULL));
1824 /* Print if the thread has not changed, otherwise an event will
1826 if (inferior_ptid == previous_ptid)
1828 print_selected_thread_frame (current_uiout,
1829 USER_SELECTED_THREAD
1830 | USER_SELECTED_FRAME);
1834 observer_notify_user_selected_context_changed (USER_SELECTED_THREAD
1835 | USER_SELECTED_FRAME);
1840 /* Implementation of `thread name'. */
1843 thread_name_command (const char *arg, int from_tty)
1845 struct thread_info *info;
1847 if (inferior_ptid == null_ptid)
1848 error (_("No thread selected"));
1850 arg = skip_spaces (arg);
1852 info = inferior_thread ();
1854 info->name = arg ? xstrdup (arg) : NULL;
1857 /* Find thread ids with a name, target pid, or extra info matching ARG. */
1860 thread_find_command (const char *arg, int from_tty)
1862 struct thread_info *tp;
1864 unsigned long match = 0;
1866 if (arg == NULL || *arg == '\0')
1867 error (_("Command requires an argument."));
1869 tmp = re_comp (arg);
1871 error (_("Invalid regexp (%s): %s"), tmp, arg);
1873 update_thread_list ();
1874 for (tp = thread_list; tp; tp = tp->next)
1876 if (tp->name != NULL && re_exec (tp->name))
1878 printf_filtered (_("Thread %s has name '%s'\n"),
1879 print_thread_id (tp), tp->name);
1883 tmp = target_thread_name (tp);
1884 if (tmp != NULL && re_exec (tmp))
1886 printf_filtered (_("Thread %s has target name '%s'\n"),
1887 print_thread_id (tp), tmp);
1891 tmp = target_pid_to_str (tp->ptid);
1892 if (tmp != NULL && re_exec (tmp))
1894 printf_filtered (_("Thread %s has target id '%s'\n"),
1895 print_thread_id (tp), tmp);
1899 tmp = target_extra_thread_info (tp);
1900 if (tmp != NULL && re_exec (tmp))
1902 printf_filtered (_("Thread %s has extra info '%s'\n"),
1903 print_thread_id (tp), tmp);
1908 printf_filtered (_("No threads match '%s'\n"), arg);
1911 /* Print notices when new threads are attached and detached. */
1912 int print_thread_events = 1;
1914 show_print_thread_events (struct ui_file *file, int from_tty,
1915 struct cmd_list_element *c, const char *value)
1917 fprintf_filtered (file,
1918 _("Printing of thread events is %s.\n"),
1922 /* See gdbthread.h. */
1925 thread_select (const char *tidstr, thread_info *tp)
1927 if (!thread_alive (tp))
1928 error (_("Thread ID %s has terminated."), tidstr);
1930 switch_to_thread (tp->ptid);
1932 annotate_thread_changed ();
1934 /* Since the current thread may have changed, see if there is any
1935 exited thread we can now delete. */
1939 /* Print thread and frame switch command response. */
1942 print_selected_thread_frame (struct ui_out *uiout,
1943 user_selected_what selection)
1945 struct thread_info *tp = inferior_thread ();
1947 if (selection & USER_SELECTED_THREAD)
1949 if (uiout->is_mi_like_p ())
1951 uiout->field_int ("new-thread-id",
1952 inferior_thread ()->global_num);
1956 uiout->text ("[Switching to thread ");
1957 uiout->field_string ("new-thread-id", print_thread_id (tp));
1959 uiout->text (target_pid_to_str (inferior_ptid));
1964 if (tp->state == THREAD_RUNNING)
1966 if (selection & USER_SELECTED_THREAD)
1967 uiout->text ("(running)\n");
1969 else if (selection & USER_SELECTED_FRAME)
1971 if (selection & USER_SELECTED_THREAD)
1974 if (has_stack_frames ())
1975 print_stack_frame_to_uiout (uiout, get_selected_frame (NULL),
1980 /* Update the 'threads_executing' global based on the threads we know
1984 update_threads_executing (void)
1986 struct thread_info *tp;
1988 threads_executing = 0;
1989 ALL_NON_EXITED_THREADS (tp)
1993 threads_executing = 1;
2000 update_thread_list (void)
2002 target_update_thread_list ();
2003 update_threads_executing ();
2006 /* Return a new value for the selected thread's id. Return a value of
2007 0 if no thread is selected. If GLOBAL is true, return the thread's
2008 global number. Otherwise return the per-inferior number. */
2010 static struct value *
2011 thread_num_make_value_helper (struct gdbarch *gdbarch, int global)
2013 struct thread_info *tp = find_thread_ptid (inferior_ptid);
2019 int_val = tp->global_num;
2021 int_val = tp->per_inf_num;
2023 return value_from_longest (builtin_type (gdbarch)->builtin_int, int_val);
2026 /* Return a new value for the selected thread's per-inferior thread
2027 number. Return a value of 0 if no thread is selected, or no
2030 static struct value *
2031 thread_id_per_inf_num_make_value (struct gdbarch *gdbarch,
2032 struct internalvar *var,
2035 return thread_num_make_value_helper (gdbarch, 0);
2038 /* Return a new value for the selected thread's global id. Return a
2039 value of 0 if no thread is selected, or no threads exist. */
2041 static struct value *
2042 global_thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
2045 return thread_num_make_value_helper (gdbarch, 1);
2048 /* Commands with a prefix of `thread'. */
2049 struct cmd_list_element *thread_cmd_list = NULL;
2051 /* Implementation of `thread' variable. */
2053 static const struct internalvar_funcs thread_funcs =
2055 thread_id_per_inf_num_make_value,
2060 /* Implementation of `gthread' variable. */
2062 static const struct internalvar_funcs gthread_funcs =
2064 global_thread_id_make_value,
2070 _initialize_thread (void)
2072 static struct cmd_list_element *thread_apply_list = NULL;
2074 add_info ("threads", info_threads_command,
2075 _("Display currently known threads.\n\
2076 Usage: info threads [-gid] [ID]...\n\
2077 -gid: Show global thread IDs.\n\
2078 If ID is given, it is a space-separated list of IDs of threads to display.\n\
2079 Otherwise, all threads are displayed."));
2081 add_prefix_cmd ("thread", class_run, thread_command, _("\
2082 Use this command to switch between threads.\n\
2083 The new thread ID must be currently known."),
2084 &thread_cmd_list, "thread ", 1, &cmdlist);
2086 add_prefix_cmd ("apply", class_run, thread_apply_command,
2087 _("Apply a command to a list of threads."),
2088 &thread_apply_list, "thread apply ", 1, &thread_cmd_list);
2090 add_cmd ("all", class_run, thread_apply_all_command,
2092 Apply a command to all threads.\n\
2094 Usage: thread apply all [-ascending] <command>\n\
2095 -ascending: Call <command> for all threads in ascending order.\n\
2096 The default is descending order.\
2098 &thread_apply_list);
2100 add_cmd ("name", class_run, thread_name_command,
2101 _("Set the current thread's name.\n\
2102 Usage: thread name [NAME]\n\
2103 If NAME is not given, then any existing name is removed."), &thread_cmd_list);
2105 add_cmd ("find", class_run, thread_find_command, _("\
2106 Find threads that match a regular expression.\n\
2107 Usage: thread find REGEXP\n\
2108 Will display thread ids whose name, target ID, or extra info matches REGEXP."),
2111 add_com_alias ("t", "thread", class_run, 1);
2113 add_setshow_boolean_cmd ("thread-events", no_class,
2114 &print_thread_events, _("\
2115 Set printing of thread events (such as thread start and exit)."), _("\
2116 Show printing of thread events (such as thread start and exit)."), NULL,
2118 show_print_thread_events,
2119 &setprintlist, &showprintlist);
2121 create_internalvar_type_lazy ("_thread", &thread_funcs, NULL);
2122 create_internalvar_type_lazy ("_gthread", >hread_funcs, NULL);