1""" 2Test lldb settings command. 3""" 4 5 6 7import os 8import re 9import lldb 10from lldbsuite.test.decorators import * 11from lldbsuite.test.lldbtest import * 12from lldbsuite.test import lldbutil 13 14 15class SettingsCommandTestCase(TestBase): 16 17 mydir = TestBase.compute_mydir(__file__) 18 NO_DEBUG_INFO_TESTCASE = True 19 20 def test_apropos_should_also_search_settings_description(self): 21 """Test that 'apropos' command should also search descriptions for the settings variables.""" 22 23 self.expect("apropos 'environment variable'", 24 substrs=["target.env-vars", 25 "environment variables", 26 "executable's environment"]) 27 28 def test_append_target_env_vars(self): 29 """Test that 'append target.run-args' works.""" 30 # Append the env-vars. 31 self.runCmd('settings append target.env-vars MY_ENV_VAR=YES') 32 # And add hooks to restore the settings during tearDown(). 33 self.addTearDownHook( 34 lambda: self.runCmd("settings clear target.env-vars")) 35 36 # Check it immediately! 37 self.expect('settings show target.env-vars', 38 substrs=['MY_ENV_VAR=YES']) 39 40 def test_insert_before_and_after_target_run_args(self): 41 """Test that 'insert-before/after target.run-args' works.""" 42 # Set the run-args first. 43 self.runCmd('settings set target.run-args a b c') 44 # And add hooks to restore the settings during tearDown(). 45 self.addTearDownHook( 46 lambda: self.runCmd("settings clear target.run-args")) 47 48 # Now insert-before the index-0 element with '__a__'. 49 self.runCmd('settings insert-before target.run-args 0 __a__') 50 # And insert-after the index-1 element with '__A__'. 51 self.runCmd('settings insert-after target.run-args 1 __A__') 52 # Check it immediately! 53 self.expect('settings show target.run-args', 54 substrs=['target.run-args', 55 '[0]: "__a__"', 56 '[1]: "a"', 57 '[2]: "__A__"', 58 '[3]: "b"', 59 '[4]: "c"']) 60 61 def test_replace_target_run_args(self): 62 """Test that 'replace target.run-args' works.""" 63 # Set the run-args and then replace the index-0 element. 64 self.runCmd('settings set target.run-args a b c') 65 # And add hooks to restore the settings during tearDown(). 66 self.addTearDownHook( 67 lambda: self.runCmd("settings clear target.run-args")) 68 69 # Now replace the index-0 element with 'A', instead. 70 self.runCmd('settings replace target.run-args 0 A') 71 # Check it immediately! 72 self.expect('settings show target.run-args', 73 substrs=['target.run-args (arguments) =', 74 '[0]: "A"', 75 '[1]: "b"', 76 '[2]: "c"']) 77 78 def test_set_prompt(self): 79 """Test that 'set prompt' actually changes the prompt.""" 80 81 # Set prompt to 'lldb2'. 82 self.runCmd("settings set prompt 'lldb2 '") 83 84 # Immediately test the setting. 85 self.expect("settings show prompt", SETTING_MSG("prompt"), 86 startstr='prompt (string) = "lldb2 "') 87 88 # The overall display should also reflect the new setting. 89 self.expect("settings show", SETTING_MSG("prompt"), 90 substrs=['prompt (string) = "lldb2 "']) 91 92 # Use '-r' option to reset to the original default prompt. 93 self.runCmd("settings clear prompt") 94 95 def test_set_term_width(self): 96 """Test that 'set term-width' actually changes the term-width.""" 97 98 self.runCmd("settings set term-width 70") 99 100 # Immediately test the setting. 101 self.expect("settings show term-width", SETTING_MSG("term-width"), 102 startstr="term-width (int) = 70") 103 104 # The overall display should also reflect the new setting. 105 self.expect("settings show", SETTING_MSG("term-width"), 106 substrs=["term-width (int) = 70"]) 107 108 # rdar://problem/10712130 109 @skipIf(oslist=["windows"], bugnumber="llvm.org/pr44431") 110 def test_set_frame_format(self): 111 """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath.""" 112 self.build() 113 114 exe = self.getBuildArtifact("a.out") 115 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 116 117 def cleanup(): 118 self.runCmd( 119 "settings set frame-format %s" % 120 self.format_string, check=False) 121 122 # Execute the cleanup function during test case tear down. 123 self.addTearDownHook(cleanup) 124 125 self.runCmd("settings show frame-format") 126 m = re.match( 127 '^frame-format \(format-string\) = "(.*)\"$', 128 self.res.GetOutput()) 129 self.assertTrue(m, "Bad settings string") 130 self.format_string = m.group(1) 131 132 # Change the default format to print function.name rather than 133 # function.name-with-args 134 format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}\`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}{, lang=${language}}\n" 135 self.runCmd("settings set frame-format %s" % format_string) 136 137 # Immediately test the setting. 138 self.expect("settings show frame-format", SETTING_MSG("frame-format"), 139 substrs=[format_string]) 140 141 self.runCmd("breakpoint set -n main") 142 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 143 RUN_SUCCEEDED) 144 self.expect("thread backtrace", 145 substrs=["`main", self.getSourceDir()]) 146 147 def test_set_auto_confirm(self): 148 """Test that after 'set auto-confirm true', manual confirmation should not kick in.""" 149 self.build() 150 151 exe = self.getBuildArtifact("a.out") 152 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 153 154 self.runCmd("settings set auto-confirm true") 155 156 # Immediately test the setting. 157 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), 158 startstr="auto-confirm (boolean) = true") 159 160 # Now 'breakpoint delete' should just work fine without confirmation 161 # prompt from the command interpreter. 162 self.runCmd("breakpoint set -n main") 163 self.expect("breakpoint delete", 164 startstr="All breakpoints removed") 165 166 # Restore the original setting of auto-confirm. 167 self.runCmd("settings clear auto-confirm") 168 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"), 169 startstr="auto-confirm (boolean) = false") 170 171 @skipIf(archs=no_match(['x86_64', 'i386', 'i686'])) 172 def test_disassembler_settings(self): 173 """Test that user options for the disassembler take effect.""" 174 self.build() 175 176 exe = self.getBuildArtifact("a.out") 177 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 178 179 # AT&T syntax 180 self.runCmd("settings set target.x86-disassembly-flavor att") 181 self.runCmd("settings set target.use-hex-immediates false") 182 self.expect("disassemble -n numberfn", 183 substrs=["$90"]) 184 self.runCmd("settings set target.use-hex-immediates true") 185 self.runCmd("settings set target.hex-immediate-style c") 186 self.expect("disassemble -n numberfn", 187 substrs=["$0x5a"]) 188 self.runCmd("settings set target.hex-immediate-style asm") 189 self.expect("disassemble -n numberfn", 190 substrs=["$5ah"]) 191 192 # Intel syntax 193 self.runCmd("settings set target.x86-disassembly-flavor intel") 194 self.runCmd("settings set target.use-hex-immediates false") 195 self.expect("disassemble -n numberfn", 196 substrs=["90"]) 197 self.runCmd("settings set target.use-hex-immediates true") 198 self.runCmd("settings set target.hex-immediate-style c") 199 self.expect("disassemble -n numberfn", 200 substrs=["0x5a"]) 201 self.runCmd("settings set target.hex-immediate-style asm") 202 self.expect("disassemble -n numberfn", 203 substrs=["5ah"]) 204 205 @skipIfDarwinEmbedded # <rdar://problem/34446098> debugserver on ios etc can't write files 206 def test_run_args_and_env_vars(self): 207 self.do_test_run_args_and_env_vars(use_launchsimple=False) 208 209 @skipIfDarwinEmbedded # <rdar://problem/34446098> debugserver on ios etc can't write files 210 def test_launchsimple_args_and_env_vars(self): 211 self.do_test_run_args_and_env_vars(use_launchsimple=True) 212 213 def do_test_run_args_and_env_vars(self, use_launchsimple): 214 """Test that run-args and env-vars are passed to the launched process.""" 215 self.build() 216 217 # Set the run-args and the env-vars. 218 # And add hooks to restore the settings during tearDown(). 219 self.runCmd('settings set target.run-args A B C') 220 self.addTearDownHook( 221 lambda: self.runCmd("settings clear target.run-args")) 222 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES') 223 self.addTearDownHook( 224 lambda: self.runCmd("settings clear target.env-vars")) 225 226 exe = self.getBuildArtifact("a.out") 227 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 228 229 target = self.dbg.GetTargetAtIndex(0) 230 launch_info = target.GetLaunchInfo() 231 found_env_var = False 232 for i in range(0, launch_info.GetNumEnvironmentEntries()): 233 if launch_info.GetEnvironmentEntryAtIndex(i) == "MY_ENV_VAR=YES": 234 found_env_var = True 235 break 236 self.assertTrue(found_env_var, 237 "MY_ENV_VAR was not set in LunchInfo object") 238 239 self.expect( 240 'target show-launch-environment', 241 substrs=["MY_ENV_VAR=YES"]) 242 243 wd = self.get_process_working_directory() 244 if use_launchsimple: 245 process = target.LaunchSimple(None, None, wd) 246 self.assertTrue(process) 247 else: 248 self.runCmd("process launch --working-dir '{0}'".format(wd), 249 RUN_SUCCEEDED) 250 251 # Read the output file produced by running the program. 252 output = lldbutil.read_file_from_process_wd(self, "output2.txt") 253 254 self.expect( 255 output, 256 exe=False, 257 substrs=[ 258 "argv[1] matches", 259 "argv[2] matches", 260 "argv[3] matches", 261 "Environment variable 'MY_ENV_VAR' successfully passed."]) 262 263 # Check that env-vars overrides unset-env-vars. 264 self.runCmd('settings set target.unset-env-vars MY_ENV_VAR') 265 266 self.expect( 267 'target show-launch-environment', 268 'env-vars overrides unset-env-vars', 269 substrs=["MY_ENV_VAR=YES"]) 270 271 wd = self.get_process_working_directory() 272 if use_launchsimple: 273 process = target.LaunchSimple(None, None, wd) 274 self.assertTrue(process) 275 else: 276 self.runCmd("process launch --working-dir '{0}'".format(wd), 277 RUN_SUCCEEDED) 278 279 # Read the output file produced by running the program. 280 output = lldbutil.read_file_from_process_wd(self, "output2.txt") 281 282 self.expect( 283 output, 284 exe=False, 285 substrs=[ 286 "Environment variable 'MY_ENV_VAR' successfully passed."]) 287 288 @skipIfRemote # it doesn't make sense to send host env to remote target 289 def test_pass_host_env_vars(self): 290 """Test that the host env vars are passed to the launched process.""" 291 self.build() 292 293 # Set some host environment variables now. 294 os.environ["MY_HOST_ENV_VAR1"] = "VAR1" 295 os.environ["MY_HOST_ENV_VAR2"] = "VAR2" 296 297 # This is the function to unset the two env variables set above. 298 def unset_env_variables(): 299 os.environ.pop("MY_HOST_ENV_VAR1") 300 os.environ.pop("MY_HOST_ENV_VAR2") 301 self.addTearDownHook(unset_env_variables) 302 303 exe = self.getBuildArtifact("a.out") 304 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 305 306 # By default, inherit-env is 'true'. 307 self.expect( 308 'settings show target.inherit-env', 309 "Default inherit-env is 'true'", 310 startstr="target.inherit-env (boolean) = true") 311 312 self.expect( 313 'target show-launch-environment', 314 'Host environment is passed correctly', 315 substrs=['MY_HOST_ENV_VAR1=VAR1', 'MY_HOST_ENV_VAR2=VAR2']) 316 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 317 RUN_SUCCEEDED) 318 319 # Read the output file produced by running the program. 320 output = lldbutil.read_file_from_process_wd(self, "output1.txt") 321 322 self.expect( 323 output, 324 exe=False, 325 substrs=[ 326 "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", 327 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) 328 329 # Now test that we can prevent the inferior from inheriting the 330 # environment. 331 self.runCmd('settings set target.inherit-env false') 332 333 self.expect( 334 'target show-launch-environment', 335 'target.inherit-env affects `target show-launch-environment`', 336 matching=False, 337 substrs = ['MY_HOST_ENV_VAR1=VAR1', 'MY_HOST_ENV_VAR2=VAR2']) 338 339 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 340 RUN_SUCCEEDED) 341 342 # Read the output file produced by running the program. 343 output = lldbutil.read_file_from_process_wd(self, "output1.txt") 344 345 self.expect( 346 output, 347 exe=False, 348 matching=False, 349 substrs=[ 350 "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", 351 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) 352 353 # Now test that we can unset variables from the inherited environment. 354 self.runCmd('settings set target.inherit-env true') 355 self.runCmd('settings set target.unset-env-vars MY_HOST_ENV_VAR1') 356 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 357 RUN_SUCCEEDED) 358 359 # Read the output file produced by running the program. 360 output = lldbutil.read_file_from_process_wd(self, "output1.txt") 361 362 self.expect( 363 'target show-launch-environment', 364 'MY_HOST_ENV_VAR1 is unset, it shouldn\'t be in `target show-launch-environment`', 365 matching=False, 366 substrs = ['MY_HOST_ENV_VAR1=VAR1']) 367 self.expect( 368 'target show-launch-environment', 369 'MY_HOST_ENV_VAR2 shouldn be in `target show-launch-environment`', 370 substrs = ['MY_HOST_ENV_VAR2=VAR2']) 371 372 self.expect( 373 output, 374 exe=False, 375 matching=False, 376 substrs=[ 377 "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed."]) 378 self.expect( 379 output, 380 exe=False, 381 substrs=[ 382 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) 383 384 @skipIfDarwinEmbedded # <rdar://problem/34446098> debugserver on ios etc can't write files 385 def test_set_error_output_path(self): 386 """Test that setting target.error/output-path for the launched process works.""" 387 self.build() 388 389 exe = self.getBuildArtifact("a.out") 390 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 391 392 # Set the error-path and output-path and verify both are set. 393 self.runCmd("settings set target.error-path '{0}'".format( 394 lldbutil.append_to_process_working_directory(self, "stderr.txt"))) 395 self.runCmd("settings set target.output-path '{0}".format( 396 lldbutil.append_to_process_working_directory(self, "stdout.txt"))) 397 # And add hooks to restore the original settings during tearDown(). 398 self.addTearDownHook( 399 lambda: self.runCmd("settings clear target.output-path")) 400 self.addTearDownHook( 401 lambda: self.runCmd("settings clear target.error-path")) 402 403 self.expect("settings show target.error-path", 404 SETTING_MSG("target.error-path"), 405 substrs=['target.error-path (file)', 'stderr.txt"']) 406 407 self.expect("settings show target.output-path", 408 SETTING_MSG("target.output-path"), 409 substrs=['target.output-path (file)', 'stdout.txt"']) 410 411 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 412 RUN_SUCCEEDED) 413 414 output = lldbutil.read_file_from_process_wd(self, "stderr.txt") 415 message = "This message should go to standard error." 416 if lldbplatformutil.hasChattyStderr(self): 417 self.expect(output, exe=False, substrs=[message]) 418 else: 419 self.expect(output, exe=False, startstr=message) 420 421 output = lldbutil.read_file_from_process_wd(self, "stdout.txt") 422 self.expect(output, exe=False, 423 startstr="This message should go to standard out.") 424 425 def test_print_dictionary_setting(self): 426 self.runCmd("settings clear target.env-vars") 427 self.runCmd("settings set target.env-vars [\"MY_VAR\"]=some-value") 428 self.expect("settings show target.env-vars", 429 substrs=["MY_VAR=some-value"]) 430 self.runCmd("settings clear target.env-vars") 431 432 def test_print_array_setting(self): 433 self.runCmd("settings clear target.run-args") 434 self.runCmd("settings set target.run-args gobbledy-gook") 435 self.expect("settings show target.run-args", 436 substrs=['[0]: "gobbledy-gook"']) 437 self.runCmd("settings clear target.run-args") 438 439 def test_settings_with_quotes(self): 440 self.runCmd("settings clear target.run-args") 441 self.runCmd("settings set target.run-args a b c") 442 self.expect("settings show target.run-args", 443 substrs=['[0]: "a"', 444 '[1]: "b"', 445 '[2]: "c"']) 446 self.runCmd("settings set target.run-args 'a b c'") 447 self.expect("settings show target.run-args", 448 substrs=['[0]: "a b c"']) 449 self.runCmd("settings clear target.run-args") 450 self.runCmd("settings clear target.env-vars") 451 self.runCmd( 452 'settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"') 453 self.expect("settings show target.env-vars", 454 substrs=['MY_FILE=this is a file name with spaces.txt']) 455 self.runCmd("settings clear target.env-vars") 456 # Test and make sure that setting "format-string" settings obeys quotes 457 # if they are provided 458 self.runCmd("settings set thread-format 'abc def' ") 459 self.expect("settings show thread-format", 460 'thread-format (format-string) = "abc def"') 461 self.runCmd('settings set thread-format "abc def" ') 462 self.expect("settings show thread-format", 463 'thread-format (format-string) = "abc def"') 464 # Make sure when no quotes are provided that we maintain any trailing 465 # spaces 466 self.runCmd('settings set thread-format abc def ') 467 self.expect("settings show thread-format", 468 'thread-format (format-string) = "abc def "') 469 self.runCmd('settings clear thread-format') 470 471 def test_settings_with_trailing_whitespace(self): 472 473 # boolean 474 # Set to known value 475 self.runCmd("settings set target.skip-prologue true") 476 # Set to new value with trailing whitespace 477 self.runCmd("settings set target.skip-prologue false ") 478 # Make sure the setting was correctly set to "false" 479 self.expect( 480 "settings show target.skip-prologue", 481 SETTING_MSG("target.skip-prologue"), 482 startstr="target.skip-prologue (boolean) = false") 483 self.runCmd("settings clear target.skip-prologue", check=False) 484 # integer 485 self.runCmd("settings set term-width 70") # Set to known value 486 # Set to new value with trailing whitespaces 487 self.runCmd("settings set term-width 60 \t") 488 self.expect("settings show term-width", SETTING_MSG("term-width"), 489 startstr="term-width (int) = 60") 490 self.runCmd("settings clear term-width", check=False) 491 # string 492 self.runCmd("settings set target.arg0 abc") # Set to known value 493 # Set to new value with trailing whitespaces 494 self.runCmd("settings set target.arg0 cde\t ") 495 self.expect("settings show target.arg0", SETTING_MSG("target.arg0"), 496 startstr='target.arg0 (string) = "cde"') 497 self.runCmd("settings clear target.arg0", check=False) 498 # file 499 path1 = self.getBuildArtifact("path1.txt") 500 path2 = self.getBuildArtifact("path2.txt") 501 self.runCmd( 502 "settings set target.output-path %s" % 503 path1) # Set to known value 504 self.expect( 505 "settings show target.output-path", 506 SETTING_MSG("target.output-path"), 507 startstr='target.output-path (file) = ', 508 substrs=[path1]) 509 self.runCmd("settings set target.output-path %s " % 510 path2) # Set to new value with trailing whitespaces 511 self.expect( 512 "settings show target.output-path", 513 SETTING_MSG("target.output-path"), 514 startstr='target.output-path (file) = ', 515 substrs=[path2]) 516 self.runCmd("settings clear target.output-path", check=False) 517 # enum 518 # Set to known value 519 self.runCmd("settings set stop-disassembly-display never") 520 # Set to new value with trailing whitespaces 521 self.runCmd("settings set stop-disassembly-display always ") 522 self.expect( 523 "settings show stop-disassembly-display", 524 SETTING_MSG("stop-disassembly-display"), 525 startstr='stop-disassembly-display (enum) = always') 526 self.runCmd("settings clear stop-disassembly-display", check=False) 527 # language 528 # Set to known value 529 self.runCmd("settings set target.language c89") 530 # Set to new value with trailing whitespace 531 self.runCmd("settings set target.language c11 ") 532 self.expect( 533 "settings show target.language", 534 SETTING_MSG("target.language"), 535 startstr="target.language (language) = c11") 536 self.runCmd("settings clear target.language", check=False) 537 # arguments 538 self.runCmd("settings set target.run-args 1 2 3") # Set to known value 539 # Set to new value with trailing whitespaces 540 self.runCmd("settings set target.run-args 3 4 5 ") 541 self.expect( 542 "settings show target.run-args", 543 SETTING_MSG("target.run-args"), 544 substrs=[ 545 'target.run-args (arguments) =', 546 '[0]: "3"', 547 '[1]: "4"', 548 '[2]: "5"']) 549 self.runCmd("settings set target.run-args 1 2 3") # Set to known value 550 # Set to new value with trailing whitespaces 551 self.runCmd("settings set target.run-args 3 \ \ ") 552 self.expect( 553 "settings show target.run-args", 554 SETTING_MSG("target.run-args"), 555 substrs=[ 556 'target.run-args (arguments) =', 557 '[0]: "3"', 558 '[1]: " "', 559 '[2]: " "']) 560 self.runCmd("settings clear target.run-args", check=False) 561 # dictionaries 562 self.runCmd("settings clear target.env-vars") # Set to known value 563 # Set to new value with trailing whitespaces 564 self.runCmd("settings set target.env-vars A=B C=D\t ") 565 self.expect( 566 "settings show target.env-vars", 567 SETTING_MSG("target.env-vars"), 568 substrs=[ 569 'target.env-vars (dictionary of strings) =', 570 'A=B', 571 'C=D']) 572 self.runCmd("settings clear target.env-vars", check=False) 573 # regex 574 # Set to known value 575 self.runCmd("settings clear target.process.thread.step-avoid-regexp") 576 # Set to new value with trailing whitespaces 577 self.runCmd( 578 "settings set target.process.thread.step-avoid-regexp foo\\ ") 579 self.expect( 580 "settings show target.process.thread.step-avoid-regexp", 581 SETTING_MSG("target.process.thread.step-avoid-regexp"), 582 substrs=['target.process.thread.step-avoid-regexp (regex) = foo\\ ']) 583 self.runCmd( 584 "settings clear target.process.thread.step-avoid-regexp", 585 check=False) 586 # format-string 587 self.runCmd("settings clear disassembly-format") # Set to known value 588 # Set to new value with trailing whitespaces 589 self.runCmd("settings set disassembly-format foo ") 590 self.expect("settings show disassembly-format", 591 SETTING_MSG("disassembly-format"), 592 substrs=['disassembly-format (format-string) = "foo "']) 593 self.runCmd("settings clear disassembly-format", check=False) 594 595 def test_settings_list(self): 596 # List settings (and optionally test the filter to only show 'target' settings). 597 self.expect("settings list target", substrs=["arg0", "detach-on-error", "language"]) 598 self.expect("settings list target", matching=False, substrs=["packet-timeout"]) 599 self.expect("settings list", substrs=["language", "arg0", "detach-on-error", "packet-timeout"]) 600 601 def test_settings_remove_single(self): 602 # Set some environment variables and use 'remove' to delete them. 603 self.runCmd("settings set target.env-vars a=b c=d") 604 self.expect("settings show target.env-vars", substrs=["a=b", "c=d"]) 605 self.runCmd("settings remove target.env-vars a") 606 self.expect("settings show target.env-vars", matching=False, substrs=["a=b"]) 607 self.expect("settings show target.env-vars", substrs=["c=d"]) 608 self.runCmd("settings remove target.env-vars c") 609 self.expect("settings show target.env-vars", matching=False, substrs=["a=b", "c=d"]) 610 611 def test_settings_remove_multiple(self): 612 self.runCmd("settings set target.env-vars a=b c=d e=f") 613 self.expect("settings show target.env-vars", substrs=["a=b", "c=d", "e=f"]) 614 self.runCmd("settings remove target.env-vars a e") 615 self.expect("settings show target.env-vars", matching=False, substrs=["a=b", "e=f"]) 616 self.expect("settings show target.env-vars", substrs=["c=d"]) 617 618 def test_settings_remove_nonexistent_value(self): 619 self.expect("settings remove target.env-vars doesntexist", error=True, 620 substrs=["no value found named 'doesntexist'"]) 621 622 def test_settings_remove_nonexistent_settings(self): 623 self.expect("settings remove doesntexist alsodoesntexist", error=True, 624 substrs=["error: invalid value path 'doesntexist'"]) 625 626 def test_settings_remove_missing_arg(self): 627 self.expect("settings remove", error=True, 628 substrs=["'settings remove' takes an array or dictionary item, or"]) 629 630 def test_settings_remove_empty_arg(self): 631 self.expect("settings remove ''", error=True, 632 substrs=["'settings remove' command requires a valid variable name"]) 633 634 def test_settings_clear_all(self): 635 # Change a dictionary. 636 self.runCmd("settings set target.env-vars a=1 b=2 c=3") 637 # Change an array. 638 self.runCmd("settings set target.run-args a1 b2 c3") 639 # Change a single boolean value. 640 self.runCmd("settings set auto-confirm true") 641 # Change a single integer value. 642 self.runCmd("settings set tab-size 2") 643 644 # Clear everything. 645 self.runCmd("settings clear --all") 646 647 # Check that settings have their default values after clearing. 648 self.expect("settings show target.env-vars", patterns=['^target.env-vars \(dictionary of strings\) =\s*$']) 649 self.expect("settings show target.run-args", patterns=['^target.run-args \(arguments\) =\s*$']) 650 self.expect("settings show auto-confirm", substrs=["false"]) 651 self.expect("settings show tab-size", substrs=["4"]) 652 653 # Check that the command fails if we combine '--all' option with any arguments. 654 self.expect( 655 "settings clear --all auto-confirm", 656 COMMAND_FAILED_AS_EXPECTED, 657 error=True, 658 substrs=["'settings clear --all' doesn't take any arguments"]) 659 660 def test_all_settings_exist(self): 661 self.expect("settings show", 662 substrs=["auto-confirm", 663 "frame-format", 664 "notify-void", 665 "prompt", 666 "script-lang", 667 "stop-disassembly-count", 668 "stop-disassembly-display", 669 "stop-line-count-after", 670 "stop-line-count-before", 671 "stop-show-column", 672 "term-width", 673 "thread-format", 674 "use-external-editor", 675 "target.breakpoints-use-platform-avoid-list", 676 "target.default-arch", 677 "target.disable-aslr", 678 "target.disable-stdio", 679 "target.x86-disassembly-flavor", 680 "target.enable-synthetic-value", 681 "target.env-vars", 682 "target.error-path", 683 "target.exec-search-paths", 684 "target.expr-prefix", 685 "target.hex-immediate-style", 686 "target.inherit-env", 687 "target.input-path", 688 "target.language", 689 "target.max-children-count", 690 "target.max-string-summary-length", 691 "target.move-to-nearest-code", 692 "target.output-path", 693 "target.prefer-dynamic-value", 694 "target.run-args", 695 "target.skip-prologue", 696 "target.source-map", 697 "target.use-hex-immediates", 698 "target.process.disable-memory-cache", 699 "target.process.extra-startup-command", 700 "target.process.thread.trace-thread", 701 "target.process.thread.step-avoid-regexp", 702 ]) 703 704 # settings under an ".experimental" domain should have two properties: 705 # 1. If the name does not exist with "experimental" in the name path, 706 # the name lookup should try to find it without "experimental". So 707 # a previously-experimental setting that has been promoted to a 708 # "real" setting will still be set by the original name. 709 # 2. Changing a setting with .experimental., name, where the setting 710 # does not exist either with ".experimental." or without, should 711 # not generate an error. So if an experimental setting is removed, 712 # people who may have that in their ~/.lldbinit files should not see 713 # any errors. 714 def test_experimental_settings(self): 715 cmdinterp = self.dbg.GetCommandInterpreter() 716 result = lldb.SBCommandReturnObject() 717 718 # Set target.arg0 to a known value, check that we can retrieve it via 719 # the actual name and via .experimental. 720 self.expect('settings set target.arg0 first-value') 721 self.expect('settings show target.arg0', substrs=['first-value']) 722 self.expect('settings show target.experimental.arg0', substrs=['first-value'], error=False) 723 724 # Set target.arg0 to a new value via a target.experimental.arg0 name, 725 # verify that we can read it back via both .experimental., and not. 726 self.expect('settings set target.experimental.arg0 second-value', error=False) 727 self.expect('settings show target.arg0', substrs=['second-value']) 728 self.expect('settings show target.experimental.arg0', substrs=['second-value'], error=False) 729 730 # showing & setting an undefined .experimental. setting should generate no errors. 731 self.expect('settings show target.experimental.setting-which-does-not-exist', patterns=['^\s$'], error=False) 732 self.expect('settings set target.experimental.setting-which-does-not-exist true', error=False) 733 734 # A domain component before .experimental. which does not exist should give an error 735 # But the code does not yet do that. 736 # self.expect('settings set target.setting-which-does-not-exist.experimental.arg0 true', error=True) 737 738 # finally, confirm that trying to set a setting that does not exist still fails. 739 # (SHOWING a setting that does not exist does not currently yield an error.) 740 self.expect('settings set target.setting-which-does-not-exist true', error=True) 741