@@ -81,8 +81,11 @@ void DWARFUnitVector::addUnitsImpl(
81
81
if (!Data.isValidOffset (Offset))
82
82
return nullptr ;
83
83
DWARFUnitHeader Header;
84
- if (!Header.extract (Context, Data, &Offset, SectionKind))
84
+ if (Error ExtractErr =
85
+ Header.extract (Context, Data, &Offset, SectionKind)) {
86
+ Context.getWarningHandler ()(std::move (ExtractErr));
85
87
return nullptr ;
88
+ }
86
89
if (!IndexEntry && IsDWO) {
87
90
const DWARFUnitIndex &Index = getDWARFUnitIndex (
88
91
Context, Header.isTypeUnit () ? DW_SECT_EXT_TYPES : DW_SECT_INFO);
@@ -244,10 +247,10 @@ Expected<uint64_t> DWARFUnit::getStringOffsetSectionItem(uint32_t Index) const {
244
247
return DA.getRelocatedValue (ItemSize, &Offset);
245
248
}
246
249
247
- bool DWARFUnitHeader::extract (DWARFContext &Context,
248
- const DWARFDataExtractor &debug_info,
249
- uint64_t *offset_ptr,
250
- DWARFSectionKind SectionKind) {
250
+ Error DWARFUnitHeader::extract (DWARFContext &Context,
251
+ const DWARFDataExtractor &debug_info,
252
+ uint64_t *offset_ptr,
253
+ DWARFSectionKind SectionKind) {
251
254
Offset = *offset_ptr;
252
255
Error Err = Error::success ();
253
256
IndexEntry = nullptr ;
@@ -277,72 +280,58 @@ bool DWARFUnitHeader::extract(DWARFContext &Context,
277
280
} else if (UnitType == DW_UT_split_compile || UnitType == DW_UT_skeleton)
278
281
DWOId = debug_info.getU64 (offset_ptr, &Err);
279
282
280
- if (Err) {
281
- Context. getWarningHandler ()( joinErrors (
283
+ if (Err)
284
+ return joinErrors (
282
285
createStringError (
283
286
errc::invalid_argument,
284
287
" DWARF unit at 0x%8.8" PRIx64 " cannot be parsed:" , Offset),
285
- std::move (Err)));
286
- return false ;
287
- }
288
+ std::move (Err));
288
289
289
290
// Header fields all parsed, capture the size of this unit header.
290
291
assert (*offset_ptr - Offset <= 255 && " unexpected header size" );
291
292
Size = uint8_t (*offset_ptr - Offset);
292
293
uint64_t NextCUOffset = Offset + getUnitLengthFieldByteSize () + getLength ();
293
294
294
- if (!debug_info.isValidOffset (getNextUnitOffset () - 1 )) {
295
- Context.getWarningHandler ()(
296
- createStringError (errc::invalid_argument,
297
- " DWARF unit from offset 0x%8.8" PRIx64 " incl. "
298
- " to offset 0x%8.8" PRIx64 " excl. "
299
- " extends past section size 0x%8.8zx" ,
300
- Offset, NextCUOffset, debug_info.size ()));
301
- return false ;
302
- }
295
+ if (!debug_info.isValidOffset (getNextUnitOffset () - 1 ))
296
+ return createStringError (errc::invalid_argument,
297
+ " DWARF unit from offset 0x%8.8" PRIx64 " incl. "
298
+ " to offset 0x%8.8" PRIx64 " excl. "
299
+ " extends past section size 0x%8.8zx" ,
300
+ Offset, NextCUOffset, debug_info.size ());
303
301
304
- if (!DWARFContext::isSupportedVersion (getVersion ())) {
305
- Context. getWarningHandler ()( createStringError (
302
+ if (!DWARFContext::isSupportedVersion (getVersion ()))
303
+ return createStringError (
306
304
errc::invalid_argument,
307
305
" DWARF unit at offset 0x%8.8" PRIx64 " "
308
306
" has unsupported version %" PRIu16 " , supported are 2-%u" ,
309
- Offset, getVersion (), DWARFContext::getMaxSupportedVersion ()));
310
- return false ;
311
- }
307
+ Offset, getVersion (), DWARFContext::getMaxSupportedVersion ());
312
308
313
309
// Type offset is unit-relative; should be after the header and before
314
310
// the end of the current unit.
315
- if (isTypeUnit () && TypeOffset < Size) {
316
- Context.getWarningHandler ()(
317
- createStringError (errc::invalid_argument,
318
- " DWARF type unit at offset "
319
- " 0x%8.8" PRIx64 " "
320
- " has its relocated type_offset 0x%8.8" PRIx64 " "
321
- " pointing inside the header" ,
322
- Offset, Offset + TypeOffset));
323
- return false ;
324
- }
325
- if (isTypeUnit () &&
326
- TypeOffset >= getUnitLengthFieldByteSize () + getLength ()) {
327
- Context.getWarningHandler ()(createStringError (
311
+ if (isTypeUnit () && TypeOffset < Size)
312
+ return createStringError (errc::invalid_argument,
313
+ " DWARF type unit at offset "
314
+ " 0x%8.8" PRIx64 " "
315
+ " has its relocated type_offset 0x%8.8" PRIx64 " "
316
+ " pointing inside the header" ,
317
+ Offset, Offset + TypeOffset);
318
+
319
+ if (isTypeUnit () && TypeOffset >= getUnitLengthFieldByteSize () + getLength ())
320
+ return createStringError (
328
321
errc::invalid_argument,
329
322
" DWARF type unit from offset 0x%8.8" PRIx64 " incl. "
330
323
" to offset 0x%8.8" PRIx64 " excl. has its "
331
324
" relocated type_offset 0x%8.8" PRIx64 " pointing past the unit end" ,
332
- Offset, NextCUOffset, Offset + TypeOffset));
333
- return false ;
334
- }
325
+ Offset, NextCUOffset, Offset + TypeOffset);
335
326
336
327
if (Error SizeErr = DWARFContext::checkAddressSizeSupported (
337
328
getAddressByteSize (), errc::invalid_argument,
338
- " DWARF unit at offset 0x%8.8" PRIx64, Offset)) {
339
- Context.getWarningHandler ()(std::move (SizeErr));
340
- return false ;
341
- }
329
+ " DWARF unit at offset 0x%8.8" PRIx64, Offset))
330
+ return SizeErr;
342
331
343
332
// Keep track of the highest DWARF version we encounter across all units.
344
333
Context.setMaxVersionIfGreater (getVersion ());
345
- return true ;
334
+ return Error::success () ;
346
335
}
347
336
348
337
bool DWARFUnitHeader::applyIndexEntry (const DWARFUnitIndex::Entry *Entry) {
0 commit comments