mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-26 17:18:55 +00: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:
@@ -367,10 +367,9 @@ static void
|
||||
sol_thread_resume (struct target_ops *ops,
|
||||
ptid_t ptid, int step, enum gdb_signal signo)
|
||||
{
|
||||
struct cleanup *old_chain;
|
||||
struct target_ops *beneath = find_target_beneath (ops);
|
||||
|
||||
old_chain = save_inferior_ptid ();
|
||||
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
|
||||
|
||||
inferior_ptid = thread_to_lwp (inferior_ptid, ptid_get_pid (main_ph.ptid));
|
||||
if (ptid_get_pid (inferior_ptid) == -1)
|
||||
@@ -389,8 +388,6 @@ sol_thread_resume (struct target_ops *ops,
|
||||
}
|
||||
|
||||
beneath->to_resume (beneath, ptid, step, signo);
|
||||
|
||||
do_cleanups (old_chain);
|
||||
}
|
||||
|
||||
/* Wait for any threads to stop. We may have to convert PTID from a
|
||||
@@ -403,10 +400,9 @@ sol_thread_wait (struct target_ops *ops,
|
||||
ptid_t rtnval;
|
||||
ptid_t save_ptid;
|
||||
struct target_ops *beneath = find_target_beneath (ops);
|
||||
struct cleanup *old_chain;
|
||||
|
||||
save_ptid = inferior_ptid;
|
||||
old_chain = save_inferior_ptid ();
|
||||
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
|
||||
|
||||
inferior_ptid = thread_to_lwp (inferior_ptid, ptid_get_pid (main_ph.ptid));
|
||||
if (ptid_get_pid (inferior_ptid) == -1)
|
||||
@@ -445,8 +441,6 @@ sol_thread_wait (struct target_ops *ops,
|
||||
package being initialized, since that can only happen after we've
|
||||
found the shared libs. */
|
||||
|
||||
do_cleanups (old_chain);
|
||||
|
||||
return rtnval;
|
||||
}
|
||||
|
||||
@@ -569,11 +563,9 @@ sol_thread_xfer_partial (struct target_ops *ops, enum target_object object,
|
||||
const gdb_byte *writebuf,
|
||||
ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
|
||||
{
|
||||
enum target_xfer_status retval;
|
||||
struct cleanup *old_chain;
|
||||
struct target_ops *beneath = find_target_beneath (ops);
|
||||
|
||||
old_chain = save_inferior_ptid ();
|
||||
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
|
||||
|
||||
if (ptid_tid_p (inferior_ptid) || !target_thread_alive (inferior_ptid))
|
||||
{
|
||||
@@ -585,12 +577,8 @@ sol_thread_xfer_partial (struct target_ops *ops, enum target_object object,
|
||||
inferior_ptid = procfs_first_available ();
|
||||
}
|
||||
|
||||
retval = beneath->to_xfer_partial (beneath, object, annex, readbuf,
|
||||
writebuf, offset, len, xfered_len);
|
||||
|
||||
do_cleanups (old_chain);
|
||||
|
||||
return retval;
|
||||
return beneath->to_xfer_partial (beneath, object, annex, readbuf,
|
||||
writebuf, offset, len, xfered_len);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -800,9 +788,8 @@ rw_common (int dowrite, const struct ps_prochandle *ph, gdb_ps_addr_t addr,
|
||||
gdb_byte *buf, int size)
|
||||
{
|
||||
int ret;
|
||||
struct cleanup *old_chain;
|
||||
|
||||
old_chain = save_inferior_ptid ();
|
||||
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
|
||||
|
||||
if (ptid_tid_p (inferior_ptid) || !target_thread_alive (inferior_ptid))
|
||||
{
|
||||
@@ -826,8 +813,6 @@ rw_common (int dowrite, const struct ps_prochandle *ph, gdb_ps_addr_t addr,
|
||||
else
|
||||
ret = target_read_memory (addr, (gdb_byte *) buf, size);
|
||||
|
||||
do_cleanups (old_chain);
|
||||
|
||||
return (ret == 0 ? PS_OK : PS_ERR);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user