Consolidate save_inferior_ptid/restore_inferior_ptid implementation to

one source file.
This commit is contained in:
Kevin Buettner 2001-05-06 22:22:03 +00:00
parent a7c92daeed
commit ce696e0556
12 changed files with 64 additions and 239 deletions

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

View 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;
}

View 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;
/*
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;

View 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);

View 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);
}
static void
build_infrun (void)

View file

@ -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);

View 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

View 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)
{

View 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,

View 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));
}
/*
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. */

View 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);

View file

@ -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)
{