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