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 "thread-fsm.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
));
161 /* See gdbthread.h. */
164 thread_cancel_execution_command (struct thread_info
*thr
)
166 if (thr
->thread_fsm
!= NULL
)
168 thread_fsm_clean_up (thr
->thread_fsm
);
169 thread_fsm_delete (thr
->thread_fsm
);
170 thr
->thread_fsm
= NULL
;
175 clear_thread_inferior_resources (struct thread_info
*tp
)
177 /* NOTE: this will take care of any left-over step_resume breakpoints,
178 but not any user-specified thread-specific breakpoints. We can not
179 delete the breakpoint straight-off, because the inferior might not
180 be stopped at the moment. */
181 delete_at_next_stop (&tp
->control
.step_resume_breakpoint
);
182 delete_at_next_stop (&tp
->control
.exception_resume_breakpoint
);
183 delete_at_next_stop (&tp
->control
.single_step_breakpoints
);
185 delete_longjmp_breakpoint_at_next_stop (tp
->num
);
187 bpstat_clear (&tp
->control
.stop_bpstat
);
189 btrace_teardown (tp
);
191 thread_cancel_execution_command (tp
);
195 free_thread (struct thread_info
*tp
)
199 if (tp
->private_dtor
)
200 tp
->private_dtor (tp
->priv
);
210 init_thread_list (void)
212 struct thread_info
*tp
, *tpnext
;
214 highest_thread_num
= 0;
219 for (tp
= thread_list
; tp
; tp
= tpnext
)
226 threads_executing
= 0;
229 /* Allocate a new thread with target id PTID and add it to the thread
232 static struct thread_info
*
233 new_thread (ptid_t ptid
)
235 struct thread_info
*tp
= XCNEW (struct thread_info
);
238 tp
->num
= ++highest_thread_num
;
239 tp
->next
= thread_list
;
242 /* Nothing to follow yet. */
243 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
244 tp
->state
= THREAD_STOPPED
;
245 tp
->suspend
.waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
251 add_thread_silent (ptid_t ptid
)
253 struct thread_info
*tp
;
255 tp
= find_thread_ptid (ptid
);
257 /* Found an old thread with the same id. It has to be dead,
258 otherwise we wouldn't be adding a new thread with the same id.
259 The OS is reusing this id --- delete it, and recreate a new
262 /* In addition to deleting the thread, if this is the current
263 thread, then we need to take care that delete_thread doesn't
264 really delete the thread if it is inferior_ptid. Create a
265 new template thread in the list with an invalid ptid, switch
266 to it, delete the original thread, reset the new thread's
267 ptid, and switch to it. */
269 if (ptid_equal (inferior_ptid
, ptid
))
271 tp
= new_thread (null_ptid
);
273 /* Make switch_to_thread not read from the thread. */
274 tp
->state
= THREAD_EXITED
;
275 switch_to_thread (null_ptid
);
277 /* Now we can delete it. */
278 delete_thread (ptid
);
280 /* Now reset its ptid, and reswitch inferior_ptid to it. */
282 tp
->state
= THREAD_STOPPED
;
283 switch_to_thread (ptid
);
285 observer_notify_new_thread (tp
);
291 /* Just go ahead and delete it. */
292 delete_thread (ptid
);
295 tp
= new_thread (ptid
);
296 observer_notify_new_thread (tp
);
302 add_thread_with_info (ptid_t ptid
, struct private_thread_info
*priv
)
304 struct thread_info
*result
= add_thread_silent (ptid
);
308 if (print_thread_events
)
309 printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid
));
311 annotate_new_thread ();
316 add_thread (ptid_t ptid
)
318 return add_thread_with_info (ptid
, NULL
);
321 /* Add TP to the end of the step-over chain LIST_P. */
324 step_over_chain_enqueue (struct thread_info
**list_p
, struct thread_info
*tp
)
326 gdb_assert (tp
->step_over_next
== NULL
);
327 gdb_assert (tp
->step_over_prev
== NULL
);
332 tp
->step_over_prev
= tp
->step_over_next
= tp
;
336 struct thread_info
*head
= *list_p
;
337 struct thread_info
*tail
= head
->step_over_prev
;
339 tp
->step_over_prev
= tail
;
340 tp
->step_over_next
= head
;
341 head
->step_over_prev
= tp
;
342 tail
->step_over_next
= tp
;
346 /* Remove TP from step-over chain LIST_P. */
349 step_over_chain_remove (struct thread_info
**list_p
, struct thread_info
*tp
)
351 gdb_assert (tp
->step_over_next
!= NULL
);
352 gdb_assert (tp
->step_over_prev
!= NULL
);
356 if (tp
== tp
->step_over_next
)
359 *list_p
= tp
->step_over_next
;
362 tp
->step_over_prev
->step_over_next
= tp
->step_over_next
;
363 tp
->step_over_next
->step_over_prev
= tp
->step_over_prev
;
364 tp
->step_over_prev
= tp
->step_over_next
= NULL
;
367 /* See gdbthread.h. */
370 thread_step_over_chain_next (struct thread_info
*tp
)
372 struct thread_info
*next
= tp
->step_over_next
;
374 return (next
== step_over_queue_head
? NULL
: next
);
377 /* See gdbthread.h. */
380 thread_is_in_step_over_chain (struct thread_info
*tp
)
382 return (tp
->step_over_next
!= NULL
);
385 /* See gdbthread.h. */
388 thread_step_over_chain_enqueue (struct thread_info
*tp
)
390 step_over_chain_enqueue (&step_over_queue_head
, tp
);
393 /* See gdbthread.h. */
396 thread_step_over_chain_remove (struct thread_info
*tp
)
398 step_over_chain_remove (&step_over_queue_head
, tp
);
401 /* Delete thread PTID. If SILENT, don't notify the observer of this
404 delete_thread_1 (ptid_t ptid
, int silent
)
406 struct thread_info
*tp
, *tpprev
;
410 for (tp
= thread_list
; tp
; tpprev
= tp
, tp
= tp
->next
)
411 if (ptid_equal (tp
->ptid
, ptid
))
417 /* Dead threads don't need to step-over. Remove from queue. */
418 if (tp
->step_over_next
!= NULL
)
419 thread_step_over_chain_remove (tp
);
421 /* If this is the current thread, or there's code out there that
422 relies on it existing (refcount > 0) we can't delete yet. Mark
423 it as exited, and notify it. */
425 || ptid_equal (tp
->ptid
, inferior_ptid
))
427 if (tp
->state
!= THREAD_EXITED
)
429 observer_notify_thread_exit (tp
, silent
);
431 /* Tag it as exited. */
432 tp
->state
= THREAD_EXITED
;
434 /* Clear breakpoints, etc. associated with this thread. */
435 clear_thread_inferior_resources (tp
);
438 /* Will be really deleted some other time. */
442 /* Notify thread exit, but only if we haven't already. */
443 if (tp
->state
!= THREAD_EXITED
)
444 observer_notify_thread_exit (tp
, silent
);
446 /* Tag it as exited. */
447 tp
->state
= THREAD_EXITED
;
448 clear_thread_inferior_resources (tp
);
451 tpprev
->next
= tp
->next
;
453 thread_list
= tp
->next
;
458 /* Delete thread PTID and notify of thread exit. If this is
459 inferior_ptid, don't actually delete it, but tag it as exited and
460 do the notification. If PTID is the user selected thread, clear
463 delete_thread (ptid_t ptid
)
465 delete_thread_1 (ptid
, 0 /* not silent */);
469 delete_thread_silent (ptid_t ptid
)
471 delete_thread_1 (ptid
, 1 /* silent */);
475 find_thread_id (int num
)
477 struct thread_info
*tp
;
479 for (tp
= thread_list
; tp
; tp
= tp
->next
)
486 /* Find a thread_info by matching PTID. */
488 find_thread_ptid (ptid_t ptid
)
490 struct thread_info
*tp
;
492 for (tp
= thread_list
; tp
; tp
= tp
->next
)
493 if (ptid_equal (tp
->ptid
, ptid
))
500 * Thread iterator function.
502 * Calls a callback function once for each thread, so long as
503 * the callback function returns false. If the callback function
504 * returns true, the iteration will end and the current thread
505 * will be returned. This can be useful for implementing a
506 * search for a thread with arbitrary attributes, or for applying
507 * some operation to every thread.
509 * FIXME: some of the existing functionality, such as
510 * "Thread apply all", might be rewritten using this functionality.
514 iterate_over_threads (int (*callback
) (struct thread_info
*, void *),
517 struct thread_info
*tp
, *next
;
519 for (tp
= thread_list
; tp
; tp
= next
)
522 if ((*callback
) (tp
, data
))
533 struct thread_info
*tp
;
535 for (tp
= thread_list
; tp
; tp
= tp
->next
)
542 valid_thread_id (int num
)
544 struct thread_info
*tp
;
546 for (tp
= thread_list
; tp
; tp
= tp
->next
)
554 pid_to_thread_id (ptid_t ptid
)
556 struct thread_info
*tp
;
558 for (tp
= thread_list
; tp
; tp
= tp
->next
)
559 if (ptid_equal (tp
->ptid
, ptid
))
566 thread_id_to_pid (int num
)
568 struct thread_info
*thread
= find_thread_id (num
);
573 return pid_to_ptid (-1);
577 in_thread_list (ptid_t ptid
)
579 struct thread_info
*tp
;
581 for (tp
= thread_list
; tp
; tp
= tp
->next
)
582 if (ptid_equal (tp
->ptid
, ptid
))
585 return 0; /* Never heard of 'im. */
588 /* Finds the first thread of the inferior given by PID. If PID is -1,
589 return the first thread in the list. */
592 first_thread_of_process (int pid
)
594 struct thread_info
*tp
, *ret
= NULL
;
596 for (tp
= thread_list
; tp
; tp
= tp
->next
)
597 if (pid
== -1 || ptid_get_pid (tp
->ptid
) == pid
)
598 if (ret
== NULL
|| tp
->num
< ret
->num
)
605 any_thread_of_process (int pid
)
607 struct thread_info
*tp
;
609 gdb_assert (pid
!= 0);
611 /* Prefer the current thread. */
612 if (ptid_get_pid (inferior_ptid
) == pid
)
613 return inferior_thread ();
615 ALL_NON_EXITED_THREADS (tp
)
616 if (ptid_get_pid (tp
->ptid
) == pid
)
623 any_live_thread_of_process (int pid
)
625 struct thread_info
*curr_tp
= NULL
;
626 struct thread_info
*tp
;
627 struct thread_info
*tp_executing
= NULL
;
629 gdb_assert (pid
!= 0);
631 /* Prefer the current thread if it's not executing. */
632 if (ptid_get_pid (inferior_ptid
) == pid
)
634 /* If the current thread is dead, forget it. If it's not
635 executing, use it. Otherwise, still choose it (below), but
636 only if no other non-executing thread is found. */
637 curr_tp
= inferior_thread ();
638 if (curr_tp
->state
== THREAD_EXITED
)
640 else if (!curr_tp
->executing
)
644 ALL_NON_EXITED_THREADS (tp
)
645 if (ptid_get_pid (tp
->ptid
) == pid
)
653 /* If both the current thread and all live threads are executing,
654 prefer the current thread. */
658 /* Otherwise, just return an executing thread, if any. */
662 /* Print a list of thread ids currently known, and the total number of
663 threads. To be used from within catch_errors. */
665 do_captured_list_thread_ids (struct ui_out
*uiout
, void *arg
)
667 struct thread_info
*tp
;
669 struct cleanup
*cleanup_chain
;
670 int current_thread
= -1;
672 update_thread_list ();
674 cleanup_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "thread-ids");
676 for (tp
= thread_list
; tp
; tp
= tp
->next
)
678 if (tp
->state
== THREAD_EXITED
)
681 if (ptid_equal (tp
->ptid
, inferior_ptid
))
682 current_thread
= tp
->num
;
685 ui_out_field_int (uiout
, "thread-id", tp
->num
);
688 do_cleanups (cleanup_chain
);
690 if (current_thread
!= -1)
691 ui_out_field_int (uiout
, "current-thread-id", current_thread
);
692 ui_out_field_int (uiout
, "number-of-threads", num
);
696 /* Official gdblib interface function to get a list of thread ids and
699 gdb_list_thread_ids (struct ui_out
*uiout
, char **error_message
)
701 if (catch_exceptions_with_msg (uiout
, do_captured_list_thread_ids
, NULL
,
702 error_message
, RETURN_MASK_ALL
) < 0)
707 /* Return true if TP is an active thread. */
709 thread_alive (struct thread_info
*tp
)
711 if (tp
->state
== THREAD_EXITED
)
713 if (!target_thread_alive (tp
->ptid
))
718 /* See gdbthreads.h. */
723 struct thread_info
*tp
, *tmp
;
725 ALL_THREADS_SAFE (tp
, tmp
)
727 if (!thread_alive (tp
))
728 delete_thread (tp
->ptid
);
732 /* See gdbthreads.h. */
735 delete_exited_threads (void)
737 struct thread_info
*tp
, *tmp
;
739 ALL_THREADS_SAFE (tp
, tmp
)
741 if (tp
->state
== THREAD_EXITED
)
742 delete_thread (tp
->ptid
);
746 /* Disable storing stack temporaries for the thread whose id is
750 disable_thread_stack_temporaries (void *data
)
753 struct thread_info
*tp
= find_thread_ptid (*pd
);
757 tp
->stack_temporaries_enabled
= 0;
758 VEC_free (value_ptr
, tp
->stack_temporaries
);
764 /* Enable storing stack temporaries for thread with id PTID and return a
765 cleanup which can disable and clear the stack temporaries. */
768 enable_thread_stack_temporaries (ptid_t ptid
)
770 struct thread_info
*tp
= find_thread_ptid (ptid
);
774 gdb_assert (tp
!= NULL
);
776 tp
->stack_temporaries_enabled
= 1;
777 tp
->stack_temporaries
= NULL
;
778 data
= XNEW (ptid_t
);
780 c
= make_cleanup (disable_thread_stack_temporaries
, data
);
785 /* Return non-zero value if stack temporaies are enabled for the thread
789 thread_stack_temporaries_enabled_p (ptid_t ptid
)
791 struct thread_info
*tp
= find_thread_ptid (ptid
);
796 return tp
->stack_temporaries_enabled
;
799 /* Push V on to the stack temporaries of the thread with id PTID. */
802 push_thread_stack_temporary (ptid_t ptid
, struct value
*v
)
804 struct thread_info
*tp
= find_thread_ptid (ptid
);
806 gdb_assert (tp
!= NULL
&& tp
->stack_temporaries_enabled
);
807 VEC_safe_push (value_ptr
, tp
->stack_temporaries
, v
);
810 /* Return 1 if VAL is among the stack temporaries of the thread
811 with id PTID. Return 0 otherwise. */
814 value_in_thread_stack_temporaries (struct value
*val
, ptid_t ptid
)
816 struct thread_info
*tp
= find_thread_ptid (ptid
);
818 gdb_assert (tp
!= NULL
&& tp
->stack_temporaries_enabled
);
819 if (!VEC_empty (value_ptr
, tp
->stack_temporaries
))
824 for (i
= 0; VEC_iterate (value_ptr
, tp
->stack_temporaries
, i
, v
); i
++)
832 /* Return the last of the stack temporaries for thread with id PTID.
833 Return NULL if there are no stack temporaries for the thread. */
836 get_last_thread_stack_temporary (ptid_t ptid
)
838 struct value
*lastval
= NULL
;
839 struct thread_info
*tp
= find_thread_ptid (ptid
);
841 gdb_assert (tp
!= NULL
);
842 if (!VEC_empty (value_ptr
, tp
->stack_temporaries
))
843 lastval
= VEC_last (value_ptr
, tp
->stack_temporaries
);
849 thread_change_ptid (ptid_t old_ptid
, ptid_t new_ptid
)
851 struct inferior
*inf
;
852 struct thread_info
*tp
;
854 /* It can happen that what we knew as the target inferior id
855 changes. E.g, target remote may only discover the remote process
856 pid after adding the inferior to GDB's list. */
857 inf
= find_inferior_ptid (old_ptid
);
858 inf
->pid
= ptid_get_pid (new_ptid
);
860 tp
= find_thread_ptid (old_ptid
);
863 observer_notify_thread_ptid_changed (old_ptid
, new_ptid
);
866 /* See gdbthread.h. */
869 set_resumed (ptid_t ptid
, int resumed
)
871 struct thread_info
*tp
;
872 int all
= ptid_equal (ptid
, minus_one_ptid
);
874 if (all
|| ptid_is_pid (ptid
))
876 for (tp
= thread_list
; tp
; tp
= tp
->next
)
877 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
878 tp
->resumed
= resumed
;
882 tp
= find_thread_ptid (ptid
);
883 gdb_assert (tp
!= NULL
);
884 tp
->resumed
= resumed
;
888 /* Helper for set_running, that marks one thread either running or
892 set_running_thread (struct thread_info
*tp
, int running
)
896 if (running
&& tp
->state
== THREAD_STOPPED
)
898 tp
->state
= running
? THREAD_RUNNING
: THREAD_STOPPED
;
902 /* If the thread is now marked stopped, remove it from
903 the step-over queue, so that we don't try to resume
904 it until the user wants it to. */
905 if (tp
->step_over_next
!= NULL
)
906 thread_step_over_chain_remove (tp
);
913 set_running (ptid_t ptid
, int running
)
915 struct thread_info
*tp
;
916 int all
= ptid_equal (ptid
, minus_one_ptid
);
919 /* We try not to notify the observer if no thread has actually changed
920 the running state -- merely to reduce the number of messages to
921 frontend. Frontend is supposed to handle multiple *running just fine. */
922 if (all
|| ptid_is_pid (ptid
))
924 for (tp
= thread_list
; tp
; tp
= tp
->next
)
925 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
927 if (tp
->state
== THREAD_EXITED
)
930 if (set_running_thread (tp
, running
))
936 tp
= find_thread_ptid (ptid
);
937 gdb_assert (tp
!= NULL
);
938 gdb_assert (tp
->state
!= THREAD_EXITED
);
939 if (set_running_thread (tp
, running
))
943 observer_notify_target_resumed (ptid
);
947 is_thread_state (ptid_t ptid
, enum thread_state state
)
949 struct thread_info
*tp
;
951 tp
= find_thread_ptid (ptid
);
953 return tp
->state
== state
;
957 is_stopped (ptid_t ptid
)
959 return is_thread_state (ptid
, THREAD_STOPPED
);
963 is_exited (ptid_t ptid
)
965 return is_thread_state (ptid
, THREAD_EXITED
);
969 is_running (ptid_t ptid
)
971 return is_thread_state (ptid
, THREAD_RUNNING
);
975 is_executing (ptid_t ptid
)
977 struct thread_info
*tp
;
979 tp
= find_thread_ptid (ptid
);
981 return tp
->executing
;
985 set_executing (ptid_t ptid
, int executing
)
987 struct thread_info
*tp
;
988 int all
= ptid_equal (ptid
, minus_one_ptid
);
990 if (all
|| ptid_is_pid (ptid
))
992 for (tp
= thread_list
; tp
; tp
= tp
->next
)
993 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
994 tp
->executing
= executing
;
998 tp
= find_thread_ptid (ptid
);
1000 tp
->executing
= executing
;
1003 /* It only takes one running thread to spawn more threads.*/
1005 threads_executing
= 1;
1006 /* Only clear the flag if the caller is telling us everything is
1008 else if (ptid_equal (minus_one_ptid
, ptid
))
1009 threads_executing
= 0;
1012 /* See gdbthread.h. */
1015 threads_are_executing (void)
1017 return threads_executing
;
1021 set_stop_requested (ptid_t ptid
, int stop
)
1023 struct thread_info
*tp
;
1024 int all
= ptid_equal (ptid
, minus_one_ptid
);
1026 if (all
|| ptid_is_pid (ptid
))
1028 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1029 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
1030 tp
->stop_requested
= stop
;
1034 tp
= find_thread_ptid (ptid
);
1036 tp
->stop_requested
= stop
;
1039 /* Call the stop requested observer so other components of GDB can
1040 react to this request. */
1042 observer_notify_thread_stop_requested (ptid
);
1046 finish_thread_state (ptid_t ptid
)
1048 struct thread_info
*tp
;
1050 int any_started
= 0;
1052 all
= ptid_equal (ptid
, minus_one_ptid
);
1054 if (all
|| ptid_is_pid (ptid
))
1056 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1058 if (tp
->state
== THREAD_EXITED
)
1060 if (all
|| ptid_get_pid (ptid
) == ptid_get_pid (tp
->ptid
))
1062 if (set_running_thread (tp
, tp
->executing
))
1069 tp
= find_thread_ptid (ptid
);
1071 if (tp
->state
!= THREAD_EXITED
)
1073 if (set_running_thread (tp
, tp
->executing
))
1079 observer_notify_target_resumed (ptid
);
1083 finish_thread_state_cleanup (void *arg
)
1085 ptid_t
*ptid_p
= arg
;
1089 finish_thread_state (*ptid_p
);
1093 pc_in_thread_step_range (CORE_ADDR pc
, struct thread_info
*thread
)
1095 return (pc
>= thread
->control
.step_range_start
1096 && pc
< thread
->control
.step_range_end
);
1099 /* Prints the list of threads and their details on UIOUT.
1100 This is a version of 'info_threads_command' suitable for
1102 If REQUESTED_THREAD is not -1, it's the GDB id of the thread
1103 that should be printed. Otherwise, all threads are
1105 If PID is not -1, only print threads from the process PID.
1106 Otherwise, threads from all attached PIDs are printed.
1107 If both REQUESTED_THREAD and PID are not -1, then the thread
1108 is printed if it belongs to the specified process. Otherwise,
1109 an error is raised. */
1111 print_thread_info (struct ui_out
*uiout
, char *requested_threads
, int pid
)
1113 struct thread_info
*tp
;
1114 ptid_t current_ptid
;
1115 struct cleanup
*old_chain
;
1116 char *extra_info
, *name
, *target_id
;
1117 int current_thread
= -1;
1119 update_thread_list ();
1120 current_ptid
= inferior_ptid
;
1122 /* We'll be switching threads temporarily. */
1123 old_chain
= make_cleanup_restore_current_thread ();
1125 /* For backward compatibility, we make a list for MI. A table is
1126 preferable for the CLI, though, because it shows table
1128 if (ui_out_is_mi_like_p (uiout
))
1129 make_cleanup_ui_out_list_begin_end (uiout
, "threads");
1134 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1136 if (!number_is_in_list (requested_threads
, tp
->num
))
1139 if (pid
!= -1 && ptid_get_pid (tp
->ptid
) != pid
)
1142 if (tp
->state
== THREAD_EXITED
)
1150 if (requested_threads
== NULL
|| *requested_threads
== '\0')
1151 ui_out_message (uiout
, 0, _("No threads.\n"));
1153 ui_out_message (uiout
, 0, _("No threads match '%s'.\n"),
1155 do_cleanups (old_chain
);
1159 make_cleanup_ui_out_table_begin_end (uiout
, 4, n_threads
, "threads");
1161 ui_out_table_header (uiout
, 1, ui_left
, "current", "");
1162 ui_out_table_header (uiout
, 4, ui_left
, "id", "Id");
1163 ui_out_table_header (uiout
, 17, ui_left
, "target-id", "Target Id");
1164 ui_out_table_header (uiout
, 1, ui_left
, "frame", "Frame");
1165 ui_out_table_body (uiout
);
1168 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1170 struct cleanup
*chain2
;
1173 if (!number_is_in_list (requested_threads
, tp
->num
))
1176 if (pid
!= -1 && ptid_get_pid (tp
->ptid
) != pid
)
1178 if (requested_threads
!= NULL
&& *requested_threads
!= '\0')
1179 error (_("Requested thread not found in requested process"));
1183 if (ptid_equal (tp
->ptid
, current_ptid
))
1184 current_thread
= tp
->num
;
1186 if (tp
->state
== THREAD_EXITED
)
1189 chain2
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
1191 if (ui_out_is_mi_like_p (uiout
))
1193 /* Compatibility. */
1194 if (ptid_equal (tp
->ptid
, current_ptid
))
1195 ui_out_text (uiout
, "* ");
1197 ui_out_text (uiout
, " ");
1201 if (ptid_equal (tp
->ptid
, current_ptid
))
1202 ui_out_field_string (uiout
, "current", "*");
1204 ui_out_field_skip (uiout
, "current");
1207 ui_out_field_int (uiout
, "id", tp
->num
);
1209 /* For the CLI, we stuff everything into the target-id field.
1210 This is a gross hack to make the output come out looking
1211 correct. The underlying problem here is that ui-out has no
1212 way to specify that a field's space allocation should be
1213 shared by several fields. For MI, we do the right thing
1216 target_id
= target_pid_to_str (tp
->ptid
);
1217 extra_info
= target_extra_thread_info (tp
);
1218 name
= tp
->name
? tp
->name
: target_thread_name (tp
);
1220 if (ui_out_is_mi_like_p (uiout
))
1222 ui_out_field_string (uiout
, "target-id", target_id
);
1224 ui_out_field_string (uiout
, "details", extra_info
);
1226 ui_out_field_string (uiout
, "name", name
);
1230 struct cleanup
*str_cleanup
;
1233 if (extra_info
&& name
)
1234 contents
= xstrprintf ("%s \"%s\" (%s)", target_id
,
1236 else if (extra_info
)
1237 contents
= xstrprintf ("%s (%s)", target_id
, extra_info
);
1239 contents
= xstrprintf ("%s \"%s\"", target_id
, name
);
1241 contents
= xstrdup (target_id
);
1242 str_cleanup
= make_cleanup (xfree
, contents
);
1244 ui_out_field_string (uiout
, "target-id", contents
);
1245 do_cleanups (str_cleanup
);
1248 if (tp
->state
== THREAD_RUNNING
)
1249 ui_out_text (uiout
, "(running)\n");
1252 /* The switch below puts us at the top of the stack (leaf
1254 switch_to_thread (tp
->ptid
);
1255 print_stack_frame (get_selected_frame (NULL
),
1256 /* For MI output, print frame level. */
1257 ui_out_is_mi_like_p (uiout
),
1261 if (ui_out_is_mi_like_p (uiout
))
1263 char *state
= "stopped";
1265 if (tp
->state
== THREAD_RUNNING
)
1267 ui_out_field_string (uiout
, "state", state
);
1270 core
= target_core_of_thread (tp
->ptid
);
1271 if (ui_out_is_mi_like_p (uiout
) && core
!= -1)
1272 ui_out_field_int (uiout
, "core", core
);
1274 do_cleanups (chain2
);
1277 /* Restores the current thread and the frame selected before
1278 the "info threads" command. */
1279 do_cleanups (old_chain
);
1281 if (pid
== -1 && requested_threads
== NULL
)
1283 gdb_assert (current_thread
!= -1
1285 || ptid_equal (inferior_ptid
, null_ptid
));
1286 if (current_thread
!= -1 && ui_out_is_mi_like_p (uiout
))
1287 ui_out_field_int (uiout
, "current-thread-id", current_thread
);
1289 if (current_thread
!= -1 && is_exited (current_ptid
))
1290 ui_out_message (uiout
, 0, "\n\
1291 The current thread <Thread ID %d> has terminated. See `help thread'.\n",
1293 else if (thread_list
1294 && current_thread
== -1
1295 && ptid_equal (current_ptid
, null_ptid
))
1296 ui_out_message (uiout
, 0, "\n\
1297 No selected thread. See `help thread'.\n");
1301 /* Print information about currently known threads
1303 Optional ARG is a thread id, or list of thread ids.
1305 Note: this has the drawback that it _really_ switches
1306 threads, which frees the frame cache. A no-side
1307 effects info-threads command would be nicer. */
1310 info_threads_command (char *arg
, int from_tty
)
1312 print_thread_info (current_uiout
, arg
, -1);
1315 /* Switch from one thread to another. */
1318 switch_to_thread (ptid_t ptid
)
1320 /* Switch the program space as well, if we can infer it from the now
1321 current thread. Otherwise, it's up to the caller to select the
1323 if (!ptid_equal (ptid
, null_ptid
))
1325 struct inferior
*inf
;
1327 inf
= find_inferior_ptid (ptid
);
1328 gdb_assert (inf
!= NULL
);
1329 set_current_program_space (inf
->pspace
);
1330 set_current_inferior (inf
);
1333 if (ptid_equal (ptid
, inferior_ptid
))
1336 inferior_ptid
= ptid
;
1337 reinit_frame_cache ();
1339 /* We don't check for is_stopped, because we're called at times
1340 while in the TARGET_RUNNING state, e.g., while handling an
1342 if (!ptid_equal (inferior_ptid
, null_ptid
)
1343 && !is_exited (ptid
)
1344 && !is_executing (ptid
))
1345 stop_pc
= regcache_read_pc (get_thread_regcache (ptid
));
1347 stop_pc
= ~(CORE_ADDR
) 0;
1351 restore_current_thread (ptid_t ptid
)
1353 switch_to_thread (ptid
);
1357 restore_selected_frame (struct frame_id a_frame_id
, int frame_level
)
1359 struct frame_info
*frame
= NULL
;
1362 /* This means there was no selected frame. */
1363 if (frame_level
== -1)
1365 select_frame (NULL
);
1369 gdb_assert (frame_level
>= 0);
1371 /* Restore by level first, check if the frame id is the same as
1372 expected. If that fails, try restoring by frame id. If that
1373 fails, nothing to do, just warn the user. */
1375 count
= frame_level
;
1376 frame
= find_relative_frame (get_current_frame (), &count
);
1379 /* The frame ids must match - either both valid or both outer_frame_id.
1380 The latter case is not failsafe, but since it's highly unlikely
1381 the search by level finds the wrong frame, it's 99.9(9)% of
1382 the time (for all practical purposes) safe. */
1383 && frame_id_eq (get_frame_id (frame
), a_frame_id
))
1385 /* Cool, all is fine. */
1386 select_frame (frame
);
1390 frame
= frame_find_by_id (a_frame_id
);
1393 /* Cool, refound it. */
1394 select_frame (frame
);
1398 /* Nothing else to do, the frame layout really changed. Select the
1399 innermost stack frame. */
1400 select_frame (get_current_frame ());
1402 /* Warn the user. */
1403 if (frame_level
> 0 && !ui_out_is_mi_like_p (current_uiout
))
1405 warning (_("Couldn't restore frame #%d in "
1406 "current thread. Bottom (innermost) frame selected:"),
1408 /* For MI, we should probably have a notification about
1409 current frame change. But this error is not very
1410 likely, so don't bother for now. */
1411 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
1415 /* Data used by the cleanup installed by
1416 'make_cleanup_restore_current_thread'. */
1418 struct current_thread_cleanup
1420 /* Next in list of currently installed 'struct
1421 current_thread_cleanup' cleanups. See
1422 'current_thread_cleanup_chain' below. */
1423 struct current_thread_cleanup
*next
;
1425 ptid_t inferior_ptid
;
1426 struct frame_id selected_frame_id
;
1427 int selected_frame_level
;
1433 /* A chain of currently installed 'struct current_thread_cleanup'
1434 cleanups. Restoring the previously selected thread looks up the
1435 old thread in the thread list by ptid. If the thread changes ptid,
1436 we need to update the cleanup's thread structure so the look up
1438 static struct current_thread_cleanup
*current_thread_cleanup_chain
;
1440 /* A thread_ptid_changed observer. Update all currently installed
1441 current_thread_cleanup cleanups that want to switch back to
1442 OLD_PTID to switch back to NEW_PTID instead. */
1445 restore_current_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1447 struct current_thread_cleanup
*it
;
1449 for (it
= current_thread_cleanup_chain
; it
!= NULL
; it
= it
->next
)
1451 if (ptid_equal (it
->inferior_ptid
, old_ptid
))
1452 it
->inferior_ptid
= new_ptid
;
1457 do_restore_current_thread_cleanup (void *arg
)
1459 struct thread_info
*tp
;
1460 struct current_thread_cleanup
*old
= arg
;
1462 tp
= find_thread_ptid (old
->inferior_ptid
);
1464 /* If the previously selected thread belonged to a process that has
1465 in the mean time been deleted (due to normal exit, detach, etc.),
1466 then don't revert back to it, but instead simply drop back to no
1469 && find_inferior_ptid (tp
->ptid
) != NULL
)
1470 restore_current_thread (old
->inferior_ptid
);
1473 restore_current_thread (null_ptid
);
1474 set_current_inferior (find_inferior_id (old
->inf_id
));
1477 /* The running state of the originally selected thread may have
1478 changed, so we have to recheck it here. */
1479 if (!ptid_equal (inferior_ptid
, null_ptid
)
1481 && is_stopped (inferior_ptid
)
1482 && target_has_registers
1484 && target_has_memory
)
1485 restore_selected_frame (old
->selected_frame_id
,
1486 old
->selected_frame_level
);
1490 restore_current_thread_cleanup_dtor (void *arg
)
1492 struct current_thread_cleanup
*old
= arg
;
1493 struct thread_info
*tp
;
1494 struct inferior
*inf
;
1496 current_thread_cleanup_chain
= current_thread_cleanup_chain
->next
;
1498 tp
= find_thread_ptid (old
->inferior_ptid
);
1501 inf
= find_inferior_id (old
->inf_id
);
1503 inf
->removable
= old
->was_removable
;
1507 /* Set the thread reference count. */
1510 set_thread_refcount (void *data
)
1513 struct thread_array_cleanup
*ta_cleanup
= data
;
1515 for (k
= 0; k
!= ta_cleanup
->count
; k
++)
1516 ta_cleanup
->tp_array
[k
]->refcount
--;
1520 make_cleanup_restore_current_thread (void)
1522 struct thread_info
*tp
;
1523 struct frame_info
*frame
;
1524 struct current_thread_cleanup
*old
= XNEW (struct current_thread_cleanup
);
1526 old
->inferior_ptid
= inferior_ptid
;
1527 old
->inf_id
= current_inferior ()->num
;
1528 old
->was_removable
= current_inferior ()->removable
;
1530 old
->next
= current_thread_cleanup_chain
;
1531 current_thread_cleanup_chain
= old
;
1533 if (!ptid_equal (inferior_ptid
, null_ptid
))
1535 old
->was_stopped
= is_stopped (inferior_ptid
);
1536 if (old
->was_stopped
1537 && target_has_registers
1539 && target_has_memory
)
1541 /* When processing internal events, there might not be a
1542 selected frame. If we naively call get_selected_frame
1543 here, then we can end up reading debuginfo for the
1544 current frame, but we don't generally need the debuginfo
1546 frame
= get_selected_frame_if_set ();
1551 old
->selected_frame_id
= get_frame_id (frame
);
1552 old
->selected_frame_level
= frame_relative_level (frame
);
1554 tp
= find_thread_ptid (inferior_ptid
);
1559 current_inferior ()->removable
= 0;
1561 return make_cleanup_dtor (do_restore_current_thread_cleanup
, old
,
1562 restore_current_thread_cleanup_dtor
);
1565 /* If non-zero tp_array_compar should sort in ascending order, otherwise in
1566 descending order. */
1568 static int tp_array_compar_ascending
;
1570 /* Sort an array for struct thread_info pointers by their NUM, order is
1571 determined by TP_ARRAY_COMPAR_ASCENDING. */
1574 tp_array_compar (const void *ap_voidp
, const void *bp_voidp
)
1576 const struct thread_info
*const *ap
= ap_voidp
;
1577 const struct thread_info
*const *bp
= bp_voidp
;
1579 return ((((*ap
)->num
> (*bp
)->num
) - ((*ap
)->num
< (*bp
)->num
))
1580 * (tp_array_compar_ascending
? +1 : -1));
1583 /* Apply a GDB command to a list of threads. List syntax is a whitespace
1584 seperated list of numbers, or ranges, or the keyword `all'. Ranges consist
1585 of two numbers seperated by a hyphen. Examples:
1587 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
1588 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
1589 thread apply all p x/i $pc Apply x/i $pc cmd to all threads. */
1592 thread_apply_all_command (char *cmd
, int from_tty
)
1594 struct cleanup
*old_chain
;
1597 struct thread_array_cleanup ta_cleanup
;
1599 tp_array_compar_ascending
= 0;
1601 && check_for_argument (&cmd
, "-ascending", strlen ("-ascending")))
1603 cmd
= skip_spaces (cmd
);
1604 tp_array_compar_ascending
= 1;
1607 if (cmd
== NULL
|| *cmd
== '\000')
1608 error (_("Please specify a command following the thread ID list"));
1610 update_thread_list ();
1612 old_chain
= make_cleanup_restore_current_thread ();
1614 /* Save a copy of the command in case it is clobbered by
1616 saved_cmd
= xstrdup (cmd
);
1617 make_cleanup (xfree
, saved_cmd
);
1619 /* Note this includes exited threads. */
1620 tc
= thread_count ();
1623 struct thread_info
**tp_array
;
1624 struct thread_info
*tp
;
1627 /* Save a copy of the thread_list in case we execute detach
1629 tp_array
= XNEWVEC (struct thread_info
*, tc
);
1630 make_cleanup (xfree
, tp_array
);
1632 ALL_NON_EXITED_THREADS (tp
)
1638 /* Because we skipped exited threads, we may end up with fewer
1639 threads in the array than the total count of threads. */
1640 gdb_assert (i
<= tc
);
1643 qsort (tp_array
, i
, sizeof (*tp_array
), tp_array_compar
);
1645 ta_cleanup
.tp_array
= tp_array
;
1646 ta_cleanup
.count
= i
;
1647 make_cleanup (set_thread_refcount
, &ta_cleanup
);
1649 for (k
= 0; k
!= i
; k
++)
1650 if (thread_alive (tp_array
[k
]))
1652 switch_to_thread (tp_array
[k
]->ptid
);
1653 printf_filtered (_("\nThread %d (%s):\n"),
1655 target_pid_to_str (inferior_ptid
));
1656 execute_command (cmd
, from_tty
);
1658 /* Restore exact command used previously. */
1659 strcpy (cmd
, saved_cmd
);
1663 do_cleanups (old_chain
);
1667 thread_apply_command (char *tidlist
, int from_tty
)
1670 struct cleanup
*old_chain
;
1672 struct get_number_or_range_state state
;
1674 if (tidlist
== NULL
|| *tidlist
== '\000')
1675 error (_("Please specify a thread ID list"));
1677 for (cmd
= tidlist
; *cmd
!= '\000' && !isalpha (*cmd
); cmd
++);
1680 error (_("Please specify a command following the thread ID list"));
1682 /* Save a copy of the command in case it is clobbered by
1684 saved_cmd
= xstrdup (cmd
);
1685 old_chain
= make_cleanup (xfree
, saved_cmd
);
1687 init_number_or_range (&state
, tidlist
);
1688 while (!state
.finished
&& state
.string
< cmd
)
1690 struct thread_info
*tp
;
1693 start
= get_number_or_range (&state
);
1695 make_cleanup_restore_current_thread ();
1697 tp
= find_thread_id (start
);
1700 warning (_("Unknown thread %d."), start
);
1701 else if (!thread_alive (tp
))
1702 warning (_("Thread %d has terminated."), start
);
1705 switch_to_thread (tp
->ptid
);
1707 printf_filtered (_("\nThread %d (%s):\n"), tp
->num
,
1708 target_pid_to_str (inferior_ptid
));
1709 execute_command (cmd
, from_tty
);
1711 /* Restore exact command used previously. */
1712 strcpy (cmd
, saved_cmd
);
1716 do_cleanups (old_chain
);
1719 /* Switch to the specified thread. Will dispatch off to thread_apply_command
1720 if prefix of arg is `apply'. */
1723 thread_command (char *tidstr
, int from_tty
)
1727 if (ptid_equal (inferior_ptid
, null_ptid
))
1728 error (_("No thread selected"));
1730 if (target_has_stack
)
1732 if (is_exited (inferior_ptid
))
1733 printf_filtered (_("[Current thread is %d (%s) (exited)]\n"),
1734 pid_to_thread_id (inferior_ptid
),
1735 target_pid_to_str (inferior_ptid
));
1737 printf_filtered (_("[Current thread is %d (%s)]\n"),
1738 pid_to_thread_id (inferior_ptid
),
1739 target_pid_to_str (inferior_ptid
));
1742 error (_("No stack."));
1746 gdb_thread_select (current_uiout
, tidstr
, NULL
);
1749 /* Implementation of `thread name'. */
1752 thread_name_command (char *arg
, int from_tty
)
1754 struct thread_info
*info
;
1756 if (ptid_equal (inferior_ptid
, null_ptid
))
1757 error (_("No thread selected"));
1759 arg
= skip_spaces (arg
);
1761 info
= inferior_thread ();
1763 info
->name
= arg
? xstrdup (arg
) : NULL
;
1766 /* Find thread ids with a name, target pid, or extra info matching ARG. */
1769 thread_find_command (char *arg
, int from_tty
)
1771 struct thread_info
*tp
;
1773 unsigned long match
= 0;
1775 if (arg
== NULL
|| *arg
== '\0')
1776 error (_("Command requires an argument."));
1778 tmp
= re_comp (arg
);
1780 error (_("Invalid regexp (%s): %s"), tmp
, arg
);
1782 update_thread_list ();
1783 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1785 if (tp
->name
!= NULL
&& re_exec (tp
->name
))
1787 printf_filtered (_("Thread %d has name '%s'\n"),
1792 tmp
= target_thread_name (tp
);
1793 if (tmp
!= NULL
&& re_exec (tmp
))
1795 printf_filtered (_("Thread %d has target name '%s'\n"),
1800 tmp
= target_pid_to_str (tp
->ptid
);
1801 if (tmp
!= NULL
&& re_exec (tmp
))
1803 printf_filtered (_("Thread %d has target id '%s'\n"),
1808 tmp
= target_extra_thread_info (tp
);
1809 if (tmp
!= NULL
&& re_exec (tmp
))
1811 printf_filtered (_("Thread %d has extra info '%s'\n"),
1817 printf_filtered (_("No threads match '%s'\n"), arg
);
1820 /* Print notices when new threads are attached and detached. */
1821 int print_thread_events
= 1;
1823 show_print_thread_events (struct ui_file
*file
, int from_tty
,
1824 struct cmd_list_element
*c
, const char *value
)
1826 fprintf_filtered (file
,
1827 _("Printing of thread events is %s.\n"),
1832 do_captured_thread_select (struct ui_out
*uiout
, void *tidstr
)
1835 struct thread_info
*tp
;
1837 num
= value_as_long (parse_and_eval (tidstr
));
1839 tp
= find_thread_id (num
);
1842 error (_("Thread ID %d not known."), num
);
1844 if (!thread_alive (tp
))
1845 error (_("Thread ID %d has terminated."), num
);
1847 switch_to_thread (tp
->ptid
);
1849 annotate_thread_changed ();
1851 ui_out_text (uiout
, "[Switching to thread ");
1852 ui_out_field_int (uiout
, "new-thread-id", pid_to_thread_id (inferior_ptid
));
1853 ui_out_text (uiout
, " (");
1854 ui_out_text (uiout
, target_pid_to_str (inferior_ptid
));
1855 ui_out_text (uiout
, ")]");
1857 /* Note that we can't reach this with an exited thread, due to the
1858 thread_alive check above. */
1859 if (tp
->state
== THREAD_RUNNING
)
1860 ui_out_text (uiout
, "(running)\n");
1863 ui_out_text (uiout
, "\n");
1864 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
1867 /* Since the current thread may have changed, see if there is any
1868 exited thread we can now delete. */
1875 gdb_thread_select (struct ui_out
*uiout
, char *tidstr
, char **error_message
)
1877 if (catch_exceptions_with_msg (uiout
, do_captured_thread_select
, tidstr
,
1878 error_message
, RETURN_MASK_ALL
) < 0)
1883 /* Update the 'threads_executing' global based on the threads we know
1887 update_threads_executing (void)
1889 struct thread_info
*tp
;
1891 threads_executing
= 0;
1892 ALL_NON_EXITED_THREADS (tp
)
1896 threads_executing
= 1;
1903 update_thread_list (void)
1905 target_update_thread_list ();
1906 update_threads_executing ();
1909 /* Return a new value for the selected thread's id. Return a value of 0 if
1910 no thread is selected, or no threads exist. */
1912 static struct value
*
1913 thread_id_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
1916 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
1918 return value_from_longest (builtin_type (gdbarch
)->builtin_int
,
1919 (tp
? tp
->num
: 0));
1922 /* Commands with a prefix of `thread'. */
1923 struct cmd_list_element
*thread_cmd_list
= NULL
;
1925 /* Implementation of `thread' variable. */
1927 static const struct internalvar_funcs thread_funcs
=
1929 thread_id_make_value
,
1935 _initialize_thread (void)
1937 static struct cmd_list_element
*thread_apply_list
= NULL
;
1939 add_info ("threads", info_threads_command
,
1940 _("Display currently known threads.\n\
1941 Usage: info threads [ID]...\n\
1942 Optional arguments are thread IDs with spaces between.\n\
1943 If no arguments, all threads are displayed."));
1945 add_prefix_cmd ("thread", class_run
, thread_command
, _("\
1946 Use this command to switch between threads.\n\
1947 The new thread ID must be currently known."),
1948 &thread_cmd_list
, "thread ", 1, &cmdlist
);
1950 add_prefix_cmd ("apply", class_run
, thread_apply_command
,
1951 _("Apply a command to a list of threads."),
1952 &thread_apply_list
, "thread apply ", 1, &thread_cmd_list
);
1954 add_cmd ("all", class_run
, thread_apply_all_command
,
1956 Apply a command to all threads.\n\
1958 Usage: thread apply all [-ascending] <command>\n\
1959 -ascending: Call <command> for all threads in ascending order.\n\
1960 The default is descending order.\
1962 &thread_apply_list
);
1964 add_cmd ("name", class_run
, thread_name_command
,
1965 _("Set the current thread's name.\n\
1966 Usage: thread name [NAME]\n\
1967 If NAME is not given, then any existing name is removed."), &thread_cmd_list
);
1969 add_cmd ("find", class_run
, thread_find_command
, _("\
1970 Find threads that match a regular expression.\n\
1971 Usage: thread find REGEXP\n\
1972 Will display thread ids whose name, target ID, or extra info matches REGEXP."),
1975 add_com_alias ("t", "thread", class_run
, 1);
1977 add_setshow_boolean_cmd ("thread-events", no_class
,
1978 &print_thread_events
, _("\
1979 Set printing of thread events (such as thread start and exit)."), _("\
1980 Show printing of thread events (such as thread start and exit)."), NULL
,
1982 show_print_thread_events
,
1983 &setprintlist
, &showprintlist
);
1985 create_internalvar_type_lazy ("_thread", &thread_funcs
, NULL
);
1987 observer_attach_thread_ptid_changed (restore_current_thread_ptid_changed
);