Home | History | Annotate | Line # | Download | only in gdb.base
with.exp revision 1.1.1.1.2.1
      1          1.1  christos # This testcase is part of GDB, the GNU debugger.
      2          1.1  christos 
      3  1.1.1.1.2.1  perseant # Copyright 2019-2023 Free Software Foundation, Inc.
      4          1.1  christos 
      5          1.1  christos # This program is free software; you can redistribute it and/or modify
      6          1.1  christos # it under the terms of the GNU General Public License as published by
      7          1.1  christos # the Free Software Foundation; either version 3 of the License, or
      8          1.1  christos # (at your option) any later version.
      9          1.1  christos #
     10          1.1  christos # This program is distributed in the hope that it will be useful,
     11          1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12          1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13          1.1  christos # GNU General Public License for more details.
     14          1.1  christos #
     15          1.1  christos # You should have received a copy of the GNU General Public License
     16          1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17          1.1  christos 
     18          1.1  christos # Test the "with" command.
     19          1.1  christos 
     20          1.1  christos load_lib completion-support.exp
     21          1.1  christos 
     22          1.1  christos standard_testfile .c
     23          1.1  christos 
     24          1.1  christos if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
     25          1.1  christos     return -1
     26          1.1  christos }
     27          1.1  christos 
     28          1.1  christos clean_restart $binfile
     29          1.1  christos 
     30          1.1  christos # Test "maint with".  VALUES is a list of values.  A nested "with" is
     31          1.1  christos # performed with each combination of pair of values from this list.
     32          1.1  christos # This exercises setting a value, and restoring it too.  This is
     33          1.1  christos # particularly important for the "special" values like "unlimited",
     34          1.1  christos # which for example for var_uinteger maps to 0 at the user-visible
     35          1.1  christos # level, but maps to -1 internally.
     36          1.1  christos 
     37          1.1  christos proc test_with {setting values} {
     38          1.1  christos     foreach val1 $values {
     39          1.1  christos 	foreach val2 $values {
     40          1.1  christos 	    gdb_test \
     41          1.1  christos 		"maint with test-settings $setting $val1 -- maint with test-settings $setting $val2 -- p 1" \
     42          1.1  christos 		" = 1"
     43          1.1  christos 	}
     44          1.1  christos     }
     45          1.1  christos }
     46          1.1  christos 
     47          1.1  christos # Test "maint with" in the error case.  SETTING is the "maint set
     48          1.1  christos # test-setting" setting to exercise.  TMP_VAL is the value to set the
     49          1.1  christos # setting to.  EXPECTED_RE is the expected GDB output, which should be
     50          1.1  christos # an error of some kind.  Also checks that the setting's original
     51          1.1  christos # value is preserved across the error.
     52          1.1  christos 
     53          1.1  christos proc test_with_error {setting tmp_val expected_re} {
     54          1.1  christos     global gdb_prompt
     55          1.1  christos 
     56          1.1  christos     with_test_prefix "$setting, $tmp_val" {
     57          1.1  christos 	set test "save org value"
     58          1.1  christos 	set org_val ""
     59          1.1  christos 	gdb_test_multiple "maint show test-settings $setting" $test {
     60          1.1  christos 	    -re "(.*)\r\n$gdb_prompt $" {
     61          1.1  christos 		set org_val $expect_out(1,string)
     62          1.1  christos 		pass $test
     63          1.1  christos 	    }
     64          1.1  christos 	}
     65          1.1  christos 
     66          1.1  christos 	gdb_test \
     67          1.1  christos 	    "maint with test-settings $setting $tmp_val -- p 1" \
     68          1.1  christos 	    $expected_re
     69          1.1  christos 
     70          1.1  christos 	gdb_test "maint show test-settings $setting" "^$org_val" \
     71          1.1  christos 	    "value hasn't changed across error"
     72          1.1  christos     }
     73          1.1  christos }
     74          1.1  christos 
     75          1.1  christos # Test "with" framework basics, using the internal "maint with
     76          1.1  christos # test-settings" subcommands.
     77          1.1  christos with_test_prefix "maint" {
     78          1.1  christos     test_with "auto-boolean" {"on" "off" "auto"}
     79          1.1  christos     test_with "boolean" {"" "on" "off" "0" "1" "enable" "disable"}
     80          1.1  christos     test_with "integer" {"0" "1" "-1" "unlimited"}
     81          1.1  christos     test_with "uinteger" {"0" "1" "unlimited"}
     82          1.1  christos     test_with "zinteger" {"0" "1" "-1"}
     83          1.1  christos     test_with "zuinteger" {"0" "1"}
     84          1.1  christos     test_with "zuinteger-unlimited" {"-1" "unlimited" "0" "1"}
     85          1.1  christos     test_with "string" {"" "foo" "\"hello world\""}
     86          1.1  christos     test_with "string-noescape" {"" "foo" "\"hello world\""}
     87          1.1  christos     test_with "filename" {"/foo" "bar/x/y"}
     88          1.1  christos     test_with "optional-filename" {"" "/foo" "bar/x/y"}
     89          1.1  christos     test_with "enum" {"xxx" "yyy"}
     90          1.1  christos 
     91          1.1  christos     # Check the most important error conditions.  E.g., empty,
     92          1.1  christos     # negative or "unlimited" values for settings that don't accept
     93          1.1  christos     # those.  Exhaustive error coverage of the set/with value parsing
     94          1.1  christos     # is left to "set" testing, in gdb.base/settings.exp.
     95          1.1  christos     test_with_error "auto-boolean" "" \
     96          1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
     97          1.1  christos     test_with_error "auto-boolean" "xxx" \
     98          1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
     99          1.1  christos     test_with_error "boolean" "2" "\"on\" or \"off\" expected\\."
    100          1.1  christos     test_with_error "uinteger" "-1" "integer -1 out of range"
    101          1.1  christos     test_with_error "uinteger" "" \
    102  1.1.1.1.2.1  perseant 	"Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
    103          1.1  christos     test_with_error "zuinteger" "-1" "integer -1 out of range"
    104          1.1  christos     test_with_error "zuinteger" "" \
    105  1.1.1.1.2.1  perseant 	"Argument required \\(integer to set it to\\)\\."
    106          1.1  christos     test_with_error "zuinteger-unlimited" "-2" \
    107          1.1  christos 	"only -1 is allowed to set as unlimited"
    108          1.1  christos     test_with_error "zuinteger-unlimited" "" \
    109  1.1.1.1.2.1  perseant 	"Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
    110          1.1  christos     test_with_error "filename" "" \
    111          1.1  christos 	"Argument required \\(filename to set it to\\.\\)\\."
    112          1.1  christos     test_with_error "enum" "" \
    113          1.1  christos 	"Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
    114          1.1  christos }
    115          1.1  christos 
    116          1.1  christos # Basic/core tests using user-visible commands.
    117          1.1  christos with_test_prefix "basics" {
    118          1.1  christos     gdb_test "print g_s" " = {a = 1, b = 2, c = 3}"
    119          1.1  christos     gdb_test "with print pretty -- print g_s" \
    120          1.1  christos 	[multi_line  \
    121          1.1  christos 	     " = {" \
    122          1.1  christos 	     "  a = 1," \
    123          1.1  christos 	     "  b = 2," \
    124          1.1  christos 	     "  c = 3" \
    125          1.1  christos 	     "}"]
    126          1.1  christos 
    127          1.1  christos     # A boolean setting.
    128          1.1  christos     gdb_test "with non-stop on -- show non-stop" \
    129          1.1  christos 	"Controlling the inferior in non-stop mode is on\\."
    130          1.1  christos     gdb_test "show non-stop" \
    131          1.1  christos 	"Controlling the inferior in non-stop mode is off\\."
    132          1.1  christos 
    133          1.1  christos     # Language.
    134          1.1  christos     gdb_test "with language pascal -- show language" \
    135          1.1  christos 	"The current source language is \"pascal\"\\."
    136          1.1  christos 
    137          1.1  christos     gdb_test "show language" \
    138          1.1  christos 	"The current source language is \"auto; currently c\"\\."
    139          1.1  christos 
    140          1.1  christos     gdb_test "with language ada -- print g_s" \
    141          1.1  christos 	" = \\(a => 1, b => 2, c => 3\\)"
    142          1.1  christos 
    143          1.1  christos     # Nested "with"s.
    144          1.1  christos     gdb_test "with language ada -- with language c -- print g_s" \
    145          1.1  christos 	" = {a = 1, b = 2, c = 3}"
    146          1.1  christos 
    147          1.1  christos     # "w" alias.
    148          1.1  christos     gdb_test "w language pascal -- show language" \
    149          1.1  christos 	"The current source language is \"pascal\"\\." \
    150          1.1  christos 	"w alias works"
    151          1.1  christos 
    152          1.1  christos     # An early prototype of the "with" command got this wrong.
    153          1.1  christos     gdb_test \
    154          1.1  christos 	"w print repeats unlimited -- w print repeats 1 -- p \"1223334444\"" \
    155          1.1  christos 	" = \"1\", '2' <repeats 2 times>, '3' <repeats 3 times>, '4' <repeats 4 times>"
    156          1.1  christos }
    157          1.1  christos 
    158          1.1  christos # Check a user-defined command.
    159          1.1  christos with_test_prefix "user-defined" {
    160          1.1  christos     # A user defined command.
    161          1.1  christos     set test "define usercmd"
    162          1.1  christos     gdb_test_multiple "define usercmd" $test {
    163          1.1  christos 	-re "End with"  {
    164          1.1  christos 	    gdb_test \
    165          1.1  christos 		[multi_line_input \
    166          1.1  christos 		     {print g_s} \
    167          1.1  christos 		     {end}] \
    168          1.1  christos 		"" \
    169          1.1  christos 		$test
    170          1.1  christos 	}
    171          1.1  christos     }
    172          1.1  christos     gdb_test "with language ada -- usercmd" \
    173          1.1  christos 	" = \\(a => 1, b => 2, c => 3\\)"
    174          1.1  christos }
    175          1.1  christos 
    176          1.1  christos # Check repeating.
    177          1.1  christos with_test_prefix "repeat" {
    178          1.1  christos     clean_restart $binfile
    179          1.1  christos 
    180          1.1  christos     # "with" with no command reinvokes the previous command.
    181          1.1  christos     gdb_test "with language ada" \
    182          1.1  christos 	"No previous command to relaunch" \
    183          1.1  christos 	"reinvoke with no previous command to relaunch"
    184          1.1  christos 
    185          1.1  christos     gdb_test "print g_s" " = {a = 1, b = 2, c = 3}"
    186          1.1  christos 
    187          1.1  christos     gdb_test "with language ada" \
    188          1.1  christos 	" = \\(a => 1, b => 2, c => 3\\)" \
    189          1.1  christos 	"reinvoke with language"
    190          1.1  christos 
    191          1.1  christos     # Same, but with "--".
    192          1.1  christos     gdb_test "with language fortran --" \
    193          1.1  christos 	" = \\( a = 1, b = 2, c = 3 \\)" \
    194          1.1  christos 	"reinvoke with language and --"
    195          1.1  christos 
    196          1.1  christos     # Repeating repeats the original "print g_s", not the last "with"
    197          1.1  christos     # command.
    198          1.1  christos     set test "repeat command line"
    199          1.1  christos     send_gdb "\n"
    200          1.1  christos     gdb_test_multiple "" $test {
    201          1.1  christos 	-re " = {a = 1, b = 2, c = 3}\r\n$gdb_prompt $" {
    202          1.1  christos 	    pass $test
    203          1.1  christos 	}
    204          1.1  christos     }
    205          1.1  christos }
    206          1.1  christos 
    207          1.1  christos # Basic run control.
    208          1.1  christos with_test_prefix "run control" {
    209          1.1  christos     clean_restart $binfile
    210          1.1  christos 
    211          1.1  christos     if ![runto_main] {
    212          1.1  christos 	return
    213          1.1  christos     }
    214          1.1  christos 
    215          1.1  christos     # Check "with" with a synchronous execution command.
    216          1.1  christos     gdb_test "with disassemble-next-line on -- next" \
    217          1.1  christos 	"return 0;.*=>.*"
    218          1.1  christos }
    219          1.1  christos 
    220          1.1  christos # Check errors.
    221          1.1  christos with_test_prefix "errors" {
    222          1.1  christos     gdb_test "with" "Missing arguments\\."
    223          1.1  christos 
    224          1.1  christos     # Try both an unknown root setting and an unknown prefixed
    225          1.1  christos     # setting.  The errors come from different locations in the
    226          1.1  christos     # sources.
    227          1.1  christos     gdb_test "with xxxx yyyy" \
    228          1.1  christos 	"Undefined set command: \"xxxx\".  Try \"help set\"\\."
    229          1.1  christos     gdb_test "with print xxxx yyyy" \
    230          1.1  christos 	"Undefined set print command: \"xxxx yyyy\".  Try \"help set print\"\\."
    231          1.1  christos     # Try one error case for "maint with", to make sure the right
    232          1.1  christos     # "maintenance with" prefix is shown.
    233          1.1  christos     gdb_test "maint with xxxx yyyy" \
    234          1.1  christos 	"Undefined maintenance set command: \"xxxx\".  Try \"help maintenance set\"\\."
    235          1.1  christos 
    236          1.1  christos     # Try ambiguous settings.
    237          1.1  christos     gdb_test "with w" \
    238          1.1  christos 	"Ambiguous set command \"w\": watchdog, width, write\\."
    239          1.1  christos     gdb_test "with print m" \
    240  1.1.1.1.2.1  perseant 	"Ambiguous set print command \"m\": max-depth, max-symbolic-offset, memory-tag-violations\\."
    241          1.1  christos 
    242          1.1  christos     gdb_test "with variable xxx=1" \
    243          1.1  christos 	"Cannot use this setting with the \"with\" command"
    244          1.1  christos 
    245          1.1  christos     gdb_test "with print elements -- p 1" \
    246  1.1.1.1.2.1  perseant 	"Argument required \\(integer to set it to, or \"unlimited\"\\)\\."
    247          1.1  christos 
    248          1.1  christos     gdb_test "with -- p 1" \
    249          1.1  christos 	"Missing setting before '--' delimiter"
    250          1.1  christos 
    251          1.1  christos     # Check that the setting is restored even if the command throws.
    252          1.1  christos     gdb_test "with print elements 1 -- unknowncommand" \
    253          1.1  christos 	"Undefined command: \"unknowncommand\"\\.  Try \"help\"\\."
    254          1.1  christos     gdb_test "show print elements" \
    255          1.1  christos 	"Limit on string chars or array elements to print is 200\\."
    256          1.1  christos }
    257          1.1  christos 
    258          1.1  christos # Check completion.
    259          1.1  christos with_test_prefix "completion" {
    260          1.1  christos     test_gdb_complete_unique \
    261          1.1  christos 	"with pri" \
    262          1.1  christos 	"with print"
    263          1.1  christos 
    264          1.1  christos     test_gdb_complete_unique \
    265          1.1  christos 	"with print ele" \
    266          1.1  christos 	"with print elements"
    267          1.1  christos 
    268          1.1  christos     test_gdb_complete_unique \
    269          1.1  christos 	"with print elements u" \
    270          1.1  christos 	"with print elements unlimited"
    271          1.1  christos 
    272          1.1  christos     test_gdb_complete_none \
    273          1.1  christos 	"with print elements unlimited "
    274          1.1  christos 
    275          1.1  christos     test_gdb_completion_offers_commands "with print elements unlimited -- "
    276          1.1  christos 
    277          1.1  christos     # Check that the completer nests into the nested command line's
    278          1.1  christos     # completer.
    279          1.1  christos     test_gdb_complete_unique \
    280          1.1  christos 	"with print elements unlimited -- with print ele" \
    281          1.1  christos 	"with print elements unlimited -- with print elements"
    282          1.1  christos 
    283          1.1  christos     # Check completion of "maint with".  "maint with" and "with"'s
    284          1.1  christos     # completers share 99% of the code.  All we need to care about
    285          1.1  christos     # here is that the completion word point is computed correctly, so
    286          1.1  christos     # any simple completion is sufficient.
    287          1.1  christos     test_gdb_complete_unique \
    288          1.1  christos 	"maint with test-set" \
    289          1.1  christos 	"maint with test-settings"
    290          1.1  christos }
    291