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 1/2] gdb: Fix regression in varobj recreation
Date: Tue, 2 Aug 2022 13:47:23 +0100 [thread overview]
Message-ID: <20220802124724.284096-2-lancelot.six@amd.com> (raw)
In-Reply-To: <20220802124724.284096-1-lancelot.six@amd.com>
"bc20e562ec0 gdb/varobj: Fix use after free in varobj" introduced a
regression. This commit makes sure that the varobj object does not
keeps stall references to object being freed when we unload an objfile.
This includes the "valid_block" field which is reset to nullptr if the
pointed to block is tied to an objfile being freed.
However, at some point varobj_invalidate_iter might try to recreate
varobjs tracking either floating or globals. Varobj tracking globals
are identified as having the "valid_block" field set nullptr, but as
bc20e562ec0 might clear this field, we have lost the ability to
distinguish between varobj referring to globals and non globals.
Fix this by introducing a "global" flag which tracks if a given varobj
was initially created as tracking a global.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29426
---
gdb/varobj.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/gdb/varobj.c b/gdb/varobj.c
index e558794617a..0683af1991e 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -102,6 +102,9 @@ struct varobj_root
to symbols that do not exist anymore. */
bool is_valid = true;
+ /* Set to true if the varobj was created as tracking a global. */
+ bool global = false;
+
/* Language-related operations for this variable and its
children. */
const struct lang_varobj_ops *lang_ops = NULL;
@@ -336,6 +339,8 @@ varobj_create (const char *objname,
var->format = variable_default_display (var.get ());
var->root->valid_block =
var->root->floating ? NULL : tracker.block ();
+ var->root->global
+ = var->root->floating ? false : var->root->valid_block == nullptr;
var->name = expression;
/* For a root var, the name and the expr are the same. */
var->path_expr = expression;
@@ -2359,7 +2364,7 @@ static void
varobj_invalidate_iter (struct varobj *var)
{
/* global and floating var must be re-evaluated. */
- if (var->root->floating || var->root->valid_block == nullptr)
+ if (var->root->floating || var->root->global)
{
struct varobj *tmp_var;
@@ -2375,7 +2380,7 @@ varobj_invalidate_iter (struct varobj *var)
varobj_delete (var, 0);
install_variable (tmp_var);
}
- else if (!var->root->floating)
+ else if (var->root->global)
{
/* Only invalidate globals as floating vars might still be valid in
some other frame. */
--
2.34.1
next prev parent reply other threads:[~2022-08-02 12:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 12:47 [PATCH 0/2] Fix regressions " Lancelot SIX via Gdb-patches
2022-08-02 12:47 ` Lancelot SIX via Gdb-patches [this message]
2022-08-02 13:26 ` [PATCH 1/2] gdb: Fix regression " Tom de Vries via Gdb-patches
2022-08-03 9:06 ` Six, Lancelot via Gdb-patches
2022-08-02 12:47 ` [PATCH 2/2] gdb/testsuite: Accept PIE/noPIE programs in gdb.mi/mi-var-invalidate-shlib.exp Lancelot SIX via Gdb-patches
2022-08-02 15:45 ` Tom de Vries via Gdb-patches
2022-08-03 9:35 ` Six, Lancelot via Gdb-patches
2022-08-03 11:51 ` Tom de Vries via Gdb-patches
2022-08-03 13:23 ` Six, Lancelot 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=20220802124724.284096-2-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