Consolidate save_inferior_ptid/restore_inferior_ptid implementation to
authorKevin Buettner <kevinb@redhat.com>
Sun, 6 May 2001 22:22:03 +0000 (22:22 +0000)
committerKevin Buettner <kevinb@redhat.com>
Sun, 6 May 2001 22:22:03 +0000 (22:22 +0000)
one source file.

12 files changed:
gdb/ChangeLog
gdb/breakpoint.c
gdb/hpux-thread.c
gdb/inferior.h
gdb/infrun.c
gdb/lin-lwp.c
gdb/lin-thread.c
gdb/linux-thread.c
gdb/proc-service.c
gdb/sol-thread.c
gdb/somsolib.c
gdb/thread-db.c

index 28555d9c16017cad26dd38f001393134193f6b5f..b577f60d3b0740c8ac11d38c5ee32a8ec56504b1 100644 (file)
@@ -1,3 +1,26 @@
+2001-05-06  Kevin Buettner  <kevinb@redhat.com>
+
+       * inferior.h (save_inferior_ptid): Declare.
+       * infrun.c (save_inferior_ptid, restore_inferior_ptid): Define.
+
+       * hpux-thread.c (save_inferior_ptid, restore_inferior_ptid):
+       Delete these functions.
+       * lin-lwp.c (save_inferior_ptid, restore_inferior_ptid): Likewise.
+       * lin-thread.c (save_inferior_ptid, restore_inferior_ptid): Likewise.
+       * linux-thread.c (save_inferior_ptid, restore_inferior_ptid):
+       Likewise.
+       * proc-service.c (save_inferior_ptid, restore_inferior_ptid):
+       Likewise.
+       * sol-thread.c (save_inferior_ptid, restore_inferior_ptid): Likewise.
+       * thread-db.c (save_inferior_ptid, restore_inferior_ptid): Likewise.
+
+       * somsolib.c (reset_inferior_ptid): Delete.
+       (som_solib_remove_inferior_hook): Use save_inferior_ptid() to
+       build the cleanup struct.
+
+       * breakpoint.c (reattach_breakpoints, detach_breakpoints): Use
+       a cleanup to save/restore inferior_ptid.
+
 2001-05-06  Mark Kettenis  <kettenis@gnu.org>
 
        Implement attach/detach for multi-threaded programs on Linux.
index 272fac06a53a3d4febacbf4664588b3b85def6a7..6abca265b47ba7e5c39e5c4bb7d606075a12f076 100644 (file)
@@ -1061,10 +1061,10 @@ reattach_breakpoints (int pid)
 {
   register struct breakpoint *b;
   int val;
-  ptid_t saved_inferior_ptid = inferior_ptid;
+  struct cleanup *old_chain = save_inferior_ptid ();
 
-  /* FIXME: use a cleanup, to insure that inferior_ptid gets replaced! */
-  inferior_ptid = pid_to_ptid (pid);   /* Because remove_breakpoint will use this global. */
+  /* Set inferior_ptid; remove_breakpoint uses this global.  */
+  inferior_ptid = pid_to_ptid (pid);
   ALL_BREAKPOINTS (b)
   {
     if (b->inserted)
@@ -1076,12 +1076,12 @@ reattach_breakpoints (int pid)
          val = target_insert_breakpoint (b->address, b->shadow_contents);
        if (val != 0)
          {
-           inferior_ptid = saved_inferior_ptid;
+           do_cleanups (old_chain);
            return val;
          }
       }
   }
-  inferior_ptid = saved_inferior_ptid;
+  do_cleanups (old_chain);
   return 0;
 }
 
@@ -1221,13 +1221,13 @@ detach_breakpoints (int pid)
 {
   register struct breakpoint *b;
   int val;
-  ptid_t saved_inferior_ptid = inferior_ptid;
+  struct cleanup *old_chain = save_inferior_ptid ();
 
   if (pid == PIDGET (inferior_ptid))
     error ("Cannot detach breakpoints of inferior_ptid");
 
-  /* FIXME: use a cleanup, to insure that inferior_ptid gets replaced! */
-  inferior_ptid = pid_to_ptid (pid);   /* Because remove_breakpoint will use this global. */
+  /* Set inferior_ptid; remove_breakpoint uses this global.  */
+  inferior_ptid = pid_to_ptid (pid);
   ALL_BREAKPOINTS (b)
   {
     if (b->inserted)
@@ -1235,12 +1235,12 @@ detach_breakpoints (int pid)
        val = remove_breakpoint (b, mark_inserted);
        if (val != 0)
          {
-           inferior_ptid = saved_inferior_ptid;
+           do_cleanups (old_chain);
            return val;
          }
       }
   }
-  inferior_ptid = saved_inferior_ptid;
+  do_cleanups (old_chain);
   return 0;
 }
 
index 4efeb4a5725aaf9486f3e76cf1fbc5b4b3edd0a5..8401995c4850b58fe67617105a404779718658fb 100644 (file)
@@ -62,10 +62,6 @@ static ptid_t main_ptid;             /* Real process ID */
 static CORE_ADDR P_cma__g_known_threads;
 static CORE_ADDR P_cma__g_current_thread;
 
-static struct cleanup *save_inferior_ptid (void);
-
-static void restore_inferior_ptid (ptid_t pid);
-
 static void hpux_thread_resume (ptid_t ptid, int step,
                                 enum target_signal signo);
 
@@ -73,46 +69,6 @@ static void init_hpux_thread_ops (void);
 
 static struct target_ops hpux_thread_ops;
 \f
-/*
-
-   LOCAL FUNCTION
-
-   save_inferior_ptid - Save inferior_ptid on the cleanup list
-   restore_inferior_ptid - Restore inferior_ptid from the cleanup list
-
-   SYNOPSIS
-
-   struct cleanup *save_inferior_ptid ()
-   void restore_inferior_ptid (int pid)
-
-   DESCRIPTION
-
-   These two functions act in unison to restore inferior_ptid in
-   case of an error.
-
-   NOTES
-
-   inferior_ptid is a global variable that needs to be changed by many of
-   these routines before calling functions in procfs.c.  In order to
-   guarantee that inferior_ptid gets restored (in case of errors), you
-   need to call save_inferior_ptid before changing it.  At the end of the
-   function, you should invoke do_cleanups to restore it.
-
- */
-
-
-static struct cleanup *
-save_inferior_ptid (void)
-{
-  return make_cleanup (restore_inferior_ptid, inferior_ptid);
-}
-
-static void
-restore_inferior_ptid (ptid_t ptid)
-{
-  inferior_ptid = ptid;
-}
-\f
 static int find_active_thread (void);
 
 static int cached_thread;
index 35ac96edf6238bf33604056c14287be29cca209b..91741975941db2152541903a274aa33808f40039 100644 (file)
@@ -51,6 +51,11 @@ extern void write_inferior_status_register (struct inferior_status
                                            *inf_status, int regno,
                                            LONGEST val);
 
+/* Save value of inferior_ptid so that it may be restored by
+   a later call to do_cleanups().  Returns the struct cleanup
+   pointer needed for later doing the cleanup.  */
+extern struct cleanup * save_inferior_ptid (void);
+
 extern void set_sigint_trap (void);
 
 extern void clear_sigint_trap (void);
index a62a72c069cc673e16f22eee8cfa48808ce0011e..21d07f27759f083b306bcbf7f3c0bbf8af13a7a9 100644 (file)
@@ -4192,6 +4192,30 @@ discard_inferior_status (struct inferior_status *inf_status)
   free_inferior_status (inf_status);
 }
 
+/* Helper function for save_inferior_ptid */
+
+static void
+restore_inferior_ptid (void *arg)
+{
+  ptid_t *saved_ptid_ptr = arg;
+  inferior_ptid = *saved_ptid_ptr;
+  xfree (arg);
+}
+
+/* Save the value of inferior_ptid so that it may be restored by a
+   later call to do_cleanups().  Returns the struct cleanup pointer
+   needed for later doing the cleanup.  */
+
+struct cleanup *
+save_inferior_ptid (void)
+{
+  ptid_t *saved_ptid_ptr;
+
+  saved_ptid_ptr = xmalloc (sizeof (ptid_t));
+  *saved_ptid_ptr = inferior_ptid;
+  return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
+}
+
 \f
 static void
 build_infrun (void)
index 58ad3c5857ee52b267d5b422622eca45e6dbaf3c..9525ac651ae16631d695f61a971754c7d488bbb7 100644 (file)
@@ -267,27 +267,6 @@ iterate_over_lwps (int (*callback) (struct lwp_info *, void *), void *data)
 }
 \f
 
-/* Helper functions.  */
-
-static void
-restore_inferior_ptid (void *arg)
-{
-  ptid_t *saved_ptid_ptr = arg;
-  inferior_ptid = *saved_ptid_ptr;
-  xfree (arg);
-}
-
-static struct cleanup *
-save_inferior_ptid (void)
-{
-  ptid_t *saved_ptid_ptr;
-
-  saved_ptid_ptr = xmalloc (sizeof (ptid_t));
-  *saved_ptid_ptr = inferior_ptid;
-  return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
-}
-\f
-
 /* Implementation of the PREPARE_TO_PROCEED hook for the Linux LWP
    layer.
 
@@ -722,7 +701,7 @@ lin_lwp_wait (ptid_t ptid, struct target_waitstatus *ourstatus)
       if (debug_lin_lwp)
        fprintf_unfiltered (gdb_stdlog, 
                            "Waiting for specific LWP %d.\n",
-                           (int) GET_LWP (ptid));
+                           GET_LWP (ptid));
 
       /* We have a specific LWP to check.  */
       lp = find_lwp_pid (ptid);
index 495fb4311a033ee2eb81efec9d6737b0af7acc62..4e1ae7a2e2fa5799208c4a12de33f0232cbb5a4f 100644 (file)
@@ -304,8 +304,6 @@ ps_ptwrite (gdb_ps_prochandle_t ph, /* write to text segment */
   return rw_common (ph, addr, (char *) buf, size, PS_WRITE);
 }
 
-static struct cleanup *save_inferior_ptid    (void);
-static void            restore_inferior_ptid (void *saved_pid);
 static char *thr_err_string   (td_err_e);
 static char *thr_state_string (td_thr_state_e);
 
@@ -623,52 +621,6 @@ init_thread_db_library (void)
  * Local utility functions:
  */
 
-
-/*
-
-   LOCAL FUNCTION
-
-   save_inferior_ptid - Save inferior_ptid on the cleanup list
-   restore_inferior_ptid - Restore inferior_ptid from the cleanup list
-
-   SYNOPSIS
-
-   struct cleanup *save_inferior_ptid (void);
-   void            restore_inferior_ptid (void *saved_pid);
-
-   DESCRIPTION
-
-   These two functions act in unison to restore inferior_ptid in
-   case of an error.
-
-   NOTES
-
-   inferior_ptid is a global variable that needs to be changed by many
-   of these routines before calling functions in procfs.c.  In order
-   to guarantee that inferior_ptid gets restored (in case of errors),
-   you need to call save_inferior_ptid before changing it.  At the end
-   of the function, you should invoke do_cleanups to restore it.
-
- */
-
-static struct cleanup *
-save_inferior_ptid (void)
-{
-  ptid_t *saved_ptid_ptr;
-  
-  saved_ptid_ptr = xmalloc (sizeof (ptid_t));
-  *saved_ptid_ptr = inferior_ptid;
-  return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
-}
-
-static void
-restore_inferior_ptid (void *arg)
-{
-  ptid_t *saved_ptid_ptr = arg;
-  inferior_ptid = *saved_ptid_ptr;
-  xfree (arg);
-}
-
 /*
 
    LOCAL FUNCTION
index 922a5635704b937d843f14e03d93ec296f20a16c..62c07c4b164b36fafc9587ab30b68faeee2d5828 100644 (file)
@@ -374,26 +374,6 @@ linuxthreads_find_trap (int pid, int stop)
   return 1;
 }
 
-/* Cleanup stub for save_inferior_ptid.  */
-static void
-restore_inferior_ptid (void *arg)
-{
-  ptid_t *saved_ptid_ptr = arg;
-  inferior_ptid = *saved_ptid_ptr;
-  xfree (arg);
-}
-
-/* Register a cleanup to restore the value of inferior_ptid.  */
-static struct cleanup *
-save_inferior_ptid (void)
-{
-  ptid_t *saved_ptid_ptr;
-  
-  saved_ptid_ptr = xmalloc (sizeof (ptid_t));
-  *saved_ptid_ptr = inferior_ptid;
-  return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
-}
-
 static void
 sigchld_handler (int signo)
 {
index 74e81ae4b185e1ee47d314efc7bf1c0a6328f04a..37ab1bd7dad9deb64e2fdc67a0ea3c9ec2fb9785 100644 (file)
@@ -60,24 +60,6 @@ typedef size_t gdb_ps_size_t;
 
 /* Helper functions.  */
 
-static void
-restore_inferior_ptid (void *arg)
-{
-  ptid_t *saved_pid_ptr = arg;
-  inferior_ptid = *saved_pid_ptr;
-  xfree (arg);
-}
-
-static struct cleanup *
-save_inferior_ptid (void)
-{
-  ptid_t *saved_ptid_ptr;
-
-  saved_ptid_ptr = xmalloc (sizeof (ptid_t));
-  *saved_ptid_ptr = inferior_ptid;
-  return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
-}
-
 /* Transfer LEN bytes of memory between BUF and address ADDR in the
    process specified by PH.  If WRITE, transfer them to the process,
    else transfer them from the process.  Returns PS_OK for success,
index 97f3e2426a9e810776772ccdd07d5c1c9d0432c1..cf8f33c984361ec73edf973cbb4eb0ef01534be3 100644 (file)
@@ -97,8 +97,6 @@ static struct ps_prochandle main_ph;
 static td_thragent_t *main_ta;
 static int sol_thread_active = 0;
 
-static struct cleanup *save_inferior_ptid (void);
-static void restore_inferior_ptid (void *pid);
 static char *td_err_string (td_err_e errcode);
 static char *td_state_string (td_thr_state_e statecode);
 static ptid_t thread_to_lwp (ptid_t thread_id, int default_lwp);
@@ -395,50 +393,6 @@ lwp_to_thread (ptid_t lwp)
   return BUILD_THREAD (ti.ti_tid, PIDGET (lwp));
 }
 \f
-/*
-
-   LOCAL FUNCTION
-
-   save_inferior_ptid - Save inferior_ptid on the cleanup list
-   restore_inferior_ptid - Restore inferior_ptid from the cleanup list
-
-   SYNOPSIS
-
-   struct cleanup *save_inferior_ptid ()
-   void restore_inferior_ptid (int pid)
-
-   DESCRIPTION
-
-   These two functions act in unison to restore inferior_ptid in
-   case of an error.
-
-   NOTES
-
-   inferior_ptid is a global variable that needs to be changed by many of
-   these routines before calling functions in procfs.c.  In order to
-   guarantee that inferior_ptid gets restored (in case of errors), you
-   need to call save_inferior_ptid before changing it.  At the end of the
-   function, you should invoke do_cleanups to restore it.
-
- */
-
-
-static struct cleanup *
-save_inferior_ptid (void)
-{
-  ptid_t *saved_ptid = xmalloc (sizeof (ptid_t));
-  *saved_ptid = inferior_ptid;
-  return make_cleanup (restore_inferior_ptid, saved_ptid);
-}
-
-static void
-restore_inferior_ptid (void *data)
-{
-  ptid_t *saved_ptid = data;
-  inferior_ptid = *saved_ptid;
-  xfree (saved_ptid);
-}
-\f
 
 /* Most target vector functions from here on actually just pass through to
    procfs.c, as they don't need to do anything specific for threads.  */
index 6838fdd3c08d2417787c9d46a5ec2e6c2271311f..fe188ca460a0f8a314653b34f0af233f36f4b0df 100644 (file)
@@ -1031,14 +1031,6 @@ keep_going:
   clear_symtab_users ();
 }
 
-
-static void
-reset_inferior_ptid (int saved_inferior_ptid)
-{
-  inferior_ptid = saved_inferior_ptid;
-}
-
-
 /* This operation removes the "hook" between GDB and the dynamic linker,
    which causes the dld to notify GDB of shared library events.
 
@@ -1057,8 +1049,7 @@ som_solib_remove_inferior_hook (int pid)
   int status;
   char dld_flags_buffer[TARGET_INT_BIT / TARGET_CHAR_BIT];
   unsigned int dld_flags_value;
-  int saved_inferior_ptid = inferior_ptid;
-  struct cleanup *old_cleanups = make_cleanup (reset_inferior_ptid, saved_inferior_ptid);
+  struct cleanup *old_cleanups = save_inferior_ptid ();
 
   /* Ensure that we're really operating on the specified process. */
   inferior_ptid = pid_to_ptid (pid);
index ab94429bb8e37c2ac74885f32336aedb1dc55caa..2c2672ae52a183e5d9af75967ba130cb4d50770b 100644 (file)
@@ -150,27 +150,6 @@ struct private_thread_info
 };
 
 \f
-/* Helper functions.  */
-
-static void
-restore_inferior_ptid (void *arg)
-{
-  ptid_t *saved_ptid_ptr = arg;
-  inferior_ptid = *saved_ptid_ptr;
-  xfree (arg);
-}
-
-static struct cleanup *
-save_inferior_ptid (void)
-{
-  ptid_t *saved_ptid_ptr;
-
-  saved_ptid_ptr = xmalloc (sizeof (ptid_t));
-  *saved_ptid_ptr = inferior_ptid;
-  return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
-}
-\f
-
 static char *
 thread_db_err_str (td_err_e err)
 {
This page took 0.038058 seconds and 4 git commands to generate.