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