10
10
from lldbsuite .test import lldbutil
11
11
12
12
13
- class LibcxxStringDataFormatterTestCase (TestBase ):
13
+ class StdStringDataFormatterTestCase (TestBase ):
14
14
def setUp (self ):
15
15
# Call super's setUp().
16
16
TestBase .setUp (self )
17
17
# Find the line number to break at.
18
18
self .main_spec = lldb .SBFileSpec ("main.cpp" )
19
19
self .namespace = "std"
20
20
21
- @add_test_categories (["libc++" ])
22
- @expectedFailureAll (
23
- bugnumber = "llvm.org/pr36109" , debug_info = "gmodules" , triple = ".*-android"
24
- )
25
- # Inline namespace is randomly ignored as Clang due to broken lookup inside
26
- # the std namespace.
27
- @expectedFailureAll (debug_info = "gmodules" )
28
- def test_with_run_command (self ):
21
+ def do_test (self ):
29
22
"""Test that that file and class static variables display correctly."""
30
- self .build ()
31
-
32
23
(target , process , thread , bkpt ) = lldbutil .run_to_source_breakpoint (
33
24
self , "Set break point at this line." , self .main_spec
34
25
)
@@ -47,42 +38,13 @@ def cleanup():
47
38
48
39
ns = self .namespace
49
40
50
- self .expect (
51
- "frame variable" ,
52
- substrs = [
53
- '(%s::wstring) wempty = L""' % ns ,
54
- '(%s::wstring) s = L"hello world! מזל טוב!"' % ns ,
55
- '(%s::wstring) S = L"!!!!"' % ns ,
56
- "(const wchar_t *) mazeltov = 0x" ,
57
- 'L"מזל טוב"' ,
58
- '(%s::string) empty = ""' % ns ,
59
- '(%s::string) q = "hello world"' % ns ,
60
- '(%s::string) Q = "quite a long std::strin with lots of info inside it"'
61
- % ns ,
62
- '(%s::string) IHaveEmbeddedZeros = "a\\ 0b\\ 0c\\ 0d"' % ns ,
63
- '(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\ 0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'
64
- % ns ,
65
- '(%s::u16string) u16_string = u"ß水氶"' % ns ,
66
- '(%s::u16string) u16_empty = u""' % ns ,
67
- '(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns ,
68
- '(%s::u32string) u32_empty = U""' % ns ,
69
- "(%s::string *) null_str = nullptr" % ns ,
70
- ],
71
- )
41
+ # Check 'S' pre-assignment.
42
+ self .expect ("frame variable S" , substrs = ['(%s::wstring) S = L"!!!!"' % ns ])
72
43
73
44
thread .StepOver ()
74
45
75
46
TheVeryLongOne = frame .FindVariable ("TheVeryLongOne" )
76
47
summaryOptions = lldb .SBTypeSummaryOptions ()
77
- summaryOptions .SetCapping (lldb .eTypeSummaryUncapped )
78
- uncappedSummaryStream = lldb .SBStream ()
79
- TheVeryLongOne .GetSummary (uncappedSummaryStream , summaryOptions )
80
- uncappedSummary = uncappedSummaryStream .GetData ()
81
- self .assertGreater (
82
- uncappedSummary .find ("someText" ),
83
- 0 ,
84
- "uncappedSummary does not include the full string" ,
85
- )
86
48
summaryOptions .SetCapping (lldb .eTypeSummaryCapped )
87
49
cappedSummaryStream = lldb .SBStream ()
88
50
TheVeryLongOne .GetSummary (cappedSummaryStream , summaryOptions )
@@ -108,31 +70,145 @@ def cleanup():
108
70
self .expect (
109
71
"frame variable" ,
110
72
substrs = [
73
+ '(%s::wstring) wempty = L""' % ns ,
74
+ '(%s::wstring) s = L"hello world! מזל טוב!"' % ns ,
111
75
'(%s::wstring) S = L"!!!!!"' % ns ,
112
76
"(const wchar_t *) mazeltov = 0x" ,
113
77
'L"מזל טוב"' ,
78
+ '(%s::string) empty = ""' % ns ,
114
79
'(%s::string) q = "hello world"' % ns ,
115
80
'(%s::string) Q = "quite a long std::strin with lots of info inside it"'
116
81
% ns ,
82
+ "(%s::string *) null_str = nullptr" % ns ,
83
+ ],
84
+ )
85
+
86
+ # Test references and pointers to std::string.
87
+ var_rq = frame .FindVariable ("rq" )
88
+ var_rQ = frame .FindVariable ("rQ" )
89
+ var_pq = frame .FindVariable ("pq" )
90
+ var_pQ = frame .FindVariable ("pQ" )
91
+
92
+ self .assertEqual (var_rq .GetSummary (), '"hello world"' , "rq summary wrong" )
93
+ self .assertEqual (
94
+ var_rQ .GetSummary (),
95
+ '"quite a long std::strin with lots of info inside it"' ,
96
+ "rQ summary wrong" ,
97
+ )
98
+ self .assertEqual (var_pq .GetSummary (), '"hello world"' , "pq summary wrong" )
99
+ self .assertEqual (
100
+ var_pQ .GetSummary (),
101
+ '"quite a long std::strin with lots of info inside it"' ,
102
+ "pQ summary wrong" ,
103
+ )
104
+
105
+ @expectedFailureAll (
106
+ bugnumber = "llvm.org/pr36109" , debug_info = "gmodules" , triple = ".*-android"
107
+ )
108
+ # Inline namespace is randomly ignored as Clang due to broken lookup inside
109
+ # the std namespace.
110
+ @expectedFailureAll (debug_info = "gmodules" )
111
+ @add_test_categories (["libc++" ])
112
+ def test_libcxx (self ):
113
+ self .build (dictionary = {"USE_LIBCPP" : 1 })
114
+ self .do_test ()
115
+
116
+ @expectedFailureAll (
117
+ bugnumber = "llvm.org/pr36109" , debug_info = "gmodules" , triple = ".*-android"
118
+ )
119
+ # Inline namespace is randomly ignored as Clang due to broken lookup inside
120
+ # the std namespace.
121
+ @expectedFailureAll (debug_info = "gmodules" )
122
+ @add_test_categories (["libstdcxx" ])
123
+ def test_libstdcxx (self ):
124
+ self .build (dictionary = {"USE_LIBSTDCPP" : 1 })
125
+ self .do_test ()
126
+
127
+ def do_test_multibyte (self ):
128
+ lldbutil .run_to_source_breakpoint (
129
+ self , "Set break point at this line." , self .main_spec
130
+ )
131
+
132
+ ns = self .namespace
133
+
134
+ self .expect (
135
+ "frame variable" ,
136
+ substrs = [
117
137
'(%s::string) IHaveEmbeddedZeros = "a\\ 0b\\ 0c\\ 0d"' % ns ,
118
138
'(%s::wstring) IHaveEmbeddedZerosToo = L"hello world!\\ 0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'
119
139
% ns ,
120
140
'(%s::u16string) u16_string = u"ß水氶"' % ns ,
141
+ '(%s::u16string) u16_empty = u""' % ns ,
121
142
'(%s::u32string) u32_string = U"🍄🍅🍆🍌"' % ns ,
122
143
'(%s::u32string) u32_empty = U""' % ns ,
123
- "(%s::string *) null_str = nullptr" % ns ,
124
144
],
125
145
)
126
146
127
- # Finally, make sure that if the string is not readable, we give an error:
128
- bkpt_2 = target .BreakpointCreateBySourceRegex (
129
- "Break here to look at bad string" , self .main_spec
147
+ @add_test_categories (["libc++" ])
148
+ def test_multibyte_libcxx (self ):
149
+ self .build (dictionary = {"USE_LIBCPP" : 1 })
150
+ self .do_test_multibyte ()
151
+
152
+ @expectedFailureAll (
153
+ bugnumber = "libstdc++ formatters don't support UTF-16/UTF-32 strings yet."
154
+ )
155
+ @add_test_categories (["libstdcxx" ])
156
+ def test_multibyte_libstdcxx (self ):
157
+ self .build (dictionary = {"USE_LIBSTDCPP" : 1 })
158
+ self .do_test_multibyte ()
159
+
160
+ def do_test_uncapped_summary (self ):
161
+ (_ , _ , thread , _ ) = lldbutil .run_to_source_breakpoint (
162
+ self , "Set break point at this line." , self .main_spec
163
+ )
164
+
165
+ TheVeryLongOne = thread .frames [0 ].FindVariable ("TheVeryLongOne" )
166
+ summaryOptions = lldb .SBTypeSummaryOptions ()
167
+ summaryOptions .SetCapping (lldb .eTypeSummaryUncapped )
168
+ uncappedSummaryStream = lldb .SBStream ()
169
+ TheVeryLongOne .GetSummary (uncappedSummaryStream , summaryOptions )
170
+ uncappedSummary = uncappedSummaryStream .GetData ()
171
+ self .assertGreater (
172
+ uncappedSummary .find ("someText" ),
173
+ 0 ,
174
+ "uncappedSummary does not include the full string" ,
130
175
)
131
- self .assertEqual (bkpt_2 .GetNumLocations (), 1 , "Got one location" )
132
- threads = lldbutil .continue_to_breakpoint (process , bkpt_2 )
133
- self .assertEqual (len (threads ), 1 , "Stopped at second breakpoint" )
134
- frame = threads [0 ].frames [0 ]
135
- var = frame .FindVariable ("in_str" )
136
- self .assertTrue (var .GetError ().Success (), "Made variable" )
176
+
177
+ @add_test_categories (["libc++" ])
178
+ def test_uncapped_libcxx (self ):
179
+ self .build (dictionary = {"USE_LIBCPP" : 1 })
180
+ self .do_test_uncapped_summary ()
181
+
182
+ @expectedFailureAll (
183
+ bugnumber = "libstdc++ std::string summary provider doesn't obey summary options."
184
+ )
185
+ @add_test_categories (["libstdcxx" ])
186
+ def test_uncapped_libstdcxx (self ):
187
+ self .build (dictionary = {"USE_LIBSTDCPP" : 1 })
188
+ self .do_test_uncapped_summary ()
189
+
190
+ def do_test_summary_unavailable (self ):
191
+ """
192
+ Make sure that if the string is not readable, we give an error.
193
+ """
194
+ (_ , _ , thread , _ ) = lldbutil .run_to_source_breakpoint (
195
+ self , "Break here to look at bad string" , self .main_spec
196
+ )
197
+
198
+ var = thread .frames [0 ].FindVariable ("in_str" )
199
+ self .assertTrue (var .GetError ().Success (), "Found variable" )
137
200
summary = var .GetSummary ()
138
201
self .assertEqual (summary , "Summary Unavailable" , "No summary for bad value" )
202
+
203
+ @add_test_categories (["libc++" ])
204
+ def test_unavailable_summary_libcxx (self ):
205
+ self .build (dictionary = {"USE_LIBCPP" : 1 })
206
+ self .do_test_summary_unavailable ()
207
+
208
+ @expectedFailureAll (
209
+ bugnumber = "libstdc++ std::string summary provider doesn't output a user-friendly message for invalid strings."
210
+ )
211
+ @add_test_categories (["libstdcxx" ])
212
+ def test_unavailable_summary_libstdcxx (self ):
213
+ self .build (dictionary = {"USE_LIBSTDCPP" : 1 })
214
+ self .do_test_summary_unavailable ()
0 commit comments