1 /* Multi-process/thread control for GDB, the GNU debugger.
3 Copyright (C) 1986-2018 Free Software Foundation, Inc.
5 Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 #include "gdbthread.h"
36 #include <sys/types.h>
39 #include "observable.h"
41 #include "cli/cli-decode.h"
42 #include "gdb_regex.h"
43 #include "cli/cli-utils.h"
44 #include "thread-fsm.h"
45 #include "tid-parse.h"
47 #include "common/gdb_optional.h"
49 /* Definition of struct thread_info exported to gdbthread.h. */
51 /* Prototypes for local functions. */
53 struct thread_info
*thread_list
= NULL
;
54 static int highest_thread_num
;
56 /* True if any thread is, or may be executing. We need to track this
57 separately because until we fully sync the thread list, we won't
58 know whether the target is fully stopped, even if we see stop
59 events for all known threads, because any of those threads may have
60 spawned new threads we haven't heard of yet. */
61 static int threads_executing
;
63 static int thread_alive (struct thread_info
*);
65 /* RAII type used to increase / decrease the refcount of each thread
66 in a given list of threads. */
68 class scoped_inc_dec_ref
71 explicit scoped_inc_dec_ref (const std::vector
<thread_info
*> &thrds
)
74 for (thread_info
*thr
: m_thrds
)
78 ~scoped_inc_dec_ref ()
80 for (thread_info
*thr
: m_thrds
)
85 const std::vector
<thread_info
*> &m_thrds
;
90 inferior_thread (void)
92 struct thread_info
*tp
= find_thread_ptid (inferior_ptid
);
97 /* Delete the breakpoint pointed at by BP_P, if there's one. */
100 delete_thread_breakpoint (struct breakpoint
**bp_p
)
104 delete_breakpoint (*bp_p
);
110 delete_step_resume_breakpoint (struct thread_info
*tp
)
113 delete_thread_breakpoint (&tp
->control
.step_resume_breakpoint
);
117 delete_exception_resume_breakpoint (struct thread_info
*tp
)
120 delete_thread_breakpoint (&tp
->control
.exception_resume_breakpoint
);
123 /* See gdbthread.h. */
126 delete_single_step_breakpoints (struct thread_info
*tp
)
129 delete_thread_breakpoint (&tp
->control
.single_step_breakpoints
);
132 /* Delete the breakpoint pointed at by BP_P at the next stop, if
136 delete_at_next_stop (struct breakpoint
**bp
)
140 (*bp
)->disposition
= disp_del_at_next_stop
;
145 /* See gdbthread.h. */
148 thread_has_single_step_breakpoints_set (struct thread_info
*tp
)
150 return tp
->control
.single_step_breakpoints
!= NULL
;
153 /* See gdbthread.h. */
156 thread_has_single_step_breakpoint_here (struct thread_info
*tp
,
157 const address_space
*aspace
,
160 struct breakpoint
*ss_bps
= tp
->control
.single_step_breakpoints
;
162 return (ss_bps
!= NULL
163 && breakpoint_has_location_inserted_here (ss_bps
, aspace
, addr
));
166 /* See gdbthread.h. */
169 thread_cancel_execution_command (struct thread_info
*thr
)
171 if (thr
->thread_fsm
!= NULL
)
173 thread_fsm_clean_up (thr
->thread_fsm
, thr
);
174 thread_fsm_delete (thr
->thread_fsm
);
175 thr
->thread_fsm
= NULL
;
180 clear_thread_inferior_resources (struct thread_info
*tp
)
182 /* NOTE: this will take care of any left-over step_resume breakpoints,
183 but not any user-specified thread-specific breakpoints. We can not
184 delete the breakpoint straight-off, because the inferior might not
185 be stopped at the moment. */
186 delete_at_next_stop (&tp
->control
.step_resume_breakpoint
);
187 delete_at_next_stop (&tp
->control
.exception_resume_breakpoint
);
188 delete_at_next_stop (&tp
->control
.single_step_breakpoints
);
190 delete_longjmp_breakpoint_at_next_stop (tp
->global_num
);
192 bpstat_clear (&tp
->control
.stop_bpstat
);
194 btrace_teardown (tp
);
196 thread_cancel_execution_command (tp
);
199 /* Set the TP's state as exited. */
202 set_thread_exited (thread_info
*tp
, int silent
)
204 /* Dead threads don't need to step-over. Remove from queue. */
205 if (tp
->step_over_next
!= NULL
)
206 thread_step_over_chain_remove (tp
);
208 if (tp
->state
!= THREAD_EXITED
)
210 gdb::observers::thread_exit
.notify (tp
, silent
);
212 /* Tag it as exited. */
213 tp
->state
= THREAD_EXITED
;
215 /* Clear breakpoints, etc. associated with this thread. */
216 clear_thread_inferior_resources (tp
);
221 init_thread_list (void)
223 struct thread_info
*tp
, *tmp
;
225 highest_thread_num
= 0;
227 ALL_THREADS_SAFE (tp
, tmp
)
229 if (tp
->deletable ())
232 set_thread_exited (tp
, 1);
236 threads_executing
= 0;
239 /* Allocate a new thread of inferior INF with target id PTID and add
240 it to the thread list. */
242 static struct thread_info
*
243 new_thread (struct inferior
*inf
, ptid_t ptid
)
245 thread_info
*tp
= new thread_info (inf
, ptid
);
247 if (thread_list
== NULL
)
251 struct thread_info
*last
;
253 for (last
= thread_list
; last
->next
!= NULL
; last
= last
->next
)
262 add_thread_silent (ptid_t ptid
)
264 struct thread_info
*tp
;
265 struct inferior
*inf
= find_inferior_ptid (ptid
);
266 gdb_assert (inf
!= NULL
);
268 tp
= find_thread_ptid (ptid
);
270 /* Found an old thread with the same id. It has to be dead,
271 otherwise we wouldn't be adding a new thread with the same id.
272 The OS is reusing this id --- delete it, and recreate a new
275 /* In addition to deleting the thread, if this is the current
276 thread, then we need to take care that delete_thread doesn't
277 really delete the thread if it is inferior_ptid. Create a
278 new template thread in the list with an invalid ptid, switch
279 to it, delete the original thread, reset the new thread's
280 ptid, and switch to it. */
282 if (inferior_ptid
== ptid
)
284 thread_info
*new_thr
= new_thread (inf
, null_ptid
);
286 /* Make switch_to_thread not read from the thread. */
287 new_thr
->state
= THREAD_EXITED
;
288 switch_to_no_thread ();
290 /* Now we can delete it. */
293 /* Now reset its ptid, and reswitch inferior_ptid to it. */
294 new_thr
->ptid
= ptid
;
295 new_thr
->state
= THREAD_STOPPED
;
296 switch_to_thread (new_thr
);
298 gdb::observers::new_thread
.notify (new_thr
);
304 /* Just go ahead and delete it. */
308 tp
= new_thread (inf
, ptid
);
309 gdb::observers::new_thread
.notify (tp
);
315 add_thread_with_info (ptid_t ptid
, private_thread_info
*priv
)
317 struct thread_info
*result
= add_thread_silent (ptid
);
319 result
->priv
.reset (priv
);
321 if (print_thread_events
)
322 printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid
));
324 annotate_new_thread ();
329 add_thread (ptid_t ptid
)
331 return add_thread_with_info (ptid
, NULL
);
334 private_thread_info::~private_thread_info () = default;
336 thread_info::thread_info (struct inferior
*inf_
, ptid_t ptid_
)
337 : ptid (ptid_
), inf (inf_
)
339 gdb_assert (inf_
!= NULL
);
341 this->global_num
= ++highest_thread_num
;
342 this->per_inf_num
= ++inf_
->highest_thread_num
;
344 /* Nothing to follow yet. */
345 memset (&this->pending_follow
, 0, sizeof (this->pending_follow
));
346 this->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
347 this->suspend
.waitstatus
.kind
= TARGET_WAITKIND_IGNORE
;
350 thread_info::~thread_info ()
355 /* Add TP to the end of the step-over chain LIST_P. */
358 step_over_chain_enqueue (struct thread_info
**list_p
, struct thread_info
*tp
)
360 gdb_assert (tp
->step_over_next
== NULL
);
361 gdb_assert (tp
->step_over_prev
== NULL
);
366 tp
->step_over_prev
= tp
->step_over_next
= tp
;
370 struct thread_info
*head
= *list_p
;
371 struct thread_info
*tail
= head
->step_over_prev
;
373 tp
->step_over_prev
= tail
;
374 tp
->step_over_next
= head
;
375 head
->step_over_prev
= tp
;
376 tail
->step_over_next
= tp
;
380 /* Remove TP from step-over chain LIST_P. */
383 step_over_chain_remove (struct thread_info
**list_p
, struct thread_info
*tp
)
385 gdb_assert (tp
->step_over_next
!= NULL
);
386 gdb_assert (tp
->step_over_prev
!= NULL
);
390 if (tp
== tp
->step_over_next
)
393 *list_p
= tp
->step_over_next
;
396 tp
->step_over_prev
->step_over_next
= tp
->step_over_next
;
397 tp
->step_over_next
->step_over_prev
= tp
->step_over_prev
;
398 tp
->step_over_prev
= tp
->step_over_next
= NULL
;
401 /* See gdbthread.h. */
404 thread_step_over_chain_next (struct thread_info
*tp
)
406 struct thread_info
*next
= tp
->step_over_next
;
408 return (next
== step_over_queue_head
? NULL
: next
);
411 /* See gdbthread.h. */
414 thread_is_in_step_over_chain (struct thread_info
*tp
)
416 return (tp
->step_over_next
!= NULL
);
419 /* See gdbthread.h. */
422 thread_step_over_chain_enqueue (struct thread_info
*tp
)
424 step_over_chain_enqueue (&step_over_queue_head
, tp
);
427 /* See gdbthread.h. */
430 thread_step_over_chain_remove (struct thread_info
*tp
)
432 step_over_chain_remove (&step_over_queue_head
, tp
);
435 /* Delete thread TP. If SILENT, don't notify the observer of this
439 delete_thread_1 (thread_info
*thr
, bool silent
)
441 struct thread_info
*tp
, *tpprev
;
445 for (tp
= thread_list
; tp
; tpprev
= tp
, tp
= tp
->next
)
452 set_thread_exited (tp
, silent
);
454 if (!tp
->deletable ())
456 /* Will be really deleted some other time. */
461 tpprev
->next
= tp
->next
;
463 thread_list
= tp
->next
;
468 /* Delete thread THREAD and notify of thread exit. If this is the
469 current thread, don't actually delete it, but tag it as exited and
470 do the notification. If this is the user selected thread, clear
474 delete_thread (thread_info
*thread
)
476 delete_thread_1 (thread
, false /* not silent */);
480 delete_thread_silent (thread_info
*thread
)
482 delete_thread_1 (thread
, true /* silent */);
486 find_thread_global_id (int global_id
)
488 struct thread_info
*tp
;
490 for (tp
= thread_list
; tp
; tp
= tp
->next
)
491 if (tp
->global_num
== global_id
)
497 static struct thread_info
*
498 find_thread_id (struct inferior
*inf
, int thr_num
)
500 struct thread_info
*tp
;
502 for (tp
= thread_list
; tp
; tp
= tp
->next
)
503 if (tp
->inf
== inf
&& tp
->per_inf_num
== thr_num
)
509 /* Find a thread_info by matching PTID. */
512 find_thread_ptid (ptid_t ptid
)
514 struct thread_info
*tp
;
516 for (tp
= thread_list
; tp
; tp
= tp
->next
)
517 if (tp
->ptid
== ptid
)
523 /* See gdbthread.h. */
526 find_thread_by_handle (struct value
*thread_handle
, struct inferior
*inf
)
528 return target_thread_handle_to_thread_info
529 (value_contents_all (thread_handle
),
530 TYPE_LENGTH (value_type (thread_handle
)),
535 * Thread iterator function.
537 * Calls a callback function once for each thread, so long as
538 * the callback function returns false. If the callback function
539 * returns true, the iteration will end and the current thread
540 * will be returned. This can be useful for implementing a
541 * search for a thread with arbitrary attributes, or for applying
542 * some operation to every thread.
544 * FIXME: some of the existing functionality, such as
545 * "Thread apply all", might be rewritten using this functionality.
549 iterate_over_threads (int (*callback
) (struct thread_info
*, void *),
552 struct thread_info
*tp
, *next
;
554 for (tp
= thread_list
; tp
; tp
= next
)
557 if ((*callback
) (tp
, data
))
568 struct thread_info
*tp
;
570 for (tp
= thread_list
; tp
; tp
= tp
->next
)
576 /* Return the number of non-exited threads in the thread list. */
579 live_threads_count (void)
582 struct thread_info
*tp
;
584 ALL_NON_EXITED_THREADS (tp
)
591 valid_global_thread_id (int global_id
)
593 struct thread_info
*tp
;
595 for (tp
= thread_list
; tp
; tp
= tp
->next
)
596 if (tp
->global_num
== global_id
)
603 in_thread_list (ptid_t ptid
)
605 struct thread_info
*tp
;
607 for (tp
= thread_list
; tp
; tp
= tp
->next
)
608 if (tp
->ptid
== ptid
)
611 return 0; /* Never heard of 'im. */
614 /* Finds the first thread of the inferior. */
617 first_thread_of_inferior (inferior
*inf
)
619 struct thread_info
*tp
, *ret
= NULL
;
621 for (tp
= thread_list
; tp
; tp
= tp
->next
)
623 if (ret
== NULL
|| tp
->global_num
< ret
->global_num
)
630 any_thread_of_inferior (inferior
*inf
)
632 struct thread_info
*tp
;
634 gdb_assert (inf
->pid
!= 0);
636 /* Prefer the current thread. */
637 if (inf
== current_inferior ())
638 return inferior_thread ();
640 ALL_NON_EXITED_THREADS (tp
)
648 any_live_thread_of_inferior (inferior
*inf
)
650 struct thread_info
*curr_tp
= NULL
;
651 struct thread_info
*tp
;
652 struct thread_info
*tp_executing
= NULL
;
654 gdb_assert (inf
!= NULL
&& inf
->pid
!= 0);
656 /* Prefer the current thread if it's not executing. */
657 if (inferior_ptid
!= null_ptid
&& current_inferior () == inf
)
659 /* If the current thread is dead, forget it. If it's not
660 executing, use it. Otherwise, still choose it (below), but
661 only if no other non-executing thread is found. */
662 curr_tp
= inferior_thread ();
663 if (curr_tp
->state
== THREAD_EXITED
)
665 else if (!curr_tp
->executing
)
669 ALL_NON_EXITED_THREADS (tp
)
678 /* If both the current thread and all live threads are executing,
679 prefer the current thread. */
683 /* Otherwise, just return an executing thread, if any. */
687 /* Return true if TP is an active thread. */
689 thread_alive (struct thread_info
*tp
)
691 if (tp
->state
== THREAD_EXITED
)
693 if (!target_thread_alive (tp
->ptid
))
698 /* See gdbthreads.h. */
703 struct thread_info
*tp
, *tmp
;
705 ALL_THREADS_SAFE (tp
, tmp
)
707 if (!thread_alive (tp
))
712 /* See gdbthreads.h. */
715 delete_exited_threads (void)
717 struct thread_info
*tp
, *tmp
;
719 ALL_THREADS_SAFE (tp
, tmp
)
721 if (tp
->state
== THREAD_EXITED
)
726 /* Return true value if stack temporaies are enabled for the thread
730 thread_stack_temporaries_enabled_p (thread_info
*tp
)
735 return tp
->stack_temporaries_enabled
;
738 /* Push V on to the stack temporaries of the thread with id PTID. */
741 push_thread_stack_temporary (thread_info
*tp
, struct value
*v
)
743 gdb_assert (tp
!= NULL
&& tp
->stack_temporaries_enabled
);
744 tp
->stack_temporaries
.push_back (v
);
747 /* Return true if VAL is among the stack temporaries of the thread
748 TP. Return false otherwise. */
751 value_in_thread_stack_temporaries (struct value
*val
, thread_info
*tp
)
753 gdb_assert (tp
!= NULL
&& tp
->stack_temporaries_enabled
);
754 for (value
*v
: tp
->stack_temporaries
)
761 /* Return the last of the stack temporaries for thread with id PTID.
762 Return NULL if there are no stack temporaries for the thread. */
765 get_last_thread_stack_temporary (thread_info
*tp
)
767 struct value
*lastval
= NULL
;
769 gdb_assert (tp
!= NULL
);
770 if (!tp
->stack_temporaries
.empty ())
771 lastval
= tp
->stack_temporaries
.back ();
777 thread_change_ptid (ptid_t old_ptid
, ptid_t new_ptid
)
779 struct inferior
*inf
;
780 struct thread_info
*tp
;
782 /* It can happen that what we knew as the target inferior id
783 changes. E.g, target remote may only discover the remote process
784 pid after adding the inferior to GDB's list. */
785 inf
= find_inferior_ptid (old_ptid
);
786 inf
->pid
= ptid_get_pid (new_ptid
);
788 tp
= find_thread_ptid (old_ptid
);
791 gdb::observers::thread_ptid_changed
.notify (old_ptid
, new_ptid
);
794 /* See gdbthread.h. */
797 set_resumed (ptid_t ptid
, int resumed
)
799 struct thread_info
*tp
;
800 int all
= ptid
== minus_one_ptid
;
802 if (all
|| ptid_is_pid (ptid
))
804 for (tp
= thread_list
; tp
; tp
= tp
->next
)
805 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
806 tp
->resumed
= resumed
;
810 tp
= find_thread_ptid (ptid
);
811 gdb_assert (tp
!= NULL
);
812 tp
->resumed
= resumed
;
816 /* Helper for set_running, that marks one thread either running or
820 set_running_thread (struct thread_info
*tp
, int running
)
824 if (running
&& tp
->state
== THREAD_STOPPED
)
826 tp
->state
= running
? THREAD_RUNNING
: THREAD_STOPPED
;
830 /* If the thread is now marked stopped, remove it from
831 the step-over queue, so that we don't try to resume
832 it until the user wants it to. */
833 if (tp
->step_over_next
!= NULL
)
834 thread_step_over_chain_remove (tp
);
840 /* See gdbthread.h. */
843 thread_info::set_running (bool running
)
845 if (set_running_thread (this, running
))
846 gdb::observers::target_resumed
.notify (this->ptid
);
850 set_running (ptid_t ptid
, int running
)
852 struct thread_info
*tp
;
853 int all
= ptid
== minus_one_ptid
;
856 /* We try not to notify the observer if no thread has actually changed
857 the running state -- merely to reduce the number of messages to
858 frontend. Frontend is supposed to handle multiple *running just fine. */
859 if (all
|| ptid_is_pid (ptid
))
861 for (tp
= thread_list
; tp
; tp
= tp
->next
)
862 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
864 if (tp
->state
== THREAD_EXITED
)
867 if (set_running_thread (tp
, running
))
873 tp
= find_thread_ptid (ptid
);
874 gdb_assert (tp
!= NULL
);
875 gdb_assert (tp
->state
!= THREAD_EXITED
);
876 if (set_running_thread (tp
, running
))
880 gdb::observers::target_resumed
.notify (ptid
);
884 is_thread_state (ptid_t ptid
, enum thread_state state
)
886 struct thread_info
*tp
;
888 tp
= find_thread_ptid (ptid
);
890 return tp
->state
== state
;
894 is_stopped (ptid_t ptid
)
896 return is_thread_state (ptid
, THREAD_STOPPED
);
900 is_exited (ptid_t ptid
)
902 return is_thread_state (ptid
, THREAD_EXITED
);
906 is_running (ptid_t ptid
)
908 return is_thread_state (ptid
, THREAD_RUNNING
);
912 is_executing (ptid_t ptid
)
914 struct thread_info
*tp
;
916 tp
= find_thread_ptid (ptid
);
918 return tp
->executing
;
922 set_executing (ptid_t ptid
, int executing
)
924 struct thread_info
*tp
;
925 int all
= ptid
== minus_one_ptid
;
927 if (all
|| ptid_is_pid (ptid
))
929 for (tp
= thread_list
; tp
; tp
= tp
->next
)
930 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
931 tp
->executing
= executing
;
935 tp
= find_thread_ptid (ptid
);
937 tp
->executing
= executing
;
940 /* It only takes one running thread to spawn more threads.*/
942 threads_executing
= 1;
943 /* Only clear the flag if the caller is telling us everything is
945 else if (minus_one_ptid
== ptid
)
946 threads_executing
= 0;
949 /* See gdbthread.h. */
952 threads_are_executing (void)
954 return threads_executing
;
958 set_stop_requested (ptid_t ptid
, int stop
)
960 struct thread_info
*tp
;
961 int all
= ptid
== minus_one_ptid
;
963 if (all
|| ptid_is_pid (ptid
))
965 for (tp
= thread_list
; tp
; tp
= tp
->next
)
966 if (all
|| ptid_get_pid (tp
->ptid
) == ptid_get_pid (ptid
))
967 tp
->stop_requested
= stop
;
971 tp
= find_thread_ptid (ptid
);
973 tp
->stop_requested
= stop
;
976 /* Call the stop requested observer so other components of GDB can
977 react to this request. */
979 gdb::observers::thread_stop_requested
.notify (ptid
);
983 finish_thread_state (ptid_t ptid
)
985 struct thread_info
*tp
;
989 all
= ptid
== minus_one_ptid
;
991 if (all
|| ptid_is_pid (ptid
))
993 for (tp
= thread_list
; tp
; tp
= tp
->next
)
995 if (tp
->state
== THREAD_EXITED
)
997 if (all
|| ptid_get_pid (ptid
) == ptid_get_pid (tp
->ptid
))
999 if (set_running_thread (tp
, tp
->executing
))
1006 tp
= find_thread_ptid (ptid
);
1008 if (tp
->state
!= THREAD_EXITED
)
1010 if (set_running_thread (tp
, tp
->executing
))
1016 gdb::observers::target_resumed
.notify (ptid
);
1019 /* See gdbthread.h. */
1022 validate_registers_access (void)
1024 /* No selected thread, no registers. */
1025 if (inferior_ptid
== null_ptid
)
1026 error (_("No thread selected."));
1028 thread_info
*tp
= inferior_thread ();
1030 /* Don't try to read from a dead thread. */
1031 if (tp
->state
== THREAD_EXITED
)
1032 error (_("The current thread has terminated"));
1034 /* ... or from a spinning thread. FIXME: This isn't actually fully
1035 correct. It'll allow an user-requested access (e.g., "print $pc"
1036 at the prompt) when a thread is not executing for some internal
1037 reason, but is marked running from the user's perspective. E.g.,
1038 the thread is waiting for its turn in the step-over queue. */
1040 error (_("Selected thread is running."));
1043 /* See gdbthread.h. */
1046 can_access_registers_thread (thread_info
*thread
)
1048 /* No thread, no registers. */
1052 /* Don't try to read from a dead thread. */
1053 if (thread
->state
== THREAD_EXITED
)
1056 /* ... or from a spinning thread. FIXME: see validate_registers_access. */
1057 if (thread
->executing
)
1064 pc_in_thread_step_range (CORE_ADDR pc
, struct thread_info
*thread
)
1066 return (pc
>= thread
->control
.step_range_start
1067 && pc
< thread
->control
.step_range_end
);
1070 /* Helper for print_thread_info. Returns true if THR should be
1071 printed. If REQUESTED_THREADS, a list of GDB ids/ranges, is not
1072 NULL, only print THR if its ID is included in the list. GLOBAL_IDS
1073 is true if REQUESTED_THREADS is list of global IDs, false if a list
1074 of per-inferior thread ids. If PID is not -1, only print THR if it
1075 is a thread from the process PID. Otherwise, threads from all
1076 attached PIDs are printed. If both REQUESTED_THREADS is not NULL
1077 and PID is not -1, then the thread is printed if it belongs to the
1078 specified process. Otherwise, an error is raised. */
1081 should_print_thread (const char *requested_threads
, int default_inf_num
,
1082 int global_ids
, int pid
, struct thread_info
*thr
)
1084 if (requested_threads
!= NULL
&& *requested_threads
!= '\0')
1089 in_list
= number_is_in_list (requested_threads
, thr
->global_num
);
1091 in_list
= tid_is_in_list (requested_threads
, default_inf_num
,
1092 thr
->inf
->num
, thr
->per_inf_num
);
1097 if (pid
!= -1 && ptid_get_pid (thr
->ptid
) != pid
)
1099 if (requested_threads
!= NULL
&& *requested_threads
!= '\0')
1100 error (_("Requested thread not found in requested process"));
1104 if (thr
->state
== THREAD_EXITED
)
1110 /* Like print_thread_info, but in addition, GLOBAL_IDS indicates
1111 whether REQUESTED_THREADS is a list of global or per-inferior
1115 print_thread_info_1 (struct ui_out
*uiout
, const char *requested_threads
,
1116 int global_ids
, int pid
,
1117 int show_global_ids
)
1119 struct thread_info
*tp
;
1120 const char *extra_info
, *name
, *target_id
;
1121 struct inferior
*inf
;
1122 int default_inf_num
= current_inferior ()->num
;
1124 update_thread_list ();
1126 /* Whether we saw any thread. */
1127 bool any_thread
= false;
1128 /* Whether the current thread is exited. */
1129 bool current_exited
= false;
1131 thread_info
*current_thread
= (inferior_ptid
!= null_ptid
1132 ? inferior_thread () : NULL
);
1135 /* For backward compatibility, we make a list for MI. A table is
1136 preferable for the CLI, though, because it shows table
1138 gdb::optional
<ui_out_emit_list
> list_emitter
;
1139 gdb::optional
<ui_out_emit_table
> table_emitter
;
1141 if (uiout
->is_mi_like_p ())
1142 list_emitter
.emplace (uiout
, "threads");
1149 if (!should_print_thread (requested_threads
, default_inf_num
,
1150 global_ids
, pid
, tp
))
1158 if (requested_threads
== NULL
|| *requested_threads
== '\0')
1159 uiout
->message (_("No threads.\n"));
1161 uiout
->message (_("No threads match '%s'.\n"),
1166 table_emitter
.emplace (uiout
, show_global_ids
? 5 : 4,
1167 n_threads
, "threads");
1169 uiout
->table_header (1, ui_left
, "current", "");
1170 uiout
->table_header (4, ui_left
, "id-in-tg", "Id");
1171 if (show_global_ids
)
1172 uiout
->table_header (4, ui_left
, "id", "GId");
1173 uiout
->table_header (17, ui_left
, "target-id", "Target Id");
1174 uiout
->table_header (1, ui_left
, "frame", "Frame");
1175 uiout
->table_body ();
1178 /* We'll be switching threads temporarily. */
1179 scoped_restore_current_thread restore_thread
;
1181 ALL_THREADS_BY_INFERIOR (inf
, tp
)
1186 if (tp
== current_thread
&& tp
->state
== THREAD_EXITED
)
1187 current_exited
= true;
1189 if (!should_print_thread (requested_threads
, default_inf_num
,
1190 global_ids
, pid
, tp
))
1193 ui_out_emit_tuple
tuple_emitter (uiout
, NULL
);
1195 if (!uiout
->is_mi_like_p ())
1197 if (tp
== current_thread
)
1198 uiout
->field_string ("current", "*");
1200 uiout
->field_skip ("current");
1202 uiout
->field_string ("id-in-tg", print_thread_id (tp
));
1205 if (show_global_ids
|| uiout
->is_mi_like_p ())
1206 uiout
->field_int ("id", tp
->global_num
);
1208 /* For the CLI, we stuff everything into the target-id field.
1209 This is a gross hack to make the output come out looking
1210 correct. The underlying problem here is that ui-out has no
1211 way to specify that a field's space allocation should be
1212 shared by several fields. For MI, we do the right thing
1215 target_id
= target_pid_to_str (tp
->ptid
);
1216 extra_info
= target_extra_thread_info (tp
);
1217 name
= tp
->name
? tp
->name
: target_thread_name (tp
);
1219 if (uiout
->is_mi_like_p ())
1221 uiout
->field_string ("target-id", target_id
);
1223 uiout
->field_string ("details", extra_info
);
1225 uiout
->field_string ("name", name
);
1229 std::string contents
;
1231 if (extra_info
&& name
)
1232 contents
= string_printf ("%s \"%s\" (%s)", target_id
,
1234 else if (extra_info
)
1235 contents
= string_printf ("%s (%s)", target_id
, extra_info
);
1237 contents
= string_printf ("%s \"%s\"", target_id
, name
);
1239 contents
= target_id
;
1241 uiout
->field_string ("target-id", contents
.c_str ());
1244 if (tp
->state
== THREAD_RUNNING
)
1245 uiout
->text ("(running)\n");
1248 /* The switch below puts us at the top of the stack (leaf
1250 switch_to_thread (tp
);
1251 print_stack_frame (get_selected_frame (NULL
),
1252 /* For MI output, print frame level. */
1253 uiout
->is_mi_like_p (),
1257 if (uiout
->is_mi_like_p ())
1259 const char *state
= "stopped";
1261 if (tp
->state
== THREAD_RUNNING
)
1263 uiout
->field_string ("state", state
);
1266 core
= target_core_of_thread (tp
->ptid
);
1267 if (uiout
->is_mi_like_p () && core
!= -1)
1268 uiout
->field_int ("core", core
);
1271 /* This end scope restores the current thread and the frame
1272 selected before the "info threads" command, and it finishes the
1273 ui-out list or table. */
1276 if (pid
== -1 && requested_threads
== NULL
)
1278 if (uiout
->is_mi_like_p () && inferior_ptid
!= null_ptid
)
1279 uiout
->field_int ("current-thread-id", current_thread
->global_num
);
1281 if (inferior_ptid
!= null_ptid
&& current_exited
)
1282 uiout
->message ("\n\
1283 The current thread <Thread ID %s> has terminated. See `help thread'.\n",
1284 print_thread_id (inferior_thread ()));
1285 else if (any_thread
&& inferior_ptid
== null_ptid
)
1286 uiout
->message ("\n\
1287 No selected thread. See `help thread'.\n");
1291 /* See gdbthread.h. */
1294 print_thread_info (struct ui_out
*uiout
, char *requested_threads
, int pid
)
1296 print_thread_info_1 (uiout
, requested_threads
, 1, pid
, 0);
1299 /* Implementation of the "info threads" command.
1301 Note: this has the drawback that it _really_ switches
1302 threads, which frees the frame cache. A no-side
1303 effects info-threads command would be nicer. */
1306 info_threads_command (const char *arg
, int from_tty
)
1308 int show_global_ids
= 0;
1311 && check_for_argument (&arg
, "-gid", sizeof ("-gid") - 1))
1313 arg
= skip_spaces (arg
);
1314 show_global_ids
= 1;
1317 print_thread_info_1 (current_uiout
, arg
, 0, -1, show_global_ids
);
1320 /* See gdbthread.h. */
1323 switch_to_thread_no_regs (struct thread_info
*thread
)
1325 struct inferior
*inf
= thread
->inf
;
1327 set_current_program_space (inf
->pspace
);
1328 set_current_inferior (inf
);
1330 inferior_ptid
= thread
->ptid
;
1331 stop_pc
= ~(CORE_ADDR
) 0;
1334 /* See gdbthread.h. */
1337 switch_to_no_thread ()
1339 if (inferior_ptid
== null_ptid
)
1342 inferior_ptid
= null_ptid
;
1343 reinit_frame_cache ();
1344 stop_pc
= ~(CORE_ADDR
) 0;
1347 /* See gdbthread.h. */
1350 switch_to_thread (thread_info
*thr
)
1352 gdb_assert (thr
!= NULL
);
1354 if (inferior_ptid
== thr
->ptid
)
1357 switch_to_thread_no_regs (thr
);
1359 reinit_frame_cache ();
1361 /* We don't check for is_stopped, because we're called at times
1362 while in the TARGET_RUNNING state, e.g., while handling an
1364 if (thr
->state
!= THREAD_EXITED
1366 stop_pc
= regcache_read_pc (get_thread_regcache (thr
));
1369 /* See common/common-gdbthread.h. */
1372 switch_to_thread (ptid_t ptid
)
1374 thread_info
*thr
= find_thread_ptid (ptid
);
1375 switch_to_thread (thr
);
1379 restore_selected_frame (struct frame_id a_frame_id
, int frame_level
)
1381 struct frame_info
*frame
= NULL
;
1384 /* This means there was no selected frame. */
1385 if (frame_level
== -1)
1387 select_frame (NULL
);
1391 gdb_assert (frame_level
>= 0);
1393 /* Restore by level first, check if the frame id is the same as
1394 expected. If that fails, try restoring by frame id. If that
1395 fails, nothing to do, just warn the user. */
1397 count
= frame_level
;
1398 frame
= find_relative_frame (get_current_frame (), &count
);
1401 /* The frame ids must match - either both valid or both outer_frame_id.
1402 The latter case is not failsafe, but since it's highly unlikely
1403 the search by level finds the wrong frame, it's 99.9(9)% of
1404 the time (for all practical purposes) safe. */
1405 && frame_id_eq (get_frame_id (frame
), a_frame_id
))
1407 /* Cool, all is fine. */
1408 select_frame (frame
);
1412 frame
= frame_find_by_id (a_frame_id
);
1415 /* Cool, refound it. */
1416 select_frame (frame
);
1420 /* Nothing else to do, the frame layout really changed. Select the
1421 innermost stack frame. */
1422 select_frame (get_current_frame ());
1424 /* Warn the user. */
1425 if (frame_level
> 0 && !current_uiout
->is_mi_like_p ())
1427 warning (_("Couldn't restore frame #%d in "
1428 "current thread. Bottom (innermost) frame selected:"),
1430 /* For MI, we should probably have a notification about
1431 current frame change. But this error is not very
1432 likely, so don't bother for now. */
1433 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
, 1);
1437 scoped_restore_current_thread::~scoped_restore_current_thread ()
1439 /* If an entry of thread_info was previously selected, it won't be
1440 deleted because we've increased its refcount. The thread represented
1441 by this thread_info entry may have already exited (due to normal exit,
1442 detach, etc), so the thread_info.state is THREAD_EXITED. */
1443 if (m_thread
!= NULL
1444 /* If the previously selected thread belonged to a process that has
1445 in the mean time exited (or killed, detached, etc.), then don't revert
1446 back to it, but instead simply drop back to no thread selected. */
1448 switch_to_thread (m_thread
);
1451 switch_to_no_thread ();
1452 set_current_inferior (m_inf
);
1455 /* The running state of the originally selected thread may have
1456 changed, so we have to recheck it here. */
1457 if (inferior_ptid
!= null_ptid
1459 && m_thread
->state
== THREAD_STOPPED
1460 && target_has_registers
1462 && target_has_memory
)
1463 restore_selected_frame (m_selected_frame_id
, m_selected_frame_level
);
1465 if (m_thread
!= NULL
)
1466 m_thread
->decref ();
1470 scoped_restore_current_thread::scoped_restore_current_thread ()
1473 m_inf
= current_inferior ();
1475 if (inferior_ptid
!= null_ptid
)
1477 thread_info
*tp
= inferior_thread ();
1478 struct frame_info
*frame
;
1480 m_was_stopped
= tp
->state
== THREAD_STOPPED
;
1482 && target_has_registers
1484 && target_has_memory
)
1486 /* When processing internal events, there might not be a
1487 selected frame. If we naively call get_selected_frame
1488 here, then we can end up reading debuginfo for the
1489 current frame, but we don't generally need the debuginfo
1491 frame
= get_selected_frame_if_set ();
1496 m_selected_frame_id
= get_frame_id (frame
);
1497 m_selected_frame_level
= frame_relative_level (frame
);
1506 /* See gdbthread.h. */
1509 show_thread_that_caused_stop (void)
1511 return highest_thread_num
> 1;
1514 /* See gdbthread.h. */
1517 show_inferior_qualified_tids (void)
1519 return (inferior_list
->next
!= NULL
|| inferior_list
->num
!= 1);
1522 /* See gdbthread.h. */
1525 print_thread_id (struct thread_info
*thr
)
1527 char *s
= get_print_cell ();
1529 if (show_inferior_qualified_tids ())
1530 xsnprintf (s
, PRINT_CELL_SIZE
, "%d.%d", thr
->inf
->num
, thr
->per_inf_num
);
1532 xsnprintf (s
, PRINT_CELL_SIZE
, "%d", thr
->per_inf_num
);
1536 /* If true, tp_array_compar should sort in ascending order, otherwise
1537 in descending order. */
1539 static bool tp_array_compar_ascending
;
1541 /* Sort an array for struct thread_info pointers by thread ID (first
1542 by inferior number, and then by per-inferior thread number). The
1543 order is determined by TP_ARRAY_COMPAR_ASCENDING. */
1546 tp_array_compar (const thread_info
*a
, const thread_info
*b
)
1548 if (a
->inf
->num
!= b
->inf
->num
)
1550 if (tp_array_compar_ascending
)
1551 return a
->inf
->num
< b
->inf
->num
;
1553 return a
->inf
->num
> b
->inf
->num
;
1556 if (tp_array_compar_ascending
)
1557 return (a
->per_inf_num
< b
->per_inf_num
);
1559 return (a
->per_inf_num
> b
->per_inf_num
);
1562 /* Apply a GDB command to a list of threads. List syntax is a whitespace
1563 separated list of numbers, or ranges, or the keyword `all'. Ranges consist
1564 of two numbers separated by a hyphen. Examples:
1566 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
1567 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
1568 thread apply all x/i $pc Apply x/i $pc cmd to all threads. */
1571 thread_apply_all_command (const char *cmd
, int from_tty
)
1573 tp_array_compar_ascending
= false;
1575 && check_for_argument (&cmd
, "-ascending", strlen ("-ascending")))
1577 cmd
= skip_spaces (cmd
);
1578 tp_array_compar_ascending
= true;
1581 if (cmd
== NULL
|| *cmd
== '\000')
1582 error (_("Please specify a command following the thread ID list"));
1584 update_thread_list ();
1586 int tc
= live_threads_count ();
1589 /* Save a copy of the thread list and increment each thread's
1590 refcount while executing the command in the context of each
1591 thread, in case the command is one that wipes threads. E.g.,
1592 detach, kill, disconnect, etc., or even normally continuing
1593 over an inferior or thread exit. */
1594 std::vector
<thread_info
*> thr_list_cpy
;
1595 thr_list_cpy
.reserve (tc
);
1600 ALL_NON_EXITED_THREADS (tp
)
1602 thr_list_cpy
.push_back (tp
);
1605 gdb_assert (thr_list_cpy
.size () == tc
);
1608 /* Increment the refcounts, and restore them back on scope
1610 scoped_inc_dec_ref
inc_dec_ref (thr_list_cpy
);
1612 std::sort (thr_list_cpy
.begin (), thr_list_cpy
.end (), tp_array_compar
);
1614 scoped_restore_current_thread restore_thread
;
1616 for (thread_info
*thr
: thr_list_cpy
)
1617 if (thread_alive (thr
))
1619 switch_to_thread (thr
);
1620 printf_filtered (_("\nThread %s (%s):\n"),
1621 print_thread_id (thr
),
1622 target_pid_to_str (inferior_ptid
));
1624 execute_command (cmd
, from_tty
);
1629 /* Implementation of the "thread apply" command. */
1632 thread_apply_command (const char *tidlist
, int from_tty
)
1634 const char *cmd
= NULL
;
1635 tid_range_parser parser
;
1637 if (tidlist
== NULL
|| *tidlist
== '\000')
1638 error (_("Please specify a thread ID list"));
1640 parser
.init (tidlist
, current_inferior ()->num
);
1641 while (!parser
.finished ())
1643 int inf_num
, thr_start
, thr_end
;
1645 if (!parser
.get_tid_range (&inf_num
, &thr_start
, &thr_end
))
1647 cmd
= parser
.cur_tok ();
1653 error (_("Please specify a command following the thread ID list"));
1655 if (tidlist
== cmd
|| !isalpha (cmd
[0]))
1656 invalid_thread_id_error (cmd
);
1658 scoped_restore_current_thread restore_thread
;
1660 parser
.init (tidlist
, current_inferior ()->num
);
1661 while (!parser
.finished () && parser
.cur_tok () < cmd
)
1663 struct thread_info
*tp
= NULL
;
1664 struct inferior
*inf
;
1665 int inf_num
, thr_num
;
1667 parser
.get_tid (&inf_num
, &thr_num
);
1668 inf
= find_inferior_id (inf_num
);
1670 tp
= find_thread_id (inf
, thr_num
);
1672 if (parser
.in_star_range ())
1676 warning (_("Unknown inferior %d"), inf_num
);
1677 parser
.skip_range ();
1681 /* No use looking for threads past the highest thread number
1682 the inferior ever had. */
1683 if (thr_num
>= inf
->highest_thread_num
)
1684 parser
.skip_range ();
1686 /* Be quiet about unknown threads numbers. */
1693 if (show_inferior_qualified_tids () || parser
.tid_is_qualified ())
1694 warning (_("Unknown thread %d.%d"), inf_num
, thr_num
);
1696 warning (_("Unknown thread %d"), thr_num
);
1700 if (!thread_alive (tp
))
1702 warning (_("Thread %s has terminated."), print_thread_id (tp
));
1706 switch_to_thread (tp
);
1708 printf_filtered (_("\nThread %s (%s):\n"), print_thread_id (tp
),
1709 target_pid_to_str (inferior_ptid
));
1710 execute_command (cmd
, from_tty
);
1714 /* Switch to the specified thread, or print the current thread. */
1717 thread_command (const char *tidstr
, int from_tty
)
1721 if (inferior_ptid
== null_ptid
)
1722 error (_("No thread selected"));
1724 if (target_has_stack
)
1726 struct thread_info
*tp
= inferior_thread ();
1728 if (tp
->state
== THREAD_EXITED
)
1729 printf_filtered (_("[Current thread is %s (%s) (exited)]\n"),
1730 print_thread_id (tp
),
1731 target_pid_to_str (inferior_ptid
));
1733 printf_filtered (_("[Current thread is %s (%s)]\n"),
1734 print_thread_id (tp
),
1735 target_pid_to_str (inferior_ptid
));
1738 error (_("No stack."));
1742 ptid_t previous_ptid
= inferior_ptid
;
1744 thread_select (tidstr
, parse_thread_id (tidstr
, NULL
));
1746 /* Print if the thread has not changed, otherwise an event will
1748 if (inferior_ptid
== previous_ptid
)
1750 print_selected_thread_frame (current_uiout
,
1751 USER_SELECTED_THREAD
1752 | USER_SELECTED_FRAME
);
1756 gdb::observers::user_selected_context_changed
.notify
1757 (USER_SELECTED_THREAD
| USER_SELECTED_FRAME
);
1762 /* Implementation of `thread name'. */
1765 thread_name_command (const char *arg
, int from_tty
)
1767 struct thread_info
*info
;
1769 if (inferior_ptid
== null_ptid
)
1770 error (_("No thread selected"));
1772 arg
= skip_spaces (arg
);
1774 info
= inferior_thread ();
1776 info
->name
= arg
? xstrdup (arg
) : NULL
;
1779 /* Find thread ids with a name, target pid, or extra info matching ARG. */
1782 thread_find_command (const char *arg
, int from_tty
)
1784 struct thread_info
*tp
;
1786 unsigned long match
= 0;
1788 if (arg
== NULL
|| *arg
== '\0')
1789 error (_("Command requires an argument."));
1791 tmp
= re_comp (arg
);
1793 error (_("Invalid regexp (%s): %s"), tmp
, arg
);
1795 update_thread_list ();
1796 for (tp
= thread_list
; tp
; tp
= tp
->next
)
1798 if (tp
->name
!= NULL
&& re_exec (tp
->name
))
1800 printf_filtered (_("Thread %s has name '%s'\n"),
1801 print_thread_id (tp
), tp
->name
);
1805 tmp
= target_thread_name (tp
);
1806 if (tmp
!= NULL
&& re_exec (tmp
))
1808 printf_filtered (_("Thread %s has target name '%s'\n"),
1809 print_thread_id (tp
), tmp
);
1813 tmp
= target_pid_to_str (tp
->ptid
);
1814 if (tmp
!= NULL
&& re_exec (tmp
))
1816 printf_filtered (_("Thread %s has target id '%s'\n"),
1817 print_thread_id (tp
), tmp
);
1821 tmp
= target_extra_thread_info (tp
);
1822 if (tmp
!= NULL
&& re_exec (tmp
))
1824 printf_filtered (_("Thread %s has extra info '%s'\n"),
1825 print_thread_id (tp
), tmp
);
1830 printf_filtered (_("No threads match '%s'\n"), arg
);
1833 /* Print notices when new threads are attached and detached. */
1834 int print_thread_events
= 1;
1836 show_print_thread_events (struct ui_file
*file
, int from_tty
,
1837 struct cmd_list_element
*c
, const char *value
)
1839 fprintf_filtered (file
,
1840 _("Printing of thread events is %s.\n"),
1844 /* See gdbthread.h. */
1847 thread_select (const char *tidstr
, thread_info
*tp
)
1849 if (!thread_alive (tp
))
1850 error (_("Thread ID %s has terminated."), tidstr
);
1852 switch_to_thread (tp
);
1854 annotate_thread_changed ();
1856 /* Since the current thread may have changed, see if there is any
1857 exited thread we can now delete. */
1861 /* Print thread and frame switch command response. */
1864 print_selected_thread_frame (struct ui_out
*uiout
,
1865 user_selected_what selection
)
1867 struct thread_info
*tp
= inferior_thread ();
1869 if (selection
& USER_SELECTED_THREAD
)
1871 if (uiout
->is_mi_like_p ())
1873 uiout
->field_int ("new-thread-id",
1874 inferior_thread ()->global_num
);
1878 uiout
->text ("[Switching to thread ");
1879 uiout
->field_string ("new-thread-id", print_thread_id (tp
));
1881 uiout
->text (target_pid_to_str (inferior_ptid
));
1886 if (tp
->state
== THREAD_RUNNING
)
1888 if (selection
& USER_SELECTED_THREAD
)
1889 uiout
->text ("(running)\n");
1891 else if (selection
& USER_SELECTED_FRAME
)
1893 if (selection
& USER_SELECTED_THREAD
)
1896 if (has_stack_frames ())
1897 print_stack_frame_to_uiout (uiout
, get_selected_frame (NULL
),
1902 /* Update the 'threads_executing' global based on the threads we know
1906 update_threads_executing (void)
1908 struct thread_info
*tp
;
1910 threads_executing
= 0;
1911 ALL_NON_EXITED_THREADS (tp
)
1915 threads_executing
= 1;
1922 update_thread_list (void)
1924 target_update_thread_list ();
1925 update_threads_executing ();
1928 /* Return a new value for the selected thread's id. Return a value of
1929 0 if no thread is selected. If GLOBAL is true, return the thread's
1930 global number. Otherwise return the per-inferior number. */
1932 static struct value
*
1933 thread_num_make_value_helper (struct gdbarch
*gdbarch
, int global
)
1937 if (inferior_ptid
== null_ptid
)
1941 thread_info
*tp
= inferior_thread ();
1943 int_val
= tp
->global_num
;
1945 int_val
= tp
->per_inf_num
;
1948 return value_from_longest (builtin_type (gdbarch
)->builtin_int
, int_val
);
1951 /* Return a new value for the selected thread's per-inferior thread
1952 number. Return a value of 0 if no thread is selected, or no
1955 static struct value
*
1956 thread_id_per_inf_num_make_value (struct gdbarch
*gdbarch
,
1957 struct internalvar
*var
,
1960 return thread_num_make_value_helper (gdbarch
, 0);
1963 /* Return a new value for the selected thread's global id. Return a
1964 value of 0 if no thread is selected, or no threads exist. */
1966 static struct value
*
1967 global_thread_id_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
1970 return thread_num_make_value_helper (gdbarch
, 1);
1973 /* Commands with a prefix of `thread'. */
1974 struct cmd_list_element
*thread_cmd_list
= NULL
;
1976 /* Implementation of `thread' variable. */
1978 static const struct internalvar_funcs thread_funcs
=
1980 thread_id_per_inf_num_make_value
,
1985 /* Implementation of `gthread' variable. */
1987 static const struct internalvar_funcs gthread_funcs
=
1989 global_thread_id_make_value
,
1995 _initialize_thread (void)
1997 static struct cmd_list_element
*thread_apply_list
= NULL
;
1999 add_info ("threads", info_threads_command
,
2000 _("Display currently known threads.\n\
2001 Usage: info threads [-gid] [ID]...\n\
2002 -gid: Show global thread IDs.\n\
2003 If ID is given, it is a space-separated list of IDs of threads to display.\n\
2004 Otherwise, all threads are displayed."));
2006 add_prefix_cmd ("thread", class_run
, thread_command
, _("\
2007 Use this command to switch between threads.\n\
2008 The new thread ID must be currently known."),
2009 &thread_cmd_list
, "thread ", 1, &cmdlist
);
2011 add_prefix_cmd ("apply", class_run
, thread_apply_command
,
2012 _("Apply a command to a list of threads.\n\
2013 Usage: thread apply ID... COMMAND\n\
2014 ID is a space-separated list of IDs of threads to apply COMMAND on."),
2015 &thread_apply_list
, "thread apply ", 1, &thread_cmd_list
);
2017 add_cmd ("all", class_run
, thread_apply_all_command
,
2019 Apply a command to all threads.\n\
2021 Usage: thread apply all [-ascending] COMMAND\n\
2022 -ascending: Call COMMAND for all threads in ascending order.\n\
2023 The default is descending order.\
2025 &thread_apply_list
);
2027 add_cmd ("name", class_run
, thread_name_command
,
2028 _("Set the current thread's name.\n\
2029 Usage: thread name [NAME]\n\
2030 If NAME is not given, then any existing name is removed."), &thread_cmd_list
);
2032 add_cmd ("find", class_run
, thread_find_command
, _("\
2033 Find threads that match a regular expression.\n\
2034 Usage: thread find REGEXP\n\
2035 Will display thread ids whose name, target ID, or extra info matches REGEXP."),
2038 add_com_alias ("t", "thread", class_run
, 1);
2040 add_setshow_boolean_cmd ("thread-events", no_class
,
2041 &print_thread_events
, _("\
2042 Set printing of thread events (such as thread start and exit)."), _("\
2043 Show printing of thread events (such as thread start and exit)."), NULL
,
2045 show_print_thread_events
,
2046 &setprintlist
, &showprintlist
);
2048 create_internalvar_type_lazy ("_thread", &thread_funcs
, NULL
);
2049 create_internalvar_type_lazy ("_gthread", >hread_funcs
, NULL
);