This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH RFC] process/thread/lwp id patch - phase 2


The patch below represents phase 2 of the mega-patch for introducing a
wider process/thread/lwp type (ptid_t) into the gdb sources that I
posted a week or so ago:

    http://sources.redhat.com/ml/gdb-patches/2001-04/msg00240.html

I expect that the patch below will be the least controversial of the
lot since it is relatively small and merely consolidates a lot of
replicated code into one location.

In a nutshell, this patch makes save_inferior_ptid() an extern
function, declaring it in inferior.h which is also where inferior_ptid
is declared.  save_inferior_ptid() and its helper,
restore_inferior_ptid(), are defined in infrun.c which,
coincidentally, is where inferior_ptid is defined.  It (infrun.c) is
also the location of the other ptid manipulation functions that will
show up in the upcoming phase 3 patch.  Finally, the redundant
machinery for saving and restoring inferior_ptid has been removed from
eight other source files.  A couple of FIXMEs in breakpoint.c
involving the saving and restoring of inferior_ptid were also
addressed.

If there are no objections, I'll commit this patch over the weekend.

	* 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.

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.32
diff -u -p -r1.32 breakpoint.c
--- breakpoint.c	2001/05/04 04:15:24	1.32
+++ breakpoint.c	2001/05/04 05:56:35
@@ -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;
 }
 
@@ -1205,13 +1205,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)
@@ -1219,12 +1219,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: hpux-thread.c
===================================================================
RCS file: /cvs/src/src/gdb/hpux-thread.c,v
retrieving revision 1.9
diff -u -p -r1.9 hpux-thread.c
--- hpux-thread.c	2001/05/04 04:15:25	1.9
+++ hpux-thread.c	2001/05/04 05:56:36
@@ -62,56 +62,12 @@ static ptid_t main_ptid;		/* Real proces
 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);
 
 static void init_hpux_thread_ops (void);
 
 static struct target_ops hpux_thread_ops;
-
-/*
-
-   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;
-}
 
 static int find_active_thread (void);
 
Index: inferior.h
===================================================================
RCS file: /cvs/src/src/gdb/inferior.h,v
retrieving revision 1.21
diff -u -p -r1.21 inferior.h
--- inferior.h	2001/05/04 04:15:25	1.21
+++ inferior.h	2001/05/04 05:56:38
@@ -51,6 +51,11 @@ extern void write_inferior_status_regist
 					    *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: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.31
diff -u -p -r1.31 infrun.c
--- infrun.c	2001/05/04 04:15:25	1.31
+++ infrun.c	2001/05/04 05:56:39
@@ -4192,6 +4192,30 @@ discard_inferior_status (struct inferior
   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;
+  free (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);
+}
+
 
 static void
 build_infrun (void)
Index: lin-lwp.c
===================================================================
RCS file: /cvs/src/src/gdb/lin-lwp.c,v
retrieving revision 1.14
diff -u -p -r1.14 lin-lwp.c
--- lin-lwp.c	2001/05/04 04:15:25	1.14
+++ lin-lwp.c	2001/05/04 05:56:40
@@ -264,27 +264,6 @@ iterate_over_lwps (int (*callback) (stru
 }
 
 
-/* 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);
-}
-
-
 /* Implementation of the PREPARE_TO_PROCEED hook for the Linux LWP
    layer.
 
Index: lin-thread.c
===================================================================
RCS file: /cvs/src/src/gdb/lin-thread.c,v
retrieving revision 1.14
diff -u -p -r1.14 lin-thread.c
--- lin-thread.c	2001/05/04 04:15:25	1.14
+++ lin-thread.c	2001/05/04 05:56:41
@@ -304,8 +304,6 @@ ps_ptwrite (gdb_ps_prochandle_t ph,	/* w
   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);
 
@@ -622,52 +620,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);
-}
 
 /*
 
Index: linux-thread.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-thread.c,v
retrieving revision 1.13
diff -u -p -r1.13 linux-thread.c
--- linux-thread.c	2001/05/04 04:15:25	1.13
+++ linux-thread.c	2001/05/04 05:56:42
@@ -374,26 +374,6 @@ linuxthreads_find_trap (int pid, int sto
   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: proc-service.c
===================================================================
RCS file: /cvs/src/src/gdb/proc-service.c,v
retrieving revision 1.3
diff -u -p -r1.3 proc-service.c
--- proc-service.c	2001/05/04 04:15:26	1.3
+++ proc-service.c	2001/05/04 05:56:42
@@ -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: sol-thread.c
===================================================================
RCS file: /cvs/src/src/gdb/sol-thread.c,v
retrieving revision 1.25
diff -u -p -r1.25 sol-thread.c
--- sol-thread.c	2001/05/04 04:15:27	1.25
+++ sol-thread.c	2001/05/04 05:56:43
@@ -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);
@@ -393,50 +391,6 @@ lwp_to_thread (ptid_t lwp)
     error ("lwp_to_thread: td_thr_get_info: %s.", td_err_string (val));
 
   return BUILD_THREAD (ti.ti_tid, PIDGET (lwp));
-}
-
-/*
-
-   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);
 }
 
 
Index: somsolib.c
===================================================================
RCS file: /cvs/src/src/gdb/somsolib.c,v
retrieving revision 1.11
diff -u -p -r1.11 somsolib.c
--- somsolib.c	2001/05/04 04:15:27	1.11
+++ somsolib.c	2001/05/04 05:56:44
@@ -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: thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/thread-db.c,v
retrieving revision 1.10
diff -u -p -r1.10 thread-db.c
--- thread-db.c	2001/05/04 04:15:28	1.10
+++ thread-db.c	2001/05/04 05:56:45
@@ -149,27 +149,6 @@ struct private_thread_info
 };
 
 
-/* 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);
-}
-
-
 static char *
 thread_db_err_str (td_err_e err)
 {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]