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 DB4EC395704F for ; Fri, 12 Jun 2020 11:36:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DB4EC395704F 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 70497AAC6; Fri, 12 Jun 2020 11:36:13 +0000 (UTC) Subject: [committed][gdb/testsuite] Don't leak tuiterm.exp spawn override To: Tom Tromey Cc: Pedro Alves , Andrew Burgess , 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> <66a24a94-3492-7667-58c5-3c0e1330cea1@suse.de> <87wo4dvha6.fsf@tromey.com> From: Tom de Vries Autocrypt: addr=tdevries@suse.de; keydata= xsBNBF0ltCcBCADDhsUnMMdEXiHFfqJdXeRvgqSEUxLCy/pHek88ALuFnPTICTwkf4g7uSR7 HvOFUoUyu8oP5mNb4VZHy3Xy8KRZGaQuaOHNhZAT1xaVo6kxjswUi3vYgGJhFMiLuIHdApoc u5f7UbV+egYVxmkvVLSqsVD4pUgHeSoAcIlm3blZ1sDKviJCwaHxDQkVmSsGXImaAU+ViJ5l CwkvyiiIifWD2SoOuFexZyZ7RUddLosgsO0npVUYbl6dEMq2a5ijGF6/rBs1m3nAoIgpXk6P TCKlSWVW6OCneTaKM5C387972qREtiArTakRQIpvDJuiR2soGfdeJ6igGA1FZjU+IsM5ABEB AAHNH1RvbSBkZSBWcmllcyA8dGRldnJpZXNAc3VzZS5kZT7CwKsEEwEIAD4WI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be3O7ik/MC q31FNIAQJPmKXX25B115MMzkSKlv4udfx7KdyxHrTSkwWZArLQiEZj5KG4cCKhIoMygPTA3U yGaIvI/BGOtHZ7bEBVUCFDFfOWJ26IOCoPnSVUvKPEOH9dv+sNy7jyBsP5QxeTqwxC/1ZtNS DUCSFQjqA6bEGwM22dP8OUY6SC94x1G81A9/xbtm9LQxKm0EiDH8KBMLfQ== Message-ID: <3e87a2cb-3550-d703-fb72-264207993adf@suse.de> Date: Fri, 12 Jun 2020 13:36:05 +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: <87wo4dvha6.fsf@tromey.com> Content-Type: multipart/mixed; boundary="------------8B9ACE590F5D6FAC4FA2AEA2" Content-Language: en-US X-Spam-Status: No, score=-15.9 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: Fri, 12 Jun 2020 11:36:12 -0000 This is a multi-part message in MIME format. --------------8B9ACE590F5D6FAC4FA2AEA2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 11-06-2020 15:55, Tom Tromey wrote: >>>>>> "Tom" == Tom de Vries writes: > > Tom> This fix uses a load_lib override. > > Tom> Any comments? > > There was a report recently about gdb overrides like this breaking > with a newer dejagnu. > You're referring to this ( https://sourceware.org/pipermail/gdb/2020-June/048689.html ) ? > Maybe we need a gdb_load or something like that, instead of > monkey-patching dejagnu? Or some other different approach. > > I'm not really opposed to this FWIW. It seems not likely to cause > problems. Though I thought that about the other override too, so.. OK, I dropped the load_lib overload. Now the idiom is: ... -load_lib tuiterm.exp +tuiterm_env ... I've also tried wrapping the test-case body using the tuiterm_env proc, like this: ... tuiterm_env { ... } ... but ran into curly-braces trouble in gdb.tui/new-layout.exp. Committed. Thanks, - Tom --------------8B9ACE590F5D6FAC4FA2AEA2 Content-Type: text/x-patch; charset=UTF-8; name="0001-gdb-testsuite-Don-t-leak-tuiterm.exp-spawn-override.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename*0="0001-gdb-testsuite-Don-t-leak-tuiterm.exp-spawn-override.pat"; filename*1="ch" [gdb/testsuite] Don't leak tuiterm.exp spawn override In lib/tuiterm.exp the builtin spawn is overridden by a tui-specific version. After running the first test-case that imports tuiterm.exp, the override remains active, so it can cause trouble in subsequent test-cases, even if they do not import tuiterm.exp. See f.i. commit c8d4f6dfd9 "[gdb/testsuite] Fix spawn in tuiterm.exp". Fix this by: - adding a variable gdb_finish_hooks which is a list of procs to run during gdb_finish - adding a proc tuiterm_env that is used in test-cases instead of "load_lib tuiterm.exp". - letting tuiterm_env: - install the tui-specific spawn version, and - use the gdb_finish_hooks to schedule restoring the builtin spawn version. Tested on x86_64-linux. gdb/testsuite/ChangeLog: 2020-06-05 Tom de Vries * lib/tuiterm.exp (spawn): Rename to ... (tui_spawn): ... this. (toplevel): Move rename of spawn ... (gdb_init_tuiterm): ... here. New proc. (gdb_finish_tuiterm): New proc. * lib/gdb.exp (gdb_finish_hooks): New global var. (gdb_finish): Handle gdb_finish_hooks. (tuiterm_env): New proc. * gdb.python/tui-window.exp: Replace load_lib tuiterm.exp with tuiterm_env. * gdb.tui/basic.exp: Same. * gdb.tui/corefile-run.exp: Same. * gdb.tui/empty.exp: Same. * gdb.tui/list-before.exp: Same. * gdb.tui/list.exp: Same. * gdb.tui/main.exp: Same. * gdb.tui/new-layout.exp: Same. * gdb.tui/regs.exp: Same. * gdb.tui/resize.exp: Same. * gdb.tui/tui-layout-asm-short-prog.exp: Same. * gdb.tui/tui-layout-asm.exp: Same. * gdb.tui/tui-missing-src.exp: Same. * gdb.tui/winheight.exp: Same. --- gdb/testsuite/gdb.python/tui-window.exp | 2 +- gdb/testsuite/gdb.tui/basic.exp | 2 +- gdb/testsuite/gdb.tui/corefile-run.exp | 2 +- gdb/testsuite/gdb.tui/empty.exp | 2 +- gdb/testsuite/gdb.tui/list-before.exp | 2 +- gdb/testsuite/gdb.tui/list.exp | 2 +- gdb/testsuite/gdb.tui/main.exp | 2 +- gdb/testsuite/gdb.tui/new-layout.exp | 2 +- gdb/testsuite/gdb.tui/regs.exp | 2 +- gdb/testsuite/gdb.tui/resize.exp | 2 +- .../gdb.tui/tui-layout-asm-short-prog.exp | 2 +- gdb/testsuite/gdb.tui/tui-layout-asm.exp | 2 +- gdb/testsuite/gdb.tui/tui-missing-src.exp | 2 +- gdb/testsuite/gdb.tui/winheight.exp | 2 +- gdb/testsuite/lib/gdb.exp | 23 ++++++++++++++++++++++ gdb/testsuite/lib/tuiterm.exp | 17 ++++++++++++++-- 16 files changed, 52 insertions(+), 16 deletions(-) diff --git a/gdb/testsuite/gdb.python/tui-window.exp b/gdb/testsuite/gdb.python/tui-window.exp index 1a4feebe22..503823a229 100644 --- a/gdb/testsuite/gdb.python/tui-window.exp +++ b/gdb/testsuite/gdb.python/tui-window.exp @@ -16,7 +16,7 @@ # Test a TUI window implemented in Python. load_lib gdb-python.exp -load_lib tuiterm.exp +tuiterm_env # This test doesn't care about the inferior. standard_testfile py-arch.c diff --git a/gdb/testsuite/gdb.tui/basic.exp b/gdb/testsuite/gdb.tui/basic.exp index 34e60384c4..3e013a9515 100644 --- a/gdb/testsuite/gdb.tui/basic.exp +++ b/gdb/testsuite/gdb.tui/basic.exp @@ -15,7 +15,7 @@ # Basic TUI tests. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/corefile-run.exp b/gdb/testsuite/gdb.tui/corefile-run.exp index 440142f74e..1878770bdc 100644 --- a/gdb/testsuite/gdb.tui/corefile-run.exp +++ b/gdb/testsuite/gdb.tui/corefile-run.exp @@ -18,7 +18,7 @@ # # Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1765117 -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/empty.exp b/gdb/testsuite/gdb.tui/empty.exp index e5d0228062..89f49d6b7f 100644 --- a/gdb/testsuite/gdb.tui/empty.exp +++ b/gdb/testsuite/gdb.tui/empty.exp @@ -15,7 +15,7 @@ # Test TUI resizing with empty windows. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile diff --git a/gdb/testsuite/gdb.tui/list-before.exp b/gdb/testsuite/gdb.tui/list-before.exp index d2f3ef472d..9c5eb5655e 100644 --- a/gdb/testsuite/gdb.tui/list-before.exp +++ b/gdb/testsuite/gdb.tui/list-before.exp @@ -15,7 +15,7 @@ # Ensure that "list" before starting the TUI will affect the view. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/list.exp b/gdb/testsuite/gdb.tui/list.exp index 41cec125d5..b1e59499c8 100644 --- a/gdb/testsuite/gdb.tui/list.exp +++ b/gdb/testsuite/gdb.tui/list.exp @@ -15,7 +15,7 @@ # Ensure that "list" will switch to the source view. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/main.exp b/gdb/testsuite/gdb.tui/main.exp index ae2393e6e9..fd3c2cd815 100644 --- a/gdb/testsuite/gdb.tui/main.exp +++ b/gdb/testsuite/gdb.tui/main.exp @@ -15,7 +15,7 @@ # Test that "file" shows "main". -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/new-layout.exp b/gdb/testsuite/gdb.tui/new-layout.exp index b71de7de5f..3ea4dd4069 100644 --- a/gdb/testsuite/gdb.tui/new-layout.exp +++ b/gdb/testsuite/gdb.tui/new-layout.exp @@ -15,7 +15,7 @@ # Test "tui new-layout". -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/regs.exp b/gdb/testsuite/gdb.tui/regs.exp index e31a47d47b..a9296a7d5f 100644 --- a/gdb/testsuite/gdb.tui/regs.exp +++ b/gdb/testsuite/gdb.tui/regs.exp @@ -15,7 +15,7 @@ # Simple test of TUI register window. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/resize.exp b/gdb/testsuite/gdb.tui/resize.exp index 1b3f407a02..fd1b35088a 100644 --- a/gdb/testsuite/gdb.tui/resize.exp +++ b/gdb/testsuite/gdb.tui/resize.exp @@ -15,7 +15,7 @@ # Test TUI resizing. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp index 4aa1ba3046..50cb61f0fa 100644 --- a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp +++ b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp @@ -16,7 +16,7 @@ # Ensure that 'layout asm' can scroll away from the last line of a # very short program using a page up sized scroll. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout-asm-short-prog.S diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm.exp b/gdb/testsuite/gdb.tui/tui-layout-asm.exp index 257321fec7..44f7a3a3a4 100644 --- a/gdb/testsuite/gdb.tui/tui-layout-asm.exp +++ b/gdb/testsuite/gdb.tui/tui-layout-asm.exp @@ -16,7 +16,7 @@ # Ensure that 'layout asm' before starting the inferior puts us in the # asm layout and displays the disassembly for main. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/gdb.tui/tui-missing-src.exp b/gdb/testsuite/gdb.tui/tui-missing-src.exp index 2d9a851bec..6b5c7fad4c 100644 --- a/gdb/testsuite/gdb.tui/tui-missing-src.exp +++ b/gdb/testsuite/gdb.tui/tui-missing-src.exp @@ -25,7 +25,7 @@ # layout must show the contents of f2.c. # 7. Going back to main() shall result in no contents again. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile diff --git a/gdb/testsuite/gdb.tui/winheight.exp b/gdb/testsuite/gdb.tui/winheight.exp index 7a17c311ea..8ac55f8472 100644 --- a/gdb/testsuite/gdb.tui/winheight.exp +++ b/gdb/testsuite/gdb.tui/winheight.exp @@ -15,7 +15,7 @@ # Test the "winheight" command. -load_lib "tuiterm.exp" +tuiterm_env standard_testfile tui-layout.c diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 64e667c20e..e7fce6fee0 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -25,6 +25,9 @@ if {$tool == ""} { exit 2 } +# List of procs to run in gdb_finish. +set gdb_finish_hooks [list] + load_lib libgloss.exp load_lib cache.exp load_lib gdb-utils.exp @@ -5241,6 +5244,12 @@ proc gdb_finish { } { } set banned_traced 0 } + + global gdb_finish_hooks + foreach gdb_finish_hook $gdb_finish_hooks { + $gdb_finish_hook + } + set gdb_finish_hooks [list] } global debug_format @@ -7259,5 +7268,19 @@ proc with_override { name override body } { return $result } +# Setup tuiterm.exp environment. To be used in test-cases instead of +# "load_lib tuiterm.exp". Calls initialization function and schedules +# finalization function. +proc tuiterm_env { } { + load_lib tuiterm.exp + + # Do initialization. + tuiterm_env_init + + # Schedule finalization. + global gdb_finish_hooks + lappend gdb_finish_hooks tuiterm_env_finish +} + # Always load compatibility stuff. load_lib future.exp diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index 8c9f97af6e..44cbc79730 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -19,8 +19,7 @@ # array; but dejagnu doesn't export this globally. So, we have to # wrap spawn with our own function, so that we can capture this value. # The value is later used in calls to stty. -rename spawn builtin_spawn -proc spawn {args} { +proc tuiterm_spawn { args } { set result [uplevel builtin_spawn $args] global gdb_spawn_name upvar spawn_out spawn_out @@ -32,6 +31,20 @@ proc spawn {args} { return $result } +# Initialize tuiterm.exp environment. +proc tuiterm_env_init { } { + # Override spawn with tui_spawn. + rename spawn builtin_spawn + rename tuiterm_spawn spawn +} + +# Finalize tuiterm.exp environment. +proc tuiterm_env_finish { } { + # Restore spawn. + rename spawn tuiterm_spawn + rename builtin_spawn spawn +} + namespace eval Term { variable _rows variable _cols --------------8B9ACE590F5D6FAC4FA2AEA2--