Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Stephan Rohr <stephan.rohr@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdb: fix assert after register write failure
Date: Mon, 12 Oct 2026 10:38:13 +0000	[thread overview]
Message-ID: <20261012103813.112609-1-stephan.rohr@intel.com> (raw)

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.


             reply	other threads:[~2026-10-12 10:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 10:38 Stephan Rohr [this message]
2026-10-15 11:49 ` Guinevere Larsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261012103813.112609-1-stephan.rohr@intel.com \
    --to=stephan.rohr@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox