* arm-tdep.c (arm_mode_strings, arm_fallback_mode_string)
[deliverable/binutils-gdb.git] / gdb / thread.c
1 /* Multi-process/thread control for GDB, the GNU debugger.
2
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.
5
6 Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA.
7
8 This file is part of GDB.
9
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.
14
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.
19
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/>. */
22
23 #include "defs.h"
24 #include "symtab.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "environ.h"
28 #include "value.h"
29 #include "target.h"
30 #include "gdbthread.h"
31 #include "exceptions.h"
32 #include "command.h"
33 #include "gdbcmd.h"
34 #include "regcache.h"
35 #include "gdb.h"
36 #include "gdb_string.h"
37
38 #include <ctype.h>
39 #include <sys/types.h>
40 #include <signal.h>
41 #include "ui-out.h"
42 #include "observer.h"
43
44 /* Definition of struct thread_info exported to gdbthread.h */
45
46 /* Prototypes for exported functions. */
47
48 void _initialize_thread (void);
49
50 /* Prototypes for local functions. */
51
52 static struct thread_info *thread_list = NULL;
53 static int highest_thread_num;
54
55 static struct thread_info *find_thread_id (int num);
56
57 static void thread_command (char *tidstr, int from_tty);
58 static void thread_apply_all_command (char *, int);
59 static int thread_alive (struct thread_info *);
60 static void info_threads_command (char *, int);
61 static void thread_apply_command (char *, int);
62 static void restore_current_thread (ptid_t);
63 static void prune_threads (void);
64
65 void
66 delete_step_resume_breakpoint (void *arg)
67 {
68 struct breakpoint **breakpointp = (struct breakpoint **) arg;
69 struct thread_info *tp;
70
71 if (*breakpointp != NULL)
72 {
73 delete_breakpoint (*breakpointp);
74 for (tp = thread_list; tp; tp = tp->next)
75 if (tp->step_resume_breakpoint == *breakpointp)
76 tp->step_resume_breakpoint = NULL;
77
78 *breakpointp = NULL;
79 }
80 }
81
82 static void
83 free_thread (struct thread_info *tp)
84 {
85 /* NOTE: this will take care of any left-over step_resume breakpoints,
86 but not any user-specified thread-specific breakpoints. We can not
87 delete the breakpoint straight-off, because the inferior might not
88 be stopped at the moment. */
89 if (tp->step_resume_breakpoint)
90 tp->step_resume_breakpoint->disposition = disp_del_at_next_stop;
91
92 /* FIXME: do I ever need to call the back-end to give it a
93 chance at this private data before deleting the thread? */
94 if (tp->private)
95 xfree (tp->private);
96
97 xfree (tp);
98 }
99
100 void
101 init_thread_list (void)
102 {
103 struct thread_info *tp, *tpnext;
104
105 highest_thread_num = 0;
106 if (!thread_list)
107 return;
108
109 for (tp = thread_list; tp; tp = tpnext)
110 {
111 tpnext = tp->next;
112 free_thread (tp);
113 }
114
115 thread_list = NULL;
116 }
117
118 struct thread_info *
119 add_thread_silent (ptid_t ptid)
120 {
121 struct thread_info *tp;
122
123 tp = (struct thread_info *) xmalloc (sizeof (*tp));
124 memset (tp, 0, sizeof (*tp));
125 tp->ptid = ptid;
126 tp->num = ++highest_thread_num;
127 tp->next = thread_list;
128 thread_list = tp;
129
130 observer_notify_new_thread (tp);
131
132 return tp;
133 }
134
135 struct thread_info *
136 add_thread_with_info (ptid_t ptid, struct private_thread_info *private)
137 {
138 struct thread_info *result = add_thread_silent (ptid);
139
140 result->private = private;
141
142 if (print_thread_events)
143 printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
144
145 return result;
146 }
147
148 struct thread_info *
149 add_thread (ptid_t ptid)
150 {
151 return add_thread_with_info (ptid, NULL);
152 }
153
154 void
155 delete_thread (ptid_t ptid)
156 {
157 struct thread_info *tp, *tpprev;
158
159 tpprev = NULL;
160
161 for (tp = thread_list; tp; tpprev = tp, tp = tp->next)
162 if (ptid_equal (tp->ptid, ptid))
163 break;
164
165 if (!tp)
166 return;
167
168 if (tpprev)
169 tpprev->next = tp->next;
170 else
171 thread_list = tp->next;
172
173 free_thread (tp);
174 }
175
176 static struct thread_info *
177 find_thread_id (int num)
178 {
179 struct thread_info *tp;
180
181 for (tp = thread_list; tp; tp = tp->next)
182 if (tp->num == num)
183 return tp;
184
185 return NULL;
186 }
187
188 /* Find a thread_info by matching PTID. */
189 struct thread_info *
190 find_thread_pid (ptid_t ptid)
191 {
192 struct thread_info *tp;
193
194 for (tp = thread_list; tp; tp = tp->next)
195 if (ptid_equal (tp->ptid, ptid))
196 return tp;
197
198 return NULL;
199 }
200
201 /*
202 * Thread iterator function.
203 *
204 * Calls a callback function once for each thread, so long as
205 * the callback function returns false. If the callback function
206 * returns true, the iteration will end and the current thread
207 * will be returned. This can be useful for implementing a
208 * search for a thread with arbitrary attributes, or for applying
209 * some operation to every thread.
210 *
211 * FIXME: some of the existing functionality, such as
212 * "Thread apply all", might be rewritten using this functionality.
213 */
214
215 struct thread_info *
216 iterate_over_threads (int (*callback) (struct thread_info *, void *),
217 void *data)
218 {
219 struct thread_info *tp;
220
221 for (tp = thread_list; tp; tp = tp->next)
222 if ((*callback) (tp, data))
223 return tp;
224
225 return NULL;
226 }
227
228 int
229 valid_thread_id (int num)
230 {
231 struct thread_info *tp;
232
233 for (tp = thread_list; tp; tp = tp->next)
234 if (tp->num == num)
235 return 1;
236
237 return 0;
238 }
239
240 int
241 pid_to_thread_id (ptid_t ptid)
242 {
243 struct thread_info *tp;
244
245 for (tp = thread_list; tp; tp = tp->next)
246 if (ptid_equal (tp->ptid, ptid))
247 return tp->num;
248
249 return 0;
250 }
251
252 ptid_t
253 thread_id_to_pid (int num)
254 {
255 struct thread_info *thread = find_thread_id (num);
256 if (thread)
257 return thread->ptid;
258 else
259 return pid_to_ptid (-1);
260 }
261
262 int
263 in_thread_list (ptid_t ptid)
264 {
265 struct thread_info *tp;
266
267 for (tp = thread_list; tp; tp = tp->next)
268 if (ptid_equal (tp->ptid, ptid))
269 return 1;
270
271 return 0; /* Never heard of 'im */
272 }
273
274 /* Print a list of thread ids currently known, and the total number of
275 threads. To be used from within catch_errors. */
276 static int
277 do_captured_list_thread_ids (struct ui_out *uiout, void *arg)
278 {
279 struct thread_info *tp;
280 int num = 0;
281 struct cleanup *cleanup_chain;
282
283 prune_threads ();
284 target_find_new_threads ();
285
286 cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "thread-ids");
287
288 for (tp = thread_list; tp; tp = tp->next)
289 {
290 num++;
291 ui_out_field_int (uiout, "thread-id", tp->num);
292 }
293
294 do_cleanups (cleanup_chain);
295 ui_out_field_int (uiout, "number-of-threads", num);
296 return GDB_RC_OK;
297 }
298
299 /* Official gdblib interface function to get a list of thread ids and
300 the total number. */
301 enum gdb_rc
302 gdb_list_thread_ids (struct ui_out *uiout, char **error_message)
303 {
304 if (catch_exceptions_with_msg (uiout, do_captured_list_thread_ids, NULL,
305 error_message, RETURN_MASK_ALL) < 0)
306 return GDB_RC_FAIL;
307 return GDB_RC_OK;
308 }
309
310 /* Load infrun state for the thread PID. */
311
312 void
313 load_infrun_state (ptid_t ptid,
314 CORE_ADDR *prev_pc,
315 int *trap_expected,
316 struct breakpoint **step_resume_breakpoint,
317 CORE_ADDR *step_range_start,
318 CORE_ADDR *step_range_end,
319 struct frame_id *step_frame_id,
320 int *handling_longjmp,
321 int *stepping_over_breakpoint,
322 int *stepping_through_solib_after_catch,
323 bpstat *stepping_through_solib_catchpoints,
324 int *current_line,
325 struct symtab **current_symtab)
326 {
327 struct thread_info *tp;
328
329 /* If we can't find the thread, then we're debugging a single threaded
330 process. No need to do anything in that case. */
331 tp = find_thread_id (pid_to_thread_id (ptid));
332 if (tp == NULL)
333 return;
334
335 *prev_pc = tp->prev_pc;
336 *trap_expected = tp->trap_expected;
337 *step_resume_breakpoint = tp->step_resume_breakpoint;
338 *step_range_start = tp->step_range_start;
339 *step_range_end = tp->step_range_end;
340 *step_frame_id = tp->step_frame_id;
341 *handling_longjmp = tp->handling_longjmp;
342 *stepping_over_breakpoint = tp->stepping_over_breakpoint;
343 *stepping_through_solib_after_catch =
344 tp->stepping_through_solib_after_catch;
345 *stepping_through_solib_catchpoints =
346 tp->stepping_through_solib_catchpoints;
347 *current_line = tp->current_line;
348 *current_symtab = tp->current_symtab;
349 }
350
351 /* Save infrun state for the thread PID. */
352
353 void
354 save_infrun_state (ptid_t ptid,
355 CORE_ADDR prev_pc,
356 int trap_expected,
357 struct breakpoint *step_resume_breakpoint,
358 CORE_ADDR step_range_start,
359 CORE_ADDR step_range_end,
360 const struct frame_id *step_frame_id,
361 int handling_longjmp,
362 int stepping_over_breakpoint,
363 int stepping_through_solib_after_catch,
364 bpstat stepping_through_solib_catchpoints,
365 int current_line,
366 struct symtab *current_symtab)
367 {
368 struct thread_info *tp;
369
370 /* If we can't find the thread, then we're debugging a single-threaded
371 process. Nothing to do in that case. */
372 tp = find_thread_id (pid_to_thread_id (ptid));
373 if (tp == NULL)
374 return;
375
376 tp->prev_pc = prev_pc;
377 tp->trap_expected = trap_expected;
378 tp->step_resume_breakpoint = step_resume_breakpoint;
379 tp->step_range_start = step_range_start;
380 tp->step_range_end = step_range_end;
381 tp->step_frame_id = (*step_frame_id);
382 tp->handling_longjmp = handling_longjmp;
383 tp->stepping_over_breakpoint = stepping_over_breakpoint;
384 tp->stepping_through_solib_after_catch = stepping_through_solib_after_catch;
385 tp->stepping_through_solib_catchpoints = stepping_through_solib_catchpoints;
386 tp->current_line = current_line;
387 tp->current_symtab = current_symtab;
388 }
389
390 /* Return true if TP is an active thread. */
391 static int
392 thread_alive (struct thread_info *tp)
393 {
394 if (PIDGET (tp->ptid) == -1)
395 return 0;
396 if (!target_thread_alive (tp->ptid))
397 {
398 tp->ptid = pid_to_ptid (-1); /* Mark it as dead */
399 return 0;
400 }
401 return 1;
402 }
403
404 static void
405 prune_threads (void)
406 {
407 struct thread_info *tp, *next;
408
409 for (tp = thread_list; tp; tp = next)
410 {
411 next = tp->next;
412 if (!thread_alive (tp))
413 delete_thread (tp->ptid);
414 }
415 }
416
417 /* Prints the list of threads and their details on UIOUT.
418 This is a version of 'info_thread_command' suitable for
419 use from MI.
420 If REQESTED_THREAD is not -1, it's the GDB id of the thread
421 that should be printed. Otherwise, all threads are
422 printed. */
423 void
424 print_thread_info (struct ui_out *uiout, int requested_thread)
425 {
426 struct thread_info *tp;
427 ptid_t current_ptid;
428 struct frame_info *cur_frame;
429 struct cleanup *old_chain;
430 struct frame_id saved_frame_id;
431 char *extra_info;
432 int current_thread = -1;
433
434 /* Backup current thread and selected frame. */
435 saved_frame_id = get_frame_id (get_selected_frame (NULL));
436 old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
437
438 make_cleanup_ui_out_list_begin_end (uiout, "threads");
439
440 prune_threads ();
441 target_find_new_threads ();
442 current_ptid = inferior_ptid;
443 for (tp = thread_list; tp; tp = tp->next)
444 {
445 struct cleanup *chain2;
446
447 if (requested_thread != -1 && tp->num != requested_thread)
448 continue;
449
450 chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
451
452 if (ptid_equal (tp->ptid, current_ptid))
453 {
454 current_thread = tp->num;
455 ui_out_text (uiout, "* ");
456 }
457 else
458 ui_out_text (uiout, " ");
459
460 ui_out_field_int (uiout, "id", tp->num);
461 ui_out_text (uiout, " ");
462 ui_out_field_string (uiout, "target-id", target_tid_to_str (tp->ptid));
463
464 extra_info = target_extra_thread_info (tp);
465 if (extra_info)
466 {
467 ui_out_text (uiout, " (");
468 ui_out_field_string (uiout, "details", extra_info);
469 ui_out_text (uiout, ")");
470 }
471 ui_out_text (uiout, " ");
472 /* That switch put us at the top of the stack (leaf frame). */
473 switch_to_thread (tp->ptid);
474 print_stack_frame (get_selected_frame (NULL),
475 /* For MI output, print frame level. */
476 ui_out_is_mi_like_p (uiout),
477 LOCATION);
478
479 do_cleanups (chain2);
480 }
481
482 /* Restores the current thread and the frame selected before
483 the "info threads" command. */
484 do_cleanups (old_chain);
485
486 if (requested_thread == -1)
487 {
488 gdb_assert (current_thread != -1 || !thread_list);
489 if (current_thread != -1 && ui_out_is_mi_like_p (uiout))
490 ui_out_field_int (uiout, "current-thread-id", current_thread);
491 }
492
493 /* If case we were not able to find the original frame, print the
494 new selected frame. */
495 if (frame_find_by_id (saved_frame_id) == NULL)
496 {
497 warning (_("Couldn't restore frame in current thread, at frame 0"));
498 /* For MI, we should probably have a notification about
499 current frame change. But this error is not very likely, so
500 don't bother for now. */
501 if (!ui_out_is_mi_like_p (uiout))
502 print_stack_frame (get_selected_frame (NULL), 0, LOCATION);
503 }
504 }
505
506
507 /* Print information about currently known threads
508
509 * Note: this has the drawback that it _really_ switches
510 * threads, which frees the frame cache. A no-side
511 * effects info-threads command would be nicer.
512 */
513
514 static void
515 info_threads_command (char *arg, int from_tty)
516 {
517 print_thread_info (uiout, -1);
518 }
519
520 /* Switch from one thread to another. */
521
522 void
523 switch_to_thread (ptid_t ptid)
524 {
525 if (ptid_equal (ptid, inferior_ptid))
526 return;
527
528 inferior_ptid = ptid;
529 reinit_frame_cache ();
530 registers_changed ();
531 stop_pc = read_pc ();
532 }
533
534 static void
535 restore_current_thread (ptid_t ptid)
536 {
537 if (!ptid_equal (ptid, inferior_ptid))
538 {
539 switch_to_thread (ptid);
540 }
541 }
542
543 static void
544 restore_selected_frame (struct frame_id a_frame_id)
545 {
546 struct frame_info *selected_frame_info = NULL;
547
548 if (frame_id_eq (a_frame_id, null_frame_id))
549 return;
550
551 if ((selected_frame_info = frame_find_by_id (a_frame_id)) != NULL)
552 {
553 select_frame (selected_frame_info);
554 }
555 }
556
557 struct current_thread_cleanup
558 {
559 ptid_t inferior_ptid;
560 struct frame_id selected_frame_id;
561 };
562
563 static void
564 do_restore_current_thread_cleanup (void *arg)
565 {
566 struct current_thread_cleanup *old = arg;
567 restore_current_thread (old->inferior_ptid);
568 restore_selected_frame (old->selected_frame_id);
569 xfree (old);
570 }
571
572 struct cleanup *
573 make_cleanup_restore_current_thread (ptid_t inferior_ptid,
574 struct frame_id a_frame_id)
575 {
576 struct current_thread_cleanup *old
577 = xmalloc (sizeof (struct current_thread_cleanup));
578 old->inferior_ptid = inferior_ptid;
579 old->selected_frame_id = a_frame_id;
580 return make_cleanup (do_restore_current_thread_cleanup, old);
581 }
582
583 /* Apply a GDB command to a list of threads. List syntax is a whitespace
584 seperated list of numbers, or ranges, or the keyword `all'. Ranges consist
585 of two numbers seperated by a hyphen. Examples:
586
587 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
588 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
589 thread apply all p x/i $pc Apply x/i $pc cmd to all threads
590 */
591
592 static void
593 thread_apply_all_command (char *cmd, int from_tty)
594 {
595 struct thread_info *tp;
596 struct cleanup *old_chain;
597 struct cleanup *saved_cmd_cleanup_chain;
598 char *saved_cmd;
599 struct frame_id saved_frame_id;
600 ptid_t current_ptid;
601 int thread_has_changed = 0;
602
603 if (cmd == NULL || *cmd == '\000')
604 error (_("Please specify a command following the thread ID list"));
605
606 current_ptid = inferior_ptid;
607 saved_frame_id = get_frame_id (get_selected_frame (NULL));
608 old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
609
610 /* It is safe to update the thread list now, before
611 traversing it for "thread apply all". MVS */
612 target_find_new_threads ();
613
614 /* Save a copy of the command in case it is clobbered by
615 execute_command */
616 saved_cmd = xstrdup (cmd);
617 saved_cmd_cleanup_chain = make_cleanup (xfree, (void *) saved_cmd);
618 for (tp = thread_list; tp; tp = tp->next)
619 if (thread_alive (tp))
620 {
621 switch_to_thread (tp->ptid);
622 printf_filtered (_("\nThread %d (%s):\n"),
623 tp->num, target_tid_to_str (inferior_ptid));
624 execute_command (cmd, from_tty);
625 strcpy (cmd, saved_cmd); /* Restore exact command used previously */
626 }
627
628 if (!ptid_equal (current_ptid, inferior_ptid))
629 thread_has_changed = 1;
630
631 do_cleanups (saved_cmd_cleanup_chain);
632 do_cleanups (old_chain);
633 /* Print stack frame only if we changed thread. */
634 if (thread_has_changed)
635 print_stack_frame (get_current_frame (), 1, SRC_LINE);
636
637 }
638
639 static void
640 thread_apply_command (char *tidlist, int from_tty)
641 {
642 char *cmd;
643 char *p;
644 struct cleanup *old_chain;
645 struct cleanup *saved_cmd_cleanup_chain;
646 char *saved_cmd;
647 struct frame_id saved_frame_id;
648 ptid_t current_ptid;
649 int thread_has_changed = 0;
650
651 if (tidlist == NULL || *tidlist == '\000')
652 error (_("Please specify a thread ID list"));
653
654 for (cmd = tidlist; *cmd != '\000' && !isalpha (*cmd); cmd++);
655
656 if (*cmd == '\000')
657 error (_("Please specify a command following the thread ID list"));
658
659 current_ptid = inferior_ptid;
660 saved_frame_id = get_frame_id (get_selected_frame (NULL));
661 old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
662
663 /* Save a copy of the command in case it is clobbered by
664 execute_command */
665 saved_cmd = xstrdup (cmd);
666 saved_cmd_cleanup_chain = make_cleanup (xfree, (void *) saved_cmd);
667 while (tidlist < cmd)
668 {
669 struct thread_info *tp;
670 int start, end;
671
672 start = strtol (tidlist, &p, 10);
673 if (p == tidlist)
674 error (_("Error parsing %s"), tidlist);
675 tidlist = p;
676
677 while (*tidlist == ' ' || *tidlist == '\t')
678 tidlist++;
679
680 if (*tidlist == '-') /* Got a range of IDs? */
681 {
682 tidlist++; /* Skip the - */
683 end = strtol (tidlist, &p, 10);
684 if (p == tidlist)
685 error (_("Error parsing %s"), tidlist);
686 tidlist = p;
687
688 while (*tidlist == ' ' || *tidlist == '\t')
689 tidlist++;
690 }
691 else
692 end = start;
693
694 for (; start <= end; start++)
695 {
696 tp = find_thread_id (start);
697
698 if (!tp)
699 warning (_("Unknown thread %d."), start);
700 else if (!thread_alive (tp))
701 warning (_("Thread %d has terminated."), start);
702 else
703 {
704 switch_to_thread (tp->ptid);
705 printf_filtered (_("\nThread %d (%s):\n"), tp->num,
706 target_tid_to_str (inferior_ptid));
707 execute_command (cmd, from_tty);
708 strcpy (cmd, saved_cmd); /* Restore exact command used previously */
709 }
710 }
711 }
712
713 if (!ptid_equal (current_ptid, inferior_ptid))
714 thread_has_changed = 1;
715
716 do_cleanups (saved_cmd_cleanup_chain);
717 do_cleanups (old_chain);
718 /* Print stack frame only if we changed thread. */
719 if (thread_has_changed)
720 print_stack_frame (get_current_frame (), 1, SRC_LINE);
721 }
722
723 /* Switch to the specified thread. Will dispatch off to thread_apply_command
724 if prefix of arg is `apply'. */
725
726 static void
727 thread_command (char *tidstr, int from_tty)
728 {
729 if (!tidstr)
730 {
731 /* Don't generate an error, just say which thread is current. */
732 if (target_has_stack)
733 printf_filtered (_("[Current thread is %d (%s)]\n"),
734 pid_to_thread_id (inferior_ptid),
735 target_tid_to_str (inferior_ptid));
736 else
737 error (_("No stack."));
738 return;
739 }
740
741 gdb_thread_select (uiout, tidstr, NULL);
742 }
743
744 /* Print notices when new threads are attached and detached. */
745 int print_thread_events = 1;
746 static void
747 show_print_thread_events (struct ui_file *file, int from_tty,
748 struct cmd_list_element *c, const char *value)
749 {
750 fprintf_filtered (file, _("\
751 Printing of thread events is %s.\n"),
752 value);
753 }
754
755 static int
756 do_captured_thread_select (struct ui_out *uiout, void *tidstr)
757 {
758 int num;
759 struct thread_info *tp;
760
761 num = value_as_long (parse_and_eval (tidstr));
762
763 tp = find_thread_id (num);
764
765 if (!tp)
766 error (_("Thread ID %d not known."), num);
767
768 if (!thread_alive (tp))
769 error (_("Thread ID %d has terminated."), num);
770
771 switch_to_thread (tp->ptid);
772
773 ui_out_text (uiout, "[Switching to thread ");
774 ui_out_field_int (uiout, "new-thread-id", pid_to_thread_id (inferior_ptid));
775 ui_out_text (uiout, " (");
776 ui_out_text (uiout, target_tid_to_str (inferior_ptid));
777 ui_out_text (uiout, ")]");
778
779 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
780 return GDB_RC_OK;
781 }
782
783 enum gdb_rc
784 gdb_thread_select (struct ui_out *uiout, char *tidstr, char **error_message)
785 {
786 if (catch_exceptions_with_msg (uiout, do_captured_thread_select, tidstr,
787 error_message, RETURN_MASK_ALL) < 0)
788 return GDB_RC_FAIL;
789 return GDB_RC_OK;
790 }
791
792 /* Commands with a prefix of `thread'. */
793 struct cmd_list_element *thread_cmd_list = NULL;
794
795 void
796 _initialize_thread (void)
797 {
798 static struct cmd_list_element *thread_apply_list = NULL;
799
800 add_info ("threads", info_threads_command,
801 _("IDs of currently known threads."));
802
803 add_prefix_cmd ("thread", class_run, thread_command, _("\
804 Use this command to switch between threads.\n\
805 The new thread ID must be currently known."),
806 &thread_cmd_list, "thread ", 1, &cmdlist);
807
808 add_prefix_cmd ("apply", class_run, thread_apply_command,
809 _("Apply a command to a list of threads."),
810 &thread_apply_list, "thread apply ", 1, &thread_cmd_list);
811
812 add_cmd ("all", class_run, thread_apply_all_command,
813 _("Apply a command to all threads."), &thread_apply_list);
814
815 if (!xdb_commands)
816 add_com_alias ("t", "thread", class_run, 1);
817
818 add_setshow_boolean_cmd ("thread-events", no_class,
819 &print_thread_events, _("\
820 Set printing of thread events (e.g., thread start and exit)."), _("\
821 Show printing of thread events (e.g., thread start and exit)."), NULL,
822 NULL,
823 show_print_thread_events,
824 &setprintlist, &showprintlist);
825 }
This page took 0.045387 seconds and 4 git commands to generate.