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 97DA73840C3D for ; Thu, 11 Jun 2020 12:12:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 97DA73840C3D 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 4C70AACB8; Thu, 11 Jun 2020 12:12:03 +0000 (UTC) Subject: [committed][gdb/testsuite] Make gdb.base/dbx.exp more robust From: Tom de Vries To: Pedro Alves , Andrew Burgess Cc: gdb-patches@sourceware.org References: <20200519163004.GA9045@delia> <20200602153830.GZ3522@embecosm.com> <72b3c10c-d316-9a0e-13e9-56dee7c765a7@redhat.com> <5d6277ac-76ea-5f47-ab9e-7da58fbddd6e@suse.de> Autocrypt: addr=tdevries@suse.de; keydata= xsBNBF0ltCcBCADDhsUnMMdEXiHFfqJdXeRvgqSEUxLCy/pHek88ALuFnPTICTwkf4g7uSR7 HvOFUoUyu8oP5mNb4VZHy3Xy8KRZGaQuaOHNhZAT1xaVo6kxjswUi3vYgGJhFMiLuIHdApoc u5f7UbV+egYVxmkvVLSqsVD4pUgHeSoAcIlm3blZ1sDKviJCwaHxDQkVmSsGXImaAU+ViJ5l CwkvyiiIifWD2SoOuFexZyZ7RUddLosgsO0npVUYbl6dEMq2a5ijGF6/rBs1m3nAoIgpXk6P TCKlSWVW6OCneTaKM5C387972qREtiArTakRQIpvDJuiR2soGfdeJ6igGA1FZjU+IsM5ABEB AAHNH1RvbSBkZSBWcmllcyA8dGRldnJpZXNAc3VzZS5kZT7CwKsEEwEIAD4WIQSsnSe5hKbL MK1mGmjuhV2rbOJEoAUCXSW0JwIbAwUJA8JnAAULCQgHAgY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j5KG4cCKhIoMygPTA3U yGaIvI/BGOtHZ7bEBVUCFDFfOWJ26IOCoPnSVUvKPEOH9dv+sNy7jyBsP5QxeTqwxC/1ZtNS DUCSFQjqA6bEGwM22dP8OUY6SC94x1G81A9/xbtm9LQxKm0EiDH8KBMLfQ== Message-ID: <9352af37-7ed7-661c-11f1-59fbc6a886e9@suse.de> Date: Thu, 11 Jun 2020 14:11:55 +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: <5d6277ac-76ea-5f47-ab9e-7da58fbddd6e@suse.de> Content-Type: multipart/mixed; boundary="------------D59D37E90C30FC2690C86AE2" Content-Language: en-US X-Spam-Status: No, score=-16.0 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: Thu, 11 Jun 2020 12:12:02 -0000 This is a multi-part message in MIME format. --------------D59D37E90C30FC2690C86AE2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit [ was: Re: [PATCH 3/3][gdb/testsuite] Warn about leaked global array ] On 04-06-2020 13:40, Tom de Vries wrote: >> BTW, global variables alone aren't the full scope of the >> bleeding between testcases. There's also the case of >> testcases overriding procedures, like gdb.base/dbx.exp, >> but those are perhaps rare enough that we can continue >> handling it "manually" as before. > AFAICT, that test-case does an effort to undo the override, though I'm > not sure how certain it is that the undo will be executed. I've committed patch below to make sure the undo is executed (and similar for GDBFLAGS). Thanks, - Tom --------------D59D37E90C30FC2690C86AE2 Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-testsuite-Make-gdb.base-dbx.exp-more-robust.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-gdb-testsuite-Make-gdb.base-dbx.exp-more-robust.patch" [gdb/testsuite] Make gdb.base/dbx.exp more robust Test-case gdb.base/dbx.exp overrides: - the GDBFLAGS variable - the gdb_file_cmd proc There's code at the end of the test-case to restore both, but that's not guaranteed to be executed. Fix this by: - using save_vars to restore GDBFLAGS - using a new proc with_override to restore gdb_file_cmd Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-06-11 Tom de Vries * lib/gdb.exp (with_override): New proc, factored out of ... * gdb.base/dbx.exp: ... here. Use with_override and save_vars. --- gdb/testsuite/gdb.base/dbx.exp | 35 ++++++++++++++++------------------ gdb/testsuite/lib/gdb.exp | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/gdb/testsuite/gdb.base/dbx.exp b/gdb/testsuite/gdb.base/dbx.exp index 4299c44368..2a53f99a28 100644 --- a/gdb/testsuite/gdb.base/dbx.exp +++ b/gdb/testsuite/gdb.base/dbx.exp @@ -147,11 +147,8 @@ proc dbx_reinitialize_dir { subdir } { # right sequence of events, allowing gdb_load to do its normal thing? This way # remotes and simulators will work, too. # -# [drow 2002-03-30]: We can restore the old gdb_file_cmd afterwards, though. -set old_gdb_file_cmd_args [info args gdb_file_cmd] -set old_gdb_file_cmd_body [info body gdb_file_cmd] -proc gdb_file_cmd {arg} { +proc local_gdb_file_cmd {arg} { global loadpath global loadfile global GDB @@ -286,24 +283,24 @@ proc test_func { } { # Start with a fresh gdb. gdb_exit -global GDBFLAGS -set saved_gdbflags $GDBFLAGS -set GDBFLAGS "$GDBFLAGS --dbx" -gdb_start -dbx_reinitialize_dir $srcdir/$subdir -gdb_load ${binfile} +with_override gdb_file_cmd local_gdb_file_cmd { + save_vars GDBFLAGS { + set GDBFLAGS "$GDBFLAGS --dbx" -test_breakpoints -test_assign -test_whereis -gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*" -test_func + gdb_start + dbx_reinitialize_dir $srcdir/$subdir + gdb_load ${binfile} -#exit and cleanup -gdb_exit + test_breakpoints + test_assign + test_whereis + gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*" + test_func -set GDBFLAGS $saved_gdbflags -eval proc gdb_file_cmd {$old_gdb_file_cmd_args} {$old_gdb_file_cmd_body} + #exit and cleanup + gdb_exit + } +} return 0 diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 9a0620a2bf..51f8a05464 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -7200,5 +7200,48 @@ proc hex_in_list { val hexlist } { return [expr $index != -1] } +# Override proc NAME to proc OVERRIDE for the duration of the execution of +# BODY. + +proc with_override { name override body } { + # Implementation note: It's possible to implement the override using + # rename, like this: + # rename $name save_$name + # rename $override $name + # set code [catch {uplevel 1 $body} result] + # rename $name $override + # rename save_$name $name + # but there are two issues here: + # - the save_$name might clash with an existing proc + # - the override is no longer available under its original name during + # the override + # So, we use this more elaborate but cleaner mechanism. + + # Save the old proc. + set old_args [info args $name] + set old_body [info body $name] + + # Install the override. + set new_args [info args $override] + set new_body [info body $override] + eval proc $name {$new_args} {$new_body} + + # Execute body. + set code [catch {uplevel 1 $body} result] + + # Restore old proc. + eval proc $name {$old_args} {$old_body} + + # Return as appropriate. + if { $code == 1 } { + global errorInfo errorCode + return -code error -errorinfo $errorInfo -errorcode $errorCode $result + } elseif { $code > 1 } { + return -code $code $result + } + + return $result +} + # Always load compatibility stuff. load_lib future.exp --------------D59D37E90C30FC2690C86AE2--