From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id A5169383F868 for ; Wed, 27 May 2020 21:50:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A5169383F868 X-ASG-Debug-ID: 1590616216-0c856e6d38168120001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id oAx1chOCSvUWOiRT (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 27 May 2020 17:50:16 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) by smtp.ebox.ca (Postfix) with ESMTP id 99D8F441B21; Wed, 27 May 2020 17:50:16 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-181-218.qc.cable.ebox.net[192.222.181.218] X-Barracuda-Apparent-Source-IP: 192.222.181.218 X-Barracuda-RBL-IP: 192.222.181.218 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb/testsuite: introduce save_procs proc Date: Wed, 27 May 2020 17:50:15 -0400 X-ASG-Orig-Subj: [PATCH] gdb/testsuite: introduce save_procs proc Message-Id: <20200527215015.15106-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1590616216 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 4500 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.82148 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-25.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, 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: Wed, 27 May 2020 21:50:19 -0000 The test gdb.base/dbx.exp redefines gdb_file_cmd, which is normally defined in lib/gdb.exp. It restores the original version of the proc at the end. But the problem is that if the test fails and an exception is thrown, it won't be restored and the following tests will be affected. This patch introduces a `save_procs` procedure inspired by `save_vars`. This lets the test restore the given procedures whatever happens. The gdb.base/dbx.exp is modified to use the new proc, and save_vars to save GDBFLAGS while at it. gdb/testsuite/ChangeLog: * lib/gdb.exp (save_procs): New. * gdb.base/dbx.exp: Use save_procs and save_vars. Change-Id: I5eff388dc74f6759f8ee6cf43d7e8a78502bce5a --- gdb/testsuite/gdb.base/dbx.exp | 45 +++++++++++++++------------------- gdb/testsuite/lib/gdb.exp | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/gdb/testsuite/gdb.base/dbx.exp b/gdb/testsuite/gdb.base/dbx.exp index 4299c44368c..4d84b54cda2 100644 --- a/gdb/testsuite/gdb.base/dbx.exp +++ b/gdb/testsuite/gdb.base/dbx.exp @@ -146,12 +146,8 @@ proc dbx_reinitialize_dir { subdir } { # file into gdb for a dbx session. So why not just override gdb_file_cmd with the # 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 dbx_gdb_file_cmd {arg} { global loadpath global loadfile global GDB @@ -283,27 +279,26 @@ proc test_func { } { gdb_test "func print_average" ".*in print_average.*\\(list=.*, low=0, high=6\\).*at.*average\.c:${decimal}\r\n${decimal}\[ \t\]+total = sum\\(list, low, high\\);" } -# 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} +save_vars { GDBFLAGS } { + save_procs { gdb_file_cmd } { + rename gdb_file_cmd {} + rename dbx_gdb_file_cmd gdb_file_cmd -test_breakpoints -test_assign -test_whereis -gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*" -test_func + # Start with a fresh gdb. + gdb_exit -#exit and cleanup -gdb_exit + set GDBFLAGS "$GDBFLAGS --dbx" + gdb_start + dbx_reinitialize_dir $srcdir/$subdir + gdb_load ${binfile} -set GDBFLAGS $saved_gdbflags -eval proc gdb_file_cmd {$old_gdb_file_cmd_args} {$old_gdb_file_cmd_body} + test_breakpoints + test_assign + test_whereis + gdb_test "file average.c:1" "1\[ \t\]+/. This is a sample program.*" + test_func -return 0 + #exit and cleanup + gdb_exit + } +} diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 444cea01c36..6a87fee1855 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -2298,6 +2298,50 @@ proc save_vars { vars body } { } } +# Run BODY in the context of the caller. After BODY is run, the procedures +# listed in PROCS will be reset to the values they had before BODY was run. +# +# This is useful for providing a scope in which it is safe to temporarily +# replace procedures. +# +# save_vars { gdb_file_cmd } { +# # re-define gdb_file_cmd +# } + +proc save_procs { procs body } { + array set saved { } + + # Save args and bodies of specified procs. + foreach proc_name $procs { + set proc_args [info args $proc_name] + set proc_body [info body $proc_name] + + set saved($proc_name) [list $proc_args $proc_body] + } + + # Run body. + set code [catch {uplevel 1 $body} result] + if { $code == 1 } { + global errorInfo errorCode + set saved_error_info $errorInfo + set saved_error_code $errorCode + } + + # Restore procs. + foreach {proc_name value} [array get saved] { + set proc_args [lindex $value 0] + set proc_body [lindex $value 1] + + eval proc $proc_name {$proc_args} {$proc_body} + } + + if {$code == 1} { + return -code $code -errorinfo $saved_error_info -errorcode $saved_error_code $result + } else { + return -code $code $result + } +} + # Run tests in BODY with the current working directory (CWD) set to # DIR. When BODY is finished, restore the original CWD. Return the # result of BODY. -- 2.26.2