#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
#include "llvm/ADT/Optional.h"
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
#include "llvm/Support/DataExtractor.h"
#include <cstddef>
#include <cstdint>
using namespace llvm;
using namespace dwarf;
bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U,
uint64_t *OffsetPtr) {
DWARFDataExtractor DebugInfoData = U.getDebugInfoExtractor();
const uint64_t UEndOffset = U.getNextUnitOffset();
return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0);
}
bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint64_t *OffsetPtr,
const DWARFDataExtractor &DebugInfoData,
uint64_t UEndOffset, uint32_t D) {
Offset = *OffsetPtr;
Depth = D;
if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
return false;
uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
if (0 == AbbrCode) {
AbbrevDecl = nullptr;
return true;
}
if (auto* Abbreviations = U.getAbbreviations()) { AbbrevDecl = Abbreviations->getAbbreviationDeclaration(AbbrCode);
} else {
AbbrevDecl = nullptr; }
if (nullptr == AbbrevDecl) {
*OffsetPtr = Offset;
return false;
}
if (Optional<size_t> FixedSize = AbbrevDecl->getFixedAttributesByteSize(U)) {
*OffsetPtr += *FixedSize;
return true;
}
for (const auto &AttrSpec : AbbrevDecl->attributes()) {
if (auto FixedSize = AttrSpec.getByteSize(U)) {
*OffsetPtr += *FixedSize;
} else if (!DWARFFormValue::skipValue(AttrSpec.Form, DebugInfoData,
OffsetPtr, U.getFormParams())) {
*OffsetPtr = Offset;
return false;
}
}
return true;
}