aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.tui
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite/gdb.tui')
-rw-r--r--gdb/testsuite/gdb.tui/corefile-run.exp2
-rw-r--r--gdb/testsuite/gdb.tui/esc-match.exp48
-rw-r--r--gdb/testsuite/gdb.tui/esc-match.py26
-rw-r--r--gdb/testsuite/gdb.tui/main-2.exp2
-rw-r--r--gdb/testsuite/gdb.tui/pr30056.exp4
-rw-r--r--gdb/testsuite/gdb.tui/tui-focus.exp2
-rw-r--r--gdb/testsuite/gdb.tui/tui-layout-asm.exp106
-rw-r--r--gdb/testsuite/gdb.tui/tuiterm.exp46
8 files changed, 193 insertions, 43 deletions
diff --git a/gdb/testsuite/gdb.tui/corefile-run.exp b/gdb/testsuite/gdb.tui/corefile-run.exp
index 89a48b5..657fc83 100644
--- a/gdb/testsuite/gdb.tui/corefile-run.exp
+++ b/gdb/testsuite/gdb.tui/corefile-run.exp
@@ -18,6 +18,8 @@
#
# Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1765117
+require gcore_cmd_available
+
tuiterm_env
standard_testfile tui-layout.c
diff --git a/gdb/testsuite/gdb.tui/esc-match.exp b/gdb/testsuite/gdb.tui/esc-match.exp
new file mode 100644
index 0000000..db78ebe
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/esc-match.exp
@@ -0,0 +1,48 @@
+# Copyright 2025 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test that the ANSI escape sequence matcher works
+# character-by-character.
+
+load_lib gdb-python.exp
+require allow_python_tests allow_tui_tests
+
+tuiterm_env
+
+Term::clean_restart 24 80
+
+set remote_python_file [gdb_remote_download host \
+ ${srcdir}/${subdir}/esc-match.py]
+gdb_test_no_output "source ${remote_python_file}" \
+ "source esc-match.py"
+
+if {![Term::enter_tui]} {
+ unsupported "TUI not supported"
+ return
+}
+
+Term::command "python print_it()"
+
+Term::dump_screen
+
+set text [Term::get_all_lines]
+# We should not see the control sequence here.
+gdb_assert {![regexp -- "\\\[35;1mOUTPUT\\\[m" $text]} \
+ "output visible without control sequences"
+
+# Also check the styling.
+set text [Term::get_region 0 1 78 23 "\n" true]
+gdb_assert {[regexp -- "<fg:magenta>.*OUTPUT" $text]} \
+ "output is magenta"
diff --git a/gdb/testsuite/gdb.tui/esc-match.py b/gdb/testsuite/gdb.tui/esc-match.py
new file mode 100644
index 0000000..7816002
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/esc-match.py
@@ -0,0 +1,26 @@
+# Copyright (C) 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+
+# Some text to print that includes styling.
+OUT = "\033[35;1mOUTPUT\033[m"
+
+
+def print_it():
+ # Print to stderr avoids any buffering, showing the bug.
+ for c in OUT:
+ print(c, end="", file=sys.stderr)
+ print(file=sys.stderr)
diff --git a/gdb/testsuite/gdb.tui/main-2.exp b/gdb/testsuite/gdb.tui/main-2.exp
index 2b0fb6b..71ad03b 100644
--- a/gdb/testsuite/gdb.tui/main-2.exp
+++ b/gdb/testsuite/gdb.tui/main-2.exp
@@ -41,7 +41,7 @@ if {![Term::enter_tui]} {
set line " return 0;"
set nr [gdb_get_line_number $line]
-set screen_line [Term::get_line_with_attrs 6]
+set screen_line [Term::get_string_with_attrs 6 1 79]
verbose -log "screen line 6: '$screen_line'"
gdb_assert { [regexp "$nr <reverse:1>$line<reverse:0>" $screen_line] } \
"highlighted line in middle of source window"
diff --git a/gdb/testsuite/gdb.tui/pr30056.exp b/gdb/testsuite/gdb.tui/pr30056.exp
index 1123593..3403033 100644
--- a/gdb/testsuite/gdb.tui/pr30056.exp
+++ b/gdb/testsuite/gdb.tui/pr30056.exp
@@ -76,12 +76,12 @@ save_vars { env(LC_ALL) } {
# open about this.
kfail cli/30498 $test
- # At this point we don't have a reponsive prompt. Send ^G to abort
+ # At this point we don't have a responsive prompt. Send ^G to abort
# the i-search.
send_gdb "\007"
}
- # We need a reponsive prompt here, to deal with the "monitor exit"
+ # We need a responsive prompt here, to deal with the "monitor exit"
# that native-extended-gdbserver will send. Check that we have a
# responsive prompt.
Term::command "echo \\n"
diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp
index 4c9d2a0..26e5060 100644
--- a/gdb/testsuite/gdb.tui/tui-focus.exp
+++ b/gdb/testsuite/gdb.tui/tui-focus.exp
@@ -73,7 +73,7 @@ foreach spec {{src true} {cmd true} {status true} {regs false} \
}
}
-# Use the Python TUI API to exercise some of the ambigous window name
+# Use the Python TUI API to exercise some of the ambiguous window name
# handling parts of the 'focus' command.
Term::clean_restart 24 80 $binfile
if {[allow_python_tests]} {
diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm.exp b/gdb/testsuite/gdb.tui/tui-layout-asm.exp
index ec78a0c..333276e 100644
--- a/gdb/testsuite/gdb.tui/tui-layout-asm.exp
+++ b/gdb/testsuite/gdb.tui/tui-layout-asm.exp
@@ -24,7 +24,9 @@ if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} {
return -1
}
-# PPC currently needs a minimum window width of 90 to work correctly.
+# The wider the window is, the less line truncation happens, so matching
+# pre-scroll to post-scroll lines is more accurate. But 100% accurate line
+# matching isn't a goal of the test-case.
set tui_asm_window_width 90
Term::clean_restart 24 ${tui_asm_window_width} $testfile
@@ -33,15 +35,41 @@ if {![Term::prepare_for_tui]} {
return
}
-# Helper proc, returns a count of the ' ' characters in STRING.
-proc count_whitespace { string } {
- return [expr {[llength [split $string { }]] - 1}]
-}
-
# This puts us into TUI mode, and should display the ASM window.
Term::command_no_prompt_prefix "layout asm"
Term::check_box_contents "check asm box contents" 0 0 ${tui_asm_window_width} 15 "<main>"
+set re_border [string_to_regexp "|"]
+
+proc drop_borders { line } {
+ # Drop left border.
+ set line [regsub -- ^$::re_border $line {}]
+ # Drop right border.
+ set line [regsub -- $::re_border$ $line {}]
+
+ return $line
+}
+
+proc lines_match { line1 line2 } {
+ set line1 [drop_borders $line1]
+ set line2 [drop_borders $line2]
+
+ foreach line [list $line1 $line2] re [list $line2 $line1] {
+ # Convert to regexp.
+ set re [string_to_regexp $re]
+
+ # Ignore whitespace mismatches.
+ regsub -all {\s+} $re {\s+} re
+
+ # Allow a substring match.
+ if { [regexp -- $re $line] } {
+ return 1
+ }
+ }
+
+ return 0
+}
+
# Scroll the ASM window down using the down arrow key. In an ideal
# world we'd like to use PageDown here, but currently our terminal
# library doesn't support such advanced things.
@@ -58,51 +86,55 @@ while (1) {
# below will just timeout. So for now we avoid testing the edge
# case.
if {[regexp -- "^\\| +\\|$" $line]} {
- # Second line is blank, we're at the end of the assembler.
- pass $testname
+ # Second line is blank, we're at the end of the assembly.
+ pass "$testname (end of assembly reached)"
break
}
# Send the down key to GDB.
send_gdb "\033\[B"
incr down_count
- set re_line [string_to_regexp $line]
- # Ignore whitespace mismatches.
- regsub -all {\s+} $re_line {\s+} re_line
+
+ # Get address from the line.
+ regexp \
+ [join \
+ [list \
+ ^ \
+ $re_border \
+ {\s+} \
+ ($hex) \
+ {\s+}] \
+ ""] \
+ $line \
+ match \
+ address
+
+ # Regexp to match line containing address.
+ set re_line \
+ [join \
+ [list \
+ ^ \
+ $re_border \
+ {\s+} \
+ $address \
+ {\s+} \
+ {[^\r\n]+} \
+ $re_border \
+ $] \
+ ""]
+
if {[Term::wait_for $re_line] \
- && [regexp $re_line [Term::get_line 1]]} {
+ && [lines_match $line [Term::get_line 1]]} {
# We scrolled successfully.
} else {
- if {[count_whitespace ${line}] != \
- [count_whitespace [Term::get_line 1]]} {
- # GDB's TUI assembler display will widen columns based on
- # the longest item that appears in a column on any line.
- # As we have just scrolled, and so revealed a new line, it
- # is possible that the width of some columns has changed.
- #
- # As a result it is possible that part of the line we were
- # expected to see in the output is now off the screen. And
- # this test will fail.
- #
- # This is unfortunate, but, right now, there's no easy way
- # to "lock" the format of the TUI assembler window. The
- # only option appears to be making the window width wider,
- # this can be done by adjusting TUI_ASM_WINDOW_WIDTH.
- verbose -log "WARNING: The following failure is probably due to the TUI window"
- verbose -log " width. See the comments in the test script for more"
- verbose -log " details."
- }
-
fail "$testname (scroll failed)"
Term::dump_screen
break
}
- if { $down_count > 250 } {
- # Maybe we should accept this as a pass in case a target
- # really does have loads of assembler to scroll through.
- fail "$testname (too much assembler)"
- Term::dump_screen
+ if { $down_count > 25 } {
+ # We've scrolled enough, we're done.
+ pass "$testname (scroll limit reached)"
break
}
}
diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp
index 9dc2402..6cd65f3 100644
--- a/gdb/testsuite/gdb.tui/tuiterm.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm.exp
@@ -102,7 +102,7 @@ proc test_backspace {} {
Term::_move_cursor 1 2
- Term::_ctl_0x08
+ Term::_ctl_0x08 0
check "backspace one" {
"abcdefgh"
"ijklmnop"
@@ -111,13 +111,22 @@ proc test_backspace {} {
} 0 2
# Cursor should not move if it is already at column 0.
- Term::_ctl_0x08
+ Term::_ctl_0x08 0
check "backspace 2" {
"abcdefgh"
"ijklmnop"
"qrstuvwx"
"yz01234 "
} 0 2
+
+ # Cursor should wrap to previous line.
+ Term::_ctl_0x08 1
+ check "backspace 3" {
+ "abcdefgh"
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 7 1
}
proc test_linefeed { } {
@@ -435,6 +444,30 @@ proc test_horizontal_absolute { } {
"qrstuvwx"
"yz01234 "
} 3 2
+
+ Term::_csi_G 8
+ check "cursor horizontal absolute 3" {
+ "abcdefgh"
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 7 2
+
+ Term::_csi_G 9
+ check "cursor horizontal absolute 4" {
+ "abcdefgh"
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 7 2
+
+ Term::_csi_`
+ check "horizontal position absolute 1" {
+ "abcdefgh"
+ "ijklmnop"
+ "qrstuvwx"
+ "yz01234 "
+ } 0 2
}
proc test_cursor_position { } {
@@ -750,6 +783,15 @@ proc test_attrs {} {
set line [Term::get_line_with_attrs 0]
gdb_assert { [regexp $re $line] } "attribute: $attr"
}
+
+ # Regression test: Check that _csi_m works without arguments.
+ setup_terminal 4 1
+ Term::_csi_m 7
+ Term::_insert "a"
+ Term::_csi_m
+ Term::_insert "a"
+ set line [Term::get_line_with_attrs 0]
+ gdb_assert { [string equal $line "<reverse:1>a<reverse:0>a "] }
}
# Run proc TEST_PROC_NAME with a "small" terminal.