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 A45F9386FC3C for ; Tue, 8 Jun 2021 21:21:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A45F9386FC3C X-ASG-Debug-ID: 1623187287-0c856e67e21437660001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id GtWXzUHW8ORFSklX (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 08 Jun 2021 17:21:27 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 89C58441B21; Tue, 8 Jun 2021 17:21:27 -0400 (EDT) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH] gdb/testsuite: capture GDB tty name in default_gdb_spawn Date: Tue, 8 Jun 2021 17:21:26 -0400 X-ASG-Orig-Subj: [PATCH] gdb/testsuite: capture GDB tty name in default_gdb_spawn Message-Id: <20210608212126.1673188-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1623187287 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 7460 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.90517 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-17.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_QUARANTINE, 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: Tue, 08 Jun 2021 21:21:30 -0000 The TUI test gdb.tui/empty.exp fails with the native-extended-gdbserver board, and takes a very long time to run due to numerous timeouts. The symptom, when looking at the logs, is that the TUI windows that we expect to be resized are not resized. Digging down, I found that GDB didn't receive any SIGWINCH that should have resulted from Term::resize's stty calls. The reason for this is: - The native-extended-gdbserver overrides gdb_start to first start GDB, then start GDBserver with --multi, then connect GDB to GDBserver. This means that two TCL "spawn"s are done, one for GDB and one for GDBserver. - The TUI test framework wants to know GDB's TTY name, so it can pass it to stty, to fake terminal resizes. To do so, it overrides the spawn built-in proc to capture the tty name from the internals of the built-in proc. It saves the TTY name to the gdb_spawn_name global variable. - Because the native-extended-gdbserver boards starts both GDB and GDBserver, the final value of gdb_spawn_name is the name of GDBserver's TTY. - When the TUI test framework attempts to resize GDB's terminal, it in fact resizes GDBserver's terminal. So obviously, GDB doesn't get the SIGWINCH, and we don't get the expected TUI redraw. Fix that by moving the hack to the default_gdb_spawn proc instead, so that we only record GDB's TTY name. That name is saved in the gdb_tty_name global variable. I tried to use with_override for this, but it doesn't seem possible to use with_override to override a builtin proc like "spawn", because "info args" and "info body" fail for it. So, manually rename the procs for the time of the spawn. Remove tuiterm_env_init and tuiterm_env_finish, since they are now empty. In turn, the gdb_finish_hooks mechanism is now unused, remove it as well. It would be easy to add them back if needed. gdb/ChangeLog: * lib/gdb.exp (default_gdb_exit): Unset gdb_tty_name. (spawn_capture_tty_name): New. (default_gdb_spawn): Capture GDB's TTY name. * lib/tuiterm.exp (tuiterm_spawn): Remove. (tuiterm_env_init, tuiterm_env_finish): Remove spawn override. (Term) : Use new variable name. (tuiterm_env_init, tuiterm_env_finish): Remove. (tuiterm_env): Don't call tuiterm_env_init and register tuiterm_env_finish in gdb_finish_hooks. (gdb_finish_hooks): Remove. (gdb_finish): Don't call finish hooks. # Schedule finalization. global gdb_finish_hooks lappend gdb_finish_hooks tuiterm_env_finish Change-Id: Ia5ab74184a52a996416022308f8d0cc523355a78 --- gdb/testsuite/lib/gdb.exp | 44 ++++++++++++++++++++++++++++------- gdb/testsuite/lib/tuiterm.exp | 35 ++-------------------------- 2 files changed, 38 insertions(+), 41 deletions(-) diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 8469ec9801c0..34882362cc9d 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -1909,6 +1909,7 @@ proc default_gdb_exit {} { remote_close host } unset gdb_spawn_id + unset ::gdb_tty_name unset inferior_spawn_id } @@ -2037,6 +2038,25 @@ proc gdb_file_cmd { arg } { } } +# The expect "spawn" function puts the tty name into the spawn_out +# array; but dejagnu doesn't export this globally. So, we have to +# wrap spawn with our own function and poke in the built-in spawn +# so that we can capture this value. +# +# If available, the TTY name is saved to the LAST_SPAWN_TTY_NAME global. +# Otherwise, LAST_SPAWN_TTY_NAME is unset. + +proc spawn_capture_tty_name { args } { + set result [uplevel builtin_spawn $args] + upvar spawn_out spawn_out + if { [info exists spawn_out] } { + set ::last_spawn_tty_name $spawn_out(slave,name) + } else { + unset ::last_spawn_tty_name + } + return $result +} + # Default gdb_spawn procedure. proc default_gdb_spawn { } { @@ -2067,13 +2087,28 @@ proc default_gdb_spawn { } { exit 1 } } - set res [remote_spawn host "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]"] + + # Capture GDB's TTY name, so we can save it below. + rename spawn builtin_spawn + rename spawn_capture_tty_name spawn + set code [catch {uplevel 1 { + remote_spawn host "$::GDB $::INTERNAL_GDBFLAGS $::GDBFLAGS [host_info gdb_opts]" + }} res] + rename spawn spawn_capture_tty_name + rename builtin_spawn spawn + + # If remote_spawn threw an error, propagate it. + if { $code == 1 } { + return -code $code -errorinfo $::errorInfo -errorcode $::errorCode $res + } + if { $res < 0 || $res == "" } { perror "Spawning $GDB failed." return 1 } set gdb_spawn_id $res + set ::gdb_tty_name $::last_spawn_tty_name return 0 } @@ -7800,13 +7835,6 @@ proc with_override { name override body } { # 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 } # Dejagnu has a version of note, but usage is not allowed outside of dejagnu. diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index fdd9f4d2188f..222583f291fb 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -15,36 +15,6 @@ # An ANSI terminal emulator for expect. -# The expect "spawn" function puts the tty name into the spawn_out -# 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. -proc tuiterm_spawn { args } { - set result [uplevel builtin_spawn $args] - global gdb_spawn_name - upvar spawn_out spawn_out - if { [info exists spawn_out] } { - set gdb_spawn_name $spawn_out(slave,name) - } else { - unset gdb_spawn_name - } - 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 { # Size of the terminal. variable _rows @@ -890,13 +860,12 @@ namespace eval Term { variable _cols variable _resize_count - global gdb_spawn_name # expect handles each argument to stty separately. This means # that gdb will see SIGWINCH twice. Rather than rely on this # behavior (which, after all, could be changed), we make it # explicit here. This also simplifies waiting for the redraw. _do_resize $rows $_cols - stty rows $_rows < $gdb_spawn_name + stty rows $_rows < $::gdb_tty_name # Due to the strange column resizing behavior, and because we # don't care about this intermediate resize, we don't check # the size here. @@ -906,7 +875,7 @@ namespace eval Term { # than what we request from expect. We hide this weird # details from the caller. _do_resize $_rows $cols - stty columns [expr {$_cols + 1}] < $gdb_spawn_name + stty columns [expr {$_cols + 1}] < $::gdb_tty_name wait_for "@@ resize done $_resize_count, size = ${_cols}x${rows}" incr _resize_count } -- 2.32.0