GDB (xrefs)
Loading...
Searching...
No Matches
thread.c
Go to the documentation of this file.
1/* Multi-process/thread control for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2023 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 "language.h"
24#include "symtab.h"
25#include "frame.h"
26#include "inferior.h"
27#include "gdbsupport/environ.h"
28#include "value.h"
29#include "target.h"
30#include "gdbthread.h"
31#include "command.h"
32#include "gdbcmd.h"
33#include "regcache.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 "observable.h"
41#include "annotate.h"
42#include "cli/cli-decode.h"
43#include "cli/cli-option.h"
44#include "gdbsupport/gdb_regex.h"
45#include "cli/cli-utils.h"
46#include "thread-fsm.h"
47#include "tid-parse.h"
48#include <algorithm>
49#include "gdbsupport/gdb_optional.h"
50#include "inline-frame.h"
51#include "stack.h"
52#include "interps.h"
53
54/* See gdbthread.h. */
55
56bool debug_threads = false;
57
58/* Implement 'show debug threads'. */
59
60static void
61show_debug_threads (struct ui_file *file, int from_tty,
62 struct cmd_list_element *c, const char *value)
63{
64 gdb_printf (file, _("Thread debugging is \"%s\".\n"), value);
65}
66
67/* Definition of struct thread_info exported to gdbthread.h. */
68
69/* Prototypes for local functions. */
70
72
73/* The current/selected thread. */
75
76/* Returns true if THR is the current thread. */
77
78static bool
80{
81 return thr == current_thread_;
82}
83
84struct thread_info*
86{
87 gdb_assert (current_thread_ != nullptr);
88 return current_thread_;
89}
90
91/* Delete the breakpoint pointed at by BP_P, if there's one. */
92
93static void
95{
96 if (*bp_p != NULL)
97 {
98 delete_breakpoint (*bp_p);
99 *bp_p = NULL;
100 }
101}
102
103void
109
110void
116
117/* See gdbthread.h. */
118
119void
125
126/* Delete the breakpoint pointed at by BP_P at the next stop, if
127 there's one. */
128
129static void
131{
132 if (*bp != NULL)
133 {
134 (*bp)->disposition = disp_del_at_next_stop;
135 *bp = NULL;
136 }
137}
138
139/* See gdbthread.h. */
140
141int
146
147/* See gdbthread.h. */
148
149int
151 const address_space *aspace,
152 CORE_ADDR addr)
153{
154 struct breakpoint *ss_bps = tp->control.single_step_breakpoints;
155
156 return (ss_bps != NULL
157 && breakpoint_has_location_inserted_here (ss_bps, aspace, addr));
158}
159
160/* See gdbthread.h. */
161
162void
164{
165 if (thr->thread_fsm () != nullptr)
166 {
167 std::unique_ptr<thread_fsm> fsm = thr->release_thread_fsm ();
168 fsm->clean_up (thr);
169 }
170}
171
172static void
174{
175 /* NOTE: this will take care of any left-over step_resume breakpoints,
176 but not any user-specified thread-specific breakpoints. We can not
177 delete the breakpoint straight-off, because the inferior might not
178 be stopped at the moment. */
182
184
186
187 btrace_teardown (tp);
188
190
192}
193
194/* Notify interpreters and observers that thread T has exited. */
195
196static void
197notify_thread_exited (thread_info *t, gdb::optional<ULONGEST> exit_code,
198 int silent)
199{
201 {
202 if (exit_code.has_value ())
203 gdb_printf (_("[%s exited with code %s]\n"),
204 target_pid_to_str (t->ptid).c_str (),
205 pulongest (*exit_code));
206 else
207 gdb_printf (_("[%s exited]\n"),
208 target_pid_to_str (t->ptid).c_str ());
209 }
210
211 interps_notify_thread_exited (t, exit_code, silent);
212 gdb::observers::thread_exit.notify (t, exit_code, silent);
213}
214
215/* See gdbthread.h. */
216
217void
218set_thread_exited (thread_info *tp, gdb::optional<ULONGEST> exit_code,
219 bool silent)
220{
221 /* Dead threads don't need to step-over. Remove from chain. */
224
225 if (tp->state != THREAD_EXITED)
226 {
227 process_stratum_target *proc_target = tp->inf->process_target ();
228
229 /* Some targets unpush themselves from the inferior's target stack before
230 clearing the inferior's thread list (which marks all threads as exited,
231 and therefore leads to this function). In this case, the inferior's
232 process target will be nullptr when we arrive here.
233
234 See also the comment in inferior::unpush_target. */
235 if (proc_target != nullptr)
237
238 notify_thread_exited (tp, exit_code, silent);
239
240 /* Tag it as exited. */
241 tp->state = THREAD_EXITED;
242
243 /* Clear breakpoints, etc. associated with this thread. */
245
246 /* Remove from the ptid_t map. We don't want for
247 inferior::find_thread to find exited threads. Also, the target
248 may reuse the ptid for a new thread, and there can only be
249 one value per key; adding a new thread with the same ptid_t
250 would overwrite the exited thread's ptid entry. */
251 size_t nr_deleted = tp->inf->ptid_thread_map.erase (tp->ptid);
252 gdb_assert (nr_deleted == 1);
253 }
254}
255
256void
258{
260
261 for (inferior *inf : all_inferiors ())
262 inf->clear_thread_list ();
263}
264
265/* Allocate a new thread of inferior INF with target id PTID and add
266 it to the thread list. */
267
268static struct thread_info *
269new_thread (struct inferior *inf, ptid_t ptid)
270{
271 thread_info *tp = new thread_info (inf, ptid);
272
273 threads_debug_printf ("creating a new thread object, inferior %d, ptid %s",
274 inf->num, ptid.to_string ().c_str ());
275
276 inf->thread_list.push_back (*tp);
277
278 /* A thread with this ptid should not exist in the map yet. */
279 gdb_assert (inf->ptid_thread_map.find (ptid) == inf->ptid_thread_map.end ());
280
281 inf->ptid_thread_map[ptid] = tp;
282
283 return tp;
284}
285
286/* Notify interpreters and observers that thread T has been created. */
287
288static void
294
295struct thread_info *
297{
298 gdb_assert (targ != nullptr);
299
300 inferior *inf = find_inferior_ptid (targ, ptid);
301
302 threads_debug_printf ("add thread to inferior %d, ptid %s, target %s",
303 inf->num, ptid.to_string ().c_str (),
304 targ->shortname ());
305
306 /* We may have an old thread with the same id in the thread list.
307 If we do, it must be dead, otherwise we wouldn't be adding a new
308 thread with the same id. The OS is reusing this id --- delete
309 the old thread, and create a new one. */
310 thread_info *tp = inf->find_thread (ptid);
311 if (tp != nullptr)
312 delete_thread (tp);
313
314 tp = new_thread (inf, ptid);
316
317 return tp;
318}
319
320struct thread_info *
323{
324 thread_info *result = add_thread_silent (targ, ptid);
325
326 result->priv = std::move (priv);
327
329 gdb_printf (_("[New %s]\n"), target_pid_to_str (ptid).c_str ());
330
332 return result;
333}
334
335struct thread_info *
337{
338 return add_thread_with_info (targ, ptid, NULL);
339}
340
342
343thread_info::thread_info (struct inferior *inf_, ptid_t ptid_)
344 : ptid (ptid_), inf (inf_)
345{
346 gdb_assert (inf_ != NULL);
347
349 this->per_inf_num = ++inf_->highest_thread_num;
350
351 /* Nothing to follow yet. */
353}
354
355/* See gdbthread.h. */
356
358{
359 threads_debug_printf ("thread %s", this->ptid.to_string ().c_str ());
360}
361
362/* See gdbthread.h. */
363
364bool
366{
367 /* If this is the current thread, or there's code out there that
368 relies on it existing (refcount > 0) we can't delete yet. */
369 return refcount () == 0 && !is_current_thread (this);
370}
371
372/* See gdbthread.h. */
373
374void
376{
377 m_executing = executing;
378 if (executing)
379 this->clear_stop_pc ();
380}
381
382/* See gdbthread.h. */
383
384void
386{
387 if (resumed == m_resumed)
388 return;
389
390 process_stratum_target *proc_target = this->inf->process_target ();
391
392 /* If we transition from resumed to not resumed, we might need to remove
393 the thread from the resumed threads with pending statuses list. */
394 if (!resumed)
396
397 m_resumed = resumed;
398
399 /* If we transition from not resumed to resumed, we might need to add
400 the thread to the resumed threads with pending statuses list. */
401 if (resumed)
403}
404
405/* See gdbthread.h. */
406
407void
409{
410 gdb_assert (!this->has_pending_waitstatus ());
411
414
415 process_stratum_target *proc_target = this->inf->process_target ();
417}
418
419/* See gdbthread.h. */
420
421void
423{
424 gdb_assert (this->has_pending_waitstatus ());
425
426 process_stratum_target *proc_target = this->inf->process_target ();
428
430}
431
432/* See gdbthread.h. */
433
434int
436{
437 return tp->step_over_list_node.is_linked ();
438}
439
440/* See gdbthread.h. */
441
442int
444{
445 int num = 0;
446
447 for (const thread_info &thread ATTRIBUTE_UNUSED : l)
448 ++num;
449
450 return num;
451}
452
453/* See gdbthread.h. */
454
455void
457{
458 infrun_debug_printf ("enqueueing thread %s in global step over chain",
459 tp->ptid.to_string ().c_str ());
460
461 gdb_assert (!thread_is_in_step_over_chain (tp));
462 global_thread_step_over_list.push_back (*tp);
463}
464
465/* See gdbthread.h. */
466
467void
472
473/* See gdbthread.h. */
474
475void
477{
478 infrun_debug_printf ("removing thread %s from global step over chain",
479 tp->ptid.to_string ().c_str ());
480
481 gdb_assert (thread_is_in_step_over_chain (tp));
482 auto it = global_thread_step_over_list.iterator_to (*tp);
484}
485
486/* Helper for the different delete_thread variants. */
487
488static void
489delete_thread_1 (thread_info *thr, gdb::optional<ULONGEST> exit_code,
490 bool silent)
491{
492 gdb_assert (thr != nullptr);
493
494 threads_debug_printf ("deleting thread %s, exit_code = %s, silent = %d",
495 thr->ptid.to_string ().c_str (),
496 (exit_code.has_value ()
497 ? pulongest (*exit_code)
498 : "<none>"),
499 silent);
500
501 set_thread_exited (thr, exit_code, silent);
502
503 if (!thr->deletable ())
504 {
505 /* Will be really deleted some other time. */
506 return;
507 }
508
509 auto it = thr->inf->thread_list.iterator_to (*thr);
510 thr->inf->thread_list.erase (it);
511
512 delete thr;
513}
514
515/* See gdbthread.h. */
516
517void
518delete_thread_with_exit_code (thread_info *thread, ULONGEST exit_code,
519 bool silent)
520{
521 delete_thread_1 (thread, exit_code, silent);
522}
523
524/* See gdbthread.h. */
525
526void
528{
529 delete_thread_1 (thread, {}, false /* not silent */);
530}
531
532void
534{
535 delete_thread_1 (thread, {}, true /* not silent */);
536}
537
538struct thread_info *
540{
541 for (thread_info *tp : all_threads ())
542 if (tp->global_num == global_id)
543 return tp;
544
545 return NULL;
546}
547
548static struct thread_info *
549find_thread_id (struct inferior *inf, int thr_num)
550{
551 for (thread_info *tp : inf->threads ())
552 if (tp->per_inf_num == thr_num)
553 return tp;
554
555 return NULL;
556}
557
558/* See gdbthread.h. */
559
560struct thread_info *
561find_thread_by_handle (gdb::array_view<const gdb_byte> handle,
562 struct inferior *inf)
563{
564 return target_thread_handle_to_thread_info (handle.data (),
565 handle.size (),
566 inf);
567}
568
569/*
570 * Thread iterator function.
571 *
572 * Calls a callback function once for each thread, so long as
573 * the callback function returns false. If the callback function
574 * returns true, the iteration will end and the current thread
575 * will be returned. This can be useful for implementing a
576 * search for a thread with arbitrary attributes, or for applying
577 * some operation to every thread.
578 *
579 * FIXME: some of the existing functionality, such as
580 * "Thread apply all", might be rewritten using this functionality.
581 */
582
583struct thread_info *
584iterate_over_threads (int (*callback) (struct thread_info *, void *),
585 void *data)
586{
587 for (thread_info *tp : all_threads_safe ())
588 if ((*callback) (tp, data))
589 return tp;
590
591 return NULL;
592}
593
594/* See gdbthread.h. */
595
596bool
598{
599 for (thread_info *tp ATTRIBUTE_UNUSED : all_threads ())
600 return true;
601 return false;
602}
603
604int
606{
607 auto rng = all_threads (proc_target);
608 return std::distance (rng.begin (), rng.end ());
609}
610
611/* Return the number of non-exited threads in the thread list. */
612
613static int
615{
616 auto rng = all_non_exited_threads ();
617 return std::distance (rng.begin (), rng.end ());
618}
619
620int
622{
623 for (thread_info *tp : all_threads ())
624 if (tp->global_num == global_id)
625 return 1;
626
627 return 0;
628}
629
630bool
632{
633 return targ->find_thread (ptid) != nullptr;
634}
635
636/* Finds the first thread of the inferior. */
637
640{
641 if (inf->thread_list.empty ())
642 return nullptr;
643
644 return &inf->thread_list.front ();
645}
646
649{
650 gdb_assert (inf->pid != 0);
651
652 /* Prefer the current thread, if there's one. */
653 if (inf == current_inferior () && inferior_ptid != null_ptid)
654 return inferior_thread ();
655
656 for (thread_info *tp : inf->non_exited_threads ())
657 return tp;
658
659 return NULL;
660}
661
664{
665 struct thread_info *curr_tp = NULL;
666 struct thread_info *tp_executing = NULL;
667
668 gdb_assert (inf != NULL && inf->pid != 0);
669
670 /* Prefer the current thread if it's not executing. */
671 if (inferior_ptid != null_ptid && current_inferior () == inf)
672 {
673 /* If the current thread is dead, forget it. If it's not
674 executing, use it. Otherwise, still choose it (below), but
675 only if no other non-executing thread is found. */
676 curr_tp = inferior_thread ();
677 if (curr_tp->state == THREAD_EXITED)
678 curr_tp = NULL;
679 else if (!curr_tp->executing ())
680 return curr_tp;
681 }
682
683 for (thread_info *tp : inf->non_exited_threads ())
684 {
685 if (!tp->executing ())
686 return tp;
687
688 tp_executing = tp;
689 }
690
691 /* If both the current thread and all live threads are executing,
692 prefer the current thread. */
693 if (curr_tp != NULL)
694 return curr_tp;
695
696 /* Otherwise, just return an executing thread, if any. */
697 return tp_executing;
698}
699
700/* Return true if TP is an active thread. */
701static bool
703{
704 if (tp->state == THREAD_EXITED)
705 return false;
706
707 /* Ensure we're looking at the right target stack. */
708 gdb_assert (tp->inf == current_inferior ());
709
710 return target_thread_alive (tp->ptid);
711}
712
713/* See gdbthreads.h. */
714
715bool
717{
718 scoped_restore_current_thread restore_thread;
719
720 /* Switch inferior first, so that we're looking at the right target
721 stack. */
723
724 if (thread_alive (thr))
725 {
726 switch_to_thread (thr);
727 restore_thread.dont_restore ();
728 return true;
729 }
730
731 return false;
732}
733
734/* See gdbthreads.h. */
735
736void
738{
739 scoped_restore_current_thread restore_thread;
740
741 for (thread_info *tp : all_threads_safe ())
742 {
744
745 if (!thread_alive (tp))
746 delete_thread (tp);
747 }
748}
749
750/* See gdbthreads.h. */
751
752void
754{
755 for (thread_info *tp : all_threads_safe ())
756 if (tp->state == THREAD_EXITED)
757 delete_thread (tp);
758}
759
760/* Return true value if stack temporaries are enabled for the thread
761 TP. */
762
763bool
765{
766 if (tp == NULL)
767 return false;
768 else
769 return tp->stack_temporaries_enabled;
770}
771
772/* Push V on to the stack temporaries of the thread with id PTID. */
773
774void
776{
777 gdb_assert (tp != NULL && tp->stack_temporaries_enabled);
778 tp->stack_temporaries.push_back (v);
779}
780
781/* Return true if VAL is among the stack temporaries of the thread
782 TP. Return false otherwise. */
783
784bool
786{
787 gdb_assert (tp != NULL && tp->stack_temporaries_enabled);
788 for (value *v : tp->stack_temporaries)
789 if (v == val)
790 return true;
791
792 return false;
793}
794
795/* Return the last of the stack temporaries for thread with id PTID.
796 Return NULL if there are no stack temporaries for the thread. */
797
798value *
800{
801 struct value *lastval = NULL;
802
803 gdb_assert (tp != NULL);
804 if (!tp->stack_temporaries.empty ())
805 lastval = tp->stack_temporaries.back ();
806
807 return lastval;
808}
809
810void
812 ptid_t old_ptid, ptid_t new_ptid)
813{
814 struct inferior *inf;
815 struct thread_info *tp;
816
817 /* It can happen that what we knew as the target inferior id
818 changes. E.g, target remote may only discover the remote process
819 pid after adding the inferior to GDB's list. */
820 inf = find_inferior_ptid (targ, old_ptid);
821 inf->pid = new_ptid.pid ();
822
823 tp = inf->find_thread (old_ptid);
824 gdb_assert (tp != nullptr);
825
826 int num_erased = inf->ptid_thread_map.erase (old_ptid);
827 gdb_assert (num_erased == 1);
828
829 tp->ptid = new_ptid;
830 inf->ptid_thread_map[new_ptid] = tp;
831
832 gdb::observers::thread_ptid_changed.notify (targ, old_ptid, new_ptid);
833}
834
835/* See gdbthread.h. */
836
837void
838set_resumed (process_stratum_target *targ, ptid_t ptid, bool resumed)
839{
840 for (thread_info *tp : all_non_exited_threads (targ, ptid))
841 tp->set_resumed (resumed);
842}
843
844/* Helper for set_running, that marks one thread either running or
845 stopped. */
846
847static bool
848set_running_thread (struct thread_info *tp, bool running)
849{
850 bool started = false;
851
852 if (running && tp->state == THREAD_STOPPED)
853 started = true;
854 tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
855
856 threads_debug_printf ("thread: %s, running? %d%s",
857 tp->ptid.to_string ().c_str (), running,
858 (started ? " (started)" : ""));
859
860 if (!running)
861 {
862 /* If the thread is now marked stopped, remove it from
863 the step-over queue, so that we don't try to resume
864 it until the user wants it to. */
867 }
868
869 return started;
870}
871
872/* Notify interpreters and observers that the target was resumed. */
873
874static void
876{
878 gdb::observers::target_resumed.notify (ptid);
879}
880
881/* See gdbthread.h. */
882
883void
885{
886 if (set_running_thread (this, running))
888}
889
890void
891set_running (process_stratum_target *targ, ptid_t ptid, bool running)
892{
893 /* We try not to notify the observer if no thread has actually
894 changed the running state -- merely to reduce the number of
895 messages to the MI frontend. A frontend is supposed to handle
896 multiple *running notifications just fine. */
897 bool any_started = false;
898
899 for (thread_info *tp : all_non_exited_threads (targ, ptid))
900 if (set_running_thread (tp, running))
901 any_started = true;
902
903 if (any_started)
905}
906
907void
908set_executing (process_stratum_target *targ, ptid_t ptid, bool executing)
909{
910 for (thread_info *tp : all_non_exited_threads (targ, ptid))
911 tp->set_executing (executing);
912
913 /* It only takes one running thread to spawn more threads. */
914 if (executing)
915 targ->threads_executing = true;
916 /* Only clear the flag if the caller is telling us everything is
917 stopped. */
918 else if (minus_one_ptid == ptid)
919 targ->threads_executing = false;
920}
921
922/* See gdbthread.h. */
923
924bool
926{
927 return target->threads_executing;
928}
929
930void
931set_stop_requested (process_stratum_target *targ, ptid_t ptid, bool stop)
932{
933 for (thread_info *tp : all_non_exited_threads (targ, ptid))
934 tp->stop_requested = stop;
935
936 /* Call the stop requested observer so other components of GDB can
937 react to this request. */
938 if (stop)
940}
941
942void
944{
945 bool any_started = false;
946
947 for (thread_info *tp : all_non_exited_threads (targ, ptid))
948 if (set_running_thread (tp, tp->executing ()))
949 any_started = true;
950
951 if (any_started)
953}
954
955/* See gdbthread.h. */
956
957void
959{
960 /* No selected thread, no registers. */
961 if (inferior_ptid == null_ptid)
962 error (_("No thread selected."));
963
965
966 /* Don't try to read from a dead thread. */
967 if (tp->state == THREAD_EXITED)
968 error (_("The current thread has terminated"));
969
970 /* ... or from a spinning thread. FIXME: This isn't actually fully
971 correct. It'll allow an user-requested access (e.g., "print $pc"
972 at the prompt) when a thread is not executing for some internal
973 reason, but is marked running from the user's perspective. E.g.,
974 the thread is waiting for its turn in the step-over queue. */
975 if (tp->executing ())
976 error (_("Selected thread is running."));
977}
978
979/* See gdbthread.h. */
980
981bool
983{
984 /* No thread, no registers. */
985 if (thread == NULL)
986 return false;
987
988 /* Don't try to read from a dead thread. */
989 if (thread->state == THREAD_EXITED)
990 return false;
991
992 /* ... or from a spinning thread. FIXME: see validate_registers_access. */
993 if (thread->executing ())
994 return false;
995
996 return true;
997}
998
999bool
1000pc_in_thread_step_range (CORE_ADDR pc, struct thread_info *thread)
1001{
1002 return (pc >= thread->control.step_range_start
1003 && pc < thread->control.step_range_end);
1004}
1005
1006/* Helper for print_thread_info. Returns true if THR should be
1007 printed. If REQUESTED_THREADS, a list of GDB ids/ranges, is not
1008 NULL, only print THR if its ID is included in the list. GLOBAL_IDS
1009 is true if REQUESTED_THREADS is list of global IDs, false if a list
1010 of per-inferior thread ids. If PID is not -1, only print THR if it
1011 is a thread from the process PID. Otherwise, threads from all
1012 attached PIDs are printed. If both REQUESTED_THREADS is not NULL
1013 and PID is not -1, then the thread is printed if it belongs to the
1014 specified process. Otherwise, an error is raised. */
1015
1016static bool
1017should_print_thread (const char *requested_threads, int default_inf_num,
1018 int global_ids, int pid, struct thread_info *thr)
1019{
1020 if (requested_threads != NULL && *requested_threads != '\0')
1021 {
1022 int in_list;
1023
1024 if (global_ids)
1025 in_list = number_is_in_list (requested_threads, thr->global_num);
1026 else
1027 in_list = tid_is_in_list (requested_threads, default_inf_num,
1028 thr->inf->num, thr->per_inf_num);
1029 if (!in_list)
1030 return false;
1031 }
1032
1033 if (pid != -1 && thr->ptid.pid () != pid)
1034 {
1035 if (requested_threads != NULL && *requested_threads != '\0')
1036 error (_("Requested thread not found in requested process"));
1037 return false;
1038 }
1039
1040 if (thr->state == THREAD_EXITED)
1041 return false;
1042
1043 return true;
1044}
1045
1046/* Return the string to display in "info threads"'s "Target Id"
1047 column, for TP. */
1048
1049static std::string
1051{
1052 std::string target_id = target_pid_to_str (tp->ptid);
1053 const char *extra_info = target_extra_thread_info (tp);
1054 const char *name = thread_name (tp);
1055
1056 if (extra_info != nullptr && name != nullptr)
1057 return string_printf ("%s \"%s\" (%s)", target_id.c_str (), name,
1058 extra_info);
1059 else if (extra_info != nullptr)
1060 return string_printf ("%s (%s)", target_id.c_str (), extra_info);
1061 else if (name != nullptr)
1062 return string_printf ("%s \"%s\"", target_id.c_str (), name);
1063 else
1064 return target_id;
1065}
1066
1067/* Like print_thread_info, but in addition, GLOBAL_IDS indicates
1068 whether REQUESTED_THREADS is a list of global or per-inferior
1069 thread ids. */
1070
1071static void
1072print_thread_info_1 (struct ui_out *uiout, const char *requested_threads,
1073 int global_ids, int pid,
1074 int show_global_ids)
1075{
1076 int default_inf_num = current_inferior ()->num;
1077
1079
1080 /* Whether we saw any thread. */
1081 bool any_thread = false;
1082 /* Whether the current thread is exited. */
1083 bool current_exited = false;
1084
1085 thread_info *current_thread = (inferior_ptid != null_ptid
1086 ? inferior_thread () : NULL);
1087
1088 {
1089 /* For backward compatibility, we make a list for MI. A table is
1090 preferable for the CLI, though, because it shows table
1091 headers. */
1092 gdb::optional<ui_out_emit_list> list_emitter;
1093 gdb::optional<ui_out_emit_table> table_emitter;
1094
1095 /* We'll be switching threads temporarily below. */
1096 scoped_restore_current_thread restore_thread;
1097
1098 if (uiout->is_mi_like_p ())
1099 list_emitter.emplace (uiout, "threads");
1100 else
1101 {
1102 int n_threads = 0;
1103 /* The width of the "Target Id" column. Grown below to
1104 accommodate the largest entry. */
1105 size_t target_id_col_width = 17;
1106
1107 for (thread_info *tp : all_threads ())
1108 {
1109 if (!should_print_thread (requested_threads, default_inf_num,
1110 global_ids, pid, tp))
1111 continue;
1112
1113 /* Switch inferiors so we're looking at the right
1114 target stack. */
1116
1117 target_id_col_width
1118 = std::max (target_id_col_width,
1119 thread_target_id_str (tp).size ());
1120
1121 ++n_threads;
1122 }
1123
1124 if (n_threads == 0)
1125 {
1126 if (requested_threads == NULL || *requested_threads == '\0')
1127 uiout->message (_("No threads.\n"));
1128 else
1129 uiout->message (_("No threads match '%s'.\n"),
1130 requested_threads);
1131 return;
1132 }
1133
1134 table_emitter.emplace (uiout, show_global_ids ? 5 : 4,
1135 n_threads, "threads");
1136
1137 uiout->table_header (1, ui_left, "current", "");
1138 uiout->table_header (4, ui_left, "id-in-tg", "Id");
1139 if (show_global_ids)
1140 uiout->table_header (4, ui_left, "id", "GId");
1141 uiout->table_header (target_id_col_width, ui_left,
1142 "target-id", "Target Id");
1143 uiout->table_header (1, ui_left, "frame", "Frame");
1144 uiout->table_body ();
1145 }
1146
1147 for (inferior *inf : all_inferiors ())
1148 for (thread_info *tp : inf->threads ())
1149 {
1150 int core;
1151
1152 any_thread = true;
1153 if (tp == current_thread && tp->state == THREAD_EXITED)
1154 current_exited = true;
1155
1156 if (!should_print_thread (requested_threads, default_inf_num,
1157 global_ids, pid, tp))
1158 continue;
1159
1160 ui_out_emit_tuple tuple_emitter (uiout, NULL);
1161
1162 if (!uiout->is_mi_like_p ())
1163 {
1164 if (tp == current_thread)
1165 uiout->field_string ("current", "*");
1166 else
1167 uiout->field_skip ("current");
1168
1169 uiout->field_string ("id-in-tg", print_thread_id (tp));
1170 }
1171
1172 if (show_global_ids || uiout->is_mi_like_p ())
1173 uiout->field_signed ("id", tp->global_num);
1174
1175 /* Switch to the thread (and inferior / target). */
1176 switch_to_thread (tp);
1177
1178 /* For the CLI, we stuff everything into the target-id field.
1179 This is a gross hack to make the output come out looking
1180 correct. The underlying problem here is that ui-out has no
1181 way to specify that a field's space allocation should be
1182 shared by several fields. For MI, we do the right thing
1183 instead. */
1184
1185 if (uiout->is_mi_like_p ())
1186 {
1187 uiout->field_string ("target-id", target_pid_to_str (tp->ptid));
1188
1189 const char *extra_info = target_extra_thread_info (tp);
1190 if (extra_info != nullptr)
1191 uiout->field_string ("details", extra_info);
1192
1193 const char *name = thread_name (tp);
1194 if (name != NULL)
1195 uiout->field_string ("name", name);
1196 }
1197 else
1198 {
1199 uiout->field_string ("target-id", thread_target_id_str (tp));
1200 }
1201
1202 if (tp->state == THREAD_RUNNING)
1203 uiout->text ("(running)\n");
1204 else
1205 {
1206 /* The switch above put us at the top of the stack (leaf
1207 frame). */
1209 /* For MI output, print frame level. */
1210 uiout->is_mi_like_p (),
1211 LOCATION, 0);
1212 }
1213
1214 if (uiout->is_mi_like_p ())
1215 {
1216 const char *state = "stopped";
1217
1218 if (tp->state == THREAD_RUNNING)
1219 state = "running";
1220 uiout->field_string ("state", state);
1221 }
1222
1223 core = target_core_of_thread (tp->ptid);
1224 if (uiout->is_mi_like_p () && core != -1)
1225 uiout->field_signed ("core", core);
1226 }
1227
1228 /* This end scope restores the current thread and the frame
1229 selected before the "info threads" command, and it finishes the
1230 ui-out list or table. */
1231 }
1232
1233 if (pid == -1 && requested_threads == NULL)
1234 {
1235 if (uiout->is_mi_like_p () && inferior_ptid != null_ptid)
1236 uiout->field_signed ("current-thread-id", current_thread->global_num);
1237
1238 if (inferior_ptid != null_ptid && current_exited)
1239 uiout->message ("\n\
1240The current thread <Thread ID %s> has terminated. See `help thread'.\n",
1242 else if (any_thread && inferior_ptid == null_ptid)
1243 uiout->message ("\n\
1244No selected thread. See `help thread'.\n");
1245 }
1246}
1247
1248/* See gdbthread.h. */
1249
1250void
1251print_thread_info (struct ui_out *uiout, const char *requested_threads,
1252 int pid)
1253{
1254 print_thread_info_1 (uiout, requested_threads, 1, pid, 0);
1255}
1256
1257/* The options for the "info threads" command. */
1258
1260{
1261 /* For "-gid". */
1262 bool show_global_ids = false;
1263};
1264
1266
1268 "gid",
1269 [] (info_threads_opts *opts) { return &opts->show_global_ids; },
1270 N_("Show global thread IDs."),
1271 },
1272
1273};
1274
1275/* Create an option_def_group for the "info threads" options, with
1276 IT_OPTS as context. */
1277
1283
1284/* Implementation of the "info threads" command.
1285
1286 Note: this has the drawback that it _really_ switches
1287 threads, which frees the frame cache. A no-side
1288 effects info-threads command would be nicer. */
1289
1290static void
1291info_threads_command (const char *arg, int from_tty)
1292{
1293 info_threads_opts it_opts;
1294
1295 auto grp = make_info_threads_options_def_group (&it_opts);
1298
1299 print_thread_info_1 (current_uiout, arg, 0, -1, it_opts.show_global_ids);
1300}
1301
1302/* Completer for the "info threads" command. */
1303
1304static void
1306 completion_tracker &tracker,
1307 const char *text, const char *word_ignored)
1308{
1309 const auto grp = make_info_threads_options_def_group (nullptr);
1310
1312 (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp))
1313 return;
1314
1315 /* Convenience to let the user know what the option can accept. */
1316 if (*text == '\0')
1317 {
1319 /* Keep this "ID" in sync with what "help info threads"
1320 says. */
1321 tracker.add_completion (make_unique_xstrdup ("ID"));
1322 }
1323}
1324
1325/* See gdbthread.h. */
1326
1327void
1329{
1330 gdb_assert (thread != nullptr);
1331 threads_debug_printf ("thread = %s", thread->ptid.to_string ().c_str ());
1332
1333 struct inferior *inf = thread->inf;
1334
1337
1338 current_thread_ = thread;
1340}
1341
1342/* See gdbthread.h. */
1343
1344void
1346{
1347 if (current_thread_ == nullptr)
1348 return;
1349
1350 threads_debug_printf ("thread = NONE");
1351
1352 current_thread_ = nullptr;
1353 inferior_ptid = null_ptid;
1355}
1356
1357/* See gdbthread.h. */
1358
1359void
1361{
1362 gdb_assert (thr != NULL);
1363
1364 if (is_current_thread (thr))
1365 return;
1366
1368
1370}
1371
1372/* See gdbsupport/common-gdbthread.h. */
1373
1374void
1375switch_to_thread (process_stratum_target *proc_target, ptid_t ptid)
1376{
1377 thread_info *thr = proc_target->find_thread (ptid);
1378 switch_to_thread (thr);
1379}
1380
1381/* See frame.h. */
1382
1383void
1385{
1386 /* If an entry of thread_info was previously selected, it won't be
1387 deleted because we've increased its refcount. The thread represented
1388 by this thread_info entry may have already exited (due to normal exit,
1389 detach, etc), so the thread_info.state is THREAD_EXITED. */
1390 if (m_thread != NULL
1391 /* If the previously selected thread belonged to a process that has
1392 in the mean time exited (or killed, detached, etc.), then don't revert
1393 back to it, but instead simply drop back to no thread selected. */
1394 && m_inf->pid != 0)
1395 switch_to_thread (m_thread.get ());
1396 else
1398
1399 /* The running state of the originally selected thread may have
1400 changed, so we have to recheck it here. */
1401 if (inferior_ptid != null_ptid
1402 && m_was_stopped
1403 && m_thread->state == THREAD_STOPPED
1405 && target_has_stack ()
1406 && target_has_memory ())
1408
1410}
1411
1417
1419{
1420 m_inf = inferior_ref::new_reference (current_inferior ());
1421
1423
1424 if (inferior_ptid != null_ptid)
1425 {
1426 m_thread = thread_info_ref::new_reference (inferior_thread ());
1427
1430 }
1431}
1432
1435 : m_dont_restore (std::move (rhs.m_dont_restore)),
1436 m_thread (std::move (rhs.m_thread)),
1437 m_inf (std::move (rhs.m_inf)),
1438 m_selected_frame_id (std::move (rhs.m_selected_frame_id)),
1439 m_selected_frame_level (std::move (rhs.m_selected_frame_level)),
1440 m_was_stopped (std::move (rhs.m_was_stopped)),
1441 m_lang (std::move (rhs.m_lang))
1442{
1443 /* Deactivate the rhs. */
1444 rhs.m_dont_restore = true;
1445}
1446
1447/* See gdbthread.h. */
1448
1449int
1451{
1452 return highest_thread_num > 1;
1453}
1454
1455/* See gdbthread.h. */
1456
1457int
1459{
1460 auto inf = inferior_list.begin ();
1461 if (inf->num != 1)
1462 return true;
1463 ++inf;
1464 return inf != inferior_list.end ();
1465}
1466
1467/* See gdbthread.h. */
1468
1469const char *
1471{
1473 return print_full_thread_id (thr);
1474
1475 char *s = get_print_cell ();
1476
1477 gdb_assert (thr != nullptr);
1478 xsnprintf (s, PRINT_CELL_SIZE, "%d", thr->per_inf_num);
1479 return s;
1480}
1481
1482/* See gdbthread.h. */
1483
1484const char *
1486{
1487 char *s = get_print_cell ();
1488
1489 gdb_assert (thr != nullptr);
1490 xsnprintf (s, PRINT_CELL_SIZE, "%d.%d", thr->inf->num, thr->per_inf_num);
1491 return s;
1492}
1493
1494/* Sort an array of struct thread_info pointers by thread ID (first by
1495 inferior number, and then by per-inferior thread number). Sorts in
1496 ascending order. */
1497
1498static bool
1500{
1501 if (a->inf->num != b->inf->num)
1502 return a->inf->num < b->inf->num;
1503
1504 return (a->per_inf_num < b->per_inf_num);
1505}
1506
1507/* Sort an array of struct thread_info pointers by thread ID (first by
1508 inferior number, and then by per-inferior thread number). Sorts in
1509 descending order. */
1510
1511static bool
1513{
1514 if (a->inf->num != b->inf->num)
1515 return a->inf->num > b->inf->num;
1516
1517 return (a->per_inf_num > b->per_inf_num);
1518}
1519
1520/* See gdbthread.h. */
1521
1522void
1523thread_try_catch_cmd (thread_info *thr, gdb::optional<int> ada_task,
1524 const char *cmd, int from_tty,
1525 const qcs_flags &flags)
1526{
1527 gdb_assert (is_current_thread (thr));
1528
1529 /* The thread header is computed before running the command since
1530 the command can change the inferior, which is not permitted
1531 by thread_target_id_str. */
1532 std::string thr_header;
1533 if (ada_task.has_value ())
1534 thr_header = string_printf (_("\nTask ID %d:\n"), *ada_task);
1535 else
1536 thr_header = string_printf (_("\nThread %s (%s):\n"),
1537 print_thread_id (thr),
1538 thread_target_id_str (thr).c_str ());
1539
1540 try
1541 {
1542 std::string cmd_result;
1544 (cmd_result, cmd, from_tty, gdb_stdout->term_out ());
1545 if (!flags.silent || cmd_result.length () > 0)
1546 {
1547 if (!flags.quiet)
1548 gdb_printf ("%s", thr_header.c_str ());
1549 gdb_printf ("%s", cmd_result.c_str ());
1550 }
1551 }
1552 catch (const gdb_exception_error &ex)
1553 {
1554 if (!flags.silent)
1555 {
1556 if (!flags.quiet)
1557 gdb_printf ("%s", thr_header.c_str ());
1558 if (flags.cont)
1559 gdb_printf ("%s\n", ex.what ());
1560 else
1561 throw;
1562 }
1563 }
1564}
1565
1566/* Option definition of "thread apply"'s "-ascending" option. */
1567
1569 "ascending",
1570 N_("\
1571Call COMMAND for all threads in ascending order.\n\
1572The default is descending order."),
1573};
1574
1575/* The qcs command line flags for the "thread apply" commands. Keep
1576 this in sync with the "frame apply" commands. */
1577
1583 "q", [] (qcs_flags *opt) { return &opt->quiet; },
1584 N_("Disables printing the thread information."),
1585 },
1586
1588 "c", [] (qcs_flags *opt) { return &opt->cont; },
1589 N_("Print any error raised by COMMAND and continue."),
1590 },
1591
1593 "s", [] (qcs_flags *opt) { return &opt->silent; },
1594 N_("Silently ignore any errors or empty output produced by COMMAND."),
1595 },
1596};
1597
1598/* Create an option_def_group for the "thread apply all" options, with
1599 ASCENDING and FLAGS as context. */
1600
1601static inline std::array<gdb::option::option_def_group, 2>
1604{
1605 return {{
1606 { {ascending_option_def.def ()}, ascending},
1608 }};
1609}
1610
1611/* Create an option_def_group for the "thread apply" options, with
1612 FLAGS as context. */
1613
1618}
1619
1620/* Apply a GDB command to a list of threads. List syntax is a whitespace
1621 separated list of numbers, or ranges, or the keyword `all'. Ranges consist
1622 of two numbers separated by a hyphen. Examples:
1623
1624 thread apply 1 2 7 4 backtrace Apply backtrace cmd to threads 1,2,7,4
1625 thread apply 2-7 9 p foo(1) Apply p foo(1) cmd to threads 2->7 & 9
1626 thread apply all x/i $pc Apply x/i $pc cmd to all threads. */
1627
1628static void
1629thread_apply_all_command (const char *cmd, int from_tty)
1630{
1631 bool ascending = false;
1633
1634 auto group = make_thread_apply_all_options_def_group (&ascending,
1635 &flags);
1638
1639 validate_flags_qcs ("thread apply all", &flags);
1640
1641 if (cmd == NULL || *cmd == '\000')
1642 error (_("Please specify a command at the end of 'thread apply all'"));
1643
1645
1646 int tc = live_threads_count ();
1647 if (tc != 0)
1648 {
1649 /* Save a copy of the thread list and increment each thread's
1650 refcount while executing the command in the context of each
1651 thread, in case the command is one that wipes threads. E.g.,
1652 detach, kill, disconnect, etc., or even normally continuing
1653 over an inferior or thread exit. */
1654 std::vector<thread_info_ref> thr_list_cpy;
1655 thr_list_cpy.reserve (tc);
1656
1657 for (thread_info *tp : all_non_exited_threads ())
1658 thr_list_cpy.push_back (thread_info_ref::new_reference (tp));
1659 gdb_assert (thr_list_cpy.size () == tc);
1660
1661 auto *sorter = (ascending
1664 std::sort (thr_list_cpy.begin (), thr_list_cpy.end (), sorter);
1665
1666 scoped_restore_current_thread restore_thread;
1667
1668 for (thread_info_ref &thr : thr_list_cpy)
1669 if (switch_to_thread_if_alive (thr.get ()))
1670 thread_try_catch_cmd (thr.get (), {}, cmd, from_tty, flags);
1671 }
1672}
1673
1674/* Completer for "thread apply [ID list]". */
1675
1676static void
1678 completion_tracker &tracker,
1679 const char *text, const char * /*word*/)
1680{
1681 /* Don't leave this to complete_options because there's an early
1682 return below. */
1683 tracker.set_use_custom_word_point (true);
1684
1685 tid_range_parser parser;
1686 parser.init (text, current_inferior ()->num);
1687
1688 try
1689 {
1690 while (!parser.finished ())
1691 {
1692 int inf_num, thr_start, thr_end;
1693
1694 if (!parser.get_tid_range (&inf_num, &thr_start, &thr_end))
1695 break;
1696
1697 if (parser.in_star_range () || parser.in_thread_range ())
1698 parser.skip_range ();
1699 }
1700 }
1701 catch (const gdb_exception_error &ex)
1702 {
1703 /* get_tid_range throws if it parses a negative number, for
1704 example. But a seemingly negative number may be the start of
1705 an option instead. */
1706 }
1707
1708 const char *cmd = parser.cur_tok ();
1709
1710 if (cmd == text)
1711 {
1712 /* No thread ID list yet. */
1713 return;
1714 }
1715
1716 /* Check if we're past a valid thread ID list already. */
1717 if (parser.finished ()
1718 && cmd > text && !isspace (cmd[-1]))
1719 return;
1720
1721 /* We're past the thread ID list, advance word point. */
1722 tracker.advance_custom_word_point_by (cmd - text);
1723 text = cmd;
1724
1725 const auto group = make_thread_apply_options_def_group (nullptr);
1727 (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
1728 return;
1729
1730 complete_nested_command_line (tracker, text);
1731}
1732
1733/* Completer for "thread apply all". */
1734
1735static void
1737 completion_tracker &tracker,
1738 const char *text, const char *word)
1739{
1740 const auto group = make_thread_apply_all_options_def_group (nullptr,
1741 nullptr);
1743 (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
1744 return;
1745
1746 complete_nested_command_line (tracker, text);
1747}
1748
1749/* Implementation of the "thread apply" command. */
1750
1751static void
1752thread_apply_command (const char *tidlist, int from_tty)
1753{
1755 const char *cmd = NULL;
1756 tid_range_parser parser;
1757
1758 if (tidlist == NULL || *tidlist == '\000')
1759 error (_("Please specify a thread ID list"));
1760
1761 parser.init (tidlist, current_inferior ()->num);
1762 while (!parser.finished ())
1763 {
1764 int inf_num, thr_start, thr_end;
1765
1766 if (!parser.get_tid_range (&inf_num, &thr_start, &thr_end))
1767 break;
1768 }
1769
1770 cmd = parser.cur_tok ();
1771
1775
1776 validate_flags_qcs ("thread apply", &flags);
1777
1778 if (*cmd == '\0')
1779 error (_("Please specify a command following the thread ID list"));
1780
1781 if (tidlist == cmd || isdigit (cmd[0]))
1783
1784 scoped_restore_current_thread restore_thread;
1785
1786 parser.init (tidlist, current_inferior ()->num);
1787 while (!parser.finished ())
1788 {
1789 struct thread_info *tp = NULL;
1790 struct inferior *inf;
1791 int inf_num, thr_num;
1792
1793 parser.get_tid (&inf_num, &thr_num);
1794 inf = find_inferior_id (inf_num);
1795 if (inf != NULL)
1796 tp = find_thread_id (inf, thr_num);
1797
1798 if (parser.in_star_range ())
1799 {
1800 if (inf == NULL)
1801 {
1802 warning (_("Unknown inferior %d"), inf_num);
1803 parser.skip_range ();
1804 continue;
1805 }
1806
1807 /* No use looking for threads past the highest thread number
1808 the inferior ever had. */
1809 if (thr_num >= inf->highest_thread_num)
1810 parser.skip_range ();
1811
1812 /* Be quiet about unknown threads numbers. */
1813 if (tp == NULL)
1814 continue;
1815 }
1816
1817 if (tp == NULL)
1818 {
1820 warning (_("Unknown thread %d.%d"), inf_num, thr_num);
1821 else
1822 warning (_("Unknown thread %d"), thr_num);
1823 continue;
1824 }
1825
1826 if (!switch_to_thread_if_alive (tp))
1827 {
1828 warning (_("Thread %s has terminated."), print_thread_id (tp));
1829 continue;
1830 }
1831
1832 thread_try_catch_cmd (tp, {}, cmd, from_tty, flags);
1833 }
1834}
1835
1836
1837/* Implementation of the "taas" command. */
1838
1839static void
1840taas_command (const char *cmd, int from_tty)
1841{
1842 if (cmd == NULL || *cmd == '\0')
1843 error (_("Please specify a command to apply on all threads"));
1844 std::string expanded = std::string ("thread apply all -s ") + cmd;
1845 execute_command (expanded.c_str (), from_tty);
1846}
1847
1848/* Implementation of the "tfaas" command. */
1849
1850static void
1851tfaas_command (const char *cmd, int from_tty)
1852{
1853 if (cmd == NULL || *cmd == '\0')
1854 error (_("Please specify a command to apply on all frames of all threads"));
1855 std::string expanded
1856 = std::string ("thread apply all -s -- frame apply all -s ") + cmd;
1857 execute_command (expanded.c_str (), from_tty);
1858}
1859
1860/* Switch to the specified thread, or print the current thread. */
1861
1862void
1863thread_command (const char *tidstr, int from_tty)
1864{
1865 if (tidstr == NULL)
1866 {
1867 if (inferior_ptid == null_ptid)
1868 error (_("No thread selected"));
1869
1870 if (target_has_stack ())
1871 {
1872 struct thread_info *tp = inferior_thread ();
1873
1874 if (tp->state == THREAD_EXITED)
1875 gdb_printf (_("[Current thread is %s (%s) (exited)]\n"),
1876 print_thread_id (tp),
1877 target_pid_to_str (inferior_ptid).c_str ());
1878 else
1879 gdb_printf (_("[Current thread is %s (%s)]\n"),
1880 print_thread_id (tp),
1881 target_pid_to_str (inferior_ptid).c_str ());
1882 }
1883 else
1884 error (_("No stack."));
1885 }
1886 else
1887 {
1888 ptid_t previous_ptid = inferior_ptid;
1889
1890 thread_select (tidstr, parse_thread_id (tidstr, NULL));
1891
1892 /* Print if the thread has not changed, otherwise an event will
1893 be sent. */
1894 if (inferior_ptid == previous_ptid)
1895 {
1899 }
1900 else
1903 }
1904}
1905
1906/* Implementation of `thread name'. */
1907
1908static void
1909thread_name_command (const char *arg, int from_tty)
1910{
1911 struct thread_info *info;
1912
1913 if (inferior_ptid == null_ptid)
1914 error (_("No thread selected"));
1915
1916 arg = skip_spaces (arg);
1917
1918 info = inferior_thread ();
1919 info->set_name (arg != nullptr ? make_unique_xstrdup (arg) : nullptr);
1920}
1921
1922/* Find thread ids with a name, target pid, or extra info matching ARG. */
1923
1924static void
1925thread_find_command (const char *arg, int from_tty)
1926{
1927 const char *tmp;
1928 unsigned long match = 0;
1929
1930 if (arg == NULL || *arg == '\0')
1931 error (_("Command requires an argument."));
1932
1933 tmp = re_comp (arg);
1934 if (tmp != 0)
1935 error (_("Invalid regexp (%s): %s"), tmp, arg);
1936
1937 /* We're going to be switching threads. */
1938 scoped_restore_current_thread restore_thread;
1939
1941
1942 for (thread_info *tp : all_threads ())
1943 {
1945
1946 if (tp->name () != nullptr && re_exec (tp->name ()))
1947 {
1948 gdb_printf (_("Thread %s has name '%s'\n"),
1949 print_thread_id (tp), tp->name ());
1950 match++;
1951 }
1952
1953 tmp = target_thread_name (tp);
1954 if (tmp != NULL && re_exec (tmp))
1955 {
1956 gdb_printf (_("Thread %s has target name '%s'\n"),
1957 print_thread_id (tp), tmp);
1958 match++;
1959 }
1960
1961 std::string name = target_pid_to_str (tp->ptid);
1962 if (!name.empty () && re_exec (name.c_str ()))
1963 {
1964 gdb_printf (_("Thread %s has target id '%s'\n"),
1965 print_thread_id (tp), name.c_str ());
1966 match++;
1967 }
1968
1969 tmp = target_extra_thread_info (tp);
1970 if (tmp != NULL && re_exec (tmp))
1971 {
1972 gdb_printf (_("Thread %s has extra info '%s'\n"),
1973 print_thread_id (tp), tmp);
1974 match++;
1975 }
1976 }
1977 if (!match)
1978 gdb_printf (_("No threads match '%s'\n"), arg);
1979}
1980
1981/* Print notices when new threads are attached and detached. */
1982bool print_thread_events = true;
1983static void
1984show_print_thread_events (struct ui_file *file, int from_tty,
1985 struct cmd_list_element *c, const char *value)
1986{
1987 gdb_printf (file,
1988 _("Printing of thread events is %s.\n"),
1989 value);
1990}
1991
1992/* See gdbthread.h. */
1993
1994void
1995thread_select (const char *tidstr, thread_info *tp)
1996{
1997 if (!switch_to_thread_if_alive (tp))
1998 error (_("Thread ID %s has terminated."), tidstr);
1999
2001
2002 /* Since the current thread may have changed, see if there is any
2003 exited thread we can now delete. */
2005}
2006
2007/* Print thread and frame switch command response. */
2008
2009void
2010print_selected_thread_frame (struct ui_out *uiout,
2011 user_selected_what selection)
2012{
2013 struct thread_info *tp = inferior_thread ();
2014
2015 if (selection & USER_SELECTED_THREAD)
2016 {
2017 if (uiout->is_mi_like_p ())
2018 {
2019 uiout->field_signed ("new-thread-id",
2020 inferior_thread ()->global_num);
2021 }
2022 else
2023 {
2024 uiout->text ("[Switching to thread ");
2025 uiout->field_string ("new-thread-id", print_thread_id (tp));
2026 uiout->text (" (");
2028 uiout->text (")]");
2029 }
2030 }
2031
2032 if (tp->state == THREAD_RUNNING)
2033 {
2034 if (selection & USER_SELECTED_THREAD)
2035 uiout->text ("(running)\n");
2036 }
2037 else if (selection & USER_SELECTED_FRAME)
2038 {
2039 if (selection & USER_SELECTED_THREAD)
2040 uiout->text ("\n");
2041
2042 if (has_stack_frames ())
2044 1, SRC_AND_LOC, 1);
2045 }
2046}
2047
2048/* Update the 'threads_executing' global based on the threads we know
2049 about right now. This is used by infrun to tell whether we should
2050 pull events out of the current target. */
2051
2052static void
2054{
2056
2057 if (targ == NULL)
2058 return;
2059
2060 targ->threads_executing = false;
2061
2062 for (inferior *inf : all_non_exited_inferiors (targ))
2063 {
2064 if (!inf->has_execution ())
2065 continue;
2066
2067 /* If the process has no threads, then it must be we have a
2068 process-exit event pending. */
2069 if (inf->thread_list.empty ())
2070 {
2071 targ->threads_executing = true;
2072 return;
2073 }
2074
2075 for (thread_info *tp : inf->non_exited_threads ())
2076 {
2077 if (tp->executing ())
2078 {
2079 targ->threads_executing = true;
2080 return;
2081 }
2082 }
2083 }
2084}
2085
2091}
2092
2093/* See gdbthread.h. */
2094
2095const char *
2096thread_name (thread_info *thread)
2097{
2098 /* Use the manually set name if there is one. */
2099 const char *name = thread->name ();
2100 if (name != nullptr)
2101 return name;
2102
2103 /* Otherwise, ask the target. Ensure we query the right target stack. */
2104 scoped_restore_current_thread restore_thread;
2105 if (thread->inf != current_inferior ())
2107
2108 return target_thread_name (thread);
2109}
2110
2111/* See gdbthread.h. */
2112
2113const char *
2115{
2116 switch (state)
2117 {
2118 case THREAD_STOPPED:
2119 return "STOPPED";
2120
2121 case THREAD_RUNNING:
2122 return "RUNNING";
2123
2124 case THREAD_EXITED:
2125 return "EXITED";
2126 }
2127
2128 gdb_assert_not_reached ("unknown thread state");
2129}
2130
2131/* Return a new value for the selected thread's id. Return a value of
2132 0 if no thread is selected. If GLOBAL is true, return the thread's
2133 global number. Otherwise return the per-inferior number. */
2134
2135static struct value *
2136thread_num_make_value_helper (struct gdbarch *gdbarch, int global)
2137{
2138 int int_val;
2139
2140 if (inferior_ptid == null_ptid)
2141 int_val = 0;
2142 else
2143 {
2145 if (global)
2146 int_val = tp->global_num;
2147 else
2148 int_val = tp->per_inf_num;
2149 }
2150
2151 return value_from_longest (builtin_type (gdbarch)->builtin_int, int_val);
2152}
2153
2154/* Return a new value for the selected thread's per-inferior thread
2155 number. Return a value of 0 if no thread is selected, or no
2156 threads exist. */
2157
2158static struct value *
2160 struct internalvar *var,
2161 void *ignore)
2162{
2164}
2165
2166/* Return a new value for the selected thread's global id. Return a
2167 value of 0 if no thread is selected, or no threads exist. */
2168
2169static struct value *
2171 void *ignore)
2172{
2174}
2175
2176/* Return a new value for the number of non-exited threads in the current
2177 inferior. If there are no threads in the current inferior return a
2178 value of 0. */
2179
2180static struct value *
2182 struct internalvar *var, void *ignore)
2183{
2184 int int_val = 0;
2185
2186 if (inferior_ptid != null_ptid)
2187 int_val = current_inferior ()->non_exited_threads ().size ();
2188
2189 return value_from_longest (builtin_type (gdbarch)->builtin_int, int_val);
2190}
2191
2192/* Commands with a prefix of `thread'. */
2193struct cmd_list_element *thread_cmd_list = NULL;
2194
2195/* Implementation of `thread' variable. */
2197static const struct internalvar_funcs thread_funcs =
2198{
2200 NULL,
2201};
2202
2203/* Implementation of `gthread' variable. */
2205static const struct internalvar_funcs gthread_funcs =
2206{
2208 NULL,
2209};
2210
2211/* Implementation of `_inferior_thread_count` convenience variable. */
2217};
2218
2219void _initialize_thread ();
2220void
2222{
2223 static struct cmd_list_element *thread_apply_list = NULL;
2225
2227
2228 /* Note: keep this "ID" in sync with what "info threads [TAB]"
2229 suggests. */
2230 static std::string info_threads_help
2232Display currently known threads.\n\
2233Usage: info threads [OPTION]... [ID]...\n\
2234If ID is given, it is a space-separated list of IDs of threads to display.\n\
2235Otherwise, all threads are displayed.\n\
2236\n\
2237Options:\n\
2238%OPTIONS%"),
2240
2241 c = add_info ("threads", info_threads_command, info_threads_help.c_str ());
2243
2244 cmd_list_element *thread_cmd
2245 = add_prefix_cmd ("thread", class_run, thread_command, _("\
2246Use this command to switch between threads.\n\
2247The new thread ID must be currently known."),
2248 &thread_cmd_list, 1, &cmdlist);
2249
2250 add_com_alias ("t", thread_cmd, class_run, 1);
2251
2252#define THREAD_APPLY_OPTION_HELP "\
2253Prints per-inferior thread number and target system's thread id\n\
2254followed by COMMAND output.\n\
2255\n\
2256By default, an error raised during the execution of COMMAND\n\
2257aborts \"thread apply\".\n\
2258\n\
2259Options:\n\
2260%OPTIONS%"
2261
2262 const auto thread_apply_opts = make_thread_apply_options_def_group (nullptr);
2263
2264 static std::string thread_apply_help = gdb::option::build_help (_("\
2265Apply a command to a list of threads.\n\
2266Usage: thread apply ID... [OPTION]... COMMAND\n\
2267ID is a space-separated list of IDs of threads to apply COMMAND on.\n"
2269 thread_apply_opts);
2270
2272 thread_apply_help.c_str (),
2273 &thread_apply_list, 1,
2276
2277 const auto thread_apply_all_opts
2278 = make_thread_apply_all_options_def_group (nullptr, nullptr);
2279
2280 static std::string thread_apply_all_help = gdb::option::build_help (_("\
2281Apply a command to all threads.\n\
2282\n\
2283Usage: thread apply all [OPTION]... COMMAND\n"
2285 thread_apply_all_opts);
2286
2288 thread_apply_all_help.c_str (),
2289 &thread_apply_list);
2291
2292 c = add_com ("taas", class_run, taas_command, _("\
2293Apply a command to all threads (ignoring errors and empty output).\n\
2294Usage: taas [OPTION]... COMMAND\n\
2295shortcut for 'thread apply all -s [OPTION]... COMMAND'\n\
2296See \"help thread apply all\" for available options."));
2298
2299 c = add_com ("tfaas", class_run, tfaas_command, _("\
2300Apply a command to all frames of all threads (ignoring errors and empty output).\n\
2301Usage: tfaas [OPTION]... COMMAND\n\
2302shortcut for 'thread apply all -s -- frame apply all -s [OPTION]... COMMAND'\n\
2303See \"help frame apply all\" for available options."));
2305
2307 _("Set the current thread's name.\n\
2308Usage: thread name [NAME]\n\
2309If NAME is not given, then any existing name is removed."), &thread_cmd_list);
2310
2311 add_cmd ("find", class_run, thread_find_command, _("\
2312Find threads that match a regular expression.\n\
2313Usage: thread find REGEXP\n\
2314Will display thread ids whose name, target ID, or extra info matches REGEXP."),
2316
2317 add_setshow_boolean_cmd ("thread-events", no_class,
2318 &print_thread_events, _("\
2319Set printing of thread events (such as thread start and exit)."), _("\
2320Show printing of thread events (such as thread start and exit)."), NULL,
2321 NULL,
2324
2326Set thread debugging."), _("\
2327Show thread debugging."), _("\
2328When on messages about thread creation and deletion are printed."),
2329 nullptr,
2332
2333 create_internalvar_type_lazy ("_thread", &thread_funcs, NULL);
2334 create_internalvar_type_lazy ("_gthread", &gthread_funcs, NULL);
2335 create_internalvar_type_lazy ("_inferior_thread_count",
2337}
const char *const name
void annotate_new_thread(void)
Definition annotate.c:215
void annotate_thread_changed(void)
Definition annotate.c:224
void delete_breakpoint(struct breakpoint *bpt)
void bpstat_clear(bpstat **bsp)
int breakpoint_has_location_inserted_here(struct breakpoint *bp, const address_space *aspace, CORE_ADDR pc)
void delete_longjmp_breakpoint_at_next_stop(int thread)
@ disp_del_at_next_stop
Definition breakpoint.h:238
void btrace_teardown(struct thread_info *tp)
Definition btrace.c:1684
void add_completion(gdb::unique_xmalloc_ptr< char > name, completion_match_for_lcd *match_for_lcd=NULL, const char *text=NULL, const char *word=NULL)
Definition completer.c:1579
void advance_custom_word_point_by(int len)
Definition completer.c:2049
void set_use_custom_word_point(bool enable)
Definition completer.h:366
std::unordered_map< ptid_t, thread_info * > ptid_thread_map
Definition inferior.h:464
int highest_thread_num
Definition inferior.h:566
struct process_stratum_target * process_target()
Definition inferior.h:449
inf_non_exited_threads_range non_exited_threads()
Definition inferior.h:481
intrusive_list< thread_info > thread_list
Definition inferior.h:460
int num
Definition inferior.h:557
thread_info * find_thread(ptid_t ptid)
void maybe_remove_resumed_with_pending_wait_status(thread_info *thread)
void maybe_add_resumed_with_pending_wait_status(thread_info *thread)
thread_info(inferior *inf, ptid_t ptid)
Definition thread.c:343
void set_pending_waitstatus(const target_waitstatus &ws)
Definition thread.c:408
thread_suspend_state m_suspend
Definition gdbthread.h:572
std::vector< struct value * > stack_temporaries
Definition gdbthread.h:539
void set_resumed(bool resumed)
Definition thread.c:385
void clear_stop_pc()
Definition gdbthread.h:379
std::unique_ptr< struct thread_fsm > release_thread_fsm()
Definition gdbthread.h:461
intrusive_list_node< thread_info > step_over_list_node
Definition gdbthread.h:543
enum thread_state state
Definition gdbthread.h:339
int per_inf_num
Definition gdbthread.h:298
void set_running(bool running)
Definition thread.c:884
ptid_t ptid
Definition gdbthread.h:259
void set_executing(bool executing)
Definition thread.c:375
bool has_pending_waitstatus() const
Definition gdbthread.h:394
void clear_pending_waitstatus()
Definition thread.c:422
struct target_waitstatus pending_follow
Definition gdbthread.h:516
bool m_resumed
Definition gdbthread.h:562
bool m_executing
Definition gdbthread.h:568
bool deletable() const
Definition thread.c:365
private_thread_info_up priv
Definition gdbthread.h:528
struct thread_fsm * thread_fsm() const
Definition gdbthread.h:452
bool executing() const
Definition gdbthread.h:319
bool stack_temporaries_enabled
Definition gdbthread.h:535
struct inferior * inf
Definition gdbthread.h:301
const char * name() const
Definition gdbthread.h:306
~thread_info()
Definition thread.c:357
thread_control_state control
Definition gdbthread.h:343
const char * cur_tok() const
Definition tid-parse.c:160
bool in_thread_range() const
Definition tid-parse.c:311
bool tid_is_qualified() const
Definition tid-parse.c:187
bool finished() const
Definition tid-parse.c:137
bool get_tid_range(int *inf_num, int *thr_start, int *thr_end)
Definition tid-parse.c:284
void init(const char *tidlist, int default_inferior)
Definition tid-parse.c:125
bool get_tid(int *inf_num, int *thr_num)
Definition tid-parse.c:295
bool in_star_range() const
Definition tid-parse.c:305
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void field_signed(const char *fldname, LONGEST value)
Definition ui-out.c:437
void field_skip(const char *fldname)
Definition ui-out.c:499
void text(const char *string)
Definition ui-out.c:566
void table_header(int width, ui_align align, const std::string &col_name, const std::string &col_hdr)
Definition ui-out.c:363
bool is_mi_like_p() const
Definition ui-out.c:810
void table_body()
Definition ui-out.c:376
void message(const char *format,...) ATTRIBUTE_PRINTF(2
Definition ui-out.c:774
struct cmd_list_element * showprintlist
Definition cli-cmds.c:163
struct cmd_list_element * cmdlist
Definition cli-cmds.c:87
struct cmd_list_element * setprintlist
Definition cli-cmds.c:161
struct cmd_list_element * showdebuglist
Definition cli-cmds.c:167
struct cmd_list_element * setdebuglist
Definition cli-cmds.c:165
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
Definition cli-decode.c:233
void set_cmd_completer_handle_brkchars(struct cmd_list_element *cmd, completer_handle_brkchars_ftype *func)
Definition cli-decode.c:125
cmd_list_element * add_com_alias(const char *name, cmd_list_element *target, command_class theclass, int abbrev_flag)
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
Definition cli-decode.c:357
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
Definition cli-decode.c:809
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
int number_is_in_list(const char *list, int number)
Definition cli-utils.c:348
void validate_flags_qcs(const char *which_command, qcs_flags *flags)
Definition cli-utils.c:436
@ class_maintenance
Definition command.h:65
@ class_run
Definition command.h:54
@ no_class
Definition command.h:53
void complete_nested_command_line(completion_tracker &tracker, const char *text)
Definition completer.c:464
EXTERN_C char * re_comp(const char *)
@ USER_SELECTED_THREAD
Definition defs.h:598
@ USER_SELECTED_FRAME
Definition defs.h:601
void restore_selected_frame(frame_id frame_id, int frame_level) noexcept
Definition frame.c:1761
void reinit_frame_cache(void)
Definition frame.c:2107
void save_selected_frame(frame_id *frame_id, int *frame_level) noexcept
Definition frame.c:1751
bool has_stack_frames()
Definition frame.c:1859
frame_info_ptr get_selected_frame(const char *message)
Definition frame.c:1888
@ LOCATION
Definition frame.h:809
@ SRC_AND_LOC
Definition frame.h:811
void print_stack_frame(frame_info_ptr, int print_level, enum print_what print_what, int set_current_sal)
Definition stack.c:353
void print_stack_frame_to_uiout(struct ui_out *uiout, frame_info_ptr, int print_level, enum print_what print_what, int set_current_sal)
Definition stack.c:337
void execute_command_to_string(std::string &res, const char *p, int from_tty, bool term_out)
Definition top.c:670
void execute_command(const char *, int)
Definition top.c:459
all_threads_safe_range all_threads_safe()
Definition gdbthread.h:770
all_matching_threads_range all_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
Definition gdbthread.h:742
all_non_exited_threads_range all_non_exited_threads(process_stratum_target *proc_target=nullptr, ptid_t filter_ptid=minus_one_ptid)
Definition gdbthread.h:753
thread_state
Definition gdbthread.h:70
@ THREAD_STOPPED
Definition gdbthread.h:72
@ THREAD_RUNNING
Definition gdbthread.h:75
@ THREAD_EXITED
Definition gdbthread.h:79
struct thread_info * inferior_thread(void)
Definition thread.c:85
void switch_to_thread(struct thread_info *thr)
Definition thread.c:1360
std::unique_ptr< private_thread_info > private_thread_info_up
Definition gdbthread.h:226
#define threads_debug_printf(fmt,...)
Definition gdbthread.h:49
gdb::ref_ptr< struct thread_info, refcounted_object_ref_policy > thread_info_ref
Definition gdbthread.h:592
intrusive_list< thread_info, thread_step_over_list_node > thread_step_over_list
Definition gdbthread.h:947
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1861
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition gnu-nat.c:1791
#define thread_info
Definition gnu-nat.h:26
size_t size
Definition go32-nat.c:239
ptid_t inferior_ptid
Definition infcmd.c:74
struct inferior * find_inferior_ptid(process_stratum_target *targ, ptid_t ptid)
Definition inferior.c:406
void set_current_inferior(struct inferior *inf)
Definition inferior.c:61
struct inferior * current_inferior(void)
Definition inferior.c:55
void switch_to_inferior_no_thread(inferior *inf)
Definition inferior.c:712
intrusive_list< inferior > inferior_list
Definition inferior.c:43
struct inferior * find_inferior_id(int num)
Definition inferior.c:379
all_inferiors_range all_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:821
all_non_exited_inferiors_range all_non_exited_inferiors(process_stratum_target *proc_target=nullptr)
Definition inferior.h:830
void notify_user_selected_context_changed(user_selected_what selection)
Definition infrun.c:6377
thread_step_over_list global_thread_step_over_list
Definition infrun.c:1393
#define infrun_debug_printf(fmt,...)
Definition infrun.h:38
void clear_inline_frame_state(process_stratum_target *target, ptid_t filter_ptid)
void interps_notify_thread_exited(thread_info *t, gdb::optional< ULONGEST > exit_code, int silent)
Definition interps.c:432
void interps_notify_target_resumed(ptid_t ptid)
Definition interps.c:483
void interps_notify_new_thread(thread_info *t)
Definition interps.c:424
static void set_language(const char *language)
Definition language.c:140
const struct language_defn * current_language
Definition language.c:82
observable< ptid_t > thread_stop_requested
observable< struct thread_info * > new_thread
observable< process_stratum_target *, ptid_t, ptid_t > thread_ptid_changed
observable< ptid_t > target_resumed
observable< thread_info *, gdb::optional< ULONGEST >, bool > thread_exit
bool process_options(const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:627
@ PROCESS_OPTIONS_UNKNOWN_IS_ERROR
Definition cli-option.h:333
@ PROCESS_OPTIONS_UNKNOWN_IS_OPERAND
Definition cli-option.h:337
std::string build_help(const char *help_tmpl, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:766
void complete_on_all_options(completion_tracker &tracker, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:170
bool complete_options(completion_tracker &tracker, const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
Definition cli-option.c:467
Definition aarch64.h:67
void set_current_program_space(struct program_space *pspace)
Definition progspace.c:243
void frame_apply_all_cmd_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
Definition stack.c:3075
const option_def & def() const
Definition cli-option.h:119
Definition gnu-nat.c:153
pid_t pid
Definition gnu-nat.c:165
struct proc * threads
Definition gnu-nat.c:157
enum language la_language
Definition language.h:275
virtual ~private_thread_info()=0
const char * shortname() const
Definition target.h:456
target_waitstatus & set_spurious()
Definition waitstatus.h:300
CORE_ADDR step_range_start
Definition gdbthread.h:124
struct breakpoint * exception_resume_breakpoint
Definition gdbthread.h:105
struct breakpoint * step_resume_breakpoint
Definition gdbthread.h:102
struct breakpoint * single_step_breakpoints
Definition gdbthread.h:112
struct target_waitstatus waitstatus
Definition gdbthread.h:194
Definition value.h:130
int target_has_stack()
Definition target.c:177
int target_core_of_thread(ptid_t ptid)
Definition target.c:3949
void target_update_thread_list(void)
Definition target.c:3776
struct thread_info * target_thread_handle_to_thread_info(const gdb_byte *thread_handle, int handle_len, struct inferior *inf)
Definition target.c:2637
int target_has_registers()
Definition target.c:189
int target_has_memory()
Definition target.c:165
const char * target_thread_name(struct thread_info *info)
Definition target.c:2629
const char * target_extra_thread_info(thread_info *tp)
Definition target.c:418
std::string target_pid_to_str(ptid_t ptid)
Definition target.c:2623
int target_thread_alive(ptid_t ptid)
Definition target.c:3770
void switch_to_thread(thread_info *thr)
Definition thread.c:1360
void delete_exception_resume_breakpoint(struct thread_info *tp)
Definition thread.c:111
thread_info * any_thread_of_inferior(inferior *inf)
Definition thread.c:648
static thread_info * current_thread_
Definition thread.c:74
static const gdb::option::flag_option_def ascending_option_def
Definition thread.c:1568
static bool set_running_thread(struct thread_info *tp, bool running)
Definition thread.c:848
bool switch_to_thread_if_alive(thread_info *thr)
Definition thread.c:716
static void notify_new_thread(thread_info *t)
Definition thread.c:289
int thread_step_over_chain_length(const thread_step_over_list &l)
Definition thread.c:443
struct thread_info * add_thread(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:336
static const gdb::option::option_def thr_qcs_flags_option_defs[]
Definition thread.c:1580
const char * thread_state_string(enum thread_state state)
Definition thread.c:2113
static void tfaas_command(const char *cmd, int from_tty)
Definition thread.c:1850
void global_thread_step_over_chain_enqueue_chain(thread_step_over_list &&list)
Definition thread.c:468
static void thread_apply_all_command_completer(cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
Definition thread.c:1735
int thread_count(process_stratum_target *proc_target)
Definition thread.c:605
void global_thread_step_over_chain_enqueue(struct thread_info *tp)
Definition thread.c:456
struct cmd_list_element * thread_cmd_list
Definition thread.c:2192
bool threads_are_executing(process_stratum_target *target)
Definition thread.c:925
struct thread_info * add_thread_silent(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:296
static bool is_current_thread(const thread_info *thr)
Definition thread.c:79
thread_info * first_thread_of_inferior(inferior *inf)
Definition thread.c:639
static const struct internalvar_funcs gthread_funcs
Definition thread.c:2204
void delete_step_resume_breakpoint(struct thread_info *tp)
Definition thread.c:104
void print_selected_thread_frame(struct ui_out *uiout, user_selected_what selection)
Definition thread.c:2009
void push_thread_stack_temporary(thread_info *tp, struct value *v)
Definition thread.c:775
void delete_thread(thread_info *thread)
Definition thread.c:527
void switch_to_thread_no_regs(struct thread_info *thread)
Definition thread.c:1328
static bool tp_array_compar_descending(const thread_info_ref &a, const thread_info_ref &b)
Definition thread.c:1512
int show_inferior_qualified_tids(void)
Definition thread.c:1458
static void delete_thread_1(thread_info *thr, gdb::optional< ULONGEST > exit_code, bool silent)
Definition thread.c:489
void validate_registers_access(void)
Definition thread.c:958
static void info_threads_command(const char *arg, int from_tty)
Definition thread.c:1291
static struct value * thread_num_make_value_helper(struct gdbarch *gdbarch, int global)
Definition thread.c:2135
static bool should_print_thread(const char *requested_threads, int default_inf_num, int global_ids, int pid, struct thread_info *thr)
Definition thread.c:1017
bool value_in_thread_stack_temporaries(struct value *val, thread_info *tp)
Definition thread.c:785
static void thread_apply_command(const char *tidlist, int from_tty)
Definition thread.c:1751
static void show_print_thread_events(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition thread.c:1983
int valid_global_thread_id(int global_id)
Definition thread.c:621
static std::array< gdb::option::option_def_group, 2 > make_thread_apply_all_options_def_group(bool *ascending, qcs_flags *flags)
Definition thread.c:1601
bool debug_threads
Definition thread.c:56
static void update_threads_executing(void)
Definition thread.c:2052
bool can_access_registers_thread(thread_info *thread)
Definition thread.c:982
int show_thread_that_caused_stop(void)
Definition thread.c:1450
bool pc_in_thread_step_range(CORE_ADDR pc, struct thread_info *thread)
Definition thread.c:1000
static void info_threads_command_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word_ignored)
Definition thread.c:1305
value * get_last_thread_stack_temporary(thread_info *tp)
Definition thread.c:799
static void notify_target_resumed(ptid_t ptid)
Definition thread.c:875
static struct value * thread_id_per_inf_num_make_value(struct gdbarch *gdbarch, struct internalvar *var, void *ignore)
Definition thread.c:2158
bool any_thread_p()
Definition thread.c:597
static bool tp_array_compar_ascending(const thread_info_ref &a, const thread_info_ref &b)
Definition thread.c:1499
static void show_debug_threads(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
Definition thread.c:61
void set_stop_requested(process_stratum_target *targ, ptid_t ptid, bool stop)
Definition thread.c:931
struct thread_info * iterate_over_threads(int(*callback)(struct thread_info *, void *), void *data)
Definition thread.c:584
struct thread_info * find_thread_global_id(int global_id)
Definition thread.c:539
static void taas_command(const char *cmd, int from_tty)
Definition thread.c:1839
const char * print_full_thread_id(struct thread_info *thr)
Definition thread.c:1485
void finish_thread_state(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:943
thread_info * any_live_thread_of_inferior(inferior *inf)
Definition thread.c:663
static void thread_apply_command_completer(cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
Definition thread.c:1676
void set_thread_exited(thread_info *tp, gdb::optional< ULONGEST > exit_code, bool silent)
Definition thread.c:218
void update_thread_list(void)
Definition thread.c:2086
void set_executing(process_stratum_target *targ, ptid_t ptid, bool executing)
Definition thread.c:908
struct thread_info * inferior_thread(void)
Definition thread.c:85
static gdb::option::option_def_group make_thread_apply_options_def_group(qcs_flags *flags)
Definition thread.c:1614
void thread_command(const char *tidstr, int from_tty)
Definition thread.c:1862
static void delete_thread_breakpoint(struct breakpoint **bp_p)
Definition thread.c:94
static void thread_find_command(const char *arg, int from_tty)
Definition thread.c:1924
void thread_try_catch_cmd(thread_info *thr, gdb::optional< int > ada_task, const char *cmd, int from_tty, const qcs_flags &flags)
Definition thread.c:1523
void set_running(process_stratum_target *targ, ptid_t ptid, bool running)
Definition thread.c:891
int thread_has_single_step_breakpoint_here(struct thread_info *tp, const address_space *aspace, CORE_ADDR addr)
Definition thread.c:150
bool thread_stack_temporaries_enabled_p(thread_info *tp)
Definition thread.c:764
static int highest_thread_num
Definition thread.c:71
void global_thread_step_over_chain_remove(struct thread_info *tp)
Definition thread.c:476
void delete_thread_with_exit_code(thread_info *thread, ULONGEST exit_code, bool silent)
Definition thread.c:518
static std::string thread_target_id_str(thread_info *tp)
Definition thread.c:1050
bool print_thread_events
Definition thread.c:1981
static void notify_thread_exited(thread_info *t, gdb::optional< ULONGEST > exit_code, int silent)
Definition thread.c:197
static struct thread_info * new_thread(struct inferior *inf, ptid_t ptid)
Definition thread.c:269
void thread_change_ptid(process_stratum_target *targ, ptid_t old_ptid, ptid_t new_ptid)
Definition thread.c:811
static int live_threads_count(void)
Definition thread.c:614
static void delete_at_next_stop(struct breakpoint **bp)
Definition thread.c:130
void set_resumed(process_stratum_target *targ, ptid_t ptid, bool resumed)
Definition thread.c:838
static struct value * inferior_thread_count_make_value(struct gdbarch *gdbarch, struct internalvar *var, void *ignore)
Definition thread.c:2180
static void thread_apply_all_command(const char *cmd, int from_tty)
Definition thread.c:1628
int thread_has_single_step_breakpoints_set(struct thread_info *tp)
Definition thread.c:142
const char * thread_name(thread_info *thread)
Definition thread.c:2095
int thread_is_in_step_over_chain(struct thread_info *tp)
Definition thread.c:435
static const gdb::option::option_def info_threads_option_defs[]
Definition thread.c:1265
void prune_threads(void)
Definition thread.c:737
static bool thread_alive(thread_info *tp)
Definition thread.c:702
#define THREAD_APPLY_OPTION_HELP
struct thread_info * find_thread_by_handle(gdb::array_view< const gdb_byte > handle, struct inferior *inf)
Definition thread.c:561
void _initialize_thread()
Definition thread.c:2220
static void thread_name_command(const char *arg, int from_tty)
Definition thread.c:1908
static void print_thread_info_1(struct ui_out *uiout, const char *requested_threads, int global_ids, int pid, int show_global_ids)
Definition thread.c:1072
struct thread_info * add_thread_with_info(process_stratum_target *targ, ptid_t ptid, private_thread_info_up priv)
Definition thread.c:321
void delete_single_step_breakpoints(struct thread_info *tp)
Definition thread.c:120
static void clear_thread_inferior_resources(struct thread_info *tp)
Definition thread.c:173
bool in_thread_list(process_stratum_target *targ, ptid_t ptid)
Definition thread.c:631
void switch_to_no_thread()
Definition thread.c:1345
void print_thread_info(struct ui_out *uiout, const char *requested_threads, int pid)
Definition thread.c:1251
void thread_cancel_execution_command(struct thread_info *thr)
Definition thread.c:163
const char * print_thread_id(struct thread_info *thr)
Definition thread.c:1470
void thread_select(const char *tidstr, thread_info *tp)
Definition thread.c:1994
static struct thread_info * find_thread_id(struct inferior *inf, int thr_num)
Definition thread.c:549
void delete_exited_threads(void)
Definition thread.c:753
void delete_thread_silent(thread_info *thread)
Definition thread.c:533
static const struct internalvar_funcs thread_funcs
Definition thread.c:2196
static struct value * global_thread_id_make_value(struct gdbarch *gdbarch, struct internalvar *var, void *ignore)
Definition thread.c:2169
static gdb::option::option_def_group make_info_threads_options_def_group(info_threads_opts *it_opts)
Definition thread.c:1279
static const struct internalvar_funcs inferior_thread_count_funcs
Definition thread.c:2212
void init_thread_list(void)
Definition thread.c:257
struct thread_info * parse_thread_id(const char *tidstr, const char **end)
Definition tid-parse.c:54
int tid_is_in_list(const char *list, int default_inferior, int inf_num, int thr_num)
Definition tid-parse.c:319
void ATTRIBUTE_NORETURN invalid_thread_id_error(const char *string)
Definition tid-parse.c:29
@ ui_left
Definition ui-out.h:45
#define current_uiout
Definition ui-out.h:40
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1886
#define gdb_stdout
Definition utils.h:182
struct internalvar * create_internalvar_type_lazy(const char *name, const struct internalvar_funcs *funcs, void *data)
Definition value.c:1966
struct value * value_from_longest(struct type *type, LONGEST num)
Definition value.c:3438