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/DWARFDebugAbbrev.h"
12 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
13 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
14 #include "llvm/Support/DataExtractor.h"
19 using namespace dwarf;
21 bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U,
22 uint32_t *OffsetPtr) {
23 DWARFDataExtractor DebugInfoData = U.getDebugInfoExtractor();
24 const uint32_t UEndOffset = U.getNextUnitOffset();
25 return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0);
28 bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint32_t *OffsetPtr,
29 const DWARFDataExtractor &DebugInfoData,
30 uint32_t UEndOffset, uint32_t D) {
33 if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
35 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
37 // NULL debug tag entry.
41 AbbrevDecl = U.getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
42 if (nullptr == AbbrevDecl) {
43 // Restore the original offset.
47 // See if all attributes in this DIE have fixed byte sizes. If so, we can
48 // just add this size to the offset to skip to the next DIE.
49 if (Optional<size_t> FixedSize = AbbrevDecl->getFixedAttributesByteSize(U)) {
50 *OffsetPtr += *FixedSize;
54 // Skip all data in the .debug_info for the attributes
55 for (const auto &AttrSpec : AbbrevDecl->attributes()) {
56 // Check if this attribute has a fixed byte size.
57 if (auto FixedSize = AttrSpec.getByteSize(U)) {
58 // Attribute byte size if fixed, just add the size to the offset.
59 *OffsetPtr += *FixedSize;
60 } else if (!DWARFFormValue::skipValue(AttrSpec.Form, DebugInfoData,
61 OffsetPtr, U.getFormParams())) {
62 // We failed to skip this attribute's value, restore the original offset
63 // and return the failure status.