1 //===- DWARFDebugInfoEntry.cpp --------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
10 #include "llvm/ADT/Optional.h"
11 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
12 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
13 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
14 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
15 #include "llvm/Support/DataExtractor.h"
20 using namespace dwarf
;
22 bool DWARFDebugInfoEntry::extractFast(const DWARFUnit
&U
, uint64_t *OffsetPtr
,
23 const DWARFDataExtractor
&DebugInfoData
,
24 uint64_t UEndOffset
, uint32_t D
) {
27 if (Offset
>= UEndOffset
) {
28 U
.getContext().getWarningHandler()(
29 createStringError(errc::invalid_argument
,
30 "DWARF unit from offset 0x%8.8" PRIx64
" incl. "
31 "to offset 0x%8.8" PRIx64
" excl. "
32 "tries to read DIEs at offset 0x%8.8" PRIx64
,
33 U
.getOffset(), U
.getNextUnitOffset(), *OffsetPtr
));
36 assert(DebugInfoData
.isValidOffset(UEndOffset
- 1));
37 uint64_t AbbrCode
= DebugInfoData
.getULEB128(OffsetPtr
);
39 // NULL debug tag entry.
43 const auto *AbbrevSet
= U
.getAbbreviations();
45 U
.getContext().getWarningHandler()(
46 createStringError(errc::invalid_argument
,
47 "DWARF unit at offset 0x%8.8" PRIx64
" "
48 "contains invalid abbreviation set offset 0x%" PRIx64
,
49 U
.getOffset(), U
.getAbbreviationsOffset()));
50 // Restore the original offset.
54 AbbrevDecl
= AbbrevSet
->getAbbreviationDeclaration(AbbrCode
);
56 U
.getContext().getWarningHandler()(
57 createStringError(errc::invalid_argument
,
58 "DWARF unit at offset 0x%8.8" PRIx64
" "
59 "contains invalid abbreviation %" PRIu64
" at "
60 "offset 0x%8.8" PRIx64
", valid abbreviations are %s",
61 U
.getOffset(), AbbrCode
, *OffsetPtr
,
62 AbbrevSet
->getCodeRange().c_str()));
63 // Restore the original offset.
67 // See if all attributes in this DIE have fixed byte sizes. If so, we can
68 // just add this size to the offset to skip to the next DIE.
69 if (Optional
<size_t> FixedSize
= AbbrevDecl
->getFixedAttributesByteSize(U
)) {
70 *OffsetPtr
+= *FixedSize
;
74 // Skip all data in the .debug_info for the attributes
75 for (const auto &AttrSpec
: AbbrevDecl
->attributes()) {
76 // Check if this attribute has a fixed byte size.
77 if (auto FixedSize
= AttrSpec
.getByteSize(U
)) {
78 // Attribute byte size if fixed, just add the size to the offset.
79 *OffsetPtr
+= *FixedSize
;
80 } else if (!DWARFFormValue::skipValue(AttrSpec
.Form
, DebugInfoData
,
81 OffsetPtr
, U
.getFormParams())) {
82 // We failed to skip this attribute's value, restore the original offset
83 // and return the failure status.
84 U
.getContext().getWarningHandler()(createStringError(
85 errc::invalid_argument
,
86 "DWARF unit at offset 0x%8.8" PRIx64
" "
87 "contains invalid FORM_* 0x%" PRIx16
" at offset 0x%8.8" PRIx64
,
88 U
.getOffset(), AttrSpec
.Form
, *OffsetPtr
));