summaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorKevin Buettner <kevinb@redhat.com>2001-05-06 22:22:03 +0000
committerKevin Buettner <kevinb@redhat.com>2001-05-06 22:22:03 +0000
commit5804effc2da38cf13cabc7a84a2c314dd4bd6d1e (patch)
tree2cc0af23c1ce60fe47549b576a92385dc9437394 /gdb
parent97692badc52dec581548db39d8a94936032dbc2c (diff)
downloadgdb-5804effc2da38cf13cabc7a84a2c314dd4bd6d1e.tar.gz
Consolidate save_inferior_ptid/restore_inferior_ptid implementation to
one source file.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog23
-rw-r--r--gdb/breakpoint.c20
-rw-r--r--gdb/hpux-thread.c44
-rw-r--r--gdb/inferior.h5
-rw-r--r--gdb/infrun.c24
-rw-r--r--gdb/lin-lwp.c23
-rw-r--r--gdb/lin-thread.c48
-rw-r--r--gdb/linux-thread.c20
-rw-r--r--gdb/proc-service.c18
-rw-r--r--gdb/sol-thread.c46
-rw-r--r--gdb/somsolib.c11
-rw-r--r--gdb/thread-db.c21
12 files changed, 64 insertions, 239 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 28555d9c160..b577f60d3b0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 272fac06a53..6abca265b47 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -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;
}
diff --git a/gdb/hpux-thread.c b/gdb/hpux-thread.c
index 4efeb4a5725..8401995c485 100644
--- a/gdb/hpux-thread.c
+++ b/gdb/hpux-thread.c
@@ -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;
-/*
-
- 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);
static int cached_thread;
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 35ac96edf62..91741975941 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -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);
diff --git a/gdb/infrun.c b/gdb/infrun.c
index a62a72c069c..21d07f27759 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -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);
+}
+
static void
build_infrun (void)
diff --git a/gdb/lin-lwp.c b/gdb/lin-lwp.c
index 58ad3c5857e..9525ac651ae 100644
--- a/gdb/lin-lwp.c
+++ b/gdb/lin-lwp.c
@@ -267,27 +267,6 @@ iterate_over_lwps (int (*callback) (struct lwp_info *, void *), void *data)
}
-/* 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.
@@ -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);
diff --git a/gdb/lin-thread.c b/gdb/lin-thread.c
index 495fb4311a0..4e1ae7a2e2f 100644
--- a/gdb/lin-thread.c
+++ b/gdb/lin-thread.c
@@ -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
diff --git a/gdb/linux-thread.c b/gdb/linux-thread.c
index 922a5635704..62c07c4b164 100644
--- a/gdb/linux-thread.c
+++ b/gdb/linux-thread.c
@@ -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)
{
diff --git a/gdb/proc-service.c b/gdb/proc-service.c
index 74e81ae4b18..37ab1bd7dad 100644
--- a/gdb/proc-service.c
+++ b/gdb/proc-service.c
@@ -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,
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
index 97f3e2426a9..cf8f33c9843 100644
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -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));
}
-/*
-
- 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);
-}
-
/* 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. */
diff --git a/gdb/somsolib.c b/gdb/somsolib.c
index 6838fdd3c08..fe188ca460a 100644
--- a/gdb/somsolib.c
+++ b/gdb/somsolib.c
@@ -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);
diff --git a/gdb/thread-db.c b/gdb/thread-db.c
index ab94429bb8e..2c2672ae52a 100644
--- a/gdb/thread-db.c
+++ b/gdb/thread-db.c
@@ -150,27 +150,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)
{