Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: lsix@lancelotsix.com, Lancelot SIX <lancelot.six@amd.com>
Subject: [PATCH 3/3] gdb/varobj: Only re-evaluate invalid globals during re_set
Date: Thu,  4 Aug 2022 14:02:31 +0100	[thread overview]
Message-ID: <20220804130231.2126565-4-lancelot.six@amd.com> (raw)
In-Reply-To: <20220804130231.2126565-1-lancelot.six@amd.com>

When doing varobj_re_set, we currently try to recreate floating varobj.
This was introduced by 4e969b4f0128 "Re-evaluate floating varobj as part
of varobj_invalidate" to deal with use a after free issue.  However
since bc20e562ec0 "Fix use after free in varobj" we now ensure that we
never have dangling pointers so this all recreation is not strictly
needed anymore for floating varobjs.

This commit proposes to remove this recreation process for floating
varobjs.

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.mi/mi-var-invalidate.exp |  4 ++--
 gdb/varobj.c                               | 18 +++++-------------
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/gdb/testsuite/gdb.mi/mi-var-invalidate.exp b/gdb/testsuite/gdb.mi/mi-var-invalidate.exp
index 1b2c68df18e..348515671c1 100644
--- a/gdb/testsuite/gdb.mi/mi-var-invalidate.exp
+++ b/gdb/testsuite/gdb.mi/mi-var-invalidate.exp
@@ -75,8 +75,8 @@ mi_runto_main
 # Change format of floating variable immediately after reload reveals a
 # bug where gdb still uses a free'd pointer.
 mi_gdb_test "-var-set-format float_simple hexadecimal" \
-        "\\^done,format=\"hexadecimal\",value=\"\\\[-1\\\]\"" \
-       "set format variable float_simple"
+	"\\^done,format=\"hexadecimal\",value=\"\\\[3\\\]\"" \
+	"set format variable float_simple"
 
 # Check local variable is "invalid".
 mi_gdb_test "-var-update linteger" \
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 55a7bd97f43..d3df608c55f 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -2359,29 +2359,21 @@ all_root_varobjs (gdb::function_view<void (struct varobj *var)> func)
 static void
 varobj_re_set_iter (struct varobj *var)
 {
-  /* Invalidated globals and floating var must be re-evaluated.  */
-  if (var->root->global || var->root->floating)
+  /* Invalidated global varobjs must be re-evaluated.  */
+  if (!var->root->is_valid && var->root->global)
     {
       struct varobj *tmp_var;
 
       /* Try to create a varobj with same expression.  If we succeed
-	 replace the old varobj, otherwise invalidate it.  */
+	 and have a global replace the old varobj.  */
       tmp_var = varobj_create (nullptr, var->name.c_str (), (CORE_ADDR) 0,
-			       var->root->floating
-			       ? USE_SELECTED_FRAME : USE_CURRENT_FRAME);
-      if (tmp_var != nullptr)
+			       USE_CURRENT_FRAME);
+      if (tmp_var != nullptr && tmp_var->root->global)
 	{
-	  gdb_assert (var->root->floating == tmp_var->root->floating);
 	  tmp_var->obj_name = var->obj_name;
 	  varobj_delete (var, 0);
 	  install_variable (tmp_var);
 	}
-      else if (var->root->global)
-	{
-	  /* Only invalidate globals as floating vars might still be valid in
-	     some other frame.  */
-	  var->root->is_valid = false;
-	}
     }
 }
 
-- 
2.34.1


  parent reply	other threads:[~2022-08-04 13:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-04 13:02 [PATCH 0/3] Varobj re_set clanup Lancelot SIX via Gdb-patches
2022-08-04 13:02 ` [PATCH 1/3] gdb/varobj: Do not invalidate locals in varobj_invalidate_iter Lancelot SIX via Gdb-patches
2022-08-05 15:03   ` Tom de Vries via Gdb-patches
2022-08-04 13:02 ` [PATCH 2/3] gdb/varobj: Reset varobj after relocations have been computed Lancelot SIX via Gdb-patches
2022-08-09 10:55   ` Tom de Vries via Gdb-patches
2022-08-04 13:02 ` Lancelot SIX via Gdb-patches [this message]
2022-08-09 10:55   ` [PATCH 3/3] gdb/varobj: Only re-evaluate invalid globals during re_set Tom de Vries via Gdb-patches
2022-08-11 14:07     ` Lancelot SIX via Gdb-patches

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=20220804130231.2126565-4-lancelot.six@amd.com \
    --to=gdb-patches@sourceware.org \
    --cc=lancelot.six@amd.com \
    --cc=lsix@lancelotsix.com \
    /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