From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7833) id 937413858CDB; Wed, 3 Aug 2022 09:00:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 937413858CDB Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Lancelot SIX To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: Fix regression in varobj recreation X-Act-Checkin: binutils-gdb X-Git-Author: Lancelot SIX X-Git-Refname: refs/heads/master X-Git-Oldrev: ecfc6ddb8074aff8882155b5900958725094f508 X-Git-Newrev: f74a5e6f2ed5180ce28d6478a6d7a7a1982c5d43 Message-Id: <20220803090034.937413858CDB@sourceware.org> Date: Wed, 3 Aug 2022 09:00:34 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Aug 2022 09:00:34 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df74a5e6f2ed5= 180ce28d6478a6d7a7a1982c5d43 commit f74a5e6f2ed5180ce28d6478a6d7a7a1982c5d43 Author: Lancelot SIX Date: Tue Aug 2 13:14:20 2022 +0100 gdb: Fix regression in varobj recreation =20 Commit bc20e562ec0 "Fix use after free in varobj" introduced a regression. This commit makes sure that the varobj object does not keeps stale 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. =20 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. =20 Fix this by introducing a "global" flag which tracks if a given varobj was initially created as tracking a global. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29426 Diff: --- 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 =3D true; =20 + /* Set to true if the varobj was created as tracking a global. */ + bool global =3D false; + /* Language-related operations for this variable and its children. */ const struct lang_varobj_ops *lang_ops =3D NULL; @@ -336,6 +339,8 @@ varobj_create (const char *objname, var->format =3D variable_default_display (var.get ()); var->root->valid_block =3D var->root->floating ? NULL : tracker.block (); + var->root->global + =3D var->root->floating ? false : var->root->valid_block =3D=3D nullptr; var->name =3D expression; /* For a root var, the name and the expr are the same. */ var->path_expr =3D 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 =3D=3D nullptr) + if (var->root->floating || var->root->global) { struct varobj *tmp_var; =20 @@ -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. */