Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [pushed 0/7] [gdb/testsuite] Tuiterm maintenance
@ 2026-10-14 14:58 Tom de Vries
  2026-10-14 14:58 ` [pushed 1/7] [gdb/testsuite] Remove unused declarations in lib/tuiterm.exp Tom de Vries
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Tom de Vries @ 2026-10-14 14:58 UTC (permalink / raw)
  To: gdb-patches

A collection of patches fixing tuiterm related issues.

All the patches are trivial, apart from "Add Term::check_size", but because that
one is testsuite related, and the branch has been extensively reviewed using both
Claude Code and Gemini CLI, I'm pushing this.

Tested on x86_64-linux.

Tom de Vries (7):
  [gdb/testsuite] Remove unused declarations in lib/tuiterm.exp
  [gdb/testsuite] Factor out Term::_copy_line
  [gdb/testsuite] Factor out small_initial in gdb.tui/tuiterm.exp
  [gdb/testsuite] Add Term::check_size
  [gdb/testsuite] Work around namespace problem in tclint plugin
  [gdb/testsuite] Fix typo in tclint-plugin.py
  [gdb/testsuite] Fix test names in gdb.tui/tuiterm.exp

 gdb/testsuite/gdb.tui/tuiterm.exp | 301 +++++++++---------------------
 gdb/testsuite/lib/tuiterm.exp     | 151 +++++++++------
 gdb/testsuite/tclint-plugin.py    |   8 +-
 3 files changed, 194 insertions(+), 266 deletions(-)


base-commit: 692a398424b5468c17843b68faefa26169d961a1
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pushed 1/7] [gdb/testsuite] Remove unused declarations in lib/tuiterm.exp
  2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
@ 2026-10-14 14:58 ` Tom de Vries
  2026-10-14 14:58 ` [pushed 2/7] [gdb/testsuite] Factor out Term::_copy_line Tom de Vries
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2026-10-14 14:58 UTC (permalink / raw)
  To: gdb-patches

Remove unused declarations in the procs in lib/tuiterm.exp.
---
 gdb/testsuite/lib/tuiterm.exp | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 035cb04dda4..3ca961a3f7d 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -315,7 +315,6 @@ proc Term::_csi_F {args} {
     _log_cur "Cursor Previous Line ($arg)" {
 	variable _cur_col
 	variable _cur_row
-	variable _rows
 
 	set _cur_col 0
 	set _cur_row [expr {max ($_cur_row - $arg, 0)}]
@@ -427,7 +426,6 @@ proc Term::_csi_L {args} {
     set arg [_default [lindex $args 0] 1]
 
     _log_cur "Insert Line ($arg)" {
-	variable _cur_col
 	variable _cur_row
 	variable _rows
 	variable _cols
@@ -506,8 +504,6 @@ proc Term::_csi_S {args} {
     set count [_default [lindex $args 0] 1]
 
     _log_cur "Pan Down ($count)" {
-	variable _cur_col
-	variable _cur_row
 	variable _cols
 	variable _rows
 	variable _chars
@@ -540,8 +536,6 @@ proc Term::_csi_T {args} {
     set count [_default [lindex $args 0] 1]
 
     _log_cur "Pan Up ($count)" {
-	variable _cur_col
-	variable _cur_row
 	variable _cols
 	variable _rows
 	variable _chars
@@ -1610,7 +1604,6 @@ proc Term::get_region { x y width height sep { attrs false } } {
 # the contents within a box (though check_box_contents is a better
 # choice for boxes with a border).  Return 1 if check succeeded.
 proc Term::check_region_contents_p { x y width height regexp } {
-    variable _chars
     dump_box $x $y $width $height
 
     # Now grab the contents of the box, join each line together
@@ -1634,8 +1627,6 @@ proc Term::check_region_contents { test_name x y width height regexp } {
 # box where expected, if there is then the contents of the box are
 # matched against REGEXP.
 proc Term::check_box_contents {test_name x y width height regexp} {
-    variable _chars
-
     dump_box $x $y $width $height
     set why [_check_box $x $y $width $height]
     if {$why != ""} {
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pushed 2/7] [gdb/testsuite] Factor out Term::_copy_line
  2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
  2026-10-14 14:58 ` [pushed 1/7] [gdb/testsuite] Remove unused declarations in lib/tuiterm.exp Tom de Vries
@ 2026-10-14 14:58 ` Tom de Vries
  2026-10-14 14:58 ` [pushed 3/7] [gdb/testsuite] Factor out small_initial in gdb.tui/tuiterm.exp Tom de Vries
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2026-10-14 14:58 UTC (permalink / raw)
  To: gdb-patches

Factor out Term::_copy_line and use it in 5 locations.
---
 gdb/testsuite/lib/tuiterm.exp | 40 +++++++++++++----------------------
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 3ca961a3f7d..62025857651 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -138,13 +138,21 @@ proc Term::_ctl_0x08 { {bw -1} } {
     }
 }
 
+# Helper function.  Copy line FROM to TO.
+proc Term::_copy_line { from to } {
+    variable _cols
+    variable _chars
+
+    for {set x 0} {$x < $_cols} {incr x} {
+	set _chars($x,$to) $_chars($x,$from)
+    }
+}
+
 # Linefeed.
 proc Term::_ctl_0x0a {} {
     _log_cur "Line feed" {
 	variable _cur_row
 	variable _rows
-	variable _cols
-	variable _chars
 
 	incr _cur_row 1
 	while {$_cur_row >= $_rows} {
@@ -156,9 +164,7 @@ proc Term::_ctl_0x0a {} {
 	    # side.
 	    for {set y 0} {$y < [expr $_rows - 1]} {incr y} {
 		set next_y [expr $y + 1]
-		for {set x 0} {$x < $_cols} {incr x} {
-		    set _chars($x,$y) $_chars($x,$next_y)
-		}
+		_copy_line $next_y $y
 	    }
 
 	    incr _cur_row -1
@@ -428,15 +434,11 @@ proc Term::_csi_L {args} {
     _log_cur "Insert Line ($arg)" {
 	variable _cur_row
 	variable _rows
-	variable _cols
-	variable _chars
 
 	set y [expr $_rows - 2]
 	set next_y [expr $y + $arg]
 	while {$y >= $_cur_row} {
-	    for {set x 0} {$x < $_cols} {incr x} {
-		set _chars($x,$next_y) $_chars($x,$y)
-	    }
+	    _copy_line $y $next_y
 	    incr y -1
 	    incr next_y -1
 	}
@@ -454,15 +456,11 @@ proc Term::_csi_M {args} {
     _log_cur "Delete line ($count)" {
 	variable _cur_row
 	variable _rows
-	variable _cols
-	variable _chars
 
 	set y $_cur_row
 	set next_y [expr {$y + $count}]
 	while {$next_y < $_rows} {
-	    for {set x 0} {$x < $_cols} {incr x} {
-		set _chars($x,$y) $_chars($x,$next_y)
-	    }
+	    _copy_line $next_y $y
 	    incr y
 	    incr next_y
 	}
@@ -504,9 +502,7 @@ proc Term::_csi_S {args} {
     set count [_default [lindex $args 0] 1]
 
     _log_cur "Pan Down ($count)" {
-	variable _cols
 	variable _rows
-	variable _chars
 
 	# The following code is written without consideration for
 	# the scroll margins.  At this time this comment was
@@ -518,9 +514,7 @@ proc Term::_csi_S {args} {
 	set y $count
 
 	while {$y < $_rows} {
-	    for {set x 0} {$x < $_cols} {incr x} {
-		set _chars($x,$dy) $_chars($x,$y)
-	    }
+	    _copy_line $y $dy
 	    incr y 1
 	    incr dy 1
 	}
@@ -536,9 +530,7 @@ proc Term::_csi_T {args} {
     set count [_default [lindex $args 0] 1]
 
     _log_cur "Pan Up ($count)" {
-	variable _cols
 	variable _rows
-	variable _chars
 
 	# The following code is written without consideration for
 	# the scroll margins.  At this time this comment was
@@ -550,9 +542,7 @@ proc Term::_csi_T {args} {
 	set dy $_rows
 
 	while {$dy >= $count} {
-	    for {set x 0} {$x < $_cols} {incr x} {
-		set _chars($x,$dy) $_chars($x,$y)
-	    }
+	    _copy_line $y $dy
 	    incr y -1
 	    incr dy -1
 	}
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pushed 3/7] [gdb/testsuite] Factor out small_initial in gdb.tui/tuiterm.exp
  2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
  2026-10-14 14:58 ` [pushed 1/7] [gdb/testsuite] Remove unused declarations in lib/tuiterm.exp Tom de Vries
  2026-10-14 14:58 ` [pushed 2/7] [gdb/testsuite] Factor out Term::_copy_line Tom de Vries
@ 2026-10-14 14:58 ` Tom de Vries
  2026-10-14 14:58 ` [pushed 4/7] [gdb/testsuite] Add Term::check_size Tom de Vries
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2026-10-14 14:58 UTC (permalink / raw)
  To: gdb-patches

There are many tests in gdb.tui/tuiterm.exp that check that the display hasn't
changed by comparing it to its initial state:
...
    check "backspace one" {
	"abcdefgh"
	"ijklmnop"
	"qrstuvwx"
	"yz01234 "
    } 0 2
...

Factor out a new variable small_initial, and use it 35 times.
---
 gdb/testsuite/gdb.tui/tuiterm.exp | 253 ++++++------------------------
 1 file changed, 45 insertions(+), 208 deletions(-)

diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp
index b6330b0d6a8..f09e1514e9b 100644
--- a/gdb/testsuite/gdb.tui/tuiterm.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm.exp
@@ -64,6 +64,14 @@ proc setup_terminal { cols rows } {
     }
 }
 
+# Variable that represents the state of the small terminal after setup_small.
+set small_initial {
+    "abcdefgh"
+    "ijklmnop"
+    "qrstuvwx"
+    "yz01234 "
+}
+
 # Most tests are fine with a small terminal.  This proc initializes the terminal
 # with 8 columns and 4 rows, with the following content:
 #
@@ -79,17 +87,11 @@ proc setup_terminal { cols rows } {
 proc setup_small {} {
     setup_terminal 8 4
 
-    Term::_insert "abcdefgh"
-    Term::_insert "ijklmnop"
-    Term::_insert "qrstuvwx"
-    Term::_insert "yz01234"
+    foreach line $::small_initial {
+	Term::_insert [string trim $line]
+    }
 
-    check "check after setup" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 7 3
+    check "check after setup" $::small_initial 7 3
 }
 
 # Some tests require a larger terminal.  This proc initializes the terminal with
@@ -108,41 +110,21 @@ proc test_backspace {} {
     Term::_move_cursor 1 2
 
     Term::_ctl_0x08 0
-    check "backspace one" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 2
+    check "backspace one" $::small_initial 0 2
 
     # Cursor should not move if it is already at column 0.
     Term::_ctl_0x08 0
-    check "backspace 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 2
+    check "backspace 2" $::small_initial 0 2
 
     # Cursor should wrap to previous line.
     Term::_ctl_0x08 1
-    check "backspace 3" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 7 1
+    check "backspace 3" $::small_initial 7 1
 }
 
 proc test_linefeed { } {
     Term::_move_cursor 1 2
     Term::_ctl_0x0a
-    check "linefeed" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 1 3
+    check "linefeed" $::small_initial 1 3
 }
 
 proc test_linefeed_scroll { } {
@@ -160,20 +142,10 @@ proc test_linefeed_scroll { } {
 proc test_carriage_return { } {
     Term::_move_cursor 1 2
     Term::_ctl_0x0d
-    check "carriage return 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 2
+    check "carriage return 1" $::small_initial 0 2
 
     Term::_ctl_0x0d
-    check "carriage return 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 2
+    check "carriage return 2" $::small_initial 0 2
 }
 
 proc test_insert_characters { } {
@@ -263,228 +235,108 @@ proc test_cursor_up { } {
     Term::_move_cursor 2 3
 
     Term::_csi_A
-    check "cursor up 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 2 2
+    check "cursor up 1" $::small_initial 2 2
 
     Term::_csi_A 2
-    check "cursor up 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 2 0
+    check "cursor up 2" $::small_initial 2 0
 
     Term::_csi_A 1
-    check "cursor up 3" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 2 0
+    check "cursor up 3" $::small_initial 2 0
 }
 
 proc test_cursor_down { } {
     Term::_move_cursor 1 0
 
     Term::_csi_B
-    check "cursor down 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 1 1
+    check "cursor down 1" $::small_initial 1 1
 
     Term::_csi_B 2
-    check "cursor down 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 1 3
+    check "cursor down 2" $::small_initial 1 3
 
     Term::_csi_B 1
-    check "cursor down 3" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 1 3
+    check "cursor down 3" $::small_initial 1 3
 }
 
 proc test_cursor_forward { } {
     Term::_move_cursor 0 1
 
     Term::_csi_C
-    check "cursor forward 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 1 1
+    check "cursor forward 1" $::small_initial 1 1
 
     Term::_csi_C 6
-    check "cursor forward 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 7 1
+    check "cursor forward 2" $::small_initial 7 1
 
     Term::_csi_C 1
-    check "cursor forward 3" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 7 1
+    check "cursor forward 3" $::small_initial 7 1
 }
 
 proc test_cursor_backward { } {
     Term::_move_cursor 7 1
 
     Term::_csi_D
-    check "cursor backward 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 6 1
+    check "cursor backward 1" $::small_initial 6 1
 
     Term::_csi_D 6
-    check "cursor backward 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 1
+    check "cursor backward 2" $::small_initial 0 1
 
     Term::_csi_D 1
-    check "cursor backward 3" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 1
+    check "cursor backward 3" $::small_initial 0 1
 }
 
 proc test_cursor_next_line { } {
     Term::_move_cursor 2 0
 
     Term::_csi_E
-    check "cursor next line 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 1
+    check "cursor next line 1" $::small_initial 0 1
 
     Term::_move_cursor 2 1
     Term::_csi_E 2
-    check "cursor next line 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 3
+    check "cursor next line 2" $::small_initial 0 3
 
     Term::_move_cursor 2 3
     Term::_csi_E 1
-    check "cursor next line 3" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 3
+    check "cursor next line 3" $::small_initial 0 3
 }
 
 proc test_cursor_previous_line { } {
     Term::_move_cursor 2 3
 
     Term::_csi_F
-    check "cursor previous line 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 2
+    check "cursor previous line 1" $::small_initial 0 2
 
     Term::_move_cursor 2 2
     Term::_csi_F 2
-    check "cursor previous line 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 0
+    check "cursor previous line 2" $::small_initial 0 0
 
     Term::_move_cursor 2 0
     Term::_csi_F 1
-    check "cursor previous line 3" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 0
+    check "cursor previous line 3" $::small_initial 0 0
 }
 
 proc test_horizontal_absolute { } {
     Term::_move_cursor 2 2
     Term::_csi_G
-    check "cursor horizontal absolute 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 2
+    check "cursor horizontal absolute 1" $::small_initial 0 2
 
     Term::_move_cursor 2 2
     Term::_csi_G 4
-    check "cursor horizontal absolute 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 3 2
+    check "cursor horizontal absolute 2" $::small_initial 3 2
 
     Term::_csi_G 8
-    check "cursor horizontal absolute 3" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 7 2
+    check "cursor horizontal absolute 3" $::small_initial 7 2
 
     Term::_csi_G 9
-    check "cursor horizontal absolute 4" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 7 2
+    check "cursor horizontal absolute 4" $::small_initial 7 2
 
     Term::_csi_`
-    check "horizontal position absolute 1" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 0 2
+    check "horizontal position absolute 1" $::small_initial 0 2
 }
 
 proc test_cursor_position { } {
     Term::_move_cursor 1 1
 
     Term::_csi_H 3 5
-    check "cursor horizontal absolute 2" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 4 2
+    check "cursor horizontal absolute 2" $::small_initial 4 2
 }
 
 proc test_cursor_horizontal_forward_tabulation { } {
@@ -682,28 +534,13 @@ proc test_vertical_line_position_absolute { } {
     Term::_move_cursor 2 1
 
     Term::_csi_d
-    check "default param" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 2 0
+    check "default param" $::small_initial 2 0
 
     Term::_csi_d 3
-    check "explicit param" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 2 2
+    check "explicit param" $::small_initial 2 2
 
     Term::_csi_d 100
-    check "try to move off-display" {
-	"abcdefgh"
-	"ijklmnop"
-	"qrstuvwx"
-	"yz01234 "
-    } 2 3
+    check "try to move off-display" $::small_initial 2 3
 }
 
 proc test_insert_line { } {
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pushed 4/7] [gdb/testsuite] Add Term::check_size
  2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
                   ` (2 preceding siblings ...)
  2026-10-14 14:58 ` [pushed 3/7] [gdb/testsuite] Factor out small_initial in gdb.tui/tuiterm.exp Tom de Vries
@ 2026-10-14 14:58 ` Tom de Vries
  2026-10-14 14:58 ` [pushed 5/7] [gdb/testsuite] Work around namespace problem in tclint plugin Tom de Vries
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2026-10-14 14:58 UTC (permalink / raw)
  To: gdb-patches

Add a proc Term::check_size that checks that tuiterm doesn't grow beyond its
dimensions, and that the cursor stays within bounds.

Use it in test-case gdb.tui/tuiterm.exp, and fix the fallout in
lib/tuiterm.exp.

Add a few more corner-case tests in gdb.tui/tuiterm.exp, and fix those as
well.

Also replace an "unset _chars" with "array unset _chars" to make
Term::_do_resize more robust.
---
 gdb/testsuite/gdb.tui/tuiterm.exp | 42 ++++++++++++++++++
 gdb/testsuite/lib/tuiterm.exp     | 72 ++++++++++++++++++++++++++++---
 2 files changed, 109 insertions(+), 5 deletions(-)

diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp
index f09e1514e9b..411026457b9 100644
--- a/gdb/testsuite/gdb.tui/tuiterm.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm.exp
@@ -337,6 +337,15 @@ proc test_cursor_position { } {
 
     Term::_csi_H 3 5
     check "cursor horizontal absolute 2" $::small_initial 4 2
+
+    Term::_csi_H 10 10
+    check "cursor position absolute, out of bounds" $::small_initial 7 3
+
+    Term::_csi_H
+    check "cursor position absolute, default" $::small_initial 0 0
+
+    Term::_csi_H 0 0
+    check "cursor position absolute, zero" $::small_initial 0 0
 }
 
 proc test_cursor_horizontal_forward_tabulation { } {
@@ -494,6 +503,15 @@ proc test_erase_character { } {
 	"qrs uvwx"
 	"y    34 "
     } 1 3
+
+    Term::_move_cursor 1 0
+    Term::_csi_X 20
+    check "erase character, more than number of columns" {
+	"a       "
+	"ijklmnop"
+	"qrs uvwx"
+	"y    34 "
+    } 1 0
 }
 
 proc test_cursor_backward_tabulation { } {
@@ -571,6 +589,18 @@ proc test_insert_line { } {
     } 2 0
 }
 
+proc test_insert_line_2 { } {
+    # As in test_insert_line, but start after row 0.
+    Term::_move_cursor 0 1
+    Term::_csi_L 12
+    check "insert line after first line, insert more lines than display has" {
+	"abcdefgh"
+	"        "
+	"        "
+	"        "
+    } 0 1
+}
+
 proc test_attrs {} {
     foreach { attr vals } {
 	reverse {
@@ -682,11 +712,20 @@ proc_with_prefix test_with_tuiterm {} {
     }
 }
 
+proc_with_prefix test_resize {} {
+    setup_terminal 8 4
+    Term::_move_cursor 7 3
+    Term::_do_resize 2 4
+    check_cursor_position "cursor after resize" 3 1
+    Term::check_size
+}
+
 # Run proc TEST_PROC_NAME with a "small" terminal.
 
 proc run_one_test_small { test_proc_name } {
     setup_small
     $test_proc_name
+    Term::check_size
 }
 
 # Run proc TEST_PROC_NAME with a "large" terminal.
@@ -694,6 +733,7 @@ proc run_one_test_small { test_proc_name } {
 proc run_one_test_large { test_proc_name } {
     setup_large
     $test_proc_name
+    Term::check_size
 }
 
 foreach_with_prefix test {
@@ -718,6 +758,7 @@ foreach_with_prefix test {
     test_repeat
     test_vertical_line_position_absolute
     test_insert_line
+    test_insert_line_2
     test_pan_up
     test_pan_down
 } {
@@ -735,3 +776,4 @@ test_attrs
 
 test_with_term
 test_with_tuiterm
+test_resize
diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 62025857651..71682785eea 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -222,6 +222,8 @@ proc Term::_csi_@ {args} {
 	variable _cols
 	variable _chars
 
+	set n [expr {min($n, $_cols - $_cur_col)}]
+
 	# Move characters right of the cursor right by N positions,
 	# starting with the rightmost one.
 	for {set in_col [expr $_cols - $n - 1]} {$in_col >= $_cur_col} {incr in_col -1} {
@@ -351,6 +353,13 @@ proc Term::_csi_H {args} {
     _log_cur "Cursor Position ($row, $col)" {
 	variable _cur_col
 	variable _cur_row
+	variable _rows
+	variable _cols
+
+	set row [expr {min($row, $_rows)}]
+	set col [expr {min($col, $_cols)}]
+	set row [expr {max($row, 1)}]
+	set col [expr {max($col, 1)}]
 
 	set _cur_row [expr {$row - 1}]
 	set _cur_col [expr {$col - 1}]
@@ -425,6 +434,45 @@ proc Term::_csi_K {args} {
     }
 }
 
+# Check that the tuiterm doesn't grow beyond its dimensions, and that the
+# cursor stays in bounds.
+proc Term::check_size {} {
+    variable _chars
+    variable _cols
+    variable _rows
+    variable _cur_col
+    variable _cur_row
+
+    if { ![array exists _chars] } {
+	# Not set up yet.
+	return
+    }
+
+    if { ! ($_cur_row >= 0 && $_cur_col >= 0
+	    && $_cur_row < $_rows && $_cur_col < $_cols) } {
+	set pos "($_cur_row, $_cur_col)"
+	set dims "($_rows, $_cols)"
+	error "cursor out of bounds: $pos in $dims"
+    }
+
+    if {[array size _chars] != $_rows * $_cols} {
+	verbose -log "size: [array size _chars]"
+	verbose -log "rows: $_rows"
+	verbose -log "cols: $_cols"
+	verbose -log "rows * cols: [expr {$_cols * $_rows}]"
+	foreach elem [array names _chars] {
+	    set res [split $elem ,]
+	    set col [lindex $res 0]
+	    set row [lindex $res 1]
+	    if { !($row >= 0 && $col >= 0
+		   && $row < $_rows && $col < $_cols) } {
+		verbose -log "$elem"
+	    }
+	}
+	error "_chars has incorrect size"
+    }
+}
+
 # Insert Line
 #
 # https://vt100.net/docs/vt510-rm/IL.html
@@ -435,8 +483,10 @@ proc Term::_csi_L {args} {
 	variable _cur_row
 	variable _rows
 
-	set y [expr $_rows - 2]
-	set next_y [expr $y + $arg]
+	set arg [expr {min($arg, $_rows - $_cur_row)}]
+
+	set y [expr {$_rows - $arg - 1}]
+	set next_y [expr {$_rows - 1}]
 	while {$y >= $_cur_row} {
 	    _copy_line $y $next_y
 	    incr y -1
@@ -532,14 +582,16 @@ proc Term::_csi_T {args} {
     _log_cur "Pan Up ($count)" {
 	variable _rows
 
+	set count [expr {min($count, $_rows)}]
+
 	# The following code is written without consideration for
 	# the scroll margins.  At this time this comment was
 	# written the tuiterm library doesn't support the scroll
 	# margins.  If/when that changes, then the following will
 	# need to be updated.
 
-	set y [expr $_rows - $count]
-	set dy $_rows
+	set y [expr {$_rows - $count - 1}]
+	set dy [expr {$_rows - 1}]
 
 	while {$dy >= $count} {
 	    _copy_line $y $dy
@@ -563,6 +615,9 @@ proc Term::_csi_X {args} {
 	variable _cur_row
 	variable _attrs
 	variable _chars
+	variable _cols
+
+	set n [expr {min($n, $_cols - $_cur_col)}]
 
 	set lattr [array get _attrs]
 	set x $_cur_col
@@ -977,6 +1032,7 @@ proc Term::_setup {rows cols} {
     variable _cur_row
     variable _attrs
     variable _resize_count
+    variable _chars
 
     set _rows $rows
     set _cols $cols
@@ -985,6 +1041,7 @@ proc Term::_setup {rows cols} {
     set _resize_count 0
     _reset_attrs _attrs
 
+    array unset _chars
     _clear_lines 0 $_rows
 }
 
@@ -1668,13 +1725,15 @@ proc Term::_do_resize {rows cols} {
     variable _chars
     variable _rows
     variable _cols
+    variable _cur_row
+    variable _cur_col
 
     set old_rows [expr {min ($_rows, $rows)}]
     set old_cols [expr {min ($_cols, $cols)}]
 
     # Copy locally.
     array set local_chars [array get _chars]
-    unset _chars
+    array unset _chars
 
     set _rows $rows
     set _cols $cols
@@ -1685,6 +1744,9 @@ proc Term::_do_resize {rows cols} {
 	    set _chars($x,$y) $local_chars($x,$y)
 	}
     }
+
+    set _cur_row [expr {min($_cur_row, $_rows - 1)}]
+    set _cur_col [expr {min($_cur_col, $_cols - 1)}]
 }
 
 proc Term::resize {rows cols {wait_for_msg 1}} {
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pushed 5/7] [gdb/testsuite] Work around namespace problem in tclint plugin
  2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
                   ` (3 preceding siblings ...)
  2026-10-14 14:58 ` [pushed 4/7] [gdb/testsuite] Add Term::check_size Tom de Vries
@ 2026-10-14 14:58 ` Tom de Vries
  2026-10-14 14:58 ` [pushed 6/7] [gdb/testsuite] Fix typo in tclint-plugin.py Tom de Vries
  2026-10-14 14:58 ` [pushed 7/7] [gdb/testsuite] Fix test names in gdb.tui/tuiterm.exp Tom de Vries
  6 siblings, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2026-10-14 14:58 UTC (permalink / raw)
  To: gdb-patches

I noticed that tclint checks don't work in Term::_log_cur uses in tuiterm
procs.

The problem is that while calls using Term::_log_cur are checked, the ones
using plain _log_cur aren't.

I've filed a tclint issue about this [1].

Work around this in the tclint plugin, and fix the fallout in lib/tuiterm.exp.

[1] https://github.com/nmoroze/tclint/issues/174
---
 gdb/testsuite/lib/tuiterm.exp  | 30 +++++++++++++++---------------
 gdb/testsuite/tclint-plugin.py |  6 ++++++
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 71682785eea..6140d32872f 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -133,7 +133,7 @@ proc Term::_ctl_0x08 { {bw -1} } {
 	}
 
 	# Wrap to previous line.
-	set _cur_col [expr $_cols - 1]
+	set _cur_col [expr {$_cols - 1}]
 	incr _cur_row -1
     }
 }
@@ -162,8 +162,8 @@ proc Term::_ctl_0x0a {} {
 	    # cursor back on the screen.  But we wrap the
 	    # scrolling inside a while loop just to be on the safe
 	    # side.
-	    for {set y 0} {$y < [expr $_rows - 1]} {incr y} {
-		set next_y [expr $y + 1]
+	    for {set y 0} {$y < $_rows - 1} {incr y} {
+		set next_y [expr {$y + 1}]
 		_copy_line $next_y $y
 	    }
 
@@ -226,13 +226,13 @@ proc Term::_csi_@ {args} {
 
 	# Move characters right of the cursor right by N positions,
 	# starting with the rightmost one.
-	for {set in_col [expr $_cols - $n - 1]} {$in_col >= $_cur_col} {incr in_col -1} {
-	    set out_col [expr $in_col + $n]
+	for {set in_col [expr {$_cols - $n - 1}]} {$in_col >= $_cur_col} {incr in_col -1} {
+	    set out_col [expr {$in_col + $n}]
 	    set _chars($out_col,$_cur_row) $_chars($in_col,$_cur_row)
 	}
 
 	# Write N blank spaces starting from the cursor.
-	_clear_in_line $_cur_col [expr $_cur_col + $n] $_cur_row
+	_clear_in_line $_cur_col [expr {$_cur_col + $n}] $_cur_row
     }
 }
 
@@ -339,7 +339,7 @@ proc Term::_csi_G {args} {
 	variable _cur_col
 	variable _cols
 
-	set _cur_col [expr {min ($arg, $_cols)} - 1]
+	set _cur_col [expr {min ($arg, $_cols) - 1}]
     }
 }
 
@@ -402,7 +402,7 @@ proc Term::_csi_J {args} {
 	} elseif {$arg == 1} {
 	    # Beginning of display to cursor (inclusive).
 	    _clear_lines 0 $_cur_row
-	    _clear_in_line 0 [expr $_cur_col + 1] $_cur_row
+	    _clear_in_line 0 [expr {$_cur_col + 1}] $_cur_row
 	} elseif {$arg == 2} {
 	    # Entire display.
 	    _clear_lines 0 $_rows
@@ -426,7 +426,7 @@ proc Term::_csi_K {args} {
 	    _clear_in_line $_cur_col $_cols $_cur_row
 	} elseif {$arg == 1} {
 	    # Beginning of line to cursor (inclusive).
-	    _clear_in_line 0 [expr $_cur_col + 1] $_cur_row
+	    _clear_in_line 0 [expr {$_cur_col + 1}] $_cur_row
 	} elseif {$arg == 2} {
 	    # Entire line.
 	    _clear_in_line 0 $_cols $_cur_row
@@ -493,7 +493,7 @@ proc Term::_csi_L {args} {
 	    incr next_y -1
 	}
 
-	_clear_lines $_cur_row [expr $_cur_row + $arg]
+	_clear_lines $_cur_row [expr {$_cur_row + $arg}]
     }
 }
 
@@ -531,8 +531,8 @@ proc Term::_csi_P {args} {
 	variable _cols
 
 	# Move all characters right of the cursor N positions left.
-	set out_col [expr $_cur_col]
-	set in_col [expr $_cur_col + $count]
+	set out_col $_cur_col
+	set in_col [expr {$_cur_col + $count}]
 
 	while {$in_col < $_cols} {
 	    set _chars($out_col,$_cur_row) $_chars($in_col,$_cur_row)
@@ -664,7 +664,7 @@ proc Term::_csi_d {args} {
 	variable _cur_row
 	variable _rows
 
-	set _cur_row [expr min ($row - 1, $_rows - 1)]
+	set _cur_row [expr {min ($row - 1, $_rows - 1)}]
     }
 }
 
@@ -886,13 +886,13 @@ proc Term::_csi_m {args} {
 		    set _attrs(invisible) 0
 		}
 		30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 {
-		    set _attrs(fg) [_color_attr [expr $item - 30]]
+		    set _attrs(fg) [_color_attr [expr {$item - 30}]]
 		}
 		39 {
 		    set _attrs(fg) default
 		}
 		40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 {
-		    set _attrs(bg) [_color_attr [expr $item - 40]]
+		    set _attrs(bg) [_color_attr [expr {$item - 40}]]
 		}
 		49 {
 		    set _attrs(bg) default
diff --git a/gdb/testsuite/tclint-plugin.py b/gdb/testsuite/tclint-plugin.py
index 5a09397c3a7..afe959dea3a 100644
--- a/gdb/testsuite/tclint-plugin.py
+++ b/gdb/testsuite/tclint-plugin.py
@@ -207,8 +207,14 @@ commands = commands_schema(
         "with_ansi_styling_terminal": _with_ansi_styling_terminal,
         "with_lock": _with_lock,
         "with_rocm_gpu_lock": _with_rocm_gpu_lock,
+        # Calls without explicit namespace prefix are not caught, so for now
+        # we add both.  This may clash with procs outside the namespace.
+        # https://github.com/nmoroze/tclint/issues/174
         "Term::_log_cur": _ns_term_log_cur,
+        "_log_cur": _ns_term_log_cur,
         "Term::with_term": _ns_term_with_term,
+        "with_term": _ns_term_with_term,
         "Term::with_tuiterm": _ns_term_with_tuiterm,
+        "with_tuiterm": _ns_term_with_tuiterm,
     }
 )
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pushed 6/7] [gdb/testsuite] Fix typo in tclint-plugin.py
  2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
                   ` (4 preceding siblings ...)
  2026-10-14 14:58 ` [pushed 5/7] [gdb/testsuite] Work around namespace problem in tclint plugin Tom de Vries
@ 2026-10-14 14:58 ` Tom de Vries
  2026-10-14 14:58 ` [pushed 7/7] [gdb/testsuite] Fix test names in gdb.tui/tuiterm.exp Tom de Vries
  6 siblings, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2026-10-14 14:58 UTC (permalink / raw)
  To: gdb-patches

An LLM review noticed a typo in tclint-plugin.py.  Fix it.
---
 gdb/testsuite/tclint-plugin.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/testsuite/tclint-plugin.py b/gdb/testsuite/tclint-plugin.py
index afe959dea3a..9ba7d10e89f 100644
--- a/gdb/testsuite/tclint-plugin.py
+++ b/gdb/testsuite/tclint-plugin.py
@@ -164,7 +164,7 @@ def _with_rocm_gpu_lock(args, parser):
 
 
 def _ns_term_log_cur(args, parser):
-    return _script_last_arg("Term::log_cur", 2, args, parser)
+    return _script_last_arg("Term::_log_cur", 2, args, parser)
 
 
 def _ns_term_with_term(args, parser):
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pushed 7/7] [gdb/testsuite] Fix test names in gdb.tui/tuiterm.exp
  2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
                   ` (5 preceding siblings ...)
  2026-10-14 14:58 ` [pushed 6/7] [gdb/testsuite] Fix typo in tclint-plugin.py Tom de Vries
@ 2026-10-14 14:58 ` Tom de Vries
  6 siblings, 0 replies; 8+ messages in thread
From: Tom de Vries @ 2026-10-14 14:58 UTC (permalink / raw)
  To: gdb-patches

I noticed an inaccurate test name in gdb.tui/tuiterm.exp.  I asked an LLM to
list locations of other occurrences, and then fixed them.
---
 gdb/testsuite/gdb.tui/tuiterm.exp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/testsuite/gdb.tui/tuiterm.exp b/gdb/testsuite/gdb.tui/tuiterm.exp
index 411026457b9..7c3aabaf6ea 100644
--- a/gdb/testsuite/gdb.tui/tuiterm.exp
+++ b/gdb/testsuite/gdb.tui/tuiterm.exp
@@ -207,7 +207,7 @@ proc test_pan_down { } {
 proc test_pan_up { } {
     Term::_move_cursor 1 2
     Term::_csi_T
-    check "pan down, default arg" {
+    check "pan up, default arg" {
 	"        "
 	"abcdefgh"
 	"ijklmnop"
@@ -215,7 +215,7 @@ proc test_pan_up { } {
     } 1 2
 
     Term::_csi_T 2
-    check "pan down, explicit arg" {
+    check "pan up, explicit arg" {
 	"        "
 	"        "
 	"        "
@@ -223,7 +223,7 @@ proc test_pan_up { } {
     } 1 2
 
     Term::_csi_T 100
-    check "pan down, excessive arg" {
+    check "pan up, excessive arg" {
 	"        "
 	"        "
 	"        "
@@ -336,7 +336,7 @@ proc test_cursor_position { } {
     Term::_move_cursor 1 1
 
     Term::_csi_H 3 5
-    check "cursor horizontal absolute 2" $::small_initial 4 2
+    check "cursor position absolute" $::small_initial 4 2
 
     Term::_csi_H 10 10
     check "cursor position absolute, out of bounds" $::small_initial 7 3
-- 
2.51.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-14 15:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-14 14:58 [pushed 0/7] [gdb/testsuite] Tuiterm maintenance Tom de Vries
2026-10-14 14:58 ` [pushed 1/7] [gdb/testsuite] Remove unused declarations in lib/tuiterm.exp Tom de Vries
2026-10-14 14:58 ` [pushed 2/7] [gdb/testsuite] Factor out Term::_copy_line Tom de Vries
2026-10-14 14:58 ` [pushed 3/7] [gdb/testsuite] Factor out small_initial in gdb.tui/tuiterm.exp Tom de Vries
2026-10-14 14:58 ` [pushed 4/7] [gdb/testsuite] Add Term::check_size Tom de Vries
2026-10-14 14:58 ` [pushed 5/7] [gdb/testsuite] Work around namespace problem in tclint plugin Tom de Vries
2026-10-14 14:58 ` [pushed 6/7] [gdb/testsuite] Fix typo in tclint-plugin.py Tom de Vries
2026-10-14 14:58 ` [pushed 7/7] [gdb/testsuite] Fix test names in gdb.tui/tuiterm.exp Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox