Home | History | Annotate | Line # | Download | only in gdb.tui
tui-layout.exp revision 1.1.1.5
      1 # Copyright 2017-2024 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 # Minimal testcase that just checks that the various "layout $foo"
     17 # commands do not cause gdb to crash.
     18 
     19 require allow_tui_tests
     20 
     21 tuiterm_env
     22 
     23 standard_testfile
     24 
     25 if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} {
     26     return -1
     27 }
     28 
     29 # Run one test of the 'layout' command, selecting LAYOUT_NAME.
     30 #
     31 # TERMINAL should be either 'dumb' or 'ansi'.  When TERMINAL is 'dumb'
     32 # then GDB is started in a terminal that does not support tui mode, in
     33 # this case the layout command is expected to fail.
     34 #
     35 # When TERMINAL is 'ansi' then GDB is started using our emulated ANSI
     36 # terminal, and the layout command is expected to succeed.
     37 #
     38 # When EXECUTION is true then a call to runto_main is used, otherwise
     39 # this call is skipped and the inferior is left in whatever state it
     40 # happens to be in after a call to clean_restart.
     41 
     42 proc test_layout_or_focus {layout_name terminal execution} {
     43     global binfile gdb_prompt
     44 
     45     set dumb_terminal [string equal $terminal "dumb"]
     46 
     47     global env
     48     save_vars { env(TERM) } {
     49 	setenv TERM $terminal
     50 	if {$dumb_terminal} {
     51 	    clean_restart $binfile
     52 	} else {
     53 	    Term::clean_restart 24 80 $binfile
     54 	    if {![Term::prepare_for_tui]} {
     55 		unsupported "TUI not supported"
     56 		return
     57 	    }
     58 	}
     59     }
     60 
     61     if {$execution} {
     62 	if {![runto_main]} {
     63 	    return 0
     64 	}
     65     }
     66 
     67     if {$dumb_terminal} {
     68 	if { [is_remote host] } {
     69 	    # setenv TERM dummy has no effect on remote host.
     70 	    return
     71 	}
     72 	gdb_test "layout $layout_name" \
     73 	    "Cannot enable the TUI: terminal doesn't support cursor addressing \\\[TERM=dumb\\\]"
     74     } else {
     75 	Term::command_no_prompt_prefix "layout $layout_name"
     76 	if {$layout_name == "asm"} {
     77 	    Term::check_box "asm box" 0 0 80 15
     78 	} elseif {$layout_name == "reg"} {
     79 	    Term::check_box "reg box" 0 0 80 8
     80 	    Term::check_box "src box" 0 7 80 8
     81 	} elseif {$layout_name == "src"} {
     82 	    Term::check_box "src box" 0 0 80 15
     83 	} elseif {$layout_name == "split"} {
     84 	    Term::check_box "src box" 0 0 80 8
     85 	    Term::check_box "asm box" 0 7 80 8
     86 	}
     87     }
     88 }
     89 
     90 foreach_with_prefix terminal {ansi dumb} {
     91     foreach_with_prefix execution {false true} {
     92 	foreach_with_prefix layout {"asm" "reg" "src" "split"} {
     93 	    test_layout_or_focus $layout $terminal $execution
     94 	}
     95     }
     96 }
     97