From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id D33453858D35 for ; Mon, 22 May 2023 10:03:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D33453858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E94601FDD4 for ; Mon, 22 May 2023 10:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1684749779; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/CHCxCmfAXqjGy1D0DobG6gnL6bSrsHSdnWq+Rpsar0=; b=fdWoft7JVJ57pR7x9Z7CeEkJAgoYBp5ta0MP+NIYCRXVUL1jc4/ZiieRmth14tMoA7aT82 76luPwpScMwaQ+pxZUU3qNLLu1ZrdyK6YTK9z39vEPQnlpW2uzYcWpjH0eMvUc8b5wsTZp MKHnvYELGJAdZyRWQfi/jk12TgsJ7r4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1684749779; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/CHCxCmfAXqjGy1D0DobG6gnL6bSrsHSdnWq+Rpsar0=; b=exHk8Ef6Bq4EEOZPVwIZDlZYmN61lt6GBQwV5rpVNaJ7Gin0xOmM6Fva6/IzX2vpE0xZtB ZDqUxHXxDVCqMdCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D82FE13776 for ; Mon, 22 May 2023 10:02:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OYa5M9M9a2TLBQAAMHmgww (envelope-from ) for ; Mon, 22 May 2023 10:02:59 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [pushed] [gdb/testsuite] Add Term::get_line_with_attrs Date: Mon, 22 May 2023 12:03:01 +0200 Message-Id: <20230522100301.4865-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Add a new proc Term::get_line_with_attrs, similar to Term::get_line, that annotates a tuiterm line with the active attributes. For instance, the line representing the TUI status window with attribute mode standout looks like this with Term::get_line: ... exec No process In: ... L?? PC: ?? ... but like this with Term::get_line_with_attrs: ... exec No process In: ... L?? PC: ?? ... Also add Term::dump_screen_with_attrs, a Term::dump_screen variant that uses Term::get_line_with_attrs instead of Term::get_line. Tested by re-running the TUI test-cases (gdb.tui/*.exp and gdb.python/tui*.exp) on x86_64-linux. --- gdb/testsuite/gdb.tui/basic.exp | 8 +++++ gdb/testsuite/lib/tuiterm.exp | 58 +++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/gdb/testsuite/gdb.tui/basic.exp b/gdb/testsuite/gdb.tui/basic.exp index ec1e9945e8f..2c55c2b95bc 100644 --- a/gdb/testsuite/gdb.tui/basic.exp +++ b/gdb/testsuite/gdb.tui/basic.exp @@ -106,3 +106,11 @@ Term::check_contents "split layout contents" \ Term::check_box "source box in split layout" 0 0 80 8 Term::check_box "asm box in split layout" 0 7 80 8 + +set re_noattr "\[^<\]" + +set status_window_line 15 + +set status [Term::get_line_with_attrs $status_window_line] +gdb_assert { [regexp "^$re_noattr*$" $status] == 1} \ + "status window: reverse" diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index 361fce83a79..5c0be85ee73 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -875,10 +875,25 @@ namespace eval Term { wait_for "^$str" } - # Return the text of screen line N, without attributes. Lines are - # 0-based. If C is given, stop before column C. Columns are also - # zero-based. - proc get_line {n {c ""}} { + # Apply the attribute list in ATTRS to attributes array UPVAR_NAME. + # Return a string annotating the changed attributes. + proc apply_attrs { upvar_name attrs } { + set res "" + upvar $upvar_name var + foreach { attr val } $attrs { + if { $var($attr) != $val } { + append res "<$attr:$val>" + set var($attr) $val + } + } + + return $res + } + + # Return the text of screen line N. Lines are 0-based. If C is given, + # stop before column C. Columns are also zero-based. If ATTRS, annotate + # with attributes. + proc get_line_1 {n c attrs} { variable _rows # This can happen during resizing, if the cursor seems to # temporarily be off-screen. @@ -891,13 +906,37 @@ namespace eval Term { variable _chars set c [_default $c $_cols] set x 0 + if { $attrs } { + _reset_attrs line_attrs + } while {$x < $c} { + if { $attrs } { + set char_attrs [lindex $_chars($x,$n) 1] + append result [apply_attrs line_attrs $char_attrs] + } append result [lindex $_chars($x,$n) 0] incr x } + if { $attrs } { + _reset_attrs zero_attrs + set char_attrs [array get zero_attrs] + append result [apply_attrs line_attrs $char_attrs] + } return $result } + # Return the text of screen line N, without attributes. Lines are + # 0-based. If C is given, stop before column C. Columns are also + # zero-based. + proc get_line {n {c ""} } { + return [get_line_1 $n $c 0] + } + + # As get_line, but annotate with attributes. + proc get_line_with_attrs {n {c ""}} { + return [get_line_1 $n $c 1] + } + # Get just the character at (X, Y). proc get_char {x y} { variable _chars @@ -1079,8 +1118,8 @@ namespace eval Term { } # A debugging function to dump the current screen, with line - # numbers. - proc dump_screen {} { + # numbers. If ATTRS, annotate with attributes. + proc dump_screen { {attrs 0} } { variable _rows variable _cols variable _cur_row @@ -1090,10 +1129,15 @@ namespace eval Term { for {set y 0} {$y < $_rows} {incr y} { set fmt [format %5d $y] - verbose -log "$fmt [get_line $y]" + verbose -log "$fmt [get_line_1 $y "" $attrs]" } } + # As dump_screen, but with attributes annotation. + proc dump_screen_with_attrs {} { + return [dump_screen 1] + } + # A debugging function to dump a box from the current screen, with line # numbers. proc dump_box { x y width height } { base-commit: a01399ff21e35422868c3853a31811c301a73883 -- 2.35.3