From 2989a3651d3f6ad8c7cffb225f77f4fca8868890 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 15 Aug 2017 23:36:09 -0600 Subject: 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 Pedro Alves * 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. --- gdb/aix-thread.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'gdb/aix-thread.c') diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index ced6203..f3434a6 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -985,12 +985,11 @@ aix_thread_resume (struct target_ops *ops, if (!PD_TID (ptid)) { - struct cleanup *cleanup = save_inferior_ptid (); + scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); struct target_ops *beneath = find_target_beneath (ops); inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); beneath->to_resume (beneath, ptid, step, sig); - do_cleanups (cleanup); } else { @@ -1022,14 +1021,16 @@ static ptid_t aix_thread_wait (struct target_ops *ops, ptid_t ptid, struct target_waitstatus *status, int options) { - struct cleanup *cleanup = save_inferior_ptid (); struct target_ops *beneath = find_target_beneath (ops); - pid_to_prc (&ptid); + { + scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); - inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); - ptid = beneath->to_wait (beneath, ptid, status, options); - do_cleanups (cleanup); + pid_to_prc (&ptid); + + inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); + ptid = beneath->to_wait (beneath, ptid, status, options); + } if (ptid_get_pid (ptid) == -1) return pid_to_ptid (-1); @@ -1684,16 +1685,12 @@ aix_thread_xfer_partial (struct target_ops *ops, enum target_object object, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { - struct cleanup *old_chain = save_inferior_ptid (); - enum target_xfer_status xfer; + scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); struct target_ops *beneath = find_target_beneath (ops); inferior_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); - xfer = beneath->to_xfer_partial (beneath, object, annex, readbuf, + return beneath->to_xfer_partial (beneath, object, annex, readbuf, writebuf, offset, len, xfered_len); - - do_cleanups (old_chain); - return xfer; } /* Clean up after the inferior exits. */ -- cgit v1.1