| 1 | # Copyright 2019-2020 Free Software Foundation, Inc. |
| 2 | |
| 3 | # This program is free software; you can redistribute it and/or modify |
| 4 | # it under the terms of the GNU General Public License as published by |
| 5 | # the Free Software Foundation; either version 3 of the License, or |
| 6 | # (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | # GNU General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public License |
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | # An ANSI terminal emulator for expect. |
| 17 | |
| 18 | # The expect "spawn" function puts the tty name into the spawn_out |
| 19 | # array; but dejagnu doesn't export this globally. So, we have to |
| 20 | # wrap spawn with our own function, so that we can capture this value. |
| 21 | # The value is later used in calls to stty. |
| 22 | rename spawn builtin_spawn |
| 23 | proc spawn {args} { |
| 24 | set result [uplevel builtin_spawn $args] |
| 25 | global gdb_spawn_name |
| 26 | upvar spawn_out spawn_out |
| 27 | set gdb_spawn_name $spawn_out(slave,name) |
| 28 | return $result |
| 29 | } |
| 30 | |
| 31 | namespace eval Term { |
| 32 | variable _rows |
| 33 | variable _cols |
| 34 | variable _chars |
| 35 | |
| 36 | variable _cur_x |
| 37 | variable _cur_y |
| 38 | |
| 39 | variable _attrs |
| 40 | |
| 41 | variable _last_char |
| 42 | |
| 43 | variable _resize_count |
| 44 | |
| 45 | # If ARG is empty, return DEF: otherwise ARG. This is useful for |
| 46 | # defaulting arguments in CSIs. |
| 47 | proc _default {arg def} { |
| 48 | if {$arg == ""} { |
| 49 | return $def |
| 50 | } |
| 51 | return $arg |
| 52 | } |
| 53 | |
| 54 | # Erase in the line Y from SX to just before EX. |
| 55 | proc _clear_in_line {sx ex y} { |
| 56 | variable _attrs |
| 57 | variable _chars |
| 58 | set lattr [array get _attrs] |
| 59 | while {$sx < $ex} { |
| 60 | set _chars($sx,$y) [list " " $lattr] |
| 61 | incr sx |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | # Erase the lines from SY to just before EY. |
| 66 | proc _clear_lines {sy ey} { |
| 67 | variable _cols |
| 68 | while {$sy < $ey} { |
| 69 | _clear_in_line 0 $_cols $sy |
| 70 | incr sy |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | # Beep. |
| 75 | proc _ctl_0x07 {} { |
| 76 | } |
| 77 | |
| 78 | # Backspace. |
| 79 | proc _ctl_0x08 {} { |
| 80 | variable _cur_x |
| 81 | incr _cur_x -1 |
| 82 | if {$_cur_x < 0} { |
| 83 | variable _cur_y |
| 84 | variable _cols |
| 85 | set _cur_x [expr {$_cols - 1}] |
| 86 | incr _cur_y -1 |
| 87 | if {$_cur_y < 0} { |
| 88 | set _cur_y 0 |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | # Linefeed. |
| 94 | proc _ctl_0x0a {} { |
| 95 | variable _cur_y |
| 96 | variable _rows |
| 97 | incr _cur_y 1 |
| 98 | if {$_cur_y >= $_rows} { |
| 99 | error "FIXME scroll" |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | # Carriage return. |
| 104 | proc _ctl_0x0d {} { |
| 105 | variable _cur_x |
| 106 | set _cur_x 0 |
| 107 | } |
| 108 | |
| 109 | # Make room for characters. |
| 110 | proc _csi_@ {args} { |
| 111 | set n [_default [lindex $args 0] 1] |
| 112 | variable _cur_x |
| 113 | variable _cur_y |
| 114 | variable _chars |
| 115 | set in_x $_cur_x |
| 116 | set out_x [expr {$_cur_x + $n}] |
| 117 | for {set i 0} {$i < $n} {incr i} { |
| 118 | set _chars($out_x,$_cur_y) $_chars($in_x,$_cur_y) |
| 119 | incr in_x |
| 120 | incr out_x |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | # Cursor Up. |
| 125 | proc _csi_A {args} { |
| 126 | variable _cur_y |
| 127 | set arg [_default [lindex $args 0] 1] |
| 128 | set _cur_y [expr {max ($_cur_y - $arg, 0)}] |
| 129 | } |
| 130 | |
| 131 | # Cursor Down. |
| 132 | proc _csi_B {args} { |
| 133 | variable _cur_y |
| 134 | variable _rows |
| 135 | set arg [_default [lindex $args 0] 1] |
| 136 | set _cur_y [expr {min ($_cur_y + $arg, $_rows)}] |
| 137 | } |
| 138 | |
| 139 | # Cursor Forward. |
| 140 | proc _csi_C {args} { |
| 141 | variable _cur_x |
| 142 | variable _cols |
| 143 | set arg [_default [lindex $args 0] 1] |
| 144 | set _cur_x [expr {min ($_cur_x + $arg, $_cols)}] |
| 145 | } |
| 146 | |
| 147 | # Cursor Back. |
| 148 | proc _csi_D {args} { |
| 149 | variable _cur_x |
| 150 | set arg [_default [lindex $args 0] 1] |
| 151 | set _cur_x [expr {max ($_cur_x - $arg, 0)}] |
| 152 | } |
| 153 | |
| 154 | # Cursor Next Line. |
| 155 | proc _csi_E {args} { |
| 156 | variable _cur_x |
| 157 | variable _cur_y |
| 158 | variable _rows |
| 159 | set arg [_default [lindex $args 0] 1] |
| 160 | set _cur_x 0 |
| 161 | set _cur_y [expr {min ($_cur_y + $arg, $_rows)}] |
| 162 | } |
| 163 | |
| 164 | # Cursor Previous Line. |
| 165 | proc _csi_F {args} { |
| 166 | variable _cur_x |
| 167 | variable _cur_y |
| 168 | variable _rows |
| 169 | set arg [_default [lindex $args 0] 1] |
| 170 | set _cur_x 0 |
| 171 | set _cur_y [expr {max ($_cur_y - $arg, 0)}] |
| 172 | } |
| 173 | |
| 174 | # Cursor Horizontal Absolute. |
| 175 | proc _csi_G {args} { |
| 176 | variable _cur_x |
| 177 | variable _cols |
| 178 | set arg [_default [lindex $args 0] 1] |
| 179 | set _cur_x [expr {min ($arg - 1, $_cols)}] |
| 180 | } |
| 181 | |
| 182 | # Move cursor (don't know the official name of this one). |
| 183 | proc _csi_H {args} { |
| 184 | variable _cur_x |
| 185 | variable _cur_y |
| 186 | set _cur_y [expr {[_default [lindex $args 0] 1] - 1}] |
| 187 | set _cur_x [expr {[_default [lindex $args 1] 1] - 1}] |
| 188 | } |
| 189 | |
| 190 | # Cursor Forward Tabulation. |
| 191 | proc _csi_I {args} { |
| 192 | set n [_default [lindex $args 0] 1] |
| 193 | variable _cur_x |
| 194 | variable _cols |
| 195 | incr _cur_x [expr {$n * 8 - $_cur_x % 8}] |
| 196 | if {$_cur_x >= $_cols} { |
| 197 | set _cur_x [expr {$_cols - 1}] |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | # Erase. |
| 202 | proc _csi_J {args} { |
| 203 | variable _cur_x |
| 204 | variable _cur_y |
| 205 | variable _rows |
| 206 | variable _cols |
| 207 | set arg [_default [lindex $args 0] 0] |
| 208 | if {$arg == 0} { |
| 209 | _clear_in_line $_cur_x $_cols $_cur_y |
| 210 | _clear_lines [expr {$_cur_y + 1}] $_rows |
| 211 | } elseif {$arg == 1} { |
| 212 | _clear_lines 0 [expr {$_cur_y - 1}] |
| 213 | _clear_in_line 0 $_cur_x $_cur_y |
| 214 | } elseif {$arg == 2} { |
| 215 | _clear_lines 0 $_rows |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | # Erase Line. |
| 220 | proc _csi_K {args} { |
| 221 | variable _cur_x |
| 222 | variable _cur_y |
| 223 | variable _cols |
| 224 | set arg [_default [lindex $args 0] 0] |
| 225 | if {$arg == 0} { |
| 226 | # From cursor to end. |
| 227 | _clear_in_line $_cur_x $_cols $_cur_y |
| 228 | } elseif {$arg == 1} { |
| 229 | _clear_in_line 0 $_cur_x $_cur_y |
| 230 | } elseif {$arg == 2} { |
| 231 | _clear_in_line 0 $_cols $_cur_y |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | # Delete lines. |
| 236 | proc _csi_M {args} { |
| 237 | variable _cur_y |
| 238 | variable _rows |
| 239 | variable _cols |
| 240 | variable _chars |
| 241 | set count [_default [lindex $args 0] 1] |
| 242 | set y $_cur_y |
| 243 | set next_y [expr {$y + 1}] |
| 244 | while {$count > 0 && $next_y < $_rows} { |
| 245 | for {set x 0} {$x < $_cols} {incr x} { |
| 246 | set _chars($x,$y) $_chars($x,$next_y) |
| 247 | } |
| 248 | incr y |
| 249 | incr next_y |
| 250 | incr count -1 |
| 251 | } |
| 252 | _clear_lines $next_y $_rows |
| 253 | } |
| 254 | |
| 255 | # Erase chars. |
| 256 | proc _csi_X {args} { |
| 257 | set n [_default [lindex $args 0] 1] |
| 258 | # Erase characters but don't move cursor. |
| 259 | variable _cur_x |
| 260 | variable _cur_y |
| 261 | variable _attrs |
| 262 | variable _chars |
| 263 | set lattr [array get _attrs] |
| 264 | set x $_cur_x |
| 265 | for {set i 0} {$i < $n} {incr i} { |
| 266 | set _chars($x,$_cur_y) [list " " $lattr] |
| 267 | incr x |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | # Backward tab stops. |
| 272 | proc _csi_Z {args} { |
| 273 | set n [_default [lindex $args 0] 1] |
| 274 | variable _cur_x |
| 275 | set _cur_x [expr {max (int (($_cur_x - 1) / 8) * 8 - ($n - 1) * 8, 0)}] |
| 276 | } |
| 277 | |
| 278 | # Repeat. |
| 279 | proc _csi_b {args} { |
| 280 | variable _last_char |
| 281 | set n [_default [lindex $args 0] 1] |
| 282 | _insert [string repeat $_last_char $n] |
| 283 | } |
| 284 | |
| 285 | # Line Position Absolute. |
| 286 | proc _csi_d {args} { |
| 287 | variable _cur_y |
| 288 | set _cur_y [expr {[_default [lindex $args 0] 1] - 1}] |
| 289 | } |
| 290 | |
| 291 | # Select Graphic Rendition. |
| 292 | proc _csi_m {args} { |
| 293 | variable _attrs |
| 294 | foreach item $args { |
| 295 | switch -exact -- $item { |
| 296 | "" - 0 { |
| 297 | set _attrs(intensity) normal |
| 298 | set _attrs(fg) default |
| 299 | set _attrs(bg) default |
| 300 | set _attrs(underline) 0 |
| 301 | set _attrs(reverse) 0 |
| 302 | } |
| 303 | 1 { |
| 304 | set _attrs(intensity) bold |
| 305 | } |
| 306 | 2 { |
| 307 | set _attrs(intensity) dim |
| 308 | } |
| 309 | 4 { |
| 310 | set _attrs(underline) 1 |
| 311 | } |
| 312 | 7 { |
| 313 | set _attrs(reverse) 1 |
| 314 | } |
| 315 | 22 { |
| 316 | set _attrs(intensity) normal |
| 317 | } |
| 318 | 24 { |
| 319 | set _attrs(underline) 0 |
| 320 | } |
| 321 | 27 { |
| 322 | set _attrs(reverse) 1 |
| 323 | } |
| 324 | 30 - 31 - 32 - 33 - 34 - 35 - 36 - 37 { |
| 325 | set _attrs(fg) $item |
| 326 | } |
| 327 | 39 { |
| 328 | set _attrs(fg) default |
| 329 | } |
| 330 | 40 - 41 - 42 - 43 - 44 - 45 - 46 - 47 { |
| 331 | set _attrs(bg) $item |
| 332 | } |
| 333 | 49 { |
| 334 | set _attrs(bg) default |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | # Insert string at the cursor location. |
| 341 | proc _insert {str} { |
| 342 | verbose "INSERT <<$str>>" |
| 343 | variable _cur_x |
| 344 | variable _cur_y |
| 345 | variable _rows |
| 346 | variable _cols |
| 347 | variable _attrs |
| 348 | variable _chars |
| 349 | set lattr [array get _attrs] |
| 350 | foreach char [split $str {}] { |
| 351 | set _chars($_cur_x,$_cur_y) [list $char $lattr] |
| 352 | incr _cur_x |
| 353 | if {$_cur_x >= $_cols} { |
| 354 | set _cur_x 0 |
| 355 | incr _cur_y |
| 356 | if {$_cur_y >= $_rows} { |
| 357 | error "FIXME scroll" |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | # Initialize. |
| 364 | proc _setup {rows cols} { |
| 365 | global stty_init |
| 366 | set stty_init "rows $rows columns $cols" |
| 367 | |
| 368 | variable _rows |
| 369 | variable _cols |
| 370 | variable _cur_x |
| 371 | variable _cur_y |
| 372 | variable _attrs |
| 373 | variable _resize_count |
| 374 | |
| 375 | set _rows $rows |
| 376 | set _cols $cols |
| 377 | set _cur_x 0 |
| 378 | set _cur_y 0 |
| 379 | set _resize_count 0 |
| 380 | array set _attrs { |
| 381 | intensity normal |
| 382 | fg default |
| 383 | bg default |
| 384 | underline 0 |
| 385 | reverse 0 |
| 386 | } |
| 387 | |
| 388 | _clear_lines 0 $_rows |
| 389 | } |
| 390 | |
| 391 | # Accept some output from gdb and update the screen. WAIT_FOR is |
| 392 | # a regexp matching the line to wait for. Return 0 on timeout, 1 |
| 393 | # on success. |
| 394 | proc wait_for {wait_for} { |
| 395 | global expect_out |
| 396 | global gdb_prompt |
| 397 | variable _cur_x |
| 398 | variable _cur_y |
| 399 | |
| 400 | set prompt_wait_for "$gdb_prompt \$" |
| 401 | |
| 402 | while 1 { |
| 403 | gdb_expect { |
| 404 | -re "^\[\x07\x08\x0a\x0d\]" { |
| 405 | scan $expect_out(0,string) %c val |
| 406 | set hexval [format "%02x" $val] |
| 407 | verbose "+++ _ctl_0x${hexval}" |
| 408 | _ctl_0x${hexval} |
| 409 | } |
| 410 | -re "^\x1b(\[0-9a-zA-Z\])" { |
| 411 | verbose "+++ unsupported escape" |
| 412 | error "unsupported escape" |
| 413 | } |
| 414 | -re "^\x1b\\\[(\[0-9;\]*)(\[a-zA-Z@\])" { |
| 415 | set cmd $expect_out(2,string) |
| 416 | set params [split $expect_out(1,string) ";"] |
| 417 | verbose "+++ _csi_$cmd <<<$expect_out(1,string)>>>" |
| 418 | eval _csi_$cmd $params |
| 419 | } |
| 420 | -re "^\[^\x07\x08\x0a\x0d\x1b\]+" { |
| 421 | _insert $expect_out(0,string) |
| 422 | variable _last_char |
| 423 | set _last_char [string index $expect_out(0,string) end] |
| 424 | } |
| 425 | |
| 426 | timeout { |
| 427 | # Assume a timeout means we somehow missed the |
| 428 | # expected result, and carry on. |
| 429 | return 0 |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | # If the cursor appears just after the prompt, return. It |
| 434 | # isn't reliable to check this only after an insertion, |
| 435 | # because curses may make "unusual" redrawing decisions. |
| 436 | if {$wait_for == "$prompt_wait_for"} { |
| 437 | set prev [get_line $_cur_y $_cur_x] |
| 438 | } else { |
| 439 | set prev [get_line $_cur_y] |
| 440 | } |
| 441 | if {[regexp -- $wait_for $prev]} { |
| 442 | if {$wait_for == "$prompt_wait_for"} { |
| 443 | break |
| 444 | } |
| 445 | set wait_for $prompt_wait_for |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | return 1 |
| 450 | } |
| 451 | |
| 452 | # Like ::clean_restart, but ensures that gdb starts in an |
| 453 | # environment where the TUI can work. ROWS and COLS are the size |
| 454 | # of the terminal. EXECUTABLE, if given, is passed to |
| 455 | # clean_restart. |
| 456 | proc clean_restart {rows cols {executable {}}} { |
| 457 | global env stty_init |
| 458 | save_vars {env(TERM) stty_init} { |
| 459 | setenv TERM ansi |
| 460 | _setup $rows $cols |
| 461 | if {$executable == ""} { |
| 462 | ::clean_restart |
| 463 | } else { |
| 464 | ::clean_restart $executable |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | # Setup ready for starting the tui, but don't actually start it. |
| 470 | # Returns 1 on success, 0 if TUI tests should be skipped. |
| 471 | proc prepare_for_tui {} { |
| 472 | if {[skip_tui_tests]} { |
| 473 | return 0 |
| 474 | } |
| 475 | |
| 476 | gdb_test_no_output "set tui border-kind ascii" |
| 477 | gdb_test_no_output "maint set tui-resize-message on" |
| 478 | return 1 |
| 479 | } |
| 480 | |
| 481 | # Start the TUI. Returns 1 on success, 0 if TUI tests should be |
| 482 | # skipped. |
| 483 | proc enter_tui {} { |
| 484 | if {![prepare_for_tui]} { |
| 485 | return 0 |
| 486 | } |
| 487 | |
| 488 | command "tui enable" |
| 489 | return 1 |
| 490 | } |
| 491 | |
| 492 | # Send the command CMD to gdb, then wait for a gdb prompt to be |
| 493 | # seen in the TUI. CMD should not end with a newline -- that will |
| 494 | # be supplied by this function. |
| 495 | proc command {cmd} { |
| 496 | send_gdb "$cmd\n" |
| 497 | wait_for [string_to_regexp $cmd] |
| 498 | } |
| 499 | |
| 500 | # Return the text of screen line N, without attributes. Lines are |
| 501 | # 0-based. If C is given, stop before column C. Columns are also |
| 502 | # zero-based. |
| 503 | proc get_line {n {c ""}} { |
| 504 | variable _rows |
| 505 | # This can happen during resizing, if the cursor seems to |
| 506 | # temporarily be off-screen. |
| 507 | if {$n >= $_rows} { |
| 508 | return "" |
| 509 | } |
| 510 | |
| 511 | set result "" |
| 512 | variable _cols |
| 513 | variable _chars |
| 514 | set c [_default $c $_cols] |
| 515 | set x 0 |
| 516 | while {$x < $c} { |
| 517 | append result [lindex $_chars($x,$n) 0] |
| 518 | incr x |
| 519 | } |
| 520 | return $result |
| 521 | } |
| 522 | |
| 523 | # Get just the character at (X, Y). |
| 524 | proc get_char {x y} { |
| 525 | variable _chars |
| 526 | return [lindex $_chars($x,$y) 0] |
| 527 | } |
| 528 | |
| 529 | # Get the entire screen as a string. |
| 530 | proc get_all_lines {} { |
| 531 | variable _rows |
| 532 | variable _cols |
| 533 | variable _chars |
| 534 | |
| 535 | set result "" |
| 536 | for {set y 0} {$y < $_rows} {incr y} { |
| 537 | for {set x 0} {$x < $_cols} {incr x} { |
| 538 | append result [lindex $_chars($x,$y) 0] |
| 539 | } |
| 540 | append result "\n" |
| 541 | } |
| 542 | |
| 543 | return $result |
| 544 | } |
| 545 | |
| 546 | # Get the text just before the cursor. |
| 547 | proc get_current_line {} { |
| 548 | variable _cur_x |
| 549 | variable _cur_y |
| 550 | return [get_line $_cur_y $_cur_x] |
| 551 | } |
| 552 | |
| 553 | # Helper function for check_box. Returns empty string if the box |
| 554 | # is found, description of why not otherwise. |
| 555 | proc _check_box {x y width height} { |
| 556 | set x2 [expr {$x + $width - 1}] |
| 557 | set y2 [expr {$y + $height - 1}] |
| 558 | |
| 559 | if {[get_char $x $y] != "+"} { |
| 560 | return "ul corner" |
| 561 | } |
| 562 | if {[get_char $x $y2] != "+"} { |
| 563 | return "ll corner" |
| 564 | } |
| 565 | if {[get_char $x2 $y] != "+"} { |
| 566 | return "ur corner" |
| 567 | } |
| 568 | if {[get_char $x2 $y2] != "+"} { |
| 569 | return "lr corner" |
| 570 | } |
| 571 | |
| 572 | # Note we do not check the horizonal borders of the box. The |
| 573 | # top will contain a title, and the bottom may as well, if it |
| 574 | # is overlapped by some other border. |
| 575 | for {set i [expr {$y + 1}]} {$i < $y2 - 1} {incr i} { |
| 576 | if {[get_char $x $i] != "|"} { |
| 577 | return "left side $i" |
| 578 | } |
| 579 | if {[get_char $x2 $i] != "|"} { |
| 580 | return "right side $i" |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | return "" |
| 585 | } |
| 586 | |
| 587 | # Check for a box at the given coordinates. |
| 588 | proc check_box {test_name x y width height} { |
| 589 | set why [_check_box $x $y $width $height] |
| 590 | if {$why == ""} { |
| 591 | pass $test_name |
| 592 | } else { |
| 593 | dump_screen |
| 594 | fail "$test_name ($why)" |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | # Check whether the text contents of the terminal match the |
| 599 | # regular expression. Note that text styling is not considered. |
| 600 | proc check_contents {test_name regexp} { |
| 601 | set contents [get_all_lines] |
| 602 | if {![gdb_assert {[regexp -- $regexp $contents]} $test_name]} { |
| 603 | dump_screen |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | # Check the contents of a box on the screen. This is a little |
| 608 | # like check_contents, but doens't check the whole screen |
| 609 | # contents, only the contents of a single box. This procedure |
| 610 | # includes (effectively) a call to check_box to ensure there is a |
| 611 | # box where expected, if there is then the contents of the box are |
| 612 | # matched against REGEXP. |
| 613 | proc check_box_contents {test_name x y width height regexp} { |
| 614 | variable _chars |
| 615 | |
| 616 | set why [_check_box $x $y $width $height] |
| 617 | if {$why != ""} { |
| 618 | dump_screen |
| 619 | fail "$test_name (box check: $why)" |
| 620 | return |
| 621 | } |
| 622 | |
| 623 | # Now grab the contents of the box, join each line together |
| 624 | # with a newline character and match against REGEXP. |
| 625 | set result "" |
| 626 | for {set yy [expr {$y + 1}]} {$yy < [expr {$y + $height - 1}]} {incr yy} { |
| 627 | for {set xx [expr {$x + 1}]} {$xx < [expr {$x + $width - 1}]} {incr xx} { |
| 628 | append result [lindex $_chars($xx,$yy) 0] |
| 629 | } |
| 630 | append result "\n" |
| 631 | } |
| 632 | |
| 633 | if {![gdb_assert {[regexp -- $regexp $result]} $test_name]} { |
| 634 | dump_screen |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | # A debugging function to dump the current screen, with line |
| 639 | # numbers. |
| 640 | proc dump_screen {} { |
| 641 | variable _rows |
| 642 | variable _cols |
| 643 | verbose -log "Screen Dump ($_cols x $_rows):" |
| 644 | for {set y 0} {$y < $_rows} {incr y} { |
| 645 | set fmt [format %5d $y] |
| 646 | verbose -log "$fmt [get_line $y]" |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | # Resize the terminal. |
| 651 | proc _do_resize {rows cols} { |
| 652 | variable _chars |
| 653 | variable _rows |
| 654 | variable _cols |
| 655 | |
| 656 | set old_rows [expr {min ($_rows, $rows)}] |
| 657 | set old_cols [expr {min ($_cols, $cols)}] |
| 658 | |
| 659 | # Copy locally. |
| 660 | array set local_chars [array get _chars] |
| 661 | unset _chars |
| 662 | |
| 663 | set _rows $rows |
| 664 | set _cols $cols |
| 665 | _clear_lines 0 $_rows |
| 666 | |
| 667 | for {set x 0} {$x < $old_cols} {incr x} { |
| 668 | for {set y 0} {$y < $old_rows} {incr y} { |
| 669 | set _chars($x,$y) $local_chars($x,$y) |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | proc resize {rows cols} { |
| 675 | variable _rows |
| 676 | variable _cols |
| 677 | variable _resize_count |
| 678 | |
| 679 | global gdb_spawn_name |
| 680 | # expect handles each argument to stty separately. This means |
| 681 | # that gdb will see SIGWINCH twice. Rather than rely on this |
| 682 | # behavior (which, after all, could be changed), we make it |
| 683 | # explicit here. This also simplifies waiting for the redraw. |
| 684 | _do_resize $rows $_cols |
| 685 | stty rows $_rows < $gdb_spawn_name |
| 686 | # Due to the strange column resizing behavior, and because we |
| 687 | # don't care about this intermediate resize, we don't check |
| 688 | # the size here. |
| 689 | wait_for "@@ resize done $_resize_count" |
| 690 | incr _resize_count |
| 691 | # Somehow the number of columns transmitted to gdb is one less |
| 692 | # than what we request from expect. We hide this weird |
| 693 | # details from the caller. |
| 694 | _do_resize $_rows $cols |
| 695 | stty columns [expr {$_cols + 1}] < $gdb_spawn_name |
| 696 | wait_for "@@ resize done $_resize_count, size = ${_cols}x${rows}" |
| 697 | incr _resize_count |
| 698 | } |
| 699 | } |