From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lndn.lancelotsix.com (lndn.lancelotsix.com [51.195.220.111]) by sourceware.org (Postfix) with ESMTPS id 3EB7E3857007 for ; Thu, 4 Aug 2022 13:02:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3EB7E3857007 Received: from octopus.. (unknown [IPv6:2a01:e0a:535:2750:508f:a0d5:5691:a9a3]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 2E2E989875; Thu, 4 Aug 2022 13:02:38 +0000 (UTC) From: Lancelot SIX To: gdb-patches@sourceware.org Cc: tdevries@suse.de, lsix@lancelotsix.com, Lancelot SIX Subject: [PATCH 1/3] gdb/varobj: Do not invalidate locals in varobj_invalidate_iter Date: Thu, 4 Aug 2022 14:02:29 +0100 Message-Id: <20220804130231.2126565-2-lancelot.six@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804130231.2126565-1-lancelot.six@amd.com> References: <20220804130231.2126565-1-lancelot.six@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Thu, 04 Aug 2022 13:02:39 +0000 (UTC) X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Aug 2022 13:02:43 -0000 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. This patch proposes to remove this un-necessary invalidation and adds a testcase which exercises a scenario where a local varobj can legitimately survive a call to varobj_invalidate_iter. At this point the varobj_invalidate and varobj_invalidate seem misnamed since they deal with re-creating invalid objects and do not do invalidation, but this will be fixed in a following patch. Tested on x86_64-linux. --- .../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/testsuite/gdb.mi/mi-var-invalidate-shlib.exp index 87d1d4a6a9d..9ba5af0c028 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}" "${binfile}" executable $opt } 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 } { } } +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 objfiles. + 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" + } + + # A this point we are stoped in the shared library. If we reload symbols + # for the main binary, symbols for the shared library remain valid. + # A varobj tracking variables in the scope of the shared library only + # should not be invalidated. + mi_gdb_load ${::binfile} + mi_gdb_test "-var-update local_var" \ + "\\^done,changelist=\\\[\\\]" \ + "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 = false; } } - else /* locals must be invalidated. */ - var->root->is_valid = false; } /* Invalidate the varobjs that are tied to locals and re-create the ones that -- 2.34.1