diff options
Diffstat (limited to 'gdb/testsuite/gdb.tui')
52 files changed, 888 insertions, 220 deletions
diff --git a/gdb/testsuite/gdb.tui/basic.exp b/gdb/testsuite/gdb.tui/basic.exp index ecb91de..8ecc91a 100644 --- a/gdb/testsuite/gdb.tui/basic.exp +++ b/gdb/testsuite/gdb.tui/basic.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 @@ -112,5 +112,9 @@ set re_noattr "\[^<\]" set status_window_line 15 set status [Term::get_line_with_attrs $status_window_line] -gdb_assert { [regexp "^<reverse:1>$re_noattr*<reverse:0>$" $status] == 1} \ +verbose -log "status line: '$status'" + +# The status line uses standout, which may translate to different attributes +# depending on the terminal settings. Just check for at least one attribute. +gdb_assert { [regexp "^<.*>(exec|extended-r)" $status] == 1 } \ "status window: reverse" diff --git a/gdb/testsuite/gdb.tui/break.exp b/gdb/testsuite/gdb.tui/break.exp index 274d292..77b2695 100644 --- a/gdb/testsuite/gdb.tui/break.exp +++ b/gdb/testsuite/gdb.tui/break.exp @@ -1,4 +1,4 @@ -# Copyright 2021-2024 Free Software Foundation, Inc. +# Copyright 2021-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 diff --git a/gdb/testsuite/gdb.tui/color-prompt.exp b/gdb/testsuite/gdb.tui/color-prompt.exp index 9ed8c47..af6e467 100644 --- a/gdb/testsuite/gdb.tui/color-prompt.exp +++ b/gdb/testsuite/gdb.tui/color-prompt.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 @@ -15,18 +15,16 @@ # Check using a prompt with color in TUI. +require allow_tui_tests + tuiterm_env Term::clean_restart 24 80 -# Set colored prompt. if {![Term::enter_tui]} { unsupported "TUI not supported" return } -Term::command "set prompt \\033\[31m(gdb) \\033\[0m" - -set line [Term::get_line_with_attrs $Term::_cur_row] -gdb_assert { [regexp "^<fg:red>$gdb_prompt <fg:default> *$" $line] } \ - "prompt with color" +set tui 1 +source $srcdir/$subdir/color-prompt.exp.tcl diff --git a/gdb/testsuite/gdb.tui/color-prompt.exp.tcl b/gdb/testsuite/gdb.tui/color-prompt.exp.tcl new file mode 100644 index 0000000..e6f4d3b --- /dev/null +++ b/gdb/testsuite/gdb.tui/color-prompt.exp.tcl @@ -0,0 +1,80 @@ +# 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/>. + +# Check using a prompt with color in TUI ($tui == 0) or CLI ($tui == 0). + +set csi [string cat {\033} "\["] +set rl_prompt_start_ignore {\001} +set rl_prompt_end_ignore {\002} + +foreach_with_prefix rl_prompt_start_end_ignore { 0 1 } { + set color_on [string cat $csi 31m] + set color_off [string cat $csi 0m] + + if { $rl_prompt_start_end_ignore } { + set color_on \ + [string cat \ + $rl_prompt_start_ignore \ + $color_on \ + $rl_prompt_end_ignore] + set color_off \ + [string cat \ + $rl_prompt_start_ignore \ + $color_off \ + $rl_prompt_end_ignore] + } + + # Set prompt with color. + set prompt "${color_on}(gdb) $color_off" + Term::command "set prompt $prompt" + + # Check the color. + set line [Term::get_line_with_attrs $Term::_cur_row] + gdb_assert { [regexp "^<fg:red>$gdb_prompt <fg:default> *$" $line] } \ + "prompt with color" + + # Type a string. + set cmd "some long command" + send_gdb $cmd + Term::wait_for_line ^[string_to_regexp "(gdb) $cmd"] 23 + + # Send ^A, aka C-a, trigger beginning-of-line. + send_gdb "\001" + if { $tui || $rl_prompt_start_end_ignore } { + Term::wait_for_line ^[string_to_regexp "(gdb) $cmd"] 6 + } else { + # Without the markers, readline may get the cursor position wrong, so + # match less strict. + Term::wait_for_line ^[string_to_regexp "(gdb) $cmd"] + } + Term::dump_screen + + # Type something else to flush out the effect of the ^A. + set prefix "A" + send_gdb $prefix + if { $tui || $rl_prompt_start_end_ignore } { + Term::wait_for_line ^[string_to_regexp "(gdb) $prefix$cmd"] 7 + } else { + # Without the markers, readline may get the cursor position wrong, so + # match less strict. + Term::wait_for_line [string_to_regexp "$prefix"] + } + + # Abort command line editing, and regenerate prompt. + send_gdb "\003" + + # Reset prompt to default prompt. + Term::command "set prompt (gdb) " +} diff --git a/gdb/testsuite/gdb.tui/compact-source.exp b/gdb/testsuite/gdb.tui/compact-source.exp index 79c8c85..31bc1dc 100644 --- a/gdb/testsuite/gdb.tui/compact-source.exp +++ b/gdb/testsuite/gdb.tui/compact-source.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 @@ -41,7 +41,7 @@ if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} { return -1 } -Term::clean_restart 24 80 $binfile +Term::clean_restart 24 80 $testfile gdb_test_no_output "maint set tui-left-margin-verbose on" gdb_test_no_output "set tui compact-source on" @@ -55,9 +55,9 @@ set re_border "\\|" set max_line_nr_in_source_file [llength $src_list] # Ensure there are more lines in the window than in the source file. -set src_window_lines [expr $max_line_nr_in_source_file + 2] +set src_window_lines [expr {$max_line_nr_in_source_file + 2}] # Account for border size. -set src_window_size [expr $src_window_lines + 2] +set src_window_size [expr {$src_window_lines + 2}] Term::command "wh src $src_window_size" set re_left_margin "___4_" @@ -65,6 +65,6 @@ set re_left_margin "___4_" Term::check_contents "compact source format" \ "$re_border$re_left_margin$re_line_four *$re_border" -set re_left_margin "___0*[expr $max_line_nr_in_source_file + 1]_" +set re_left_margin "___0*[expr {$max_line_nr_in_source_file + 1}]_" Term::check_contents_not "no surplus line number" \ "$re_border$re_left_margin *$re_border" diff --git a/gdb/testsuite/gdb.tui/completion.exp b/gdb/testsuite/gdb.tui/completion.exp index e79c468..7d126e0 100644 --- a/gdb/testsuite/gdb.tui/completion.exp +++ b/gdb/testsuite/gdb.tui/completion.exp @@ -1,4 +1,4 @@ -# Copyright 2015-2024 Free Software Foundation, Inc. +# Copyright 2015-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 diff --git a/gdb/testsuite/gdb.tui/corefile-run.exp b/gdb/testsuite/gdb.tui/corefile-run.exp index f96ead9..03775be 100644 --- a/gdb/testsuite/gdb.tui/corefile-run.exp +++ b/gdb/testsuite/gdb.tui/corefile-run.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 @@ -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 @@ -46,26 +48,52 @@ set src_line_nr [gdb_get_line_number $src_line] set run_re \ "\\\[Inferior $decimal \\\(process $decimal\\\) exited normally\\]" -if { [info exists USE_TUI] && $USE_TUI == 0 } { +with_test_prefix cli { + set re_kfail \ + "[string_to_regexp fbsd-nat.c]:$decimal: internal-error: wait_1: " + set re_quit [string_to_regexp "Quit this debugging session? (y or n) "] + set re_core_file [string_to_regexp "Create a core file of GDB? (y or n) "] clean_restart $testfile gdb_test "core-file $core" $src_line "load corefile" - gdb_test "run" $run_re "run until the end" - return + set ok 0 + gdb_test_multiple "run" "run until the end" { + -early -re $re_kfail { + kfail tdep/33176 $gdb_test_name + # Get back gdb prompt. + gdb_expect { + -re ($re_quit|$re_core_file) { + send_gdb "n\n" + exp_continue + } + -re "$gdb_prompt " { + } + } + } + -re -wrap $run_re { + set ok 1 + pass $gdb_test_name + } + } + if {!$ok} { + return + } } -Term::clean_restart 24 80 $testfile -if {![Term::enter_tui]} { - unsupported "TUI not supported" - return -} +with_test_prefix tui { + Term::clean_restart 24 80 $testfile + if {![Term::enter_tui]} { + unsupported "TUI not supported" + return + } -set text [Term::get_all_lines] -gdb_assert {![string match "No Source Available" $text]} \ - "initial source listing" + set text [Term::get_all_lines] + gdb_assert {![string match "No Source Available" $text]} \ + "initial source listing" -send_gdb "core-file $core\n" -Term::wait_for "Program terminated" -Term::check_contents "load corefile" "$src_line_nr *$src_line.*$gdb_prompt .*" + send_gdb "core-file $core\n" + Term::wait_for "Program terminated" + Term::check_contents "load corefile" "$src_line_nr *$src_line.*$gdb_prompt .*" -Term::command "run" -Term::check_contents "run until the end" $run_re + Term::command "run" + Term::check_contents "run until the end" $run_re +} diff --git a/gdb/testsuite/gdb.tui/empty.exp b/gdb/testsuite/gdb.tui/empty.exp index 1adf30b..19196e8 100644 --- a/gdb/testsuite/gdb.tui/empty.exp +++ b/gdb/testsuite/gdb.tui/empty.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 @@ -65,7 +65,7 @@ set layouts { proc check_boxes {boxes} { set boxno 1 foreach box $boxes { - eval Term::check_box [list "box $boxno"] $box + Term::check_box "box $boxno" {*}$box incr boxno } } 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/gdb.sh b/gdb/testsuite/gdb.tui/gdb.sh new file mode 100755 index 0000000..32a4e8a --- /dev/null +++ b/gdb/testsuite/gdb.tui/gdb.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# 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/>. + +printf "foo\033(%%5" + +read -r _ diff --git a/gdb/testsuite/gdb.tui/info-win.exp b/gdb/testsuite/gdb.tui/info-win.exp index 4d71f04..fd880b3 100644 --- a/gdb/testsuite/gdb.tui/info-win.exp +++ b/gdb/testsuite/gdb.tui/info-win.exp @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 diff --git a/gdb/testsuite/gdb.tui/list-before.exp b/gdb/testsuite/gdb.tui/list-before.exp index 2474365..3323c85 100644 --- a/gdb/testsuite/gdb.tui/list-before.exp +++ b/gdb/testsuite/gdb.tui/list-before.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 diff --git a/gdb/testsuite/gdb.tui/list.exp b/gdb/testsuite/gdb.tui/list.exp index 74b2c51..d24479f 100644 --- a/gdb/testsuite/gdb.tui/list.exp +++ b/gdb/testsuite/gdb.tui/list.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 diff --git a/gdb/testsuite/gdb.tui/long-prompt.exp b/gdb/testsuite/gdb.tui/long-prompt.exp index 1116b57..c4cb2c3 100644 --- a/gdb/testsuite/gdb.tui/long-prompt.exp +++ b/gdb/testsuite/gdb.tui/long-prompt.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/main-2.exp b/gdb/testsuite/gdb.tui/main-2.exp index 1dcb3cf..2bc6b8d 100644 --- a/gdb/testsuite/gdb.tui/main-2.exp +++ b/gdb/testsuite/gdb.tui/main-2.exp @@ -1,4 +1,4 @@ -# Copyright 2024 Free Software Foundation, Inc. +# Copyright 2024-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 @@ -26,7 +26,7 @@ if { [build_executable "failed to prepare" $testfile $srcfile ] == -1} { return -1 } -Term::clean_restart 24 80 $binfile +Term::clean_restart 24 80 $testfile if {![runto_main]} { perror "test suppressed" @@ -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 11 79] verbose -log "screen line 6: '$screen_line'" -gdb_assert { [regexp "$nr <reverse:1>$line<reverse:0>" $screen_line] } \ +gdb_assert { [regexp "<reverse:1>$line<reverse:0>" $screen_line] } \ "highlighted line in middle of source window" diff --git a/gdb/testsuite/gdb.tui/main-one-line.c b/gdb/testsuite/gdb.tui/main-one-line.c index 60744a9..442865c 100644 --- a/gdb/testsuite/gdb.tui/main-one-line.c +++ b/gdb/testsuite/gdb.tui/main-one-line.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2021-2024 Free Software Foundation, Inc. + Copyright 2021-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 diff --git a/gdb/testsuite/gdb.tui/main.exp b/gdb/testsuite/gdb.tui/main.exp index 4213035..e49da35 100644 --- a/gdb/testsuite/gdb.tui/main.exp +++ b/gdb/testsuite/gdb.tui/main.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 @@ -43,7 +43,10 @@ if {![Term::enter_tui]} { } send_gdb "file [standard_output_file $testfile]\n" -gdb_assert { [Term::wait_for "Reading symbols from"] } "file command" +# Matching the output is difficult because it may or may not wrap. Simply +# match the resulting prompt. +gdb_assert { [Term::wait_for ""] } "file command" + Term::check_contents "show main after file" \ [string_to_regexp "|___[format %06d $nr]_$line"] diff --git a/gdb/testsuite/gdb.tui/narrow.exp b/gdb/testsuite/gdb.tui/narrow.exp index 2efa440..b721475 100644 --- a/gdb/testsuite/gdb.tui/narrow.exp +++ b/gdb/testsuite/gdb.tui/narrow.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/new-layout.exp b/gdb/testsuite/gdb.tui/new-layout.exp index f838814..6a4c68f 100644 --- a/gdb/testsuite/gdb.tui/new-layout.exp +++ b/gdb/testsuite/gdb.tui/new-layout.exp @@ -1,4 +1,4 @@ -# Copyright 2020-2024 Free Software Foundation, Inc. +# Copyright 2020-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 @@ -45,15 +45,12 @@ gdb_test "tui new-layout example src 1 src 1" \ gdb_test "tui new-layout example src 1" \ "New layout does not contain the \"cmd\" window" -# Avoid unbalanced curly braces problems with tcl 8.5. -if { [tcl_version_at_least 8 6] } { - gdb_test "tui new-layout example src 1\}" \ - "Extra '\}' in layout specification" - gdb_test "tui new-layout example {src 1} 1\}" \ - "Extra '\}' in layout specification" - gdb_test "tui new-layout example \{src 1" \ - "Missing '\}' in layout specification" -} +gdb_test "tui new-layout example src 1\}" \ + "Extra '\}' in layout specification" +gdb_test "tui new-layout example {src 1} 1\}" \ + "Extra '\}' in layout specification" +gdb_test "tui new-layout example \{src 1" \ + "Missing '\}' in layout specification" # Each entry of this list describes a layout, and some associated # tests. The items within each entry are: @@ -84,7 +81,7 @@ set layouts \ proc check_boxes {boxes} { set boxno 1 foreach box $boxes { - eval Term::check_box [list "box $boxno"] $box + Term::check_box "box $boxno" {*}$box incr boxno } } @@ -150,4 +147,7 @@ Term::check_box "before cmd_only: src box in src layout" 0 0 80 15 Term::command "layout cmd_only" Term::command "layout src" + +# Flush out and check the resulting src box. +Term::command "print 1" Term::check_box "after cmd_only: src box in src layout" 0 0 80 15 diff --git a/gdb/testsuite/gdb.tui/pr30056.exp b/gdb/testsuite/gdb.tui/pr30056.exp index 11e198d..22278e3 100644 --- a/gdb/testsuite/gdb.tui/pr30056.exp +++ b/gdb/testsuite/gdb.tui/pr30056.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 @@ -22,67 +22,72 @@ require {have_host_locale C.UTF-8} tuiterm_env +standard_testfile tui-long-line.c + +if { [build_executable "failed to prepare" $testfile $srcfile] == -1 } { + return +} + save_vars { env(LC_ALL) } { setenv LC_ALL C.UTF-8 # Start terminal. - Term::clean_restart 24 80 - - # Start TUI. - if {![Term::enter_tui]} { - unsupported "TUI not supported" - return - } - - # Send "^R", starting reverse-i-search. - send_gdb "\022" - Term::wait_for_region_contents 0 $Term::_cur_row $Term::_cols 1 \ - [string_to_regexp "(reverse-i-search)`': "] - - # Send "xyz". - send_gdb "xyz" - Term::wait_for_region_contents 0 $Term::_cur_row $Term::_cols 1 \ - [string_to_regexp "(failed reverse-i-search)`xyz': "] - - # Send arrow-right. - send_gdb "\033\[C" + Term::clean_restart 24 80 $testfile +} - # We need to the arrow-right to be processed by readline, before we - # send the following ^C. Waiting 1 ms seems to do that. - after 1 +# Start TUI. +if {![Term::enter_tui]} { + unsupported "TUI not supported" + return +} - # Send ^C. +# Send "^R", starting reverse-i-search. +send_gdb "\022" +gdb_assert { [Term::wait_for_region_contents 0 $Term::_cur_row $Term::_cols 1 \ + [string_to_regexp "(reverse-i-search)`': "]] } \ + "reverse-i-search" + +# Send "xyz". +send_gdb "xyz" +gdb_assert { [Term::wait_for_region_contents 0 $Term::_cur_row $Term::_cols 1 \ + [string_to_regexp "(failed reverse-i-search)`xyz': "]] } \ + "xyz" + +# Send arrow-right. +send_gdb "\033\[C" +# Wait for arrow-right effect. +gdb_assert { [Term::wait_for_region_contents 1 1 78 13 \ + [string_to_regexp " ain (void)"]] } "arrow right" + +# Send ^C. +send_gdb "\003" +gdb_assert { [Term::wait_for "Quit"] } "Control-C" + +set test "Control-C aborts isearch" + +# Send "xyz", again. +send_gdb "xyz" +# Wait for xyx to appear. +gdb_assert { [Term::wait_for_region_contents \ + 0 $Term::_cur_row $Term::_cols 1 "xyz"] } \ + "xyz, again" + +if { [Term::check_region_contents_p 0 $Term::_cur_row $Term::_cols 1 \ + "^$gdb_prompt xyz"] } { + pass $test + + # Send ^C to clear the command line. send_gdb "\003" - gdb_assert { [Term::wait_for "Quit"] } "Control-C" - - # Uncomment this to simulate that PR cli/30498 is fixed. - #send_gdb "\007" - - set test "Control-C aborts isearch" - - # Send "xyz", again. - send_gdb "xyz" - # Wait for xyx to appear. - Term::wait_for_region_contents 0 $Term::_cur_row $Term::_cols 1 "xyz" - - if { [Term::check_region_contents_p 0 $Term::_cur_row $Term::_cols 1 \ - "^$gdb_prompt xyz"] } { - pass $test - - # Send ^C to clear the command line. - send_gdb "\003" - } else { - # Sending ^C currently doesn't abort the i-search. PR cli/30498 is - # open about this. - kfail cli/30498 $test - - # At this point we don't have a reponsive prompt. Send ^G to abort - # the i-search. - send_gdb "\007" - } - - # We need a reponsive 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" +} else { + # Sending ^C currently doesn't abort the i-search. + fail $test + + # At this point we don't have a responsive prompt. Send ^G to abort + # the i-search. + send_gdb "\007" } + +# 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/regs.exp b/gdb/testsuite/gdb.tui/regs.exp index 183c2ea..fbc93fd 100644 --- a/gdb/testsuite/gdb.tui/regs.exp +++ b/gdb/testsuite/gdb.tui/regs.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 diff --git a/gdb/testsuite/gdb.tui/reread.exp b/gdb/testsuite/gdb.tui/reread.exp index 9f16bee..c8b0beb 100644 --- a/gdb/testsuite/gdb.tui/reread.exp +++ b/gdb/testsuite/gdb.tui/reread.exp @@ -1,4 +1,4 @@ -# Copyright 2024 Free Software Foundation, Inc. +# Copyright 2024-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 diff --git a/gdb/testsuite/gdb.tui/resize-2.exp b/gdb/testsuite/gdb.tui/resize-2.exp index 729e1ee..4262dc9 100644 --- a/gdb/testsuite/gdb.tui/resize-2.exp +++ b/gdb/testsuite/gdb.tui/resize-2.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/resize-one-line.exp b/gdb/testsuite/gdb.tui/resize-one-line.exp index bdb7e01..bd89c17 100644 --- a/gdb/testsuite/gdb.tui/resize-one-line.exp +++ b/gdb/testsuite/gdb.tui/resize-one-line.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/resize.exp b/gdb/testsuite/gdb.tui/resize.exp index 1fa86f5..e13b269 100644 --- a/gdb/testsuite/gdb.tui/resize.exp +++ b/gdb/testsuite/gdb.tui/resize.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 diff --git a/gdb/testsuite/gdb.tui/scroll.exp b/gdb/testsuite/gdb.tui/scroll.exp index 6fba0e1..3c17e71 100644 --- a/gdb/testsuite/gdb.tui/scroll.exp +++ b/gdb/testsuite/gdb.tui/scroll.exp @@ -1,4 +1,4 @@ -# Copyright 2021-2024 Free Software Foundation, Inc. +# Copyright 2021-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 diff --git a/gdb/testsuite/gdb.tui/secondary-prompt.exp b/gdb/testsuite/gdb.tui/secondary-prompt.exp index 63e62db..d92bb78 100644 --- a/gdb/testsuite/gdb.tui/secondary-prompt.exp +++ b/gdb/testsuite/gdb.tui/secondary-prompt.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/single-key-2.exp b/gdb/testsuite/gdb.tui/single-key-2.exp index efaaf03..33a8b14 100644 --- a/gdb/testsuite/gdb.tui/single-key-2.exp +++ b/gdb/testsuite/gdb.tui/single-key-2.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/single-key.exp b/gdb/testsuite/gdb.tui/single-key.exp index f821941..a3887e0 100644 --- a/gdb/testsuite/gdb.tui/single-key.exp +++ b/gdb/testsuite/gdb.tui/single-key.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/small-term.exp b/gdb/testsuite/gdb.tui/small-term.exp index 9ed150e..0ff8027 100644 --- a/gdb/testsuite/gdb.tui/small-term.exp +++ b/gdb/testsuite/gdb.tui/small-term.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/source-search.c b/gdb/testsuite/gdb.tui/source-search.c new file mode 100644 index 0000000..2320c5c --- /dev/null +++ b/gdb/testsuite/gdb.tui/source-search.c @@ -0,0 +1,127 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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/>. */ + +int +main (void) +{ + /* Line 21 */ + /* Line 22 */ + /* Line 23 */ + /* Line 24 */ + /* Line 25 */ + /* Line 26 */ + /* Line 27 */ + /* Line 28 */ + /* Line 29 */ + /* Line 30 */ + /* Line 31 */ + /* Line 32 */ + /* Line 33 */ + /* Line 34 */ + /* Line 35 */ + /* Line 36 */ + /* Line 37 */ + /* Line 38 */ + /* Line 39 */ + /* Line 40 */ + /* Line 41 */ + /* Line 42 */ + /* Line 43 */ + /* Line 44 */ + /* Line 45 */ + /* Line 46 */ + /* Line 47 */ + /* Line 48 */ + /* Line 49 */ + /* Line 50 */ + /* Line 51 */ + /* Line 52 */ + /* Line 53 */ + /* Line 54 */ + /* Line 55 */ + /* Line 56 */ + /* Line 57 */ + /* Line 58 */ + /* Line 59 */ + /* Line 60 */ + /* Line 61 */ + /* Line 62 */ + /* Line 63 */ + /* Line 64 */ + /* Line 65 */ + /* Line 66 */ + /* Line 67 */ + /* Line 68 */ + /* Line 69 */ + /* Line 70 */ + /* Line 71 */ + /* Line 72 */ + /* Line 73 */ + /* Line 74 */ + /* Line 75 */ + /* Line 76 */ + /* Line 77 */ + /* Line 78 */ + /* Line 79 */ + /* Line 80 */ + /* Line 81 */ + /* Line 82 */ + /* Line 83 */ + /* Line 84 */ + /* Line 85 */ + /* Line 86 */ + /* Line 87 */ + /* Line 88 */ + /* Line 89 */ + /* Line 90 */ + /* Line 91 */ + /* Line 92 */ + /* Line 93 */ + /* Line 94 */ + /* Line 95 */ + /* Line 96 */ + /* Line 97 */ + /* Line 98 */ + /* Line 99 */ + /* Line 100 */ + /* Line 101 */ + /* Line 102 */ + /* Line 103 */ + /* Line 104 */ + /* Line 105 */ + /* Line 106 */ + /* Line 107 */ + /* Line 108 */ + /* Line 109 */ + /* Line 110 */ + /* Line 111 */ + /* Line 112 */ + /* Line 113 */ + /* Line 114 */ + /* Line 115 */ + /* Line 116 */ + /* Line 117 */ + /* Line 118 */ + /* Line 119 */ + /* Line 120 */ + /* Line 121 */ + /* Line 122 */ + /* Line 123 */ + /* Line 124 */ + /* Line 125 */ + return 0; +} /* Last line. */ diff --git a/gdb/testsuite/gdb.tui/source-search.exp b/gdb/testsuite/gdb.tui/source-search.exp new file mode 100644 index 0000000..4fcdca3 --- /dev/null +++ b/gdb/testsuite/gdb.tui/source-search.exp @@ -0,0 +1,72 @@ +# 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 forward-search and reverse-search within the TUI src window. + +tuiterm_env + +standard_testfile .c + +if {[build_executable "failed to build" ${testfile} ${srcfile}] == -1} { + return +} + +Term::clean_restart 24 80 $testfile +if {![Term::enter_tui]} { + unsupported "TUI not supported" + return +} + +proc check_src_window { testname first_line } { + set last_line [expr {$first_line + 12}] + Term::check_box_contents $testname 0 0 80 15 \ + "^\\s+${first_line}\\s+.*\\s+${last_line}\\s+/\\* Line ${last_line} \\*/\\s+$" + +} + +# Initialise the src window so that it is displaying known contents. +# Check that the expected contents are displayed. +Term::command "list 20" +set first_line 15 +check_src_window "initial src contents" $first_line + +# Search forward. Searches are from the last line displayed, so this +# will move the next source line onto the screen each time. +for { set i 1 } { $i < 4 } { incr i } { + incr first_line + Term::command "forward-search Line" + check_src_window "src windows after forward-search $i" $first_line +} + +# Reverse search. Like forward-search, but move backward through the +# source. +for { set i 1 } { $i < 3 } { incr i } { + incr first_line -1 + Term::command "reverse-search Line" + check_src_window "src windows after reverse-search $i" $first_line +} + +# Until there are no matching lines left. +Term::command "reverse-search Line" +gdb_assert {[regexp -- "^Expression not found\\s+$" [Term::get_line 22]]} \ + "check start of source was reached" + +Term::command "forward-search Last line" +Term::check_box_contents "forward-search to end of file" 0 0 80 15 \ + "^\\s+122\\s+.*/\\* Last line\\. \\*/\\s+$" + +Term::command "reverse-search This testcase is part" +Term::check_box_contents "reverse-search to start of file" 0 0 80 15 \ + "^\\s+1\\s+.*\\s+13\\s+GNU General Public License for more details\\.\\s+$" diff --git a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.c b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.c index 514abf5..74b03eb 100644 --- a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.c +++ b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2016-2024 Free Software Foundation, Inc. + Copyright 2016-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 diff --git a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp index e0ed682..7a9841f 100644 --- a/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp +++ b/gdb/testsuite/gdb.tui/tui-disasm-long-lines.exp @@ -1,4 +1,4 @@ -# Copyright 2010-2024 Free Software Foundation, Inc. +# Copyright 2010-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 @@ -35,7 +35,7 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "$binfile" \ } } -Term::clean_restart 24 80 $binfile +Term::clean_restart 24 80 $testfile if {![Term::prepare_for_tui]} { unsupported "TUI not supported" return diff --git a/gdb/testsuite/gdb.tui/tui-disasm-styling.exp b/gdb/testsuite/gdb.tui/tui-disasm-styling.exp index 513d787..6859744 100644 --- a/gdb/testsuite/gdb.tui/tui-disasm-styling.exp +++ b/gdb/testsuite/gdb.tui/tui-disasm-styling.exp @@ -37,12 +37,15 @@ proc check_asm_output { expect_styled testname } { $testname } -Term::clean_restart 24 80 $binfile +Term::clean_restart 24 80 $testfile if {![Term::enter_tui]} { unsupported "TUI not supported" return } +# Proc enter_tui switches off styling, re-enable it. +Term::command "set style enabled on" + Term::command "layout asm" Term::check_box "asm box" 0 0 80 15 diff --git a/gdb/testsuite/gdb.tui/tui-focus.c b/gdb/testsuite/gdb.tui/tui-focus.c index cb8b860..4caa75a 100644 --- a/gdb/testsuite/gdb.tui/tui-focus.c +++ b/gdb/testsuite/gdb.tui/tui-focus.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2023-2024 Free Software Foundation, Inc. + Copyright 2023-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 diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp index 2377ce2..50a3315 100644 --- a/gdb/testsuite/gdb.tui/tui-focus.exp +++ b/gdb/testsuite/gdb.tui/tui-focus.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 @@ -36,7 +36,7 @@ foreach spec {{src true} {cmd true} {status true} {regs false} \ lassign $spec window valid_p with_test_prefix "window=$window" { - Term::clean_restart 24 80 $binfile + Term::clean_restart 24 80 $testfile if {![Term::prepare_for_tui]} { unsupported "TUI not supported" return @@ -73,9 +73,9 @@ 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 +Term::clean_restart 24 80 $testfile if {[allow_python_tests]} { # Create a very simple tui window. gdb_py_test_silent_cmd \ diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.S b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.S index bbca380..6e36152 100644 --- a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.S +++ b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.S @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2020-2024 Free Software Foundation, Inc. + Copyright 2020-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 @@ -20,8 +20,11 @@ _start: .rept 5 nop .endr + +#ifndef __CYGWIN__ #ifdef __arm__ .section .note.GNU-stack,"",%progbits #else .section .note.GNU-stack,"",@progbits #endif +#endif 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 09afa5c..e21914b 100644 --- a/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp +++ b/gdb/testsuite/gdb.tui/tui-layout-asm-short-prog.exp @@ -1,4 +1,4 @@ -# Copyright 2020-2024 Free Software Foundation, Inc. +# Copyright 2020-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 @@ -20,9 +20,13 @@ tuiterm_env standard_testfile tui-layout-asm-short-prog.S -if {[build_executable "failed to prepare" ${testfile} ${srcfile} \ - {debug additional_flags=-nostdlib \ - additional_flags=-nostartfiles}] == -1} { +set opts {} +lappend opts debug +lappend opts additional_flags=-static +lappend opts additional_flags=-nostdlib +lappend opts ldflags=-nostartfiles + +if { [build_executable "failed to prepare" $testfile $srcfile $opts] == -1 } { return -1 } @@ -53,7 +57,7 @@ gdb_assert { [string match "|___0x*" $first_line] } \ # Scroll forward a large amount, this should take us to the last # instruction in the program. -Term::command "+ 13" +Term::command "+ 15" Term::check_box_contents "check asm box contents again" 0 0 80 15 \ [multi_line \ "^___$hex\[^\r\n\]+" \ @@ -61,6 +65,6 @@ Term::check_box_contents "check asm box contents again" 0 0 80 15 \ # Now scroll backward again, we should return to the start of the # program. -Term::command "- 13" +Term::command "- 15" gdb_assert {[string eq "$first_line" [Term::get_line 1]]} \ "check first line is back" diff --git a/gdb/testsuite/gdb.tui/tui-layout-asm.exp b/gdb/testsuite/gdb.tui/tui-layout-asm.exp index 91566ca..333276e 100644 --- a/gdb/testsuite/gdb.tui/tui-layout-asm.exp +++ b/gdb/testsuite/gdb.tui/tui-layout-asm.exp @@ -1,4 +1,4 @@ -# Copyright 2020-2024 Free Software Foundation, Inc. +# Copyright 2020-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 @@ -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/tui-layout.c b/gdb/testsuite/gdb.tui/tui-layout.c index 83d59d7..c69fe32 100644 --- a/gdb/testsuite/gdb.tui/tui-layout.c +++ b/gdb/testsuite/gdb.tui/tui-layout.c @@ -1,6 +1,6 @@ /* This testcase is part of GDB, the GNU debugger. - Copyright 2017-2024 Free Software Foundation, Inc. + Copyright 2017-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 diff --git a/gdb/testsuite/gdb.tui/tui-layout.exp b/gdb/testsuite/gdb.tui/tui-layout.exp index 1c682b9..f604871 100644 --- a/gdb/testsuite/gdb.tui/tui-layout.exp +++ b/gdb/testsuite/gdb.tui/tui-layout.exp @@ -1,4 +1,4 @@ -# Copyright 2017-2024 Free Software Foundation, Inc. +# Copyright 2017-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 @@ -40,7 +40,7 @@ if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { # happens to be in after a call to clean_restart. proc test_layout_or_focus {layout_name terminal execution} { - global binfile gdb_prompt + global gdb_prompt set dumb_terminal [string equal $terminal "dumb"] @@ -48,9 +48,9 @@ proc test_layout_or_focus {layout_name terminal execution} { save_vars { env(TERM) } { setenv TERM $terminal if {$dumb_terminal} { - clean_restart $binfile + clean_restart $::testfile } else { - Term::clean_restart 24 80 $binfile + Term::clean_restart 24 80 $::testfile if {![Term::prepare_for_tui]} { unsupported "TUI not supported" return diff --git a/gdb/testsuite/gdb.tui/tui-long-line.c b/gdb/testsuite/gdb.tui/tui-long-line.c new file mode 100644 index 0000000..8f1d6eb --- /dev/null +++ b/gdb/testsuite/gdb.tui/tui-long-line.c @@ -0,0 +1,24 @@ +/* This testcase is part of GDB, the GNU debugger. + + 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/>. */ + + +int +main (void) +{ + /* This is a comment that is meant to be longer than the usual 80 characters width of a tuiterm. */ + return 0; +} diff --git a/gdb/testsuite/gdb.tui/tui-missing-src.exp b/gdb/testsuite/gdb.tui/tui-missing-src.exp index 2310c1d..ae98775 100644 --- a/gdb/testsuite/gdb.tui/tui-missing-src.exp +++ b/gdb/testsuite/gdb.tui/tui-missing-src.exp @@ -1,4 +1,4 @@ -# Copyright 2020-2024 Free Software Foundation, Inc. +# Copyright 2020-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 @@ -27,6 +27,7 @@ # Check if start command is supported. require !use_gdb_stub +require allow_tui_tests tuiterm_env @@ -64,10 +65,8 @@ f2 (int x) close $fd # Step 3: Compile the source files. -if { [gdb_compile "${srcfiles}" "${binfile}" \ - executable {debug additional_flags=-O0}] != "" } { - untested "failed to compile" - return -1 +if { [build_executable "failed to prepare" $testfile $srcfiles] == -1 } { + return } # Step 4: Remove the main.c file. diff --git a/gdb/testsuite/gdb.tui/tui-mode-switch.exp b/gdb/testsuite/gdb.tui/tui-mode-switch.exp new file mode 100644 index 0000000..c605962 --- /dev/null +++ b/gdb/testsuite/gdb.tui/tui-mode-switch.exp @@ -0,0 +1,57 @@ +require allow_tui_tests + +tuiterm_env + +if { [ishost *-*-*bsd*] } { + # We need support for alternate screen, and xterm doesn't have it. + set term xterm-clear +} else { + set term xterm +} + +Term::with_term $term { + Term::clean_restart 12 40 +} + +if {![Term::prepare_for_tui]} { + unsupported "TUI not supported" + return 0 +} + +# Generate prompt. +Term::gen_prompt + +# Move to last line. +for { set i 1 } { $i <= 11 } { incr i } { + send_gdb "\n" + Term::wait_for "" +} + +# Type "foo". +send_gdb "foo" +set line { 0 11 40 1 } +gdb_assert { [Term::wait_for_region_contents {*}$line "^$gdb_prompt foo"] } \ + "type foo" + +# Enter TUI. +send_gdb "\030\001" +gdb_assert { [Term::wait_for ""] } "enter TUI" + +# Exit TUI. +send_gdb "\030\001" +gdb_assert { [Term::wait_for ""] } "exit TUI" + +# Type b. +send_gdb "b" +gdb_assert { [Term::wait_for_region_contents {*}$line "^$gdb_prompt b"] } \ + "type b" + +# Check that we don't see "boo". +gdb_assert { ![Term::check_region_contents_p {*}$line "^$gdb_prompt boo"] } \ + "no boo" +Term::dump_screen + +# We need an empty prompt here, to deal with the "monitor exit" that +# native-extended-gdbserver will send. Send a backspace. +send_gdb "\010" +Term::wait_for "" diff --git a/gdb/testsuite/gdb.tui/tui-nl-filtered-output.exp b/gdb/testsuite/gdb.tui/tui-nl-filtered-output.exp index 52aa7ac..db11f60 100644 --- a/gdb/testsuite/gdb.tui/tui-nl-filtered-output.exp +++ b/gdb/testsuite/gdb.tui/tui-nl-filtered-output.exp @@ -1,4 +1,4 @@ -# Copyright 2017-2024 Free Software Foundation, Inc. +# Copyright 2017-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 diff --git a/gdb/testsuite/gdb.tui/tuiterm-2.exp b/gdb/testsuite/gdb.tui/tuiterm-2.exp index bf82958..9e3ddc7 100644 --- a/gdb/testsuite/gdb.tui/tuiterm-2.exp +++ b/gdb/testsuite/gdb.tui/tuiterm-2.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 @@ -106,6 +106,84 @@ with_override Term::accept_gdb_output test_accept_gdb_output { } gdb_assert { [Term::wait_for ""] } } + + with_test_prefix "Term::wait_for 2" { + Term::_setup 4 20 + set send_cnt 0 + set expect_send {} + set action_cnt 0 + set actions { + { + Term::_move_cursor 0 0 + + Term::_insert "${::border}(gdb) " + set pos $Term::_cur_col + + Term::_insert "foo" + + Term::_move_cursor 19 0 + Term::_insert "$::border" + + Term::_move_cursor $pos 0 + } + { + Term::_move_cursor 0 1 + + Term::_insert "${::border}(gdb) " + set pos $Term::_cur_col + + Term::_move_cursor 19 1 + Term::_insert "$::border" + + Term::_move_cursor $pos 1 + } + } + + # Wait for a prompt. + gdb_assert { [Term::wait_for ""] } + + # The first action sets the cursor after the prompt on the + # first line. The second action sets the cursor after the + # prompt on the second line. Check that wait_for returns + # after the second action, not the first. + gdb_assert { $Term::_cur_row == 1 } + } } } } + +proc_with_prefix unrecognized_escape_sequence {} { + if { [spawn $::srcdir/$::subdir/gdb.sh] == 0 } { + unsupported "cannot spawn gdb.sh" + return + } + switch_gdb_spawn_id $spawn_id + + Term::_setup 4 20 + + save_vars ::timeout { + set ::timeout 1 + + set line { 0 0 20 1 } + + # Parse "foo". + gdb_assert { [Term::wait_for_region_contents \ + {*}$line \ + [string_to_regexp "foo"]] } \ + "foo" + + # Parse "\033(%5". + gdb_assert { ![Term::accept_gdb_output 0] } \ + "fail to parse escape sequence" + gdb_assert { [Term::wait_for_region_contents \ + {*}$line \ + [string_to_regexp "^\[(%5"]] } \ + "echoed escape sequence" + } + Term::dump_screen + + close $spawn_id + clear_gdb_spawn_id +} + +unrecognized_escape_sequence diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp index cf87ee2..a91643e 100644 --- a/gdb/testsuite/gdb.tui/tuiterm.exp +++ b/gdb/testsuite/gdb.tui/tuiterm.exp @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 @@ -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 { } { @@ -620,13 +653,21 @@ proc test_cursor_backward_tabulation { } { } proc test_repeat { } { - Term::_move_cursor 2 1 - set Term::_last_char X + Term::_move_cursor 0 1 - Term::_csi_b 3 + Term::_insert "xxX" + gdb_assert { $Term::_last_char == "X" } + check "insert" { + "abcdefgh" + "xxXlmnop" + "qrstuvwx" + "yz01234 " + } 3 1 + + Term::_csi_b 2 check "repeat" { "abcdefgh" - "ijXXXnop" + "xxXXXnop" "qrstuvwx" "yz01234 " } 5 1 @@ -750,6 +791,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. @@ -757,7 +807,7 @@ proc test_attrs {} { proc run_one_test_small { test_proc_name } { save_vars { env(TERM) stty_init } { setup_small - eval $test_proc_name + $test_proc_name } } @@ -766,7 +816,7 @@ proc run_one_test_small { test_proc_name } { proc run_one_test_large { test_proc_name } { save_vars { env(TERM) stty_init } { setup_large - eval $test_proc_name + $test_proc_name } } diff --git a/gdb/testsuite/gdb.tui/winheight.exp b/gdb/testsuite/gdb.tui/winheight.exp index e06a934..38c7bcc 100644 --- a/gdb/testsuite/gdb.tui/winheight.exp +++ b/gdb/testsuite/gdb.tui/winheight.exp @@ -1,4 +1,4 @@ -# Copyright 2019-2024 Free Software Foundation, Inc. +# Copyright 2019-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 @@ -99,14 +99,14 @@ Term::check_box "check for asm window" 0 0 80 15 # The test then switches to the 'split' layout, and calculates the # expected window sizes. foreach_with_prefix cmd_size {20 12 5} { - set src_size_before [expr 24 - ${cmd_size} - 1] - set split_size [expr (24 - ${cmd_size}) / 2] + set src_size_before [expr {24 - ${cmd_size} - 1}] + set split_size [expr {(24 - ${cmd_size}) / 2}] if { $split_size < 3 } { # The minimum window size is 3, so force that. set src_size_after 3 set asm_size_after 3 - } elseif { [expr $split_size % 2] == 0 } { + } elseif { $split_size % 2 == 0 } { # The remaining space can be divided evenly between the two # windows. set src_size_after ${split_size} @@ -115,7 +115,7 @@ foreach_with_prefix cmd_size {20 12 5} { # The space can't be divided evenly, the asm window will get # the extra line. set src_size_after ${split_size} - set asm_size_after [expr ${split_size} + 1] + set asm_size_after [expr {${split_size} + 1}] } Term::command "layout src" @@ -125,5 +125,6 @@ foreach_with_prefix cmd_size {20 12 5} { # Both windows should be of equal size, which will be their minimum. Term::command "layout split" Term::check_box "check for src window in split" 0 0 80 ${src_size_after} - Term::check_box "check for asm window in split" 0 [expr ${src_size_after} - 1] 80 ${asm_size_after} + Term::check_box "check for asm window in split" \ + 0 [expr {${src_size_after} - 1}] 80 ${asm_size_after} } diff --git a/gdb/testsuite/gdb.tui/winwidth.exp b/gdb/testsuite/gdb.tui/winwidth.exp index 525e7ad..d9170d8 100644 --- a/gdb/testsuite/gdb.tui/winwidth.exp +++ b/gdb/testsuite/gdb.tui/winwidth.exp @@ -1,4 +1,4 @@ -# Copyright 2022-2024 Free Software Foundation, Inc. +# Copyright 2022-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 diff --git a/gdb/testsuite/gdb.tui/wrap-line.exp b/gdb/testsuite/gdb.tui/wrap-line.exp index d3020bf..ef166f7 100644 --- a/gdb/testsuite/gdb.tui/wrap-line.exp +++ b/gdb/testsuite/gdb.tui/wrap-line.exp @@ -1,4 +1,4 @@ -# Copyright 2023-2024 Free Software Foundation, Inc. +# Copyright 2023-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 @@ -37,11 +37,11 @@ proc fill_line { width } { # Take into account that the prompt also takes space. set prefix [string length "(gdb) "] - set start [expr $prefix + 1] + set start [expr {$prefix + 1}] # Print chars. for { set i $start } { $i <= $width } { incr i } { - set c [expr $i % 10] + set c [expr {$i % 10}] send_gdb $c append res $c } @@ -59,7 +59,7 @@ proc test_wrap { wrap_width tui } { set str [fill_line $wrap_width] # Remaining space on line. - set space [string repeat " " [expr $::cols - $wrap_width]] + set space [string repeat " " [expr {$::cols - $wrap_width}]] # Now print the first char we expect to wrap. send_gdb "W" @@ -104,29 +104,35 @@ proc test_wrap_cli_tui { auto_detected_width } { set re1 "Number of characters gdb thinks are in a line is ($::decimal)\\." set re2 \ "Number of characters readline reports are in a line is ($::decimal)\\." + set re3 \ + "Readline wrapping mode: (\[a-z\]+) \[\^\r\n]*" set cmd "maint info screen" set re \ [multi_line \ "^$re1" \ $re2 \ - ".*"] + ".*" \ + $re3] gdb_test_multiple $cmd "" { -re -wrap $re { set gdb_width $expect_out(1,string) set readline_width $expect_out(2,string) + set wrapping_mode $expect_out(3,string) pass $gdb_test_name } } - gdb_assert { $gdb_width == $::cols } "width" + if { $wrapping_mode == "readline" } { + gdb_assert { $gdb_width == $::cols } "width" - # TERM=ansi, so readline hides the last column. - gdb_assert { $gdb_width == [expr $readline_width + 1] } + # TERM=ansi, so readline hides the last column. + gdb_assert { $gdb_width == [expr $readline_width + 1] } - with_test_prefix cli { - set wrap_width $readline_width + with_test_prefix cli { + set wrap_width $readline_width - test_wrap $wrap_width 0 + test_wrap $wrap_width 0 + } } with_test_prefix tui { @@ -159,7 +165,7 @@ with_test_prefix width-hard-coded { } with_test_prefix width-auto-detected { - Term::with_tuiterm {*}$dims { + Term::with_tuiterm $lines $cols { save_vars { ::INTERNAL_GDBFLAGS } { # Avoid "set width 0" argument. set INTERNAL_GDBFLAGS \ @@ -172,7 +178,7 @@ with_test_prefix width-auto-detected { set test "startup prompt" gdb_test_multiple "" $test { - -re "^$gdb_prompt $" { + -re "^(\033\\\[6n)?$gdb_prompt $" { pass "$test" } } |