From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 4CF853952537 for ; Tue, 19 May 2020 16:29:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4CF853952537 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 25A7FAB91 for ; Tue, 19 May 2020 16:29:25 +0000 (UTC) Date: Tue, 19 May 2020 18:29:20 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 1/3][gdb/testsuite] Fix global array cp_class_table_history leak Message-ID: <20200519162919.GA8981@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-18.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Tue, 19 May 2020 16:29:25 -0000 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 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 + } +}