Home | History | Annotate | Line # | Download | only in gdb.base
      1 # Copyright 2016-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 standard_testfile
     17 
     18 set compile_options "debug"
     19 if {[build_executable $testfile.exp $testfile ${srcfile} ${compile_options}] == -1} {
     20     untested "failed to compile"
     21     return -1
     22 }
     23 
     24 # Ensure no output has been sent.  Use MESSAGE as test message.
     25 
     26 proc ensure_no_output {message} {
     27     global decimal
     28 
     29     # Run a command and use an anchor to make sure no output appears
     30     # before the command's expected output.
     31     gdb_test "print 999" "^\\\$$decimal = 999" $message
     32 }
     33 
     34 # Run a few execution-related commands on CON1, and ensure the proper
     35 # output, or none, if appropriate, is sent to CON2.  CON1_NAME and
     36 # CON2_NAME are the names of the consoles.
     37 
     38 proc do_execution_tests {con1 con1_name con2 con2_name} {
     39     global srcfile
     40     global decimal
     41 
     42     set bp_lineno [gdb_get_line_number "set break $con1_name here"]
     43 
     44     with_spawn_id $con1 {
     45 	gdb_test "next" "global = 1;"
     46     }
     47     with_spawn_id $con2 {
     48 	ensure_no_output "next causes no spurious output on other console"
     49     }
     50 
     51     with_spawn_id $con1 {
     52 	gdb_test "break $srcfile:$bp_lineno" \
     53 	    "Breakpoint $decimal .*$srcfile, line $bp_lineno\\." \
     54 	    "set breakpoint"
     55     }
     56     with_spawn_id $con2 {
     57 	ensure_no_output "break causes no spurious output on other console"
     58     }
     59 
     60     with_spawn_id $con1 {
     61 	gdb_test "continue" "set break $con1_name here .*" "continue to breakpoint"
     62     }
     63 
     64     with_spawn_id $con2 {
     65 	set test "breakpoint hit reported on other console"
     66 	gdb_test_multiple "" $test {
     67 	    -re "Breakpoint $decimal, .* set break $con1_name here " {
     68 		pass $test
     69 	    }
     70 	}
     71     }
     72 }
     73 
     74 # The test proper.
     75 
     76 proc_with_prefix do_test {} {
     77     global srcfile testfile
     78     global gdb_prompt
     79     global gdb_spawn_id
     80     global gdb_main_spawn_id extra_spawn_id
     81 
     82     clean_restart $testfile
     83 
     84     if ![runto_main] {
     85 	return -1
     86     }
     87 
     88     gdb_test "new-ui" \
     89 	"Usage: new-ui INTERPRETER TTY" \
     90 	"new-ui without arguments"
     91 
     92     set test "new-ui does not repeat"
     93     send_gdb "\n"
     94     gdb_test_multiple "" $test {
     95 	-re "^\r\n$gdb_prompt $" {
     96 	    pass $test
     97 	}
     98     }
     99 
    100     # Save the main UI's spawn ID.
    101     set gdb_main_spawn_id $gdb_spawn_id
    102 
    103     # Create the new PTY for the secondary console UI.
    104     spawn -pty
    105     set extra_spawn_id $spawn_id
    106     set extra_tty_name $spawn_out(slave,name)
    107     gdb_test_multiple "new-ui console $extra_tty_name" "new-ui" {
    108 	-re "New UI allocated\r\n$gdb_prompt $" {
    109 	}
    110     }
    111 
    112     with_spawn_id $extra_spawn_id {
    113 	set test "initial prompt on extra console"
    114 	gdb_test_multiple "" $test {
    115 	    -re "$gdb_prompt $" {
    116 		pass $test
    117 	    }
    118 	}
    119     }
    120 
    121     # Ensure non-execution commands in one console don't cause output
    122     # in the other consoles.
    123     with_spawn_id $gdb_main_spawn_id {
    124 	gdb_test "print 1" "^\\\$1 = 1" "print on main console"
    125     }
    126     with_spawn_id $extra_spawn_id {
    127 	gdb_test "print 2" "^\\\$2 = 2" "print on extra console"
    128     }
    129 
    130     # Verify that we get proper queries on the main UI, but that they are
    131     # auto-answered on secondary UIs.
    132     with_spawn_id $gdb_main_spawn_id {
    133 	gdb_test "delete" "" "delete all breakpoints, watchpoints, tracepoints, and catchpoints on main console" \
    134 		 "Delete all breakpoints, watchpoints, tracepoints, and catchpoints. .y or n. $" "n"
    135     }
    136     with_spawn_id $extra_spawn_id {
    137 	# Check output in two stages in order to override
    138 	# gdb_test_multiple's internal "got interactive prompt" fail
    139 	# that would otherwise match if the expect buffer happens to
    140 	# fill with partial output that ends in "(y or n) ".
    141 	set test "delete all breakpoints, watchpoints, tracepoints, and catchpoints on extra console"
    142 	gdb_test_multiple "delete" $test {
    143 	    -re "Delete all breakpoints, watchpoints, tracepoints, and catchpoints. .y or n. " {
    144 		gdb_test "" \
    145 		    ".answered Y; input not from terminal." \
    146 		    $test
    147 	    }
    148 	}
    149     }
    150 
    151     # Run a few execution tests with the main console as the driver
    152     # console.
    153     with_test_prefix "main console" {
    154 	do_execution_tests \
    155 	    $gdb_main_spawn_id "main console" \
    156 	    $extra_spawn_id "extra console"
    157     }
    158     # Same, but with the extra console as driver.
    159     with_test_prefix "extra console" {
    160 	do_execution_tests \
    161 	    $extra_spawn_id "extra console" \
    162 	    $gdb_main_spawn_id "main console"
    163     }
    164 }
    165 
    166 # Test missing / invalid arguments.
    167 
    168 proc_with_prefix do_test_invalid_args {} {
    169     global testfile
    170 
    171     clean_restart $testfile
    172 
    173     spawn -pty
    174     set extra_tty_name $spawn_out(slave,name)
    175 
    176     # Test bad terminal path.
    177     gdb_test "new-ui console /non/existent/path" \
    178 	     "opening terminal failed: No such file or directory\." \
    179 	     "new-ui with bad terminal path"
    180 
    181     # Test bad interpreter name.
    182     gdb_test "new-ui bloop $extra_tty_name" \
    183 	     "Interpreter `bloop' unrecognized" \
    184 	     "new-ui with bad interpreter name"
    185 
    186     # Test that the TUI cannot be used for a new UI.
    187     if [allow_tui_tests] {
    188 	gdb_test "new-ui tui $extra_tty_name" \
    189 	    "interpreter 'tui' cannot be used with a new UI" \
    190 	    "new-ui with tui"
    191     }
    192 
    193     # Test that we can continue working normally.
    194     if ![runto_main] {
    195 	return
    196     }
    197 }
    198 
    199 do_test
    200 do_test_invalid_args
    201