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