1 /* Multi-process/thread control for GDB, the GNU debugger.
3 Copyright (C) 1986-2015 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"
37 #include <sys/types.h>
42 #include "cli/cli-decode.h"
43 #include "gdb_regex.h"
44 #include "cli/cli-utils.h"
45 #include "continuations.h"
47 /* Definition of struct thread_info exported to gdbthread.h. */
49 /* Prototypes for exported functions. */
51 void _initialize_thread (void);
53 /* Prototypes for local functions. */
55 struct thread_info
*thread_list
= NULL
;
56 static int highest_thread_num
;
58 /* True if any thread is, or may be executing. We need to track this
59 separately because until we fully sync the thread list, we won't
60 know whether the target is fully stopped, even if we see stop
61 events for all known threads, because any of those threads may have
62 spawned new threads we haven't heard of yet. */
63 static int threads_executing
;
65 static void thread_apply_all_command (char *, int);
66 static int thread_alive (struct thread_info
*);
67 static void info_threads_command (char *, int);
68 static void thread_apply_command (char *, int);
69 static void restore_current_thread (ptid_t
);
71 /* Data to cleanup thread array. */
73 struct thread_array_cleanup
75 /* Array of thread pointers used to set
77 struct thread_info
**tp_array
;
79 /* Thread count in the array. */
85 inferior_thread (void)
87 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
92 /* Delete the breakpoint pointed at by BP_P, if there's one. */
95 delete_thread_breakpoint (struct breakpoint
**bp_p
)
99 delete_breakpoint (*bp_p
);
105 delete_step_resume_breakpoint (struct thread_info
*tp
)
108 delete_thread_breakpoint (&tp
->control
.step_resume_breakpoint
);
112 delete_exception_resume_breakpoint (struct thread_info
*tp
)
115 delete_thread_breakpoint (&tp
->control
.exception_resume_breakpoint
);
118 /* See gdbthread.h. */
121 delete_single_step_breakpoints (struct thread_info
*tp
)
124 delete_thread_breakpoint (&tp
->control
.single_step_breakpoints
);
127 /* Delete the breakpoint pointed at by BP_P at the next stop, if
131 delete_at_next_stop (struct breakpoint
**bp
)
135 (*bp
)->disposition
= disp_del_at_next_stop
;
140 /* See gdbthread.h. */
143 thread_has_single_step_breakpoints_set (struct thread_info
*tp
)
145 return tp
->control
.single_step_breakpoints
!= NULL
;
148 /* See gdbthread.h. */
151 thread_has_single_step_breakpoint_here (struct thread_info
*tp
,
152 struct address_space
*aspace
,
155 struct breakpoint
*ss_bps
= tp
->control
.single_step_breakpoints
;
157 return (ss_bps
!= NULL
158 && breakpoint_has_location_inserted_here (ss_bps
, aspace
, addr
));
162 clear_thread_inferior_resources (struct thread_info
*tp
)
164 /* NOTE: this will take care of any left-over step_resume breakpoints,
165 but not any user-specified thread-specific breakpoints. We can not
166 delete the breakpoint straight-off, because the inferior might not
167 be stopped at the moment. */
168 delete_at_next_stop (&tp
->control
.step_resume_breakpoint
);
169 delete_at_next_stop (&tp
->control
.exception_resume_breakpoint
);
170 delete_at_next_stop (&tp
->control
.single_step_breakpoints
);
172 delete_longjmp_breakpoint_at_next_stop (tp
->num
);
174 bpstat_clear (&tp
->control
.stop_bpstat
);
176 btrace_teardown (tp
);
178 do_all_intermediate_continuations_thread (tp
, 1);
179 do_all_continuations_thread (tp
, 1);
183 free_thread (struct thread_info
*tp
)
187 if (tp
->private_dtor
)
188 tp
->private_dtor (tp
->priv
);
198 init_thread_list (void)
200 struct thread_info
*tp
, *tpnext
;
202 highest_thread_num
= 0;
207 for (tp
= thread_list
; tp
; tp
= tpnext
)
214 threads_executing
= 0;
217 /* Allocate a new thread with target id PTID and add it to the thread
220 static struct thread_info
*
221 new_thread (ptid_t ptid
)
223 struct thread_info
*tp
= XCNEW (struct thread_info
);
226 tp
->num
= ++highest_thread_num
;
227 tp
->next
= thread_list
;
230 /* Nothing to follow yet. */
231 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
232 tp
->state
= THREAD_STOPPED
;
233 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
239 add_thread_silent (ptid_t ptid
)
241 struct thread_info
*tp
;
243 tp
= find_thread_ptid (ptid
);
245 /* Found an old thread with the same id. It has to be dead,
246 otherwise we wouldn't be adding a new thread with the same id.
247 The OS is reusing this id --- delete it, and recreate a new
250 /* In addition to deleting the thread, if this is the current
251 thread, then we need to take care that delete_thread doesn't
252 really delete the thread if it is inferior_ptid. Create a
253 new template thread in the list with an invalid ptid, switch
254 to it, delete the original thread, reset the new thread's
255 ptid, and switch to it. */
257 if (ptid_equal (inferior_ptid
, ptid
))
259 tp
= new_thread (null_ptid
);
261 /* Make switch_to_thread not read from the thread. */
262 tp
->state
= THREAD_EXITED
;
263 switch_to_thread (null_ptid
);
265 /* Now we can delete it. */
266 delete_thread (ptid
);
268 /* Now reset its ptid, and reswitch inferior_ptid to it. */
270 tp
->state
= THREAD_STOPPED
;
271 switch_to_thread (ptid
);
273 observer_notify_new_thread (tp
);
279 /* Just go ahead and delete it. */
280 delete_thread (ptid
);
283 tp
= new_thread (ptid
);
284 observer_notify_new_thread (tp
);
290 add_thread_with_info (ptid_t ptid
, struct private_thread_info
*priv
)
292 struct thread_info
*result
= add_thread_silent (ptid
);
296 if (print_thread_events
)
297 printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid
));
299 annotate_new_thread ();
304 add_thread (ptid_t ptid
)
306 return add_thread_with_info (ptid
, NULL
);
309 /* Add TP to the end of the step-over chain LIST_P. */
312 step_over_chain_enqueue (struct thread_info
**list_p
, struct thread_info
*tp
)
314 gdb_assert (tp
->step_over_next
== NULL
);
315 gdb_assert (tp
->step_over_prev
== NULL
);
320 tp
->step_over_prev
= tp
->step_over_next
= tp
;
324 struct thread_info
*head
= *list_p
;
325 struct thread_info
*tail
= head
->step_over_prev
;
327 tp
->step_over_prev
= tail
;
328 tp
->step_over_next
= head
;
329 head
->step_over_prev
= tp
;
330 tail
->step_over_next
= tp
;
334 /* Remove TP from step-over chain LIST_P. */
337 step_over_chain_remove (struct thread_info
**list_p
, struct thread_info
*tp
)
339 gdb_assert (tp
->step_over_next
!= NULL
);
340 gdb_assert (tp
->step_over_prev
!= NULL
);
344 if (tp
== tp
->step_over_next
)
347 *list_p
= tp
->step_over_next
;
350 tp
->step_over_prev
->step_over_next
= tp
->step_over_next
;
351 tp
->step_over_next
->step_over_prev
= tp
->step_over_prev
;
352 tp
->step_over_prev
= tp
->step_over_next
= NULL
;
355 /* See gdbthread.h. */
358 thread_step_over_chain_next (struct thread_info
*tp
)
360 struct thread_info
*next
= tp
->step_over_next
;
362 return (next
== step_over_queue_head
? NULL
: next
);
365 /* See gdbthread.h. */
368 thread_is_in_step_over_chain (struct thread_info
*tp
)
370 return (tp
->step_over_next
!= NULL
);
373 /* See gdbthread.h. */
376 thread_step_over_chain_enqueue (struct thread_info
*tp
)
378 step_over_chain_enqueue (&step_over_queue_head
, tp
);
381 /* See gdbthread.h. */
384 thread_step_over_chain_remove (struct thread_info
*tp
)
386 step_over_chain_remove (&step_over_queue_head
, tp
);
389 /* Delete thread PTID. If SILENT, don't notify the observer of this
392 delete_thread_1 (ptid_t ptid
, int silent
)
394 struct thread_info
*tp
, *tpprev
;
398 for (tp
= thread_list
; tp
; tpprev
= tp
, tp
= tp
->next
)
399 if (ptid_equal (tp
->ptid
, ptid
))
405 /* Dead threads don't need to step-over. Remove from queue. */
406 if (tp
->step_over_next
!= NULL
)
407 thread_step_over_chain_remove (tp
);
409 /* If this is the current thread, or there's code out there that
410 relies on it existing (refcount > 0) we can't delete yet. Mark
411 it as exited, and notify it. */
413 || ptid_equal (tp
->ptid
, inferior_ptid
))
415 if (tp
->state
!= THREAD_EXITED
)
417 observer_notify_thread_exit (tp
, silent
);
419 /* Tag it as exited. */
420 tp
->state
= THREAD_EXITED
;
422 /* Clear breakpoints, etc. associated with this thread. */
423 clear_thread_inferior_resources (tp
);
426 /* Will be really deleted some other time. */
430 /* Notify thread exit, but only if we haven't already. */
431 if (tp
->state
!= THREAD_EXITED
)
432 observer_notify_thread_exit (tp
, silent
);
434 /* Tag it as exited. */
435 tp
->state
= THREAD_EXITED
;
436 clear_thread_inferior_resources (tp
);
439 tpprev
->next
= tp
->next
;
441 thread_list
= tp
->next
;
446 /* Delete thread PTID and notify of thread exit. If this is
447 inferior_ptid, don't actually delete it, but tag it as exited and
448 do the notification. If PTID is the user selected thread, clear
451 delete_thread (ptid_t ptid
)
453 delete_thread_1 (ptid
, 0 /* not silent */);
457 delete_thread_silent (ptid_t ptid
)
459 delete_thread_1 (ptid
, 1 /* silent */);
463 find_thread_id (int num
)
465 struct thread_info
*tp
;
467 for (tp
= thread_list
; tp
; tp
= tp
->next
)
474 /* Find a thread_info by matching PTID. */
476 find_thread_ptid (ptid_t ptid
)
478 struct thread_info
*tp
;
480 for (tp
= thread_list
; tp
; tp
= tp
->next
)
481 if (ptid_equal (tp
->ptid
, ptid
))
488 * Thread iterator function.
490 * Calls a callback function once for each thread, so long as
491 * the callback function returns false. If the callback function
492 * returns true, the iteration will end and the current thread
493 * will be returned. This can be useful for implementing a
494 * search for a thread with arbitrary attributes, or for applying
495 * some operation to every thread.
497 * FIXME: some of the existing functionality, such as
498 * "Thread apply all", might be rewritten using this functionality.
502 iterate_over_threads (int (*callback
) (struct thread_info
*, void *),
505 struct thread_info
*tp
, *next
;
507 for (tp
= thread_list
; tp
; tp
= next
)
510 if ((*callback
) (tp
, data
))
521 struct thread_info
*tp
;
523 for (tp
= thread_list
; tp
; tp
= tp
->next
)
530 valid_thread_id (int num
)
532 struct thread_info
*tp
;
534 for (tp
= thread_list
; tp
; tp
= tp
->next
)
542 pid_to_thread_id (ptid_t ptid
)
544 struct thread_info
*tp
;
546 for (tp
= thread_list
; tp
; tp
= tp
->next
)
547 if (ptid_equal (tp
->ptid
, ptid
))
554 thread_id_to_pid (int num
)
556 struct thread_info
*thread
= find_thread_id (num
);
561 return pid_to_ptid (-1);
565 in_thread_list (ptid_t ptid
)
567 struct thread_info
*tp
;
569 for (tp
= thread_list
; tp
; tp
= tp
->next
)
570 if (ptid_equal (tp
->ptid
, ptid
))
573 return 0; /* Never heard of 'im. */
576 /* Finds the first thread of the inferior given by PID. If PID is -1,
577 return the first thread in the list. */
580 first_thread_of_process (int pid
)
582 struct thread_info
*tp
, *ret
= NULL
;
584 for (tp
= thread_list
; tp
; tp
= tp
->next
)
585 if (pid
== -1 || ptid_get_pid (tp
->ptid
) == pid
)
586 if (ret
== NULL
|| tp
->num
< ret
->num
)
593 any_thread_of_process (int pid
)
595 struct thread_info
*tp
;
597 gdb_assert (pid
!= 0);
599 /* Prefer the current thread. */
600 if (ptid_get_pid (inferior_ptid
) == pid
)
601 return inferior_thread ();
603 ALL_NON_EXITED_THREADS (tp
)
604 if (ptid_get_pid (tp
->ptid
) == pid
)
611 any_live_thread_of_process (int pid
)
613 struct thread_info
*curr_tp
= NULL
;
614 struct thread_info
*tp
;
615 struct thread_info
*tp_executing
= NULL
;
617 gdb_assert (pid
!= 0);
619 /* Prefer the current thread if it's not executing. */
620 if (ptid_get_pid (inferior_ptid
) == pid
)
622 /* If the current thread is dead, forget it. If it's not
623 executing, use it. Otherwise, still choose it (below), but
624 only if no other non-executing thread is found. */
625 curr_tp
= inferior_thread ();
626 if (curr_tp
->state
== THREAD_EXITED
)
628 else if (!curr_tp
->executing
)
632 ALL_NON_EXITED_THREADS (tp
)
633 if (ptid_get_pid (tp
->ptid
) == pid
)
641 /* If both the current thread and all live threads are executing,
642 prefer the current thread. */
646 /* Otherwise, just return an executing thread, if any. */
650 /* Print a list of thread ids currently known, and the total number of
651 threads. To be used from within catch_errors. */
653 do_captured_list_thread_ids (struct ui_out
*uiout
, void *arg
)
655 struct thread_info
*tp
;
657 struct cleanup
*cleanup_chain
;
658 int current_thread
= -1;
660 update_thread_list ();
662 cleanup_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "thread-ids");
664 for (tp
= thread_list
; tp
; tp
= tp
->next
)
666 if (tp
->state
== THREAD_EXITED
)
669 if (ptid_equal (tp
->ptid
, inferior_ptid
))
670 current_thread
= tp
->num
;
673 ui_out_field_int (uiout
, "thread-id", tp
->num
);
676 do_cleanups (cleanup_chain
);
678 if (current_thread
!= -1)
679 ui_out_field_int (uiout
, "current-thread-id", current_thread
);
680 ui_out_field_int (uiout
, "number-of-threads", num
);
684 /* Official gdblib interface function to get a list of thread ids and
687 gdb_list_thread_ids (struct ui_out
*uiout
, char **error_message
)
689 if (catch_exceptions_with_msg (uiout
, do_captured_list_thread_ids
, NULL
,
690 error_message
, RETURN_MASK_ALL
) < 0)
695 /* Return true if TP is an active thread. */
697 thread_alive (struct thread_info
*tp
)
699 if (tp
->state
== THREAD_EXITED
)
701 if (!target_thread_alive (tp
->ptid
))
706 /* See gdbthreads.h. */
711 struct thread_info
*tp
, *tmp
;
713 ALL_THREADS_SAFE (tp
, tmp
)
715 if (!thread_alive (tp
))
716 delete_thread (tp
->ptid
);
720 /* See gdbthreads.h. */
723 delete_exited_threads (void)
725 struct thread_info
*tp
, *tmp
;
727 ALL_THREADS_SAFE (tp
, tmp
)
729 if (tp
->state
== THREAD_EXITED
)
730 delete_thread (tp
->ptid
);
734 /* Disable storing stack temporaries for the thread whose id is
738 disable_thread_stack_temporaries (void *data
)
741 struct thread_info
*tp
= find_thread_ptid (*pd
);
745 tp
->stack_temporaries_enabled
= 0;
746 VEC_free (value_ptr
, tp
->stack_temporaries
);
752 /* Enable storing stack temporaries for thread with id PTID and return a
753 cleanup which can disable and clear the stack temporaries. */
756 enable_thread_stack_temporaries (ptid_t ptid
)
758 struct thread_info
*tp
= find_thread_ptid (ptid
);
762 gdb_assert (tp
!= NULL
);
764 tp
->stack_temporaries_enabled
= 1;
765 tp
->stack_temporaries
= NULL
;
766 data
= XNEW (ptid_t
);
768 c
= make_cleanup (disable_thread_stack_temporaries
, data
);
773 /* Return non-zero value if stack temporaies are enabled for the thread
777 thread_stack_temporaries_enabled_p (ptid_t ptid
)
779 struct thread_info
*tp
= find_thread_ptid (ptid
);
784 return tp
->stack_temporaries_enabled
;
787 /* Push V on to the stack temporaries of the thread with id PTID. */
790 push_thread_stack_temporary (ptid_t ptid
, struct value
*v
)
792 struct thread_info
*tp
= find_thread_ptid (ptid
);
794 gdb_assert (tp
!= NULL
&& tp
->stack_temporaries_enabled
);
795 VEC_safe_push (value_ptr
, tp
->stack_temporaries
, v
);
798 /* Return 1 if VAL is among the stack temporaries of the thread
799 with id PTID. Return 0 otherwise. */
802 value_in_thread_stack_temporaries (struct value
*val
, ptid_t ptid
)
804 struct thread_info
*tp
= find_thread_ptid (ptid
);
806 gdb_assert (tp
!= NULL
&& tp
->stack_temporaries_enabled
);
807 if (!VEC_empty (value_ptr
, tp
->stack_temporaries
))
812 for (i
= 0; VEC_iterate (value_ptr
, tp
->stack_temporaries
, i
, v
); i
++)
820 /* Return the last of the stack temporaries for thread with id PTID.
821 Return NULL if there are no stack temporaries for the thread. */
824 get_last_thread_stack_temporary (ptid_t ptid
)
826 struct value
*lastval
= NULL
;
827 struct thread_info
*tp
= find_thread_ptid (ptid
);
829 gdb_assert (tp
!= NULL
);
830 if (!VEC_empty (value_ptr
, tp
->stack_temporaries
))
831 lastval
= VEC_last (value_ptr
, tp
->stack_temporaries
);
837 thread_change_ptid (ptid_t old_ptid
, ptid_t new_ptid
)
839 struct inferior
*inf
;
840 struct thread_info
*tp
;
842 /* It can happen that what we knew as the target inferior id
843 changes. E.g, target remote may only discover the remote process
844 pid after adding the inferior to GDB's list. */
845 inf
= find_inferior_ptid (old_ptid
);
846 inf
->pid
= ptid_get_pid (new_ptid
);
848 tp
= find_thread_ptid (old_ptid
);
851 observer_notify_thread_ptid_changed (old_ptid
, new_ptid
);
854 /* See gdbthread.h. */
857 set_resumed (ptid_t ptid
, int resumed
)
859 struct thread_info
*tp
;
860 int all
= ptid_equal (ptid
, minus_one_ptid
);
862 if (all
|| ptid_is_pid (ptid
))
864 for (tp
= thread_list
; tp
; tp
= tp
->next
)
865 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
866 tp
->resumed
= resumed
;
870 tp
= find_thread_ptid (ptid
);
871 gdb_assert (tp
!= NULL
);
872 tp
->resumed
= resumed
;
876 /* Helper for set_running, that marks one thread either running or
880 set_running_thread (struct thread_info
*tp
, int running
)
884 if (running
&& tp
->state
== THREAD_STOPPED
)
886 tp
->state
= running
? THREAD_RUNNING
: THREAD_STOPPED
;
890 /* If the thread is now marked stopped, remove it from
891 the step-over queue, so that we don't try to resume
892 it until the user wants it to. */
893 if (tp
->step_over_next
!= NULL
)
894 thread_step_over_chain_remove (tp
);
901 set_running (ptid_t ptid
, int running
)
903 struct thread_info
*tp
;
904 int all
= ptid_equal (ptid
, minus_one_ptid
);
907 /* We try not to notify the observer if no thread has actually changed
908 the running state -- merely to reduce the number of messages to
909 frontend. Frontend is supposed to handle multiple *running just fine. */
910 if (all
|| ptid_is_pid (ptid
))
912 for (tp
= thread_list
; tp
; tp
= tp
->next
)
913 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
915 if (tp
->state
== THREAD_EXITED
)
918 if (set_running_thread (tp
, running
))
924 tp
= find_thread_ptid (ptid
);
925 gdb_assert (tp
!= NULL
);
926 gdb_assert (tp
->state
!= THREAD_EXITED
);
927 if (set_running_thread (tp
, running
))
931 observer_notify_target_resumed (ptid
);
935 is_thread_state (ptid_t ptid
, enum thread_state state
)
937 struct thread_info
*tp
;
939 tp
= find_thread_ptid (ptid
);
941 return tp
->state
== state
;
945 is_stopped (ptid_t ptid
)
947 return is_thread_state (ptid
, THREAD_STOPPED
);
951 is_exited (ptid_t ptid
)
953 return is_thread_state (ptid
, THREAD_EXITED
);
957 is_running (ptid_t ptid
)
959 return is_thread_state (ptid
, THREAD_RUNNING
);
963 is_executing (ptid_t ptid
)
965 struct thread_info
*tp
;
967 tp
= find_thread_ptid (ptid
);
969 return tp
->executing
;
973 set_executing (ptid_t ptid
, int executing
)
975 struct thread_info
*tp
;
976 int all
= ptid_equal (ptid
, minus_one_ptid
);
978 if (all
|| ptid_is_pid (ptid
))
980 for (tp
= thread_list
; tp
; tp
= tp
->next
)
981 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
982 tp
->executing
= executing
;
986 tp
= find_thread_ptid (ptid
);
988 tp
->executing
= executing
;
991 /* It only takes one running thread to spawn more threads.*/
993 threads_executing
= 1;
994 /* Only clear the flag if the caller is telling us everything is
996 else if (ptid_equal (minus_one_ptid
, ptid
))
997 threads_executing
= 0;
1000 /* See gdbthread.h. */
1003 threads_are_executing (void)
1005 return threads_executing
;
1009 set_stop_requested (ptid_t ptid
, int stop
)
1011 struct thread_info
*tp
;
1012 int all
= ptid_equal (ptid
, minus_one_ptid
);
1014 if (all
|| ptid_is_pid (ptid
))
1016 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1017 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
1018 tp
->stop_requested
= stop
;
1022 tp
= find_thread_ptid (ptid
);
1024 tp
->stop_requested
= stop
;
1027 /* Call the stop requested observer so other components of GDB can
1028 react to this request. */
1030 observer_notify_thread_stop_requested (ptid
);
1034 finish_thread_state (ptid_t ptid
)
1036 struct thread_info
*tp
;
1038 int any_started
= 0;
1040 all
= ptid_equal (ptid
, minus_one_ptid
);
1042 if (all
|| ptid_is_pid (ptid
))
1044 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1046 if (tp
->state
== THREAD_EXITED
)
1048 if (all
|| ptid_get_pid (ptid
) == ptid_get_pid (tp
->ptid
))
1050 if (set_running_thread (tp
, tp
->executing
))
1057 tp
= find_thread_ptid (ptid
);
1059 if (tp
->state
!= THREAD_EXITED
)
1061 if (set_running_thread (tp
, tp
->executing
))
1067 observer_notify_target_resumed (ptid
);
1071 finish_thread_state_cleanup (void *arg
)
1073 ptid_t
*ptid_p
= arg
;
1077 finish_thread_state (*ptid_p
);
1081 pc_in_thread_step_range (CORE_ADDR pc
, struct thread_info
*thread
)
1083 return (pc
>= thread
->control
.step_range_start
1084 && pc
< thread
->control
.step_range_end
);
1087 /* Prints the list of threads and their details on UIOUT.
1088 This is a version of 'info_threads_command' suitable for
1090 If REQUESTED_THREAD is not -1, it's the GDB id of the thread
1091 that should be printed. Otherwise, all threads are
1093 If PID is not -1, only print threads from the process PID.
1094 Otherwise, threads from all attached PIDs are printed.
1095 If both REQUESTED_THREAD and PID are not -1, then the thread
1096 is printed if it belongs to the specified process. Otherwise,
1097 an error is raised. */
1099 print_thread_info (struct ui_out
*uiout
, char *requested_threads
, int pid
)
1101 struct thread_info
*tp
;
1102 ptid_t current_ptid
;
1103 struct cleanup
*old_chain
;
1104 char *extra_info
, *name
, *target_id
;
1105 int current_thread
= -1;
1107 update_thread_list ();
1108 current_ptid
= inferior_ptid
;
1110 /* We'll be switching threads temporarily. */
1111 old_chain
= make_cleanup_restore_current_thread ();
1113 /* For backward compatibility, we make a list for MI. A table is
1114 preferable for the CLI, though, because it shows table
1116 if (ui_out_is_mi_like_p (uiout
))
1117 make_cleanup_ui_out_list_begin_end (uiout
, "threads");
1122 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1124 if (!number_is_in_list (requested_threads
, tp
->num
))
1127 if (pid
!= -1 && ptid_get_pid (tp
->ptid
) != pid
)
1130 if (tp
->state
== THREAD_EXITED
)
1138 if (requested_threads
== NULL
|| *requested_threads
== '\0')
1139 ui_out_message (uiout
, 0, _("No threads.\n"));
1141 ui_out_message (uiout
, 0, _("No threads match '%s'.\n"),
1143 do_cleanups (old_chain
);
1147 make_cleanup_ui_out_table_begin_end (uiout
, 4, n_threads
, "threads");
1149 ui_out_table_header (uiout
, 1, ui_left
, "current", "");
1150 ui_out_table_header (uiout
, 4, ui_left
, "id", "Id");
1151 ui_out_table_header (uiout
, 17, ui_left
, "target-id", "Target Id");
1152 ui_out_table_header (uiout
, 1, ui_left
, "frame", "Frame");
1153 ui_out_table_body (uiout
);
1156 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1158 struct cleanup
*chain2
;
1161 if (!number_is_in_list (requested_threads
, tp
->num
))
1164 if (pid
!= -1 && ptid_get_pid (tp
->ptid
) != pid
)
1166 if (requested_threads
!= NULL
&& *requested_threads
!= '\0')
1167 error (_("Requested thread not found in requested process"));
1171 if (ptid_equal (tp
->ptid
, current_ptid
))
1172 current_thread
= tp
->num
;
1174 if (tp
->state
== THREAD_EXITED
)
1177 chain2
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
1179 if (ui_out_is_mi_like_p (uiout
))
1181 /* Compatibility. */
1182 if (ptid_equal (tp
->ptid
, current_ptid
))
1183 ui_out_text (uiout
, "* ");
1185 ui_out_text (uiout
, " ");
1189 if (ptid_equal (tp
->ptid
, current_ptid
))
1190 ui_out_field_string (uiout
, "current", "*");
1192 ui_out_field_skip (uiout
, "current");
1195 ui_out_field_int (uiout
, "id", tp
->num
);
1197 /* For the CLI, we stuff everything into the target-id field.
1198 This is a gross hack to make the output come out looking
1199 correct. The underlying problem here is that ui-out has no
1200 way to specify that a field's space allocation should be
1201 shared by several fields. For MI, we do the right thing
1204 target_id
= target_pid_to_str (tp
->ptid
);
1205 extra_info
= target_extra_thread_info (tp
);
1206 name
= tp
->name
? tp
->name
: target_thread_name (tp
);
1208 if (ui_out_is_mi_like_p (uiout
))
1210 ui_out_field_string (uiout
, "target-id", target_id
);
1212 ui_out_field_string (uiout
, "details", extra_info
);
1214 ui_out_field_string (uiout
, "name", name
);
1218 struct cleanup
*str_cleanup
;
1221 if (extra_info
&& name
)
1222 contents
= xstrprintf ("%s \"%s\" (%s)", target_id
,
1224 else if (extra_info
)
1225 contents
= xstrprintf ("%s (%s)", target_id
, extra_info
);
1227 contents
= xstrprintf ("%s \"%s\"", target_id
, name
);
1229 contents
= xstrdup (target_id
);
1230 str_cleanup
= make_cleanup (xfree
, contents
);
1232 ui_out_field_string (uiout
, "target-id", contents
);
1233 do_cleanups (str_cleanup
);
1236 if (tp
->state
== THREAD_RUNNING
)
1237 ui_out_text (uiout
, "(running)\n");
1240 /* The switch below puts us at the top of the stack (leaf
1242 switch_to_thread (tp
->ptid
);
1243 print_stack_frame (get_selected_frame (NULL
),
1244 /* For MI output, print frame level. */
1245 ui_out_is_mi_like_p (uiout
),
1249 if (ui_out_is_mi_like_p (uiout
))
1251 char *state
= "stopped";
1253 if (tp
->state
== THREAD_RUNNING
)
1255 ui_out_field_string (uiout
, "state", state
);
1258 core
= target_core_of_thread (tp
->ptid
);
1259 if (ui_out_is_mi_like_p (uiout
) && core
!= -1)
1260 ui_out_field_int (uiout
, "core", core
);
1262 do_cleanups (chain2
);
1265 /* Restores the current thread and the frame selected before
1266 the "info threads" command. */
1267 do_cleanups (old_chain
);
1269 if (pid
== -1 && requested_threads
== NULL
)
1271 gdb_assert (current_thread
!= -1
1273 || ptid_equal (inferior_ptid
, null_ptid
));
1274 if (current_thread
!= -1 && ui_out_is_mi_like_p (uiout
))
1275 ui_out_field_int (uiout
, "current-thread-id", current_thread
);
1277 if (current_thread
!= -1 && is_exited (current_ptid
))
1278 ui_out_message (uiout
, 0, "\n\
1279 The current thread <Thread ID %d> has terminated. See `help thread'.\n",
1281 else if (thread_list
1282 && current_thread
== -1
1283 && ptid_equal (current_ptid
, null_ptid
))
1284 ui_out_message (uiout
, 0, "\n\
1285 No selected thread. See `help thread'.\n");
1289 /* Print information about currently known threads
1291 Optional ARG is a thread id, or list of thread ids.
1293 Note: this has the drawback that it _really_ switches
1294 threads, which frees the frame cache. A no-side
1295 effects info-threads command would be nicer. */
1298 info_threads_command (char *arg
, int from_tty
)
1300 print_thread_info (current_uiout
, arg
, -1);
1303 /* Switch from one thread to another. */
1306 switch_to_thread (ptid_t ptid
)
1308 /* Switch the program space as well, if we can infer it from the now
1309 current thread. Otherwise, it's up to the caller to select the
1311 if (!ptid_equal (ptid
, null_ptid
))
1313 struct inferior
*inf
;
1315 inf
= find_inferior_ptid (ptid
);
1316 gdb_assert (inf
!= NULL
);
1317 set_current_program_space (inf
->pspace
);
1318 set_current_inferior (inf
);
1321 if (ptid_equal (ptid
, inferior_ptid
))
1324 inferior_ptid
= ptid
;
1325 reinit_frame_cache ();
1327 /* We don't check for is_stopped, because we're called at times
1328 while in the TARGET_RUNNING state, e.g., while handling an
1330 if (!ptid_equal (inferior_ptid
, null_ptid
)
1331 && !is_exited (ptid
)
1332 && !is_executing (ptid
))
1333 stop_pc
= regcache_read_pc (get_thread_regcache (ptid
));
1335 stop_pc
= ~(CORE_ADDR
) 0;
1339 restore_current_thread (ptid_t ptid
)
1341 switch_to_thread (ptid
);
1345 restore_selected_frame (struct frame_id a_frame_id
, int frame_level
)
1347 struct frame_info
*frame
= NULL
;
1350 /* This means there was no selected frame. */
1351 if (frame_level
== -1)
1353 select_frame (NULL
);
1357 gdb_assert (frame_level
>= 0);
1359 /* Restore by level first, check if the frame id is the same as
1360 expected. If that fails, try restoring by frame id. If that
1361 fails, nothing to do, just warn the user. */
1363 count
= frame_level
;
1364 frame
= find_relative_frame (get_current_frame (), &count
);
1367 /* The frame ids must match - either both valid or both outer_frame_id.
1368 The latter case is not failsafe, but since it's highly unlikely
1369 the search by level finds the wrong frame, it's 99.9(9)% of
1370 the time (for all practical purposes) safe. */
1371 && frame_id_eq (get_frame_id (frame
), a_frame_id
))
1373 /* Cool, all is fine. */
1374 select_frame (frame
);
1378 frame
= frame_find_by_id (a_frame_id
);
1381 /* Cool, refound it. */
1382 select_frame (frame
);
1386 /* Nothing else to do, the frame layout really changed. Select the
1387 innermost stack frame. */
1388 select_frame (get_current_frame ());
1390 /* Warn the user. */
1391 if (frame_level
> 0 && !ui_out_is_mi_like_p (current_uiout
))
1393 warning (_("Couldn't restore frame #%d in "
1394 "current thread. Bottom (innermost) frame selected:"),
1396 /* For MI, we should probably have a notification about
1397 current frame change. But this error is not very
1398 likely, so don't bother for now. */
1399 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
1403 /* Data used by the cleanup installed by
1404 'make_cleanup_restore_current_thread'. */
1406 struct current_thread_cleanup
1408 /* Next in list of currently installed 'struct
1409 current_thread_cleanup' cleanups. See
1410 'current_thread_cleanup_chain' below. */
1411 struct current_thread_cleanup
*next
;
1413 ptid_t inferior_ptid
;
1414 struct frame_id selected_frame_id
;
1415 int selected_frame_level
;
1421 /* A chain of currently installed 'struct current_thread_cleanup'
1422 cleanups. Restoring the previously selected thread looks up the
1423 old thread in the thread list by ptid. If the thread changes ptid,
1424 we need to update the cleanup's thread structure so the look up
1426 static struct current_thread_cleanup
*current_thread_cleanup_chain
;
1428 /* A thread_ptid_changed observer. Update all currently installed
1429 current_thread_cleanup cleanups that want to switch back to
1430 OLD_PTID to switch back to NEW_PTID instead. */
1433 restore_current_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1435 struct current_thread_cleanup
*it
;
1437 for (it
= current_thread_cleanup_chain
; it
!= NULL
; it
= it
->next
)
1439 if (ptid_equal (it
->inferior_ptid
, old_ptid
))
1440 it
->inferior_ptid
= new_ptid
;
1445 do_restore_current_thread_cleanup (void *arg
)
1447 struct thread_info
*tp
;
1448 struct current_thread_cleanup
*old
= arg
;
1450 tp
= find_thread_ptid (old
->inferior_ptid
);
1452 /* If the previously selected thread belonged to a process that has
1453 in the mean time been deleted (due to normal exit, detach, etc.),
1454 then don't revert back to it, but instead simply drop back to no
1457 && find_inferior_ptid (tp
->ptid
) != NULL
)
1458 restore_current_thread (old
->inferior_ptid
);
1461 restore_current_thread (null_ptid
);
1462 set_current_inferior (find_inferior_id (old
->inf_id
));
1465 /* The running state of the originally selected thread may have
1466 changed, so we have to recheck it here. */
1467 if (!ptid_equal (inferior_ptid
, null_ptid
)
1469 && is_stopped (inferior_ptid
)
1470 && target_has_registers
1472 && target_has_memory
)
1473 restore_selected_frame (old
->selected_frame_id
,
1474 old
->selected_frame_level
);
1478 restore_current_thread_cleanup_dtor (void *arg
)
1480 struct current_thread_cleanup
*old
= arg
;
1481 struct thread_info
*tp
;
1482 struct inferior
*inf
;
1484 current_thread_cleanup_chain
= current_thread_cleanup_chain
->next
;
1486 tp
= find_thread_ptid (old
->inferior_ptid
);
1489 inf
= find_inferior_id (old
->inf_id
);
1491 inf
->removable
= old
->was_removable
;
1495 /* Set the thread reference count. */
1498 set_thread_refcount (void *data
)
1501 struct thread_array_cleanup
*ta_cleanup
= data
;
1503 for (k
= 0; k
!= ta_cleanup
->count
; k
++)
1504 ta_cleanup
->tp_array
[k
]->refcount
--;
1508 make_cleanup_restore_current_thread (void)
1510 struct thread_info
*tp
;
1511 struct frame_info
*frame
;
1512 struct current_thread_cleanup
*old
= XNEW (struct current_thread_cleanup
);
1514 old
->inferior_ptid
= inferior_ptid
;
1515 old
->inf_id
= current_inferior ()->num
;
1516 old
->was_removable
= current_inferior ()->removable
;
1518 old
->next
= current_thread_cleanup_chain
;
1519 current_thread_cleanup_chain
= old
;
1521 if (!ptid_equal (inferior_ptid
, null_ptid
))
1523 old
->was_stopped
= is_stopped (inferior_ptid
);
1524 if (old
->was_stopped
1525 && target_has_registers
1527 && target_has_memory
)
1529 /* When processing internal events, there might not be a
1530 selected frame. If we naively call get_selected_frame
1531 here, then we can end up reading debuginfo for the
1532 current frame, but we don't generally need the debuginfo
1534 frame
= get_selected_frame_if_set ();
1539 old
->selected_frame_id
= get_frame_id (frame
);
1540 old
->selected_frame_level
= frame_relative_level (frame
);
1542 tp
= find_thread_ptid (inferior_ptid
);
1547 current_inferior ()->removable
= 0;
1549 return make_cleanup_dtor (do_restore_current_thread_cleanup
, old
,
1550 restore_current_thread_cleanup_dtor
);
1553 /* If non-zero tp_array_compar should sort in ascending order, otherwise in
1554 descending order. */
1556 static int tp_array_compar_ascending
;
1558 /* Sort an array for struct thread_info pointers by their NUM, order is
1559 determined by TP_ARRAY_COMPAR_ASCENDING. */
1562 tp_array_compar (const void *ap_voidp
, const void *bp_voidp
)
1564 const struct thread_info
*const *ap
= ap_voidp
;
1565 const struct thread_info
*const *bp
= bp_voidp
;
1567 return ((((*ap
)->num
> (*bp
)->num
) - ((*ap
)->num
< (*bp
)->num
))
1568 * (tp_array_compar_ascending
? +1 : -1));
1571 /* Apply a GDB command to a list of threads. List syntax is a whitespace
1572 seperated list of numbers, or ranges, or the keyword `all'. Ranges consist
1573 of two numbers seperated by a hyphen. Examples:
1575 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
1576 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
1577 thread apply all p x/i $pc Apply x/i $pc cmd to all threads. */
1580 thread_apply_all_command (char *cmd
, int from_tty
)
1582 struct cleanup
*old_chain
;
1585 struct thread_array_cleanup ta_cleanup
;
1587 tp_array_compar_ascending
= 0;
1589 && check_for_argument (&cmd
, "-ascending", strlen ("-ascending")))
1591 cmd
= skip_spaces (cmd
);
1592 tp_array_compar_ascending
= 1;
1595 if (cmd
== NULL
|| *cmd
== '\000')
1596 error (_("Please specify a command following the thread ID list"));
1598 update_thread_list ();
1600 old_chain
= make_cleanup_restore_current_thread ();
1602 /* Save a copy of the command in case it is clobbered by
1604 saved_cmd
= xstrdup (cmd
);
1605 make_cleanup (xfree
, saved_cmd
);
1607 /* Note this includes exited threads. */
1608 tc
= thread_count ();
1611 struct thread_info
**tp_array
;
1612 struct thread_info
*tp
;
1615 /* Save a copy of the thread_list in case we execute detach
1617 tp_array
= XNEWVEC (struct thread_info
*, tc
);
1618 make_cleanup (xfree
, tp_array
);
1620 ALL_NON_EXITED_THREADS (tp
)
1626 /* Because we skipped exited threads, we may end up with fewer
1627 threads in the array than the total count of threads. */
1628 gdb_assert (i
<= tc
);
1631 qsort (tp_array
, i
, sizeof (*tp_array
), tp_array_compar
);
1633 ta_cleanup
.tp_array
= tp_array
;
1634 ta_cleanup
.count
= i
;
1635 make_cleanup (set_thread_refcount
, &ta_cleanup
);
1637 for (k
= 0; k
!= i
; k
++)
1638 if (thread_alive (tp_array
[k
]))
1640 switch_to_thread (tp_array
[k
]->ptid
);
1641 printf_filtered (_("\nThread %d (%s):\n"),
1643 target_pid_to_str (inferior_ptid
));
1644 execute_command (cmd
, from_tty
);
1646 /* Restore exact command used previously. */
1647 strcpy (cmd
, saved_cmd
);
1651 do_cleanups (old_chain
);
1655 thread_apply_command (char *tidlist
, int from_tty
)
1658 struct cleanup
*old_chain
;
1660 struct get_number_or_range_state state
;
1662 if (tidlist
== NULL
|| *tidlist
== '\000')
1663 error (_("Please specify a thread ID list"));
1665 for (cmd
= tidlist
; *cmd
!= '\000' && !isalpha (*cmd
); cmd
++);
1668 error (_("Please specify a command following the thread ID list"));
1670 /* Save a copy of the command in case it is clobbered by
1672 saved_cmd
= xstrdup (cmd
);
1673 old_chain
= make_cleanup (xfree
, saved_cmd
);
1675 init_number_or_range (&state
, tidlist
);
1676 while (!state
.finished
&& state
.string
< cmd
)
1678 struct thread_info
*tp
;
1681 start
= get_number_or_range (&state
);
1683 make_cleanup_restore_current_thread ();
1685 tp
= find_thread_id (start
);
1688 warning (_("Unknown thread %d."), start
);
1689 else if (!thread_alive (tp
))
1690 warning (_("Thread %d has terminated."), start
);
1693 switch_to_thread (tp
->ptid
);
1695 printf_filtered (_("\nThread %d (%s):\n"), tp
->num
,
1696 target_pid_to_str (inferior_ptid
));
1697 execute_command (cmd
, from_tty
);
1699 /* Restore exact command used previously. */
1700 strcpy (cmd
, saved_cmd
);
1704 do_cleanups (old_chain
);
1707 /* Switch to the specified thread. Will dispatch off to thread_apply_command
1708 if prefix of arg is `apply'. */
1711 thread_command (char *tidstr
, int from_tty
)
1715 if (ptid_equal (inferior_ptid
, null_ptid
))
1716 error (_("No thread selected"));
1718 if (target_has_stack
)
1720 if (is_exited (inferior_ptid
))
1721 printf_filtered (_("[Current thread is %d (%s) (exited)]\n"),
1722 pid_to_thread_id (inferior_ptid
),
1723 target_pid_to_str (inferior_ptid
));
1725 printf_filtered (_("[Current thread is %d (%s)]\n"),
1726 pid_to_thread_id (inferior_ptid
),
1727 target_pid_to_str (inferior_ptid
));
1730 error (_("No stack."));
1734 gdb_thread_select (current_uiout
, tidstr
, NULL
);
1737 /* Implementation of `thread name'. */
1740 thread_name_command (char *arg
, int from_tty
)
1742 struct thread_info
*info
;
1744 if (ptid_equal (inferior_ptid
, null_ptid
))
1745 error (_("No thread selected"));
1747 arg
= skip_spaces (arg
);
1749 info
= inferior_thread ();
1751 info
->name
= arg
? xstrdup (arg
) : NULL
;
1754 /* Find thread ids with a name, target pid, or extra info matching ARG. */
1757 thread_find_command (char *arg
, int from_tty
)
1759 struct thread_info
*tp
;
1761 unsigned long match
= 0;
1763 if (arg
== NULL
|| *arg
== '\0')
1764 error (_("Command requires an argument."));
1766 tmp
= re_comp (arg
);
1768 error (_("Invalid regexp (%s): %s"), tmp
, arg
);
1770 update_thread_list ();
1771 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1773 if (tp
->name
!= NULL
&& re_exec (tp
->name
))
1775 printf_filtered (_("Thread %d has name '%s'\n"),
1780 tmp
= target_thread_name (tp
);
1781 if (tmp
!= NULL
&& re_exec (tmp
))
1783 printf_filtered (_("Thread %d has target name '%s'\n"),
1788 tmp
= target_pid_to_str (tp
->ptid
);
1789 if (tmp
!= NULL
&& re_exec (tmp
))
1791 printf_filtered (_("Thread %d has target id '%s'\n"),
1796 tmp
= target_extra_thread_info (tp
);
1797 if (tmp
!= NULL
&& re_exec (tmp
))
1799 printf_filtered (_("Thread %d has extra info '%s'\n"),
1805 printf_filtered (_("No threads match '%s'\n"), arg
);
1808 /* Print notices when new threads are attached and detached. */
1809 int print_thread_events
= 1;
1811 show_print_thread_events (struct ui_file
*file
, int from_tty
,
1812 struct cmd_list_element
*c
, const char *value
)
1814 fprintf_filtered (file
,
1815 _("Printing of thread events is %s.\n"),
1820 do_captured_thread_select (struct ui_out
*uiout
, void *tidstr
)
1823 struct thread_info
*tp
;
1825 num
= value_as_long (parse_and_eval (tidstr
));
1827 tp
= find_thread_id (num
);
1830 error (_("Thread ID %d not known."), num
);
1832 if (!thread_alive (tp
))
1833 error (_("Thread ID %d has terminated."), num
);
1835 switch_to_thread (tp
->ptid
);
1837 annotate_thread_changed ();
1839 ui_out_text (uiout
, "[Switching to thread ");
1840 ui_out_field_int (uiout
, "new-thread-id", pid_to_thread_id (inferior_ptid
));
1841 ui_out_text (uiout
, " (");
1842 ui_out_text (uiout
, target_pid_to_str (inferior_ptid
));
1843 ui_out_text (uiout
, ")]");
1845 /* Note that we can't reach this with an exited thread, due to the
1846 thread_alive check above. */
1847 if (tp
->state
== THREAD_RUNNING
)
1848 ui_out_text (uiout
, "(running)\n");
1851 ui_out_text (uiout
, "\n");
1852 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
1855 /* Since the current thread may have changed, see if there is any
1856 exited thread we can now delete. */
1863 gdb_thread_select (struct ui_out
*uiout
, char *tidstr
, char **error_message
)
1865 if (catch_exceptions_with_msg (uiout
, do_captured_thread_select
, tidstr
,
1866 error_message
, RETURN_MASK_ALL
) < 0)
1871 /* Update the 'threads_executing' global based on the threads we know
1875 update_threads_executing (void)
1877 struct thread_info
*tp
;
1879 threads_executing
= 0;
1880 ALL_NON_EXITED_THREADS (tp
)
1884 threads_executing
= 1;
1891 update_thread_list (void)
1893 target_update_thread_list ();
1894 update_threads_executing ();
1897 /* Return a new value for the selected thread's id. Return a value of 0 if
1898 no thread is selected, or no threads exist. */
1900 static struct value
*
1901 thread_id_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
1904 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
1906 return value_from_longest (builtin_type (gdbarch
)->builtin_int
,
1907 (tp
? tp
->num
: 0));
1910 /* Commands with a prefix of `thread'. */
1911 struct cmd_list_element
*thread_cmd_list
= NULL
;
1913 /* Implementation of `thread' variable. */
1915 static const struct internalvar_funcs thread_funcs
=
1917 thread_id_make_value
,
1923 _initialize_thread (void)
1925 static struct cmd_list_element
*thread_apply_list
= NULL
;
1927 add_info ("threads", info_threads_command
,
1928 _("Display currently known threads.\n\
1929 Usage: info threads [ID]...\n\
1930 Optional arguments are thread IDs with spaces between.\n\
1931 If no arguments, all threads are displayed."));
1933 add_prefix_cmd ("thread", class_run
, thread_command
, _("\
1934 Use this command to switch between threads.\n\
1935 The new thread ID must be currently known."),
1936 &thread_cmd_list
, "thread ", 1, &cmdlist
);
1938 add_prefix_cmd ("apply", class_run
, thread_apply_command
,
1939 _("Apply a command to a list of threads."),
1940 &thread_apply_list
, "thread apply ", 1, &thread_cmd_list
);
1942 add_cmd ("all", class_run
, thread_apply_all_command
,
1944 Apply a command to all threads.\n\
1946 Usage: thread apply all [-ascending] <command>\n\
1947 -ascending: Call <command> for all threads in ascending order.\n\
1948 The default is descending order.\
1950 &thread_apply_list
);
1952 add_cmd ("name", class_run
, thread_name_command
,
1953 _("Set the current thread's name.\n\
1954 Usage: thread name [NAME]\n\
1955 If NAME is not given, then any existing name is removed."), &thread_cmd_list
);
1957 add_cmd ("find", class_run
, thread_find_command
, _("\
1958 Find threads that match a regular expression.\n\
1959 Usage: thread find REGEXP\n\
1960 Will display thread ids whose name, target ID, or extra info matches REGEXP."),
1963 add_com_alias ("t", "thread", class_run
, 1);
1965 add_setshow_boolean_cmd ("thread-events", no_class
,
1966 &print_thread_events
, _("\
1967 Set printing of thread events (such as thread start and exit)."), _("\
1968 Show printing of thread events (such as thread start and exit)."), NULL
,
1970 show_print_thread_events
,
1971 &setprintlist
, &showprintlist
);
1973 create_internalvar_type_lazy ("_thread", &thread_funcs
, NULL
);
1975 observer_attach_thread_ptid_changed (restore_current_thread_ptid_changed
);