Home | History | Annotate | Line # | Download | only in gdb.base
      1      1.1  christos # This testcase is part of GDB, the GNU debugger.
      2      1.1  christos 
      3  1.1.1.3  christos # Copyright 2019-2024 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 set/show commands framework.  The test uses the
     19      1.1  christos # "maintenance test-settings set/show xxx" subcommands to exercise
     20      1.1  christos # TAB-completion and setting processing.
     21      1.1  christos 
     22      1.1  christos load_lib completion-support.exp
     23      1.1  christos 
     24      1.1  christos standard_testfile .c
     25      1.1  christos 
     26      1.1  christos if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
     27      1.1  christos     return -1
     28      1.1  christos }
     29      1.1  christos 
     30      1.1  christos clean_restart
     31      1.1  christos 
     32      1.1  christos if { ![readline_is_used] } {
     33      1.1  christos     untested "no tab completion support without readline"
     34      1.1  christos     return -1
     35      1.1  christos }
     36      1.1  christos 
     37      1.1  christos # Test the show command SHOW_CMD.  EXPECTED_RE is the expected output.
     38      1.1  christos # Also verifies that $_gdb_maint_setting_str produces an equivalent output,
     39      1.1  christos # matching it with EXPECTED_RE.  EXPECTED_RE double quotes are escaped
     40      1.1  christos # unless EXPECTED_RE_ESCAPED is true, indicating the quotes in EXPECTED_RE
     41      1.1  christos # are already escaped.
     42      1.1  christos # The value for the setting corresponding to SHOW_CMD is then reset
     43      1.1  christos # to RESET_VALUE, then set again to the value given by $_gdb_maint_setting_str
     44      1.1  christos # and $_gdb_maint_setting.  The default value of RESET_VALUE (0) should work for
     45      1.1  christos # most settings.  Note that we do not check that RESET_VALUE differs from
     46      1.1  christos # the expected value, as we assume different values will be verified.
     47      1.1  christos # The setting value must still be the one in force before calling show_setting.
     48      1.1  christos # In other words, this verifies that
     49      1.1  christos #   maint set test-settings <some_setting> $_gdb_maint_setting_str(<some_setting>)
     50      1.1  christos #   maint set test-settings <some_setting> $_gdb_maint_setting(<some_setting>)
     51      1.1  christos # do not change the setting value.
     52      1.1  christos # This procedure makes it easier to make the test
     53      1.1  christos # name/message unique, since we test the "show" commands many times.
     54      1.1  christos # EXPECTED_RE is made part of the test name.
     55      1.1  christos proc show_setting {show_cmd expected_re {expected_re_escaped 0} {reset_value 0}} {
     56      1.1  christos     global gdb_prompt
     57      1.1  christos 
     58      1.1  christos     with_test_prefix "$show_cmd $expected_re" {
     59      1.1  christos 	gdb_test "$show_cmd" $expected_re "show"
     60      1.1  christos 
     61      1.1  christos 	# Remove the first two words (such as "maint show") to have the
     62      1.1  christos 	# setting name to use for $_gdb_maint_setting_str.
     63      1.1  christos 	regsub "\[^ \]+ +\[^ \]+ +\(.*\)" $show_cmd "\\1" maint_setting
     64      1.1  christos 	if {$expected_re_escaped} {
     65      1.1  christos 	    set escaped_expected_re $expected_re
     66      1.1  christos 	} else {
     67      1.1  christos 	    regsub -all "\"" $expected_re "\\\\\\\"" escaped_expected_re
     68      1.1  christos 	}
     69      1.1  christos 	set test "print \$_gdb_maint_setting_str"
     70      1.1  christos 	set setting_str_value "xxxYYYxxx"
     71      1.1  christos 	gdb_test_multiple "print \$_gdb_maint_setting_str(\"$maint_setting\")" $test {
     72      1.1  christos 	    -re " = \"\($escaped_expected_re\)\".*$gdb_prompt $" {
     73      1.1  christos 		set setting_str_value $expect_out(1,string)
     74      1.1  christos 		regsub -all "\\\\" $expect_out(1,string) "" setting_str_value
     75      1.1  christos 		pass $test
     76      1.1  christos 	    }
     77      1.1  christos 	}
     78      1.1  christos 
     79      1.1  christos 	# Change the setting value to RESET_VALUE, set it back to setting_str_value
     80      1.1  christos 	# and check we still have the original value.
     81      1.1  christos 	gdb_test_no_output "maintenance set $maint_setting $reset_value" "str reset $reset_value"
     82      1.1  christos 	gdb_test_no_output "maintenance set $maint_setting $setting_str_value" "str set again"
     83      1.1  christos 	gdb_test "$show_cmd" $expected_re "str show after reset+set again"
     84      1.1  christos 
     85      1.1  christos 	# Same test, but with value captured from $_gdb_maint_setting.
     86      1.1  christos 	set test "print \$_gdb_maint_setting"
     87      1.1  christos 	set setting_value "xxxYYYxxx"
     88      1.1  christos 	gdb_test_multiple "print \$_gdb_maint_setting(\"$maint_setting\")" $test {
     89      1.1  christos 	    -re " = \"\(.*\)\".*$gdb_prompt $" {
     90      1.1  christos 		set setting_value $expect_out(1,string)
     91      1.1  christos 		regsub -all "\\\\" $expect_out(1,string) "" setting_value
     92      1.1  christos 		pass $test
     93      1.1  christos 	    }
     94      1.1  christos 	    -re " = \(.*\)\r\n$gdb_prompt $" {
     95      1.1  christos 		set setting_value $expect_out(1,string)
     96      1.1  christos 		pass $test
     97      1.1  christos 	    }
     98      1.1  christos 	}
     99      1.1  christos 
    100      1.1  christos 	gdb_test_no_output "maintenance set $maint_setting $reset_value" "reset $reset_value"
    101      1.1  christos 	gdb_test_no_output "maintenance set $maint_setting $setting_value" "set again"
    102      1.1  christos 	gdb_test "$show_cmd" $expected_re "show after reset+set again"
    103      1.1  christos     }
    104      1.1  christos }
    105      1.1  christos 
    106      1.1  christos # Verifies that $_gdb_setting (SETTING) gives a value whose ptype matches EXPECTED.
    107      1.1  christos proc check_type {setting expected} {
    108      1.1  christos     with_test_prefix "check_type $setting $expected" {
    109      1.1  christos 	gdb_test "print \$_gdb_maint_setting(\"$setting\")"
    110      1.1  christos 	gdb_test "ptype $" "$expected"
    111      1.1  christos 
    112      1.1  christos 	# Currently, GDB ptype <internal function> always tells it is type int.
    113      1.1  christos 	# ptype should better report an error such as:
    114      1.1  christos 	#   "No type information for GDB functions"
    115      1.1  christos 	# Test 'type int', so as to make it fail if ptype is changed.
    116      1.1  christos 	gdb_test "ptype \$_gdb_maint_setting(\"$setting\")" \
    117      1.1  christos             "type = int"
    118      1.1  christos     }
    119      1.1  christos }
    120      1.1  christos 
    121      1.1  christos # var_Xinteger tests.  VARIANT determines which command/variant to
    122      1.1  christos # exercise.
    123      1.1  christos proc test-integer {variant} {
    124      1.1  christos     set set_cmd "maint set test-settings $variant"
    125      1.1  christos     set show_cmd "maint show test-settings $variant"
    126      1.1  christos 
    127      1.1  christos     # A bogus value.
    128      1.1  christos     gdb_test "$set_cmd bogus" \
    129      1.1  christos 	"No symbol table is loaded\\.  Use the \"file\" command\\."
    130      1.1  christos 
    131      1.1  christos     # Seemingly-valid but not quite valid value.
    132      1.1  christos     gdb_test "$set_cmd 1a" \
    133      1.1  christos 	"Invalid number \"1a\"\\."
    134      1.1  christos 
    135      1.1  christos     # Valid value followed by garbage.
    136      1.1  christos     gdb_test "$set_cmd 1 1" \
    137      1.1  christos 	"A syntax error in expression, near `1'\\."
    138      1.1  christos 
    139      1.1  christos     # Valid value followed by garbage.
    140      1.1  christos     gdb_test "$set_cmd 1 x" \
    141      1.1  christos 	"A syntax error in expression, near `x'\\."
    142      1.1  christos 
    143      1.1  christos     if {$variant == "zuinteger-unlimited"} {
    144      1.1  christos 	# -1 means unlimited.  Other negative values are rejected.  -1
    145      1.1  christos 	# -is tested further below, along the "unlimited" tests.
    146  1.1.1.3  christos 	gdb_test "$set_cmd -2" "integer -2 out of range"
    147      1.1  christos 	check_type "test-settings $variant" "type = int"
    148      1.1  christos     } elseif {$variant == "uinteger" || $variant == "zuinteger"} {
    149      1.1  christos 	# Negative values are not accepted.
    150      1.1  christos 	gdb_test "$set_cmd -1" "integer -1 out of range"
    151      1.1  christos 	gdb_test "$set_cmd -2" "integer -2 out of range"
    152      1.1  christos 	check_type "test-settings $variant" "type = unsigned int"
    153      1.1  christos     } else {
    154      1.1  christos 	# Negative values are not accepted.
    155      1.1  christos 	gdb_test_no_output "$set_cmd -1"
    156      1.1  christos 	show_setting "$show_cmd" "-1"
    157      1.1  christos 	gdb_test_no_output "$set_cmd -2"
    158      1.1  christos 	show_setting "$show_cmd" "-2"
    159      1.1  christos 	check_type "test-settings $variant" "type = int"
    160      1.1  christos     }
    161      1.1  christos 
    162      1.1  christos     # Regular integer is accepted.
    163      1.1  christos     gdb_test_no_output "$set_cmd 999"
    164      1.1  christos     show_setting "$show_cmd" "999"
    165      1.1  christos 
    166      1.1  christos     if {$variant == "zinteger" || $variant == "zuinteger"} {
    167      1.1  christos 	# 0 means 0.
    168      1.1  christos 	gdb_test_no_output "$set_cmd 0"
    169      1.1  christos 	show_setting "$show_cmd" "0"
    170      1.1  christos     } else {
    171      1.1  christos 	# Either 0 or -1 mean unlimited.  Test both the number and
    172      1.1  christos 	# "unlimited".  For the latter, test both full name and
    173      1.1  christos 	# abbreviations.
    174      1.1  christos 
    175      1.1  christos 	if {$variant == "zuinteger-unlimited"} {
    176      1.1  christos 	    gdb_test_no_output "$set_cmd -1"
    177      1.1  christos 	} else {
    178      1.1  christos 	    gdb_test_no_output "$set_cmd 0"
    179      1.1  christos 	}
    180      1.1  christos 	show_setting "$show_cmd" "unlimited"
    181      1.1  christos 
    182      1.1  christos 	foreach_with_prefix value {
    183      1.1  christos 	    "u"
    184      1.1  christos 	    "un"
    185      1.1  christos 	    "unl"
    186      1.1  christos 	    "unli"
    187      1.1  christos 	    "unlim"
    188      1.1  christos 	    "unlimi"
    189      1.1  christos 	    "unlimit"
    190      1.1  christos 	    "unlimite"
    191      1.1  christos 	    "unlimited"
    192      1.1  christos 	} {
    193      1.1  christos 	    # Alternate between integer and unlimited, to make sure the
    194      1.1  christos 	    # setting really took effect.
    195      1.1  christos 	    gdb_test_no_output "$set_cmd 1"
    196      1.1  christos 	    show_setting "$show_cmd" "1"
    197      1.1  christos 
    198      1.1  christos 	    gdb_test_no_output "$set_cmd $value"
    199      1.1  christos 	    show_setting "$show_cmd" "unlimited"
    200      1.1  christos 	}
    201      1.1  christos     }
    202      1.1  christos 
    203      1.1  christos     if {$variant == "zuinteger"} {
    204      1.1  christos 	test_gdb_complete_multiple "maint set test-settings " "zuinteger" "" {
    205      1.1  christos 	    "zuinteger"
    206      1.1  christos 	    "zuinteger-unlimited"
    207      1.1  christos 	}
    208      1.1  christos     } else {
    209      1.1  christos 	test_gdb_complete_unique \
    210      1.1  christos 	    "$set_cmd" \
    211      1.1  christos 	    "$set_cmd"
    212      1.1  christos     }
    213      1.1  christos 
    214      1.1  christos     if {$variant == "zinteger" || $variant == "zuinteger"} {
    215      1.1  christos 	test_gdb_complete_none \
    216  1.1.1.2  christos 	    "$set_cmd "
    217      1.1  christos     } else {
    218  1.1.1.2  christos 	test_gdb_complete_multiple "$set_cmd " "" "" {
    219  1.1.1.2  christos 	    "NUMBER"
    220  1.1.1.2  christos 	    "unlimited"
    221  1.1.1.2  christos 	}
    222  1.1.1.2  christos 	test_gdb_complete_none \
    223  1.1.1.2  christos 	    "$set_cmd 1"
    224      1.1  christos 	test_gdb_complete_unique \
    225  1.1.1.2  christos 	    "$set_cmd u" \
    226      1.1  christos 	    "$set_cmd unlimited"
    227      1.1  christos     }
    228      1.1  christos 
    229      1.1  christos     # Check junk after "unlimited".
    230      1.1  christos     gdb_test "$set_cmd unlimitedu" "No symbol table is loaded.*"
    231      1.1  christos 
    232      1.1  christos     if {$variant == "zinteger" || $variant == "zuinteger"} {
    233      1.1  christos 	gdb_test "$set_cmd unlimited u" "No symbol table is loaded.*"
    234      1.1  christos 	gdb_test "$set_cmd unlimited 1" "No symbol table is loaded.*"
    235      1.1  christos 	gdb_test "$set_cmd unlimited -1" "No symbol table is loaded.*"
    236      1.1  christos     } else {
    237      1.1  christos 	gdb_test "$set_cmd unlimited u" "Junk after \"unlimited\": u"
    238      1.1  christos 	gdb_test "$set_cmd unlimited 1" "Junk after \"unlimited\": 1"
    239      1.1  christos 	gdb_test "$set_cmd unlimited -1" "Junk after \"unlimited\": -1"
    240      1.1  christos     }
    241      1.1  christos 
    242      1.1  christos     test_gdb_complete_none "$set_cmd unlimited "
    243      1.1  christos     test_gdb_complete_none "$set_cmd unlimitedu"
    244      1.1  christos     test_gdb_complete_none "$set_cmd unlimited u"
    245      1.1  christos     test_gdb_complete_none "$set_cmd unlimited 1"
    246      1.1  christos     test_gdb_complete_none "$set_cmd x"
    247      1.1  christos     test_gdb_complete_none "$set_cmd x "
    248      1.1  christos     test_gdb_complete_none "$set_cmd -1"
    249      1.1  christos     test_gdb_complete_none "$set_cmd -1 "
    250      1.1  christos     test_gdb_complete_none "$set_cmd 1 "
    251      1.1  christos 
    252      1.1  christos     # Check show command completion.
    253      1.1  christos     if {$variant == "zuinteger"} {
    254      1.1  christos 	test_gdb_complete_multiple "maintenance show test-settings " "zuinteger" "" {
    255      1.1  christos 	    "zuinteger"
    256      1.1  christos 	    "zuinteger-unlimited"
    257      1.1  christos 	}
    258      1.1  christos     } else {
    259      1.1  christos 	test_gdb_complete_unique \
    260      1.1  christos 	    "$show_cmd" \
    261      1.1  christos 	    "$show_cmd"
    262      1.1  christos     }
    263      1.1  christos     test_gdb_complete_none "$show_cmd "
    264      1.1  christos }
    265      1.1  christos 
    266      1.1  christos # boolean tests.
    267      1.1  christos proc_with_prefix test-boolean {} {
    268      1.1  christos     # Use these variables to make sure we don't call the wrong command
    269      1.1  christos     # by mistake.
    270      1.1  christos     set set_cmd "maint set test-settings boolean"
    271      1.1  christos     set show_cmd "maint show test-settings boolean"
    272      1.1  christos 
    273      1.1  christos     # A bogus value.
    274      1.1  christos     gdb_test "$set_cmd bogus" \
    275      1.1  christos 	"\"on\" or \"off\" expected\\."
    276      1.1  christos 
    277      1.1  christos     # Seemingly-valid but not quite valid value.
    278      1.1  christos     gdb_test "$set_cmd on1" \
    279      1.1  christos 	"\"on\" or \"off\" expected\\."
    280      1.1  christos 
    281      1.1  christos     # Valid value followed by garbage.
    282      1.1  christos     gdb_test "$set_cmd on 1" \
    283      1.1  christos 	"\"on\" or \"off\" expected\\."
    284      1.1  christos 
    285      1.1  christos     # Unlike auto-bool settings, "-1" is not accepted.
    286      1.1  christos     gdb_test "$set_cmd -1" \
    287      1.1  christos 	"\"on\" or \"off\" expected\\."
    288      1.1  christos 
    289      1.1  christos     # Nor "auto".
    290      1.1  christos     gdb_test "$set_cmd auto" \
    291      1.1  christos 	"\"on\" or \"off\" expected\\."
    292      1.1  christos 
    293      1.1  christos     # "o" is ambiguous.
    294      1.1  christos     gdb_test "$set_cmd o" \
    295      1.1  christos 	"\"on\" or \"off\" expected\\."
    296      1.1  christos 
    297      1.1  christos     # Various valid values.  Test both full value names and
    298      1.1  christos     # abbreviations.
    299      1.1  christos 
    300      1.1  christos     # Note that unlike with auto-bool, empty value implies "on".
    301      1.1  christos     foreach_with_prefix value {
    302      1.1  christos 	""
    303      1.1  christos 	"on"
    304      1.1  christos 	"1"
    305      1.1  christos 	"y"
    306      1.1  christos 	"ye"
    307      1.1  christos 	"yes"
    308      1.1  christos 	"e"
    309      1.1  christos 	"en"
    310      1.1  christos 	"ena"
    311      1.1  christos 	"enab"
    312      1.1  christos 	"enabl"
    313      1.1  christos 	"enable"
    314      1.1  christos     } {
    315      1.1  christos 	gdb_test_no_output "$set_cmd off"
    316      1.1  christos 	show_setting "$show_cmd" "off"
    317      1.1  christos 
    318      1.1  christos 	gdb_test_no_output "$set_cmd $value"
    319      1.1  christos 	show_setting "$show_cmd" "on"
    320      1.1  christos     }
    321      1.1  christos 
    322      1.1  christos     check_type "test-settings boolean" "type = int"
    323      1.1  christos 
    324      1.1  christos     foreach_with_prefix value {
    325      1.1  christos 	"of"
    326      1.1  christos 	"off"
    327      1.1  christos 	"0"
    328      1.1  christos 	"n"
    329      1.1  christos 	"no"
    330      1.1  christos 	"d"
    331      1.1  christos 	"di"
    332      1.1  christos 	"dis"
    333      1.1  christos 	"disa"
    334      1.1  christos 	"disab"
    335      1.1  christos 	"disabl"
    336      1.1  christos 	"disable"
    337      1.1  christos     } {
    338      1.1  christos 	gdb_test_no_output "$set_cmd on"
    339      1.1  christos 	show_setting "$show_cmd" "on"
    340      1.1  christos 
    341      1.1  christos 	gdb_test_no_output "$set_cmd $value"
    342      1.1  christos 	show_setting "$show_cmd" "off"
    343      1.1  christos     }
    344      1.1  christos 
    345      1.1  christos     test_gdb_complete_multiple "$set_cmd " "" "o" {
    346      1.1  christos 	"off"
    347      1.1  christos 	"on"
    348      1.1  christos     }
    349      1.1  christos 
    350      1.1  christos     test_gdb_complete_unique \
    351      1.1  christos 	"$set_cmd of" \
    352      1.1  christos 	"$set_cmd off"
    353      1.1  christos 
    354      1.1  christos     test_gdb_complete_none "$set_cmd x"
    355      1.1  christos 
    356      1.1  christos     # Check that the show command doesn't complete anything.
    357      1.1  christos     test_gdb_complete_unique \
    358      1.1  christos 	"$show_cmd" \
    359      1.1  christos 	"$show_cmd"
    360      1.1  christos     test_gdb_complete_none "$show_cmd "
    361      1.1  christos }
    362      1.1  christos 
    363      1.1  christos # auto-boolean tests.
    364      1.1  christos proc_with_prefix test-auto-boolean {} {
    365      1.1  christos     # Use these variables to make sure we don't call the wrong command
    366      1.1  christos     # by mistake.
    367      1.1  christos     set set_cmd "maint set test-settings auto-boolean"
    368      1.1  christos     set show_cmd "maint show test-settings auto-boolean"
    369      1.1  christos 
    370      1.1  christos     # A bogus value.
    371      1.1  christos     gdb_test "$set_cmd bogus" \
    372      1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    373      1.1  christos 
    374      1.1  christos     # Seemingly-valid but not quite valid value.
    375      1.1  christos     gdb_test "$set_cmd on1" \
    376      1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    377      1.1  christos 
    378      1.1  christos     # Valid value followed by garbage.
    379      1.1  christos     gdb_test "$set_cmd on 1" \
    380      1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    381      1.1  christos 
    382      1.1  christos     # "o" is ambiguous.
    383      1.1  christos     gdb_test "$set_cmd o" \
    384      1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    385      1.1  christos 
    386      1.1  christos     # Various valid values.  Test both full value names and
    387      1.1  christos     # abbreviations.
    388      1.1  christos 
    389      1.1  christos     foreach_with_prefix value {
    390      1.1  christos 	"on"
    391      1.1  christos 	"1"
    392      1.1  christos 	"y"
    393      1.1  christos 	"ye"
    394      1.1  christos 	"yes"
    395      1.1  christos 	"e"
    396      1.1  christos 	"en"
    397      1.1  christos 	"ena"
    398      1.1  christos 	"enab"
    399      1.1  christos 	"enabl"
    400      1.1  christos 	"enable"
    401      1.1  christos     } {
    402      1.1  christos 	gdb_test_no_output "$set_cmd off"
    403      1.1  christos 	show_setting "$show_cmd" "off"
    404      1.1  christos 
    405      1.1  christos 	gdb_test_no_output "$set_cmd $value"
    406      1.1  christos 	show_setting "$show_cmd" "on"
    407      1.1  christos     }
    408      1.1  christos 
    409      1.1  christos     foreach_with_prefix value {
    410      1.1  christos 	"of"
    411      1.1  christos 	"off"
    412      1.1  christos 	"0"
    413      1.1  christos 	"n"
    414      1.1  christos 	"no"
    415      1.1  christos 	"d"
    416      1.1  christos 	"di"
    417      1.1  christos 	"dis"
    418      1.1  christos 	"disa"
    419      1.1  christos 	"disab"
    420      1.1  christos 	"disabl"
    421      1.1  christos 	"disable"
    422      1.1  christos     } {
    423      1.1  christos 	gdb_test_no_output "$set_cmd on"
    424      1.1  christos 	show_setting "$show_cmd" "on"
    425      1.1  christos 
    426      1.1  christos 	gdb_test_no_output "$set_cmd $value"
    427      1.1  christos 	show_setting "$show_cmd" "off"
    428      1.1  christos     }
    429      1.1  christos 
    430      1.1  christos     foreach_with_prefix value {
    431      1.1  christos 	"a"
    432      1.1  christos 	"au"
    433      1.1  christos 	"aut"
    434      1.1  christos 	"auto"
    435      1.1  christos 	"-1"
    436      1.1  christos     } {
    437      1.1  christos 	gdb_test_no_output "$set_cmd on"
    438      1.1  christos 	show_setting "$show_cmd" "on"
    439      1.1  christos 
    440      1.1  christos 	gdb_test_no_output "$set_cmd $value"
    441      1.1  christos 	show_setting "$show_cmd" "auto"
    442      1.1  christos     }
    443      1.1  christos 
    444      1.1  christos     check_type "test-settings auto-boolean" "type = int"
    445      1.1  christos 
    446      1.1  christos     # "-" is not accepted as abbreviation of "-1".
    447      1.1  christos     gdb_test "$set_cmd -" \
    448      1.1  christos 	"\"on\", \"off\" or \"auto\" expected\\."
    449      1.1  christos 
    450      1.1  christos     test_gdb_complete_multiple "$set_cmd " "" "" {
    451      1.1  christos 	"auto"
    452      1.1  christos 	"off"
    453      1.1  christos 	"on"
    454      1.1  christos     }
    455      1.1  christos 
    456      1.1  christos     test_gdb_complete_unique \
    457      1.1  christos 	"$set_cmd of" \
    458      1.1  christos 	"$set_cmd off"
    459      1.1  christos 
    460      1.1  christos     test_gdb_complete_none "$set_cmd x"
    461      1.1  christos 
    462      1.1  christos     # Check that the show command doesn't complete anything.
    463      1.1  christos     test_gdb_complete_unique \
    464      1.1  christos 	"$show_cmd" \
    465      1.1  christos 	"$show_cmd"
    466      1.1  christos     test_gdb_complete_none "$show_cmd "
    467      1.1  christos }
    468      1.1  christos 
    469      1.1  christos # Enum option tests.
    470      1.1  christos proc_with_prefix test-enum {} {
    471      1.1  christos     # Use these variables to make sure we don't call the wrong command
    472      1.1  christos     # by mistake.
    473      1.1  christos     set set_cmd "maint set test-settings enum"
    474      1.1  christos     set show_cmd "maint show test-settings enum"
    475      1.1  christos 
    476      1.1  christos     # Missing value.
    477      1.1  christos     gdb_test "$set_cmd" \
    478      1.1  christos 	"Requires an argument\\. Valid arguments are xxx, yyy, zzz\\."
    479      1.1  christos 
    480      1.1  christos     # A bogus value.
    481      1.1  christos     gdb_test "$set_cmd bogus" \
    482      1.1  christos 	"Undefined item: \"bogus\"."
    483      1.1  christos 
    484      1.1  christos     # Seemingly-valid but not quite valid value.
    485      1.1  christos     gdb_test "$set_cmd xxx1" \
    486      1.1  christos 	"Undefined item: \"xxx1\"."
    487      1.1  christos 
    488      1.1  christos     # Valid value followed by garbage.
    489      1.1  christos     gdb_test "$set_cmd xxx 1" \
    490      1.1  christos 	"Junk after item \"xxx\": 1"
    491      1.1  christos     # Valid value followed by garbage, with extra spaces.
    492      1.1  christos     gdb_test "$set_cmd xxx      1" \
    493      1.1  christos 	"Junk after item \"xxx\": 1"
    494      1.1  christos     # Abbreviated value followed by garbage.
    495      1.1  christos     gdb_test "$set_cmd xx 1" \
    496      1.1  christos 	"Junk after item \"xx\": 1"
    497      1.1  christos 
    498      1.1  christos     # Various valid values.  Test both full value names and
    499      1.1  christos     # abbreviations.
    500      1.1  christos     gdb_test_no_output "$set_cmd x"
    501      1.1  christos     show_setting "$show_cmd" "xxx" 0 "zzz"
    502      1.1  christos     gdb_test_no_output "$set_cmd yy"
    503      1.1  christos     show_setting "$show_cmd" "yyy" 0 "zzz"
    504      1.1  christos     gdb_test_no_output "$set_cmd zzz"
    505      1.1  christos     show_setting "$show_cmd" "zzz" 0 "yyy"
    506      1.1  christos 
    507  1.1.1.3  christos     check_type "test-settings enum" "type = char \\\[4\\\]"
    508      1.1  christos 
    509      1.1  christos     test_gdb_complete_multiple "$set_cmd " "" "" {
    510      1.1  christos 	"xxx"
    511      1.1  christos 	"yyy"
    512      1.1  christos 	"zzz"
    513      1.1  christos     }
    514      1.1  christos 
    515      1.1  christos     test_gdb_complete_unique \
    516      1.1  christos 	"$set_cmd x" \
    517      1.1  christos 	"$set_cmd xxx"
    518      1.1  christos 
    519      1.1  christos     test_gdb_complete_none "$set_cmd a"
    520      1.1  christos 
    521      1.1  christos     # Check that the show command doesn't complete anything.
    522      1.1  christos     test_gdb_complete_unique \
    523      1.1  christos 	"$show_cmd" \
    524      1.1  christos 	"$show_cmd"
    525      1.1  christos     test_gdb_complete_none "$show_cmd "
    526      1.1  christos }
    527      1.1  christos 
    528      1.1  christos # string settings tests.
    529      1.1  christos proc test-string {variant} {
    530      1.1  christos     global gdb_prompt
    531      1.1  christos     global srcfile binfile
    532      1.1  christos 
    533      1.1  christos     # Load symbols for the completion test below.
    534      1.1  christos     clean_restart $binfile
    535      1.1  christos 
    536      1.1  christos     # Use these variables to make sure we don't call the wrong command
    537      1.1  christos     # by mistake.
    538      1.1  christos     set set_cmd "maint set test-settings $variant"
    539      1.1  christos     set show_cmd "maint show test-settings $variant"
    540      1.1  christos 
    541      1.1  christos     # Checks that gdb doesn't crash if we haven't set the string yet.
    542      1.1  christos     if {$variant != "filename"} {
    543  1.1.1.3  christos 	# This odd expected output here is because we expect GDB to
    544  1.1.1.3  christos 	# emit a single blank line as a result of this command.
    545  1.1.1.3  christos 	gdb_test -nonl "$show_cmd" "^\r\n" "$show_cmd: show default"
    546      1.1  christos     } else {
    547      1.1  christos 	gdb_test "$show_cmd" "/foo/bar" "$show_cmd: show default"
    548      1.1  christos     }
    549      1.1  christos 
    550      1.1  christos     # A string value.
    551      1.1  christos     gdb_test_no_output "$set_cmd hello world"
    552      1.1  christos     show_setting "$show_cmd" "hello world"
    553      1.1  christos 
    554      1.1  christos     check_type "test-settings $variant" "type = char \\\[\[1-9\]\[0-9\]*\\\]"
    555      1.1  christos 
    556      1.1  christos     # A quoted string value.
    557      1.1  christos     if {$variant == "string"} {
    558      1.1  christos 	gdb_test_no_output "$set_cmd \"hello world\""
    559      1.1  christos 	show_setting "$show_cmd" "\\\\\"hello world\\\\\"" 1
    560      1.1  christos     } else {
    561      1.1  christos 	gdb_test_no_output "$set_cmd \"hello world\""
    562      1.1  christos 	show_setting "$show_cmd" "\"hello world\""
    563      1.1  christos     }
    564      1.1  christos 
    565      1.1  christos     # Test clearing the string.
    566      1.1  christos     with_test_prefix "clear string" {
    567      1.1  christos 	if {$variant == "filename"} {
    568      1.1  christos 	    gdb_test "$set_cmd" \
    569      1.1  christos 		"Argument required \\(filename to set it to\\.\\)\\."
    570      1.1  christos 
    571      1.1  christos 	    # Check the value didn't change.
    572      1.1  christos 	    show_setting "$show_cmd" "\"hello world\""
    573      1.1  christos 	} else {
    574      1.1  christos 	    gdb_test_no_output "$set_cmd"
    575  1.1.1.3  christos 	    # This odd expected output here is because we expect GDB to
    576  1.1.1.3  christos 	    # emit a single blank line as a result of this command.
    577  1.1.1.3  christos 	    gdb_test -nonl "$show_cmd" "^\r\n" "$show_cmd: empty second time"
    578      1.1  christos 	}
    579      1.1  christos     }
    580      1.1  christos 
    581      1.1  christos     # Test completion.
    582      1.1  christos     if {$variant == "string" || $variant == "string-noescape" } {
    583      1.1  christos 	# Make sure GDB doesn't try to complete on symbols, which
    584      1.1  christos 	# doesn't make any sense.
    585      1.1  christos 	test_gdb_complete_none "$set_cmd "
    586      1.1  christos     } else {
    587      1.1  christos 	# Complete on filename.
    588      1.1  christos 
    589      1.1  christos 	# See comments in gdb.base/completion.exp.
    590      1.1  christos 
    591      1.1  christos 	# We `cd' to ${srcdir}, and then do the completion relative to
    592      1.1  christos 	# the current directory.
    593      1.1  christos 
    594      1.1  christos 	# ${srcdir} may be a relative path.  We want to make sure we
    595      1.1  christos 	# end up in the right directory - so make sure we know where
    596      1.1  christos 	# it is.
    597  1.1.1.2  christos 	with_cwd $::srcdir {
    598  1.1.1.2  christos 	    set fullsrcdir [pwd]
    599  1.1.1.2  christos 	}
    600      1.1  christos 
    601      1.1  christos 	gdb_test "cd ${fullsrcdir}" \
    602      1.1  christos 	    "Working directory [string_to_regexp ${fullsrcdir}].*" \
    603      1.1  christos 	    "cd to \${srcdir}"
    604      1.1  christos 
    605      1.1  christos 	set unique_file ../testsuite/gdb.base/comp-dir/subdir/dummy
    606      1.1  christos 
    607      1.1  christos 	test_gdb_complete_unique \
    608      1.1  christos 	    "$set_cmd ${unique_file}" \
    609      1.1  christos 	    "$set_cmd ${unique_file}.txt"
    610      1.1  christos 
    611      1.1  christos 	test_gdb_complete_none "$set_cmd ${unique_file}.abc"
    612      1.1  christos     }
    613      1.1  christos 
    614      1.1  christos     # Check show command completion.
    615      1.1  christos     if {$variant == "string"} {
    616      1.1  christos 	test_gdb_complete_multiple "maint show test-settings " "string" "" {
    617      1.1  christos 	    "string"
    618      1.1  christos 	    "string-noescape"
    619      1.1  christos 	}
    620      1.1  christos     } else {
    621      1.1  christos 	test_gdb_complete_unique \
    622      1.1  christos 	    "$show_cmd" \
    623      1.1  christos 	    "$show_cmd"
    624      1.1  christos     }
    625      1.1  christos     test_gdb_complete_none "$show_cmd "
    626      1.1  christos }
    627      1.1  christos 
    628  1.1.1.3  christos # Check that $_gdb_setting & co report the correct error strings.
    629  1.1.1.3  christos proc test-setting-error {} {
    630  1.1.1.3  christos     gdb_test {print $_gdb_setting("xxx")} \
    631  1.1.1.3  christos 	"First argument of \\\$_gdb_setting must be a valid setting of the 'show' command\\."
    632  1.1.1.3  christos     gdb_test {print $_gdb_setting_str("xxx")} \
    633  1.1.1.3  christos 	"First argument of \\\$_gdb_setting_str must be a valid setting of the 'show' command\\."
    634  1.1.1.3  christos 
    635  1.1.1.3  christos     gdb_test {print $_gdb_maint_setting("xxx")} \
    636  1.1.1.3  christos 	"First argument of \\\$_gdb_maint_setting must be a valid setting of the 'maintenance show' command\\."
    637  1.1.1.3  christos     gdb_test {print $_gdb_maint_setting_str("xxx")} \
    638  1.1.1.3  christos 	"First argument of \\\$_gdb_maint_setting_str must be a valid setting of the 'maintenance show' command\\."
    639  1.1.1.3  christos }
    640  1.1.1.3  christos 
    641      1.1  christos foreach variant {
    642      1.1  christos     uinteger
    643      1.1  christos     integer
    644      1.1  christos     zinteger
    645      1.1  christos     zuinteger
    646      1.1  christos     zuinteger-unlimited
    647      1.1  christos } {
    648      1.1  christos     with_test_prefix "test-integer $variant" {
    649      1.1  christos 	test-integer $variant
    650      1.1  christos     }
    651      1.1  christos }
    652      1.1  christos 
    653      1.1  christos test-boolean
    654      1.1  christos test-auto-boolean
    655      1.1  christos test-enum
    656      1.1  christos 
    657      1.1  christos foreach variant {
    658      1.1  christos     string
    659      1.1  christos     string-noescape
    660      1.1  christos     optional-filename
    661      1.1  christos     filename
    662      1.1  christos } {
    663      1.1  christos     with_test_prefix "test-string $variant" {
    664      1.1  christos 	test-string $variant
    665      1.1  christos     }
    666      1.1  christos }
    667  1.1.1.3  christos 
    668  1.1.1.3  christos test-setting-error
    669