2017-02-28 00:43:14 +01:00
|
|
|
//===- DWARFDebugInfoEntry.cpp --------------------------------------------===//
|
2011-09-13 21:42:23 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
|
2017-02-28 00:43:14 +01:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2015-01-30 19:07:45 +01:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
|
2017-02-28 00:43:14 +01:00
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
|
|
|
|
#include "llvm/Support/DataExtractor.h"
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
|
2011-09-13 21:42:23 +02:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace dwarf;
|
|
|
|
|
2016-12-13 19:25:19 +01:00
|
|
|
bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U,
|
2013-04-08 16:37:16 +02:00
|
|
|
uint32_t *OffsetPtr) {
|
2017-06-29 18:52:08 +02:00
|
|
|
DWARFDataExtractor DebugInfoData = U.getDebugInfoExtractor();
|
2016-11-15 02:23:06 +01:00
|
|
|
const uint32_t UEndOffset = U.getNextUnitOffset();
|
2016-12-21 22:37:06 +01:00
|
|
|
return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0);
|
2016-11-15 02:23:06 +01:00
|
|
|
}
|
2017-02-28 00:43:14 +01:00
|
|
|
|
2016-12-21 22:37:06 +01:00
|
|
|
bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint32_t *OffsetPtr,
|
2017-06-29 18:52:08 +02:00
|
|
|
const DWARFDataExtractor &DebugInfoData,
|
2016-12-21 22:37:06 +01:00
|
|
|
uint32_t UEndOffset, uint32_t D) {
|
2013-04-08 16:37:16 +02:00
|
|
|
Offset = *OffsetPtr;
|
2016-12-21 22:37:06 +01:00
|
|
|
Depth = D;
|
2013-10-29 00:58:58 +01:00
|
|
|
if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
|
|
|
|
return false;
|
2013-04-08 16:37:16 +02:00
|
|
|
uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
|
|
|
|
if (0 == AbbrCode) {
|
|
|
|
// NULL debug tag entry.
|
2014-04-15 08:32:26 +02:00
|
|
|
AbbrevDecl = nullptr;
|
2013-04-08 16:37:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-15 02:23:06 +01:00
|
|
|
AbbrevDecl = U.getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
|
2014-04-15 08:32:26 +02:00
|
|
|
if (nullptr == AbbrevDecl) {
|
2013-10-29 00:58:58 +01:00
|
|
|
// Restore the original offset.
|
|
|
|
*OffsetPtr = Offset;
|
|
|
|
return false;
|
|
|
|
}
|
2016-11-15 02:23:06 +01:00
|
|
|
// See if all attributes in this DIE have fixed byte sizes. If so, we can
|
|
|
|
// just add this size to the offset to skip to the next DIE.
|
|
|
|
if (Optional<size_t> FixedSize = AbbrevDecl->getFixedAttributesByteSize(U)) {
|
|
|
|
*OffsetPtr += *FixedSize;
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-08 16:37:16 +02:00
|
|
|
|
|
|
|
// Skip all data in the .debug_info for the attributes
|
2014-03-13 08:52:54 +01:00
|
|
|
for (const auto &AttrSpec : AbbrevDecl->attributes()) {
|
2016-11-15 02:23:06 +01:00
|
|
|
// Check if this attribute has a fixed byte size.
|
2017-01-10 22:18:26 +01:00
|
|
|
if (auto FixedSize = AttrSpec.getByteSize(U)) {
|
2016-11-15 02:23:06 +01:00
|
|
|
// Attribute byte size if fixed, just add the size to the offset.
|
2016-11-11 17:21:37 +01:00
|
|
|
*OffsetPtr += *FixedSize;
|
2016-11-15 02:23:06 +01:00
|
|
|
} else if (!DWARFFormValue::skipValue(AttrSpec.Form, DebugInfoData,
|
2017-06-26 20:43:01 +02:00
|
|
|
OffsetPtr, U.getFormParams())) {
|
2016-11-15 02:23:06 +01:00
|
|
|
// We failed to skip this attribute's value, restore the original offset
|
|
|
|
// and return the failure status.
|
2013-04-08 16:37:16 +02:00
|
|
|
*OffsetPtr = Offset;
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-13 21:42:23 +02:00
|
|
|
}
|
2013-04-08 16:37:16 +02:00
|
|
|
return true;
|
2011-09-13 21:42:23 +02:00
|
|
|
}
|