LLVM  14.0.0git
DWARFDebugInfoEntry.cpp
Go to the documentation of this file.
1 //===- DWARFDebugInfoEntry.cpp --------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/ADT/Optional.h"
16 #include <cstddef>
17 #include <cstdint>
18 
19 using namespace llvm;
20 using namespace dwarf;
21 
23  const DWARFDataExtractor &DebugInfoData,
24  uint64_t UEndOffset, uint32_t ParentIdx) {
25  Offset = *OffsetPtr;
26  this->ParentIdx = ParentIdx;
27  if (Offset >= UEndOffset) {
30  "DWARF unit from offset 0x%8.8" PRIx64 " incl. "
31  "to offset 0x%8.8" PRIx64 " excl. "
32  "tries to read DIEs at offset 0x%8.8" PRIx64,
33  U.getOffset(), U.getNextUnitOffset(), *OffsetPtr));
34  return false;
35  }
36  assert(DebugInfoData.isValidOffset(UEndOffset - 1));
37  uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
38  if (0 == AbbrCode) {
39  // NULL debug tag entry.
40  AbbrevDecl = nullptr;
41  return true;
42  }
43  const auto *AbbrevSet = U.getAbbreviations();
44  if (!AbbrevSet) {
47  "DWARF unit at offset 0x%8.8" PRIx64 " "
48  "contains invalid abbreviation set offset 0x%" PRIx64,
50  // Restore the original offset.
51  *OffsetPtr = Offset;
52  return false;
53  }
54  AbbrevDecl = AbbrevSet->getAbbreviationDeclaration(AbbrCode);
55  if (!AbbrevDecl) {
58  "DWARF unit at offset 0x%8.8" PRIx64 " "
59  "contains invalid abbreviation %" PRIu64 " at "
60  "offset 0x%8.8" PRIx64 ", valid abbreviations are %s",
61  U.getOffset(), AbbrCode, *OffsetPtr,
62  AbbrevSet->getCodeRange().c_str()));
63  // Restore the original offset.
64  *OffsetPtr = Offset;
65  return false;
66  }
67  // See if all attributes in this DIE have fixed byte sizes. If so, we can
68  // just add this size to the offset to skip to the next DIE.
69  if (Optional<size_t> FixedSize = AbbrevDecl->getFixedAttributesByteSize(U)) {
70  *OffsetPtr += *FixedSize;
71  return true;
72  }
73 
74  // Skip all data in the .debug_info for the attributes
75  for (const auto &AttrSpec : AbbrevDecl->attributes()) {
76  // Check if this attribute has a fixed byte size.
77  if (auto FixedSize = AttrSpec.getByteSize(U)) {
78  // Attribute byte size if fixed, just add the size to the offset.
79  *OffsetPtr += *FixedSize;
80  } else if (!DWARFFormValue::skipValue(AttrSpec.Form, DebugInfoData,
81  OffsetPtr, U.getFormParams())) {
82  // We failed to skip this attribute's value, restore the original offset
83  // and return the failure status.
86  "DWARF unit at offset 0x%8.8" PRIx64 " "
87  "contains invalid FORM_* 0x%" PRIx16 " at offset 0x%8.8" PRIx64,
88  U.getOffset(), AttrSpec.Form, *OffsetPtr));
89  *OffsetPtr = Offset;
90  return false;
91  }
92  }
93  return true;
94 }
llvm::DWARFDebugInfoEntry::extractFast
bool extractFast(const DWARFUnit &U, uint64_t *OffsetPtr, const DWARFDataExtractor &DebugInfoData, uint64_t UEndOffset, uint32_t ParentIdx)
Extracts a debug info entry, which is a child of a given unit, starting at a given offset.
Definition: DWARFDebugInfoEntry.cpp:22
DWARFFormValue.h
llvm::DWARFUnit::getAbbreviations
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.cpp:869
llvm::errc::invalid_argument
@ invalid_argument
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
Optional.h
DWARFContext.h
llvm::Optional< size_t >
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::DWARFUnit::getFormParams
const dwarf::FormParams & getFormParams() const
Definition: DWARFUnit.h:282
llvm::DWARFDataExtractor
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Definition: DWARFDataExtractor.h:21
llvm::DataExtractor::getULEB128
uint64_t getULEB128(uint64_t *offset_ptr, llvm::Error *Err=nullptr) const
Extract a unsigned LEB128 value from *offset_ptr.
Definition: DataExtractor.cpp:221
llvm::DWARFFormValue::skipValue
bool skipValue(DataExtractor DebugInfoData, uint64_t *OffsetPtr, const dwarf::FormParams Params) const
Skip a form's value in DebugInfoData at the offset specified by OffsetPtr.
Definition: DWARFFormValue.h:145
uint64_t
DWARFUnit.h
llvm::DWARFContext::getWarningHandler
function_ref< void(Error)> getWarningHandler()
Definition: DWARFContext.h:387
llvm::DataExtractor::isValidOffset
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:665
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::DWARFUnit::getNextUnitOffset
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:298
llvm::DWARFUnit::getContext
DWARFContext & getContext() const
Definition: DWARFUnit.h:279
uint32_t
DWARFDebugInfoEntry.h
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1231
DWARFDebugAbbrev.h
llvm::DWARFUnit
Definition: DWARFUnit.h:203
DataExtractor.h
llvm::DWARFUnit::getOffset
uint64_t getOffset() const
Definition: DWARFUnit.h:281
llvm::DWARFUnit::getAbbreviationsOffset
uint64_t getAbbreviationsOffset() const
Definition: DWARFUnit.h:367