@@ -81,8 +81,11 @@ void DWARFUnitVector::addUnitsImpl(
8181 if (!Data.isValidOffset (Offset))
8282 return nullptr ;
8383 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));
8587 return nullptr ;
88+ }
8689 if (!IndexEntry && IsDWO) {
8790 const DWARFUnitIndex &Index = getDWARFUnitIndex (
8891 Context, Header.isTypeUnit () ? DW_SECT_EXT_TYPES : DW_SECT_INFO);
@@ -244,10 +247,10 @@ Expected<uint64_t> DWARFUnit::getStringOffsetSectionItem(uint32_t Index) const {
244247 return DA.getRelocatedValue (ItemSize, &Offset);
245248}
246249
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) {
251254 Offset = *offset_ptr;
252255 Error Err = Error::success ();
253256 IndexEntry = nullptr ;
@@ -277,72 +280,58 @@ bool DWARFUnitHeader::extract(DWARFContext &Context,
277280 } else if (UnitType == DW_UT_split_compile || UnitType == DW_UT_skeleton)
278281 DWOId = debug_info.getU64 (offset_ptr, &Err);
279282
280- if (Err) {
281- Context. getWarningHandler ()( joinErrors (
283+ if (Err)
284+ return joinErrors (
282285 createStringError (
283286 errc::invalid_argument,
284287 " DWARF unit at 0x%8.8" PRIx64 " cannot be parsed:" , Offset),
285- std::move (Err)));
286- return false ;
287- }
288+ std::move (Err));
288289
289290 // Header fields all parsed, capture the size of this unit header.
290291 assert (*offset_ptr - Offset <= 255 && " unexpected header size" );
291292 Size = uint8_t (*offset_ptr - Offset);
292293 uint64_t NextCUOffset = Offset + getUnitLengthFieldByteSize () + getLength ();
293294
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 ());
303301
304- if (!DWARFContext::isSupportedVersion (getVersion ())) {
305- Context. getWarningHandler ()( createStringError (
302+ if (!DWARFContext::isSupportedVersion (getVersion ()))
303+ return createStringError (
306304 errc::invalid_argument,
307305 " DWARF unit at offset 0x%8.8" PRIx64 " "
308306 " has unsupported version %" PRIu16 " , supported are 2-%u" ,
309- Offset, getVersion (), DWARFContext::getMaxSupportedVersion ()));
310- return false ;
311- }
307+ Offset, getVersion (), DWARFContext::getMaxSupportedVersion ());
312308
313309 // Type offset is unit-relative; should be after the header and before
314310 // 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 (
328321 errc::invalid_argument,
329322 " DWARF type unit from offset 0x%8.8" PRIx64 " incl. "
330323 " to offset 0x%8.8" PRIx64 " excl. has its "
331324 " 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);
335326
336327 if (Error SizeErr = DWARFContext::checkAddressSizeSupported (
337328 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;
342331
343332 // Keep track of the highest DWARF version we encounter across all units.
344333 Context.setMaxVersionIfGreater (getVersion ());
345- return true ;
334+ return Error::success () ;
346335}
347336
348337bool DWARFUnitHeader::applyIndexEntry (const DWARFUnitIndex::Entry *Entry) {
0 commit comments