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:
Tom Tromey
2017-08-15 23:36:09 -06:00
parent e60eb28803
commit 2989a3651d
13 changed files with 78 additions and 133 deletions

View File

@@ -294,7 +294,7 @@ bsd_uthread_fetch_registers (struct target_ops *ops,
CORE_ADDR addr = ptid_get_tid (ptid);
struct target_ops *beneath = find_target_beneath (ops);
CORE_ADDR active_addr;
struct cleanup *cleanup = save_inferior_ptid ();
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
/* We are doing operations (e.g. reading memory) that rely on
inferior_ptid. */
@@ -315,8 +315,6 @@ bsd_uthread_fetch_registers (struct target_ops *ops,
uthread_ops->supply_uthread (regcache, regnum,
addr + bsd_uthread_thread_ctx_offset);
}
do_cleanups (cleanup);
}
static void
@@ -330,7 +328,7 @@ bsd_uthread_store_registers (struct target_ops *ops,
ptid_t ptid = regcache_get_ptid (regcache);
CORE_ADDR addr = ptid_get_tid (ptid);
CORE_ADDR active_addr;
struct cleanup *cleanup = save_inferior_ptid ();
scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
/* We are doing operations (e.g. reading memory) that rely on
inferior_ptid. */
@@ -349,8 +347,6 @@ bsd_uthread_store_registers (struct target_ops *ops,
request to the layer beneath. */
beneath->to_store_registers (beneath, regcache, regnum);
}
do_cleanups (cleanup);
}
static ptid_t