blob: c29207bdd39cad8c7256d1358f4dede933d2d589 [file] [log] [blame]
Johnny Chen77377772010-09-07 17:06:13 +00001"""
2Test lldb settings command.
3"""
4
Zachary Turner35d017f2015-10-23 17:04:29 +00005from __future__ import print_function
6
Zachary Turner0a0490b2015-10-27 20:12:05 +00007import use_lldb_suite
Zachary Turner77db4a82015-10-22 20:06:20 +00008
Richard Mitton5c98c9a2013-10-03 01:50:35 +00009import os, time, re
Johnny Chen77377772010-09-07 17:06:13 +000010import lldb
Zachary Turner95c453a2015-11-03 02:06:18 +000011from lldbsuite.test.lldbtest import *
Johnny Chen77377772010-09-07 17:06:13 +000012
13class SettingsCommandTestCase(TestBase):
14
Greg Clayton4570d3e2013-12-10 23:19:29 +000015 mydir = TestBase.compute_mydir(__file__)
Johnny Chen77377772010-09-07 17:06:13 +000016
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000017 @classmethod
18 def classCleanup(cls):
Johnny Chena91b9472010-10-22 21:06:04 +000019 """Cleanup the test byproducts."""
Filipe Cabecinhas0eec15a2012-06-20 10:13:40 +000020 cls.RemoveTempFile("output1.txt")
21 cls.RemoveTempFile("output2.txt")
22 cls.RemoveTempFile("stderr.txt")
23 cls.RemoveTempFile("stdout.txt")
Johnny Chen1a9f4dd2010-09-16 01:53:04 +000024
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000025 @no_debug_info_test
Johnny Chen7fa6c952011-02-04 00:50:49 +000026 def test_apropos_should_also_search_settings_description(self):
27 """Test that 'apropos' command should also search descriptions for the settings variables."""
28
29 self.expect("apropos 'environment variable'",
Greg Clayton1d885962011-11-08 02:43:13 +000030 substrs = ["target.env-vars",
Johnny Chen7fa6c952011-02-04 00:50:49 +000031 "environment variables",
32 "executable's environment"])
33
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000034 @no_debug_info_test
Johnny Chen8cc80b22012-01-23 19:49:28 +000035 def test_append_target_env_vars(self):
Greg Clayton67cc0632012-08-22 17:17:09 +000036 """Test that 'append target.run-args' works."""
Johnny Chen8cc80b22012-01-23 19:49:28 +000037 # Append the env-vars.
38 self.runCmd('settings append target.env-vars MY_ENV_VAR=YES')
39 # And add hooks to restore the settings during tearDown().
40 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000041 lambda: self.runCmd("settings clear target.env-vars"))
Johnny Chen8cc80b22012-01-23 19:49:28 +000042
43 # Check it immediately!
44 self.expect('settings show target.env-vars',
45 substrs = ['MY_ENV_VAR=YES'])
46
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000047 @no_debug_info_test
Johnny Chen8cc80b22012-01-23 19:49:28 +000048 def test_insert_before_and_after_target_run_args(self):
49 """Test that 'insert-before/after target.run-args' works."""
50 # Set the run-args first.
51 self.runCmd('settings set target.run-args a b c')
52 # And add hooks to restore the settings during tearDown().
53 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000054 lambda: self.runCmd("settings clear target.run-args"))
Johnny Chen8cc80b22012-01-23 19:49:28 +000055
56 # Now insert-before the index-0 element with '__a__'.
57 self.runCmd('settings insert-before target.run-args 0 __a__')
58 # And insert-after the index-1 element with '__A__'.
59 self.runCmd('settings insert-after target.run-args 1 __A__')
60 # Check it immediately!
61 self.expect('settings show target.run-args',
Greg Clayton67cc0632012-08-22 17:17:09 +000062 substrs = ['target.run-args',
Johnny Chen8cc80b22012-01-23 19:49:28 +000063 '[0]: "__a__"',
64 '[1]: "a"',
65 '[2]: "__A__"',
66 '[3]: "b"',
67 '[4]: "c"'])
68
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000069 @no_debug_info_test
Johnny Chen5928f642012-01-21 01:45:18 +000070 def test_replace_target_run_args(self):
71 """Test that 'replace target.run-args' works."""
72 # Set the run-args and then replace the index-0 element.
73 self.runCmd('settings set target.run-args a b c')
74 # And add hooks to restore the settings during tearDown().
75 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +000076 lambda: self.runCmd("settings clear target.run-args"))
Johnny Chen5928f642012-01-21 01:45:18 +000077
78 # Now replace the index-0 element with 'A', instead.
79 self.runCmd('settings replace target.run-args 0 A')
80 # Check it immediately!
81 self.expect('settings show target.run-args',
Greg Clayton67cc0632012-08-22 17:17:09 +000082 substrs = ['target.run-args (arguments) =',
Johnny Chen5928f642012-01-21 01:45:18 +000083 '[0]: "A"',
84 '[1]: "b"',
85 '[2]: "c"'])
86
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000087 @no_debug_info_test
Johnny Chen77377772010-09-07 17:06:13 +000088 def test_set_prompt(self):
89 """Test that 'set prompt' actually changes the prompt."""
Johnny Chen881c3712010-09-07 17:12:10 +000090
Johnny Chen23cb3712010-09-27 17:36:59 +000091 # Set prompt to 'lldb2'.
Greg Clayton00108402013-03-06 21:17:06 +000092 self.runCmd("settings set prompt 'lldb2 '")
Johnny Chen881c3712010-09-07 17:12:10 +000093
94 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +000095 self.expect("settings show prompt", SETTING_MSG("prompt"),
Greg Clayton00108402013-03-06 21:17:06 +000096 startstr = 'prompt (string) = "lldb2 "')
Johnny Chen881c3712010-09-07 17:12:10 +000097
98 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +000099 self.expect("settings show", SETTING_MSG("prompt"),
Greg Clayton00108402013-03-06 21:17:06 +0000100 substrs = ['prompt (string) = "lldb2 "'])
Johnny Chen77377772010-09-07 17:06:13 +0000101
Johnny Chen23cb3712010-09-27 17:36:59 +0000102 # Use '-r' option to reset to the original default prompt.
Greg Clayton67cc0632012-08-22 17:17:09 +0000103 self.runCmd("settings clear prompt")
Johnny Chen23cb3712010-09-27 17:36:59 +0000104
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000105 @no_debug_info_test
Johnny Chena37764b2010-09-07 17:31:05 +0000106 def test_set_term_width(self):
107 """Test that 'set term-width' actually changes the term-width."""
108
Johnny Chena37764b2010-09-07 17:31:05 +0000109 self.runCmd("settings set term-width 70")
110
111 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000112 self.expect("settings show term-width", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +0000113 startstr = "term-width (int) = 70")
Johnny Chena37764b2010-09-07 17:31:05 +0000114
115 # The overall display should also reflect the new setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000116 self.expect("settings show", SETTING_MSG("term-width"),
Greg Clayton4c207172011-04-19 22:32:36 +0000117 substrs = ["term-width (int) = 70"])
Johnny Chena37764b2010-09-07 17:31:05 +0000118
Johnny Chen41b780d2012-01-18 19:07:08 +0000119 #rdar://problem/10712130
Johnny Chen41b780d2012-01-18 19:07:08 +0000120 def test_set_frame_format(self):
121 """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 +0000122 self.build()
Johnny Chen41b780d2012-01-18 19:07:08 +0000123
124 exe = os.path.join(os.getcwd(), "a.out")
125 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
126
Filipe Cabecinhas5158f3d2012-05-18 21:35:43 +0000127 def cleanup():
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000128 self.runCmd("settings set frame-format %s" % self.format_string, check=False)
Filipe Cabecinhas5158f3d2012-05-18 21:35:43 +0000129
130 # Execute the cleanup function during test case tear down.
131 self.addTearDownHook(cleanup)
132
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000133 self.runCmd("settings show frame-format")
Richard Mitton5c98c9a2013-10-03 01:50:35 +0000134 m = re.match(
Greg Clayton554f68d2015-02-04 22:00:53 +0000135 '^frame-format \(format-string\) = "(.*)\"$',
Richard Mitton5c98c9a2013-10-03 01:50:35 +0000136 self.res.GetOutput())
137 self.assertTrue(m, "Bad settings string")
138 self.format_string = m.group(1)
Ashok Thirumurthibb82b842013-09-25 15:30:14 +0000139
140 # Change the default format to print function.name rather than function.name-with-args
Dawn Perchikdc975672015-06-23 18:35:31 +0000141 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 +0000142 self.runCmd("settings set frame-format %s" % format_string)
143
144 # Immediately test the setting.
145 self.expect("settings show frame-format", SETTING_MSG("frame-format"),
146 substrs = [format_string])
147
148 self.runCmd("breakpoint set -n main")
149 self.runCmd("run")
150 self.expect("thread backtrace",
151 substrs = ["`main", os.getcwd()])
152
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000153 def test_set_auto_confirm(self):
154 """Test that after 'set auto-confirm true', manual confirmation should not kick in."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000155 self.build()
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000156
157 exe = os.path.join(os.getcwd(), "a.out")
158 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
159
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000160 self.runCmd("settings set auto-confirm true")
161
162 # Immediately test the setting.
Johnny Chena913ea42010-10-19 19:39:20 +0000163 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000164 startstr = "auto-confirm (boolean) = true")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000165
166 # Now 'breakpoint delete' should just work fine without confirmation
167 # prompt from the command interpreter.
168 self.runCmd("breakpoint set -n main")
169 self.expect("breakpoint delete",
170 startstr = "All breakpoints removed")
171
172 # Restore the original setting of auto-confirm.
Greg Clayton67cc0632012-08-22 17:17:09 +0000173 self.runCmd("settings clear auto-confirm")
Johnny Chena913ea42010-10-19 19:39:20 +0000174 self.expect("settings show auto-confirm", SETTING_MSG("auto-confirm"),
Greg Clayton4c207172011-04-19 22:32:36 +0000175 startstr = "auto-confirm (boolean) = false")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000176
Todd Fiala68615ce2015-09-15 21:38:04 +0000177 @skipUnlessArch(['x86_64', 'i386', 'i686'])
Daniel Malead79ae052013-08-07 21:54:09 +0000178 def test_disassembler_settings(self):
179 """Test that user options for the disassembler take effect."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000180 self.build()
Daniel Malead79ae052013-08-07 21:54:09 +0000181
182 exe = os.path.join(os.getcwd(), "a.out")
183 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
184
185 # AT&T syntax
186 self.runCmd("settings set target.x86-disassembly-flavor att")
187 self.runCmd("settings set target.use-hex-immediates false")
188 self.expect("disassemble -n numberfn",
189 substrs = ["$90"])
190 self.runCmd("settings set target.use-hex-immediates true")
191 self.runCmd("settings set target.hex-immediate-style c")
192 self.expect("disassemble -n numberfn",
193 substrs = ["$0x5a"])
194 self.runCmd("settings set target.hex-immediate-style asm")
195 self.expect("disassemble -n numberfn",
196 substrs = ["$5ah"])
197
198 # Intel syntax
199 self.runCmd("settings set target.x86-disassembly-flavor intel")
200 self.runCmd("settings set target.use-hex-immediates false")
201 self.expect("disassemble -n numberfn",
202 substrs = ["90"])
203 self.runCmd("settings set target.use-hex-immediates true")
204 self.runCmd("settings set target.hex-immediate-style c")
205 self.expect("disassemble -n numberfn",
206 substrs = ["0x5a"])
207 self.runCmd("settings set target.hex-immediate-style asm")
208 self.expect("disassemble -n numberfn",
209 substrs = ["5ah"])
210
Zachary Turner893b09e2015-08-26 19:44:36 +0000211 @expectedFailureWindows("llvm.org/pr24579")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000212 def test_run_args_and_env_vars(self):
Johnny Chend5e111c2010-09-15 22:27:29 +0000213 """Test that run-args and env-vars are passed to the launched process."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000214 self.build()
Johnny Chend5e111c2010-09-15 22:27:29 +0000215 exe = os.path.join(os.getcwd(), "a.out")
216 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
217
218 # Set the run-args and the env-vars.
Johnny Chen707d8222010-10-19 23:40:13 +0000219 # And add hooks to restore the settings during tearDown().
Greg Clayton1d885962011-11-08 02:43:13 +0000220 self.runCmd('settings set target.run-args A B C')
Johnny Chen707d8222010-10-19 23:40:13 +0000221 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000222 lambda: self.runCmd("settings clear target.run-args"))
Greg Clayton1d885962011-11-08 02:43:13 +0000223 self.runCmd('settings set target.env-vars ["MY_ENV_VAR"]=YES')
Johnny Chen707d8222010-10-19 23:40:13 +0000224 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000225 lambda: self.runCmd("settings clear target.env-vars"))
Johnny Chend5e111c2010-09-15 22:27:29 +0000226
Sean Callanan05834cd2015-07-01 23:56:30 +0000227 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chend5e111c2010-09-15 22:27:29 +0000228
229 # Read the output file produced by running the program.
Vince Harroned7cbb22015-02-18 23:14:49 +0000230 if lldb.remote_platform:
231 self.runCmd('platform get-file "output2.txt" "output2.txt"')
Johnny Chena245f932010-12-14 23:43:29 +0000232 with open('output2.txt', 'r') as f:
Johnny Chen277c8f02010-10-08 22:10:42 +0000233 output = f.read()
Johnny Chend5e111c2010-09-15 22:27:29 +0000234
Johnny Chenbe7da212010-10-08 20:01:03 +0000235 self.expect(output, exe=False,
236 substrs = ["argv[1] matches",
237 "argv[2] matches",
238 "argv[3] matches",
239 "Environment variable 'MY_ENV_VAR' successfully passed."])
Johnny Chend5e111c2010-09-15 22:27:29 +0000240
Vince Harroned7cbb22015-02-18 23:14:49 +0000241 @skipIfRemote # it doesn't make sense to send host env to remote target
Johnny Chen80554b82010-12-04 00:44:56 +0000242 def test_pass_host_env_vars(self):
243 """Test that the host env vars are passed to the launched process."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000244 self.build()
Johnny Chen80554b82010-12-04 00:44:56 +0000245
246 exe = os.path.join(os.getcwd(), "a.out")
247 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
248
249 # By default, inherit-env is 'true'.
Greg Clayton1d885962011-11-08 02:43:13 +0000250 self.expect('settings show target.inherit-env', "Default inherit-env is 'true'",
251 startstr = "target.inherit-env (boolean) = true")
Johnny Chen80554b82010-12-04 00:44:56 +0000252
253 # Set some host environment variables now.
254 os.environ["MY_HOST_ENV_VAR1"] = "VAR1"
255 os.environ["MY_HOST_ENV_VAR2"] = "VAR2"
256
Johnny Chena245f932010-12-14 23:43:29 +0000257 # This is the function to unset the two env variables set above.
258 def unset_env_variables():
259 os.environ.pop("MY_HOST_ENV_VAR1")
260 os.environ.pop("MY_HOST_ENV_VAR2")
261
262 self.addTearDownHook(unset_env_variables)
Sean Callanan05834cd2015-07-01 23:56:30 +0000263 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chen80554b82010-12-04 00:44:56 +0000264
265 # Read the output file produced by running the program.
Vince Harroned7cbb22015-02-18 23:14:49 +0000266 if lldb.remote_platform:
267 self.runCmd('platform get-file "output1.txt" "output1.txt"')
Johnny Chena245f932010-12-14 23:43:29 +0000268 with open('output1.txt', 'r') as f:
Johnny Chen80554b82010-12-04 00:44:56 +0000269 output = f.read()
270
271 self.expect(output, exe=False,
272 substrs = ["The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.",
273 "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed."])
274
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000275 def test_set_error_output_path(self):
Greg Clayton1d885962011-11-08 02:43:13 +0000276 """Test that setting target.error/output-path for the launched process works."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000277 self.build()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000278
279 exe = os.path.join(os.getcwd(), "a.out")
280 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
281
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000282 # Set the error-path and output-path and verify both are set.
Greg Clayton1d885962011-11-08 02:43:13 +0000283 self.runCmd("settings set target.error-path stderr.txt")
284 self.runCmd("settings set target.output-path stdout.txt")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000285 # And add hooks to restore the original settings during tearDown().
Johnny Chen707d8222010-10-19 23:40:13 +0000286 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000287 lambda: self.runCmd("settings clear target.output-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000288 self.addTearDownHook(
Greg Clayton67cc0632012-08-22 17:17:09 +0000289 lambda: self.runCmd("settings clear target.error-path"))
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000290
Greg Clayton1d885962011-11-08 02:43:13 +0000291 self.expect("settings show target.error-path",
292 SETTING_MSG("target.error-path"),
Vince Harron1f4706c2015-02-18 23:12:26 +0000293 substrs = ['target.error-path (file) = "stderr.txt"'])
Johnny Chen707d8222010-10-19 23:40:13 +0000294
Greg Clayton1d885962011-11-08 02:43:13 +0000295 self.expect("settings show target.output-path",
296 SETTING_MSG("target.output-path"),
Vince Harron1f4706c2015-02-18 23:12:26 +0000297 substrs = ['target.output-path (file) = "stdout.txt"'])
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000298
Sean Callanan05834cd2015-07-01 23:56:30 +0000299 self.runCmd("run", RUN_SUCCEEDED)
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000300
Vince Harron1f4706c2015-02-18 23:12:26 +0000301 if lldb.remote_platform:
302 self.runCmd('platform get-file "stderr.txt" "stderr.txt"')
303 self.runCmd('platform get-file "stdout.txt" "stdout.txt"')
304
305
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000306 # The 'stderr.txt' file should now exist.
307 self.assertTrue(os.path.isfile("stderr.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000308 "'stderr.txt' exists due to target.error-path.")
Johnny Chen93b0c8b2011-01-25 17:39:43 +0000309
310 # Read the output file produced by running the program.
311 with open('stderr.txt', 'r') as f:
312 output = f.read()
313
314 self.expect(output, exe=False,
315 startstr = "This message should go to standard error.")
316
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000317 # The 'stdout.txt' file should now exist.
318 self.assertTrue(os.path.isfile("stdout.txt"),
Greg Clayton1d885962011-11-08 02:43:13 +0000319 "'stdout.txt' exists due to target.output-path.")
Johnny Chen3e9c50c2010-10-18 17:51:45 +0000320
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000321 # Read the output file produced by running the program.
Johnny Chenbe7da212010-10-08 20:01:03 +0000322 with open('stdout.txt', 'r') as f:
323 output = f.read()
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000324
Johnny Chenbe7da212010-10-08 20:01:03 +0000325 self.expect(output, exe=False,
326 startstr = "This message should go to standard out.")
Johnny Chen2fcc0e52010-09-16 18:26:06 +0000327
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000328 @no_debug_info_test
Caroline Ticec9c235e2011-01-31 18:18:54 +0000329 def test_print_dictionary_setting(self):
Greg Clayton67cc0632012-08-22 17:17:09 +0000330 self.runCmd ("settings clear target.env-vars")
Greg Clayton1d885962011-11-08 02:43:13 +0000331 self.runCmd ("settings set target.env-vars [\"MY_VAR\"]=some-value")
332 self.expect ("settings show target.env-vars",
Greg Clayton4c207172011-04-19 22:32:36 +0000333 substrs = [ "MY_VAR=some-value" ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000334 self.runCmd ("settings clear target.env-vars")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000335
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000336 @no_debug_info_test
Caroline Ticec9c235e2011-01-31 18:18:54 +0000337 def test_print_array_setting(self):
Greg Clayton67cc0632012-08-22 17:17:09 +0000338 self.runCmd ("settings clear target.run-args")
Greg Clayton1d885962011-11-08 02:43:13 +0000339 self.runCmd ("settings set target.run-args gobbledy-gook")
340 self.expect ("settings show target.run-args",
Greg Clayton4c207172011-04-19 22:32:36 +0000341 substrs = [ '[0]: "gobbledy-gook"' ])
Greg Clayton67cc0632012-08-22 17:17:09 +0000342 self.runCmd ("settings clear target.run-args")
Caroline Ticec9c235e2011-01-31 18:18:54 +0000343
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000344 @no_debug_info_test
Caroline Ticec9c235e2011-01-31 18:18:54 +0000345 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
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000371 @no_debug_info_test
Greg Clayton00108402013-03-06 21:17:06 +0000372 def test_settings_with_trailing_whitespace (self):
373
374 # boolean
375 self.runCmd ("settings set target.skip-prologue true") # Set to known value
376 self.runCmd ("settings set target.skip-prologue false ") # Set to new value with trailing whitespace
377 # Make sure the setting was correctly set to "false"
378 self.expect ("settings show target.skip-prologue", SETTING_MSG("target.skip-prologue"),
379 startstr = "target.skip-prologue (boolean) = false")
380 self.runCmd("settings clear target.skip-prologue", check=False)
381 # integer
382 self.runCmd ("settings set term-width 70") # Set to known value
383 self.runCmd ("settings set term-width 60 \t") # Set to new value with trailing whitespaces
384 self.expect ("settings show term-width", SETTING_MSG("term-width"),
385 startstr = "term-width (int) = 60")
386 self.runCmd("settings clear term-width", check=False)
387 # string
388 self.runCmd ("settings set target.arg0 abc") # Set to known value
389 self.runCmd ("settings set target.arg0 cde\t ") # Set to new value with trailing whitespaces
390 self.expect ("settings show target.arg0", SETTING_MSG("target.arg0"),
391 startstr = 'target.arg0 (string) = "cde"')
392 self.runCmd("settings clear target.arg0", check=False)
393 # file
Zachary Turner83887fb2015-01-21 00:40:27 +0000394 path1 = os.path.join(os.getcwd(), "path1.txt")
395 path2 = os.path.join(os.getcwd(), "path2.txt")
396 self.runCmd ("settings set target.output-path %s" % path1) # Set to known value
Greg Clayton00108402013-03-06 21:17:06 +0000397 self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"),
Zachary Turner83887fb2015-01-21 00:40:27 +0000398 startstr = 'target.output-path (file) = ', substrs=[path1])
399 self.runCmd ("settings set target.output-path %s " % path2) # Set to new value with trailing whitespaces
400 self.expect ("settings show target.output-path", SETTING_MSG("target.output-path"),
401 startstr = 'target.output-path (file) = ', substrs=[path2])
Greg Clayton00108402013-03-06 21:17:06 +0000402 self.runCmd("settings clear target.output-path", check=False)
403 # enum
404 self.runCmd ("settings set stop-disassembly-display never") # Set to known value
405 self.runCmd ("settings set stop-disassembly-display always ") # Set to new value with trailing whitespaces
406 self.expect ("settings show stop-disassembly-display", SETTING_MSG("stop-disassembly-display"),
407 startstr = 'stop-disassembly-display (enum) = always')
408 self.runCmd("settings clear stop-disassembly-display", check=False)
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000409 # language
410 self.runCmd ("settings set target.language c89") # Set to known value
Tamas Berghammer62a15142015-10-09 11:01:56 +0000411 self.runCmd ("settings set target.language go ") # Set to new value with trailing whitespace
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000412 self.expect ("settings show target.language", SETTING_MSG("target.language"),
Tamas Berghammer62a15142015-10-09 11:01:56 +0000413 startstr = "target.language (language) = go")
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000414 self.runCmd("settings clear target.language", check=False)
Greg Clayton00108402013-03-06 21:17:06 +0000415 # arguments
416 self.runCmd ("settings set target.run-args 1 2 3") # Set to known value
417 self.runCmd ("settings set target.run-args 3 4 5 ") # 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]: "4"',
422 '[2]: "5"' ])
Pavel Labathdf50f942015-02-16 13:13:39 +0000423 self.runCmd ("settings set target.run-args 1 2 3") # Set to known value
424 self.runCmd ("settings set target.run-args 3 \ \ ") # Set to new value with trailing whitespaces
425 self.expect ("settings show target.run-args", SETTING_MSG("target.run-args"),
426 substrs = [ 'target.run-args (arguments) =',
427 '[0]: "3"',
428 '[1]: " "',
429 '[2]: " "' ])
Greg Clayton00108402013-03-06 21:17:06 +0000430 self.runCmd("settings clear target.run-args", check=False)
431 # dictionaries
432 self.runCmd ("settings clear target.env-vars") # Set to known value
433 self.runCmd ("settings set target.env-vars A=B C=D\t ") # Set to new value with trailing whitespaces
434 self.expect ("settings show target.env-vars", SETTING_MSG("target.env-vars"),
435 substrs = [ 'target.env-vars (dictionary of strings) =',
436 'A=B',
437 'C=D'])
438 self.runCmd("settings clear target.env-vars", check=False)
Pavel Labathdf50f942015-02-16 13:13:39 +0000439 # regex
440 self.runCmd ("settings clear target.process.thread.step-avoid-regexp") # Set to known value
441 self.runCmd ("settings set target.process.thread.step-avoid-regexp foo\\ ") # Set to new value with trailing whitespaces
442 self.expect ("settings show target.process.thread.step-avoid-regexp",
443 SETTING_MSG("target.process.thread.step-avoid-regexp"),
444 substrs = [ 'target.process.thread.step-avoid-regexp (regex) = foo\\ '])
445 self.runCmd("settings clear target.process.thread.step-avoid-regexp", check=False)
446 # format-string
447 self.runCmd ("settings clear disassembly-format") # Set to known value
448 self.runCmd ("settings set disassembly-format foo ") # Set to new value with trailing whitespaces
449 self.expect ("settings show disassembly-format",
450 SETTING_MSG("disassembly-format"),
451 substrs = [ 'disassembly-format (format-string) = "foo "'])
452 self.runCmd("settings clear disassembly-format", check=False)
Todd Fiala68615ce2015-09-15 21:38:04 +0000453
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000454 @no_debug_info_test
Caroline Ticeb904ca52011-03-10 22:29:54 +0000455 def test_all_settings_exist (self):
456 self.expect ("settings show",
Greg Clayton67cc0632012-08-22 17:17:09 +0000457 substrs = [ "auto-confirm",
458 "frame-format",
459 "notify-void",
460 "prompt",
461 "script-lang",
462 "stop-disassembly-count",
463 "stop-disassembly-display",
464 "stop-line-count-after",
465 "stop-line-count-before",
466 "term-width",
467 "thread-format",
468 "use-external-editor",
469 "target.default-arch",
Ilia K055ad9b2015-05-18 13:41:01 +0000470 "target.move-to-nearest-code",
Greg Clayton67cc0632012-08-22 17:17:09 +0000471 "target.expr-prefix",
Dawn Perchik23b1dec2015-07-21 22:05:07 +0000472 "target.language",
Greg Clayton67cc0632012-08-22 17:17:09 +0000473 "target.prefer-dynamic-value",
474 "target.enable-synthetic-value",
475 "target.skip-prologue",
476 "target.source-map",
477 "target.exec-search-paths",
478 "target.max-children-count",
479 "target.max-string-summary-length",
480 "target.breakpoints-use-platform-avoid-list",
481 "target.run-args",
482 "target.env-vars",
483 "target.inherit-env",
484 "target.input-path",
485 "target.output-path",
486 "target.error-path",
487 "target.disable-aslr",
488 "target.disable-stdio",
Daniel Malead79ae052013-08-07 21:54:09 +0000489 "target.x86-disassembly-flavor",
490 "target.use-hex-immediates",
491 "target.hex-immediate-style",
Greg Clayton67cc0632012-08-22 17:17:09 +0000492 "target.process.disable-memory-cache",
493 "target.process.extra-startup-command",
494 "target.process.thread.step-avoid-regexp",
495 "target.process.thread.trace-thread"])