(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)
...