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 5525E387085F for ; Tue, 2 Jun 2020 13:02:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5525E387085F 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 CEAD0ACF1; Tue, 2 Jun 2020 13:02:18 +0000 (UTC) Subject: Re: [PATCH 1/3][gdb/testsuite] Fix global array cp_class_table_history leak To: Tom Tromey Cc: gdb-patches@sourceware.org References: <20200519162919.GA8981@delia> <87tv073f1i.fsf@tromey.com> From: Tom de Vries Autocrypt: addr=tdevries@suse.de; keydata= xsBNBF0ltCcBCADDhsUnMMdEXiHFfqJdXeRvgqSEUxLCy/pHek88ALuFnPTICTwkf4g7uSR7 HvOFUoUyu8oP5mNb4VZHy3Xy8KRZGaQuaOHNhZAT1xaVo6kxjswUi3vYgGJhFMiLuIHdApoc u5f7UbV+egYVxmkvVLSqsVD4pUgHeSoAcIlm3blZ1sDKviJCwaHxDQkVmSsGXImaAU+ViJ5l CwkvyiiIifWD2SoOuFexZyZ7RUddLosgsO0npVUYbl6dEMq2a5ijGF6/rBs1m3nAoIgpXk6P TCKlSWVW6OCneTaKM5C387972qREtiArTakRQIpvDJuiR2soGfdeJ6igGA1FZjU+IsM5ABEB AAHNH1RvbSBkZSBWcmllcyA8dGRldnJpZXNAc3VzZS5kZT7CwKsEEwEIAD4WIQSsnSe5hKbL MK1mGmjuhV2rbOJEoAUCXSW0JwIbAwUJA8JnAAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAh CRDuhV2rbOJEoBYhBKydJ7mEpsswrWYaaO6FXats4kSgc48H/Ra2lq5p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QxeTqwxC/1ZtNS DUCSFQjqA6bEGwM22dP8OUY6SC94x1G81A9/xbtm9LQxKm0EiDH8KBMLfQ== Message-ID: <32ce36a4-1da6-7841-8e3b-fcb82b625e1a@suse.de> Date: Tue, 2 Jun 2020 15:02:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <87tv073f1i.fsf@tromey.com> Content-Type: multipart/mixed; boundary="------------D18523FE22B89611B4CFC5E1" Content-Language: en-US X-Spam-Status: No, score=-16.8 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, 02 Jun 2020 13:02:19 -0000 This is a multi-part message in MIME format. --------------D18523FE22B89611B4CFC5E1 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 22-05-2020 22:12, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries writes: > > Tom> +# This test-case uses the cp_test_ptype_class cache (by means of the ibid > Tom> +# argument), so initialize and finalize the cache. > Tom> +init_cp_test_ptype_class_cache > Tom> + > Tom> do_tests > Tom> + > Tom> +finish_cp_test_ptype_class_cache > > If the users always have to do this init/test/finish thing, then maybe > some kind of wrapper proc would be more appropriate. > Done. > Also, it's more robust to use 'catch' to ensure that the cleanup is > always run. > Done. > However, is the finish bit needed? If the init proc cleans up all the > state, then it seems unnecessary. Agreed, strictly speaking it's unnecessary, it's just a cleanup. Thanks, - Tom --------------D18523FE22B89611B4CFC5E1 Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-testsuite-Fix-global-array-cp_class_table_history-leak.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-gdb-testsuite-Fix-global-array-cp_class_table_history-l"; filename*1="eak.patch" [gdb/testsuite] Fix global array cp_class_table_history leak 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. 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, use_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 use_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 | 68 +++++++++++++++++++++++++++++++++------ 3 files changed, 68 insertions(+), 12 deletions(-) diff --git a/gdb/testsuite/gdb.cp/inherit.exp b/gdb/testsuite/gdb.cp/inherit.exp index 2d4635c96a..67a11533dd 100644 --- a/gdb/testsuite/gdb.cp/inherit.exp +++ b/gdb/testsuite/gdb.cp/inherit.exp @@ -719,4 +719,8 @@ proc do_tests { } { test_print_mvi_classes } -do_tests +# This test-case uses the cp_test_ptype_class cache (by means of the ibid +# argument), so mark it as such. +use_cp_test_ptype_class_cache { + do_tests +} diff --git a/gdb/testsuite/gdb.cp/virtfunc.exp b/gdb/testsuite/gdb.cp/virtfunc.exp index 2b046c5759..dc83091692 100644 --- a/gdb/testsuite/gdb.cp/virtfunc.exp +++ b/gdb/testsuite/gdb.cp/virtfunc.exp @@ -289,4 +289,8 @@ proc do_tests {} { gdb_test "step" ".*E::vg.*" "step through thunk into E::vg" } -do_tests +# This test-case uses the cp_test_ptype_class cache (by means of the ibid +# argument), so mark it as such. +use_cp_test_ptype_class_cache { + do_tests +} diff --git a/gdb/testsuite/lib/cp-support.exp b/gdb/testsuite/lib/cp-support.exp index b4a5582742..ba97fbbd87 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,46 @@ 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 + } +} + +# Run WRAPPED_BODY using the cp_test_ptype_class_cache. + +proc use_cp_test_ptype_class_cache { wrapped_body } { + init_cp_test_ptype_class_cache + set code [catch {uplevel 1 $wrapped_body} result] + finish_cp_test_ptype_class_cache + + if {$code == 1} { + global errorInfo errorCode + return -code error -errorinfo $errorInfo -errorcode $errorCode $result + } elseif {$code > 1} { + return -code $code $result + } +} --------------D18523FE22B89611B4CFC5E1--