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