Eric Christopher | c2ce004 | 2012-08-23 00:52:51 +0000 | [diff] [blame] | 1 | //===-- DWARFDebugInfoEntry.cpp -------------------------------------------===// |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 2 | // |
| 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 Prantl | 0c36a75 | 2015-01-06 16:50:25 +0000 | [diff] [blame] | 10 | #include "SyntaxHighlighting.h" |
Zachary Turner | 82af943 | 2015-01-30 18:07:45 +0000 | [diff] [blame] | 11 | #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 Riss | b3c9912 | 2014-10-10 15:51:10 +0000 | [diff] [blame] | 16 | #include "llvm/Support/DataTypes.h" |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Debug.h" |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Dwarf.h" |
| 19 | #include "llvm/Support/Format.h" |
| 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | using namespace llvm; |
| 22 | using namespace dwarf; |
Adrian Prantl | 0c36a75 | 2015-01-06 16:50:25 +0000 | [diff] [blame] | 23 | using namespace syntax; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 24 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 25 | bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 26 | uint32_t *OffsetPtr) { |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 27 | DataExtractor DebugInfoData = U.getDebugInfoExtractor(); |
| 28 | const uint32_t UEndOffset = U.getNextUnitOffset(); |
Greg Clayton | 78a07bf | 2016-12-21 21:37:06 +0000 | [diff] [blame] | 29 | return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0); |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 30 | } |
Greg Clayton | 78a07bf | 2016-12-21 21:37:06 +0000 | [diff] [blame] | 31 | bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint32_t *OffsetPtr, |
| 32 | const DataExtractor &DebugInfoData, |
| 33 | uint32_t UEndOffset, uint32_t D) { |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 34 | Offset = *OffsetPtr; |
Greg Clayton | 78a07bf | 2016-12-21 21:37:06 +0000 | [diff] [blame] | 35 | Depth = D; |
Alexey Samsonov | 330b893 | 2013-10-28 23:58:58 +0000 | [diff] [blame] | 36 | if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset)) |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 37 | return false; |
| 38 | uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr); |
| 39 | if (0 == AbbrCode) { |
| 40 | // NULL debug tag entry. |
Craig Topper | 2617dcc | 2014-04-15 06:32:26 +0000 | [diff] [blame] | 41 | AbbrevDecl = nullptr; |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 42 | return true; |
| 43 | } |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 44 | AbbrevDecl = U.getAbbreviations()->getAbbreviationDeclaration(AbbrCode); |
Craig Topper | 2617dcc | 2014-04-15 06:32:26 +0000 | [diff] [blame] | 45 | if (nullptr == AbbrevDecl) { |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 46 | // Restore the original offset. |
| 47 | *OffsetPtr = Offset; |
| 48 | return false; |
| 49 | } |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 50 | // 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 Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 56 | |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 57 | // Skip all data in the .debug_info for the attributes |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 58 | for (const auto &AttrSpec : AbbrevDecl->attributes()) { |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 59 | // Check if this attribute has a fixed byte size. |
Victor Leschuk | cbddae7 | 2017-01-10 21:18:26 +0000 | [diff] [blame] | 60 | if (auto FixedSize = AttrSpec.getByteSize(U)) { |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 61 | // Attribute byte size if fixed, just add the size to the offset. |
Greg Clayton | 82f12b1 | 2016-11-11 16:21:37 +0000 | [diff] [blame] | 62 | *OffsetPtr += *FixedSize; |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 63 | } 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 Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 67 | *OffsetPtr = Offset; |
| 68 | return false; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 71 | return true; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 72 | } |