3 Test lldb-mi -gdb-set and -gdb-show commands for 'print option-name'.
6 from __future__ import print_function
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
15 class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
17 mydir = TestBase.compute_mydir(__file__)
19 # evaluates array when char-array-as-string is off
20 def eval_and_check_array(self, var, typ, length):
21 self.runCmd("-var-create - * %s" % var)
23 '\^done,name="var\d+",numchild="%d",value="\[%d\]",type="%s \[%d\]",thread-id="1",has_more="0"' %
24 (length, length, typ, length))
26 # evaluates any type which can be represented as string of characters
27 def eval_and_match_string(self, var, value, typ):
28 value = value.replace("\\", "\\\\").replace("\"", "\\\"")
29 self.runCmd("-var-create - * " + var)
31 '\^done,name="var\d+",numchild="[0-9]+",value="%s",type="%s",thread-id="1",has_more="0"' %
34 @skipIfWindows # llvm.org/pr24452: Get lldb-mi working on Windows
35 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
36 @skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots
37 def test_lldbmi_gdb_set_show_print_char_array_as_string(self):
38 """Test that 'lldb-mi --interpreter' can print array of chars as string."""
40 self.spawnLldbMi(args=None)
43 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
46 # Run to BP_gdb_set_show_print_char_array_as_string_test
49 '// BP_gdb_set_show_print_char_array_as_string_test')
50 self.runCmd("-break-insert main.cpp:%d" % line)
51 self.expect("\^done,bkpt={number=\"1\"")
52 self.runCmd("-exec-run")
53 self.expect("\^running")
54 self.expect("\*stopped,reason=\"breakpoint-hit\"")
56 # Test that default print char-array-as-string value is "off"
57 self.runCmd("-gdb-show print char-array-as-string")
58 self.expect("\^done,value=\"off\"")
60 # Test that a char* is expanded to string when print
61 # char-array-as-string is "off"
62 self.eval_and_match_string(
64 r'0x[0-9a-f]+ \"\\t\\\"hello\\\"\\n\"',
67 # Test that a char[] isn't expanded to string when print
68 # char-array-as-string is "off"
69 self.eval_and_check_array("ca", "const char", 10)
71 # Test that a char16_t* is expanded to string when print
72 # char-array-as-string is "off"
73 self.eval_and_match_string(
75 r'0x[0-9a-f]+ u\"\\t\\\"hello\\\"\\n\"',
78 # Test that a char16_t[] isn't expanded to string when print
79 # char-array-as-string is "off"
80 self.eval_and_check_array("u16a", "const char16_t", 10)
82 # Test that a char32_t* is expanded to string when print
83 # char-array-as-string is "off"
84 self.eval_and_match_string(
86 r'0x[0-9a-f]+ U\"\\t\\\"hello\\\"\\n\"',
89 # Test that a char32_t[] isn't expanded to string when print
90 # char-array-as-string is "off"
91 self.eval_and_check_array("u32a", "const char32_t", 10)
93 # Test that -gdb-set can set print char-array-as-string flag
94 self.runCmd("-gdb-set print char-array-as-string on")
96 self.runCmd("-gdb-set print char-array-as-string 1")
98 self.runCmd("-gdb-show print char-array-as-string")
99 self.expect("\^done,value=\"on\"")
101 # Test that a char* with escape chars is expanded to string when print
102 # char-array-as-string is "on"
103 self.eval_and_match_string(
105 r'0x[0-9a-f]+ \"\\t\\\"hello\\\"\\n\"',
108 # Test that a char[] with escape chars is expanded to string when print
109 # char-array-as-string is "on"
110 self.eval_and_match_string(
112 r'\"\\t\\\"hello\\\"\\n\"',
113 r'const char \[10\]')
115 # Test that a char16_t* with escape chars is expanded to string when
116 # print char-array-as-string is "on"
117 self.eval_and_match_string(
119 r'0x[0-9a-f]+ u\"\\t\\\"hello\\\"\\n\"',
120 r'const char16_t \*')
122 # Test that a char16_t[] with escape chars is expanded to string when
123 # print char-array-as-string is "on"
124 self.eval_and_match_string(
126 r'u\"\\t\\\"hello\\\"\\n\"',
127 r'const char16_t \[10\]')
129 # Test that a char32_t* with escape chars is expanded to string when
130 # print char-array-as-string is "on"
131 self.eval_and_match_string(
133 r'0x[0-9a-f]+ U\"\\t\\\"hello\\\"\\n\"',
134 r'const char32_t \*')
136 # Test that a char32_t[] with escape chars is expanded to string when
137 # print char-array-as-string is "on"
138 self.eval_and_match_string(
140 r'U\"\\t\\\"hello\\\"\\n\"',
141 r'const char32_t \[10\]')
143 # Test russian unicode strings
144 self.eval_and_match_string(
146 r'0x[0-9a-f]+ u\"\\\\Аламо-сквер\"',
147 r'const char16_t \*')
148 self.eval_and_match_string(
151 r'const char16_t \[8\]')
152 self.eval_and_match_string(
154 r'0x[0-9a-f]+ U\"\\\\Чайнатаун\"',
155 r'const char32_t \*')
156 self.eval_and_match_string(
159 r'const char32_t \[9\]')
161 # Test that -gdb-set print char-array-as-string fails if "on"/"off"
163 self.runCmd("-gdb-set print char-array-as-string")
165 "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
167 # Test that -gdb-set print char-array-as-string fails when option is
169 self.runCmd("-gdb-set print char-array-as-string unknown")
171 "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
173 @skipIfWindows # llvm.org/pr24452: Get lldb-mi working on Windows
174 @expectedFailureAll(compiler="gcc", bugnumber="llvm.org/pr23357")
175 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
176 def test_lldbmi_gdb_set_show_print_expand_aggregates(self):
177 """Test that 'lldb-mi --interpreter' can expand aggregates everywhere."""
179 self.spawnLldbMi(args=None)
182 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
183 self.expect("\^done")
185 # Run to BP_gdb_set_show_print_expand_aggregates
188 '// BP_gdb_set_show_print_expand_aggregates')
189 self.runCmd("-break-insert main.cpp:%d" % line)
190 self.expect("\^done,bkpt={number=\"1\"")
191 self.runCmd("-exec-run")
192 self.expect("\^running")
193 self.expect("\*stopped,reason=\"breakpoint-hit\"")
195 # Test that default print expand-aggregates value is "off"
196 self.runCmd("-gdb-show print expand-aggregates")
197 self.expect("\^done,value=\"off\"")
199 # Test that composite type isn't expanded when print expand-aggregates
201 self.runCmd("-var-create var1 * complx")
203 "\^done,name=\"var1\",numchild=\"3\",value=\"{\.\.\.}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
205 # Test that composite type[] isn't expanded when print
206 # expand-aggregates is "off"
207 self.eval_and_check_array("complx_array", "complex_type", 2)
209 # Test that a struct with a char first element is not formatted as a
211 self.runCmd("-var-create - * &nstr")
213 "\^done,name=\"var\d+\",numchild=\"2\",value=\"0x[0-9a-f]+\",type=\"not_str \*\",thread-id=\"1\",has_more=\"0\"")
215 # Test that -gdb-set can set print expand-aggregates flag
216 self.runCmd("-gdb-set print expand-aggregates on")
217 self.expect("\^done")
218 self.runCmd("-gdb-set print expand-aggregates 1")
219 self.expect("\^done")
220 self.runCmd("-gdb-show print expand-aggregates")
221 self.expect("\^done,value=\"on\"")
223 # Test that composite type is expanded when print expand-aggregates is
225 self.runCmd("-var-create var3 * complx")
227 "\^done,name=\"var3\",numchild=\"3\",value=\"{i = 3, inner = {l = 3}, complex_ptr = 0x[0-9a-f]+}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
229 # Test that composite type[] is expanded when print expand-aggregates
231 self.runCmd("-var-create var4 * complx_array")
233 "\^done,name=\"var4\",numchild=\"2\",value=\"{\[0\] = {i = 4, inner = {l = 4}, complex_ptr = 0x[0-9a-f]+}, \[1\] = {i = 5, inner = {l = 5}, complex_ptr = 0x[0-9a-f]+}}\",type=\"complex_type \[2\]\",thread-id=\"1\",has_more=\"0\"")
235 # Test that -gdb-set print expand-aggregates fails if "on"/"off" isn't
237 self.runCmd("-gdb-set print expand-aggregates")
239 "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
241 # Test that -gdb-set print expand-aggregates fails when option is
243 self.runCmd("-gdb-set print expand-aggregates unknown")
245 "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
247 @skipIfWindows # llvm.org/pr24452: Get lldb-mi working on Windows
248 @expectedFailureAll(compiler="gcc", bugnumber="llvm.org/pr23357")
249 @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
250 def test_lldbmi_gdb_set_show_print_aggregate_field_names(self):
251 """Test that 'lldb-mi --interpreter' can expand aggregates everywhere."""
253 self.spawnLldbMi(args=None)
256 self.runCmd("-file-exec-and-symbols %s" % self.myexe)
257 self.expect("\^done")
259 # Run to BP_gdb_set_show_print_aggregate_field_names
262 '// BP_gdb_set_show_print_aggregate_field_names')
263 self.runCmd("-break-insert main.cpp:%d" % line)
264 self.expect("\^done,bkpt={number=\"1\"")
265 self.runCmd("-exec-run")
266 self.expect("\^running")
267 self.expect("\*stopped,reason=\"breakpoint-hit\"")
269 # Test that default print aggregatep-field-names value is "on"
270 self.runCmd("-gdb-show print aggregate-field-names")
271 self.expect("\^done,value=\"on\"")
273 # Set print expand-aggregates flag to "on"
274 self.runCmd("-gdb-set print expand-aggregates on")
275 self.expect("\^done")
277 # Test that composite type is expanded with field name when print
278 # aggregate-field-names is "on"
279 self.runCmd("-var-create var1 * complx")
281 "\^done,name=\"var1\",numchild=\"3\",value=\"{i = 3, inner = {l = 3}, complex_ptr = 0x[0-9a-f]+}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
283 # Test that composite type[] is expanded with field name when print
284 # aggregate-field-names is "on"
285 self.runCmd("-var-create var2 * complx_array")
287 "\^done,name=\"var2\",numchild=\"2\",value=\"{\[0\] = {i = 4, inner = {l = 4}, complex_ptr = 0x[0-9a-f]+}, \[1\] = {i = 5, inner = {l = 5}, complex_ptr = 0x[0-9a-f]+}}\",type=\"complex_type \[2\]\",thread-id=\"1\",has_more=\"0\"")
289 # Test that -gdb-set can set print aggregate-field-names flag
290 self.runCmd("-gdb-set print aggregate-field-names off")
291 self.expect("\^done")
292 self.runCmd("-gdb-set print aggregate-field-names 0")
293 self.expect("\^done")
294 self.runCmd("-gdb-show print aggregate-field-names")
295 self.expect("\^done,value=\"off\"")
297 # Test that composite type is expanded without field name when print
298 # aggregate-field-names is "off"
299 self.runCmd("-var-create var3 * complx")
301 "\^done,name=\"var3\",numchild=\"3\",value=\"{3,\{3\},0x[0-9a-f]+}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
303 # Test that composite type[] is expanded without field name when print
304 # aggregate-field-names is "off"
305 self.runCmd("-var-create var4 * complx_array")
307 "\^done,name=\"var4\",numchild=\"2\",value=\"{{4,\{4\},0x[0-9a-f]+},{5,\{5\},0x[0-9a-f]+}}\",type=\"complex_type \[2\]\",thread-id=\"1\",has_more=\"0\"")
309 # Test that -gdb-set print aggregate-field-names fails if "on"/"off"
311 self.runCmd("-gdb-set print aggregate-field-names")
313 "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
315 # Test that -gdb-set print aggregate-field-names fails when option is
317 self.runCmd("-gdb-set print aggregate-field-names unknown")
319 "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")