blob: 976bc4651ae696b5c7cdd81ad618c28625ceee88 [file] [log] [blame]
Eugene Zelenkoe94042c2017-02-27 23:43:14 +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
Chandler Carruth6bda14b2017-06-06 11:49:48 +000010#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000011#include "llvm/ADT/Optional.h"
Zachary Turner82af9432015-01-30 18:07:45 +000012#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
Zachary Turner82af9432015-01-30 18:07:45 +000013#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000014#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
15#include "llvm/Support/DataExtractor.h"
16#include <cstddef>
17#include <cstdint>
18
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000019using namespace llvm;
20using namespace dwarf;
21
Greg Claytonc8c10322016-12-13 18:25:19 +000022bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U,
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000023 uint32_t *OffsetPtr) {
Paul Robinson17536b92017-06-29 16:52:08 +000024 DWARFDataExtractor DebugInfoData = U.getDebugInfoExtractor();
Greg Clayton6f6e4db2016-11-15 01:23:06 +000025 const uint32_t UEndOffset = U.getNextUnitOffset();
Greg Clayton78a07bf2016-12-21 21:37:06 +000026 return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0);
Greg Clayton6f6e4db2016-11-15 01:23:06 +000027}
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000028
Greg Clayton78a07bf2016-12-21 21:37:06 +000029bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint32_t *OffsetPtr,
Paul Robinson17536b92017-06-29 16:52:08 +000030 const DWARFDataExtractor &DebugInfoData,
Greg Clayton78a07bf2016-12-21 21:37:06 +000031 uint32_t UEndOffset, uint32_t D) {
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000032 Offset = *OffsetPtr;
Greg Clayton78a07bf2016-12-21 21:37:06 +000033 Depth = D;
Alexey Samsonov330b8932013-10-28 23:58:58 +000034 if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000035 return false;
36 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
37 if (0 == AbbrCode) {
38 // NULL debug tag entry.
Craig Topper2617dcc2014-04-15 06:32:26 +000039 AbbrevDecl = nullptr;
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000040 return true;
41 }
Greg Clayton6f6e4db2016-11-15 01:23:06 +000042 AbbrevDecl = U.getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
Craig Topper2617dcc2014-04-15 06:32:26 +000043 if (nullptr == AbbrevDecl) {
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000044 // Restore the original offset.
45 *OffsetPtr = Offset;
46 return false;
47 }
Greg Clayton6f6e4db2016-11-15 01:23:06 +000048 // See if all attributes in this DIE have fixed byte sizes. If so, we can
49 // just add this size to the offset to skip to the next DIE.
50 if (Optional<size_t> FixedSize = AbbrevDecl->getFixedAttributesByteSize(U)) {
51 *OffsetPtr += *FixedSize;
52 return true;
53 }
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000054
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000055 // Skip all data in the .debug_info for the attributes
Alexey Samsonov1eabf982014-03-13 07:52:54 +000056 for (const auto &AttrSpec : AbbrevDecl->attributes()) {
Greg Clayton6f6e4db2016-11-15 01:23:06 +000057 // Check if this attribute has a fixed byte size.
Victor Leschukcbddae72017-01-10 21:18:26 +000058 if (auto FixedSize = AttrSpec.getByteSize(U)) {
Greg Clayton6f6e4db2016-11-15 01:23:06 +000059 // Attribute byte size if fixed, just add the size to the offset.
Greg Clayton82f12b12016-11-11 16:21:37 +000060 *OffsetPtr += *FixedSize;
Greg Clayton6f6e4db2016-11-15 01:23:06 +000061 } else if (!DWARFFormValue::skipValue(AttrSpec.Form, DebugInfoData,
Paul Robinson75c068c2017-06-26 18:43:01 +000062 OffsetPtr, U.getFormParams())) {
Greg Clayton6f6e4db2016-11-15 01:23:06 +000063 // We failed to skip this attribute's value, restore the original offset
64 // and return the failure status.
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000065 *OffsetPtr = Offset;
66 return false;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000067 }
68 }
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000069 return true;
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000070}