Fix arm-epoc-pe build problem:
[deliverable/binutils-gdb.git] / gdb / thread.c
index f4b57afc63685210dcb837ef92e97012be4c1aac..38e74d45b154e9c18664a63e2aaada2a2d26afc9 100644 (file)
@@ -35,6 +35,9 @@
 #include <ctype.h>
 #include <sys/types.h>
 #include <signal.h>
+#ifdef UI_OUT
+#include "ui-out.h"
+#endif
 
 /*#include "lynxos-core.h" */
 
 
 /* Prototypes for exported functions. */
 
-void _initialize_thread PARAMS ((void));
+void _initialize_thread (void);
 
 /* Prototypes for local functions. */
 
 static struct thread_info *thread_list = NULL;
 static int highest_thread_num;
 
-static struct thread_info *find_thread_id PARAMS ((int num));
+static struct thread_info *find_thread_id (int num);
 
-static void thread_command PARAMS ((char *tidstr, int from_tty));
-static void thread_apply_all_command PARAMS ((char *, int));
-static int thread_alive PARAMS ((struct thread_info *));
-static void info_threads_command PARAMS ((char *, int));
-static void thread_apply_command PARAMS ((char *, int));
-static void restore_current_thread PARAMS ((int));
-static void switch_to_thread PARAMS ((int pid));
-static void prune_threads PARAMS ((void));
+static void thread_command (char *tidstr, int from_tty);
+static void thread_apply_all_command (char *, int);
+static int thread_alive (struct thread_info *);
+static void info_threads_command (char *, int);
+static void thread_apply_command (char *, int);
+static void restore_current_thread (int);
+static void switch_to_thread (int pid);
+static void prune_threads (void);
 
 void
 init_thread_list ()
@@ -106,6 +109,7 @@ add_thread (pid)
   tp->stepping_through_solib_catchpoints = NULL;
   tp->stepping_through_sigtramp = 0;
   tp->next = thread_list;
+  tp->private = NULL;
   thread_list = tp;
   return tp;
 }
@@ -249,6 +253,37 @@ in_thread_list (pid)
 
   return 0;                    /* Never heard of 'im */
 }
+#ifdef UI_OUT
+/* Print a list of thread ids currently known, and the total number of
+   threads. To be used from within catch_errors. */
+static int 
+do_captured_list_thread_ids (void *arg)
+{
+  struct thread_info *tp;
+  int num = 0;
+
+  ui_out_list_begin (uiout, "thread-ids");
+
+  for (tp = thread_list; tp; tp = tp->next)
+    {
+      num++;
+      ui_out_field_int (uiout, "thread-id", tp->num);
+    }
+
+  ui_out_list_end (uiout);
+  ui_out_field_int (uiout, "number-of-threads", num);
+  return GDB_RC_OK;
+}
+
+/* Official gdblib interface function to get a list of thread ids and
+   the total number. */
+enum gdb_rc
+gdb_list_thread_ids (/* output object */)
+{
+  return catch_errors (do_captured_list_thread_ids, NULL,
+                      NULL, RETURN_MASK_ALL);
+}
+#endif
 
 /* Load infrun state for the thread PID.  */
 
@@ -484,6 +519,28 @@ restore_current_thread (pid)
     }
 }
 
+struct current_thread_cleanup
+{
+  int inferior_pid;
+};
+
+static void
+do_restore_current_thread_cleanup (void *arg)
+{
+  struct current_thread_cleanup *old = arg;
+  restore_current_thread (old->inferior_pid);
+  free (old);
+}
+
+static struct cleanup *
+make_cleanup_restore_current_thread (int inferior_pid)
+{
+  struct current_thread_cleanup *old
+    = xmalloc (sizeof (struct current_thread_cleanup));
+  old->inferior_pid = inferior_pid;
+  return make_cleanup (do_restore_current_thread_cleanup, old);
+}
+
 /* Apply a GDB command to a list of threads.  List syntax is a whitespace
    seperated list of numbers, or ranges, or the keyword `all'.  Ranges consist
    of two numbers seperated by a hyphen.  Examples:
@@ -504,8 +561,7 @@ thread_apply_all_command (cmd, from_tty)
   if (cmd == NULL || *cmd == '\000')
     error ("Please specify a command following the thread ID list");
 
-  old_chain = make_cleanup ((make_cleanup_func) restore_current_thread,
-                           (void *) inferior_pid);
+  old_chain = make_cleanup_restore_current_thread (inferior_pid);
 
   for (tp = thread_list; tp; tp = tp->next)
     if (thread_alive (tp))
@@ -521,6 +577,8 @@ thread_apply_all_command (cmd, from_tty)
 #endif
        execute_command (cmd, from_tty);
       }
+
+  do_cleanups (old_chain);
 }
 
 static void
@@ -540,8 +598,7 @@ thread_apply_command (tidlist, from_tty)
   if (*cmd == '\000')
     error ("Please specify a command following the thread ID list");
 
-  old_chain = make_cleanup ((make_cleanup_func) restore_current_thread,
-                           (void *) inferior_pid);
+  old_chain = make_cleanup_restore_current_thread (inferior_pid);
 
   while (tidlist < cmd)
     {
@@ -592,6 +649,8 @@ thread_apply_command (tidlist, from_tty)
            }
        }
     }
+
+  do_cleanups (old_chain);
 }
 
 /* Switch to the specified thread.  Will dispatch off to thread_apply_command
@@ -602,9 +661,6 @@ thread_command (tidstr, from_tty)
      char *tidstr;
      int from_tty;
 {
-  int num;
-  struct thread_info *tp;
-
   if (!tidstr)
     {
       /* Don't generate an error, just say which thread is current. */
@@ -621,22 +677,45 @@ thread_command (tidstr, from_tty)
        error ("No stack.");
       return;
     }
-  num = atoi (tidstr);
+
+  gdb_thread_select (tidstr);
+}
+
+static int
+do_captured_thread_select (void *tidstr)
+{
+  int num;
+  struct thread_info *tp;
+
+  num = atoi ((char *)tidstr);
 
   tp = find_thread_id (num);
 
+#ifdef UI_OUT
+  if (!tp)
+    error ("Thread ID %d not known.", num);
+#else
   if (!tp)
     error ("Thread ID %d not known.  Use the \"info threads\" command to\n\
 see the IDs of currently known threads.", num);
+#endif
 
   if (!thread_alive (tp))
     error ("Thread ID %d has terminated.\n", num);
 
   switch_to_thread (tp->pid);
 
-  if (context_hook)
-    context_hook (num);
-
+#ifdef UI_OUT
+  ui_out_text (uiout, "[Switching to thread ");
+  ui_out_field_int (uiout, "new-thread-id", pid_to_thread_id (inferior_pid));
+  ui_out_text (uiout, " (");
+#if defined(HPUXHPPA)
+  ui_out_text (uiout, target_tid_to_str (inferior_pid));
+#else
+  ui_out_text (uiout, target_pid_to_str (inferior_pid));
+#endif
+  ui_out_text (uiout, ")]");
+#else /* UI_OUT */
   printf_filtered ("[Switching to thread %d (%s)]\n",
                   pid_to_thread_id (inferior_pid),
 #if defined(HPUXHPPA)
@@ -645,7 +724,17 @@ see the IDs of currently known threads.", num);
                   target_pid_to_str (inferior_pid)
 #endif
     );
+#endif /* UI_OUT */
+
   print_stack_frame (selected_frame, selected_frame_level, 1);
+  return GDB_RC_OK;
+}
+
+enum gdb_rc
+gdb_thread_select (char *tidstr)
+{
+  return catch_errors (do_captured_thread_select, tidstr,
+                      NULL, RETURN_MASK_ALL);
 }
 
 /* Commands with a prefix of `thread'.  */
This page took 0.025575 seconds and 4 git commands to generate.