2 Test lldb settings command.
10 from lldbsuite
.test
.decorators
import *
11 from lldbsuite
.test
.lldbtest
import *
12 from lldbsuite
.test
import lldbutil
15 class SettingsCommandTestCase(TestBase
):
17 mydir
= TestBase
.compute_mydir(__file__
)
18 NO_DEBUG_INFO_TESTCASE
= True
20 def test_apropos_should_also_search_settings_description(self
):
21 """Test that 'apropos' command should also search descriptions for the settings variables."""
23 self
.expect("apropos 'environment variable'",
24 substrs
=["target.env-vars",
25 "environment variables",
26 "executable's environment"])
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().
34 lambda: self
.runCmd("settings clear target.env-vars"))
36 # Check it immediately!
37 self
.expect('settings show target.env-vars',
38 substrs
=['MY_ENV_VAR=YES'])
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().
46 lambda: self
.runCmd("settings clear target.run-args"))
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',
61 @expectedFailureAll(oslist
=["windows"], bugnumber
="llvm.org/pr44430")
62 def test_replace_target_run_args(self
):
63 """Test that 'replace target.run-args' works."""
64 # Set the run-args and then replace the index-0 element.
65 self
.runCmd('settings set target.run-args a b c')
66 # And add hooks to restore the settings during tearDown().
68 lambda: self
.runCmd("settings clear target.run-args"))
70 # Now replace the index-0 element with 'A', instead.
71 self
.runCmd('settings replace target.run-args 0 A')
72 # Check it immediately!
73 self
.expect('settings show target.run-args',
74 substrs
=['target.run-args (arguments) =',
79 def test_set_prompt(self
):
80 """Test that 'set prompt' actually changes the prompt."""
82 # Set prompt to 'lldb2'.
83 self
.runCmd("settings set prompt 'lldb2 '")
85 # Immediately test the setting.
86 self
.expect("settings show prompt", SETTING_MSG("prompt"),
87 startstr
='prompt (string) = "lldb2 "')
89 # The overall display should also reflect the new setting.
90 self
.expect("settings show", SETTING_MSG("prompt"),
91 substrs
=['prompt (string) = "lldb2 "'])
93 # Use '-r' option to reset to the original default prompt.
94 self
.runCmd("settings clear prompt")
96 def test_set_term_width(self
):
97 """Test that 'set term-width' actually changes the term-width."""
99 self
.runCmd("settings set term-width 70")
101 # Immediately test the setting.
102 self
.expect("settings show term-width", SETTING_MSG("term-width"),
103 startstr
="term-width (int) = 70")
105 # The overall display should also reflect the new setting.
106 self
.expect("settings show", SETTING_MSG("term-width"),
107 substrs
=["term-width (int) = 70"])
109 # rdar://problem/10712130
110 @skipIf(oslist
=["windows"], bugnumber
="llvm.org/pr44431")
111 def test_set_frame_format(self
):
112 """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath."""
115 exe
= self
.getBuildArtifact("a.out")
116 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
120 "settings set frame-format %s" %
121 self
.format_string
, check
=False)
123 # Execute the cleanup function during test case tear down.
124 self
.addTearDownHook(cleanup
)
126 self
.runCmd("settings show frame-format")
128 '^frame-format \(format-string\) = "(.*)\"$',
129 self
.res
.GetOutput())
130 self
.assertTrue(m
, "Bad settings string")
131 self
.format_string
= m
.group(1)
133 # Change the default format to print function.name rather than
134 # function.name-with-args
135 format_string
= "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}\`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}{, lang=${language}}\n"
136 self
.runCmd("settings set frame-format %s" % format_string
)
138 # Immediately test the setting.
139 self
.expect("settings show frame-format", SETTING_MSG("frame-format"),
140 substrs
=[format_string
])
142 self
.runCmd("breakpoint set -n main")
143 self
.runCmd("process launch --working-dir '{0}'".format(self
.get_process_working_directory()),
145 self
.expect("thread backtrace",
146 substrs
=["`main", self
.getSourceDir()])
148 def test_set_auto_confirm(self
):
149 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
152 exe
= self
.getBuildArtifact("a.out")
153 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
155 self
.runCmd("settings set auto-confirm true")
157 # Immediately test the setting.
158 self
.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
159 startstr
="auto-confirm (boolean) = true")
161 # Now 'breakpoint delete' should just work fine without confirmation
162 # prompt from the command interpreter.
163 self
.runCmd("breakpoint set -n main")
164 self
.expect("breakpoint delete",
165 startstr
="All breakpoints removed")
167 # Restore the original setting of auto-confirm.
168 self
.runCmd("settings clear auto-confirm")
169 self
.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
170 startstr
="auto-confirm (boolean) = false")
172 @skipIf(archs
=no_match(['x86_64', 'i386', 'i686']))
173 def test_disassembler_settings(self
):
174 """Test that user options for the disassembler take effect."""
177 exe
= self
.getBuildArtifact("a.out")
178 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
181 self
.runCmd("settings set target.x86-disassembly-flavor att")
182 self
.runCmd("settings set target.use-hex-immediates false")
183 self
.expect("disassemble -n numberfn",
185 self
.runCmd("settings set target.use-hex-immediates true")
186 self
.runCmd("settings set target.hex-immediate-style c")
187 self
.expect("disassemble -n numberfn",
189 self
.runCmd("settings set target.hex-immediate-style asm")
190 self
.expect("disassemble -n numberfn",
194 self
.runCmd("settings set target.x86-disassembly-flavor intel")
195 self
.runCmd("settings set target.use-hex-immediates false")
196 self
.expect("disassemble -n numberfn",
198 self
.runCmd("settings set target.use-hex-immediates true")
199 self
.runCmd("settings set target.hex-immediate-style c")
200 self
.expect("disassemble -n numberfn",
202 self
.runCmd("settings set target.hex-immediate-style asm")
203 self
.expect("disassemble -n numberfn",
206 @skipIfDarwinEmbedded # <rdar://problem/34446098> debugserver on ios etc can't write files
207 def test_run_args_and_env_vars(self
):
208 """Test that run-args and env-vars are passed to the launched process."""
210 exe
= self
.getBuildArtifact("a.out")
211 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
213 # Set the run-args and the env-vars.
214 # And add hooks to restore the settings during tearDown().
215 self
.runCmd('settings set target.run-args A B C')
216 self
.addTearDownHook(
217 lambda: self
.runCmd("settings clear target.run-args"))
218 self
.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
219 self
.addTearDownHook(
220 lambda: self
.runCmd("settings clear target.env-vars"))
222 self
.runCmd("process launch --working-dir '{0}'".format(self
.get_process_working_directory()),
225 # Read the output file produced by running the program.
226 output
= lldbutil
.read_file_from_process_wd(self
, "output2.txt")
235 "Environment variable 'MY_ENV_VAR' successfully passed."])
237 @skipIfRemote # it doesn't make sense to send host env to remote target
238 def test_pass_host_env_vars(self
):
239 """Test that the host env vars are passed to the launched process."""
242 exe
= self
.getBuildArtifact("a.out")
243 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
245 # By default, inherit-env is 'true'.
247 'settings show target.inherit-env',
248 "Default inherit-env is 'true'",
249 startstr
="target.inherit-env (boolean) = true")
251 # Set some host environment variables now.
252 os
.environ
["MY_HOST_ENV_VAR1"] = "VAR1"
253 os
.environ
["MY_HOST_ENV_VAR2"] = "VAR2"
255 # This is the function to unset the two env variables set above.
256 def unset_env_variables():
257 os
.environ
.pop("MY_HOST_ENV_VAR1")
258 os
.environ
.pop("MY_HOST_ENV_VAR2")
260 self
.addTearDownHook(unset_env_variables
)
261 self
.runCmd("process launch --working-dir '{0}'".format(self
.get_process_working_directory()),
264 # Read the output file produced by running the program.
265 output
= lldbutil
.read_file_from_process_wd(self
, "output1.txt")
271 "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
272 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
274 @skipIfDarwinEmbedded # <rdar://problem/34446098> debugserver on ios etc can't write files
275 def test_set_error_output_path(self
):
276 """Test that setting target.error/output-path for the launched process works."""
279 exe
= self
.getBuildArtifact("a.out")
280 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
282 # Set the error-path and output-path and verify both are set.
283 self
.runCmd("settings set target.error-path '{0}'".format(
284 lldbutil
.append_to_process_working_directory(self
, "stderr.txt")))
285 self
.runCmd("settings set target.output-path '{0}".format(
286 lldbutil
.append_to_process_working_directory(self
, "stdout.txt")))
287 # And add hooks to restore the original settings during tearDown().
288 self
.addTearDownHook(
289 lambda: self
.runCmd("settings clear target.output-path"))
290 self
.addTearDownHook(
291 lambda: self
.runCmd("settings clear target.error-path"))
293 self
.expect("settings show target.error-path",
294 SETTING_MSG("target.error-path"),
295 substrs
=['target.error-path (file)', 'stderr.txt"'])
297 self
.expect("settings show target.output-path",
298 SETTING_MSG("target.output-path"),
299 substrs
=['target.output-path (file)', 'stdout.txt"'])
301 self
.runCmd("process launch --working-dir '{0}'".format(self
.get_process_working_directory()),
304 output
= lldbutil
.read_file_from_process_wd(self
, "stderr.txt")
305 message
= "This message should go to standard error."
306 if lldbplatformutil
.hasChattyStderr(self
):
307 self
.expect(output
, exe
=False, substrs
=[message
])
309 self
.expect(output
, exe
=False, startstr
=message
)
311 output
= lldbutil
.read_file_from_process_wd(self
, "stdout.txt")
312 self
.expect(output
, exe
=False,
313 startstr
="This message should go to standard out.")
315 def test_print_dictionary_setting(self
):
316 self
.runCmd("settings clear target.env-vars")
317 self
.runCmd("settings set target.env-vars [\"MY_VAR\"]=some-value")
318 self
.expect("settings show target.env-vars",
319 substrs
=["MY_VAR=some-value"])
320 self
.runCmd("settings clear target.env-vars")
322 def test_print_array_setting(self
):
323 self
.runCmd("settings clear target.run-args")
324 self
.runCmd("settings set target.run-args gobbledy-gook")
325 self
.expect("settings show target.run-args",
326 substrs
=['[0]: "gobbledy-gook"'])
327 self
.runCmd("settings clear target.run-args")
329 def test_settings_with_quotes(self
):
330 self
.runCmd("settings clear target.run-args")
331 self
.runCmd("settings set target.run-args a b c")
332 self
.expect("settings show target.run-args",
336 self
.runCmd("settings set target.run-args 'a b c'")
337 self
.expect("settings show target.run-args",
338 substrs
=['[0]: "a b c"'])
339 self
.runCmd("settings clear target.run-args")
340 self
.runCmd("settings clear target.env-vars")
342 'settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
343 self
.expect("settings show target.env-vars",
344 substrs
=['MY_FILE=this is a file name with spaces.txt'])
345 self
.runCmd("settings clear target.env-vars")
346 # Test and make sure that setting "format-string" settings obeys quotes
347 # if they are provided
348 self
.runCmd("settings set thread-format 'abc def' ")
349 self
.expect("settings show thread-format",
350 'thread-format (format-string) = "abc def"')
351 self
.runCmd('settings set thread-format "abc def" ')
352 self
.expect("settings show thread-format",
353 'thread-format (format-string) = "abc def"')
354 # Make sure when no quotes are provided that we maintain any trailing
356 self
.runCmd('settings set thread-format abc def ')
357 self
.expect("settings show thread-format",
358 'thread-format (format-string) = "abc def "')
359 self
.runCmd('settings clear thread-format')
361 @expectedFailureAll(oslist
=["windows"], bugnumber
="llvm.org/pr44430")
362 def test_settings_with_trailing_whitespace(self
):
366 self
.runCmd("settings set target.skip-prologue true")
367 # Set to new value with trailing whitespace
368 self
.runCmd("settings set target.skip-prologue false ")
369 # Make sure the setting was correctly set to "false"
371 "settings show target.skip-prologue",
372 SETTING_MSG("target.skip-prologue"),
373 startstr
="target.skip-prologue (boolean) = false")
374 self
.runCmd("settings clear target.skip-prologue", check
=False)
376 self
.runCmd("settings set term-width 70") # Set to known value
377 # Set to new value with trailing whitespaces
378 self
.runCmd("settings set term-width 60 \t")
379 self
.expect("settings show term-width", SETTING_MSG("term-width"),
380 startstr
="term-width (int) = 60")
381 self
.runCmd("settings clear term-width", check
=False)
383 self
.runCmd("settings set target.arg0 abc") # Set to known value
384 # Set to new value with trailing whitespaces
385 self
.runCmd("settings set target.arg0 cde\t ")
386 self
.expect("settings show target.arg0", SETTING_MSG("target.arg0"),
387 startstr
='target.arg0 (string) = "cde"')
388 self
.runCmd("settings clear target.arg0", check
=False)
390 path1
= self
.getBuildArtifact("path1.txt")
391 path2
= self
.getBuildArtifact("path2.txt")
393 "settings set target.output-path %s" %
394 path1
) # Set to known value
396 "settings show target.output-path",
397 SETTING_MSG("target.output-path"),
398 startstr
='target.output-path (file) = ',
400 self
.runCmd("settings set target.output-path %s " %
401 path2
) # Set to new value with trailing whitespaces
403 "settings show target.output-path",
404 SETTING_MSG("target.output-path"),
405 startstr
='target.output-path (file) = ',
407 self
.runCmd("settings clear target.output-path", check
=False)
410 self
.runCmd("settings set stop-disassembly-display never")
411 # Set to new value with trailing whitespaces
412 self
.runCmd("settings set stop-disassembly-display always ")
414 "settings show stop-disassembly-display",
415 SETTING_MSG("stop-disassembly-display"),
416 startstr
='stop-disassembly-display (enum) = always')
417 self
.runCmd("settings clear stop-disassembly-display", check
=False)
420 self
.runCmd("settings set target.language c89")
421 # Set to new value with trailing whitespace
422 self
.runCmd("settings set target.language c11 ")
424 "settings show target.language",
425 SETTING_MSG("target.language"),
426 startstr
="target.language (language) = c11")
427 self
.runCmd("settings clear target.language", check
=False)
429 self
.runCmd("settings set target.run-args 1 2 3") # Set to known value
430 # Set to new value with trailing whitespaces
431 self
.runCmd("settings set target.run-args 3 4 5 ")
433 "settings show target.run-args",
434 SETTING_MSG("target.run-args"),
436 'target.run-args (arguments) =',
440 self
.runCmd("settings set target.run-args 1 2 3") # Set to known value
441 # Set to new value with trailing whitespaces
442 self
.runCmd("settings set target.run-args 3 \ \ ")
444 "settings show target.run-args",
445 SETTING_MSG("target.run-args"),
447 'target.run-args (arguments) =',
451 self
.runCmd("settings clear target.run-args", check
=False)
453 self
.runCmd("settings clear target.env-vars") # Set to known value
454 # Set to new value with trailing whitespaces
455 self
.runCmd("settings set target.env-vars A=B C=D\t ")
457 "settings show target.env-vars",
458 SETTING_MSG("target.env-vars"),
460 'target.env-vars (dictionary of strings) =',
463 self
.runCmd("settings clear target.env-vars", check
=False)
466 self
.runCmd("settings clear target.process.thread.step-avoid-regexp")
467 # Set to new value with trailing whitespaces
469 "settings set target.process.thread.step-avoid-regexp foo\\ ")
471 "settings show target.process.thread.step-avoid-regexp",
472 SETTING_MSG("target.process.thread.step-avoid-regexp"),
473 substrs
=['target.process.thread.step-avoid-regexp (regex) = foo\\ '])
475 "settings clear target.process.thread.step-avoid-regexp",
478 self
.runCmd("settings clear disassembly-format") # Set to known value
479 # Set to new value with trailing whitespaces
480 self
.runCmd("settings set disassembly-format foo ")
481 self
.expect("settings show disassembly-format",
482 SETTING_MSG("disassembly-format"),
483 substrs
=['disassembly-format (format-string) = "foo "'])
484 self
.runCmd("settings clear disassembly-format", check
=False)
486 def test_settings_list(self
):
487 # List settings (and optionally test the filter to only show 'target' settings).
488 self
.expect("settings list target", substrs
=["language", "arg0", "detach-on-error"])
489 self
.expect("settings list target", matching
=False, substrs
=["packet-timeout"])
490 self
.expect("settings list", substrs
=["language", "arg0", "detach-on-error", "packet-timeout"])
492 def test_settings_remove_single(self
):
493 # Set some environment variables and use 'remove' to delete them.
494 self
.runCmd("settings set target.env-vars a=b c=d")
495 self
.expect("settings show target.env-vars", substrs
=["a=b", "c=d"])
496 self
.runCmd("settings remove target.env-vars a")
497 self
.expect("settings show target.env-vars", matching
=False, substrs
=["a=b"])
498 self
.expect("settings show target.env-vars", substrs
=["c=d"])
499 self
.runCmd("settings remove target.env-vars c")
500 self
.expect("settings show target.env-vars", matching
=False, substrs
=["a=b", "c=d"])
502 def test_settings_remove_multiple(self
):
503 self
.runCmd("settings set target.env-vars a=b c=d e=f")
504 self
.expect("settings show target.env-vars", substrs
=["a=b", "c=d", "e=f"])
505 self
.runCmd("settings remove target.env-vars a e")
506 self
.expect("settings show target.env-vars", matching
=False, substrs
=["a=b", "e=f"])
507 self
.expect("settings show target.env-vars", substrs
=["c=d"])
509 def test_settings_remove_nonexistent_value(self
):
510 self
.expect("settings remove target.env-vars doesntexist", error
=True,
511 substrs
=["no value found named 'doesntexist'"])
513 def test_settings_remove_nonexistent_settings(self
):
514 self
.expect("settings remove doesntexist alsodoesntexist", error
=True,
515 substrs
=["error: invalid value path 'doesntexist'"])
517 def test_settings_remove_missing_arg(self
):
518 self
.expect("settings remove", error
=True,
519 substrs
=["'settings remove' takes an array or dictionary item, or"])
521 def test_settings_remove_empty_arg(self
):
522 self
.expect("settings remove ''", error
=True,
523 substrs
=["'settings remove' command requires a valid variable name"])
525 def test_all_settings_exist(self
):
526 self
.expect("settings show",
527 substrs
=["auto-confirm",
532 "stop-disassembly-count",
533 "stop-disassembly-display",
534 "stop-line-count-after",
535 "stop-line-count-before",
539 "use-external-editor",
540 "target.default-arch",
541 "target.move-to-nearest-code",
542 "target.expr-prefix",
544 "target.prefer-dynamic-value",
545 "target.enable-synthetic-value",
546 "target.skip-prologue",
548 "target.exec-search-paths",
549 "target.max-children-count",
550 "target.max-string-summary-length",
551 "target.breakpoints-use-platform-avoid-list",
554 "target.inherit-env",
556 "target.output-path",
558 "target.disable-aslr",
559 "target.disable-stdio",
560 "target.x86-disassembly-flavor",
561 "target.use-hex-immediates",
562 "target.hex-immediate-style",
563 "target.process.disable-memory-cache",
564 "target.process.extra-startup-command",
565 "target.process.thread.step-avoid-regexp",
566 "target.process.thread.trace-thread"])
568 # settings under an ".experimental" domain should have two properties:
569 # 1. If the name does not exist with "experimental" in the name path,
570 # the name lookup should try to find it without "experimental". So
571 # a previously-experimental setting that has been promoted to a
572 # "real" setting will still be set by the original name.
573 # 2. Changing a setting with .experimental., name, where the setting
574 # does not exist either with ".experimental." or without, should
575 # not generate an error. So if an experimental setting is removed,
576 # people who may have that in their ~/.lldbinit files should not see
578 def test_experimental_settings(self
):
579 cmdinterp
= self
.dbg
.GetCommandInterpreter()
580 result
= lldb
.SBCommandReturnObject()
582 # Set target.arg0 to a known value, check that we can retrieve it via
583 # the actual name and via .experimental.
584 self
.expect('settings set target.arg0 first-value')
585 self
.expect('settings show target.arg0', substrs
=['first-value'])
586 self
.expect('settings show target.experimental.arg0', substrs
=['first-value'], error
=False)
588 # Set target.arg0 to a new value via a target.experimental.arg0 name,
589 # verify that we can read it back via both .experimental., and not.
590 self
.expect('settings set target.experimental.arg0 second-value', error
=False)
591 self
.expect('settings show target.arg0', substrs
=['second-value'])
592 self
.expect('settings show target.experimental.arg0', substrs
=['second-value'], error
=False)
594 # showing & setting an undefined .experimental. setting should generate no errors.
595 self
.expect('settings show target.experimental.setting-which-does-not-exist', patterns
=['^\s$'], error
=False)
596 self
.expect('settings set target.experimental.setting-which-does-not-exist true', error
=False)
598 # A domain component before .experimental. which does not exist should give an error
599 # But the code does not yet do that.
600 # self.expect('settings set target.setting-which-does-not-exist.experimental.arg0 true', error=True)
602 # finally, confirm that trying to set a setting that does not exist still fails.
603 # (SHOWING a setting that does not exist does not currently yield an error.)
604 self
.expect('settings set target.setting-which-does-not-exist true', error
=True)