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 @skipIfReproducer 207 def test_run_args_and_env_vars(self): 208 self.do_test_run_args_and_env_vars(use_launchsimple=False) 209 210 @skipIfDarwinEmbedded # <rdar://problem/34446098> debugserver on ios etc can't write files 211 @skipIfReproducer 212 def test_launchsimple_args_and_env_vars(self): 213 self.do_test_run_args_and_env_vars(use_launchsimple=True) 214 215 def do_test_run_args_and_env_vars(self, use_launchsimple): 216 """Test that run-args and env-vars are passed to the launched process.""" 217 self.build() 218 219 # Set the run-args and the env-vars. 220 # And add hooks to restore the settings during tearDown(). 221 self.runCmd('settings set target.run-args A B C') 222 self.addTearDownHook( 223 lambda: self.runCmd("settings clear target.run-args")) 224 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES') 225 self.addTearDownHook( 226 lambda: self.runCmd("settings clear target.env-vars")) 227 228 exe = self.getBuildArtifact("a.out") 229 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 230 231 target = self.dbg.GetTargetAtIndex(0) 232 launch_info = target.GetLaunchInfo() 233 found_env_var = False 234 for i in range(0, launch_info.GetNumEnvironmentEntries()): 235 if launch_info.GetEnvironmentEntryAtIndex(i) == "MY_ENV_VAR=YES": 236 found_env_var = True 237 break 238 self.assertTrue(found_env_var, 239 "MY_ENV_VAR was not set in LunchInfo object") 240 241 self.assertEqual(launch_info.GetNumArguments(), 3) 242 self.assertEqual(launch_info.GetArgumentAtIndex(0), "A") 243 self.assertEqual(launch_info.GetArgumentAtIndex(1), "B") 244 self.assertEqual(launch_info.GetArgumentAtIndex(2), "C") 245 246 self.expect( 247 'target show-launch-environment', 248 substrs=["MY_ENV_VAR=YES"]) 249 250 wd = self.get_process_working_directory() 251 if use_launchsimple: 252 process = target.LaunchSimple(None, None, wd) 253 self.assertTrue(process) 254 else: 255 self.runCmd("process launch --working-dir '{0}'".format(wd), 256 RUN_SUCCEEDED) 257 258 # Read the output file produced by running the program. 259 output = lldbutil.read_file_from_process_wd(self, "output2.txt") 260 261 self.expect( 262 output, 263 exe=False, 264 substrs=[ 265 "argv[1] matches", 266 "argv[2] matches", 267 "argv[3] matches", 268 "Environment variable 'MY_ENV_VAR' successfully passed."]) 269 270 # Check that env-vars overrides unset-env-vars. 271 self.runCmd('settings set target.unset-env-vars MY_ENV_VAR') 272 273 self.expect( 274 'target show-launch-environment', 275 'env-vars overrides unset-env-vars', 276 substrs=["MY_ENV_VAR=YES"]) 277 278 wd = self.get_process_working_directory() 279 if use_launchsimple: 280 process = target.LaunchSimple(None, None, wd) 281 self.assertTrue(process) 282 else: 283 self.runCmd("process launch --working-dir '{0}'".format(wd), 284 RUN_SUCCEEDED) 285 286 # Read the output file produced by running the program. 287 output = lldbutil.read_file_from_process_wd(self, "output2.txt") 288 289 self.expect( 290 output, 291 exe=False, 292 substrs=[ 293 "Environment variable 'MY_ENV_VAR' successfully passed."]) 294 295 @skipIfRemote # it doesn't make sense to send host env to remote target 296 @skipIfReproducer 297 def test_pass_host_env_vars(self): 298 """Test that the host env vars are passed to the launched process.""" 299 self.build() 300 301 # Set some host environment variables now. 302 os.environ["MY_HOST_ENV_VAR1"] = "VAR1" 303 os.environ["MY_HOST_ENV_VAR2"] = "VAR2" 304 305 # This is the function to unset the two env variables set above. 306 def unset_env_variables(): 307 os.environ.pop("MY_HOST_ENV_VAR1") 308 os.environ.pop("MY_HOST_ENV_VAR2") 309 self.addTearDownHook(unset_env_variables) 310 311 exe = self.getBuildArtifact("a.out") 312 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 313 314 # By default, inherit-env is 'true'. 315 self.expect( 316 'settings show target.inherit-env', 317 "Default inherit-env is 'true'", 318 startstr="target.inherit-env (boolean) = true") 319 320 self.expect( 321 'target show-launch-environment', 322 'Host environment is passed correctly', 323 substrs=['MY_HOST_ENV_VAR1=VAR1', 'MY_HOST_ENV_VAR2=VAR2']) 324 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 325 RUN_SUCCEEDED) 326 327 # Read the output file produced by running the program. 328 output = lldbutil.read_file_from_process_wd(self, "output1.txt") 329 330 self.expect( 331 output, 332 exe=False, 333 substrs=[ 334 "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", 335 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) 336 337 # Now test that we can prevent the inferior from inheriting the 338 # environment. 339 self.runCmd('settings set target.inherit-env false') 340 341 self.expect( 342 'target show-launch-environment', 343 'target.inherit-env affects `target show-launch-environment`', 344 matching=False, 345 substrs = ['MY_HOST_ENV_VAR1=VAR1', 'MY_HOST_ENV_VAR2=VAR2']) 346 347 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 348 RUN_SUCCEEDED) 349 350 # Read the output file produced by running the program. 351 output = lldbutil.read_file_from_process_wd(self, "output1.txt") 352 353 self.expect( 354 output, 355 exe=False, 356 matching=False, 357 substrs=[ 358 "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.", 359 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) 360 361 # Now test that we can unset variables from the inherited environment. 362 self.runCmd('settings set target.inherit-env true') 363 self.runCmd('settings set target.unset-env-vars MY_HOST_ENV_VAR1') 364 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 365 RUN_SUCCEEDED) 366 367 # Read the output file produced by running the program. 368 output = lldbutil.read_file_from_process_wd(self, "output1.txt") 369 370 self.expect( 371 'target show-launch-environment', 372 'MY_HOST_ENV_VAR1 is unset, it shouldn\'t be in `target show-launch-environment`', 373 matching=False, 374 substrs = ['MY_HOST_ENV_VAR1=VAR1']) 375 self.expect( 376 'target show-launch-environment', 377 'MY_HOST_ENV_VAR2 shouldn be in `target show-launch-environment`', 378 substrs = ['MY_HOST_ENV_VAR2=VAR2']) 379 380 self.expect( 381 output, 382 exe=False, 383 matching=False, 384 substrs=[ 385 "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed."]) 386 self.expect( 387 output, 388 exe=False, 389 substrs=[ 390 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."]) 391 392 @skipIfDarwinEmbedded # <rdar://problem/34446098> debugserver on ios etc can't write files 393 @skipIfReproducer 394 def test_set_error_output_path(self): 395 """Test that setting target.error/output-path for the launched process works.""" 396 self.build() 397 398 exe = self.getBuildArtifact("a.out") 399 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 400 401 # Set the error-path and output-path and verify both are set. 402 self.runCmd("settings set target.error-path '{0}'".format( 403 lldbutil.append_to_process_working_directory(self, "stderr.txt"))) 404 self.runCmd("settings set target.output-path '{0}".format( 405 lldbutil.append_to_process_working_directory(self, "stdout.txt"))) 406 # And add hooks to restore the original settings during tearDown(). 407 self.addTearDownHook( 408 lambda: self.runCmd("settings clear target.output-path")) 409 self.addTearDownHook( 410 lambda: self.runCmd("settings clear target.error-path")) 411 412 self.expect("settings show target.error-path", 413 SETTING_MSG("target.error-path"), 414 substrs=['target.error-path (file)', 'stderr.txt"']) 415 416 self.expect("settings show target.output-path", 417 SETTING_MSG("target.output-path"), 418 substrs=['target.output-path (file)', 'stdout.txt"']) 419 420 self.runCmd("process launch --working-dir '{0}'".format(self.get_process_working_directory()), 421 RUN_SUCCEEDED) 422 423 output = lldbutil.read_file_from_process_wd(self, "stderr.txt") 424 message = "This message should go to standard error." 425 if lldbplatformutil.hasChattyStderr(self): 426 self.expect(output, exe=False, substrs=[message]) 427 else: 428 self.expect(output, exe=False, startstr=message) 429 430 output = lldbutil.read_file_from_process_wd(self, "stdout.txt") 431 self.expect(output, exe=False, 432 startstr="This message should go to standard out.") 433 434 def test_print_dictionary_setting(self): 435 self.runCmd("settings clear target.env-vars") 436 self.runCmd("settings set target.env-vars [\"MY_VAR\"]=some-value") 437 self.expect("settings show target.env-vars", 438 substrs=["MY_VAR=some-value"]) 439 self.runCmd("settings clear target.env-vars") 440 441 def test_print_array_setting(self): 442 self.runCmd("settings clear target.run-args") 443 self.runCmd("settings set target.run-args gobbledy-gook") 444 self.expect("settings show target.run-args", 445 substrs=['[0]: "gobbledy-gook"']) 446 self.runCmd("settings clear target.run-args") 447 448 def test_settings_with_quotes(self): 449 self.runCmd("settings clear target.run-args") 450 self.runCmd("settings set target.run-args a b c") 451 self.expect("settings show target.run-args", 452 substrs=['[0]: "a"', 453 '[1]: "b"', 454 '[2]: "c"']) 455 self.runCmd("settings set target.run-args 'a b c'") 456 self.expect("settings show target.run-args", 457 substrs=['[0]: "a b c"']) 458 self.runCmd("settings clear target.run-args") 459 self.runCmd("settings clear target.env-vars") 460 self.runCmd( 461 'settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"') 462 self.expect("settings show target.env-vars", 463 substrs=['MY_FILE=this is a file name with spaces.txt']) 464 self.runCmd("settings clear target.env-vars") 465 # Test and make sure that setting "format-string" settings obeys quotes 466 # if they are provided 467 self.runCmd("settings set thread-format 'abc def' ") 468 self.expect("settings show thread-format", 469 startstr='thread-format (format-string) = "abc def"') 470 self.runCmd('settings set thread-format "abc def" ') 471 self.expect("settings show thread-format", 472 startstr='thread-format (format-string) = "abc def"') 473 # Make sure when no quotes are provided that we maintain any trailing 474 # spaces 475 self.runCmd('settings set thread-format abc def ') 476 self.expect("settings show thread-format", 477 startstr='thread-format (format-string) = "abc def "') 478 self.runCmd('settings clear thread-format') 479 480 def test_settings_with_trailing_whitespace(self): 481 482 # boolean 483 # Set to known value 484 self.runCmd("settings set target.skip-prologue true") 485 # Set to new value with trailing whitespace 486 self.runCmd("settings set target.skip-prologue false ") 487 # Make sure the setting was correctly set to "false" 488 self.expect( 489 "settings show target.skip-prologue", 490 SETTING_MSG("target.skip-prologue"), 491 startstr="target.skip-prologue (boolean) = false") 492 self.runCmd("settings clear target.skip-prologue", check=False) 493 # integer 494 self.runCmd("settings set term-width 70") # Set to known value 495 # Set to new value with trailing whitespaces 496 self.runCmd("settings set term-width 60 \t") 497 self.expect("settings show term-width", SETTING_MSG("term-width"), 498 startstr="term-width (int) = 60") 499 self.runCmd("settings clear term-width", check=False) 500 # string 501 self.runCmd("settings set target.arg0 abc") # Set to known value 502 # Set to new value with trailing whitespaces 503 self.runCmd("settings set target.arg0 cde\t ") 504 self.expect("settings show target.arg0", SETTING_MSG("target.arg0"), 505 startstr='target.arg0 (string) = "cde"') 506 self.runCmd("settings clear target.arg0", check=False) 507 # file 508 path1 = self.getBuildArtifact("path1.txt") 509 path2 = self.getBuildArtifact("path2.txt") 510 self.runCmd( 511 "settings set target.output-path %s" % 512 path1) # Set to known value 513 self.expect( 514 "settings show target.output-path", 515 SETTING_MSG("target.output-path"), 516 startstr='target.output-path (file) = ', 517 substrs=[path1]) 518 self.runCmd("settings set target.output-path %s " % 519 path2) # Set to new value with trailing whitespaces 520 self.expect( 521 "settings show target.output-path", 522 SETTING_MSG("target.output-path"), 523 startstr='target.output-path (file) = ', 524 substrs=[path2]) 525 self.runCmd("settings clear target.output-path", check=False) 526 # enum 527 # Set to known value 528 self.runCmd("settings set stop-disassembly-display never") 529 # Set to new value with trailing whitespaces 530 self.runCmd("settings set stop-disassembly-display always ") 531 self.expect( 532 "settings show stop-disassembly-display", 533 SETTING_MSG("stop-disassembly-display"), 534 startstr='stop-disassembly-display (enum) = always') 535 self.runCmd("settings clear stop-disassembly-display", check=False) 536 # language 537 # Set to known value 538 self.runCmd("settings set target.language c89") 539 # Set to new value with trailing whitespace 540 self.runCmd("settings set target.language c11 ") 541 self.expect( 542 "settings show target.language", 543 SETTING_MSG("target.language"), 544 startstr="target.language (language) = c11") 545 self.runCmd("settings clear target.language", check=False) 546 # arguments 547 self.runCmd("settings set target.run-args 1 2 3") # Set to known value 548 # Set to new value with trailing whitespaces 549 self.runCmd("settings set target.run-args 3 4 5 ") 550 self.expect( 551 "settings show target.run-args", 552 SETTING_MSG("target.run-args"), 553 substrs=[ 554 'target.run-args (arguments) =', 555 '[0]: "3"', 556 '[1]: "4"', 557 '[2]: "5"']) 558 self.runCmd("settings set target.run-args 1 2 3") # Set to known value 559 # Set to new value with trailing whitespaces 560 self.runCmd("settings set target.run-args 3 \ \ ") 561 self.expect( 562 "settings show target.run-args", 563 SETTING_MSG("target.run-args"), 564 substrs=[ 565 'target.run-args (arguments) =', 566 '[0]: "3"', 567 '[1]: " "', 568 '[2]: " "']) 569 self.runCmd("settings clear target.run-args", check=False) 570 # dictionaries 571 self.runCmd("settings clear target.env-vars") # Set to known value 572 # Set to new value with trailing whitespaces 573 self.runCmd("settings set target.env-vars A=B C=D\t ") 574 self.expect( 575 "settings show target.env-vars", 576 SETTING_MSG("target.env-vars"), 577 substrs=[ 578 'target.env-vars (dictionary of strings) =', 579 'A=B', 580 'C=D']) 581 self.runCmd("settings clear target.env-vars", check=False) 582 # regex 583 # Set to known value 584 self.runCmd("settings clear target.process.thread.step-avoid-regexp") 585 # Set to new value with trailing whitespaces 586 self.runCmd( 587 "settings set target.process.thread.step-avoid-regexp foo\\ ") 588 self.expect( 589 "settings show target.process.thread.step-avoid-regexp", 590 SETTING_MSG("target.process.thread.step-avoid-regexp"), 591 substrs=['target.process.thread.step-avoid-regexp (regex) = foo\\ ']) 592 self.runCmd( 593 "settings clear target.process.thread.step-avoid-regexp", 594 check=False) 595 # format-string 596 self.runCmd("settings clear disassembly-format") # Set to known value 597 # Set to new value with trailing whitespaces 598 self.runCmd("settings set disassembly-format foo ") 599 self.expect("settings show disassembly-format", 600 SETTING_MSG("disassembly-format"), 601 substrs=['disassembly-format (format-string) = "foo "']) 602 self.runCmd("settings clear disassembly-format", check=False) 603 604 def test_settings_list(self): 605 # List settings (and optionally test the filter to only show 'target' settings). 606 self.expect("settings list target", substrs=["arg0", "detach-on-error", "language"]) 607 self.expect("settings list target", matching=False, substrs=["packet-timeout"]) 608 self.expect("settings list", substrs=["language", "arg0", "detach-on-error", "packet-timeout"]) 609 610 def test_settings_remove_single(self): 611 # Set some environment variables and use 'remove' to delete them. 612 self.runCmd("settings set target.env-vars a=b c=d") 613 self.expect("settings show target.env-vars", substrs=["a=b", "c=d"]) 614 self.runCmd("settings remove target.env-vars a") 615 self.expect("settings show target.env-vars", matching=False, substrs=["a=b"]) 616 self.expect("settings show target.env-vars", substrs=["c=d"]) 617 self.runCmd("settings remove target.env-vars c") 618 self.expect("settings show target.env-vars", matching=False, substrs=["a=b", "c=d"]) 619 620 def test_settings_remove_multiple(self): 621 self.runCmd("settings set target.env-vars a=b c=d e=f") 622 self.expect("settings show target.env-vars", substrs=["a=b", "c=d", "e=f"]) 623 self.runCmd("settings remove target.env-vars a e") 624 self.expect("settings show target.env-vars", matching=False, substrs=["a=b", "e=f"]) 625 self.expect("settings show target.env-vars", substrs=["c=d"]) 626 627 def test_settings_remove_nonexistent_value(self): 628 self.expect("settings remove target.env-vars doesntexist", error=True, 629 substrs=["no value found named 'doesntexist'"]) 630 631 def test_settings_remove_nonexistent_settings(self): 632 self.expect("settings remove doesntexist alsodoesntexist", error=True, 633 substrs=["error: invalid value path 'doesntexist'"]) 634 635 def test_settings_remove_missing_arg(self): 636 self.expect("settings remove", error=True, 637 substrs=["'settings remove' takes an array or dictionary item, or"]) 638 639 def test_settings_remove_empty_arg(self): 640 self.expect("settings remove ''", error=True, 641 substrs=["'settings remove' command requires a valid variable name"]) 642 643 def test_settings_clear_all(self): 644 # Change a dictionary. 645 self.runCmd("settings set target.env-vars a=1 b=2 c=3") 646 # Change an array. 647 self.runCmd("settings set target.run-args a1 b2 c3") 648 # Change a single boolean value. 649 self.runCmd("settings set auto-confirm true") 650 # Change a single integer value. 651 self.runCmd("settings set tab-size 2") 652 653 # Clear everything. 654 self.runCmd("settings clear --all") 655 656 # Check that settings have their default values after clearing. 657 self.expect("settings show target.env-vars", patterns=['^target.env-vars \(dictionary of strings\) =\s*$']) 658 self.expect("settings show target.run-args", patterns=['^target.run-args \(arguments\) =\s*$']) 659 self.expect("settings show auto-confirm", substrs=["false"]) 660 self.expect("settings show tab-size", substrs=["4"]) 661 662 # Check that the command fails if we combine '--all' option with any arguments. 663 self.expect( 664 "settings clear --all auto-confirm", 665 COMMAND_FAILED_AS_EXPECTED, 666 error=True, 667 substrs=["'settings clear --all' doesn't take any arguments"]) 668 669 def test_all_settings_exist(self): 670 self.expect("settings show", 671 substrs=["auto-confirm", 672 "frame-format", 673 "notify-void", 674 "prompt", 675 "script-lang", 676 "stop-disassembly-count", 677 "stop-disassembly-display", 678 "stop-line-count-after", 679 "stop-line-count-before", 680 "stop-show-column", 681 "term-width", 682 "thread-format", 683 "use-external-editor", 684 "target.breakpoints-use-platform-avoid-list", 685 "target.default-arch", 686 "target.disable-aslr", 687 "target.disable-stdio", 688 "target.x86-disassembly-flavor", 689 "target.enable-synthetic-value", 690 "target.env-vars", 691 "target.error-path", 692 "target.exec-search-paths", 693 "target.expr-prefix", 694 "target.hex-immediate-style", 695 "target.inherit-env", 696 "target.input-path", 697 "target.language", 698 "target.max-children-count", 699 "target.max-string-summary-length", 700 "target.move-to-nearest-code", 701 "target.output-path", 702 "target.prefer-dynamic-value", 703 "target.run-args", 704 "target.skip-prologue", 705 "target.source-map", 706 "target.use-hex-immediates", 707 "target.process.disable-memory-cache", 708 "target.process.extra-startup-command", 709 "target.process.thread.trace-thread", 710 "target.process.thread.step-avoid-regexp", 711 ]) 712 713 # settings under an ".experimental" domain should have two properties: 714 # 1. If the name does not exist with "experimental" in the name path, 715 # the name lookup should try to find it without "experimental". So 716 # a previously-experimental setting that has been promoted to a 717 # "real" setting will still be set by the original name. 718 # 2. Changing a setting with .experimental., name, where the setting 719 # does not exist either with ".experimental." or without, should 720 # not generate an error. So if an experimental setting is removed, 721 # people who may have that in their ~/.lldbinit files should not see 722 # any errors. 723 def test_experimental_settings(self): 724 cmdinterp = self.dbg.GetCommandInterpreter() 725 result = lldb.SBCommandReturnObject() 726 727 # Set target.arg0 to a known value, check that we can retrieve it via 728 # the actual name and via .experimental. 729 self.expect('settings set target.arg0 first-value') 730 self.expect('settings show target.arg0', substrs=['first-value']) 731 self.expect('settings show target.experimental.arg0', substrs=['first-value'], error=False) 732 733 # Set target.arg0 to a new value via a target.experimental.arg0 name, 734 # verify that we can read it back via both .experimental., and not. 735 self.expect('settings set target.experimental.arg0 second-value', error=False) 736 self.expect('settings show target.arg0', substrs=['second-value']) 737 self.expect('settings show target.experimental.arg0', substrs=['second-value'], error=False) 738 739 # showing & setting an undefined .experimental. setting should generate no errors. 740 self.expect('settings show target.experimental.setting-which-does-not-exist', patterns=['^\s$'], error=False) 741 self.expect('settings set target.experimental.setting-which-does-not-exist true', error=False) 742 743 # A domain component before .experimental. which does not exist should give an error 744 # But the code does not yet do that. 745 # self.expect('settings set target.setting-which-does-not-exist.experimental.arg0 true', error=True) 746 747 # finally, confirm that trying to set a setting that does not exist still fails. 748 # (SHOWING a setting that does not exist does not currently yield an error.) 749 self.expect('settings set target.setting-which-does-not-exist true', error=True) 750