linux-record: Squash cases with identical handling
[deliverable/binutils-gdb.git] / gdb / thread.c
index dd8f7da0d647038e198c1cba96d6be5b90a6a194..75bfb4771b268df7fafb09efe86608fbc9061ef5 100644 (file)
@@ -1403,7 +1403,16 @@ print_thread_info (struct ui_out *uiout, char *requested_threads, int pid)
 static void
 info_threads_command (char *arg, int from_tty)
 {
-  print_thread_info_1 (current_uiout, arg, 0, -1, 0);
+  int show_global_ids = 0;
+
+  if (arg != NULL
+      && check_for_argument (&arg, "-gid", sizeof ("-gid") - 1))
+    {
+      arg = skip_spaces (arg);
+      show_global_ids = 1;
+    }
+
+  print_thread_info_1 (current_uiout, arg, 0, -1, show_global_ids);
 }
 
 /* See gdbthread.h.  */
@@ -1675,6 +1684,14 @@ make_cleanup_restore_current_thread (void)
 
 /* See gdbthread.h.  */
 
+int
+show_thread_that_caused_stop (void)
+{
+  return highest_thread_num > 1;
+}
+
+/* See gdbthread.h.  */
+
 int
 show_inferior_qualified_tids (void)
 {
@@ -1809,7 +1826,7 @@ thread_apply_all_command (char *cmd, int from_tty)
 static void
 thread_apply_command (char *tidlist, int from_tty)
 {
-  char *cmd;
+  char *cmd = NULL;
   struct cleanup *old_chain;
   char *saved_cmd;
   struct tid_range_parser parser;
@@ -1817,11 +1834,25 @@ thread_apply_command (char *tidlist, int from_tty)
   if (tidlist == NULL || *tidlist == '\000')
     error (_("Please specify a thread ID list"));
 
-  for (cmd = tidlist; *cmd != '\000' && !isalpha (*cmd); cmd++);
+  tid_range_parser_init (&parser, tidlist, current_inferior ()->num);
+  while (!tid_range_parser_finished (&parser))
+    {
+      int inf_num, thr_start, thr_end;
 
-  if (*cmd == '\000')
+      if (!tid_range_parser_get_tid_range (&parser,
+                                          &inf_num, &thr_start, &thr_end))
+       {
+         cmd = (char *) tid_range_parser_string (&parser);
+         break;
+       }
+    }
+
+  if (cmd == NULL)
     error (_("Please specify a command following the thread ID list"));
 
+  if (tidlist == cmd || !isalpha (cmd[0]))
+    invalid_thread_id_error (cmd);
+
   /* Save a copy of the command in case it is clobbered by
      execute_command.  */
   saved_cmd = xstrdup (cmd);
@@ -1841,6 +1872,26 @@ thread_apply_command (char *tidlist, int from_tty)
       inf = find_inferior_id (inf_num);
       if (inf != NULL)
        tp = find_thread_id (inf, thr_num);
+
+      if (tid_range_parser_star_range (&parser))
+       {
+         if (inf == NULL)
+           {
+             warning (_("Unknown inferior %d"), inf_num);
+             tid_range_parser_skip (&parser);
+             continue;
+           }
+
+         /* No use looking for threads past the highest thread number
+            the inferior ever had.  */
+         if (thr_num >= inf->highest_thread_num)
+           tid_range_parser_skip (&parser);
+
+         /* Be quiet about unknown threads numbers.  */
+         if (tp == NULL)
+           continue;
+       }
+
       if (tp == NULL)
        {
          if (show_inferior_qualified_tids ()
@@ -1987,7 +2038,7 @@ show_print_thread_events (struct ui_file *file, int from_tty,
 static int
 do_captured_thread_select (struct ui_out *uiout, void *tidstr_v)
 {
-  const char *tidstr = tidstr_v;
+  const char *tidstr = (const char *) tidstr_v;
   struct thread_info *tp;
 
   if (ui_out_is_mi_like_p (uiout))
@@ -2074,18 +2125,45 @@ update_thread_list (void)
   update_threads_executing ();
 }
 
+/* Return a new value for the selected thread's id.  Return a value of
+   0 if no thread is selected.  If GLOBAL is true, return the thread's
+   global number.  Otherwise return the per-inferior number.  */
+
+static struct value *
+thread_num_make_value_helper (struct gdbarch *gdbarch, int global)
+{
+  struct thread_info *tp = find_thread_ptid (inferior_ptid);
+  int int_val;
+
+  if (tp == NULL)
+    int_val = 0;
+  else if (global)
+    int_val = tp->global_num;
+  else
+    int_val = tp->per_inf_num;
+
+  return value_from_longest (builtin_type (gdbarch)->builtin_int, int_val);
+}
+
 /* Return a new value for the selected thread's per-inferior thread
    number.  Return a value of 0 if no thread is selected, or no
    threads exist.  */
 
 static struct value *
-thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
-                     void *ignore)
+thread_id_per_inf_num_make_value (struct gdbarch *gdbarch, struct internalvar *var,
+                                 void *ignore)
 {
-  struct thread_info *tp = find_thread_ptid (inferior_ptid);
+  return thread_num_make_value_helper (gdbarch, 0);
+}
 
-  return value_from_longest (builtin_type (gdbarch)->builtin_int,
-                            (tp ? tp->per_inf_num : 0));
+/* Return a new value for the selected thread's global id.  Return a
+   value of 0 if no thread is selected, or no threads exist.  */
+
+static struct value *
+global_thread_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
+                            void *ignore)
+{
+  return thread_num_make_value_helper (gdbarch, 1);
 }
 
 /* Commands with a prefix of `thread'.  */
@@ -2095,7 +2173,16 @@ struct cmd_list_element *thread_cmd_list = NULL;
 
 static const struct internalvar_funcs thread_funcs =
 {
-  thread_id_make_value,
+  thread_id_per_inf_num_make_value,
+  NULL,
+  NULL
+};
+
+/* Implementation of `gthread' variable.  */
+
+static const struct internalvar_funcs gthread_funcs =
+{
+  global_thread_id_make_value,
   NULL,
   NULL
 };
@@ -2107,7 +2194,8 @@ _initialize_thread (void)
 
   add_info ("threads", info_threads_command, 
            _("Display currently known threads.\n\
-Usage: info threads [ID]...\n\
+Usage: info threads [-gid] [ID]...\n\
+-gid: Show global thread IDs.\n\
 If ID is given, it is a space-separated list of IDs of threads to display.\n\
 Otherwise, all threads are displayed."));
 
@@ -2152,6 +2240,7 @@ Show printing of thread events (such as thread start and exit)."), NULL,
          &setprintlist, &showprintlist);
 
   create_internalvar_type_lazy ("_thread", &thread_funcs, NULL);
+  create_internalvar_type_lazy ("_gthread", &gthread_funcs, NULL);
 
   observer_attach_thread_ptid_changed (restore_current_thread_ptid_changed);
 }
This page took 0.028365 seconds and 4 git commands to generate.