blob: f430a9dae3db60a4ecea5def6deb922b958a2941 [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
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000022 @no_debug_info_test
Johnny Chen7fa6c952011-02-04 00:50:49 +000023 def test_apropos_should_also_search_settings_description(self):
24 """Test that 'apropos' command should also search descriptions for the settings variables."""
25
26 self.expect("apropos 'environment variable'",
Greg Clayton1d885962011-11-08 02:43:13 +000027 substrs = ["target.env-vars",
Johnny Chen7fa6c952011-02-04 00:50:49 +000028 "environment variables",
29 "executable's environment"])
30
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000031 @no_debug_info_test
Johnny Chen8cc80b22012-01-23 19:49:28 +000032 def test_append_target_env_vars(self):
Greg Clayton67cc0632012-08-22 17:17:09 +000033 """Test that 'append target.run-args' works."""
Johnny Chen8cc80b22012-01-23 19:49:28 +000034 # Append the env-vars.
35 self.runCmd('settings append target.env-vars MY_ENV_VAR=YES')
36 # And add hooks to restore the settings during tearDown().
37 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000038 lambda: self.runCmd("settings clear target.env-vars"))
Johnny Chen8cc80b22012-01-23 19:49:28 +000039
40 # Check it immediately!
41 self.expect('settings show target.env-vars',
42 substrs = ['MY_ENV_VAR=YES'])
43
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000044 @no_debug_info_test
Johnny Chen8cc80b22012-01-23 19:49:28 +000045 def test_insert_before_and_after_target_run_args(self):
46 """Test that 'insert-before/after target.run-args' works."""
47 # Set the run-args first.
48 self.runCmd('settings set target.run-args a b c')
49 # And add hooks to restore the settings during tearDown().
50 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000051 lambda: self.runCmd("settings clear target.run-args"))
Johnny Chen8cc80b22012-01-23 19:49:28 +000052
53 # Now insert-before the index-0 element with '__a__'.
54 self.runCmd('settings insert-before target.run-args 0 __a__')
55 # And insert-after the index-1 element with '__A__'.
56 self.runCmd('settings insert-after target.run-args 1 __A__')
57 # Check it immediately!
58 self.expect('settings show target.run-args',
Greg Clayton67cc0632012-08-22 17:17:09 +000059 substrs = ['target.run-args',
Johnny Chen8cc80b22012-01-23 19:49:28 +000060 '[0]: "__a__"',
61 '[1]: "a"',
62 '[2]: "__A__"',
63 '[3]: "b"',
64 '[4]: "c"'])
65
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000066 @no_debug_info_test
Johnny Chen5928f642012-01-21 01:45:18 +000067 def test_replace_target_run_args(self):
68 """Test that 'replace target.run-args' works."""
69 # Set the run-args and then replace the index-0 element.
70 self.runCmd('settings set target.run-args a b c')
71 # And add hooks to restore the settings during tearDown().
72 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000073 lambda: self.runCmd("settings clear target.run-args"))
Johnny Chen5928f642012-01-21 01:45:18 +000074
75 # Now replace the index-0 element with 'A', instead.
76 self.runCmd('settings replace target.run-args 0 A')
77 # Check it immediately!
78 self.expect('settings show target.run-args',
Greg Clayton67cc0632012-08-22 17:17:09 +000079 substrs = ['target.run-args (arguments) =',
Johnny Chen5928f642012-01-21 01:45:18 +000080 '[0]: "A"',
81 '[1]: "b"',
82 '[2]: "c"'])
83
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000084 @no_debug_info_test
Johnny Chen77377772010-09-07 17:06:13 +000085 def test_set_prompt(self):
86 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000087
Johnny Chen23cb3712010-09-27 17:36:59 +000088 # Set prompt to 'lldb2'.
Greg Clayton00108402013-03-06 21:17:06 +000089 self.runCmd("settings set prompt 'lldb2 '")
Johnny Chen881c3712010-09-07 17:12:10 +000090
91 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000092 self.expect("settings show prompt", SETTING_MSG("prompt"),
Greg Clayton00108402013-03-06 21:17:06 +000093 startstr = 'prompt (string) = "lldb2 "')
Johnny Chen881c3712010-09-07 17:12:10 +000094
95 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000096 self.expect("settings show", SETTING_MSG("prompt"),
Greg Clayton00108402013-03-06 21:17:06 +000097 substrs = ['prompt (string) = "lldb2 "'])
Johnny Chen77377772010-09-07 17:06:13 +000098
Johnny Chen23cb3712010-09-27 17:36:59 +000099 # Use '-r' option to reset to the original default prompt.
Greg Clayton67cc0632012-08-22 17:17:09 +0000100 self.runCmd("settings clear prompt")
Johnny Chen23cb3712010-09-27 17:36:59 +0000101
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000102 @no_debug_info_test
Johnny Chena37764b2010-09-07 17:31:05 +0000103 def test_set_term_width(self):
104 """Test that 'set term-width' actually changes the term-width."""
105
Johnny Chena37764b2010-09-07 17:31:05 +0000106 self.runCmd("settings set term-width 70")
107
108 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000109 self.expect("settings show term-width", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +0000110 startstr = "term-width (int) = 70")
Johnny Chena37764b2010-09-07 17:31:05 +0000111
112 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000113 self.expect("settings show", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +0000114 substrs = ["term-width (int) = 70"])
Johnny Chena37764b2010-09-07 17:31:05 +0000115
Johnny Chen41b780d2012-01-18 19:07:08 +0000116 #rdar://problem/10712130
Johnny Chen41b780d2012-01-18 19:07:08 +0000117 def test_set_frame_format(self):
118 """Test that 'set frame-format' with a backtick char in the format string works as well as fullpath."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000119 self.build()
Johnny Chen41b780d2012-01-18 19:07:08 +0000120
121 exe = os.path.join(os.getcwd(), "a.out")
122 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
123
Filipe Cabecinhas5158f3d2012-05-18 21:35:43 +0000124 def cleanup():
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000125 self.runCmd("settings set frame-format %s" % self.format_string, check=False)
Filipe Cabecinhas5158f3d2012-05-18 21:35:43 +0000126
127 # Execute the cleanup function during test case tear down.
128 self.addTearDownHook(cleanup)
129
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000130 self.runCmd("settings show frame-format")
Richard Mitton5c98c9a2013-10-03 01:50:35 +0000131 m = re.match(
Greg Clayton554f68d2015-02-04 22:00:53 +0000132 '^frame-format \(format-string\) = "(.*)\"$',
Richard Mitton5c98c9a2013-10-03 01:50:35 +0000133 self.res.GetOutput())
134 self.assertTrue(m, "Bad settings string")
135 self.format_string = m.group(1)
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000136
137 # Change the default format to print function.name rather than function.name-with-args
Dawn Perchikdc975672015-06-23 18:35:31 +0000138 format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at ${line.file.fullpath}:${line.number}}{, lang=${language}}\n"
Johnny Chen41b780d2012-01-18 19:07:08 +0000139 self.runCmd("settings set frame-format %s" % format_string)
140
141 # Immediately test the setting.
142 self.expect("settings show frame-format", SETTING_MSG("frame-format"),
143 substrs = [format_string])
144
145 self.runCmd("breakpoint set -n main")
146 self.runCmd("run")
147 self.expect("thread backtrace",
148 substrs = ["`main", os.getcwd()])
149
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000150 def test_set_auto_confirm(self):
151 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000152 self.build()
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000153
154 exe = os.path.join(os.getcwd(), "a.out")
155 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
156
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000157 self.runCmd("settings set auto-confirm true")
158
159 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000160 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000161 startstr = "auto-confirm (boolean) = true")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000162
163 # Now 'breakpoint delete' should just work fine without confirmation
164 # prompt from the command interpreter.
165 self.runCmd("breakpoint set -n main")
166 self.expect("breakpoint delete",
167 startstr = "All breakpoints removed")
168
169 # Restore the original setting of auto-confirm.
Greg Clayton67cc0632012-08-22 17:17:09 +0000170 self.runCmd("settings clear auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +0000171 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000172 startstr = "auto-confirm (boolean) = false")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000173
Todd Fiala68615ce2015-09-15 21:38:04 +0000174 @skipUnlessArch(['x86_64', 'i386', 'i686'])
Daniel Malead79ae052013-08-07 21:54:09 +0000175 def test_disassembler_settings(self):
176 """Test that user options for the disassembler take effect."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000177 self.build()
Daniel Malead79ae052013-08-07 21:54:09 +0000178
179 exe = os.path.join(os.getcwd(), "a.out")
180 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
181
182 # AT&T syntax
183 self.runCmd("settings set target.x86-disassembly-flavor att")
184 self.runCmd("settings set target.use-hex-immediates false")
185 self.expect("disassemble -n numberfn",
186 substrs = ["$90"])
187 self.runCmd("settings set target.use-hex-immediates true")
188 self.runCmd("settings set target.hex-immediate-style c")
189 self.expect("disassemble -n numberfn",
190 substrs = ["$0x5a"])
191 self.runCmd("settings set target.hex-immediate-style asm")
192 self.expect("disassemble -n numberfn",
193 substrs = ["$5ah"])
194
195 # Intel syntax
196 self.runCmd("settings set target.x86-disassembly-flavor intel")
197 self.runCmd("settings set target.use-hex-immediates false")
198 self.expect("disassemble -n numberfn",
199 substrs = ["90"])
200 self.runCmd("settings set target.use-hex-immediates true")
201 self.runCmd("settings set target.hex-immediate-style c")
202 self.expect("disassemble -n numberfn",
203 substrs = ["0x5a"])
204 self.runCmd("settings set target.hex-immediate-style asm")
205 self.expect("disassemble -n numberfn",
206 substrs = ["5ah"])
207
Zachary Turner893b09e2015-08-26 19:44:36 +0000208 @expectedFailureWindows("llvm.org/pr24579")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000209 def test_run_args_and_env_vars(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000210 """Test that run-args and env-vars are passed to the launched process."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000211 self.build()
Johnny Chend5e111c2010-09-15 22:27:29 +0000212 exe = os.path.join(os.getcwd(), "a.out")
213 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
214
215 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +0000216 # And add hooks to restore the settings during tearDown().
Greg Clayton1d885962011-11-08 02:43:13 +0000217 self.runCmd('settings set target.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +0000218 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000219 lambda: self.runCmd("settings clear target.run-args"))
Greg Clayton1d885962011-11-08 02:43:13 +0000220 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +0000221 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000222 lambda: self.runCmd("settings clear target.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +0000223
Sean Callanan05834cd2015-07-01 23:56:30 +0000224 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chend5e111c2010-09-15 22:27:29 +0000225
226 # Read the output file produced by running the program.
Vince Harroned7cbb22015-02-18 23:14:49 +0000227 if lldb.remote_platform:
228 self.runCmd('platform get-file "output2.txt" "output2.txt"')
Johnny Chena245f932010-12-14 23:43:29 +0000229 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000230 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000231
Johnny Chenbe7da212010-10-08 20:01:03 +0000232 self.expect(output, exe=False,
233 substrs = ["argv[1] matches",
234 "argv[2] matches",
235 "argv[3] matches",
236 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000237
Vince Harroned7cbb22015-02-18 23:14:49 +0000238 @skipIfRemote # it doesn't make sense to send host env to remote target
Johnny Chen80554b82010-12-04 00:44:56 +0000239 def test_pass_host_env_vars(self):
240 """Test that the host env vars are passed to the launched process."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000241 self.build()
Johnny Chen80554b82010-12-04 00:44:56 +0000242
243 exe = os.path.join(os.getcwd(), "a.out")
244 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
245
246 # By default, inherit-env is 'true'.
Greg Clayton1d885962011-11-08 02:43:13 +0000247 self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
248 startstr = "target.inherit-env (boolean) = true")
Johnny Chen80554b82010-12-04 00:44:56 +0000249
250 # Set some host environment variables now.
251 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
252 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
253
Johnny Chena245f932010-12-14 23:43:29 +0000254 # This is the function to unset the two env variables set above.
255 def unset_env_variables():
256 os.environ.pop("MY_HOST_ENV_VAR1")
257 os.environ.pop("MY_HOST_ENV_VAR2")
258
259 self.addTearDownHook(unset_env_variables)
Sean Callanan05834cd2015-07-01 23:56:30 +0000260 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chen80554b82010-12-04 00:44:56 +0000261
262 # Read the output file produced by running the program.
Vince Harroned7cbb22015-02-18 23:14:49 +0000263 if lldb.remote_platform:
264 self.runCmd('platform get-file "output1.txt" "output1.txt"')
Johnny Chena245f932010-12-14 23:43:29 +0000265 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000266 output = f.read()
267
268 self.expect(output, exe=False,
269 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
270 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
271
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000272 def test_set_error_output_path(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000273 """Test that setting target.error/output-path for the launched process works."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000274 self.build()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000275
276 exe = os.path.join(os.getcwd(), "a.out")
277 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
278
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000279 # Set the error-path and output-path and verify both are set.
Greg Clayton1d885962011-11-08 02:43:13 +0000280 self.runCmd("settings set target.error-path stderr.txt")
281 self.runCmd("settings set target.output-path stdout.txt")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000282 # And add hooks to restore the original settings during tearDown().
Johnny Chen707d8222010-10-19 23:40:13 +0000283 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000284 lambda: self.runCmd("settings clear target.output-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000285 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000286 lambda: self.runCmd("settings clear target.error-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000287
Greg Clayton1d885962011-11-08 02:43:13 +0000288 self.expect("settings show target.error-path",
289 SETTING_MSG("target.error-path"),
Vince Harron1f4706c2015-02-18 23:12:26 +0000290 substrs = ['target.error-path (file) = "stderr.txt"'])
Johnny Chen707d8222010-10-19 23:40:13 +0000291
Greg Clayton1d885962011-11-08 02:43:13 +0000292 self.expect("settings show target.output-path",
293 SETTING_MSG("target.output-path"),
Vince Harron1f4706c2015-02-18 23:12:26 +0000294 substrs = ['target.output-path (file) = "stdout.txt"'])
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000295
Sean Callanan05834cd2015-07-01 23:56:30 +0000296 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000297
Vince Harron1f4706c2015-02-18 23:12:26 +0000298 if lldb.remote_platform:
299 self.runCmd('platform get-file "stderr.txt" "stderr.txt"')
300 self.runCmd('platform get-file "stdout.txt" "stdout.txt"')
301
302
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000303 # The 'stderr.txt' file should now exist.
304 self.assertTrue(os.path.isfile("stderr.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000305 "'stderr.txt' exists due to target.error-path.")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000306
307 # Read the output file produced by running the program.
308 with open('stderr.txt', 'r') as f:
309 output = f.read()
310
311 self.expect(output, exe=False,
312 startstr = "This message should go to standard error.")
313
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000314 # The 'stdout.txt' file should now exist.
315 self.assertTrue(os.path.isfile("stdout.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000316 "'stdout.txt' exists due to target.output-path.")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000317
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000318 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000319 with open('stdout.txt', 'r') as f:
320 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000321
Johnny Chenbe7da212010-10-08 20:01:03 +0000322 self.expect(output, exe=False,
323 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000324
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000325 @no_debug_info_test
Caroline Ticec9c235e2011-01-31 18:18:54 +0000326 def test_print_dictionary_setting(self):
Greg Clayton67cc0632012-08-22 17:17:09 +0000327 self.runCmd ("settings clear target.env-vars")
Greg Clayton1d885962011-11-08 02:43:13 +0000328 self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
329 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000330 substrs = [ "MY_VAR=some-value" ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000331 self.runCmd ("settings clear target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000332
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000333 @no_debug_info_test
Caroline Ticec9c235e2011-01-31 18:18:54 +0000334 def test_print_array_setting(self):
Greg Clayton67cc0632012-08-22 17:17:09 +0000335 self.runCmd ("settings clear target.run-args")
Greg Clayton1d885962011-11-08 02:43:13 +0000336 self.runCmd ("settings set target.run-args gobbledy-gook")
337 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000338 substrs = [ '[0]: "gobbledy-gook"' ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000339 self.runCmd ("settings clear target.run-args")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000340
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000341 @no_debug_info_test
Caroline Ticec9c235e2011-01-31 18:18:54 +0000342 def test_settings_with_quotes (self):
Greg Clayton67cc0632012-08-22 17:17:09 +0000343 self.runCmd ("settings clear target.run-args")
Greg Clayton1d885962011-11-08 02:43:13 +0000344 self.runCmd ("settings set target.run-args a b c")
345 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000346 substrs = [ '[0]: "a"',
347 '[1]: "b"',
348 '[2]: "c"' ])
Greg Clayton1d885962011-11-08 02:43:13 +0000349 self.runCmd ("settings set target.run-args 'a b c'")
350 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000351 substrs = [ '[0]: "a b c"' ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000352 self.runCmd ("settings clear target.run-args")
353 self.runCmd ("settings clear target.env-vars")
Greg Clayton1d885962011-11-08 02:43:13 +0000354 self.runCmd ('settings set target.env-vars ["MY_FILE"]="this is a file name with spaces.txt"')
355 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000356 substrs = [ 'MY_FILE=this is a file name with spaces.txt' ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000357 self.runCmd ("settings clear target.env-vars")
Greg Claytonb2e0c112015-06-03 02:02:48 +0000358 # Test and make sure that setting "format-string" settings obeys quotes if they are provided
359 self.runCmd ("settings set thread-format 'abc def' ")
360 self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def"')
361 self.runCmd ('settings set thread-format "abc def" ')
362 self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def"')
363 # Make sure when no quotes are provided that we maintain any trailing spaces
364 self.runCmd ('settings set thread-format abc def ')
365 self.expect ("settings show thread-format", 'thread-format (format-string) = "abc def "')
Greg Claytonf7d163a2015-06-16 23:09:37 +0000366 self.runCmd ('settings clear thread-format')
Caroline Ticec9c235e2011-01-31 18:18:54 +0000367
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000368 @no_debug_info_test
Greg Clayton00108402013-03-06 21:17:06 +0000369 def test_settings_with_trailing_whitespace (self):
370
371 # boolean
372 self.runCmd ("settings set target.skip-prologue true") # Set to known value
373 self.runCmd ("settings set target.skip-prologue false ") # Set to new value with trailing whitespace
374 # Make sure the setting was correctly set to "false"
375 self.expect ("settings show target.skip-prologue", SETTING_MSG("target.skip-prologue"),
376 startstr = "target.skip-prologue (boolean) = false")
377 self.runCmd("settings clear target.skip-prologue", check=False)
378 # integer
379 self.runCmd ("settings set term-width 70") # Set to known value
380 self.runCmd ("settings set term-width 60 \t") # Set to new value with trailing whitespaces
381 self.expect ("settings show term-width", SETTING_MSG("term-width"),
382 startstr = "term-width (int) = 60")
383 self.runCmd("settings clear term-width", check=False)
384 # string
385 self.runCmd ("settings set target.arg0 abc") # Set to known value
386 self.runCmd ("settings set target.arg0 cde\t ") # Set to new value with trailing whitespaces
387 self.expect ("settings show target.arg0", SETTING_MSG("target.arg0"),
388 startstr = 'target.arg0 (string) = "cde"')
389 self.runCmd("settings clear target.arg0", check=False)
390 # file
Zachary Turner83887fb2015-01-21 00:40:27 +0000391 path1 = os.path.join(os.getcwd(), "path1.txt")
392 path2 = os.path.join(os.getcwd(), "path2.txt")
393 self.runCmd ("settings set target.output-path %s" % path1) # Set to known value
Greg Clayton00108402013-03-06 21:17:06 +0000394 self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"),
Zachary Turner83887fb2015-01-21 00:40:27 +0000395 startstr = 'target.output-path (file) = ', substrs=[path1])
396 self.runCmd ("settings set target.output-path %s " % path2) # Set to new value with trailing whitespaces
397 self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"),
398 startstr = 'target.output-path (file) = ', substrs=[path2])
Greg Clayton00108402013-03-06 21:17:06 +0000399 self.runCmd("settings clear target.output-path", check=False)
400 # enum
401 self.runCmd ("settings set stop-disassembly-display never") # Set to known value
402 self.runCmd ("settings set stop-disassembly-display always ") # Set to new value with trailing whitespaces
403 self.expect ("settings show stop-disassembly-display", SETTING_MSG("stop-disassembly-display"),
404 startstr = 'stop-disassembly-display (enum) = always')
405 self.runCmd("settings clear stop-disassembly-display", check=False)
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000406 # language
407 self.runCmd ("settings set target.language c89") # Set to known value
408 self.runCmd ("settings set target.language pascal ") # Set to new value with trailing whitespace
409 self.expect ("settings show target.language", SETTING_MSG("target.language"),
410 startstr = "target.language (language) = pascal")
411 self.runCmd("settings clear target.language", check=False)
Greg Clayton00108402013-03-06 21:17:06 +0000412 # arguments
413 self.runCmd ("settings set target.run-args 1 2 3") # Set to known value
414 self.runCmd ("settings set target.run-args 3 4 5 ") # Set to new value with trailing whitespaces
415 self.expect ("settings show target.run-args", SETTING_MSG("target.run-args"),
416 substrs = [ 'target.run-args (arguments) =',
417 '[0]: "3"',
418 '[1]: "4"',
419 '[2]: "5"' ])
Pavel Labathdf50f942015-02-16 13:13:39 +0000420 self.runCmd ("settings set target.run-args 1 2 3") # Set to known value
421 self.runCmd ("settings set target.run-args 3 \ \ ") # Set to new value with trailing whitespaces
422 self.expect ("settings show target.run-args", SETTING_MSG("target.run-args"),
423 substrs = [ 'target.run-args (arguments) =',
424 '[0]: "3"',
425 '[1]: " "',
426 '[2]: " "' ])
Greg Clayton00108402013-03-06 21:17:06 +0000427 self.runCmd("settings clear target.run-args", check=False)
428 # dictionaries
429 self.runCmd ("settings clear target.env-vars") # Set to known value
430 self.runCmd ("settings set target.env-vars A=B C=D\t ") # Set to new value with trailing whitespaces
431 self.expect ("settings show target.env-vars", SETTING_MSG("target.env-vars"),
432 substrs = [ 'target.env-vars (dictionary of strings) =',
433 'A=B',
434 'C=D'])
435 self.runCmd("settings clear target.env-vars", check=False)
Pavel Labathdf50f942015-02-16 13:13:39 +0000436 # regex
437 self.runCmd ("settings clear target.process.thread.step-avoid-regexp") # Set to known value
438 self.runCmd ("settings set target.process.thread.step-avoid-regexp foo\\ ") # Set to new value with trailing whitespaces
439 self.expect ("settings show target.process.thread.step-avoid-regexp",
440 SETTING_MSG("target.process.thread.step-avoid-regexp"),
441 substrs = [ 'target.process.thread.step-avoid-regexp (regex) = foo\\ '])
442 self.runCmd("settings clear target.process.thread.step-avoid-regexp", check=False)
443 # format-string
444 self.runCmd ("settings clear disassembly-format") # Set to known value
445 self.runCmd ("settings set disassembly-format foo ") # Set to new value with trailing whitespaces
446 self.expect ("settings show disassembly-format",
447 SETTING_MSG("disassembly-format"),
448 substrs = [ 'disassembly-format (format-string) = "foo "'])
449 self.runCmd("settings clear disassembly-format", check=False)
Todd Fiala68615ce2015-09-15 21:38:04 +0000450
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000451 @no_debug_info_test
Caroline Ticeb904ca52011-03-10 22:29:54 +0000452 def test_all_settings_exist (self):
453 self.expect ("settings show",
Greg Clayton67cc0632012-08-22 17:17:09 +0000454 substrs = [ "auto-confirm",
455 "frame-format",
456 "notify-void",
457 "prompt",
458 "script-lang",
459 "stop-disassembly-count",
460 "stop-disassembly-display",
461 "stop-line-count-after",
462 "stop-line-count-before",
463 "term-width",
464 "thread-format",
465 "use-external-editor",
466 "target.default-arch",
Ilia K055ad9b2015-05-18 13:41:01 +0000467 "target.move-to-nearest-code",
Greg Clayton67cc0632012-08-22 17:17:09 +0000468 "target.expr-prefix",
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000469 "target.language",
Greg Clayton67cc0632012-08-22 17:17:09 +0000470 "target.prefer-dynamic-value",
471 "target.enable-synthetic-value",
472 "target.skip-prologue",
473 "target.source-map",
474 "target.exec-search-paths",
475 "target.max-children-count",
476 "target.max-string-summary-length",
477 "target.breakpoints-use-platform-avoid-list",
478 "target.run-args",
479 "target.env-vars",
480 "target.inherit-env",
481 "target.input-path",
482 "target.output-path",
483 "target.error-path",
484 "target.disable-aslr",
485 "target.disable-stdio",
Daniel Malead79ae052013-08-07 21:54:09 +0000486 "target.x86-disassembly-flavor",
487 "target.use-hex-immediates",
488 "target.hex-immediate-style",
Greg Clayton67cc0632012-08-22 17:17:09 +0000489 "target.process.disable-memory-cache",
490 "target.process.extra-startup-command",
491 "target.process.thread.step-avoid-regexp",
492 "target.process.thread.trace-thread"])
493
Caroline Ticeb904ca52011-03-10 22:29:54 +0000494
495
Johnny Chen77377772010-09-07 17:06:13 +0000496if __name__ == '__main__':
497 import atexit
498 lldb.SBDebugger.Initialize()
499 atexit.register(lambda: lldb.SBDebugger.Terminate())
500 unittest2.main()