mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-05-31 10:09:16 +08:00
Remove save_inferior_ptid
This removes save_inferior_ptid, a cleanup function, in favor of scoped_restore. This also fixes a possible (it seems unlikely that it could happen in practice) memory leak -- save_inferior_ptid should have used make_cleanup_dtor, because it allocated memory. I tested this on the buildbot. However, there are two caveats to this. First, sometimes it seems I misread the results. Second, I think this patch touches some platforms that can't be tested by the buildbot. So, extra care seems warranted. ChangeLog 2017-08-18 Tom Tromey <tom@tromey.com> Pedro Alves <palves@redhat.com> * spu-multiarch.c (parse_spufs_run): Use scoped_restore. * sol-thread.c (sol_thread_resume, sol_thread_wait) (sol_thread_xfer_partial, rw_common): Use scoped_restore. * procfs.c (procfs_do_thread_registers): Use scoped_restore. * proc-service.c (ps_xfer_memory): Use scoped_restore. * linux-tdep.c (linux_corefile_thread): Remove a cleanup. (linux_get_siginfo_data): Add "thread" argument. Use scoped_restore. * linux-nat.c (linux_child_follow_fork) (check_stopped_by_watchpoint): Use scoped_restore. * infrun.c (displaced_step_prepare_throw, write_memory_ptid) (THREAD_STOPPED_BY, handle_signal_stop): Use scoped_restore. (restore_inferior_ptid, save_inferior_ptid): Remove. * btrace.c (btrace_fetch): Use scoped_restore. * bsd-uthread.c (bsd_uthread_fetch_registers) (bsd_uthread_store_registers): Use scoped_restore. * breakpoint.c (reattach_breakpoints, detach_breakpoints): Use scoped_restore. * aix-thread.c (aix_thread_resume, aix_thread_wait) (aix_thread_xfer_partial): Use scoped_restore. * inferior.h (save_inferior_ptid): Remove.
This commit is contained in:
@ -477,7 +477,6 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child,
|
||||
{
|
||||
struct lwp_info *child_lp = NULL;
|
||||
int status = W_STOPCODE (0);
|
||||
struct cleanup *old_chain;
|
||||
int has_vforked;
|
||||
ptid_t parent_ptid, child_ptid;
|
||||
int parent_pid, child_pid;
|
||||
@ -490,16 +489,15 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child,
|
||||
child_pid = ptid_get_lwp (child_ptid);
|
||||
|
||||
/* We're already attached to the parent, by default. */
|
||||
old_chain = save_inferior_ptid ();
|
||||
inferior_ptid = child_ptid;
|
||||
child_lp = add_lwp (inferior_ptid);
|
||||
child_lp = add_lwp (child_ptid);
|
||||
child_lp->stopped = 1;
|
||||
child_lp->last_resume_kind = resume_stop;
|
||||
|
||||
/* Detach new forked process? */
|
||||
if (detach_fork)
|
||||
{
|
||||
make_cleanup (delete_lwp_cleanup, child_lp);
|
||||
struct cleanup *old_chain = make_cleanup (delete_lwp_cleanup,
|
||||
child_lp);
|
||||
|
||||
if (linux_nat_prepare_to_resume != NULL)
|
||||
linux_nat_prepare_to_resume (child_lp);
|
||||
@ -513,7 +511,7 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child,
|
||||
once before detaching to clear the flags. */
|
||||
|
||||
if (!gdbarch_software_single_step_p (target_thread_architecture
|
||||
(child_lp->ptid)))
|
||||
(child_lp->ptid)))
|
||||
{
|
||||
linux_disable_event_reporting (child_pid);
|
||||
if (ptrace (PTRACE_SINGLESTEP, child_pid, 0, 0) < 0)
|
||||
@ -533,17 +531,18 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child,
|
||||
ptrace (PTRACE_DETACH, child_pid, 0, signo);
|
||||
}
|
||||
|
||||
/* Resets value of inferior_ptid to parent ptid. */
|
||||
do_cleanups (old_chain);
|
||||
}
|
||||
else
|
||||
{
|
||||
scoped_restore save_inferior_ptid
|
||||
= make_scoped_restore (&inferior_ptid);
|
||||
inferior_ptid = child_ptid;
|
||||
|
||||
/* Let the thread_db layer learn about this new process. */
|
||||
check_for_thread_db ();
|
||||
}
|
||||
|
||||
do_cleanups (old_chain);
|
||||
|
||||
if (has_vforked)
|
||||
{
|
||||
struct lwp_info *parent_lp;
|
||||
@ -2458,12 +2457,10 @@ maybe_clear_ignore_sigint (struct lwp_info *lp)
|
||||
static int
|
||||
check_stopped_by_watchpoint (struct lwp_info *lp)
|
||||
{
|
||||
struct cleanup *old_chain;
|
||||
|
||||
if (linux_ops->to_stopped_by_watchpoint == NULL)
|
||||
return 0;
|
||||
|
||||
old_chain = save_inferior_ptid ();
|
||||
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
|
||||
inferior_ptid = lp->ptid;
|
||||
|
||||
if (linux_ops->to_stopped_by_watchpoint (linux_ops))
|
||||
@ -2478,8 +2475,6 @@ check_stopped_by_watchpoint (struct lwp_info *lp)
|
||||
lp->stopped_data_address_p = 0;
|
||||
}
|
||||
|
||||
do_cleanups (old_chain);
|
||||
|
||||
return lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user