* [PATCH] gdb: fix assert after register write failure
@ 2026-10-12 10:38 Stephan Rohr
2026-10-15 11:49 ` Guinevere Larsen
0 siblings, 1 reply; 2+ messages in thread
From: Stephan Rohr @ 2026-10-12 10:38 UTC (permalink / raw)
To: gdb-patches
From: Eduard Sargsyan <eduard.sargsyan@intel.com>
GDB tries to invalidate register cache if write to register fails. In case
when write was requested to be done for a remote inferior and connection with
remote is dead (so write request will fail) GDB cleans register caches and as
result setting register status fails with segmentation fault, because internal
pointers are not valid anymore and the unique_ptr with register status is
null.
This change adds check if register status cache is still valid before trying to
modify (set status to UNKNOWN).
---
gdb/regcache.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/gdb/regcache.c b/gdb/regcache.c
index 773e8ac37d0..01c60ea8047 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -883,8 +883,11 @@ regcache::raw_write (int regnum, gdb::array_view<const gdb_byte> src)
/* Invalidate the register after it is written, in case of a
failure. */
- auto invalidator
- = make_scope_exit ([&] { this->invalidate (regnum); });
+ auto invalidator = make_scope_exit ([&]
+ {
+ if (this->m_register_status != nullptr)
+ this->invalidate (regnum);
+ });
target_store_registers (this, regnum);
--
2.43.0
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gdb: fix assert after register write failure
2026-10-12 10:38 [PATCH] gdb: fix assert after register write failure Stephan Rohr
@ 2026-10-15 11:49 ` Guinevere Larsen
0 siblings, 0 replies; 2+ messages in thread
From: Guinevere Larsen @ 2026-10-15 11:49 UTC (permalink / raw)
To: Stephan Rohr, gdb-patches
On 10/12/26 7:38 AM, Stephan Rohr wrote:
> From: Eduard Sargsyan <eduard.sargsyan@intel.com>
>
> GDB tries to invalidate register cache if write to register fails. In case
> when write was requested to be done for a remote inferior and connection with
> remote is dead (so write request will fail) GDB cleans register caches and as
> result setting register status fails with segmentation fault, because internal
> pointers are not valid anymore and the unique_ptr with register status is
> null.
>
> This change adds check if register status cache is still valid before trying to
> modify (set status to UNKNOWN).
> ---
Hi! Thanks for working on this!
I wonder if it would be better to move this check to
regcache::invalidate instead, so that we don't need to make this check
every time invalidate is called in this kind of situation.
--
Cheers,
Guinevere Larsen
it/its
she/her (deprecated)
> gdb/regcache.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/regcache.c b/gdb/regcache.c
> index 773e8ac37d0..01c60ea8047 100644
> --- a/gdb/regcache.c
> +++ b/gdb/regcache.c
> @@ -883,8 +883,11 @@ regcache::raw_write (int regnum, gdb::array_view<const gdb_byte> src)
>
> /* Invalidate the register after it is written, in case of a
> failure. */
> - auto invalidator
> - = make_scope_exit ([&] { this->invalidate (regnum); });
> + auto invalidator = make_scope_exit ([&]
> + {
> + if (this->m_register_status != nullptr)
> + this->invalidate (regnum);
> + });
>
> target_store_registers (this, regnum);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-15 11:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-12 10:38 [PATCH] gdb: fix assert after register write failure Stephan Rohr
2026-10-15 11:49 ` Guinevere Larsen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox