diff options
author | Tom Tromey <tom@tromey.com> | 2017-08-15 23:36:09 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2017-08-18 11:06:26 -0600 |
commit | 2989a3651d3f6ad8c7cffb225f77f4fca8868890 (patch) | |
tree | 8eefedd30fba1827d138d783ab7e621b838d0994 /gdb/infrun.c | |
parent | e60eb2880368b4e4752577c626ab0dadf0499cb5 (diff) | |
download | gdb-2989a3651d3f6ad8c7cffb225f77f4fca8868890.zip gdb-2989a3651d3f6ad8c7cffb225f77f4fca8868890.tar.gz gdb-2989a3651d3f6ad8c7cffb225f77f4fca8868890.tar.bz2 |
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.
Diffstat (limited to 'gdb/infrun.c')
-rw-r--r-- | gdb/infrun.c | 53 |
1 files changed, 7 insertions, 46 deletions
diff --git a/gdb/infrun.c b/gdb/infrun.c index d6723fd..541fc09 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1756,7 +1756,7 @@ displaced_step_dump_bytes (struct ui_file *file, static int displaced_step_prepare_throw (ptid_t ptid) { - struct cleanup *old_cleanups, *ignore_cleanups; + struct cleanup *ignore_cleanups; struct thread_info *tp = find_thread_ptid (ptid); struct regcache *regcache = get_thread_regcache (ptid); struct gdbarch *gdbarch = get_regcache_arch (regcache); @@ -1808,7 +1808,7 @@ displaced_step_prepare_throw (ptid_t ptid) displaced_step_clear (displaced); - old_cleanups = save_inferior_ptid (); + scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); inferior_ptid = ptid; original = regcache_read_pc (regcache); @@ -1834,7 +1834,6 @@ displaced_step_prepare_throw (ptid_t ptid) "Stepping over breakpoint in-line instead.\n"); } - do_cleanups (old_cleanups); return -1; } @@ -1864,7 +1863,7 @@ displaced_step_prepare_throw (ptid_t ptid) /* The architecture doesn't know how or want to displaced step this instruction or instruction sequence. Fallback to stepping over the breakpoint in-line. */ - do_cleanups (old_cleanups); + do_cleanups (ignore_cleanups); return -1; } @@ -1883,8 +1882,6 @@ displaced_step_prepare_throw (ptid_t ptid) discard_cleanups (ignore_cleanups); - do_cleanups (old_cleanups); - if (debug_displaced) fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n", paddress (gdbarch, copy)); @@ -1941,11 +1938,10 @@ static void write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, const gdb_byte *myaddr, int len) { - struct cleanup *ptid_cleanup = save_inferior_ptid (); + scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); inferior_ptid = ptid; write_memory (memaddr, myaddr, len); - do_cleanups (ptid_cleanup); } /* Restore the contents of the copy area for thread PTID. */ @@ -4366,17 +4362,10 @@ wait_one (struct target_waitstatus *ws) static int \ thread_stopped_by_ ## REASON (ptid_t ptid) \ { \ - struct cleanup *old_chain; \ - int res; \ - \ - old_chain = save_inferior_ptid (); \ + scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); \ inferior_ptid = ptid; \ \ - res = target_stopped_by_ ## REASON (); \ - \ - do_cleanups (old_chain); \ - \ - return res; \ + return target_stopped_by_ ## REASON (); \ } /* Generate thread_stopped_by_watchpoint. */ @@ -5706,7 +5695,7 @@ handle_signal_stop (struct execution_control_state *ecs) { struct regcache *regcache = get_thread_regcache (ecs->ptid); struct gdbarch *gdbarch = get_regcache_arch (regcache); - struct cleanup *old_chain = save_inferior_ptid (); + scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); inferior_ptid = ecs->ptid; @@ -5726,8 +5715,6 @@ handle_signal_stop (struct execution_control_state *ecs) fprintf_unfiltered (gdb_stdlog, "infrun: (no data address available)\n"); } - - do_cleanups (old_chain); } /* This is originated from start_remote(), start_inferior() and @@ -9116,32 +9103,6 @@ discard_infcall_control_state (struct infcall_control_state *inf_status) xfree (inf_status); } -/* restore_inferior_ptid() will be used by the cleanup machinery - to restore the inferior_ptid value saved in a call to - save_inferior_ptid(). */ - -static void -restore_inferior_ptid (void *arg) -{ - ptid_t *saved_ptid_ptr = (ptid_t *) 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 = XNEW (ptid_t); - - *saved_ptid_ptr = inferior_ptid; - return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); -} - /* See infrun.h. */ void |