2001-01-02 Michael Snyder <msnyder@cleaver.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / thread.c
index 00c6467f254b54958560155bd9b2360cb5fabafb..647976c5719694ac2905999c2b345d8a8f90ab76 100644 (file)
@@ -74,13 +74,13 @@ free_thread (struct thread_info *tp)
   /* FIXME: do I ever need to call the back-end to give it a
      chance at this private data before deleting the thread?  */
   if (tp->private)
-    free (tp->private);
+    xfree (tp->private);
 
-  free (tp);
+  xfree (tp);
 }
 
 void
-init_thread_list ()
+init_thread_list (void)
 {
   struct thread_info *tp, *tpnext;
 
@@ -101,8 +101,7 @@ init_thread_list ()
    so that back_ends can initialize their private data.  */
 
 struct thread_info *
-add_thread (pid)
-     int pid;
+add_thread (int pid)
 {
   struct thread_info *tp;
 
@@ -131,8 +130,7 @@ add_thread (pid)
 }
 
 void
-delete_thread (pid)
-     int pid;
+delete_thread (int pid)
 {
   struct thread_info *tp, *tpprev;
 
@@ -154,8 +152,7 @@ delete_thread (pid)
 }
 
 static struct thread_info *
-find_thread_id (num)
-     int num;
+find_thread_id (int num)
 {
   struct thread_info *tp;
 
@@ -168,8 +165,7 @@ find_thread_id (num)
 
 /* Find a thread_info by matching 'pid'.  */
 struct thread_info *
-find_thread_pid (pid)
-     int pid;
+find_thread_pid (int pid)
 {
   struct thread_info *tp;
 
@@ -195,9 +191,8 @@ find_thread_pid (pid)
  */
 
 struct thread_info *
-iterate_over_threads (callback, data)
-     int (*callback) ();
-     void *data;
+iterate_over_threads (int (*callback) (struct thread_info *, void *),
+                     void *data)
 {
   struct thread_info *tp;
 
@@ -209,8 +204,7 @@ iterate_over_threads (callback, data)
 }
 
 int
-valid_thread_id (num)
-     int num;
+valid_thread_id (int num)
 {
   struct thread_info *tp;
 
@@ -222,8 +216,7 @@ valid_thread_id (num)
 }
 
 int
-pid_to_thread_id (pid)
-     int pid;
+pid_to_thread_id (int pid)
 {
   struct thread_info *tp;
 
@@ -235,8 +228,7 @@ pid_to_thread_id (pid)
 }
 
 int
-thread_id_to_pid (num)
-     int num;
+thread_id_to_pid (int num)
 {
   struct thread_info *thread = find_thread_id (num);
   if (thread)
@@ -246,8 +238,7 @@ thread_id_to_pid (num)
 }
 
 int
-in_thread_list (pid)
-     int pid;
+in_thread_list (int pid)
 {
   struct thread_info *tp;
 
@@ -292,29 +283,15 @@ gdb_list_thread_ids (/* output object */)
 /* Load infrun state for the thread PID.  */
 
 void
-load_infrun_state (pid, prev_pc, prev_func_start, prev_func_name,
-                  trap_expected, step_resume_breakpoint,
-                  through_sigtramp_breakpoint, step_range_start,
-                  step_range_end, step_frame_address,
-                  handling_longjmp, another_trap,
-                  stepping_through_solib_after_catch,
-                  stepping_through_solib_catchpoints,
-                  stepping_through_sigtramp)
-     int pid;
-     CORE_ADDR *prev_pc;
-     CORE_ADDR *prev_func_start;
-     char **prev_func_name;
-     int *trap_expected;
-     struct breakpoint **step_resume_breakpoint;
-     struct breakpoint **through_sigtramp_breakpoint;
-     CORE_ADDR *step_range_start;
-     CORE_ADDR *step_range_end;
-     CORE_ADDR *step_frame_address;
-     int *handling_longjmp;
-     int *another_trap;
-     int *stepping_through_solib_after_catch;
-     bpstat *stepping_through_solib_catchpoints;
-     int *stepping_through_sigtramp;
+load_infrun_state (int pid, CORE_ADDR *prev_pc, CORE_ADDR *prev_func_start,
+                  char **prev_func_name, int *trap_expected,
+                  struct breakpoint **step_resume_breakpoint,
+                  struct breakpoint **through_sigtramp_breakpoint,
+                  CORE_ADDR *step_range_start, CORE_ADDR *step_range_end,
+                  CORE_ADDR *step_frame_address, int *handling_longjmp,
+                  int *another_trap, int *stepping_through_solib_after_catch,
+                  bpstat *stepping_through_solib_catchpoints,
+                  int *stepping_through_sigtramp)
 {
   struct thread_info *tp;
 
@@ -343,29 +320,15 @@ load_infrun_state (pid, prev_pc, prev_func_start, prev_func_name,
 /* Save infrun state for the thread PID.  */
 
 void
-save_infrun_state (pid, prev_pc, prev_func_start, prev_func_name,
-                  trap_expected, step_resume_breakpoint,
-                  through_sigtramp_breakpoint, step_range_start,
-                  step_range_end, step_frame_address,
-                  handling_longjmp, another_trap,
-                  stepping_through_solib_after_catch,
-                  stepping_through_solib_catchpoints,
-                  stepping_through_sigtramp)
-     int pid;
-     CORE_ADDR prev_pc;
-     CORE_ADDR prev_func_start;
-     char *prev_func_name;
-     int trap_expected;
-     struct breakpoint *step_resume_breakpoint;
-     struct breakpoint *through_sigtramp_breakpoint;
-     CORE_ADDR step_range_start;
-     CORE_ADDR step_range_end;
-     CORE_ADDR step_frame_address;
-     int handling_longjmp;
-     int another_trap;
-     int stepping_through_solib_after_catch;
-     bpstat stepping_through_solib_catchpoints;
-     int stepping_through_sigtramp;
+save_infrun_state (int pid, CORE_ADDR prev_pc, CORE_ADDR prev_func_start,
+                  char *prev_func_name, int trap_expected,
+                  struct breakpoint *step_resume_breakpoint,
+                  struct breakpoint *through_sigtramp_breakpoint,
+                  CORE_ADDR step_range_start, CORE_ADDR step_range_end,
+                  CORE_ADDR step_frame_address, int handling_longjmp,
+                  int another_trap, int stepping_through_solib_after_catch,
+                  bpstat stepping_through_solib_catchpoints,
+                  int stepping_through_sigtramp)
 {
   struct thread_info *tp;
 
@@ -393,8 +356,7 @@ save_infrun_state (pid, prev_pc, prev_func_start, prev_func_name,
 
 /* Return true if TP is an active thread. */
 static int
-thread_alive (tp)
-     struct thread_info *tp;
+thread_alive (struct thread_info *tp)
 {
   if (tp->pid == -1)
     return 0;
@@ -407,7 +369,7 @@ thread_alive (tp)
 }
 
 static void
-prune_threads ()
+prune_threads (void)
 {
   struct thread_info *tp, *next;
 
@@ -427,9 +389,7 @@ prune_threads ()
  */
 
 static void
-info_threads_command (arg, from_tty)
-     char *arg;
-     int from_tty;
+info_threads_command (char *arg, int from_tty)
 {
   struct thread_info *tp;
   int current_pid;
@@ -499,8 +459,7 @@ info_threads_command (arg, from_tty)
 /* Switch from one thread to another. */
 
 static void
-switch_to_thread (pid)
-     int pid;
+switch_to_thread (int pid)
 {
   if (pid == inferior_pid)
     return;
@@ -513,8 +472,7 @@ switch_to_thread (pid)
 }
 
 static void
-restore_current_thread (pid)
-     int pid;
+restore_current_thread (int pid)
 {
   if (pid != inferior_pid)
     {
@@ -533,7 +491,7 @@ do_restore_current_thread_cleanup (void *arg)
 {
   struct current_thread_cleanup *old = arg;
   restore_current_thread (old->inferior_pid);
-  free (old);
+  xfree (old);
 }
 
 static struct cleanup *
@@ -555,18 +513,26 @@ make_cleanup_restore_current_thread (int inferior_pid)
  */
 
 static void
-thread_apply_all_command (cmd, from_tty)
-     char *cmd;
-     int from_tty;
+thread_apply_all_command (char *cmd, int from_tty)
 {
   struct thread_info *tp;
   struct cleanup *old_chain;
+  struct cleanup *saved_cmd_cleanup_chain;
+  char *saved_cmd;
 
   if (cmd == NULL || *cmd == '\000')
     error ("Please specify a command following the thread ID list");
 
   old_chain = make_cleanup_restore_current_thread (inferior_pid);
 
+  /* It is safe to update the thread list now, before
+     traversing it for "thread apply all".  MVS */
+  target_find_new_threads ();
+
+  /* Save a copy of the command in case it is clobbered by
+     execute_command */
+  saved_cmd = strdup (cmd);
+  saved_cmd_cleanup_chain = make_cleanup (xfree, (void *) saved_cmd);
   for (tp = thread_list; tp; tp = tp->next)
     if (thread_alive (tp))
       {
@@ -580,19 +546,21 @@ thread_apply_all_command (cmd, from_tty)
                         target_pid_to_str (inferior_pid));
 #endif
        execute_command (cmd, from_tty);
+       strcpy (cmd, saved_cmd); /* Restore exact command used previously */
       }
 
+  do_cleanups (saved_cmd_cleanup_chain);
   do_cleanups (old_chain);
 }
 
 static void
-thread_apply_command (tidlist, from_tty)
-     char *tidlist;
-     int from_tty;
+thread_apply_command (char *tidlist, int from_tty)
 {
   char *cmd;
   char *p;
   struct cleanup *old_chain;
+  struct cleanup *saved_cmd_cleanup_chain;
+  char *saved_cmd;
 
   if (tidlist == NULL || *tidlist == '\000')
     error ("Please specify a thread ID list");
@@ -604,6 +572,10 @@ thread_apply_command (tidlist, from_tty)
 
   old_chain = make_cleanup_restore_current_thread (inferior_pid);
 
+  /* Save a copy of the command in case it is clobbered by
+     execute_command */
+  saved_cmd = strdup (cmd);
+  saved_cmd_cleanup_chain = make_cleanup (xfree, (void *) saved_cmd);
   while (tidlist < cmd)
     {
       struct thread_info *tp;
@@ -650,10 +622,12 @@ thread_apply_command (tidlist, from_tty)
                               target_pid_to_str (inferior_pid));
 #endif
              execute_command (cmd, from_tty);
+             strcpy (cmd, saved_cmd);  /* Restore exact command used previously */
            }
        }
     }
 
+  do_cleanups (saved_cmd_cleanup_chain);
   do_cleanups (old_chain);
 }
 
@@ -661,9 +635,7 @@ thread_apply_command (tidlist, from_tty)
    if prefix of arg is `apply'.  */
 
 static void
-thread_command (tidstr, from_tty)
-     char *tidstr;
-     int from_tty;
+thread_command (char *tidstr, int from_tty)
 {
   if (!tidstr)
     {
@@ -745,7 +717,7 @@ gdb_thread_select (char *tidstr)
 struct cmd_list_element *thread_cmd_list = NULL;
 
 void
-_initialize_thread ()
+_initialize_thread (void)
 {
   static struct cmd_list_element *thread_apply_list = NULL;
 
This page took 0.027538 seconds and 4 git commands to generate.