Make single-step breakpoints be per-thread
[deliverable/binutils-gdb.git] / gdb / thread.c
1 /* Multi-process/thread control for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2014 Free Software Foundation, Inc.
4
5 Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA.
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
22 #include "defs.h"
23 #include "symtab.h"
24 #include "frame.h"
25 #include "inferior.h"
26 #include "environ.h"
27 #include "value.h"
28 #include "target.h"
29 #include "gdbthread.h"
30 #include "command.h"
31 #include "gdbcmd.h"
32 #include "regcache.h"
33 #include "gdb.h"
34 #include "btrace.h"
35
36 #include <ctype.h>
37 #include <sys/types.h>
38 #include <signal.h>
39 #include "ui-out.h"
40 #include "observer.h"
41 #include "annotate.h"
42 #include "cli/cli-decode.h"
43 #include "gdb_regex.h"
44 #include "cli/cli-utils.h"
45 #include "continuations.h"
46
47 /* Definition of struct thread_info exported to gdbthread.h. */
48
49 /* Prototypes for exported functions. */
50
51 void _initialize_thread (void);
52
53 /* Prototypes for local functions. */
54
55 struct thread_info *thread_list = NULL;
56 static int highest_thread_num;
57
58 /* True if any thread is, or may be executing. We need to track this
59 separately because until we fully sync the thread list, we won't
60 know whether the target is fully stopped, even if we see stop
61 events for all known threads, because any of those threads may have
62 spawned new threads we haven't heard of yet. */
63 static int threads_executing;
64
65 static void thread_command (char *tidstr, int from_tty);
66 static void thread_apply_all_command (char *, int);
67 static int thread_alive (struct thread_info *);
68 static void info_threads_command (char *, int);
69 static void thread_apply_command (char *, int);
70 static void restore_current_thread (ptid_t);
71 static void prune_threads (void);
72
73 /* Data to cleanup thread array. */
74
75 struct thread_array_cleanup
76 {
77 /* Array of thread pointers used to set
78 reference count. */
79 struct thread_info **tp_array;
80
81 /* Thread count in the array. */
82 int count;
83 };
84
85
86 struct thread_info*
87 inferior_thread (void)
88 {
89 struct thread_info *tp = find_thread_ptid (inferior_ptid);
90 gdb_assert (tp);
91 return tp;
92 }
93
94 /* Delete the breakpoint pointed at by BP_P, if there's one. */
95
96 static void
97 delete_thread_breakpoint (struct breakpoint **bp_p)
98 {
99 if (*bp_p != NULL)
100 {
101 delete_breakpoint (*bp_p);
102 *bp_p = NULL;
103 }
104 }
105
106 void
107 delete_step_resume_breakpoint (struct thread_info *tp)
108 {
109 if (tp != NULL)
110 delete_thread_breakpoint (&tp->control.step_resume_breakpoint);
111 }
112
113 void
114 delete_exception_resume_breakpoint (struct thread_info *tp)
115 {
116 if (tp != NULL)
117 delete_thread_breakpoint (&tp->control.exception_resume_breakpoint);
118 }
119
120 /* See gdbthread.h. */
121
122 void
123 delete_single_step_breakpoints (struct thread_info *tp)
124 {
125 if (tp != NULL)
126 delete_thread_breakpoint (&tp->control.single_step_breakpoints);
127 }
128
129 /* Delete the breakpoint pointed at by BP_P at the next stop, if
130 there's one. */
131
132 static void
133 delete_at_next_stop (struct breakpoint **bp)
134 {
135 if (*bp != NULL)
136 {
137 (*bp)->disposition = disp_del_at_next_stop;
138 *bp = NULL;
139 }
140 }
141
142 /* See gdbthread.h. */
143
144 int
145 thread_has_single_step_breakpoints_set (struct thread_info *tp)
146 {
147 return tp->control.single_step_breakpoints != NULL;
148 }
149
150 /* See gdbthread.h. */
151
152 int
153 thread_has_single_step_breakpoint_here (struct thread_info *tp,
154 struct address_space *aspace,
155 CORE_ADDR addr)
156 {
157 struct breakpoint *ss_bps = tp->control.single_step_breakpoints;
158
159 return (ss_bps != NULL
160 && breakpoint_has_location_inserted_here (ss_bps, aspace, addr));
161 }
162
163 static void
164 clear_thread_inferior_resources (struct thread_info *tp)
165 {
166 /* NOTE: this will take care of any left-over step_resume breakpoints,
167 but not any user-specified thread-specific breakpoints. We can not
168 delete the breakpoint straight-off, because the inferior might not
169 be stopped at the moment. */
170 delete_at_next_stop (&tp->control.step_resume_breakpoint);
171 delete_at_next_stop (&tp->control.exception_resume_breakpoint);
172 delete_at_next_stop (&tp->control.single_step_breakpoints);
173
174 delete_longjmp_breakpoint_at_next_stop (tp->num);
175
176 bpstat_clear (&tp->control.stop_bpstat);
177
178 btrace_teardown (tp);
179
180 do_all_intermediate_continuations_thread (tp, 1);
181 do_all_continuations_thread (tp, 1);
182 }
183
184 static void
185 free_thread (struct thread_info *tp)
186 {
187 if (tp->private)
188 {
189 if (tp->private_dtor)
190 tp->private_dtor (tp->private);
191 else
192 xfree (tp->private);
193 }
194
195 xfree (tp->name);
196 xfree (tp);
197 }
198
199 void
200 init_thread_list (void)
201 {
202 struct thread_info *tp, *tpnext;
203
204 highest_thread_num = 0;
205
206 if (!thread_list)
207 return;
208
209 for (tp = thread_list; tp; tp = tpnext)
210 {
211 tpnext = tp->next;
212 free_thread (tp);
213 }
214
215 thread_list = NULL;
216 threads_executing = 0;
217 }
218
219 /* Allocate a new thread with target id PTID and add it to the thread
220 list. */
221
222 static struct thread_info *
223 new_thread (ptid_t ptid)
224 {
225 struct thread_info *tp;
226
227 tp = xcalloc (1, sizeof (*tp));
228
229 tp->ptid = ptid;
230 tp->num = ++highest_thread_num;
231 tp->next = thread_list;
232 thread_list = tp;
233
234 /* Nothing to follow yet. */
235 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
236 tp->state = THREAD_STOPPED;
237
238 return tp;
239 }
240
241 struct thread_info *
242 add_thread_silent (ptid_t ptid)
243 {
244 struct thread_info *tp;
245
246 tp = find_thread_ptid (ptid);
247 if (tp)
248 /* Found an old thread with the same id. It has to be dead,
249 otherwise we wouldn't be adding a new thread with the same id.
250 The OS is reusing this id --- delete it, and recreate a new
251 one. */
252 {
253 /* In addition to deleting the thread, if this is the current
254 thread, then we need to take care that delete_thread doesn't
255 really delete the thread if it is inferior_ptid. Create a
256 new template thread in the list with an invalid ptid, switch
257 to it, delete the original thread, reset the new thread's
258 ptid, and switch to it. */
259
260 if (ptid_equal (inferior_ptid, ptid))
261 {
262 tp = new_thread (null_ptid);
263
264 /* Make switch_to_thread not read from the thread. */
265 tp->state = THREAD_EXITED;
266 switch_to_thread (null_ptid);
267
268 /* Now we can delete it. */
269 delete_thread (ptid);
270
271 /* Now reset its ptid, and reswitch inferior_ptid to it. */
272 tp->ptid = ptid;
273 tp->state = THREAD_STOPPED;
274 switch_to_thread (ptid);
275
276 observer_notify_new_thread (tp);
277
278 /* All done. */
279 return tp;
280 }
281 else
282 /* Just go ahead and delete it. */
283 delete_thread (ptid);
284 }
285
286 tp = new_thread (ptid);
287 observer_notify_new_thread (tp);
288
289 return tp;
290 }
291
292 struct thread_info *
293 add_thread_with_info (ptid_t ptid, struct private_thread_info *private)
294 {
295 struct thread_info *result = add_thread_silent (ptid);
296
297 result->private = private;
298
299 if (print_thread_events)
300 printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
301
302 annotate_new_thread ();
303 return result;
304 }
305
306 struct thread_info *
307 add_thread (ptid_t ptid)
308 {
309 return add_thread_with_info (ptid, NULL);
310 }
311
312 /* Delete thread PTID. If SILENT, don't notify the observer of this
313 exit. */
314 static void
315 delete_thread_1 (ptid_t ptid, int silent)
316 {
317 struct thread_info *tp, *tpprev;
318
319 tpprev = NULL;
320
321 for (tp = thread_list; tp; tpprev = tp, tp = tp->next)
322 if (ptid_equal (tp->ptid, ptid))
323 break;
324
325 if (!tp)
326 return;
327
328 /* If this is the current thread, or there's code out there that
329 relies on it existing (refcount > 0) we can't delete yet. Mark
330 it as exited, and notify it. */
331 if (tp->refcount > 0
332 || ptid_equal (tp->ptid, inferior_ptid))
333 {
334 if (tp->state != THREAD_EXITED)
335 {
336 observer_notify_thread_exit (tp, silent);
337
338 /* Tag it as exited. */
339 tp->state = THREAD_EXITED;
340
341 /* Clear breakpoints, etc. associated with this thread. */
342 clear_thread_inferior_resources (tp);
343 }
344
345 /* Will be really deleted some other time. */
346 return;
347 }
348
349 /* Notify thread exit, but only if we haven't already. */
350 if (tp->state != THREAD_EXITED)
351 observer_notify_thread_exit (tp, silent);
352
353 /* Tag it as exited. */
354 tp->state = THREAD_EXITED;
355 clear_thread_inferior_resources (tp);
356
357 if (tpprev)
358 tpprev->next = tp->next;
359 else
360 thread_list = tp->next;
361
362 free_thread (tp);
363 }
364
365 /* Delete thread PTID and notify of thread exit. If this is
366 inferior_ptid, don't actually delete it, but tag it as exited and
367 do the notification. If PTID is the user selected thread, clear
368 it. */
369 void
370 delete_thread (ptid_t ptid)
371 {
372 delete_thread_1 (ptid, 0 /* not silent */);
373 }
374
375 void
376 delete_thread_silent (ptid_t ptid)
377 {
378 delete_thread_1 (ptid, 1 /* silent */);
379 }
380
381 struct thread_info *
382 find_thread_id (int num)
383 {
384 struct thread_info *tp;
385
386 for (tp = thread_list; tp; tp = tp->next)
387 if (tp->num == num)
388 return tp;
389
390 return NULL;
391 }
392
393 /* Find a thread_info by matching PTID. */
394 struct thread_info *
395 find_thread_ptid (ptid_t ptid)
396 {
397 struct thread_info *tp;
398
399 for (tp = thread_list; tp; tp = tp->next)
400 if (ptid_equal (tp->ptid, ptid))
401 return tp;
402
403 return NULL;
404 }
405
406 /*
407 * Thread iterator function.
408 *
409 * Calls a callback function once for each thread, so long as
410 * the callback function returns false. If the callback function
411 * returns true, the iteration will end and the current thread
412 * will be returned. This can be useful for implementing a
413 * search for a thread with arbitrary attributes, or for applying
414 * some operation to every thread.
415 *
416 * FIXME: some of the existing functionality, such as
417 * "Thread apply all", might be rewritten using this functionality.
418 */
419
420 struct thread_info *
421 iterate_over_threads (int (*callback) (struct thread_info *, void *),
422 void *data)
423 {
424 struct thread_info *tp, *next;
425
426 for (tp = thread_list; tp; tp = next)
427 {
428 next = tp->next;
429 if ((*callback) (tp, data))
430 return tp;
431 }
432
433 return NULL;
434 }
435
436 int
437 thread_count (void)
438 {
439 int result = 0;
440 struct thread_info *tp;
441
442 for (tp = thread_list; tp; tp = tp->next)
443 ++result;
444
445 return result;
446 }
447
448 int
449 valid_thread_id (int num)
450 {
451 struct thread_info *tp;
452
453 for (tp = thread_list; tp; tp = tp->next)
454 if (tp->num == num)
455 return 1;
456
457 return 0;
458 }
459
460 int
461 pid_to_thread_id (ptid_t ptid)
462 {
463 struct thread_info *tp;
464
465 for (tp = thread_list; tp; tp = tp->next)
466 if (ptid_equal (tp->ptid, ptid))
467 return tp->num;
468
469 return 0;
470 }
471
472 ptid_t
473 thread_id_to_pid (int num)
474 {
475 struct thread_info *thread = find_thread_id (num);
476
477 if (thread)
478 return thread->ptid;
479 else
480 return pid_to_ptid (-1);
481 }
482
483 int
484 in_thread_list (ptid_t ptid)
485 {
486 struct thread_info *tp;
487
488 for (tp = thread_list; tp; tp = tp->next)
489 if (ptid_equal (tp->ptid, ptid))
490 return 1;
491
492 return 0; /* Never heard of 'im. */
493 }
494
495 /* Finds the first thread of the inferior given by PID. If PID is -1,
496 return the first thread in the list. */
497
498 struct thread_info *
499 first_thread_of_process (int pid)
500 {
501 struct thread_info *tp, *ret = NULL;
502
503 for (tp = thread_list; tp; tp = tp->next)
504 if (pid == -1 || ptid_get_pid (tp->ptid) == pid)
505 if (ret == NULL || tp->num < ret->num)
506 ret = tp;
507
508 return ret;
509 }
510
511 struct thread_info *
512 any_thread_of_process (int pid)
513 {
514 struct thread_info *tp;
515
516 gdb_assert (pid != 0);
517
518 /* Prefer the current thread. */
519 if (ptid_get_pid (inferior_ptid) == pid)
520 return inferior_thread ();
521
522 ALL_NON_EXITED_THREADS (tp)
523 if (ptid_get_pid (tp->ptid) == pid)
524 return tp;
525
526 return NULL;
527 }
528
529 struct thread_info *
530 any_live_thread_of_process (int pid)
531 {
532 struct thread_info *curr_tp = NULL;
533 struct thread_info *tp;
534 struct thread_info *tp_executing = NULL;
535
536 gdb_assert (pid != 0);
537
538 /* Prefer the current thread if it's not executing. */
539 if (ptid_get_pid (inferior_ptid) == pid)
540 {
541 /* If the current thread is dead, forget it. If it's not
542 executing, use it. Otherwise, still choose it (below), but
543 only if no other non-executing thread is found. */
544 curr_tp = inferior_thread ();
545 if (curr_tp->state == THREAD_EXITED)
546 curr_tp = NULL;
547 else if (!curr_tp->executing)
548 return curr_tp;
549 }
550
551 ALL_NON_EXITED_THREADS (tp)
552 if (ptid_get_pid (tp->ptid) == pid)
553 {
554 if (!tp->executing)
555 return tp;
556
557 tp_executing = tp;
558 }
559
560 /* If both the current thread and all live threads are executing,
561 prefer the current thread. */
562 if (curr_tp != NULL)
563 return curr_tp;
564
565 /* Otherwise, just return an executing thread, if any. */
566 return tp_executing;
567 }
568
569 /* Print a list of thread ids currently known, and the total number of
570 threads. To be used from within catch_errors. */
571 static int
572 do_captured_list_thread_ids (struct ui_out *uiout, void *arg)
573 {
574 struct thread_info *tp;
575 int num = 0;
576 struct cleanup *cleanup_chain;
577 int current_thread = -1;
578
579 update_thread_list ();
580
581 cleanup_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "thread-ids");
582
583 for (tp = thread_list; tp; tp = tp->next)
584 {
585 if (tp->state == THREAD_EXITED)
586 continue;
587
588 if (ptid_equal (tp->ptid, inferior_ptid))
589 current_thread = tp->num;
590
591 num++;
592 ui_out_field_int (uiout, "thread-id", tp->num);
593 }
594
595 do_cleanups (cleanup_chain);
596
597 if (current_thread != -1)
598 ui_out_field_int (uiout, "current-thread-id", current_thread);
599 ui_out_field_int (uiout, "number-of-threads", num);
600 return GDB_RC_OK;
601 }
602
603 /* Official gdblib interface function to get a list of thread ids and
604 the total number. */
605 enum gdb_rc
606 gdb_list_thread_ids (struct ui_out *uiout, char **error_message)
607 {
608 if (catch_exceptions_with_msg (uiout, do_captured_list_thread_ids, NULL,
609 error_message, RETURN_MASK_ALL) < 0)
610 return GDB_RC_FAIL;
611 return GDB_RC_OK;
612 }
613
614 /* Return true if TP is an active thread. */
615 static int
616 thread_alive (struct thread_info *tp)
617 {
618 if (tp->state == THREAD_EXITED)
619 return 0;
620 if (!target_thread_alive (tp->ptid))
621 return 0;
622 return 1;
623 }
624
625 static void
626 prune_threads (void)
627 {
628 struct thread_info *tp, *next;
629
630 for (tp = thread_list; tp; tp = next)
631 {
632 next = tp->next;
633 if (!thread_alive (tp))
634 delete_thread (tp->ptid);
635 }
636 }
637
638 void
639 thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid)
640 {
641 struct inferior *inf;
642 struct thread_info *tp;
643
644 /* It can happen that what we knew as the target inferior id
645 changes. E.g, target remote may only discover the remote process
646 pid after adding the inferior to GDB's list. */
647 inf = find_inferior_pid (ptid_get_pid (old_ptid));
648 inf->pid = ptid_get_pid (new_ptid);
649
650 tp = find_thread_ptid (old_ptid);
651 tp->ptid = new_ptid;
652
653 observer_notify_thread_ptid_changed (old_ptid, new_ptid);
654 }
655
656 void
657 set_running (ptid_t ptid, int running)
658 {
659 struct thread_info *tp;
660 int all = ptid_equal (ptid, minus_one_ptid);
661
662 /* We try not to notify the observer if no thread has actually changed
663 the running state -- merely to reduce the number of messages to
664 frontend. Frontend is supposed to handle multiple *running just fine. */
665 if (all || ptid_is_pid (ptid))
666 {
667 int any_started = 0;
668
669 for (tp = thread_list; tp; tp = tp->next)
670 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
671 {
672 if (tp->state == THREAD_EXITED)
673 continue;
674 if (running && tp->state == THREAD_STOPPED)
675 any_started = 1;
676 tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
677 }
678 if (any_started)
679 observer_notify_target_resumed (ptid);
680 }
681 else
682 {
683 int started = 0;
684
685 tp = find_thread_ptid (ptid);
686 gdb_assert (tp);
687 gdb_assert (tp->state != THREAD_EXITED);
688 if (running && tp->state == THREAD_STOPPED)
689 started = 1;
690 tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
691 if (started)
692 observer_notify_target_resumed (ptid);
693 }
694 }
695
696 static int
697 is_thread_state (ptid_t ptid, enum thread_state state)
698 {
699 struct thread_info *tp;
700
701 tp = find_thread_ptid (ptid);
702 gdb_assert (tp);
703 return tp->state == state;
704 }
705
706 int
707 is_stopped (ptid_t ptid)
708 {
709 return is_thread_state (ptid, THREAD_STOPPED);
710 }
711
712 int
713 is_exited (ptid_t ptid)
714 {
715 return is_thread_state (ptid, THREAD_EXITED);
716 }
717
718 int
719 is_running (ptid_t ptid)
720 {
721 return is_thread_state (ptid, THREAD_RUNNING);
722 }
723
724 int
725 is_executing (ptid_t ptid)
726 {
727 struct thread_info *tp;
728
729 tp = find_thread_ptid (ptid);
730 gdb_assert (tp);
731 return tp->executing;
732 }
733
734 void
735 set_executing (ptid_t ptid, int executing)
736 {
737 struct thread_info *tp;
738 int all = ptid_equal (ptid, minus_one_ptid);
739
740 if (all || ptid_is_pid (ptid))
741 {
742 for (tp = thread_list; tp; tp = tp->next)
743 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
744 tp->executing = executing;
745 }
746 else
747 {
748 tp = find_thread_ptid (ptid);
749 gdb_assert (tp);
750 tp->executing = executing;
751 }
752
753 /* It only takes one running thread to spawn more threads.*/
754 if (executing)
755 threads_executing = 1;
756 /* Only clear the flag if the caller is telling us everything is
757 stopped. */
758 else if (ptid_equal (minus_one_ptid, ptid))
759 threads_executing = 0;
760 }
761
762 /* See gdbthread.h. */
763
764 int
765 threads_are_executing (void)
766 {
767 return threads_executing;
768 }
769
770 void
771 set_stop_requested (ptid_t ptid, int stop)
772 {
773 struct thread_info *tp;
774 int all = ptid_equal (ptid, minus_one_ptid);
775
776 if (all || ptid_is_pid (ptid))
777 {
778 for (tp = thread_list; tp; tp = tp->next)
779 if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
780 tp->stop_requested = stop;
781 }
782 else
783 {
784 tp = find_thread_ptid (ptid);
785 gdb_assert (tp);
786 tp->stop_requested = stop;
787 }
788
789 /* Call the stop requested observer so other components of GDB can
790 react to this request. */
791 if (stop)
792 observer_notify_thread_stop_requested (ptid);
793 }
794
795 void
796 finish_thread_state (ptid_t ptid)
797 {
798 struct thread_info *tp;
799 int all;
800 int any_started = 0;
801
802 all = ptid_equal (ptid, minus_one_ptid);
803
804 if (all || ptid_is_pid (ptid))
805 {
806 for (tp = thread_list; tp; tp = tp->next)
807 {
808 if (tp->state == THREAD_EXITED)
809 continue;
810 if (all || ptid_get_pid (ptid) == ptid_get_pid (tp->ptid))
811 {
812 if (tp->executing && tp->state == THREAD_STOPPED)
813 any_started = 1;
814 tp->state = tp->executing ? THREAD_RUNNING : THREAD_STOPPED;
815 }
816 }
817 }
818 else
819 {
820 tp = find_thread_ptid (ptid);
821 gdb_assert (tp);
822 if (tp->state != THREAD_EXITED)
823 {
824 if (tp->executing && tp->state == THREAD_STOPPED)
825 any_started = 1;
826 tp->state = tp->executing ? THREAD_RUNNING : THREAD_STOPPED;
827 }
828 }
829
830 if (any_started)
831 observer_notify_target_resumed (ptid);
832 }
833
834 void
835 finish_thread_state_cleanup (void *arg)
836 {
837 ptid_t *ptid_p = arg;
838
839 gdb_assert (arg);
840
841 finish_thread_state (*ptid_p);
842 }
843
844 int
845 pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread)
846 {
847 return (pc >= thread->control.step_range_start
848 && pc < thread->control.step_range_end);
849 }
850
851 /* Prints the list of threads and their details on UIOUT.
852 This is a version of 'info_threads_command' suitable for
853 use from MI.
854 If REQUESTED_THREAD is not -1, it's the GDB id of the thread
855 that should be printed. Otherwise, all threads are
856 printed.
857 If PID is not -1, only print threads from the process PID.
858 Otherwise, threads from all attached PIDs are printed.
859 If both REQUESTED_THREAD and PID are not -1, then the thread
860 is printed if it belongs to the specified process. Otherwise,
861 an error is raised. */
862 void
863 print_thread_info (struct ui_out *uiout, char *requested_threads, int pid)
864 {
865 struct thread_info *tp;
866 ptid_t current_ptid;
867 struct cleanup *old_chain;
868 char *extra_info, *name, *target_id;
869 int current_thread = -1;
870
871 update_thread_list ();
872 current_ptid = inferior_ptid;
873
874 /* We'll be switching threads temporarily. */
875 old_chain = make_cleanup_restore_current_thread ();
876
877 /* For backward compatibility, we make a list for MI. A table is
878 preferable for the CLI, though, because it shows table
879 headers. */
880 if (ui_out_is_mi_like_p (uiout))
881 make_cleanup_ui_out_list_begin_end (uiout, "threads");
882 else
883 {
884 int n_threads = 0;
885
886 for (tp = thread_list; tp; tp = tp->next)
887 {
888 if (!number_is_in_list (requested_threads, tp->num))
889 continue;
890
891 if (pid != -1 && ptid_get_pid (tp->ptid) != pid)
892 continue;
893
894 if (tp->state == THREAD_EXITED)
895 continue;
896
897 ++n_threads;
898 }
899
900 if (n_threads == 0)
901 {
902 if (requested_threads == NULL || *requested_threads == '\0')
903 ui_out_message (uiout, 0, _("No threads.\n"));
904 else
905 ui_out_message (uiout, 0, _("No threads match '%s'.\n"),
906 requested_threads);
907 do_cleanups (old_chain);
908 return;
909 }
910
911 make_cleanup_ui_out_table_begin_end (uiout, 4, n_threads, "threads");
912
913 ui_out_table_header (uiout, 1, ui_left, "current", "");
914 ui_out_table_header (uiout, 4, ui_left, "id", "Id");
915 ui_out_table_header (uiout, 17, ui_left, "target-id", "Target Id");
916 ui_out_table_header (uiout, 1, ui_left, "frame", "Frame");
917 ui_out_table_body (uiout);
918 }
919
920 for (tp = thread_list; tp; tp = tp->next)
921 {
922 struct cleanup *chain2;
923 int core;
924
925 if (!number_is_in_list (requested_threads, tp->num))
926 continue;
927
928 if (pid != -1 && ptid_get_pid (tp->ptid) != pid)
929 {
930 if (requested_threads != NULL && *requested_threads != '\0')
931 error (_("Requested thread not found in requested process"));
932 continue;
933 }
934
935 if (ptid_equal (tp->ptid, current_ptid))
936 current_thread = tp->num;
937
938 if (tp->state == THREAD_EXITED)
939 continue;
940
941 chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
942
943 if (ui_out_is_mi_like_p (uiout))
944 {
945 /* Compatibility. */
946 if (ptid_equal (tp->ptid, current_ptid))
947 ui_out_text (uiout, "* ");
948 else
949 ui_out_text (uiout, " ");
950 }
951 else
952 {
953 if (ptid_equal (tp->ptid, current_ptid))
954 ui_out_field_string (uiout, "current", "*");
955 else
956 ui_out_field_skip (uiout, "current");
957 }
958
959 ui_out_field_int (uiout, "id", tp->num);
960
961 /* For the CLI, we stuff everything into the target-id field.
962 This is a gross hack to make the output come out looking
963 correct. The underlying problem here is that ui-out has no
964 way to specify that a field's space allocation should be
965 shared by several fields. For MI, we do the right thing
966 instead. */
967
968 target_id = target_pid_to_str (tp->ptid);
969 extra_info = target_extra_thread_info (tp);
970 name = tp->name ? tp->name : target_thread_name (tp);
971
972 if (ui_out_is_mi_like_p (uiout))
973 {
974 ui_out_field_string (uiout, "target-id", target_id);
975 if (extra_info)
976 ui_out_field_string (uiout, "details", extra_info);
977 if (name)
978 ui_out_field_string (uiout, "name", name);
979 }
980 else
981 {
982 struct cleanup *str_cleanup;
983 char *contents;
984
985 if (extra_info && name)
986 contents = xstrprintf ("%s \"%s\" (%s)", target_id,
987 name, extra_info);
988 else if (extra_info)
989 contents = xstrprintf ("%s (%s)", target_id, extra_info);
990 else if (name)
991 contents = xstrprintf ("%s \"%s\"", target_id, name);
992 else
993 contents = xstrdup (target_id);
994 str_cleanup = make_cleanup (xfree, contents);
995
996 ui_out_field_string (uiout, "target-id", contents);
997 do_cleanups (str_cleanup);
998 }
999
1000 if (tp->state == THREAD_RUNNING)
1001 ui_out_text (uiout, "(running)\n");
1002 else
1003 {
1004 /* The switch below puts us at the top of the stack (leaf
1005 frame). */
1006 switch_to_thread (tp->ptid);
1007 print_stack_frame (get_selected_frame (NULL),
1008 /* For MI output, print frame level. */
1009 ui_out_is_mi_like_p (uiout),
1010 LOCATION, 0);
1011 }
1012
1013 if (ui_out_is_mi_like_p (uiout))
1014 {
1015 char *state = "stopped";
1016
1017 if (tp->state == THREAD_RUNNING)
1018 state = "running";
1019 ui_out_field_string (uiout, "state", state);
1020 }
1021
1022 core = target_core_of_thread (tp->ptid);
1023 if (ui_out_is_mi_like_p (uiout) && core != -1)
1024 ui_out_field_int (uiout, "core", core);
1025
1026 do_cleanups (chain2);
1027 }
1028
1029 /* Restores the current thread and the frame selected before
1030 the "info threads" command. */
1031 do_cleanups (old_chain);
1032
1033 if (pid == -1 && requested_threads == NULL)
1034 {
1035 gdb_assert (current_thread != -1
1036 || !thread_list
1037 || ptid_equal (inferior_ptid, null_ptid));
1038 if (current_thread != -1 && ui_out_is_mi_like_p (uiout))
1039 ui_out_field_int (uiout, "current-thread-id", current_thread);
1040
1041 if (current_thread != -1 && is_exited (current_ptid))
1042 ui_out_message (uiout, 0, "\n\
1043 The current thread <Thread ID %d> has terminated. See `help thread'.\n",
1044 current_thread);
1045 else if (thread_list
1046 && current_thread == -1
1047 && ptid_equal (current_ptid, null_ptid))
1048 ui_out_message (uiout, 0, "\n\
1049 No selected thread. See `help thread'.\n");
1050 }
1051 }
1052
1053 /* Print information about currently known threads
1054
1055 Optional ARG is a thread id, or list of thread ids.
1056
1057 Note: this has the drawback that it _really_ switches
1058 threads, which frees the frame cache. A no-side
1059 effects info-threads command would be nicer. */
1060
1061 static void
1062 info_threads_command (char *arg, int from_tty)
1063 {
1064 print_thread_info (current_uiout, arg, -1);
1065 }
1066
1067 /* Switch from one thread to another. */
1068
1069 void
1070 switch_to_thread (ptid_t ptid)
1071 {
1072 /* Switch the program space as well, if we can infer it from the now
1073 current thread. Otherwise, it's up to the caller to select the
1074 space it wants. */
1075 if (!ptid_equal (ptid, null_ptid))
1076 {
1077 struct inferior *inf;
1078
1079 inf = find_inferior_pid (ptid_get_pid (ptid));
1080 gdb_assert (inf != NULL);
1081 set_current_program_space (inf->pspace);
1082 set_current_inferior (inf);
1083 }
1084
1085 if (ptid_equal (ptid, inferior_ptid))
1086 return;
1087
1088 inferior_ptid = ptid;
1089 reinit_frame_cache ();
1090
1091 /* We don't check for is_stopped, because we're called at times
1092 while in the TARGET_RUNNING state, e.g., while handling an
1093 internal event. */
1094 if (!ptid_equal (inferior_ptid, null_ptid)
1095 && !is_exited (ptid)
1096 && !is_executing (ptid))
1097 stop_pc = regcache_read_pc (get_thread_regcache (ptid));
1098 else
1099 stop_pc = ~(CORE_ADDR) 0;
1100 }
1101
1102 static void
1103 restore_current_thread (ptid_t ptid)
1104 {
1105 switch_to_thread (ptid);
1106 }
1107
1108 static void
1109 restore_selected_frame (struct frame_id a_frame_id, int frame_level)
1110 {
1111 struct frame_info *frame = NULL;
1112 int count;
1113
1114 /* This means there was no selected frame. */
1115 if (frame_level == -1)
1116 {
1117 select_frame (NULL);
1118 return;
1119 }
1120
1121 gdb_assert (frame_level >= 0);
1122
1123 /* Restore by level first, check if the frame id is the same as
1124 expected. If that fails, try restoring by frame id. If that
1125 fails, nothing to do, just warn the user. */
1126
1127 count = frame_level;
1128 frame = find_relative_frame (get_current_frame (), &count);
1129 if (count == 0
1130 && frame != NULL
1131 /* The frame ids must match - either both valid or both outer_frame_id.
1132 The latter case is not failsafe, but since it's highly unlikely
1133 the search by level finds the wrong frame, it's 99.9(9)% of
1134 the time (for all practical purposes) safe. */
1135 && frame_id_eq (get_frame_id (frame), a_frame_id))
1136 {
1137 /* Cool, all is fine. */
1138 select_frame (frame);
1139 return;
1140 }
1141
1142 frame = frame_find_by_id (a_frame_id);
1143 if (frame != NULL)
1144 {
1145 /* Cool, refound it. */
1146 select_frame (frame);
1147 return;
1148 }
1149
1150 /* Nothing else to do, the frame layout really changed. Select the
1151 innermost stack frame. */
1152 select_frame (get_current_frame ());
1153
1154 /* Warn the user. */
1155 if (frame_level > 0 && !ui_out_is_mi_like_p (current_uiout))
1156 {
1157 warning (_("Couldn't restore frame #%d in "
1158 "current thread. Bottom (innermost) frame selected:"),
1159 frame_level);
1160 /* For MI, we should probably have a notification about
1161 current frame change. But this error is not very
1162 likely, so don't bother for now. */
1163 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1164 }
1165 }
1166
1167 struct current_thread_cleanup
1168 {
1169 ptid_t inferior_ptid;
1170 struct frame_id selected_frame_id;
1171 int selected_frame_level;
1172 int was_stopped;
1173 int inf_id;
1174 int was_removable;
1175 };
1176
1177 static void
1178 do_restore_current_thread_cleanup (void *arg)
1179 {
1180 struct thread_info *tp;
1181 struct current_thread_cleanup *old = arg;
1182
1183 tp = find_thread_ptid (old->inferior_ptid);
1184
1185 /* If the previously selected thread belonged to a process that has
1186 in the mean time been deleted (due to normal exit, detach, etc.),
1187 then don't revert back to it, but instead simply drop back to no
1188 thread selected. */
1189 if (tp
1190 && find_inferior_pid (ptid_get_pid (tp->ptid)) != NULL)
1191 restore_current_thread (old->inferior_ptid);
1192 else
1193 {
1194 restore_current_thread (null_ptid);
1195 set_current_inferior (find_inferior_id (old->inf_id));
1196 }
1197
1198 /* The running state of the originally selected thread may have
1199 changed, so we have to recheck it here. */
1200 if (!ptid_equal (inferior_ptid, null_ptid)
1201 && old->was_stopped
1202 && is_stopped (inferior_ptid)
1203 && target_has_registers
1204 && target_has_stack
1205 && target_has_memory)
1206 restore_selected_frame (old->selected_frame_id,
1207 old->selected_frame_level);
1208 }
1209
1210 static void
1211 restore_current_thread_cleanup_dtor (void *arg)
1212 {
1213 struct current_thread_cleanup *old = arg;
1214 struct thread_info *tp;
1215 struct inferior *inf;
1216
1217 tp = find_thread_ptid (old->inferior_ptid);
1218 if (tp)
1219 tp->refcount--;
1220 inf = find_inferior_id (old->inf_id);
1221 if (inf != NULL)
1222 inf->removable = old->was_removable;
1223 xfree (old);
1224 }
1225
1226 /* Set the thread reference count. */
1227
1228 static void
1229 set_thread_refcount (void *data)
1230 {
1231 int k;
1232 struct thread_array_cleanup *ta_cleanup = data;
1233
1234 for (k = 0; k != ta_cleanup->count; k++)
1235 ta_cleanup->tp_array[k]->refcount--;
1236 }
1237
1238 struct cleanup *
1239 make_cleanup_restore_current_thread (void)
1240 {
1241 struct thread_info *tp;
1242 struct frame_info *frame;
1243 struct current_thread_cleanup *old;
1244
1245 old = xmalloc (sizeof (struct current_thread_cleanup));
1246 old->inferior_ptid = inferior_ptid;
1247 old->inf_id = current_inferior ()->num;
1248 old->was_removable = current_inferior ()->removable;
1249
1250 if (!ptid_equal (inferior_ptid, null_ptid))
1251 {
1252 old->was_stopped = is_stopped (inferior_ptid);
1253 if (old->was_stopped
1254 && target_has_registers
1255 && target_has_stack
1256 && target_has_memory)
1257 {
1258 /* When processing internal events, there might not be a
1259 selected frame. If we naively call get_selected_frame
1260 here, then we can end up reading debuginfo for the
1261 current frame, but we don't generally need the debuginfo
1262 at this point. */
1263 frame = get_selected_frame_if_set ();
1264 }
1265 else
1266 frame = NULL;
1267
1268 old->selected_frame_id = get_frame_id (frame);
1269 old->selected_frame_level = frame_relative_level (frame);
1270
1271 tp = find_thread_ptid (inferior_ptid);
1272 if (tp)
1273 tp->refcount++;
1274 }
1275
1276 current_inferior ()->removable = 0;
1277
1278 return make_cleanup_dtor (do_restore_current_thread_cleanup, old,
1279 restore_current_thread_cleanup_dtor);
1280 }
1281
1282 /* Apply a GDB command to a list of threads. List syntax is a whitespace
1283 seperated list of numbers, or ranges, or the keyword `all'. Ranges consist
1284 of two numbers seperated by a hyphen. Examples:
1285
1286 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
1287 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
1288 thread apply all p x/i $pc Apply x/i $pc cmd to all threads. */
1289
1290 static void
1291 thread_apply_all_command (char *cmd, int from_tty)
1292 {
1293 struct cleanup *old_chain;
1294 char *saved_cmd;
1295 int tc;
1296 struct thread_array_cleanup ta_cleanup;
1297
1298 if (cmd == NULL || *cmd == '\000')
1299 error (_("Please specify a command following the thread ID list"));
1300
1301 update_thread_list ();
1302
1303 old_chain = make_cleanup_restore_current_thread ();
1304
1305 /* Save a copy of the command in case it is clobbered by
1306 execute_command. */
1307 saved_cmd = xstrdup (cmd);
1308 make_cleanup (xfree, saved_cmd);
1309 tc = thread_count ();
1310
1311 if (tc)
1312 {
1313 struct thread_info **tp_array;
1314 struct thread_info *tp;
1315 int i = 0, k;
1316
1317 /* Save a copy of the thread_list in case we execute detach
1318 command. */
1319 tp_array = xmalloc (sizeof (struct thread_info *) * tc);
1320 make_cleanup (xfree, tp_array);
1321 ta_cleanup.tp_array = tp_array;
1322 ta_cleanup.count = tc;
1323
1324 ALL_NON_EXITED_THREADS (tp)
1325 {
1326 tp_array[i] = tp;
1327 tp->refcount++;
1328 i++;
1329 }
1330
1331 make_cleanup (set_thread_refcount, &ta_cleanup);
1332
1333 for (k = 0; k != i; k++)
1334 if (thread_alive (tp_array[k]))
1335 {
1336 switch_to_thread (tp_array[k]->ptid);
1337 printf_filtered (_("\nThread %d (%s):\n"),
1338 tp_array[k]->num,
1339 target_pid_to_str (inferior_ptid));
1340 execute_command (cmd, from_tty);
1341
1342 /* Restore exact command used previously. */
1343 strcpy (cmd, saved_cmd);
1344 }
1345 }
1346
1347 do_cleanups (old_chain);
1348 }
1349
1350 static void
1351 thread_apply_command (char *tidlist, int from_tty)
1352 {
1353 char *cmd;
1354 struct cleanup *old_chain;
1355 char *saved_cmd;
1356 struct get_number_or_range_state state;
1357
1358 if (tidlist == NULL || *tidlist == '\000')
1359 error (_("Please specify a thread ID list"));
1360
1361 for (cmd = tidlist; *cmd != '\000' && !isalpha (*cmd); cmd++);
1362
1363 if (*cmd == '\000')
1364 error (_("Please specify a command following the thread ID list"));
1365
1366 /* Save a copy of the command in case it is clobbered by
1367 execute_command. */
1368 saved_cmd = xstrdup (cmd);
1369 old_chain = make_cleanup (xfree, saved_cmd);
1370
1371 init_number_or_range (&state, tidlist);
1372 while (!state.finished && state.string < cmd)
1373 {
1374 struct thread_info *tp;
1375 int start;
1376
1377 start = get_number_or_range (&state);
1378
1379 make_cleanup_restore_current_thread ();
1380
1381 tp = find_thread_id (start);
1382
1383 if (!tp)
1384 warning (_("Unknown thread %d."), start);
1385 else if (!thread_alive (tp))
1386 warning (_("Thread %d has terminated."), start);
1387 else
1388 {
1389 switch_to_thread (tp->ptid);
1390
1391 printf_filtered (_("\nThread %d (%s):\n"), tp->num,
1392 target_pid_to_str (inferior_ptid));
1393 execute_command (cmd, from_tty);
1394
1395 /* Restore exact command used previously. */
1396 strcpy (cmd, saved_cmd);
1397 }
1398 }
1399
1400 do_cleanups (old_chain);
1401 }
1402
1403 /* Switch to the specified thread. Will dispatch off to thread_apply_command
1404 if prefix of arg is `apply'. */
1405
1406 static void
1407 thread_command (char *tidstr, int from_tty)
1408 {
1409 if (!tidstr)
1410 {
1411 if (ptid_equal (inferior_ptid, null_ptid))
1412 error (_("No thread selected"));
1413
1414 if (target_has_stack)
1415 {
1416 if (is_exited (inferior_ptid))
1417 printf_filtered (_("[Current thread is %d (%s) (exited)]\n"),
1418 pid_to_thread_id (inferior_ptid),
1419 target_pid_to_str (inferior_ptid));
1420 else
1421 printf_filtered (_("[Current thread is %d (%s)]\n"),
1422 pid_to_thread_id (inferior_ptid),
1423 target_pid_to_str (inferior_ptid));
1424 }
1425 else
1426 error (_("No stack."));
1427 return;
1428 }
1429
1430 gdb_thread_select (current_uiout, tidstr, NULL);
1431 }
1432
1433 /* Implementation of `thread name'. */
1434
1435 static void
1436 thread_name_command (char *arg, int from_tty)
1437 {
1438 struct thread_info *info;
1439
1440 if (ptid_equal (inferior_ptid, null_ptid))
1441 error (_("No thread selected"));
1442
1443 arg = skip_spaces (arg);
1444
1445 info = inferior_thread ();
1446 xfree (info->name);
1447 info->name = arg ? xstrdup (arg) : NULL;
1448 }
1449
1450 /* Find thread ids with a name, target pid, or extra info matching ARG. */
1451
1452 static void
1453 thread_find_command (char *arg, int from_tty)
1454 {
1455 struct thread_info *tp;
1456 char *tmp;
1457 unsigned long match = 0;
1458
1459 if (arg == NULL || *arg == '\0')
1460 error (_("Command requires an argument."));
1461
1462 tmp = re_comp (arg);
1463 if (tmp != 0)
1464 error (_("Invalid regexp (%s): %s"), tmp, arg);
1465
1466 update_thread_list ();
1467 for (tp = thread_list; tp; tp = tp->next)
1468 {
1469 if (tp->name != NULL && re_exec (tp->name))
1470 {
1471 printf_filtered (_("Thread %d has name '%s'\n"),
1472 tp->num, tp->name);
1473 match++;
1474 }
1475
1476 tmp = target_thread_name (tp);
1477 if (tmp != NULL && re_exec (tmp))
1478 {
1479 printf_filtered (_("Thread %d has target name '%s'\n"),
1480 tp->num, tmp);
1481 match++;
1482 }
1483
1484 tmp = target_pid_to_str (tp->ptid);
1485 if (tmp != NULL && re_exec (tmp))
1486 {
1487 printf_filtered (_("Thread %d has target id '%s'\n"),
1488 tp->num, tmp);
1489 match++;
1490 }
1491
1492 tmp = target_extra_thread_info (tp);
1493 if (tmp != NULL && re_exec (tmp))
1494 {
1495 printf_filtered (_("Thread %d has extra info '%s'\n"),
1496 tp->num, tmp);
1497 match++;
1498 }
1499 }
1500 if (!match)
1501 printf_filtered (_("No threads match '%s'\n"), arg);
1502 }
1503
1504 /* Print notices when new threads are attached and detached. */
1505 int print_thread_events = 1;
1506 static void
1507 show_print_thread_events (struct ui_file *file, int from_tty,
1508 struct cmd_list_element *c, const char *value)
1509 {
1510 fprintf_filtered (file,
1511 _("Printing of thread events is %s.\n"),
1512 value);
1513 }
1514
1515 static int
1516 do_captured_thread_select (struct ui_out *uiout, void *tidstr)
1517 {
1518 int num;
1519 struct thread_info *tp;
1520
1521 num = value_as_long (parse_and_eval (tidstr));
1522
1523 tp = find_thread_id (num);
1524
1525 if (!tp)
1526 error (_("Thread ID %d not known."), num);
1527
1528 if (!thread_alive (tp))
1529 error (_("Thread ID %d has terminated."), num);
1530
1531 switch_to_thread (tp->ptid);
1532
1533 annotate_thread_changed ();
1534
1535 ui_out_text (uiout, "[Switching to thread ");
1536 ui_out_field_int (uiout, "new-thread-id", pid_to_thread_id (inferior_ptid));
1537 ui_out_text (uiout, " (");
1538 ui_out_text (uiout, target_pid_to_str (inferior_ptid));
1539 ui_out_text (uiout, ")]");
1540
1541 /* Note that we can't reach this with an exited thread, due to the
1542 thread_alive check above. */
1543 if (tp->state == THREAD_RUNNING)
1544 ui_out_text (uiout, "(running)\n");
1545 else
1546 {
1547 ui_out_text (uiout, "\n");
1548 print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
1549 }
1550
1551 /* Since the current thread may have changed, see if there is any
1552 exited thread we can now delete. */
1553 prune_threads ();
1554
1555 return GDB_RC_OK;
1556 }
1557
1558 enum gdb_rc
1559 gdb_thread_select (struct ui_out *uiout, char *tidstr, char **error_message)
1560 {
1561 if (catch_exceptions_with_msg (uiout, do_captured_thread_select, tidstr,
1562 error_message, RETURN_MASK_ALL) < 0)
1563 return GDB_RC_FAIL;
1564 return GDB_RC_OK;
1565 }
1566
1567 /* Update the 'threads_executing' global based on the threads we know
1568 about right now. */
1569
1570 static void
1571 update_threads_executing (void)
1572 {
1573 struct thread_info *tp;
1574
1575 threads_executing = 0;
1576 ALL_NON_EXITED_THREADS (tp)
1577 {
1578 if (tp->executing)
1579 {
1580 threads_executing = 1;
1581 break;
1582 }
1583 }
1584 }
1585
1586 void
1587 update_thread_list (void)
1588 {
1589 prune_threads ();
1590 target_find_new_threads ();
1591 update_threads_executing ();
1592 }
1593
1594 /* Return a new value for the selected thread's id. Return a value of 0 if
1595 no thread is selected, or no threads exist. */
1596
1597 static struct value *
1598 thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
1599 void *ignore)
1600 {
1601 struct thread_info *tp = find_thread_ptid (inferior_ptid);
1602
1603 return value_from_longest (builtin_type (gdbarch)->builtin_int,
1604 (tp ? tp->num : 0));
1605 }
1606
1607 /* Commands with a prefix of `thread'. */
1608 struct cmd_list_element *thread_cmd_list = NULL;
1609
1610 /* Implementation of `thread' variable. */
1611
1612 static const struct internalvar_funcs thread_funcs =
1613 {
1614 thread_id_make_value,
1615 NULL,
1616 NULL
1617 };
1618
1619 void
1620 _initialize_thread (void)
1621 {
1622 static struct cmd_list_element *thread_apply_list = NULL;
1623
1624 add_info ("threads", info_threads_command,
1625 _("Display currently known threads.\n\
1626 Usage: info threads [ID]...\n\
1627 Optional arguments are thread IDs with spaces between.\n\
1628 If no arguments, all threads are displayed."));
1629
1630 add_prefix_cmd ("thread", class_run, thread_command, _("\
1631 Use this command to switch between threads.\n\
1632 The new thread ID must be currently known."),
1633 &thread_cmd_list, "thread ", 1, &cmdlist);
1634
1635 add_prefix_cmd ("apply", class_run, thread_apply_command,
1636 _("Apply a command to a list of threads."),
1637 &thread_apply_list, "thread apply ", 1, &thread_cmd_list);
1638
1639 add_cmd ("all", class_run, thread_apply_all_command,
1640 _("Apply a command to all threads."), &thread_apply_list);
1641
1642 add_cmd ("name", class_run, thread_name_command,
1643 _("Set the current thread's name.\n\
1644 Usage: thread name [NAME]\n\
1645 If NAME is not given, then any existing name is removed."), &thread_cmd_list);
1646
1647 add_cmd ("find", class_run, thread_find_command, _("\
1648 Find threads that match a regular expression.\n\
1649 Usage: thread find REGEXP\n\
1650 Will display thread ids whose name, target ID, or extra info matches REGEXP."),
1651 &thread_cmd_list);
1652
1653 if (!xdb_commands)
1654 add_com_alias ("t", "thread", class_run, 1);
1655
1656 add_setshow_boolean_cmd ("thread-events", no_class,
1657 &print_thread_events, _("\
1658 Set printing of thread events (such as thread start and exit)."), _("\
1659 Show printing of thread events (such as thread start and exit)."), NULL,
1660 NULL,
1661 show_print_thread_events,
1662 &setprintlist, &showprintlist);
1663
1664 create_internalvar_type_lazy ("_thread", &thread_funcs, NULL);
1665 }
This page took 0.099785 seconds and 5 git commands to generate.