aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-03-24 11:44:00 +0100
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-03-24 13:56:46 +0100
commit5783e150b2a9308e23262a5b62f5d51c8c932ece (patch)
treecfa98366ac130a422bf33e7c0b9a7e380f21c0e6
parent83bfc77ff537667989bd375b991d379ee4dda350 (diff)
downloadgdb-5783e150b2a9308e23262a5b62f5d51c8c932ece.zip
gdb-5783e150b2a9308e23262a5b62f5d51c8c932ece.tar.gz
gdb-5783e150b2a9308e23262a5b62f5d51c8c932ece.tar.bz2
(re-)fix the regcache leaks when detaching from an executable.
Commit 799efbe8e01ab8292c01f46ac59a6fb2349d4535 was supposed to fix the below leak. However, for this fix to work, it is critical to save the ptid before detach. This commit (pushed as OBVIOUS, as the change was already reviewed/approved) saves the ptid before the detach, as in the original reviewed patch (see https://sourceware.org/ml/gdb-patches/2019-02/msg00263.html). Re-tested on debian/amd64, natively and under valgrind. ==7426== 1,123 (72 direct, 1,051 indirect) bytes in 1 blocks are definitely lost in loss record 2,872 of 3,020 ==7426== at 0x4C2C4CC: operator new(unsigned long) (vg_replace_malloc.c:344) ==7426== by 0x5BD1E1: get_thread_arch_aspace_regcache(ptid_t, gdbarch*, address_space*) (regcache.c:330) ==7426== by 0x5BD39A: get_thread_regcache (regcache.c:366) ==7426== by 0x5BD39A: get_current_regcache() (regcache.c:372) ==7426== by 0x4B1EB4: get_current_frame() (frame.c:1588) ...
-rw-r--r--gdb/target.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/gdb/target.c b/gdb/target.c
index 5f596b6..6c05b6b 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -2013,6 +2013,11 @@ target_preopen (int from_tty)
void
target_detach (inferior *inf, int from_tty)
{
+ /* After we have detached, we will clear the register cache for this inferior
+ by calling registers_changed_ptid. We must save the pid_ptid before
+ detaching, as the target detach method will clear inf->pid. */
+ ptid_t save_pid_ptid = ptid_t (inf->pid);
+
/* As long as some to_detach implementations rely on the current_inferior
(either directly, or indirectly, like through target_gdbarch or by
reading memory), INF needs to be the current inferior. When that
@@ -2033,14 +2038,11 @@ target_detach (inferior *inf, int from_tty)
current_top_target ()->detach (inf, from_tty);
- /* After we have detached, clear the register cache for this inferior. */
- ptid_t pid_ptid = ptid_t (inf->pid);
-
- registers_changed_ptid (pid_ptid);
+ registers_changed_ptid (save_pid_ptid);
/* We have to ensure we have no frame cache left. Normally,
- registers_changed_ptid (pid_ptid) calls reinit_frame_cache when
- inferior_ptid matches pid_ptid, but in our case, it does not
+ registers_changed_ptid (save_pid_ptid) calls reinit_frame_cache when
+ inferior_ptid matches save_pid_ptid, but in our case, it does not
call it, as inferior_ptid has been reset. */
reinit_frame_cache ();
}