testsuite: Fix recent GCC FAIL: gdb.arch/i386-signal.exp
[deliverable/binutils-gdb.git] / gdb / thread.c
index 8ec6a38e391c4bd50e76bb141263a88495d350f1..13449a854a4345581c115bd2cd0eea97c100be08 100644 (file)
@@ -166,7 +166,7 @@ thread_cancel_execution_command (struct thread_info *thr)
 {
   if (thr->thread_fsm != NULL)
     {
-      thread_fsm_clean_up (thr->thread_fsm);
+      thread_fsm_clean_up (thr->thread_fsm, thr);
       thread_fsm_delete (thr->thread_fsm);
       thr->thread_fsm = NULL;
     }
@@ -1201,7 +1201,6 @@ print_thread_info_1 (struct ui_out *uiout, char *requested_threads,
   ptid_t current_ptid;
   struct cleanup *old_chain;
   const char *extra_info, *name, *target_id;
-  int current_thread = -1;
   struct inferior *inf;
   int default_inf_num = current_inferior ()->num;
 
@@ -1261,9 +1260,6 @@ print_thread_info_1 (struct ui_out *uiout, char *requested_threads,
       struct cleanup *chain2;
       int core;
 
-      if (ptid_equal (tp->ptid, current_ptid))
-       current_thread = tp->global_num;
-
       if (!should_print_thread (requested_threads, default_inf_num,
                                global_ids, pid, tp))
        continue;
@@ -1684,6 +1680,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)
 {
@@ -1721,7 +1725,7 @@ tp_array_compar (const void *ap_voidp, const void *bp_voidp)
 
   if (a->inf->num != b->inf->num)
     {
-      return ((a->inf->num > b->inf->num) - (a->inf->num < b->inf->num)
+      return (((a->inf->num > b->inf->num) - (a->inf->num < b->inf->num))
              * (tp_array_compar_ascending ? +1 : -1));
     }
 
@@ -1818,7 +1822,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;
@@ -1826,11 +1830,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 (!tid_range_parser_get_tid_range (&parser,
+                                          &inf_num, &thr_start, &thr_end))
+       {
+         cmd = (char *) tid_range_parser_string (&parser);
+         break;
+       }
+    }
 
-  if (*cmd == '\000')
+  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);
@@ -1850,6 +1868,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 ()
@@ -1885,7 +1923,7 @@ thread_apply_command (char *tidlist, int from_tty)
 void
 thread_command (char *tidstr, int from_tty)
 {
-  if (!tidstr)
+  if (tidstr == NULL)
     {
       if (ptid_equal (inferior_ptid, null_ptid))
        error (_("No thread selected"));
@@ -1905,10 +1943,31 @@ thread_command (char *tidstr, int from_tty)
        }
       else
        error (_("No stack."));
-      return;
     }
+  else
+    {
+      ptid_t previous_ptid = inferior_ptid;
+      enum gdb_rc result;
+
+      result = gdb_thread_select (current_uiout, tidstr, NULL);
 
-  gdb_thread_select (current_uiout, tidstr, NULL);
+      /* If thread switch did not succeed don't notify or print.  */
+      if (result == GDB_RC_FAIL)
+       return;
+
+      /* Print if the thread has not changed, otherwise an event will be sent.  */
+      if (ptid_equal (inferior_ptid, previous_ptid))
+       {
+         print_selected_thread_frame (current_uiout,
+                                      USER_SELECTED_THREAD
+                                      | USER_SELECTED_FRAME);
+       }
+      else
+       {
+         observer_notify_user_selected_context_changed (USER_SELECTED_THREAD
+                                                        | USER_SELECTED_FRAME);
+       }
+    }
 }
 
 /* Implementation of `thread name'.  */
@@ -1996,7 +2055,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))
@@ -2020,32 +2079,53 @@ do_captured_thread_select (struct ui_out *uiout, void *tidstr_v)
 
   annotate_thread_changed ();
 
-  if (ui_out_is_mi_like_p (uiout))
-    ui_out_field_int (uiout, "new-thread-id", inferior_thread ()->global_num);
-  else
+  /* Since the current thread may have changed, see if there is any
+     exited thread we can now delete.  */
+  prune_threads ();
+
+  return GDB_RC_OK;
+}
+
+/* Print thread and frame switch command response.  */
+
+void
+print_selected_thread_frame (struct ui_out *uiout,
+                            user_selected_what selection)
+{
+  struct thread_info *tp = inferior_thread ();
+  struct inferior *inf = current_inferior ();
+
+  if (selection & USER_SELECTED_THREAD)
     {
-      ui_out_text (uiout, "[Switching to thread ");
-      ui_out_field_string (uiout, "new-thread-id", print_thread_id (tp));
-      ui_out_text (uiout, " (");
-      ui_out_text (uiout, target_pid_to_str (inferior_ptid));
-      ui_out_text (uiout, ")]");
+      if (ui_out_is_mi_like_p (uiout))
+       {
+         ui_out_field_int (uiout, "new-thread-id",
+                           inferior_thread ()->global_num);
+       }
+      else
+       {
+         ui_out_text (uiout, "[Switching to thread ");
+         ui_out_field_string (uiout, "new-thread-id", print_thread_id (tp));
+         ui_out_text (uiout, " (");
+         ui_out_text (uiout, target_pid_to_str (inferior_ptid));
+         ui_out_text (uiout, ")]");
+       }
     }
 
-  /* Note that we can't reach this with an exited thread, due to the
-     thread_alive check above.  */
   if (tp->state == THREAD_RUNNING)
-    ui_out_text (uiout, "(running)\n");
-  else
     {
-      ui_out_text (uiout, "\n");
-      print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
+      if (selection & USER_SELECTED_THREAD)
+       ui_out_text (uiout, "(running)\n");
     }
+  else if (selection & USER_SELECTED_FRAME)
+    {
+      if (selection & USER_SELECTED_THREAD)
+       ui_out_text (uiout, "\n");
 
-  /* Since the current thread may have changed, see if there is any
-     exited thread we can now delete.  */
-  prune_threads ();
-
-  return GDB_RC_OK;
+      if (has_stack_frames ())
+       print_stack_frame_to_uiout (uiout, get_selected_frame (NULL),
+                                   1, SRC_AND_LOC, 1);
+    }
 }
 
 enum gdb_rc
@@ -2083,18 +2163,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 a new value for the selected thread's global id.  Return a
+   value of 0 if no thread is selected, or no threads exist.  */
 
-  return value_from_longest (builtin_type (gdbarch)->builtin_int,
-                            (tp ? tp->per_inf_num : 0));
+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'.  */
@@ -2104,7 +2211,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
 };
@@ -2162,6 +2278,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.02903 seconds and 4 git commands to generate.