From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7833) id D4CD93858C74; Thu, 11 Aug 2022 14:17:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4CD93858C74 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/varobj: Do not invalidate locals in varobj_invalidate_iter X-Act-Checkin: binutils-gdb X-Git-Author: Lancelot SIX X-Git-Refname: refs/heads/master X-Git-Oldrev: 537710a69cf440250c27a59b7d01b5a5a1a9b462 X-Git-Newrev: 739be95178196df4babdcb47de856a12ba06253f Message-Id: <20220811141719.D4CD93858C74@sourceware.org> Date: Thu, 11 Aug 2022 14:17:19 +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: Thu, 11 Aug 2022 14:17:19 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D739be9517819= 6df4babdcb47de856a12ba06253f commit 739be95178196df4babdcb47de856a12ba06253f Author: Lancelot SIX Date: Thu Aug 11 15:09:55 2022 +0100 gdb/varobj: Do not invalidate locals in varobj_invalidate_iter =20 The varobj_invalidate_iter function has logic to invalidate any local varobj it can find. However since bc20e562ec0 "gdb/varobj: Fix use after free in varobj" all varobj containing references to an objfile are cleared when the objfile goes out of scope. This means that at this point any local varobj seen by varobj_invalidate_iter either has already been invalidated by varobj_invalidate_if_uses_objfile or only contains valid references and there is no reason to invalidate it. =20 This patch proposes to remove this unnecessary invalidation and adds a testcase which exercises a scenario where a local varobj can legitimate= ly survive a call to varobj_invalidate_iter. =20 At this point the varobj_invalidate and varobj_invalidate_iter seem misnamed since they deal with re-creating invalid objects and do not do invalidation, but this will be fixed in a following patch. =20 Tested on x86_64-linux. Diff: --- gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp | 40 ++++++++++++++++++++= +--- gdb/varobj.c | 2 -- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp b/gdb/testsui= te/gdb.mi/mi-var-invalidate-shlib.exp index 87d1d4a6a9d..c8b9b3e039a 100644 --- a/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp +++ b/gdb/testsuite/gdb.mi/mi-var-invalidate-shlib.exp @@ -40,10 +40,6 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${b= infile}" executable $opt } =20 proc do_test { separate_debuginfo } { - if { $separate_debuginfo } { - gdb_gnu_strip_debug $::shlib_path - } - if { [mi_clean_restart] } { unsupported "failed to start GDB" return @@ -132,6 +128,42 @@ proc do_test { separate_debuginfo } { } } =20 +proc_with_prefix local_not_invalidated { separate_debuginfo } { + if { [mi_clean_restart] } { + unsupported "failed to start GDB" + return + } + + # Start the process once and create varobjs referencing the loaded obj= files. + with_test_prefix "setup" { + mi_load_shlibs $::shlib_path + if { $separate_debuginfo } { + mi_load_shlibs ${::shlib_path}.debug + } + + mi_gdb_reinitialize_dir $::srcdir/$::subdir + mi_gdb_load $::binfile + + mi_runto foo -pending + mi_next "next" + mi_create_varobj local_var local_var "create local varobj" + } + + # At this point we are stopped in the shared library. If we reload sy= mbols + # for the main binary, symbols for the shared library remain valid. A + # varobj tracking variables in the scope of the shared library only sh= ould + # not be invalidated. + mi_gdb_load ${::binfile} + mi_gdb_test "-var-update local_var" \ + "\\^done,changelist=3D\\\[\\\]" \ + "local_var preserved" +} + foreach_with_prefix separate_debuginfo {0 1} { + if { $separate_debuginfo } { + gdb_gnu_strip_debug $::shlib_path + } + do_test $separate_debuginfo + local_not_invalidated $separate_debuginfo } diff --git a/gdb/varobj.c b/gdb/varobj.c index 0683af1991e..a142bb02e03 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -2387,8 +2387,6 @@ varobj_invalidate_iter (struct varobj *var) var->root->is_valid =3D false; } } - else /* locals must be invalidated. */ - var->root->is_valid =3D false; } =20 /* Invalidate the varobjs that are tied to locals and re-create the ones t= hat