1 /* Multi-process/thread control for GDB, the GNU debugger.
3 Copyright (C) 1986-2017 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 void thread_apply_all_command (char *, int);
64 static int thread_alive (struct thread_info *);
66 /* RAII type used to increase / decrease the refcount of each thread
67 in a given list of threads. */
69 class scoped_inc_dec_ref
72 explicit scoped_inc_dec_ref (const std::vector<thread_info *> &thrds)
75 for (thread_info *thr : m_thrds)
79 ~scoped_inc_dec_ref ()
81 for (thread_info *thr : m_thrds)
86 const std::vector<thread_info *> &m_thrds;
91 inferior_thread (void)
93 struct thread_info *tp = find_thread_ptid (inferior_ptid);
98 /* Delete the breakpoint pointed at by BP_P, if there's one. */
101 delete_thread_breakpoint (struct breakpoint **bp_p)
105 delete_breakpoint (*bp_p);
111 delete_step_resume_breakpoint (struct thread_info *tp)
114 delete_thread_breakpoint (&tp->control.step_resume_breakpoint);
118 delete_exception_resume_breakpoint (struct thread_info *tp)
121 delete_thread_breakpoint (&tp->control.exception_resume_breakpoint);
124 /* See gdbthread.h. */
127 delete_single_step_breakpoints (struct thread_info *tp)
130 delete_thread_breakpoint (&tp->control.single_step_breakpoints);
133 /* Delete the breakpoint pointed at by BP_P at the next stop, if
137 delete_at_next_stop (struct breakpoint **bp)
141 (*bp)->disposition = disp_del_at_next_stop;
146 /* See gdbthread.h. */
149 thread_has_single_step_breakpoints_set (struct thread_info *tp)
151 return tp->control.single_step_breakpoints != NULL;
154 /* See gdbthread.h. */
157 thread_has_single_step_breakpoint_here (struct thread_info *tp,
158 const address_space *aspace,
161 struct breakpoint *ss_bps = tp->control.single_step_breakpoints;
163 return (ss_bps != NULL
164 && breakpoint_has_location_inserted_here (ss_bps, aspace, addr));
167 /* See gdbthread.h. */
170 thread_cancel_execution_command (struct thread_info *thr)
172 if (thr->thread_fsm != NULL)
174 thread_fsm_clean_up (thr->thread_fsm, thr);
175 thread_fsm_delete (thr->thread_fsm);
176 thr->thread_fsm = NULL;
181 clear_thread_inferior_resources (struct thread_info *tp)
183 /* NOTE: this will take care of any left-over step_resume breakpoints,
184 but not any user-specified thread-specific breakpoints. We can not
185 delete the breakpoint straight-off, because the inferior might not
186 be stopped at the moment. */
187 delete_at_next_stop (&tp->control.step_resume_breakpoint);
188 delete_at_next_stop (&tp->control.exception_resume_breakpoint);
189 delete_at_next_stop (&tp->control.single_step_breakpoints);
191 delete_longjmp_breakpoint_at_next_stop (tp->global_num);
193 bpstat_clear (&tp->control.stop_bpstat);
195 btrace_teardown (tp);
197 thread_cancel_execution_command (tp);
200 /* Set the TP's state as exited. */
203 set_thread_exited (thread_info *tp, int silent)
205 /* Dead threads don't need to step-over. Remove from queue. */
206 if (tp->step_over_next != NULL)
207 thread_step_over_chain_remove (tp);
209 if (tp->state != THREAD_EXITED)
211 observer_notify_thread_exit (tp, silent);
213 /* Tag it as exited. */
214 tp->state = THREAD_EXITED;
216 /* Clear breakpoints, etc. associated with this thread. */
217 clear_thread_inferior_resources (tp);
222 init_thread_list (void)
224 struct thread_info *tp, *tpnext;
226 highest_thread_num = 0;
231 for (tp = thread_list; tp; tp = tpnext)
234 if (tp->deletable ())
237 set_thread_exited (tp, 1);
241 threads_executing = 0;
244 /* Allocate a new thread of inferior INF with target id PTID and add
245 it to the thread list. */
247 static struct thread_info *
248 new_thread (struct inferior *inf, ptid_t ptid)
250 thread_info *tp = new thread_info (inf, ptid);
252 if (thread_list == NULL)
256 struct thread_info *last;
258 for (last = thread_list; last->next != NULL; last = last->next)
267 add_thread_silent (ptid_t ptid)
269 struct thread_info *tp;
270 struct inferior *inf = find_inferior_ptid (ptid);
271 gdb_assert (inf != NULL);
273 tp = find_thread_ptid (ptid);
275 /* Found an old thread with the same id. It has to be dead,
276 otherwise we wouldn't be adding a new thread with the same id.
277 The OS is reusing this id --- delete it, and recreate a new
280 /* In addition to deleting the thread, if this is the current
281 thread, then we need to take care that delete_thread doesn't
282 really delete the thread if it is inferior_ptid. Create a
283 new template thread in the list with an invalid ptid, switch
284 to it, delete the original thread, reset the new thread's
285 ptid, and switch to it. */
287 if (inferior_ptid == ptid)
289 tp = new_thread (inf, null_ptid);
291 /* Make switch_to_thread not read from the thread. */
292 tp->state = THREAD_EXITED;
293 switch_to_thread (null_ptid);
295 /* Now we can delete it. */
296 delete_thread (ptid);
298 /* Now reset its ptid, and reswitch inferior_ptid to it. */
300 tp->state = THREAD_STOPPED;
301 switch_to_thread (ptid);
303 observer_notify_new_thread (tp);
309 /* Just go ahead and delete it. */
310 delete_thread (ptid);
313 tp = new_thread (inf, ptid);
314 observer_notify_new_thread (tp);
320 add_thread_with_info (ptid_t ptid, struct private_thread_info *priv)
322 struct thread_info *result = add_thread_silent (ptid);
326 if (print_thread_events)
327 printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
329 annotate_new_thread ();
334 add_thread (ptid_t ptid)
336 return add_thread_with_info (ptid, NULL);
339 thread_info::thread_info (struct inferior *inf_, ptid_t ptid_)
340 : ptid (ptid_), inf (inf_)
342 gdb_assert (inf_ != NULL);
344 this->global_num = ++highest_thread_num;
345 this->per_inf_num = ++inf_->highest_thread_num;
347 /* Nothing to follow yet. */
348 memset (&this->pending_follow, 0, sizeof (this->pending_follow));
349 this->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
350 this->suspend.waitstatus.kind = TARGET_WAITKIND_IGNORE;
353 thread_info::~thread_info ()
357 if (this->private_dtor)
358 this->private_dtor (this->priv);
366 /* Add TP to the end of the step-over chain LIST_P. */
369 step_over_chain_enqueue (struct thread_info **list_p, struct thread_info *tp)
371 gdb_assert (tp->step_over_next == NULL);
372 gdb_assert (tp->step_over_prev == NULL);
377 tp->step_over_prev = tp->step_over_next = tp;
381 struct thread_info *head = *list_p;
382 struct thread_info *tail = head->step_over_prev;
384 tp->step_over_prev = tail;
385 tp->step_over_next = head;
386 head->step_over_prev = tp;
387 tail->step_over_next = tp;
391 /* Remove TP from step-over chain LIST_P. */
394 step_over_chain_remove (struct thread_info **list_p, struct thread_info *tp)
396 gdb_assert (tp->step_over_next != NULL);
397 gdb_assert (tp->step_over_prev != NULL);
401 if (tp == tp->step_over_next)
404 *list_p = tp->step_over_next;
407 tp->step_over_prev->step_over_next = tp->step_over_next;
408 tp->step_over_next->step_over_prev = tp->step_over_prev;
409 tp->step_over_prev = tp->step_over_next = NULL;
412 /* See gdbthread.h. */
415 thread_step_over_chain_next (struct thread_info *tp)
417 struct thread_info *next = tp->step_over_next;
419 return (next == step_over_queue_head ? NULL : next);
422 /* See gdbthread.h. */
425 thread_is_in_step_over_chain (struct thread_info *tp)
427 return (tp->step_over_next != NULL);
430 /* See gdbthread.h. */
433 thread_step_over_chain_enqueue (struct thread_info *tp)
435 step_over_chain_enqueue (&step_over_queue_head, tp);
438 /* See gdbthread.h. */
441 thread_step_over_chain_remove (struct thread_info *tp)
443 step_over_chain_remove (&step_over_queue_head, tp);
446 /* Delete thread PTID. If SILENT, don't notify the observer of this
449 delete_thread_1 (ptid_t ptid, int silent)
451 struct thread_info *tp, *tpprev;
455 for (tp = thread_list; tp; tpprev = tp, tp = tp->next)
456 if (tp->ptid == ptid)
462 set_thread_exited (tp, silent);
464 if (!tp->deletable ())
466 /* Will be really deleted some other time. */
471 tpprev->next = tp->next;
473 thread_list = tp->next;
478 /* Delete thread PTID and notify of thread exit. If this is
479 inferior_ptid, don't actually delete it, but tag it as exited and
480 do the notification. If PTID is the user selected thread, clear
483 delete_thread (ptid_t ptid)
485 delete_thread_1 (ptid, 0 /* not silent */);
489 delete_thread_silent (ptid_t ptid)
491 delete_thread_1 (ptid, 1 /* silent */);
495 find_thread_global_id (int global_id)
497 struct thread_info *tp;
499 for (tp = thread_list; tp; tp = tp->next)
500 if (tp->global_num == global_id)
506 static struct thread_info *
507 find_thread_id (struct inferior *inf, int thr_num)
509 struct thread_info *tp;
511 for (tp = thread_list; tp; tp = tp->next)
512 if (tp->inf == inf && tp->per_inf_num == thr_num)
518 /* Find a thread_info by matching PTID. */
521 find_thread_ptid (ptid_t ptid)
523 struct thread_info *tp;
525 for (tp = thread_list; tp; tp = tp->next)
526 if (tp->ptid == ptid)
532 /* See gdbthread.h. */
535 find_thread_by_handle (struct value *thread_handle, struct inferior *inf)
537 return target_thread_handle_to_thread_info
538 (value_contents_all (thread_handle),
539 TYPE_LENGTH (value_type (thread_handle)),
544 * Thread iterator function.
546 * Calls a callback function once for each thread, so long as
547 * the callback function returns false. If the callback function
548 * returns true, the iteration will end and the current thread
549 * will be returned. This can be useful for implementing a
550 * search for a thread with arbitrary attributes, or for applying
551 * some operation to every thread.
553 * FIXME: some of the existing functionality, such as
554 * "Thread apply all", might be rewritten using this functionality.
558 iterate_over_threads (int (*callback) (struct thread_info *, void *),
561 struct thread_info *tp, *next;
563 for (tp = thread_list; tp; tp = next)
566 if ((*callback) (tp, data))
577 struct thread_info *tp;
579 for (tp = thread_list; tp; tp = tp->next)
585 /* Return the number of non-exited threads in the thread list. */
588 live_threads_count (void)
591 struct thread_info *tp;
593 ALL_NON_EXITED_THREADS (tp)
600 valid_global_thread_id (int global_id)
602 struct thread_info *tp;
604 for (tp = thread_list; tp; tp = tp->next)
605 if (tp->global_num == global_id)
612 ptid_to_global_thread_id (ptid_t ptid)
614 struct thread_info *tp;
616 for (tp = thread_list; tp; tp = tp->next)
617 if (tp->ptid == ptid)
618 return tp->global_num;
624 global_thread_id_to_ptid (int global_id)
626 struct thread_info *thread = find_thread_global_id (global_id);
631 return minus_one_ptid;
635 in_thread_list (ptid_t ptid)
637 struct thread_info *tp;
639 for (tp = thread_list; tp; tp = tp->next)
640 if (tp->ptid == ptid)
643 return 0; /* Never heard of 'im. */
646 /* Finds the first thread of the inferior given by PID. If PID is -1,
647 return the first thread in the list. */
650 first_thread_of_process (int pid)
652 struct thread_info *tp, *ret = NULL;
654 for (tp = thread_list; tp; tp = tp->next)
655 if (pid == -1 || ptid_get_pid (tp->ptid) == pid)
656 if (ret == NULL || tp->global_num < ret->global_num)
663 any_thread_of_process (int pid)
665 struct thread_info *tp;
667 gdb_assert (pid != 0);
669 /* Prefer the current thread. */
670 if (ptid_get_pid (inferior_ptid) == pid)
671 return inferior_thread ();
673 ALL_NON_EXITED_THREADS (tp)
674 if (ptid_get_pid (tp->ptid) == pid)
681 any_live_thread_of_process (int pid)
683 struct thread_info *curr_tp = NULL;
684 struct thread_info *tp;
685 struct thread_info *tp_executing = NULL;
687 gdb_assert (pid != 0);
689 /* Prefer the current thread if it's not executing. */
690 if (ptid_get_pid (inferior_ptid) == pid)
692 /* If the current thread is dead, forget it. If it's not
693 executing, use it. Otherwise, still choose it (below), but
694 only if no other non-executing thread is found. */
695 curr_tp = inferior_thread ();
696 if (curr_tp->state == THREAD_EXITED)
698 else if (!curr_tp->executing)
702 ALL_NON_EXITED_THREADS (tp)
703 if (ptid_get_pid (tp->ptid) == pid)
711 /* If both the current thread and all live threads are executing,
712 prefer the current thread. */
716 /* Otherwise, just return an executing thread, if any. */
720 /* Return true if TP is an active thread. */
722 thread_alive (struct thread_info *tp)
724 if (tp->state == THREAD_EXITED)
726 if (!target_thread_alive (tp->ptid))
731 /* See gdbthreads.h. */
736 struct thread_info *tp, *tmp;
738 ALL_THREADS_SAFE (tp, tmp)
740 if (!thread_alive (tp))
741 delete_thread (tp->ptid);
745 /* See gdbthreads.h. */
748 delete_exited_threads (void)
750 struct thread_info *tp, *tmp;
752 ALL_THREADS_SAFE (tp, tmp)
754 if (tp->state == THREAD_EXITED)
755 delete_thread (tp->ptid);
759 /* Disable storing stack temporaries for the thread whose id is
763 disable_thread_stack_temporaries (void *data)
765 ptid_t *pd = (ptid_t *) data;
766 struct thread_info *tp = find_thread_ptid (*pd);
770 tp->stack_temporaries_enabled = 0;
771 VEC_free (value_ptr, tp->stack_temporaries);
777 /* Enable storing stack temporaries for thread with id PTID and return a
778 cleanup which can disable and clear the stack temporaries. */
781 enable_thread_stack_temporaries (ptid_t ptid)
783 struct thread_info *tp = find_thread_ptid (ptid);
787 gdb_assert (tp != NULL);
789 tp->stack_temporaries_enabled = 1;
790 tp->stack_temporaries = NULL;
791 data = XNEW (ptid_t);
793 c = make_cleanup (disable_thread_stack_temporaries, data);
798 /* Return non-zero value if stack temporaies are enabled for the thread
802 thread_stack_temporaries_enabled_p (ptid_t ptid)
804 struct thread_info *tp = find_thread_ptid (ptid);
809 return tp->stack_temporaries_enabled;
812 /* Push V on to the stack temporaries of the thread with id PTID. */
815 push_thread_stack_temporary (ptid_t ptid, struct value *v)
817 struct thread_info *tp = find_thread_ptid (ptid);
819 gdb_assert (tp != NULL && tp->stack_temporaries_enabled);
820 VEC_safe_push (value_ptr, tp->stack_temporaries, v);
823 /* Return 1 if VAL is among the stack temporaries of the thread
824 with id PTID. Return 0 otherwise. */
827 value_in_thread_stack_temporaries (struct value *val, ptid_t ptid)
829 struct thread_info *tp = find_thread_ptid (ptid);
831 gdb_assert (tp != NULL && tp->stack_temporaries_enabled);
832 if (!VEC_empty (value_ptr, tp->stack_temporaries))
837 for (i = 0; VEC_iterate (value_ptr, tp->stack_temporaries, i, v); i++)
845 /* Return the last of the stack temporaries for thread with id PTID.
846 Return NULL if there are no stack temporaries for the thread. */
849 get_last_thread_stack_temporary (ptid_t ptid)
851 struct value *lastval = NULL;
852 struct thread_info *tp = find_thread_ptid (ptid);
854 gdb_assert (tp != NULL);
855 if (!VEC_empty (value_ptr, tp->stack_temporaries))
856 lastval = VEC_last (value_ptr, tp->stack_temporaries);
862 thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid)
864 struct inferior *inf;
865 struct thread_info *tp;
867 /* It can happen that what we knew as the target inferior id
868 changes. E.g, target remote may only discover the remote process
869 pid after adding the inferior to GDB's list. */
870 inf = find_inferior_ptid (old_ptid);
871 inf->pid = ptid_get_pid (new_ptid);
873 tp = find_thread_ptid (old_ptid);
876 observer_notify_thread_ptid_changed (old_ptid, new_ptid);
879 /* See gdbthread.h. */
882 set_resumed (ptid_t ptid, int resumed)
884 struct thread_info *tp;
885 int all = ptid == minus_one_ptid;
887 if (all || ptid_is_pid (ptid))
889 for (tp = thread_list; tp; tp = tp->next)
890 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
891 tp->resumed = resumed;
895 tp = find_thread_ptid (ptid);
896 gdb_assert (tp != NULL);
897 tp->resumed = resumed;
901 /* Helper for set_running, that marks one thread either running or
905 set_running_thread (struct thread_info *tp, int running)
909 if (running && tp->state == THREAD_STOPPED)
911 tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
915 /* If the thread is now marked stopped, remove it from
916 the step-over queue, so that we don't try to resume
917 it until the user wants it to. */
918 if (tp->step_over_next != NULL)
919 thread_step_over_chain_remove (tp);
926 set_running (ptid_t ptid, int running)
928 struct thread_info *tp;
929 int all = ptid == minus_one_ptid;
932 /* We try not to notify the observer if no thread has actually changed
933 the running state -- merely to reduce the number of messages to
934 frontend. Frontend is supposed to handle multiple *running just fine. */
935 if (all || ptid_is_pid (ptid))
937 for (tp = thread_list; tp; tp = tp->next)
938 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
940 if (tp->state == THREAD_EXITED)
943 if (set_running_thread (tp, running))
949 tp = find_thread_ptid (ptid);
950 gdb_assert (tp != NULL);
951 gdb_assert (tp->state != THREAD_EXITED);
952 if (set_running_thread (tp, running))
956 observer_notify_target_resumed (ptid);
960 is_thread_state (ptid_t ptid, enum thread_state state)
962 struct thread_info *tp;
964 tp = find_thread_ptid (ptid);
966 return tp->state == state;
970 is_stopped (ptid_t ptid)
972 return is_thread_state (ptid, THREAD_STOPPED);
976 is_exited (ptid_t ptid)
978 return is_thread_state (ptid, THREAD_EXITED);
982 is_running (ptid_t ptid)
984 return is_thread_state (ptid, THREAD_RUNNING);
988 is_executing (ptid_t ptid)
990 struct thread_info *tp;
992 tp = find_thread_ptid (ptid);
994 return tp->executing;
998 set_executing (ptid_t ptid, int executing)
1000 struct thread_info *tp;
1001 int all = ptid == minus_one_ptid;
1003 if (all || ptid_is_pid (ptid))
1005 for (tp = thread_list; tp; tp = tp->next)
1006 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
1007 tp->executing = executing;
1011 tp = find_thread_ptid (ptid);
1013 tp->executing = executing;
1016 /* It only takes one running thread to spawn more threads.*/
1018 threads_executing = 1;
1019 /* Only clear the flag if the caller is telling us everything is
1021 else if (minus_one_ptid == ptid)
1022 threads_executing = 0;
1025 /* See gdbthread.h. */
1028 threads_are_executing (void)
1030 return threads_executing;
1034 set_stop_requested (ptid_t ptid, int stop)
1036 struct thread_info *tp;
1037 int all = ptid == minus_one_ptid;
1039 if (all || ptid_is_pid (ptid))
1041 for (tp = thread_list; tp; tp = tp->next)
1042 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
1043 tp->stop_requested = stop;
1047 tp = find_thread_ptid (ptid);
1049 tp->stop_requested = stop;
1052 /* Call the stop requested observer so other components of GDB can
1053 react to this request. */
1055 observer_notify_thread_stop_requested (ptid);
1059 finish_thread_state (ptid_t ptid)
1061 struct thread_info *tp;
1063 int any_started = 0;
1065 all = ptid == minus_one_ptid;
1067 if (all || ptid_is_pid (ptid))
1069 for (tp = thread_list; tp; tp = tp->next)
1071 if (tp->state == THREAD_EXITED)
1073 if (all || ptid_get_pid (ptid) == ptid_get_pid (tp->ptid))
1075 if (set_running_thread (tp, tp->executing))
1082 tp = find_thread_ptid (ptid);
1084 if (tp->state != THREAD_EXITED)
1086 if (set_running_thread (tp, tp->executing))
1092 observer_notify_target_resumed (ptid);
1096 finish_thread_state_cleanup (void *arg)
1098 ptid_t *ptid_p = (ptid_t *) arg;
1102 finish_thread_state (*ptid_p);
1105 /* See gdbthread.h. */
1108 validate_registers_access (void)
1110 /* No selected thread, no registers. */
1111 if (inferior_ptid == null_ptid)
1112 error (_("No thread selected."));
1114 /* Don't try to read from a dead thread. */
1115 if (is_exited (inferior_ptid))
1116 error (_("The current thread has terminated"));
1118 /* ... or from a spinning thread. FIXME: This isn't actually fully
1119 correct. It'll allow an user-requested access (e.g., "print $pc"
1120 at the prompt) when a thread is not executing for some internal
1121 reason, but is marked running from the user's perspective. E.g.,
1122 the thread is waiting for its turn in the step-over queue. */
1123 if (is_executing (inferior_ptid))
1124 error (_("Selected thread is running."));
1127 /* See gdbthread.h. */
1130 can_access_registers_ptid (ptid_t ptid)
1132 /* No thread, no registers. */
1133 if (ptid == null_ptid)
1136 /* Don't try to read from a dead thread. */
1137 if (is_exited (ptid))
1140 /* ... or from a spinning thread. FIXME: see validate_registers_access. */
1141 if (is_executing (ptid))
1148 pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread)
1150 return (pc >= thread->control.step_range_start
1151 && pc < thread->control.step_range_end);
1154 /* Helper for print_thread_info. Returns true if THR should be
1155 printed. If REQUESTED_THREADS, a list of GDB ids/ranges, is not
1156 NULL, only print THR if its ID is included in the list. GLOBAL_IDS
1157 is true if REQUESTED_THREADS is list of global IDs, false if a list
1158 of per-inferior thread ids. If PID is not -1, only print THR if it
1159 is a thread from the process PID. Otherwise, threads from all
1160 attached PIDs are printed. If both REQUESTED_THREADS is not NULL
1161 and PID is not -1, then the thread is printed if it belongs to the
1162 specified process. Otherwise, an error is raised. */
1165 should_print_thread (const char *requested_threads, int default_inf_num,
1166 int global_ids, int pid, struct thread_info *thr)
1168 if (requested_threads != NULL && *requested_threads != '\0')
1173 in_list = number_is_in_list (requested_threads, thr->global_num);
1175 in_list = tid_is_in_list (requested_threads, default_inf_num,
1176 thr->inf->num, thr->per_inf_num);
1181 if (pid != -1 && ptid_get_pid (thr->ptid) != pid)
1183 if (requested_threads != NULL && *requested_threads != '\0')
1184 error (_("Requested thread not found in requested process"));
1188 if (thr->state == THREAD_EXITED)
1194 /* Like print_thread_info, but in addition, GLOBAL_IDS indicates
1195 whether REQUESTED_THREADS is a list of global or per-inferior
1199 print_thread_info_1 (struct ui_out *uiout, const char *requested_threads,
1200 int global_ids, int pid,
1201 int show_global_ids)
1203 struct thread_info *tp;
1204 ptid_t current_ptid;
1205 const char *extra_info, *name, *target_id;
1206 struct inferior *inf;
1207 int default_inf_num = current_inferior ()->num;
1209 update_thread_list ();
1210 current_ptid = inferior_ptid;
1213 /* For backward compatibility, we make a list for MI. A table is
1214 preferable for the CLI, though, because it shows table
1216 gdb::optional<ui_out_emit_list> list_emitter;
1217 gdb::optional<ui_out_emit_table> table_emitter;
1219 if (uiout->is_mi_like_p ())
1220 list_emitter.emplace (uiout, "threads");
1225 for (tp = thread_list; tp; tp = tp->next)
1227 if (!should_print_thread (requested_threads, default_inf_num,
1228 global_ids, pid, tp))
1236 if (requested_threads == NULL || *requested_threads == '\0')
1237 uiout->message (_("No threads.\n"));
1239 uiout->message (_("No threads match '%s'.\n"),
1244 table_emitter.emplace (uiout, show_global_ids ? 5 : 4,
1245 n_threads, "threads");
1247 uiout->table_header (1, ui_left, "current", "");
1248 uiout->table_header (4, ui_left, "id-in-tg", "Id");
1249 if (show_global_ids)
1250 uiout->table_header (4, ui_left, "id", "GId");
1251 uiout->table_header (17, ui_left, "target-id", "Target Id");
1252 uiout->table_header (1, ui_left, "frame", "Frame");
1253 uiout->table_body ();
1256 /* We'll be switching threads temporarily. */
1257 scoped_restore_current_thread restore_thread;
1259 ALL_THREADS_BY_INFERIOR (inf, tp)
1263 if (!should_print_thread (requested_threads, default_inf_num,
1264 global_ids, pid, tp))
1267 ui_out_emit_tuple tuple_emitter (uiout, NULL);
1269 if (!uiout->is_mi_like_p ())
1271 if (tp->ptid == current_ptid)
1272 uiout->field_string ("current", "*");
1274 uiout->field_skip ("current");
1276 uiout->field_string ("id-in-tg", print_thread_id (tp));
1279 if (show_global_ids || uiout->is_mi_like_p ())
1280 uiout->field_int ("id", tp->global_num);
1282 /* For the CLI, we stuff everything into the target-id field.
1283 This is a gross hack to make the output come out looking
1284 correct. The underlying problem here is that ui-out has no
1285 way to specify that a field's space allocation should be
1286 shared by several fields. For MI, we do the right thing
1289 target_id = target_pid_to_str (tp->ptid);
1290 extra_info = target_extra_thread_info (tp);
1291 name = tp->name ? tp->name : target_thread_name (tp);
1293 if (uiout->is_mi_like_p ())
1295 uiout->field_string ("target-id", target_id);
1297 uiout->field_string ("details", extra_info);
1299 uiout->field_string ("name", name);
1303 std::string contents;
1305 if (extra_info && name)
1306 contents = string_printf ("%s \"%s\" (%s)", target_id,
1308 else if (extra_info)
1309 contents = string_printf ("%s (%s)", target_id, extra_info);
1311 contents = string_printf ("%s \"%s\"", target_id, name);
1313 contents = target_id;
1315 uiout->field_string ("target-id", contents.c_str ());
1318 if (tp->state == THREAD_RUNNING)
1319 uiout->text ("(running)\n");
1322 /* The switch below puts us at the top of the stack (leaf
1324 switch_to_thread (tp->ptid);
1325 print_stack_frame (get_selected_frame (NULL),
1326 /* For MI output, print frame level. */
1327 uiout->is_mi_like_p (),
1331 if (uiout->is_mi_like_p ())
1333 const char *state = "stopped";
1335 if (tp->state == THREAD_RUNNING)
1337 uiout->field_string ("state", state);
1340 core = target_core_of_thread (tp->ptid);
1341 if (uiout->is_mi_like_p () && core != -1)
1342 uiout->field_int ("core", core);
1345 /* This end scope restores the current thread and the frame
1346 selected before the "info threads" command, and it finishes the
1347 ui-out list or table. */
1350 if (pid == -1 && requested_threads == NULL)
1352 if (uiout->is_mi_like_p ()
1353 && inferior_ptid != null_ptid)
1355 int num = ptid_to_global_thread_id (inferior_ptid);
1357 gdb_assert (num != 0);
1358 uiout->field_int ("current-thread-id", num);
1361 if (inferior_ptid != null_ptid && is_exited (inferior_ptid))
1362 uiout->message ("\n\
1363 The current thread <Thread ID %s> has terminated. See `help thread'.\n",
1364 print_thread_id (inferior_thread ()));
1365 else if (thread_list != NULL && inferior_ptid == null_ptid)
1366 uiout->message ("\n\
1367 No selected thread. See `help thread'.\n");
1371 /* See gdbthread.h. */
1374 print_thread_info (struct ui_out *uiout, char *requested_threads, int pid)
1376 print_thread_info_1 (uiout, requested_threads, 1, pid, 0);
1379 /* Implementation of the "info threads" command.
1381 Note: this has the drawback that it _really_ switches
1382 threads, which frees the frame cache. A no-side
1383 effects info-threads command would be nicer. */
1386 info_threads_command (const char *arg, int from_tty)
1388 int show_global_ids = 0;
1391 && check_for_argument (&arg, "-gid", sizeof ("-gid") - 1))
1393 arg = skip_spaces (arg);
1394 show_global_ids = 1;
1397 print_thread_info_1 (current_uiout, arg, 0, -1, show_global_ids);
1400 /* See gdbthread.h. */
1403 switch_to_thread_no_regs (struct thread_info *thread)
1405 struct inferior *inf = thread->inf;
1407 set_current_program_space (inf->pspace);
1408 set_current_inferior (inf);
1410 inferior_ptid = thread->ptid;
1411 stop_pc = ~(CORE_ADDR) 0;
1414 /* Switch to no thread selected. */
1417 switch_to_no_thread ()
1419 if (inferior_ptid == null_ptid)
1422 inferior_ptid = null_ptid;
1423 reinit_frame_cache ();
1424 stop_pc = ~(CORE_ADDR) 0;
1427 /* Switch from one thread to another. */
1430 switch_to_thread (thread_info *thr)
1432 gdb_assert (thr != NULL);
1434 if (inferior_ptid == thr->ptid)
1437 switch_to_thread_no_regs (thr);
1439 reinit_frame_cache ();
1441 /* We don't check for is_stopped, because we're called at times
1442 while in the TARGET_RUNNING state, e.g., while handling an
1444 if (thr->state != THREAD_EXITED
1446 stop_pc = regcache_read_pc (get_thread_regcache (thr->ptid));
1449 /* See gdbthread.h. */
1452 switch_to_thread (ptid_t ptid)
1454 if (ptid == null_ptid)
1455 switch_to_no_thread ();
1457 switch_to_thread (find_thread_ptid (ptid));
1461 restore_selected_frame (struct frame_id a_frame_id, int frame_level)
1463 struct frame_info *frame = NULL;
1466 /* This means there was no selected frame. */
1467 if (frame_level == -1)
1469 select_frame (NULL);
1473 gdb_assert (frame_level >= 0);
1475 /* Restore by level first, check if the frame id is the same as
1476 expected. If that fails, try restoring by frame id. If that
1477 fails, nothing to do, just warn the user. */
1479 count = frame_level;
1480 frame = find_relative_frame (get_current_frame (), &count);
1483 /* The frame ids must match - either both valid or both outer_frame_id.
1484 The latter case is not failsafe, but since it's highly unlikely
1485 the search by level finds the wrong frame, it's 99.9(9)% of
1486 the time (for all practical purposes) safe. */
1487 && frame_id_eq (get_frame_id (frame), a_frame_id))
1489 /* Cool, all is fine. */
1490 select_frame (frame);
1494 frame = frame_find_by_id (a_frame_id);
1497 /* Cool, refound it. */
1498 select_frame (frame);
1502 /* Nothing else to do, the frame layout really changed. Select the
1503 innermost stack frame. */
1504 select_frame (get_current_frame ());
1506 /* Warn the user. */
1507 if (frame_level > 0 && !current_uiout->is_mi_like_p ())
1509 warning (_("Couldn't restore frame #%d in "
1510 "current thread. Bottom (innermost) frame selected:"),
1512 /* For MI, we should probably have a notification about
1513 current frame change. But this error is not very
1514 likely, so don't bother for now. */
1515 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1519 scoped_restore_current_thread::~scoped_restore_current_thread ()
1521 /* If an entry of thread_info was previously selected, it won't be
1522 deleted because we've increased its refcount. The thread represented
1523 by this thread_info entry may have already exited (due to normal exit,
1524 detach, etc), so the thread_info.state is THREAD_EXITED. */
1525 if (m_thread != NULL
1526 /* If the previously selected thread belonged to a process that has
1527 in the mean time exited (or killed, detached, etc.), then don't revert
1528 back to it, but instead simply drop back to no thread selected. */
1530 switch_to_thread (m_thread);
1533 switch_to_no_thread ();
1534 set_current_inferior (m_inf);
1537 /* The running state of the originally selected thread may have
1538 changed, so we have to recheck it here. */
1539 if (inferior_ptid != null_ptid
1541 && is_stopped (inferior_ptid)
1542 && target_has_registers
1544 && target_has_memory)
1545 restore_selected_frame (m_selected_frame_id, m_selected_frame_level);
1547 if (m_thread != NULL)
1548 m_thread->decref ();
1552 scoped_restore_current_thread::scoped_restore_current_thread ()
1555 m_inf = current_inferior ();
1557 if (inferior_ptid != null_ptid)
1559 thread_info *tp = find_thread_ptid (inferior_ptid);
1560 struct frame_info *frame;
1562 gdb_assert (tp != NULL);
1564 m_was_stopped = tp->state == THREAD_STOPPED;
1566 && target_has_registers
1568 && target_has_memory)
1570 /* When processing internal events, there might not be a
1571 selected frame. If we naively call get_selected_frame
1572 here, then we can end up reading debuginfo for the
1573 current frame, but we don't generally need the debuginfo
1575 frame = get_selected_frame_if_set ();
1580 m_selected_frame_id = get_frame_id (frame);
1581 m_selected_frame_level = frame_relative_level (frame);
1590 /* See gdbthread.h. */
1593 show_thread_that_caused_stop (void)
1595 return highest_thread_num > 1;
1598 /* See gdbthread.h. */
1601 show_inferior_qualified_tids (void)
1603 return (inferior_list->next != NULL || inferior_list->num != 1);
1606 /* See gdbthread.h. */
1609 print_thread_id (struct thread_info *thr)
1611 char *s = get_print_cell ();
1613 if (show_inferior_qualified_tids ())
1614 xsnprintf (s, PRINT_CELL_SIZE, "%d.%d", thr->inf->num, thr->per_inf_num);
1616 xsnprintf (s, PRINT_CELL_SIZE, "%d", thr->per_inf_num);
1620 /* If true, tp_array_compar should sort in ascending order, otherwise
1621 in descending order. */
1623 static bool tp_array_compar_ascending;
1625 /* Sort an array for struct thread_info pointers by thread ID (first
1626 by inferior number, and then by per-inferior thread number). The
1627 order is determined by TP_ARRAY_COMPAR_ASCENDING. */
1630 tp_array_compar (const thread_info *a, const thread_info *b)
1632 if (a->inf->num != b->inf->num)
1634 if (tp_array_compar_ascending)
1635 return a->inf->num < b->inf->num;
1637 return a->inf->num > b->inf->num;
1640 if (tp_array_compar_ascending)
1641 return (a->per_inf_num < b->per_inf_num);
1643 return (a->per_inf_num > b->per_inf_num);
1646 /* Apply a GDB command to a list of threads. List syntax is a whitespace
1647 seperated list of numbers, or ranges, or the keyword `all'. Ranges consist
1648 of two numbers seperated by a hyphen. Examples:
1650 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
1651 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
1652 thread apply all p x/i $pc Apply x/i $pc cmd to all threads. */
1655 thread_apply_all_command (char *cmd, int from_tty)
1657 tp_array_compar_ascending = false;
1659 && check_for_argument (&cmd, "-ascending", strlen ("-ascending")))
1661 cmd = skip_spaces (cmd);
1662 tp_array_compar_ascending = true;
1665 if (cmd == NULL || *cmd == '\000')
1666 error (_("Please specify a command following the thread ID list"));
1668 update_thread_list ();
1670 /* Save a copy of the command in case it is clobbered by
1672 std::string saved_cmd = cmd;
1674 int tc = live_threads_count ();
1677 /* Save a copy of the thread list and increment each thread's
1678 refcount while executing the command in the context of each
1679 thread, in case the command is one that wipes threads. E.g.,
1680 detach, kill, disconnect, etc., or even normally continuing
1681 over an inferior or thread exit. */
1682 std::vector<thread_info *> thr_list_cpy;
1683 thr_list_cpy.reserve (tc);
1688 ALL_NON_EXITED_THREADS (tp)
1690 thr_list_cpy.push_back (tp);
1693 gdb_assert (thr_list_cpy.size () == tc);
1696 /* Increment the refcounts, and restore them back on scope
1698 scoped_inc_dec_ref inc_dec_ref (thr_list_cpy);
1700 std::sort (thr_list_cpy.begin (), thr_list_cpy.end (), tp_array_compar);
1702 scoped_restore_current_thread restore_thread;
1704 for (thread_info *thr : thr_list_cpy)
1705 if (thread_alive (thr))
1707 switch_to_thread (thr->ptid);
1708 printf_filtered (_("\nThread %s (%s):\n"),
1709 print_thread_id (thr),
1710 target_pid_to_str (inferior_ptid));
1711 execute_command (cmd, from_tty);
1713 /* Restore exact command used previously. */
1714 strcpy (cmd, saved_cmd.c_str ());
1719 /* Implementation of the "thread apply" command. */
1722 thread_apply_command (const char *tidlist, int from_tty)
1725 tid_range_parser parser;
1727 if (tidlist == NULL || *tidlist == '\000')
1728 error (_("Please specify a thread ID list"));
1730 parser.init (tidlist, current_inferior ()->num);
1731 while (!parser.finished ())
1733 int inf_num, thr_start, thr_end;
1735 if (!parser.get_tid_range (&inf_num, &thr_start, &thr_end))
1737 cmd = (char *) parser.cur_tok ();
1743 error (_("Please specify a command following the thread ID list"));
1745 if (tidlist == cmd || !isalpha (cmd[0]))
1746 invalid_thread_id_error (cmd);
1748 /* Save a copy of the command in case it is clobbered by
1750 std::string saved_cmd = cmd;
1752 scoped_restore_current_thread restore_thread;
1754 parser.init (tidlist, current_inferior ()->num);
1755 while (!parser.finished () && parser.cur_tok () < cmd)
1757 struct thread_info *tp = NULL;
1758 struct inferior *inf;
1759 int inf_num, thr_num;
1761 parser.get_tid (&inf_num, &thr_num);
1762 inf = find_inferior_id (inf_num);
1764 tp = find_thread_id (inf, thr_num);
1766 if (parser.in_star_range ())
1770 warning (_("Unknown inferior %d"), inf_num);
1771 parser.skip_range ();
1775 /* No use looking for threads past the highest thread number
1776 the inferior ever had. */
1777 if (thr_num >= inf->highest_thread_num)
1778 parser.skip_range ();
1780 /* Be quiet about unknown threads numbers. */
1787 if (show_inferior_qualified_tids () || parser.tid_is_qualified ())
1788 warning (_("Unknown thread %d.%d"), inf_num, thr_num);
1790 warning (_("Unknown thread %d"), thr_num);
1794 if (!thread_alive (tp))
1796 warning (_("Thread %s has terminated."), print_thread_id (tp));
1800 switch_to_thread (tp->ptid);
1802 printf_filtered (_("\nThread %s (%s):\n"), print_thread_id (tp),
1803 target_pid_to_str (inferior_ptid));
1804 execute_command (cmd, from_tty);
1806 /* Restore exact command used previously. */
1807 strcpy (cmd, saved_cmd.c_str ());
1811 /* Switch to the specified thread. Will dispatch off to thread_apply_command
1812 if prefix of arg is `apply'. */
1815 thread_command (const char *tidstr, int from_tty)
1819 if (inferior_ptid == null_ptid)
1820 error (_("No thread selected"));
1822 if (target_has_stack)
1824 struct thread_info *tp = inferior_thread ();
1826 if (is_exited (inferior_ptid))
1827 printf_filtered (_("[Current thread is %s (%s) (exited)]\n"),
1828 print_thread_id (tp),
1829 target_pid_to_str (inferior_ptid));
1831 printf_filtered (_("[Current thread is %s (%s)]\n"),
1832 print_thread_id (tp),
1833 target_pid_to_str (inferior_ptid));
1836 error (_("No stack."));
1840 ptid_t previous_ptid = inferior_ptid;
1842 thread_select (tidstr, parse_thread_id (tidstr, NULL));
1844 /* Print if the thread has not changed, otherwise an event will
1846 if (inferior_ptid == previous_ptid)
1848 print_selected_thread_frame (current_uiout,
1849 USER_SELECTED_THREAD
1850 | USER_SELECTED_FRAME);
1854 observer_notify_user_selected_context_changed (USER_SELECTED_THREAD
1855 | USER_SELECTED_FRAME);
1860 /* Implementation of `thread name'. */
1863 thread_name_command (const char *arg, int from_tty)
1865 struct thread_info *info;
1867 if (inferior_ptid == null_ptid)
1868 error (_("No thread selected"));
1870 arg = skip_spaces (arg);
1872 info = inferior_thread ();
1874 info->name = arg ? xstrdup (arg) : NULL;
1877 /* Find thread ids with a name, target pid, or extra info matching ARG. */
1880 thread_find_command (const char *arg, int from_tty)
1882 struct thread_info *tp;
1884 unsigned long match = 0;
1886 if (arg == NULL || *arg == '\0')
1887 error (_("Command requires an argument."));
1889 tmp = re_comp (arg);
1891 error (_("Invalid regexp (%s): %s"), tmp, arg);
1893 update_thread_list ();
1894 for (tp = thread_list; tp; tp = tp->next)
1896 if (tp->name != NULL && re_exec (tp->name))
1898 printf_filtered (_("Thread %s has name '%s'\n"),
1899 print_thread_id (tp), tp->name);
1903 tmp = target_thread_name (tp);
1904 if (tmp != NULL && re_exec (tmp))
1906 printf_filtered (_("Thread %s has target name '%s'\n"),
1907 print_thread_id (tp), tmp);
1911 tmp = target_pid_to_str (tp->ptid);
1912 if (tmp != NULL && re_exec (tmp))
1914 printf_filtered (_("Thread %s has target id '%s'\n"),
1915 print_thread_id (tp), tmp);
1919 tmp = target_extra_thread_info (tp);
1920 if (tmp != NULL && re_exec (tmp))
1922 printf_filtered (_("Thread %s has extra info '%s'\n"),
1923 print_thread_id (tp), tmp);
1928 printf_filtered (_("No threads match '%s'\n"), arg);
1931 /* Print notices when new threads are attached and detached. */
1932 int print_thread_events = 1;
1934 show_print_thread_events (struct ui_file *file, int from_tty,
1935 struct cmd_list_element *c, const char *value)
1937 fprintf_filtered (file,
1938 _("Printing of thread events is %s.\n"),
1942 /* See gdbthread.h. */
1945 thread_select (const char *tidstr, thread_info *tp)
1947 if (!thread_alive (tp))
1948 error (_("Thread ID %s has terminated."), tidstr);
1950 switch_to_thread (tp->ptid);
1952 annotate_thread_changed ();
1954 /* Since the current thread may have changed, see if there is any
1955 exited thread we can now delete. */
1959 /* Print thread and frame switch command response. */
1962 print_selected_thread_frame (struct ui_out *uiout,
1963 user_selected_what selection)
1965 struct thread_info *tp = inferior_thread ();
1966 struct inferior *inf = current_inferior ();
1968 if (selection & USER_SELECTED_THREAD)
1970 if (uiout->is_mi_like_p ())
1972 uiout->field_int ("new-thread-id",
1973 inferior_thread ()->global_num);
1977 uiout->text ("[Switching to thread ");
1978 uiout->field_string ("new-thread-id", print_thread_id (tp));
1980 uiout->text (target_pid_to_str (inferior_ptid));
1985 if (tp->state == THREAD_RUNNING)
1987 if (selection & USER_SELECTED_THREAD)
1988 uiout->text ("(running)\n");
1990 else if (selection & USER_SELECTED_FRAME)
1992 if (selection & USER_SELECTED_THREAD)
1995 if (has_stack_frames ())
1996 print_stack_frame_to_uiout (uiout, get_selected_frame (NULL),
2001 /* Update the 'threads_executing' global based on the threads we know
2005 update_threads_executing (void)
2007 struct thread_info *tp;
2009 threads_executing = 0;
2010 ALL_NON_EXITED_THREADS (tp)
2014 threads_executing = 1;
2021 update_thread_list (void)
2023 target_update_thread_list ();
2024 update_threads_executing ();
2027 /* Return a new value for the selected thread's id. Return a value of
2028 0 if no thread is selected. If GLOBAL is true, return the thread's
2029 global number. Otherwise return the per-inferior number. */
2031 static struct value *
2032 thread_num_make_value_helper (struct gdbarch *gdbarch, int global)
2034 struct thread_info *tp = find_thread_ptid (inferior_ptid);
2040 int_val = tp->global_num;
2042 int_val = tp->per_inf_num;
2044 return value_from_longest (builtin_type (gdbarch)->builtin_int, int_val);
2047 /* Return a new value for the selected thread's per-inferior thread
2048 number. Return a value of 0 if no thread is selected, or no
2051 static struct value *
2052 thread_id_per_inf_num_make_value (struct gdbarch *gdbarch,
2053 struct internalvar *var,
2056 return thread_num_make_value_helper (gdbarch, 0);
2059 /* Return a new value for the selected thread's global id. Return a
2060 value of 0 if no thread is selected, or no threads exist. */
2062 static struct value *
2063 global_thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
2066 return thread_num_make_value_helper (gdbarch, 1);
2069 /* Commands with a prefix of `thread'. */
2070 struct cmd_list_element *thread_cmd_list = NULL;
2072 /* Implementation of `thread' variable. */
2074 static const struct internalvar_funcs thread_funcs =
2076 thread_id_per_inf_num_make_value,
2081 /* Implementation of `gthread' variable. */
2083 static const struct internalvar_funcs gthread_funcs =
2085 global_thread_id_make_value,
2091 _initialize_thread (void)
2093 static struct cmd_list_element *thread_apply_list = NULL;
2095 add_info ("threads", info_threads_command,
2096 _("Display currently known threads.\n\
2097 Usage: info threads [-gid] [ID]...\n\
2098 -gid: Show global thread IDs.\n\
2099 If ID is given, it is a space-separated list of IDs of threads to display.\n\
2100 Otherwise, all threads are displayed."));
2102 add_prefix_cmd ("thread", class_run, thread_command, _("\
2103 Use this command to switch between threads.\n\
2104 The new thread ID must be currently known."),
2105 &thread_cmd_list, "thread ", 1, &cmdlist);
2107 add_prefix_cmd ("apply", class_run, thread_apply_command,
2108 _("Apply a command to a list of threads."),
2109 &thread_apply_list, "thread apply ", 1, &thread_cmd_list);
2111 add_cmd ("all", class_run, thread_apply_all_command,
2113 Apply a command to all threads.\n\
2115 Usage: thread apply all [-ascending] <command>\n\
2116 -ascending: Call <command> for all threads in ascending order.\n\
2117 The default is descending order.\
2119 &thread_apply_list);
2121 add_cmd ("name", class_run, thread_name_command,
2122 _("Set the current thread's name.\n\
2123 Usage: thread name [NAME]\n\
2124 If NAME is not given, then any existing name is removed."), &thread_cmd_list);
2126 add_cmd ("find", class_run, thread_find_command, _("\
2127 Find threads that match a regular expression.\n\
2128 Usage: thread find REGEXP\n\
2129 Will display thread ids whose name, target ID, or extra info matches REGEXP."),
2132 add_com_alias ("t", "thread", class_run, 1);
2134 add_setshow_boolean_cmd ("thread-events", no_class,
2135 &print_thread_events, _("\
2136 Set printing of thread events (such as thread start and exit)."), _("\
2137 Show printing of thread events (such as thread start and exit)."), NULL,
2139 show_print_thread_events,
2140 &setprintlist, &showprintlist);
2142 create_internalvar_type_lazy ("_thread", &thread_funcs, NULL);
2143 create_internalvar_type_lazy ("_gthread", >hread_funcs, NULL);