Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 1 | //===- DWARFDebugInfoEntry.cpp --------------------------------------------===// |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 9 | #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 10 | #include "llvm/ADT/Optional.h" |
Zachary Turner | 82af943 | 2015-01-30 18:07:45 +0000 | [diff] [blame] | 11 | #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" |
Zachary Turner | 82af943 | 2015-01-30 18:07:45 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/DWARF/DWARFFormValue.h" |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/DWARF/DWARFUnit.h" |
| 14 | #include "llvm/Support/DataExtractor.h" |
| 15 | #include <cstddef> |
| 16 | #include <cstdint> |
| 17 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | using namespace dwarf; |
| 20 | |
Greg Clayton | c8c1032 | 2016-12-13 18:25:19 +0000 | [diff] [blame] | 21 | bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, |
Igor Kudrin | f26a70a | 2019-08-06 10:49:40 +0000 | [diff] [blame] | 22 | uint64_t *OffsetPtr) { |
Paul Robinson | 17536b9 | 2017-06-29 16:52:08 +0000 | [diff] [blame] | 23 | DWARFDataExtractor DebugInfoData = U.getDebugInfoExtractor(); |
Igor Kudrin | f26a70a | 2019-08-06 10:49:40 +0000 | [diff] [blame] | 24 | const uint64_t UEndOffset = U.getNextUnitOffset(); |
Greg Clayton | 78a07bf | 2016-12-21 21:37:06 +0000 | [diff] [blame] | 25 | return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0); |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 26 | } |
Eugene Zelenko | e94042c | 2017-02-27 23:43:14 +0000 | [diff] [blame] | 27 | |
Igor Kudrin | f26a70a | 2019-08-06 10:49:40 +0000 | [diff] [blame] | 28 | bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint64_t *OffsetPtr, |
Paul Robinson | 17536b9 | 2017-06-29 16:52:08 +0000 | [diff] [blame] | 29 | const DWARFDataExtractor &DebugInfoData, |
Igor Kudrin | f26a70a | 2019-08-06 10:49:40 +0000 | [diff] [blame] | 30 | uint64_t UEndOffset, uint32_t D) { |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 31 | Offset = *OffsetPtr; |
Greg Clayton | 78a07bf | 2016-12-21 21:37:06 +0000 | [diff] [blame] | 32 | Depth = D; |
Alexey Samsonov | 330b893 | 2013-10-28 23:58:58 +0000 | [diff] [blame] | 33 | if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset)) |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 34 | return false; |
| 35 | uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr); |
| 36 | if (0 == AbbrCode) { |
| 37 | // NULL debug tag entry. |
Craig Topper | 2617dcc | 2014-04-15 06:32:26 +0000 | [diff] [blame] | 38 | AbbrevDecl = nullptr; |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 39 | return true; |
| 40 | } |
Igor Kudrin | 9ceb192 | 2020-08-12 15:37:16 +0700 | [diff] [blame^] | 41 | if (const auto *AbbrevSet = U.getAbbreviations()) |
| 42 | AbbrevDecl = AbbrevSet->getAbbreviationDeclaration(AbbrCode); |
Craig Topper | 2617dcc | 2014-04-15 06:32:26 +0000 | [diff] [blame] | 43 | if (nullptr == AbbrevDecl) { |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 44 | // Restore the original offset. |
| 45 | *OffsetPtr = Offset; |
| 46 | return false; |
| 47 | } |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 48 | // 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 Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 54 | |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 55 | // Skip all data in the .debug_info for the attributes |
Alexey Samsonov | 1eabf98 | 2014-03-13 07:52:54 +0000 | [diff] [blame] | 56 | for (const auto &AttrSpec : AbbrevDecl->attributes()) { |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 57 | // Check if this attribute has a fixed byte size. |
Victor Leschuk | cbddae7 | 2017-01-10 21:18:26 +0000 | [diff] [blame] | 58 | if (auto FixedSize = AttrSpec.getByteSize(U)) { |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 59 | // Attribute byte size if fixed, just add the size to the offset. |
Greg Clayton | 82f12b1 | 2016-11-11 16:21:37 +0000 | [diff] [blame] | 60 | *OffsetPtr += *FixedSize; |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 61 | } else if (!DWARFFormValue::skipValue(AttrSpec.Form, DebugInfoData, |
Paul Robinson | 75c068c | 2017-06-26 18:43:01 +0000 | [diff] [blame] | 62 | OffsetPtr, U.getFormParams())) { |
Greg Clayton | 6f6e4db | 2016-11-15 01:23:06 +0000 | [diff] [blame] | 63 | // We failed to skip this attribute's value, restore the original offset |
| 64 | // and return the failure status. |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 65 | *OffsetPtr = Offset; |
| 66 | return false; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
Alexey Samsonov | c03f2ee | 2013-04-08 14:37:16 +0000 | [diff] [blame] | 69 | return true; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 70 | } |