gdb: fix assert after register write failure

GDB tries to invalidate the register cache if a write to a register fails.
In case the connection to a remote inferior is closed during the write,
the remote target is unpushed, which deletes the regcache.  GDB receives
a TARGET_CLOSE_ERROR.  With this, the regcache is deleted and GDB runs
into a use-after-free bug; the previously set up make_scope_exit
invalidator writes to the already deleted regcache.

Fix this by catching the exception and only invalidating the regcache
if the error is not a TARGET_CLOSE_ERROR.

Co-Authored-By: Stephan Rohr <stephan.rohr@intel.com>
Approved-By: Tom Tromey <tom@tromey.com>
2 files changed