From c2feffd819867b2d21c5d7e6b3b40377ef692415 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Tue, 25 Apr 2023 08:33:56 +0200 Subject: [PATCH] [gdb/testsuite] Add debug prints in Term::wait_for The semantics of wait_for are non-trivial, and a bit hard to understand sometimes. Add some debug prints in wait_for that make it clear: - what regexps we're trying to match, - what strings we compare to the regexps, and - whether there's a match or mismatch. I've added this ad-hoc a couple of times, and it seems that it's worth having readily available. The debug prints are enabled by adding DEBUG_TUI_MATCHING=1 to the RUNTESTFLAGS: ... $ make check RUNTESTFLAGS="gdb.tui/empty.exp DEBUG_TUI_MATCHING=1" ... Tested on x86_64-linux. --- gdb/testsuite/lib/tuiterm.exp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index ff38af082da..bb462911046 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -716,6 +716,20 @@ namespace eval Term { return 1 } + # Print arg using "verbose -log" if DEBUG_TUI_MATCHING == 1. + proc debug_tui_matching { arg } { + set debug 0 + if { [info exists ::DEBUG_TUI_MATCHING] } { + set debug $::DEBUG_TUI_MATCHING + } + + if { ! $debug } { + return + } + + verbose -log "$arg" + } + # Accept some output from gdb and update the screen. WAIT_FOR is # a regexp matching the line to wait for. Return 0 on timeout, 1 # on success. @@ -724,7 +738,10 @@ namespace eval Term { variable _cur_col variable _cur_row + set fn "wait_for" + set prompt_wait_for "$gdb_prompt \$" + debug_tui_matching "$fn: regexp: '$wait_for'" while 1 { if { [accept_gdb_output] == 0 } { @@ -740,10 +757,14 @@ namespace eval Term { set prev [get_line $_cur_row] } if {[regexp -- $wait_for $prev]} { + debug_tui_matching "$fn: match: '$prev'" if {$wait_for == "$prompt_wait_for"} { break } set wait_for $prompt_wait_for + debug_tui_matching "$fn: regexp prompt: '$wait_for'" + } else { + debug_tui_matching "$fn: mismatch: '$prev'" } } -- 2.30.2