one source file.
+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.
{
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)
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;
}
{
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)
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;
}
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 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;
*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);
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)
}
\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.
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);
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);
* 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
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)
{
/* 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,
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);
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. */
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.
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);
};
\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)
{