blob: 4305107936c264a2c941b56a60a8950fb7522cf5 [file] [log] [blame]
Johnny Chen77377772010-09-07 17:06:13 +00001"""
2Test lldb settings command.
3"""
4
Richard Mitton5c98c9a2013-10-03 01:50:35 +00005import os, time, re
Johnny Chen77377772010-09-07 17:06:13 +00006import unittest2
7import lldb
8from lldbtest import *
9
10class SettingsCommandTestCase(TestBase):
11
Greg Clayton4570d3e2013-12-10 23:19:29 +000012 mydir = TestBase.compute_mydir(__file__)
Johnny Chen77377772010-09-07 17:06:13 +000013
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000014 @classmethod
15 def classCleanup(cls):
Johnny Chena91b9472010-10-22 21:06:04 +000016 """Cleanup the test byproducts."""
Filipe Cabecinhas0eec15a2012-06-20 10:13:40 +000017 cls.RemoveTempFile("output1.txt")
18 cls.RemoveTempFile("output2.txt")
19 cls.RemoveTempFile("stderr.txt")
20 cls.RemoveTempFile("stdout.txt")
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000021
Johnny Chen7fa6c952011-02-04 00:50:49 +000022 def test_apropos_should_also_search_settings_description(self):
23 """Test that 'apropos' command should also search descriptions for the settings variables."""
24
25 self.expect("apropos 'environment variable'",
Greg Clayton1d885962011-11-08 02:43:13 +000026 substrs = ["target.env-vars",
Johnny Chen7fa6c952011-02-04 00:50:49 +000027 "environment variables",
28 "executable's environment"])
29
Johnny Chen8cc80b22012-01-23 19:49:28 +000030 def test_append_target_env_vars(self):
Greg Clayton67cc0632012-08-22 17:17:09 +000031 """Test that 'append target.run-args' works."""
Johnny Chen8cc80b22012-01-23 19:49:28 +000032 # Append the env-vars.
33 self.runCmd('settings append target.env-vars MY_ENV_VAR=YES')
34 # And add hooks to restore the settings during tearDown().
35 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000036 lambda: self.runCmd("settings clear target.env-vars"))
Johnny Chen8cc80b22012-01-23 19:49:28 +000037
38 # Check it immediately!
39 self.expect('settings show target.env-vars',
40 substrs = ['MY_ENV_VAR=YES'])
41
42 def test_insert_before_and_after_target_run_args(self):
43 """Test that 'insert-before/after target.run-args' works."""
44 # Set the run-args first.
45 self.runCmd('settings set target.run-args a b c')
46 # And add hooks to restore the settings during tearDown().
47 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000048 lambda: self.runCmd("settings clear target.run-args"))
Johnny Chen8cc80b22012-01-23 19:49:28 +000049
50 # Now insert-before the index-0 element with '__a__'.
51 self.runCmd('settings insert-before target.run-args 0 __a__')
52 # And insert-after the index-1 element with '__A__'.
53 self.runCmd('settings insert-after target.run-args 1 __A__')
54 # Check it immediately!
55 self.expect('settings show target.run-args',
Greg Clayton67cc0632012-08-22 17:17:09 +000056 substrs = ['target.run-args',
Johnny Chen8cc80b22012-01-23 19:49:28 +000057 '[0]: "__a__"',
58 '[1]: "a"',
59 '[2]: "__A__"',
60 '[3]: "b"',
61 '[4]: "c"'])
62
Johnny Chen5928f642012-01-21 01:45:18 +000063 def test_replace_target_run_args(self):
64 """Test that 'replace target.run-args' works."""
65 # Set the run-args and then replace the index-0 element.
66 self.runCmd('settings set target.run-args a b c')
67 # And add hooks to restore the settings during tearDown().
68 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000069 lambda: self.runCmd("settings clear target.run-args"))
Johnny Chen5928f642012-01-21 01:45:18 +000070
71 # Now replace the index-0 element with 'A', instead.
72 self.runCmd('settings replace target.run-args 0 A')
73 # Check it immediately!
74 self.expect('settings show target.run-args',
Greg Clayton67cc0632012-08-22 17:17:09 +000075 substrs = ['target.run-args (arguments) =',
Johnny Chen5928f642012-01-21 01:45:18 +000076 '[0]: "A"',
77 '[1]: "b"',
78 '[2]: "c"'])
79
Johnny Chen77377772010-09-07 17:06:13 +000080 def test_set_prompt(self):
81 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000082
Johnny Chen23cb3712010-09-27 17:36:59 +000083 # Set prompt to 'lldb2'.
Greg Clayton00108402013-03-06 21:17:06 +000084 self.runCmd("settings set prompt 'lldb2 '")
Johnny Chen881c3712010-09-07 17:12:10 +000085
86 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000087 self.expect("settings show prompt", SETTING_MSG("prompt"),
Greg Clayton00108402013-03-06 21:17:06 +000088 startstr = 'prompt (string) = "lldb2 "')
Johnny Chen881c3712010-09-07 17:12:10 +000089
90 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000091 self.expect("settings show", SETTING_MSG("prompt"),
Greg Clayton00108402013-03-06 21:17:06 +000092 substrs = ['prompt (string) = "lldb2 "'])
Johnny Chen77377772010-09-07 17:06:13 +000093
Johnny Chen23cb3712010-09-27 17:36:59 +000094 # Use '-r' option to reset to the original default prompt.
Greg Clayton67cc0632012-08-22 17:17:09 +000095 self.runCmd("settings clear prompt")
Johnny Chen23cb3712010-09-27 17:36:59 +000096
Johnny Chena37764b2010-09-07 17:31:05 +000097 def test_set_term_width(self):
98 """Test that 'set term-width' actually changes the term-width."""
99
Johnny Chena37764b2010-09-07 17:31:05 +0000100 self.runCmd("settings set term-width 70")
101
102 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000103 self.expect("settings show term-width", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +0000104 startstr = "term-width (int) = 70")
Johnny Chena37764b2010-09-07 17:31:05 +0000105
106 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000107 self.expect("settings show", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +0000108 substrs = ["term-width (int) = 70"])
Johnny Chena37764b2010-09-07 17:31:05 +0000109
Johnny Chen41b780d2012-01-18 19:07:08 +0000110 #rdar://problem/10712130
Johnny Chen41b780d2012-01-18 19:07:08 +0000111 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."""
113 self.buildDefault()
114
115 exe = os.path.join(os.getcwd(), "a.out")
116 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
117
Filipe Cabecinhas5158f3d2012-05-18 21:35:43 +0000118 def cleanup():
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000119 self.runCmd("settings set frame-format %s" % self.format_string, check=False)
Filipe Cabecinhas5158f3d2012-05-18 21:35:43 +0000120
121 # Execute the cleanup function during test case tear down.
122 self.addTearDownHook(cleanup)
123
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000124 self.runCmd("settings show frame-format")
Richard Mitton5c98c9a2013-10-03 01:50:35 +0000125 m = re.match(
Greg Clayton554f68d2015-02-04 22:00:53 +0000126 '^frame-format \(format-string\) = "(.*)\"$',
Richard Mitton5c98c9a2013-10-03 01:50:35 +0000127 self.res.GetOutput())
128 self.assertTrue(m, "Bad settings string")
129 self.format_string = m.group(1)
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000130
131 # Change the default format to print function.name rather than function.name-with-args
132 format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}\n"
Johnny Chen41b780d2012-01-18 19:07:08 +0000133 self.runCmd("settings set frame-format %s" % format_string)
134
135 # Immediately test the setting.
136 self.expect("settings show frame-format", SETTING_MSG("frame-format"),
137 substrs = [format_string])
138
139 self.runCmd("breakpoint set -n main")
140 self.runCmd("run")
141 self.expect("thread backtrace",
142 substrs = ["`main", os.getcwd()])
143
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000144 def test_set_auto_confirm(self):
145 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
146 self.buildDefault()
147
148 exe = os.path.join(os.getcwd(), "a.out")
149 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
150
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000151 self.runCmd("settings set auto-confirm true")
152
153 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000154 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000155 startstr = "auto-confirm (boolean) = true")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000156
157 # Now 'breakpoint delete' should just work fine without confirmation
158 # prompt from the command interpreter.
159 self.runCmd("breakpoint set -n main")
160 self.expect("breakpoint delete",
161 startstr = "All breakpoints removed")
162
163 # Restore the original setting of auto-confirm.
Greg Clayton67cc0632012-08-22 17:17:09 +0000164 self.runCmd("settings clear auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +0000165 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000166 startstr = "auto-confirm (boolean) = false")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000167
Tamas Berghammer3215d042015-04-17 09:37:06 +0000168 @expectedFailureArch("arm")
169 @expectedFailureArch("aarch64")
Daniel Malead79ae052013-08-07 21:54:09 +0000170 def test_disassembler_settings(self):
171 """Test that user options for the disassembler take effect."""
172 self.buildDefault()
173
174 exe = os.path.join(os.getcwd(), "a.out")
175 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
176
177 # AT&T syntax
178 self.runCmd("settings set target.x86-disassembly-flavor att")
179 self.runCmd("settings set target.use-hex-immediates false")
180 self.expect("disassemble -n numberfn",
181 substrs = ["$90"])
182 self.runCmd("settings set target.use-hex-immediates true")
183 self.runCmd("settings set target.hex-immediate-style c")
184 self.expect("disassemble -n numberfn",
185 substrs = ["$0x5a"])
186 self.runCmd("settings set target.hex-immediate-style asm")
187 self.expect("disassemble -n numberfn",
188 substrs = ["$5ah"])
189
190 # Intel syntax
191 self.runCmd("settings set target.x86-disassembly-flavor intel")
192 self.runCmd("settings set target.use-hex-immediates false")
193 self.expect("disassemble -n numberfn",
194 substrs = ["90"])
195 self.runCmd("settings set target.use-hex-immediates true")
196 self.runCmd("settings set target.hex-immediate-style c")
197 self.expect("disassemble -n numberfn",
198 substrs = ["0x5a"])
199 self.runCmd("settings set target.hex-immediate-style asm")
200 self.expect("disassemble -n numberfn",
201 substrs = ["5ah"])
202
Robert Flack13c7ad92015-03-30 14:12:17 +0000203 @skipUnlessDarwin
Johnny Chen24086bc2012-04-06 19:54:10 +0000204 @dsym_test
Johnny Chena245f932010-12-14 23:43:29 +0000205 def test_run_args_and_env_vars_with_dsym(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000206 """Test that run-args and env-vars are passed to the launched process."""
207 self.buildDsym()
208 self.pass_run_args_and_env_vars()
209
Johnny Chen24086bc2012-04-06 19:54:10 +0000210 @dwarf_test
Johnny Chena245f932010-12-14 23:43:29 +0000211 def test_run_args_and_env_vars_with_dwarf(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000212 """Test that run-args and env-vars are passed to the launched process."""
213 self.buildDwarf()
214 self.pass_run_args_and_env_vars()
215
216 def pass_run_args_and_env_vars(self):
217 """Test that run-args and env-vars are passed to the launched process."""
218 exe = os.path.join(os.getcwd(), "a.out")
219 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
220
221 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +0000222 # And add hooks to restore the settings during tearDown().
Greg Clayton1d885962011-11-08 02:43:13 +0000223 self.runCmd('settings set target.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +0000224 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000225 lambda: self.runCmd("settings clear target.run-args"))
Greg Clayton1d885962011-11-08 02:43:13 +0000226 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +0000227 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000228 lambda: self.runCmd("settings clear target.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +0000229
Siva Chandra3154aa22015-05-27 22:27:41 +0000230 self.runCmd("run", RUN_FAILED)
Johnny Chend5e111c2010-09-15 22:27:29 +0000231
232 # Read the output file produced by running the program.
Vince Harroned7cbb22015-02-18 23:14:49 +0000233 if lldb.remote_platform:
234 self.runCmd('platform get-file "output2.txt" "output2.txt"')
Johnny Chena245f932010-12-14 23:43:29 +0000235 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000236 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000237
Johnny Chenbe7da212010-10-08 20:01:03 +0000238 self.expect(output, exe=False,
239 substrs = ["argv[1] matches",
240 "argv[2] matches",
241 "argv[3] matches",
242 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000243
Vince Harroned7cbb22015-02-18 23:14:49 +0000244 @skipIfRemote # it doesn't make sense to send host env to remote target
Johnny Chen80554b82010-12-04 00:44:56 +0000245 def test_pass_host_env_vars(self):
246 """Test that the host env vars are passed to the launched process."""
247 self.buildDefault()
248
249 exe = os.path.join(os.getcwd(), "a.out")
250 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
251
252 # By default, inherit-env is 'true'.
Greg Clayton1d885962011-11-08 02:43:13 +0000253 self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
254 startstr = "target.inherit-env (boolean) = true")
Johnny Chen80554b82010-12-04 00:44:56 +0000255
256 # Set some host environment variables now.
257 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
258 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
259
Johnny Chena245f932010-12-14 23:43:29 +0000260 # This is the function to unset the two env variables set above.
261 def unset_env_variables():
262 os.environ.pop("MY_HOST_ENV_VAR1")
263 os.environ.pop("MY_HOST_ENV_VAR2")
264
265 self.addTearDownHook(unset_env_variables)
Siva Chandra3154aa22015-05-27 22:27:41 +0000266 self.runCmd("run", RUN_FAILED)
Johnny Chen80554b82010-12-04 00:44:56 +0000267
268 # Read the output file produced by running the program.
Vince Harroned7cbb22015-02-18 23:14:49 +0000269 if lldb.remote_platform:
270 self.runCmd('platform get-file "output1.txt" "output1.txt"')
Johnny Chena245f932010-12-14 23:43:29 +0000271 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000272 output = f.read()
273
274 self.expect(output, exe=False,
275 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
276 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
277
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000278 def test_set_error_output_path(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000279 """Test that setting target.error/output-path for the launched process works."""
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000280 self.buildDefault()
281
282 exe = os.path.join(os.getcwd(), "a.out")
283 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
284
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000285 # Set the error-path and output-path and verify both are set.
Greg Clayton1d885962011-11-08 02:43:13 +0000286 self.runCmd("settings set target.error-path stderr.txt")
287 self.runCmd("settings set target.output-path stdout.txt")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000288 # And add hooks to restore the original settings during tearDown().
Johnny Chen707d8222010-10-19 23:40:13 +0000289 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000290 lambda: self.runCmd("settings clear target.output-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000291 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000292 lambda: self.runCmd("settings clear target.error-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000293
Greg Clayton1d885962011-11-08 02:43:13 +0000294 self.expect("settings show target.error-path",
295 SETTING_MSG("target.error-path"),
Vince Harron1f4706c2015-02-18 23:12:26 +0000296 substrs = ['target.error-path (file) = "stderr.txt"'])
Johnny Chen707d8222010-10-19 23:40:13 +0000297
Greg Clayton1d885962011-11-08 02:43:13 +0000298 self.expect("settings show target.output-path",
299 SETTING_MSG("target.output-path"),
Vince Harron1f4706c2015-02-18 23:12:26 +0000300 substrs = ['target.output-path (file) = "stdout.txt"'])
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000301
Siva Chandra3154aa22015-05-27 22:27:41 +0000302 self.runCmd("run", RUN_FAILED)
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000303
Vince Harron1f4706c2015-02-18 23:12:26 +0000304 if lldb.remote_platform:
305 self.runCmd('platform get-file "stderr.txt" "stderr.txt"')
306 self.runCmd('platform get-file "stdout.txt" "stdout.txt"')
307
308
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000309 # The 'stderr.txt' file should now exist.
310 self.assertTrue(os.path.isfile("stderr.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000311 "'stderr.txt' exists due to target.error-path.")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000312
313 # Read the output file produced by running the program.
314 with open('stderr.txt', 'r') as f:
315 output = f.read()
316
317 self.expect(output, exe=False,
318 startstr = "This message should go to standard error.")
319
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000320 # The 'stdout.txt' file should now exist.
321 self.assertTrue(os.path.isfile("stdout.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000322 "'stdout.txt' exists due to target.output-path.")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000323
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000324 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000325 with open('stdout.txt', 'r') as f:
326 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000327
Johnny Chenbe7da212010-10-08 20:01:03 +0000328 self.expect(output, exe=False,
329 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000330
Caroline Ticec9c235e2011-01-31 18:18:54 +0000331 def test_print_dictionary_setting(self):
Greg Clayton67cc0632012-08-22 17:17:09 +0000332 self.runCmd ("settings clear target.env-vars")
Greg Clayton1d885962011-11-08 02:43:13 +0000333 self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
334 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000335 substrs = [ "MY_VAR=some-value" ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000336 self.runCmd ("settings clear target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000337
338 def test_print_array_setting(self):
Greg Clayton67cc0632012-08-22 17:17:09 +0000339 self.runCmd ("settings clear target.run-args")
Greg Clayton1d885962011-11-08 02:43:13 +0000340 self.runCmd ("settings set target.run-args gobbledy-gook")
341 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000342 substrs = [ '[0]: "gobbledy-gook"' ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000343 self.runCmd ("settings clear target.run-args")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000344
345 def test_settings_with_quotes (self):
Greg Clayton67cc0632012-08-22 17:17:09 +0000346 self.runCmd ("settings clear target.run-args")
Greg Clayton1d885962011-11-08 02:43:13 +0000347 self.runCmd ("settings set target.run-args a b c")
348 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000349 substrs = [ '[0]: "a"',
350 '[1]: "b"',
351 '[2]: "c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000352 self.runCmd ("settings set target.run-args 'a b c'")
353 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000354 substrs = [ '[0]: "a b c"' ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000355 self.runCmd ("settings clear target.run-args")
356 self.runCmd ("settings clear target.env-vars")
Greg Clayton1d885962011-11-08 02:43:13 +0000357 self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
358 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000359 substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000360 self.runCmd ("settings clear target.env-vars")
Greg Claytonb2e0c112015-06-03 02:02:48 +0000361 # Test and make sure that setting "format-string" settings obeys quotes if they are provided
362 self.runCmd ("settings set thread-format 'abc def' ")
363 self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def"')
364 self.runCmd ('settings set thread-format "abc def" ')
365 self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def"')
366 # Make sure when no quotes are provided that we maintain any trailing spaces
367 self.runCmd ('settings set thread-format abc def ')
368 self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def "')
Greg Claytonf7d163a2015-06-16 23:09:37 +0000369 self.runCmd ('settings clear thread-format')
Caroline Ticec9c235e2011-01-31 18:18:54 +0000370
Greg Clayton00108402013-03-06 21:17:06 +0000371 def test_settings_with_trailing_whitespace (self):
372
373 # boolean
374 self.runCmd ("settings set target.skip-prologue true") # Set to known value
375 self.runCmd ("settings set target.skip-prologue false ") # Set to new value with trailing whitespace
376 # Make sure the setting was correctly set to "false"
377 self.expect ("settings show target.skip-prologue", SETTING_MSG("target.skip-prologue"),
378 startstr = "target.skip-prologue (boolean) = false")
379 self.runCmd("settings clear target.skip-prologue", check=False)
380 # integer
381 self.runCmd ("settings set term-width 70") # Set to known value
382 self.runCmd ("settings set term-width 60 \t") # Set to new value with trailing whitespaces
383 self.expect ("settings show term-width", SETTING_MSG("term-width"),
384 startstr = "term-width (int) = 60")
385 self.runCmd("settings clear term-width", check=False)
386 # string
387 self.runCmd ("settings set target.arg0 abc") # Set to known value
388 self.runCmd ("settings set target.arg0 cde\t ") # Set to new value with trailing whitespaces
389 self.expect ("settings show target.arg0", SETTING_MSG("target.arg0"),
390 startstr = 'target.arg0 (string) = "cde"')
391 self.runCmd("settings clear target.arg0", check=False)
392 # file
Zachary Turner83887fb2015-01-21 00:40:27 +0000393 path1 = os.path.join(os.getcwd(), "path1.txt")
394 path2 = os.path.join(os.getcwd(), "path2.txt")
395 self.runCmd ("settings set target.output-path %s" % path1) # Set to known value
Greg Clayton00108402013-03-06 21:17:06 +0000396 self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"),
Zachary Turner83887fb2015-01-21 00:40:27 +0000397 startstr = 'target.output-path (file) = ', substrs=[path1])
398 self.runCmd ("settings set target.output-path %s " % path2) # Set to new value with trailing whitespaces
399 self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"),
400 startstr = 'target.output-path (file) = ', substrs=[path2])
Greg Clayton00108402013-03-06 21:17:06 +0000401 self.runCmd("settings clear target.output-path", check=False)
402 # enum
403 self.runCmd ("settings set stop-disassembly-display never") # Set to known value
404 self.runCmd ("settings set stop-disassembly-display always ") # Set to new value with trailing whitespaces
405 self.expect ("settings show stop-disassembly-display", SETTING_MSG("stop-disassembly-display"),
406 startstr = 'stop-disassembly-display (enum) = always')
407 self.runCmd("settings clear stop-disassembly-display", check=False)
408 # arguments
409 self.runCmd ("settings set target.run-args 1 2 3") # Set to known value
410 self.runCmd ("settings set target.run-args 3 4 5 ") # Set to new value with trailing whitespaces
411 self.expect ("settings show target.run-args", SETTING_MSG("target.run-args"),
412 substrs = [ 'target.run-args (arguments) =',
413 '[0]: "3"',
414 '[1]: "4"',
415 '[2]: "5"' ])
Pavel Labathdf50f942015-02-16 13:13:39 +0000416 self.runCmd ("settings set target.run-args 1 2 3") # Set to known value
417 self.runCmd ("settings set target.run-args 3 \ \ ") # Set to new value with trailing whitespaces
418 self.expect ("settings show target.run-args", SETTING_MSG("target.run-args"),
419 substrs = [ 'target.run-args (arguments) =',
420 '[0]: "3"',
421 '[1]: " "',
422 '[2]: " "' ])
Greg Clayton00108402013-03-06 21:17:06 +0000423 self.runCmd("settings clear target.run-args", check=False)
424 # dictionaries
425 self.runCmd ("settings clear target.env-vars") # Set to known value
426 self.runCmd ("settings set target.env-vars A=B C=D\t ") # Set to new value with trailing whitespaces
427 self.expect ("settings show target.env-vars", SETTING_MSG("target.env-vars"),
428 substrs = [ 'target.env-vars (dictionary of strings) =',
429 'A=B',
430 'C=D'])
431 self.runCmd("settings clear target.env-vars", check=False)
Pavel Labathdf50f942015-02-16 13:13:39 +0000432 # regex
433 self.runCmd ("settings clear target.process.thread.step-avoid-regexp") # Set to known value
434 self.runCmd ("settings set target.process.thread.step-avoid-regexp foo\\ ") # Set to new value with trailing whitespaces
435 self.expect ("settings show target.process.thread.step-avoid-regexp",
436 SETTING_MSG("target.process.thread.step-avoid-regexp"),
437 substrs = [ 'target.process.thread.step-avoid-regexp (regex) = foo\\ '])
438 self.runCmd("settings clear target.process.thread.step-avoid-regexp", check=False)
439 # format-string
440 self.runCmd ("settings clear disassembly-format") # Set to known value
441 self.runCmd ("settings set disassembly-format foo ") # Set to new value with trailing whitespaces
442 self.expect ("settings show disassembly-format",
443 SETTING_MSG("disassembly-format"),
444 substrs = [ 'disassembly-format (format-string) = "foo "'])
445 self.runCmd("settings clear disassembly-format", check=False)
Greg Clayton00108402013-03-06 21:17:06 +0000446
Caroline Ticeb904ca52011-03-10 22:29:54 +0000447 def test_all_settings_exist (self):
448 self.expect ("settings show",
Greg Clayton67cc0632012-08-22 17:17:09 +0000449 substrs = [ "auto-confirm",
450 "frame-format",
451 "notify-void",
452 "prompt",
453 "script-lang",
454 "stop-disassembly-count",
455 "stop-disassembly-display",
456 "stop-line-count-after",
457 "stop-line-count-before",
458 "term-width",
459 "thread-format",
460 "use-external-editor",
461 "target.default-arch",
Ilia K055ad9b2015-05-18 13:41:01 +0000462 "target.move-to-nearest-code",
Greg Clayton67cc0632012-08-22 17:17:09 +0000463 "target.expr-prefix",
464 "target.prefer-dynamic-value",
465 "target.enable-synthetic-value",
466 "target.skip-prologue",
467 "target.source-map",
468 "target.exec-search-paths",
469 "target.max-children-count",
470 "target.max-string-summary-length",
471 "target.breakpoints-use-platform-avoid-list",
472 "target.run-args",
473 "target.env-vars",
474 "target.inherit-env",
475 "target.input-path",
476 "target.output-path",
477 "target.error-path",
478 "target.disable-aslr",
479 "target.disable-stdio",
Daniel Malead79ae052013-08-07 21:54:09 +0000480 "target.x86-disassembly-flavor",
481 "target.use-hex-immediates",
482 "target.hex-immediate-style",
Greg Clayton67cc0632012-08-22 17:17:09 +0000483 "target.process.disable-memory-cache",
484 "target.process.extra-startup-command",
485 "target.process.thread.step-avoid-regexp",
486 "target.process.thread.trace-thread"])
487
Caroline Ticeb904ca52011-03-10 22:29:54 +0000488
489
Johnny Chen77377772010-09-07 17:06:13 +0000490if __name__ == '__main__':
491 import atexit
492 lldb.SBDebugger.Initialize()
493 atexit.register(lambda: lldb.SBDebugger.Terminate())
494 unittest2.main()