7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"
10
+ #include " llvm/Testing/Support/Error.h"
10
11
#include " gtest/gtest.h"
11
12
12
13
using namespace llvm ;
13
14
14
15
namespace {
15
16
17
+ struct WarningHandler {
18
+ ~WarningHandler () { EXPECT_THAT_ERROR (std::move (Err), Succeeded ()); }
19
+
20
+ void operator ()(Error E) { Err = joinErrors (std::move (Err), std::move (E)); }
21
+
22
+ Error getWarning () { return std::move (Err); }
23
+
24
+ Error Err = Error::success();
25
+ };
26
+
16
27
template <size_t SecSize>
17
28
void ExpectExtractError (const char (&SecDataRaw)[SecSize],
18
29
const char *ErrorMessage) {
@@ -21,7 +32,8 @@ void ExpectExtractError(const char (&SecDataRaw)[SecSize],
21
32
/* AddressSize = */ 4 );
22
33
DWARFDebugArangeSet Set;
23
34
uint64_t Offset = 0 ;
24
- Error E = Set.extract (Extractor, &Offset);
35
+ WarningHandler Warnings;
36
+ Error E = Set.extract (Extractor, &Offset, Warnings);
25
37
ASSERT_TRUE (E.operator bool ());
26
38
EXPECT_STREQ (ErrorMessage, toString (std::move (E)).c_str ());
27
39
}
@@ -166,24 +178,94 @@ TEST(DWARFDebugArangeSet, UnevenLength) {
166
178
" of the tuple size" );
167
179
}
168
180
169
- TEST (DWARFDebugArangeSet, ZeroLengthEntry ) {
181
+ TEST (DWARFDebugArangeSet, ZeroAddressEntry ) {
170
182
static const char DebugArangesSecRaw[] =
171
- " \x24 \x00\x00\x00 " // Length
183
+ " \x1c \x00\x00\x00 " // Length
172
184
" \x02\x00 " // Version
173
185
" \x00\x00\x00\x00 " // Debug Info Offset
174
186
" \x04 " // Address Size
175
187
" \x00 " // Segment Selector Size
176
188
" \x00\x00\x00\x00 " // Padding
177
189
" \x00\x00\x00\x00 " // Entry1: Address
178
190
" \x01\x00\x00\x00 " // Length
191
+ " \x00\x00\x00\x00 " // Termination tuple
192
+ " \x00\x00\x00\x00 " ;
193
+ DWARFDataExtractor Extractor (
194
+ StringRef (DebugArangesSecRaw, sizeof (DebugArangesSecRaw) - 1 ),
195
+ /* IsLittleEndian=*/ true ,
196
+ /* AddressSize=*/ 4 );
197
+ DWARFDebugArangeSet Set;
198
+ uint64_t Offset = 0 ;
199
+ ASSERT_THAT_ERROR (Set.extract (Extractor, &Offset, WarningHandler ()),
200
+ Succeeded ());
201
+ auto Range = Set.descriptors ();
202
+ auto Iter = Range.begin ();
203
+ ASSERT_EQ (std::distance (Iter, Range.end ()), 1u );
204
+ EXPECT_EQ (Iter->Address , 0u );
205
+ EXPECT_EQ (Iter->Length , 1u );
206
+ }
207
+
208
+ TEST (DWARFDebugArangeSet, ZeroLengthEntry) {
209
+ static const char DebugArangesSecRaw[] =
210
+ " \x1c\x00\x00\x00 " // Length
211
+ " \x02\x00 " // Version
212
+ " \x00\x00\x00\x00 " // Debug Info Offset
213
+ " \x04 " // Address Size
214
+ " \x00 " // Segment Selector Size
215
+ " \x00\x00\x00\x00 " // Padding
216
+ " \x01\x00\x00\x00 " // Entry1: Address
217
+ " \x00\x00\x00\x00 " // Length
218
+ " \x00\x00\x00\x00 " // Termination tuple
219
+ " \x00\x00\x00\x00 " ;
220
+ DWARFDataExtractor Extractor (
221
+ StringRef (DebugArangesSecRaw, sizeof (DebugArangesSecRaw) - 1 ),
222
+ /* IsLittleEndian=*/ true ,
223
+ /* AddressSize=*/ 4 );
224
+ DWARFDebugArangeSet Set;
225
+ uint64_t Offset = 0 ;
226
+ ASSERT_THAT_ERROR (Set.extract (Extractor, &Offset, WarningHandler ()),
227
+ Succeeded ());
228
+ auto Range = Set.descriptors ();
229
+ auto Iter = Range.begin ();
230
+ ASSERT_EQ (std::distance (Iter, Range.end ()), 1u );
231
+ EXPECT_EQ (Iter->Address , 1u );
232
+ EXPECT_EQ (Iter->Length , 0u );
233
+ }
234
+
235
+ TEST (DWARFDebugArangesSet, PrematureTerminator) {
236
+ static const char DebugArangesSecRaw[] =
237
+ " \x24\x00\x00\x00 " // Length
238
+ " \x02\x00 " // Version
239
+ " \x00\x00\x00\x00 " // Debug Info Offset
240
+ " \x04 " // Address Size
241
+ " \x00 " // Segment Selector Size
242
+ " \x00\x00\x00\x00 " // Padding
243
+ " \x00\x00\x00\x00 " // Entry1: Premature
244
+ " \x00\x00\x00\x00 " // terminator
179
245
" \x01\x00\x00\x00 " // Entry2: Address
180
- " \x00 \x00\x00\x00 " // Length (invalid)
246
+ " \x01 \x00\x00\x00 " // Length
181
247
" \x00\x00\x00\x00 " // Termination tuple
182
248
" \x00\x00\x00\x00 " ;
183
- ExpectExtractError (
184
- DebugArangesSecRaw,
185
- " address range table at offset 0x0 has an invalid tuple (length = 0) "
186
- " at offset 0x18" );
249
+ DWARFDataExtractor Extractor (
250
+ StringRef (DebugArangesSecRaw, sizeof (DebugArangesSecRaw) - 1 ),
251
+ /* IsLittleEndian=*/ true ,
252
+ /* AddressSize=*/ 4 );
253
+ DWARFDebugArangeSet Set;
254
+ uint64_t Offset = 0 ;
255
+ WarningHandler Warnings;
256
+ ASSERT_THAT_ERROR (Set.extract (Extractor, &Offset, Warnings), Succeeded ());
257
+ auto Range = Set.descriptors ();
258
+ auto Iter = Range.begin ();
259
+ ASSERT_EQ (std::distance (Iter, Range.end ()), 2u );
260
+ EXPECT_EQ (Iter->Address , 0u );
261
+ EXPECT_EQ (Iter->Length , 0u );
262
+ ++Iter;
263
+ EXPECT_EQ (Iter->Address , 1u );
264
+ EXPECT_EQ (Iter->Length , 1u );
265
+ EXPECT_THAT_ERROR (
266
+ Warnings.getWarning (),
267
+ FailedWithMessage (" address range table at offset 0x0 has a premature "
268
+ " terminator entry at offset 0x10" ));
187
269
}
188
270
189
271
} // end anonymous namespace
0 commit comments