LLVM  16.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 "llvm/Support/Errc.h"
17 #include <cstddef>
18 #include <cstdint>
19 
20 using namespace llvm;
21 using namespace dwarf;
22 
24  const DWARFDataExtractor &DebugInfoData,
25  uint64_t UEndOffset, uint32_t ParentIdx) {
26  Offset = *OffsetPtr;
27  this->ParentIdx = ParentIdx;
28  if (Offset >= UEndOffset) {
31  "DWARF unit from offset 0x%8.8" PRIx64 " incl. "
32  "to offset 0x%8.8" PRIx64 " excl. "
33  "tries to read DIEs at offset 0x%8.8" PRIx64,
34  U.getOffset(), U.getNextUnitOffset(), *OffsetPtr));
35  return false;
36  }
37  assert(DebugInfoData.isValidOffset(UEndOffset - 1));
38  uint64_t AbbrCode = DebugInfoData.getULEB128(OffsetPtr);
39  if (0 == AbbrCode) {
40  // NULL debug tag entry.
41  AbbrevDecl = nullptr;
42  return true;
43  }
44  const auto *AbbrevSet = U.getAbbreviations();
45  if (!AbbrevSet) {
48  "DWARF unit at offset 0x%8.8" PRIx64 " "
49  "contains invalid abbreviation set offset 0x%" PRIx64,
51  // Restore the original offset.
52  *OffsetPtr = Offset;
53  return false;
54  }
55  AbbrevDecl = AbbrevSet->getAbbreviationDeclaration(AbbrCode);
56  if (!AbbrevDecl) {
59  "DWARF unit at offset 0x%8.8" PRIx64 " "
60  "contains invalid abbreviation %" PRIu64 " at "
61  "offset 0x%8.8" PRIx64 ", valid abbreviations are %s",
62  U.getOffset(), AbbrCode, *OffsetPtr,
63  AbbrevSet->getCodeRange().c_str()));
64  // Restore the original offset.
65  *OffsetPtr = Offset;
66  return false;
67  }
68  // See if all attributes in this DIE have fixed byte sizes. If so, we can
69  // just add this size to the offset to skip to the next DIE.
70  if (Optional<size_t> FixedSize = AbbrevDecl->getFixedAttributesByteSize(U)) {
71  *OffsetPtr += *FixedSize;
72  return true;
73  }
74 
75  // Skip all data in the .debug_info for the attributes
76  for (const auto &AttrSpec : AbbrevDecl->attributes()) {
77  // Check if this attribute has a fixed byte size.
78  if (auto FixedSize = AttrSpec.getByteSize(U)) {
79  // Attribute byte size if fixed, just add the size to the offset.
80  *OffsetPtr += *FixedSize;
81  } else if (!DWARFFormValue::skipValue(AttrSpec.Form, DebugInfoData,
82  OffsetPtr, U.getFormParams())) {
83  // We failed to skip this attribute's value, restore the original offset
84  // and return the failure status.
87  "DWARF unit at offset 0x%8.8" PRIx64 " "
88  "contains invalid FORM_* 0x%" PRIx16 " at offset 0x%8.8" PRIx64,
89  U.getOffset(), AttrSpec.Form, *OffsetPtr));
90  *OffsetPtr = Offset;
91  return false;
92  }
93  }
94  return true;
95 }
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:23
DWARFFormValue.h
llvm::DWARFUnit::getAbbreviations
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.cpp:1041
llvm::errc::invalid_argument
@ invalid_argument
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Optional.h
DWARFContext.h
Errc.h
llvm::Optional< size_t >
llvm::DWARFUnit::getFormParams
const dwarf::FormParams & getFormParams() const
Definition: DWARFUnit.h:315
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:220
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:147
uint64_t
DWARFUnit.h
llvm::DWARFContext::getWarningHandler
function_ref< void(Error)> getWarningHandler()
Definition: DWARFContext.h:417
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:331
llvm::DWARFUnit::getContext
DWARFContext & getContext() const
Definition: DWARFUnit.h:312
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:1238
DWARFDebugAbbrev.h
llvm::DWARFUnit
Definition: DWARFUnit.h:207
llvm::DWARFUnit::getOffset
uint64_t getOffset() const
Definition: DWARFUnit.h:314
llvm::DWARFUnit::getAbbreviationsOffset
uint64_t getAbbreviationsOffset() const
Definition: DWARFUnit.h:403
DWARFDataExtractor.h