Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH][gdb/testsuite] Add Term::dump_box in lib/tuiterm.exp
Date: Tue, 5 Oct 2021 15:22:07 +0200	[thread overview]
Message-ID: <20211005132206.GA19271@delia> (raw)

Hi,

Factor out new proc Term::get_region and use it to implement a
new proc Term::dump_box, similar to Term::dump_screen.

Tested on x86_64-linux.

Any comments?

Thanks,
- Tom

[gdb/testsuite] Add Term::dump_box in lib/tuiterm.exp

---
 gdb/testsuite/lib/tuiterm.exp | 42 +++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp
index 222583f291f..a0197402b1f 100644
--- a/gdb/testsuite/lib/tuiterm.exp
+++ b/gdb/testsuite/lib/tuiterm.exp
@@ -772,28 +772,38 @@ namespace eval Term {
 	}
     }
 
-    # Check that the region of the screen described by X, Y, WIDTH,
-    # and HEIGHT match REGEXP.  This is like check_contents except
-    # only part of the screen is checked.  This can be used to check
-    # the contents within a box (though check_box_contents is a better
-    # choice for boxes with a border).
-    proc check_region_contents { test_name x y width height regexp } {
+    # Get the region of the screen described by X, Y, WIDTH,
+    # and HEIGHT, and separate the lines using SEP.
+    proc get_region { x y width height sep } {
 	variable _chars
 
-	# Now grab the contents of the box, join each line together
-	# with a '\r\n' sequence and match against REGEXP.
+	# Grab the contents of the box, join each line together
+	# using $sep.
 	set result ""
 	for {set yy $y} {$yy < [expr {$y + $height}]} {incr yy} {
 	    if {$yy > $y} {
 		# Add the end of line sequence only if this isn't the
 		# first line.
-		append result "\r\n"
+		append result $sep
 	    }
 	    for {set xx $x} {$xx < [expr {$x + $width}]} {incr xx} {
 		append result [lindex $_chars($xx,$yy) 0]
 	    }
 	}
+	return $result
+    }
+
+    # Check that the region of the screen described by X, Y, WIDTH,
+    # and HEIGHT match REGEXP.  This is like check_contents except
+    # only part of the screen is checked.  This can be used to check
+    # the contents within a box (though check_box_contents is a better
+    # choice for boxes with a border).
+    proc check_region_contents { test_name x y width height regexp } {
+	variable _chars
 
+	# Now grab the contents of the box, join each line together
+	# with a '\r\n' sequence and match against REGEXP.
+	set result [get_region $x $y $width $height "\r\n"]
 	if {![gdb_assert {[regexp -- $regexp $result]} $test_name]} {
 	    dump_screen
 	}
@@ -831,6 +841,20 @@ namespace eval Term {
 	}
     }
 
+    # A debugging function to dump a box from the current screen, with line
+    # numbers.
+    proc dump_box { x y width height } {
+	verbose -log "Box Dump ($width x $height) @ ($x, $y):"
+	set region [get_region $x $y $width $height "\n"]
+	set lines [split $region "\n"]
+	set nr $y
+	foreach line $lines {
+	    set fmt [format %5d $nr]
+	    verbose -log "$fmt $line"
+	    incr nr
+	}
+    }
+
     # Resize the terminal.
     proc _do_resize {rows cols} {
 	variable _chars

             reply	other threads:[~2021-10-05 13:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-05 13:22 Tom de Vries via Gdb-patches [this message]
2021-10-05 18:10 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211005132206.GA19271@delia \
    --to=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox