From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/3][gdb/testsuite] Fix global array cp_class_table_history leak
Date: Tue, 19 May 2020 18:29:20 +0200 [thread overview]
Message-ID: <20200519162919.GA8981@delia> (raw)
Hi,
Test-cases using proc cp_test_ptype_class set a global array
cp_class_table_history, which remains set after the test-case has run. This
has the potential to:
- cause tcl errors, as well as
- reuse results from one test-case in another test-case when that is not
appropriate
Fix this by:
- moving the variable into a namespace, and
- only using the variable in the test-cases that need it, and
- resetting the variable at the end of those test-cases.
Any comments?
Thanks,
- Tom
[gdb/testsuite] Fix global array cp_class_table_history leak
gdb/testsuite/ChangeLog:
2020-05-19 Tom de Vries <tdevries@suse.de>
PR testsuite/25996
* lib/cp-support.exp (init_cp_test_ptype_class_cache)
(finish_cp_test_ptype_class_cache): New proc.
(cp_test_ptype_class): Only use use_cp_class_table_history if
init_cp_test_ptype_class_cache was called.
* gdb.cp/inherit.exp: Call init_cp_test_ptype_class_cache and
finish_cp_test_ptype_class_cache.
* gdb.cp/virtfunc.exp: Same.
---
gdb/testsuite/gdb.cp/inherit.exp | 6 +++++
gdb/testsuite/gdb.cp/virtfunc.exp | 6 +++++
gdb/testsuite/lib/cp-support.exp | 53 +++++++++++++++++++++++++++++++--------
3 files changed, 55 insertions(+), 10 deletions(-)
diff --git a/gdb/testsuite/gdb.cp/inherit.exp b/gdb/testsuite/gdb.cp/inherit.exp
index 9616015709..29d4880999 100644
--- a/gdb/testsuite/gdb.cp/inherit.exp
+++ b/gdb/testsuite/gdb.cp/inherit.exp
@@ -711,4 +711,10 @@ proc do_tests { } {
test_print_mvi_classes
}
+# This test-case uses the cp_test_ptype_class cache (by means of the ibid
+# argument), so initialize and finalize the cache.
+init_cp_test_ptype_class_cache
+
do_tests
+
+finish_cp_test_ptype_class_cache
diff --git a/gdb/testsuite/gdb.cp/virtfunc.exp b/gdb/testsuite/gdb.cp/virtfunc.exp
index 2b046c5759..214ab1ec22 100644
--- a/gdb/testsuite/gdb.cp/virtfunc.exp
+++ b/gdb/testsuite/gdb.cp/virtfunc.exp
@@ -289,4 +289,10 @@ proc do_tests {} {
gdb_test "step" ".*E::vg.*" "step through thunk into E::vg"
}
+# This test-case uses the cp_test_ptype_class cache (by means of the ibid
+# argument), so initialize and finalize the cache.
+init_cp_test_ptype_class_cache
+
do_tests
+
+finish_cp_test_ptype_class_cache
diff --git a/gdb/testsuite/lib/cp-support.exp b/gdb/testsuite/lib/cp-support.exp
index b4a5582742..4142b00d8e 100644
--- a/gdb/testsuite/lib/cp-support.exp
+++ b/gdb/testsuite/lib/cp-support.exp
@@ -255,17 +255,22 @@ proc cp_test_ptype_class { in_exp in_testname in_key in_tag in_class_table
set in_command "ptype${in_ptype_arg} $in_exp"
}
- # Save class tables in a history array for reuse.
-
- global cp_class_table_history
- if { $in_class_table == "ibid" } then {
- if { ! [info exists cp_class_table_history("$in_key,$in_tag") ] } then {
- fail "$in_testname // bad ibid"
- return false
+ namespace upvar ::cp_support_internal:: use_cp_class_table_history \
+ use_cp_class_table_history
+ if { [info exists use_cp_class_table_history ] } {
+ # Save class tables in a history array for reuse.
+
+ namespace upvar ::cp_support_internal:: cp_class_table_history \
+ cp_class_table_history
+ if { $in_class_table == "ibid" } then {
+ if { ! [info exists cp_class_table_history("$in_key,$in_tag") ] } then {
+ fail "$in_testname // bad ibid"
+ return false
+ }
+ set in_class_table $cp_class_table_history("$in_key,$in_tag")
+ } else {
+ set cp_class_table_history("$in_key,$in_tag") $in_class_table
}
- set in_class_table $cp_class_table_history("$in_key,$in_tag")
- } else {
- set cp_class_table_history("$in_key,$in_tag") $in_class_table
}
# Split the class table into separate tables.
@@ -764,3 +769,31 @@ proc cp_test_ptype_class { in_exp in_testname in_key in_tag in_class_table
return true
}
+
+# Initialize the cp_test_ptype_class cache.
+
+proc init_cp_test_ptype_class_cache { } {
+ namespace upvar ::cp_support_internal:: use_cp_class_table_history \
+ use_cp_class_table_history
+ set use_cp_class_table_history 1
+
+ namespace upvar ::cp_support_internal:: cp_class_table_history \
+ cp_class_table_history
+ if { [info exists cp_class_table_history] } {
+ unset cp_class_table_history
+ }
+}
+
+# Finalize the cp_test_ptype_class cache.
+
+proc finish_cp_test_ptype_class_cache { } {
+ namespace upvar ::cp_support_internal:: use_cp_class_table_history \
+ use_cp_class_table_history
+ unset use_cp_class_table_history
+
+ namespace upvar ::cp_support_internal:: cp_class_table_history \
+ cp_class_table_history
+ if { [info exists cp_class_table_history] } {
+ unset cp_class_table_history
+ }
+}
next reply other threads:[~2020-05-19 16:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 16:29 Tom de Vries [this message]
2020-05-22 20:12 ` Tom Tromey
2020-06-02 13:02 ` Tom de Vries
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=20200519162919.GA8981@delia \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/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