1 /* Multi-process/thread control for GDB, the GNU debugger.
3 Copyright (C) 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
6 Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
30 #include "gdbthread.h"
31 #include "exceptions.h"
36 #include "gdb_string.h"
39 #include <sys/types.h>
45 /* Definition of struct thread_info exported to gdbthread.h */
47 /* Prototypes for exported functions. */
49 void _initialize_thread (void);
51 /* Prototypes for local functions. */
53 static struct thread_info
*thread_list
= NULL
;
54 static int highest_thread_num
;
56 static struct thread_info
*find_thread_id (int num
);
58 static void thread_command (char *tidstr
, int from_tty
);
59 static void thread_apply_all_command (char *, int);
60 static int thread_alive (struct thread_info
*);
61 static void info_threads_command (char *, int);
62 static void thread_apply_command (char *, int);
63 static void restore_current_thread (ptid_t
);
64 static void prune_threads (void);
66 static int main_thread_running
= 0;
67 static int main_thread_executing
= 0;
70 delete_step_resume_breakpoint (void *arg
)
72 struct breakpoint
**breakpointp
= (struct breakpoint
**) arg
;
73 struct thread_info
*tp
;
75 if (*breakpointp
!= NULL
)
77 delete_breakpoint (*breakpointp
);
78 for (tp
= thread_list
; tp
; tp
= tp
->next
)
79 if (tp
->step_resume_breakpoint
== *breakpointp
)
80 tp
->step_resume_breakpoint
= NULL
;
87 free_thread (struct thread_info
*tp
)
89 /* NOTE: this will take care of any left-over step_resume breakpoints,
90 but not any user-specified thread-specific breakpoints. We can not
91 delete the breakpoint straight-off, because the inferior might not
92 be stopped at the moment. */
93 if (tp
->step_resume_breakpoint
)
94 tp
->step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
96 bpstat_clear (&tp
->stop_bpstat
);
98 /* FIXME: do I ever need to call the back-end to give it a
99 chance at this private data before deleting the thread? */
107 init_thread_list (void)
109 struct thread_info
*tp
, *tpnext
;
111 highest_thread_num
= 0;
112 main_thread_running
= 0;
113 main_thread_executing
= 0;
118 for (tp
= thread_list
; tp
; tp
= tpnext
)
128 add_thread_silent (ptid_t ptid
)
130 struct thread_info
*tp
;
132 tp
= (struct thread_info
*) xmalloc (sizeof (*tp
));
133 memset (tp
, 0, sizeof (*tp
));
135 tp
->num
= ++highest_thread_num
;
136 tp
->next
= thread_list
;
139 observer_notify_new_thread (tp
);
145 add_thread_with_info (ptid_t ptid
, struct private_thread_info
*private)
147 struct thread_info
*result
= add_thread_silent (ptid
);
149 result
->private = private;
151 if (print_thread_events
)
152 printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid
));
154 annotate_new_thread ();
159 add_thread (ptid_t ptid
)
161 return add_thread_with_info (ptid
, NULL
);
164 /* Delete thread PTID. If SILENT, don't notify the observer of this
167 delete_thread_1 (ptid_t ptid
, int silent
)
169 struct thread_info
*tp
, *tpprev
;
173 for (tp
= thread_list
; tp
; tpprev
= tp
, tp
= tp
->next
)
174 if (ptid_equal (tp
->ptid
, ptid
))
181 tpprev
->next
= tp
->next
;
183 thread_list
= tp
->next
;
186 observer_notify_thread_exit (tp
);
192 delete_thread (ptid_t ptid
)
194 delete_thread_1 (ptid
, 0 /* not silent */);
198 delete_thread_silent (ptid_t ptid
)
200 delete_thread_1 (ptid
, 1 /* silent */);
203 static struct thread_info
*
204 find_thread_id (int num
)
206 struct thread_info
*tp
;
208 for (tp
= thread_list
; tp
; tp
= tp
->next
)
215 /* Find a thread_info by matching PTID. */
217 find_thread_pid (ptid_t ptid
)
219 struct thread_info
*tp
;
221 for (tp
= thread_list
; tp
; tp
= tp
->next
)
222 if (ptid_equal (tp
->ptid
, ptid
))
229 * Thread iterator function.
231 * Calls a callback function once for each thread, so long as
232 * the callback function returns false. If the callback function
233 * returns true, the iteration will end and the current thread
234 * will be returned. This can be useful for implementing a
235 * search for a thread with arbitrary attributes, or for applying
236 * some operation to every thread.
238 * FIXME: some of the existing functionality, such as
239 * "Thread apply all", might be rewritten using this functionality.
243 iterate_over_threads (int (*callback
) (struct thread_info
*, void *),
246 struct thread_info
*tp
;
248 for (tp
= thread_list
; tp
; tp
= tp
->next
)
249 if ((*callback
) (tp
, data
))
259 struct thread_info
*tp
;
261 for (tp
= thread_list
; tp
; tp
= tp
->next
)
268 valid_thread_id (int num
)
270 struct thread_info
*tp
;
272 for (tp
= thread_list
; tp
; tp
= tp
->next
)
280 pid_to_thread_id (ptid_t ptid
)
282 struct thread_info
*tp
;
284 for (tp
= thread_list
; tp
; tp
= tp
->next
)
285 if (ptid_equal (tp
->ptid
, ptid
))
292 thread_id_to_pid (int num
)
294 struct thread_info
*thread
= find_thread_id (num
);
298 return pid_to_ptid (-1);
302 in_thread_list (ptid_t ptid
)
304 struct thread_info
*tp
;
306 for (tp
= thread_list
; tp
; tp
= tp
->next
)
307 if (ptid_equal (tp
->ptid
, ptid
))
310 return 0; /* Never heard of 'im */
313 /* Print a list of thread ids currently known, and the total number of
314 threads. To be used from within catch_errors. */
316 do_captured_list_thread_ids (struct ui_out
*uiout
, void *arg
)
318 struct thread_info
*tp
;
320 struct cleanup
*cleanup_chain
;
323 target_find_new_threads ();
325 cleanup_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "thread-ids");
327 for (tp
= thread_list
; tp
; tp
= tp
->next
)
330 ui_out_field_int (uiout
, "thread-id", tp
->num
);
333 do_cleanups (cleanup_chain
);
334 ui_out_field_int (uiout
, "number-of-threads", num
);
338 /* Official gdblib interface function to get a list of thread ids and
341 gdb_list_thread_ids (struct ui_out
*uiout
, char **error_message
)
343 if (catch_exceptions_with_msg (uiout
, do_captured_list_thread_ids
, NULL
,
344 error_message
, RETURN_MASK_ALL
) < 0)
349 /* Load infrun state for the thread PID. */
352 load_infrun_state (ptid_t ptid
,
355 struct breakpoint
**step_resume_breakpoint
,
356 CORE_ADDR
*step_range_start
,
357 CORE_ADDR
*step_range_end
,
358 struct frame_id
*step_frame_id
,
359 int *stepping_over_breakpoint
,
360 int *stepping_through_solib_after_catch
,
361 bpstat
*stepping_through_solib_catchpoints
,
363 struct symtab
**current_symtab
,
364 struct continuation
**continuations
,
365 struct continuation
**intermediate_continuations
,
366 int *proceed_to_finish
,
367 enum step_over_calls_kind
*step_over_calls
,
370 enum target_signal
*stop_signal
,
373 struct thread_info
*tp
;
375 /* If we can't find the thread, then we're debugging a single threaded
376 process. No need to do anything in that case. */
377 tp
= find_thread_id (pid_to_thread_id (ptid
));
381 *prev_pc
= tp
->prev_pc
;
382 *trap_expected
= tp
->trap_expected
;
383 *step_resume_breakpoint
= tp
->step_resume_breakpoint
;
384 *step_range_start
= tp
->step_range_start
;
385 *step_range_end
= tp
->step_range_end
;
386 *step_frame_id
= tp
->step_frame_id
;
387 *stepping_over_breakpoint
= tp
->stepping_over_breakpoint
;
388 *stepping_through_solib_after_catch
=
389 tp
->stepping_through_solib_after_catch
;
390 *stepping_through_solib_catchpoints
=
391 tp
->stepping_through_solib_catchpoints
;
392 *current_line
= tp
->current_line
;
393 *current_symtab
= tp
->current_symtab
;
395 /* In all-stop mode, these are global state, while in non-stop mode,
396 they are per thread. */
399 *continuations
= tp
->continuations
;
400 tp
->continuations
= NULL
;
401 *intermediate_continuations
= tp
->intermediate_continuations
;
402 tp
->intermediate_continuations
= NULL
;
403 *proceed_to_finish
= tp
->proceed_to_finish
;
404 *step_over_calls
= tp
->step_over_calls
;
405 *stop_step
= tp
->stop_step
;
406 *step_multi
= tp
->step_multi
;
407 *stop_signal
= tp
->stop_signal
;
409 /* Swap instead of copy, so we only have to update one of
411 *stop_bpstat
= tp
->stop_bpstat
;
416 /* Save infrun state for the thread PID. */
419 save_infrun_state (ptid_t ptid
,
422 struct breakpoint
*step_resume_breakpoint
,
423 CORE_ADDR step_range_start
,
424 CORE_ADDR step_range_end
,
425 const struct frame_id
*step_frame_id
,
426 int stepping_over_breakpoint
,
427 int stepping_through_solib_after_catch
,
428 bpstat stepping_through_solib_catchpoints
,
430 struct symtab
*current_symtab
,
431 struct continuation
*continuations
,
432 struct continuation
*intermediate_continuations
,
433 int proceed_to_finish
,
434 enum step_over_calls_kind step_over_calls
,
437 enum target_signal stop_signal
,
440 struct thread_info
*tp
;
442 /* If we can't find the thread, then we're debugging a single-threaded
443 process. Nothing to do in that case. */
444 tp
= find_thread_id (pid_to_thread_id (ptid
));
448 tp
->prev_pc
= prev_pc
;
449 tp
->trap_expected
= trap_expected
;
450 tp
->step_resume_breakpoint
= step_resume_breakpoint
;
451 tp
->step_range_start
= step_range_start
;
452 tp
->step_range_end
= step_range_end
;
453 tp
->step_frame_id
= (*step_frame_id
);
454 tp
->stepping_over_breakpoint
= stepping_over_breakpoint
;
455 tp
->stepping_through_solib_after_catch
= stepping_through_solib_after_catch
;
456 tp
->stepping_through_solib_catchpoints
= stepping_through_solib_catchpoints
;
457 tp
->current_line
= current_line
;
458 tp
->current_symtab
= current_symtab
;
460 /* In all-stop mode, these are global state, while in non-stop mode,
461 they are per thread. */
464 tp
->continuations
= continuations
;
465 tp
->intermediate_continuations
= intermediate_continuations
;
466 tp
->proceed_to_finish
= proceed_to_finish
;
467 tp
->step_over_calls
= step_over_calls
;
468 tp
->stop_step
= stop_step
;
469 tp
->step_multi
= step_multi
;
470 tp
->stop_signal
= stop_signal
;
471 tp
->stop_bpstat
= stop_bpstat
;
475 /* Return true if TP is an active thread. */
477 thread_alive (struct thread_info
*tp
)
479 if (PIDGET (tp
->ptid
) == -1)
481 if (!target_thread_alive (tp
->ptid
))
483 tp
->ptid
= pid_to_ptid (-1); /* Mark it as dead */
492 struct thread_info
*tp
, *next
;
494 for (tp
= thread_list
; tp
; tp
= next
)
497 if (!thread_alive (tp
))
498 delete_thread (tp
->ptid
);
503 set_running (ptid_t ptid
, int running
)
505 struct thread_info
*tp
;
509 /* This is one of the targets that does not add main
510 thread to the thread list. Just use a single
511 global flag to indicate that a thread is running.
513 This problem is unique to ST programs. For MT programs,
514 the main thread is always present in the thread list. If it's
515 not, the first call to context_switch will mess up GDB internal
517 if (running
&& !main_thread_running
&& !suppress_resume_observer
)
518 observer_notify_target_resumed (ptid
);
519 main_thread_running
= running
;
523 /* We try not to notify the observer if no thread has actually changed
524 the running state -- merely to reduce the number of messages to
525 frontend. Frontend is supposed to handle multiple *running just fine. */
526 if (PIDGET (ptid
) == -1)
529 for (tp
= thread_list
; tp
; tp
= tp
->next
)
531 if (running
&& !tp
->running_
)
533 tp
->running_
= running
;
535 if (any_started
&& !suppress_resume_observer
)
536 observer_notify_target_resumed (ptid
);
540 tp
= find_thread_pid (ptid
);
542 if (running
&& !tp
->running_
&& !suppress_resume_observer
)
543 observer_notify_target_resumed (ptid
);
544 tp
->running_
= running
;
549 is_running (ptid_t ptid
)
551 struct thread_info
*tp
;
553 if (!target_has_execution
)
557 return main_thread_running
;
559 tp
= find_thread_pid (ptid
);
567 struct thread_info
*tp
;
569 if (!target_has_execution
)
573 return main_thread_running
;
575 for (tp
= thread_list
; tp
; tp
= tp
->next
)
583 is_executing (ptid_t ptid
)
585 struct thread_info
*tp
;
587 if (!target_has_execution
)
591 return main_thread_executing
;
593 tp
= find_thread_pid (ptid
);
595 return tp
->executing_
;
599 set_executing (ptid_t ptid
, int executing
)
601 struct thread_info
*tp
;
605 /* This target does not add the main thread to the thread list.
606 Use a global flag to indicate that the thread is
608 main_thread_executing
= executing
;
612 if (PIDGET (ptid
) == -1)
614 for (tp
= thread_list
; tp
; tp
= tp
->next
)
615 tp
->executing_
= executing
;
619 tp
= find_thread_pid (ptid
);
621 tp
->executing_
= executing
;
625 /* Prints the list of threads and their details on UIOUT.
626 This is a version of 'info_thread_command' suitable for
628 If REQESTED_THREAD is not -1, it's the GDB id of the thread
629 that should be printed. Otherwise, all threads are
632 print_thread_info (struct ui_out
*uiout
, int requested_thread
)
634 struct thread_info
*tp
;
636 struct frame_info
*cur_frame
;
637 struct cleanup
*old_chain
;
638 struct frame_id saved_frame_id
;
640 int current_thread
= -1;
642 /* Backup current thread and selected frame. */
643 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
644 old_chain
= make_cleanup_restore_current_thread (inferior_ptid
, saved_frame_id
);
646 make_cleanup_ui_out_list_begin_end (uiout
, "threads");
649 target_find_new_threads ();
650 current_ptid
= inferior_ptid
;
651 for (tp
= thread_list
; tp
; tp
= tp
->next
)
653 struct cleanup
*chain2
;
655 if (requested_thread
!= -1 && tp
->num
!= requested_thread
)
658 chain2
= make_cleanup_ui_out_tuple_begin_end (uiout
, NULL
);
660 if (ptid_equal (tp
->ptid
, current_ptid
))
662 current_thread
= tp
->num
;
663 ui_out_text (uiout
, "* ");
666 ui_out_text (uiout
, " ");
668 ui_out_field_int (uiout
, "id", tp
->num
);
669 ui_out_text (uiout
, " ");
670 ui_out_field_string (uiout
, "target-id", target_tid_to_str (tp
->ptid
));
672 extra_info
= target_extra_thread_info (tp
);
675 ui_out_text (uiout
, " (");
676 ui_out_field_string (uiout
, "details", extra_info
);
677 ui_out_text (uiout
, ")");
679 ui_out_text (uiout
, " ");
680 /* That switch put us at the top of the stack (leaf frame). */
681 switch_to_thread (tp
->ptid
);
682 print_stack_frame (get_selected_frame (NULL
),
683 /* For MI output, print frame level. */
684 ui_out_is_mi_like_p (uiout
),
687 do_cleanups (chain2
);
690 /* Restores the current thread and the frame selected before
691 the "info threads" command. */
692 do_cleanups (old_chain
);
694 if (requested_thread
== -1)
696 gdb_assert (current_thread
!= -1 || !thread_list
);
697 if (current_thread
!= -1 && ui_out_is_mi_like_p (uiout
))
698 ui_out_field_int (uiout
, "current-thread-id", current_thread
);
701 /* If case we were not able to find the original frame, print the
702 new selected frame. */
703 if (frame_find_by_id (saved_frame_id
) == NULL
)
705 warning (_("Couldn't restore frame in current thread, at frame 0"));
706 /* For MI, we should probably have a notification about
707 current frame change. But this error is not very likely, so
708 don't bother for now. */
709 if (!ui_out_is_mi_like_p (uiout
))
710 print_stack_frame (get_selected_frame (NULL
), 0, LOCATION
);
715 /* Print information about currently known threads
717 * Note: this has the drawback that it _really_ switches
718 * threads, which frees the frame cache. A no-side
719 * effects info-threads command would be nicer.
723 info_threads_command (char *arg
, int from_tty
)
725 print_thread_info (uiout
, -1);
728 /* Switch from one thread to another. */
731 switch_to_thread (ptid_t ptid
)
733 if (ptid_equal (ptid
, inferior_ptid
))
736 inferior_ptid
= ptid
;
737 reinit_frame_cache ();
738 registers_changed ();
739 stop_pc
= read_pc ();
743 restore_current_thread (ptid_t ptid
)
745 if (!ptid_equal (ptid
, inferior_ptid
))
747 switch_to_thread (ptid
);
752 restore_selected_frame (struct frame_id a_frame_id
)
754 struct frame_info
*selected_frame_info
= NULL
;
756 if (frame_id_eq (a_frame_id
, null_frame_id
))
759 if ((selected_frame_info
= frame_find_by_id (a_frame_id
)) != NULL
)
761 select_frame (selected_frame_info
);
765 struct current_thread_cleanup
767 ptid_t inferior_ptid
;
768 struct frame_id selected_frame_id
;
772 do_restore_current_thread_cleanup (void *arg
)
774 struct current_thread_cleanup
*old
= arg
;
775 restore_current_thread (old
->inferior_ptid
);
776 restore_selected_frame (old
->selected_frame_id
);
781 make_cleanup_restore_current_thread (ptid_t inferior_ptid
,
782 struct frame_id a_frame_id
)
784 struct current_thread_cleanup
*old
785 = xmalloc (sizeof (struct current_thread_cleanup
));
786 old
->inferior_ptid
= inferior_ptid
;
787 old
->selected_frame_id
= a_frame_id
;
788 return make_cleanup (do_restore_current_thread_cleanup
, old
);
791 /* Apply a GDB command to a list of threads. List syntax is a whitespace
792 seperated list of numbers, or ranges, or the keyword `all'. Ranges consist
793 of two numbers seperated by a hyphen. Examples:
795 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
796 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
797 thread apply all p x/i $pc Apply x/i $pc cmd to all threads
801 thread_apply_all_command (char *cmd
, int from_tty
)
803 struct thread_info
*tp
;
804 struct cleanup
*old_chain
;
805 struct cleanup
*saved_cmd_cleanup_chain
;
807 struct frame_id saved_frame_id
;
809 int thread_has_changed
= 0;
811 if (cmd
== NULL
|| *cmd
== '\000')
812 error (_("Please specify a command following the thread ID list"));
814 current_ptid
= inferior_ptid
;
815 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
816 old_chain
= make_cleanup_restore_current_thread (inferior_ptid
, saved_frame_id
);
818 /* It is safe to update the thread list now, before
819 traversing it for "thread apply all". MVS */
820 target_find_new_threads ();
822 /* Save a copy of the command in case it is clobbered by
824 saved_cmd
= xstrdup (cmd
);
825 saved_cmd_cleanup_chain
= make_cleanup (xfree
, (void *) saved_cmd
);
826 for (tp
= thread_list
; tp
; tp
= tp
->next
)
827 if (thread_alive (tp
))
829 switch_to_thread (tp
->ptid
);
830 printf_filtered (_("\nThread %d (%s):\n"),
831 tp
->num
, target_tid_to_str (inferior_ptid
));
832 execute_command (cmd
, from_tty
);
833 strcpy (cmd
, saved_cmd
); /* Restore exact command used previously */
836 if (!ptid_equal (current_ptid
, inferior_ptid
))
837 thread_has_changed
= 1;
839 do_cleanups (saved_cmd_cleanup_chain
);
840 do_cleanups (old_chain
);
841 /* Print stack frame only if we changed thread. */
842 if (thread_has_changed
)
843 print_stack_frame (get_current_frame (), 1, SRC_LINE
);
848 thread_apply_command (char *tidlist
, int from_tty
)
852 struct cleanup
*old_chain
;
853 struct cleanup
*saved_cmd_cleanup_chain
;
855 struct frame_id saved_frame_id
;
857 int thread_has_changed
= 0;
859 if (tidlist
== NULL
|| *tidlist
== '\000')
860 error (_("Please specify a thread ID list"));
862 for (cmd
= tidlist
; *cmd
!= '\000' && !isalpha (*cmd
); cmd
++);
865 error (_("Please specify a command following the thread ID list"));
867 current_ptid
= inferior_ptid
;
868 saved_frame_id
= get_frame_id (get_selected_frame (NULL
));
869 old_chain
= make_cleanup_restore_current_thread (inferior_ptid
, saved_frame_id
);
871 /* Save a copy of the command in case it is clobbered by
873 saved_cmd
= xstrdup (cmd
);
874 saved_cmd_cleanup_chain
= make_cleanup (xfree
, (void *) saved_cmd
);
875 while (tidlist
< cmd
)
877 struct thread_info
*tp
;
880 start
= strtol (tidlist
, &p
, 10);
882 error (_("Error parsing %s"), tidlist
);
885 while (*tidlist
== ' ' || *tidlist
== '\t')
888 if (*tidlist
== '-') /* Got a range of IDs? */
890 tidlist
++; /* Skip the - */
891 end
= strtol (tidlist
, &p
, 10);
893 error (_("Error parsing %s"), tidlist
);
896 while (*tidlist
== ' ' || *tidlist
== '\t')
902 for (; start
<= end
; start
++)
904 tp
= find_thread_id (start
);
907 warning (_("Unknown thread %d."), start
);
908 else if (!thread_alive (tp
))
909 warning (_("Thread %d has terminated."), start
);
912 switch_to_thread (tp
->ptid
);
913 printf_filtered (_("\nThread %d (%s):\n"), tp
->num
,
914 target_tid_to_str (inferior_ptid
));
915 execute_command (cmd
, from_tty
);
916 strcpy (cmd
, saved_cmd
); /* Restore exact command used previously */
921 if (!ptid_equal (current_ptid
, inferior_ptid
))
922 thread_has_changed
= 1;
924 do_cleanups (saved_cmd_cleanup_chain
);
925 do_cleanups (old_chain
);
926 /* Print stack frame only if we changed thread. */
927 if (thread_has_changed
)
928 print_stack_frame (get_current_frame (), 1, SRC_LINE
);
931 /* Switch to the specified thread. Will dispatch off to thread_apply_command
932 if prefix of arg is `apply'. */
935 thread_command (char *tidstr
, int from_tty
)
939 /* Don't generate an error, just say which thread is current. */
940 if (target_has_stack
)
941 printf_filtered (_("[Current thread is %d (%s)]\n"),
942 pid_to_thread_id (inferior_ptid
),
943 target_tid_to_str (inferior_ptid
));
945 error (_("No stack."));
949 annotate_thread_changed ();
950 gdb_thread_select (uiout
, tidstr
, NULL
);
953 /* Print notices when new threads are attached and detached. */
954 int print_thread_events
= 1;
956 show_print_thread_events (struct ui_file
*file
, int from_tty
,
957 struct cmd_list_element
*c
, const char *value
)
959 fprintf_filtered (file
, _("\
960 Printing of thread events is %s.\n"),
965 do_captured_thread_select (struct ui_out
*uiout
, void *tidstr
)
968 struct thread_info
*tp
;
970 num
= value_as_long (parse_and_eval (tidstr
));
972 tp
= find_thread_id (num
);
975 error (_("Thread ID %d not known."), num
);
977 if (!thread_alive (tp
))
978 error (_("Thread ID %d has terminated."), num
);
980 switch_to_thread (tp
->ptid
);
982 ui_out_text (uiout
, "[Switching to thread ");
983 ui_out_field_int (uiout
, "new-thread-id", pid_to_thread_id (inferior_ptid
));
984 ui_out_text (uiout
, " (");
985 ui_out_text (uiout
, target_tid_to_str (inferior_ptid
));
986 ui_out_text (uiout
, ")]");
988 print_stack_frame (get_selected_frame (NULL
), 1, SRC_AND_LOC
);
993 gdb_thread_select (struct ui_out
*uiout
, char *tidstr
, char **error_message
)
995 if (catch_exceptions_with_msg (uiout
, do_captured_thread_select
, tidstr
,
996 error_message
, RETURN_MASK_ALL
) < 0)
1001 /* Commands with a prefix of `thread'. */
1002 struct cmd_list_element
*thread_cmd_list
= NULL
;
1005 _initialize_thread (void)
1007 static struct cmd_list_element
*thread_apply_list
= NULL
;
1009 add_info ("threads", info_threads_command
,
1010 _("IDs of currently known threads."));
1012 add_prefix_cmd ("thread", class_run
, thread_command
, _("\
1013 Use this command to switch between threads.\n\
1014 The new thread ID must be currently known."),
1015 &thread_cmd_list
, "thread ", 1, &cmdlist
);
1017 add_prefix_cmd ("apply", class_run
, thread_apply_command
,
1018 _("Apply a command to a list of threads."),
1019 &thread_apply_list
, "thread apply ", 1, &thread_cmd_list
);
1021 add_cmd ("all", class_run
, thread_apply_all_command
,
1022 _("Apply a command to all threads."), &thread_apply_list
);
1025 add_com_alias ("t", "thread", class_run
, 1);
1027 add_setshow_boolean_cmd ("thread-events", no_class
,
1028 &print_thread_events
, _("\
1029 Set printing of thread events (such as thread start and exit)."), _("\
1030 Show printing of thread events (such as thread start and exit)."), NULL
,
1032 show_print_thread_events
,
1033 &setprintlist
, &showprintlist
);