From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iUWRHhCZz2r8ZAkAWB0awg (envelope-from ) for ; Wed, 14 Oct 2026 11:00:32 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=z3gcG68o; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=RACGgoaQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=VMXHjzD7; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=86yfI9jE; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 6A2AD1E04E; Wed, 14 Oct 2026 11:00:32 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 508841E04E for ; Wed, 14 Oct 2026 11:00:31 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 84BD04BA23E1 for ; Wed, 14 Oct 2026 15:00:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84BD04BA23E1 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=z3gcG68o; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=RACGgoaQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=VMXHjzD7; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=86yfI9jE Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by sourceware.org (Postfix) with ESMTPS id B15B24BA23C1 for ; Wed, 14 Oct 2026 14:58:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B15B24BA23C1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B15B24BA23C1 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791989921; cv=none; b=atQ2Gw3iENopSn2dSmCDtXA9Fq28yX0jOl/RKqYJEDqrWe5ONFCr0XADF5bCbZrOXKelw/MjwtBhSYdLct5YISmgsth0zllkjbbaKX8aYhNOxNljWWcfU+gMHtVrRmEjO2wwIIMoOuXZIKDmkDMf3ExMyVZaC2SmJEemPPHP5tU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791989921; c=relaxed/simple; bh=d3Toym6Jfv3u81mCCfVBB6g+xJpNbyRToeIZKAuyqNo=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=gHGM8lJzP9y36wSYSRuJGM+CUTLz/ECETDJdQGfi+qfuRRWhc1MQRRjK9Ax41QORYjrSN6K0kg868OgKJb1jBeS5W0sRKJ0u3mB28kcLQRU5Wx/bkhhWruTlTXh9SMGMkZymX/l4DU/8m0XWg0BHIHMcBhSQHySYOA3FW6Qy7U4= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=z3gcG68o; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=RACGgoaQ; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=VMXHjzD7; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=86yfI9jE DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B15B24BA23C1 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9400E2224B for ; Wed, 14 Oct 2026 14:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1791989920; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Vy9FI/RR1hXrw2cmNfN3qov7QnXnqriCNcuNEbICTM=; b=z3gcG68oa5OOBUC2s7bnZEl1180gkRqpWNYv4j56YsLJBthMOQVfx0lzRyMYOuZ0evxHLL 5TysJoL0Gqm9D/kq3z5UAgG/ECehdNCNyTM2QJTzZ0bR/88Es9JqKUBBQmp+ter3VtmtGs hd/Hvb+AhV6Ak3xsKCqPUbIRsf4yOkM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1791989920; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Vy9FI/RR1hXrw2cmNfN3qov7QnXnqriCNcuNEbICTM=; b=RACGgoaQ9wg6EbIwKdnr48sjYOQ8l3pEKZImGpMYl/w2YzY5SBPtymjs3JSOVXP9vDKS/Q AK7gl/9IqSHDomAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1791989919; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Vy9FI/RR1hXrw2cmNfN3qov7QnXnqriCNcuNEbICTM=; b=VMXHjzD7AKpjXtGAB5QdL6/hcFqlGCRSg0UvnqAI3Vl/Vtcge4tqhUsLekmrgNeFTBoaNf liG7AOVNIqxONy/VseMTe6GysKSiMR6RY/aW990F3g73Bsbksfxk/rgz9O6NHzAyC7bfGl NWJvgB7NYyuGujvfx9bySOhzV3Wsnak= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1791989919; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8Vy9FI/RR1hXrw2cmNfN3qov7QnXnqriCNcuNEbICTM=; b=86yfI9jE629dIQBFv2Fg1LC/G4oLwS1BqmFPSo12TI+5Fm0caxZ+SlXXeYfE5ccUAvJ/tp pT1eHfGuMmGeYhDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 25F601368E for ; Wed, 14 Oct 2026 14:58:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 92gBHp6Yz2qpIgAAD6G6ig:T5 (envelope-from ) for ; Wed, 14 Oct 2026 14:58:39 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [pushed 4/7] [gdb/testsuite] Add Term::check_size Date: Wed, 14 Oct 2026 16:58:35 +0200 Message-ID: <20261014145838.3560108-5-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20261014145838.3560108-1-tdevries@suse.de> References: <20261014145838.3560108-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[vt100.net:url]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_TLS_ALL(0.00)[] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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