]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / tools / lldb-mi / variable / TestMiGdbSetShowPrint.py
1 # coding=utf8
2 """
3 Test lldb-mi -gdb-set and -gdb-show commands for 'print option-name'.
4 """
5
6 from __future__ import print_function
7
8
9 import lldbmi_testcase
10 from lldbsuite.test.decorators import *
11 from lldbsuite.test.lldbtest import *
12 from lldbsuite.test import lldbutil
13
14
15 class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
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)
22         self.expect(
23             '\^done,name="var\d+",numchild="%d",value="\[%d\]",type="%s \[%d\]",thread-id="1",has_more="0"' %
24             (length, length, typ, length))
25
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)
30         self.expect(
31             '\^done,name="var\d+",numchild="[0-9]+",value="%s",type="%s",thread-id="1",has_more="0"' %
32             (value, typ))
33
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."""
39
40         self.spawnLldbMi(args=None)
41
42         # Load executable
43         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
44         self.expect("\^done")
45
46         # Run to BP_gdb_set_show_print_char_array_as_string_test
47         line = line_number(
48             'main.cpp',
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\"")
55
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\"")
59
60         # Test that a char* is expanded to string when print
61         # char-array-as-string is "off"
62         self.eval_and_match_string(
63             "cp",
64             r'0x[0-9a-f]+ \"\\t\\\"hello\\\"\\n\"',
65             r'const char \*')
66
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)
70
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(
74             "u16p",
75             r'0x[0-9a-f]+ u\"\\t\\\"hello\\\"\\n\"',
76             r'const char16_t \*')
77
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)
81
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(
85             "u32p",
86             r'0x[0-9a-f]+ U\"\\t\\\"hello\\\"\\n\"',
87             r'const char32_t \*')
88
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)
92
93         # Test that -gdb-set can set print char-array-as-string flag
94         self.runCmd("-gdb-set print char-array-as-string on")
95         self.expect("\^done")
96         self.runCmd("-gdb-set print char-array-as-string 1")
97         self.expect("\^done")
98         self.runCmd("-gdb-show print char-array-as-string")
99         self.expect("\^done,value=\"on\"")
100
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(
104             "cp",
105             r'0x[0-9a-f]+ \"\\t\\\"hello\\\"\\n\"',
106             r'const char \*')
107
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(
111             "ca",
112             r'\"\\t\\\"hello\\\"\\n\"',
113             r'const char \[10\]')
114
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(
118             "u16p",
119             r'0x[0-9a-f]+ u\"\\t\\\"hello\\\"\\n\"',
120             r'const char16_t \*')
121
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(
125             "u16a",
126             r'u\"\\t\\\"hello\\\"\\n\"',
127             r'const char16_t \[10\]')
128
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(
132             "u32p",
133             r'0x[0-9a-f]+ U\"\\t\\\"hello\\\"\\n\"',
134             r'const char32_t \*')
135
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(
139             "u32a",
140             r'U\"\\t\\\"hello\\\"\\n\"',
141             r'const char32_t \[10\]')
142
143         # Test russian unicode strings
144         self.eval_and_match_string(
145             "u16p_rus",
146             r'0x[0-9a-f]+ u\"\\\\Аламо-сквер\"',
147             r'const char16_t \*')
148         self.eval_and_match_string(
149             "u16a_rus",
150             r'u\"\\\\Бейвью\"',
151             r'const char16_t \[8\]')
152         self.eval_and_match_string(
153             "u32p_rus",
154             r'0x[0-9a-f]+ U\"\\\\Чайнатаун\"',
155             r'const char32_t \*')
156         self.eval_and_match_string(
157             "u32a_rus",
158             r'U\"\\\\Догпатч\"',
159             r'const char32_t \[9\]')
160
161         # Test that -gdb-set print char-array-as-string fails if "on"/"off"
162         # isn't specified
163         self.runCmd("-gdb-set print char-array-as-string")
164         self.expect(
165             "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
166
167         # Test that -gdb-set print char-array-as-string fails when option is
168         # unknown
169         self.runCmd("-gdb-set print char-array-as-string unknown")
170         self.expect(
171             "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
172
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."""
178
179         self.spawnLldbMi(args=None)
180
181         # Load executable
182         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
183         self.expect("\^done")
184
185         # Run to BP_gdb_set_show_print_expand_aggregates
186         line = line_number(
187             'main.cpp',
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\"")
194
195         # Test that default print expand-aggregates value is "off"
196         self.runCmd("-gdb-show print expand-aggregates")
197         self.expect("\^done,value=\"off\"")
198
199         # Test that composite type isn't expanded when print expand-aggregates
200         # is "off"
201         self.runCmd("-var-create var1 * complx")
202         self.expect(
203             "\^done,name=\"var1\",numchild=\"3\",value=\"{\.\.\.}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
204
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)
208
209         # Test that a struct with a char first element is not formatted as a
210         # string
211         self.runCmd("-var-create - * &nstr")
212         self.expect(
213             "\^done,name=\"var\d+\",numchild=\"2\",value=\"0x[0-9a-f]+\",type=\"not_str \*\",thread-id=\"1\",has_more=\"0\"")
214
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\"")
222
223         # Test that composite type is expanded when print expand-aggregates is
224         # "on"
225         self.runCmd("-var-create var3 * complx")
226         self.expect(
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\"")
228
229         # Test that composite type[] is expanded when print expand-aggregates
230         # is "on"
231         self.runCmd("-var-create var4 * complx_array")
232         self.expect(
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\"")
234
235         # Test that -gdb-set print expand-aggregates fails if "on"/"off" isn't
236         # specified
237         self.runCmd("-gdb-set print expand-aggregates")
238         self.expect(
239             "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
240
241         # Test that -gdb-set print expand-aggregates fails when option is
242         # unknown
243         self.runCmd("-gdb-set print expand-aggregates unknown")
244         self.expect(
245             "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
246
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."""
252
253         self.spawnLldbMi(args=None)
254
255         # Load executable
256         self.runCmd("-file-exec-and-symbols %s" % self.myexe)
257         self.expect("\^done")
258
259         # Run to BP_gdb_set_show_print_aggregate_field_names
260         line = line_number(
261             'main.cpp',
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\"")
268
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\"")
272
273         # Set print expand-aggregates flag to "on"
274         self.runCmd("-gdb-set print expand-aggregates on")
275         self.expect("\^done")
276
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")
280         self.expect(
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\"")
282
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")
286         self.expect(
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\"")
288
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\"")
296
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")
300         self.expect(
301             "\^done,name=\"var3\",numchild=\"3\",value=\"{3,\{3\},0x[0-9a-f]+}\",type=\"complex_type\",thread-id=\"1\",has_more=\"0\"")
302
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")
306         self.expect(
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\"")
308
309         # Test that -gdb-set print aggregate-field-names fails if "on"/"off"
310         # isn't specified
311         self.runCmd("-gdb-set print aggregate-field-names")
312         self.expect(
313             "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
314
315         # Test that -gdb-set print aggregate-field-names fails when option is
316         # unknown
317         self.runCmd("-gdb-set print aggregate-field-names unknown")
318         self.expect(
319             "\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")