public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Eduard Sargsyan <eduard.sargsyan@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/1] gdb: fix assert after register write failure
Date: Tue, 19 Dec 2023 15:14:48 +0000	[thread overview]
Message-ID: <20231219151448.23519-2-eduard.sargsyan@intel.com> (raw)
In-Reply-To: <20231219151448.23519-1-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/ChangeLog:
2021-03-18  Eduard Sargsyan  <eduard.sargsyan@intel.com>

	* regcache.c (regcache::raw_write): Add check for pointer validity.
---
 gdb/regcache.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 6140a05f02b..94ca89a58de 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -882,8 +882,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.34.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  reply	other threads:[~2023-12-19 15:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 15:14 [PATCH 0/1] Crash on register invalidation Eduard Sargsyan
2023-12-19 15:14 ` Eduard Sargsyan [this message]
2023-12-22 16:10   ` [PATCH 1/1] gdb: fix assert after register write failure Tom Tromey
2023-12-22 16:36   ` Simon Marchi

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=20231219151448.23519-2-eduard.sargsyan@intel.com \
    --to=eduard.sargsyan@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).