blob: 2b7d0c3363a1d56b73a60cb0f38b07610be99c56 [file] [log] [blame]
Eugene Zelenkoe94042c2017-02-27 23:43:14 +00001//===- DWARFDebugInfoEntry.cpp --------------------------------------------===//
Benjamin Krameraa2f78f2011-09-13 19:42:23 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Krameraa2f78f2011-09-13 19:42:23 +00006//
7//===----------------------------------------------------------------------===//
8
Chandler Carruth6bda14b2017-06-06 11:49:48 +00009#include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000010#include "llvm/ADT/Optional.h"
Zachary Turner82af9432015-01-30 18:07:45 +000011#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
Zachary Turner82af9432015-01-30 18:07:45 +000012#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000013#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
14#include "llvm/Support/DataExtractor.h"
15#include <cstddef>
16#include <cstdint>
17
Benjamin Krameraa2f78f2011-09-13 19:42:23 +000018using namespace llvm;
19using namespace dwarf;
20
Greg Claytonc8c10322016-12-13 18:25:19 +000021bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U,
Igor Kudrinf26a70a2019-08-06 10:49:40 +000022 uint64_t *OffsetPtr) {
Paul Robinson17536b92017-06-29 16:52:08 +000023 DWARFDataExtractor DebugInfoData = U.getDebugInfoExtractor();
Igor Kudrinf26a70a2019-08-06 10:49:40 +000024 const uint64_t UEndOffset = U.getNextUnitOffset();
Greg Clayton78a07bf2016-12-21 21:37:06 +000025 return extractFast(U, OffsetPtr, DebugInfoData, UEndOffset, 0);
Greg Clayton6f6e4db2016-11-15 01:23:06 +000026}
Eugene Zelenkoe94042c2017-02-27 23:43:14 +000027
Igor Kudrinf26a70a2019-08-06 10:49:40 +000028bool DWARFDebugInfoEntry::extractFast(const DWARFUnit &U, uint64_t *OffsetPtr,
Paul Robinson17536b92017-06-29 16:52:08 +000029 const DWARFDataExtractor &DebugInfoData,
Igor Kudrinf26a70a2019-08-06 10:49:40 +000030 uint64_t UEndOffset, uint32_t D) {
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000031 Offset = *OffsetPtr;
Greg Clayton78a07bf2016-12-21 21:37:06 +000032 Depth = D;
Alexey Samsonov330b8932013-10-28 23:58:58 +000033 if (Offset >= UEndOffset || !DebugInfoData.isValidOffset(Offset))
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000034 return false;
35 uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
36 if (0 == AbbrCode) {
37 // NULL debug tag entry.
Craig Topper2617dcc2014-04-15 06:32:26 +000038 AbbrevDecl = nullptr;
Alexey Samsonovc03f2ee2013-04-08 14:37:16 +000039 return true;
40 }
Igor Kudrin9ceb1922020-08-12 15:37:16 +070041 if (const auto *AbbrevSet = U.getAbbreviations())
42 AbbrevDecl = AbbrevSet->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}