* top.c (init_main): Make `set history file name' complete on file
[deliverable/binutils-gdb.git] / gdb / thread.c
index 38e74d45b154e9c18664a63e2aaada2a2d26afc9..7c047e19a656bd0fe0fd843bf1d6e7199ea75e44 100644 (file)
@@ -1,8 +1,9 @@
 /* Multi-process/thread control for GDB, the GNU debugger.
-   Copyright 1986, 1987, 1988, 1993, 1998, 1999, 2000
-
-   Contributed by Lynx Real-Time Systems, Inc.  Los Gatos, CA.
+   Copyright 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2001
    Free Software Foundation, Inc.
+   Contributed by Lynx Real-Time Systems, Inc.  Los Gatos, CA.
+   
 
    This file is part of GDB.
 
@@ -31,6 +32,7 @@
 #include "gdbthread.h"
 #include "command.h"
 #include "gdbcmd.h"
+#include "regcache.h"
 
 #include <ctype.h>
 #include <sys/types.h>
@@ -63,30 +65,45 @@ static void restore_current_thread (int);
 static void switch_to_thread (int pid);
 static void prune_threads (void);
 
+static void
+free_thread (struct thread_info *tp)
+{
+  /* NOTE: this will take care of any left-over step_resume breakpoints,
+     but not any user-specified thread-specific breakpoints. */
+  if (tp->step_resume_breakpoint)
+    delete_breakpoint (tp->step_resume_breakpoint);
+
+  /* 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)
+    xfree (tp->private);
+
+  xfree (tp);
+}
+
 void
-init_thread_list ()
+init_thread_list (void)
 {
   struct thread_info *tp, *tpnext;
 
+  highest_thread_num = 0;
   if (!thread_list)
     return;
 
   for (tp = thread_list; tp; tp = tpnext)
     {
       tpnext = tp->next;
-      free (tp);
+      free_thread (tp);
     }
 
   thread_list = NULL;
-  highest_thread_num = 0;
 }
 
 /* add_thread now returns a pointer to the new thread_info, 
    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;
 
@@ -115,8 +132,7 @@ add_thread (pid)
 }
 
 void
-delete_thread (pid)
-     int pid;
+delete_thread (int pid)
 {
   struct thread_info *tp, *tpprev;
 
@@ -134,24 +150,11 @@ delete_thread (pid)
   else
     thread_list = tp->next;
 
-  /* NOTE: this will take care of any left-over step_resume breakpoints,
-     but not any user-specified thread-specific breakpoints. */
-  if (tp->step_resume_breakpoint)
-    delete_breakpoint (tp->step_resume_breakpoint);
-
-  /* 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);
-
-  free (tp);
-
-  return;
+  free_thread (tp);
 }
 
 static struct thread_info *
-find_thread_id (num)
-     int num;
+find_thread_id (int num)
 {
   struct thread_info *tp;
 
@@ -164,8 +167,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;
 
@@ -191,9 +193,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;
 
@@ -205,8 +206,7 @@ iterate_over_threads (callback, data)
 }
 
 int
-valid_thread_id (num)
-     int num;
+valid_thread_id (int num)
 {
   struct thread_info *tp;
 
@@ -218,8 +218,7 @@ valid_thread_id (num)
 }
 
 int
-pid_to_thread_id (pid)
-     int pid;
+pid_to_thread_id (int pid)
 {
   struct thread_info *tp;
 
@@ -231,8 +230,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)
@@ -242,8 +240,7 @@ thread_id_to_pid (num)
 }
 
 int
-in_thread_list (pid)
-     int pid;
+in_thread_list (int pid)
 {
   struct thread_info *tp;
 
@@ -288,29 +285,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;
 
@@ -339,29 +322,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;
 
@@ -389,8 +358,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;
@@ -403,7 +371,7 @@ thread_alive (tp)
 }
 
 static void
-prune_threads ()
+prune_threads (void)
 {
   struct thread_info *tp, *next;
 
@@ -423,9 +391,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;
@@ -495,8 +461,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;
@@ -509,8 +474,7 @@ switch_to_thread (pid)
 }
 
 static void
-restore_current_thread (pid)
-     int pid;
+restore_current_thread (int pid)
 {
   if (pid != inferior_pid)
     {
@@ -529,7 +493,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 *
@@ -551,18 +515,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 = xstrdup (cmd);
+  saved_cmd_cleanup_chain = make_cleanup (xfree, (void *) saved_cmd);
   for (tp = thread_list; tp; tp = tp->next)
     if (thread_alive (tp))
       {
@@ -576,19 +548,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");
@@ -600,6 +574,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 = xstrdup (cmd);
+  saved_cmd_cleanup_chain = make_cleanup (xfree, (void *) saved_cmd);
   while (tidlist < cmd)
     {
       struct thread_info *tp;
@@ -646,10 +624,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);
 }
 
@@ -657,9 +637,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)
     {
@@ -741,7 +719,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.027928 seconds and 4 git commands to generate.