blob: c487e1dca7c6a9e2bf5451b600f0d6d9613530e1 [file] [log] [blame]
Eric Christopherc2ce0042012-08-23 00:52:51 +00001//===-- DWARFDebugInfoEntry.cpp -------------------------------------------===//
Benjamin Krameraa2f78f2011-09-13 19:42:23 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Adrian Prantl0c36a752015-01-06 16:50:25 +000010#include "SyntaxHighlighting.h"
Zachary Turner82af9432015-01-30 18:07:45 +000011#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
12#include "llvm/DebugInfo/DWARF/DWARFContext.h"
13#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
14#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
15#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
Frederic Rissb3c99122014-10-10 15:51:10 +000016#include "llvm/Support/DataTypes.h"
Eric Christopher2cbd5762013-01-07 19:32:41 +000017#include "llvm/Support/Debug.h"
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000018#include "llvm/Support/Dwarf.h"
19#include "llvm/Support/Format.h"
20#include "llvm/Support/raw_ostream.h"
21using namespace llvm;
22using namespace dwarf;
Adrian Prantl0c36a752015-01-06 16:50:25 +000023using namespace syntax;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000024
Greg Claytonc8c10322016-12-13 18:25:19 +000025bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U,
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000026 uint32_t *OffsetPtr) {
Greg Clayton6f6e4db2016-11-15 01:23:06 +000027 DataExtractor DebugInfoData = U.getDebugInfoExtractor();
28 const uint32_t UEndOffset = U.getNextUnitOffset();
Greg Clayton78a07bf2016-12-21 21:37:06 +000029 return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0);
Greg Clayton6f6e4db2016-11-15 01:23:06 +000030}
Greg Clayton78a07bf2016-12-21 21:37:06 +000031bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint32_t *OffsetPtr,
32 const DataExtractor &DebugInfoData,
33 uint32_t UEndOffset, uint32_t D) {
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000034 Offset = *OffsetPtr;
Greg Clayton78a07bf2016-12-21 21:37:06 +000035 Depth = D;
Alexey Samsonov330b8932013-10-28 23:58:58 +000036 if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000037 return false;
38 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
39 if (0 == AbbrCode) {
40 // NULL debug tag entry.
Craig Topper2617dcc2014-04-15 06:32:26 +000041 AbbrevDecl = nullptr;
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000042 return true;
43 }
Greg Clayton6f6e4db2016-11-15 01:23:06 +000044 AbbrevDecl = U.getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
Craig Topper2617dcc2014-04-15 06:32:26 +000045 if (nullptr == AbbrevDecl) {
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000046 // Restore the original offset.
47 *OffsetPtr = Offset;
48 return false;
49 }
Greg Clayton6f6e4db2016-11-15 01:23:06 +000050 // See if all attributes in this DIE have fixed byte sizes. If so, we can
51 // just add this size to the offset to skip to the next DIE.
52 if (Optional<size_t> FixedSize = AbbrevDecl->getFixedAttributesByteSize(U)) {
53 *OffsetPtr += *FixedSize;
54 return true;
55 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000056
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000057 // Skip all data in the .debug_info for the attributes
Alexey Samsonov1eabf982014-03-13 07:52:54 +000058 for (const auto &AttrSpec : AbbrevDecl->attributes()) {
Greg Clayton6f6e4db2016-11-15 01:23:06 +000059 // Check if this attribute has a fixed byte size.
Victor Leschukcbddae72017-01-10 21:18:26 +000060 if (auto FixedSize = AttrSpec.getByteSize(U)) {
Greg Clayton6f6e4db2016-11-15 01:23:06 +000061 // Attribute byte size if fixed, just add the size to the offset.
Greg Clayton82f12b12016-11-11 16:21:37 +000062 *OffsetPtr += *FixedSize;
Greg Clayton6f6e4db2016-11-15 01:23:06 +000063 } else if (!DWARFFormValue::skipValue(AttrSpec.Form, DebugInfoData,
64 OffsetPtr, &U)) {
65 // We failed to skip this attribute's value, restore the original offset
66 // and return the failure status.
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000067 *OffsetPtr = Offset;
68 return false;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000069 }
70 }
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000071 return true;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000072}