1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
//===- DWARFLinkerCompileUnit.h ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
#include "DWARFLinkerUnit.h"
#include "llvm/DWARFLinkerParallel/DWARFFile.h"
#include "llvm/DWARFLinkerParallel/DWARFLinker.h"
#include <optional>
namespace llvm {
namespace dwarflinker_parallel {
struct LinkContext;
class DWARFFile;
/// Stores all information related to a compile unit, be it in its original
/// instance of the object file or its brand new cloned and generated DIE tree.
class CompileUnit : public DwarfUnit {
public:
CompileUnit(LinkContext &, unsigned ID, StringRef ClangModuleName,
DWARFFile &File,
DWARFLinker::SwiftInterfacesMapTy *,
UnitMessageHandlerTy WarningHandler)
: DwarfUnit(ID, ClangModuleName, WarningHandler), ContaingFile(File) {
FormParams.Version = 4;
FormParams.Format = dwarf::DWARF32;
FormParams.AddrSize = 4;
UnitName = ContaingFile.FileName;
}
CompileUnit(LinkContext &, DWARFUnit &OrigUnit, unsigned ID,
StringRef ClangModuleName, DWARFFile &File,
UnitMessageHandlerTy WarningHandler)
: DwarfUnit(ID, ClangModuleName, WarningHandler),
ContaingFile(File), OrigUnit(&OrigUnit) {
DWARFDie CUDie = OrigUnit.getUnitDIE();
if (!CUDie)
return;
if (File.Dwarf)
Endianess = File.Dwarf->isLittleEndian() ? support::endianness::little
: support::endianness::big;
FormParams.Version = OrigUnit.getVersion();
FormParams.Format = dwarf::DWARF32;
FormParams.AddrSize = OrigUnit.getAddressByteSize();
Language = dwarf::toUnsigned(CUDie.find(dwarf::DW_AT_language), 0);
UnitName = ContaingFile.FileName;
SysRoot = dwarf::toStringRef(CUDie.find(dwarf::DW_AT_LLVM_sysroot)).str();
}
/// \defgroup Helper methods to access OrigUnit.
///
/// @{
/// Returns paired compile unit from input DWARF.
DWARFUnit &getOrigUnit() const {
assert(OrigUnit != nullptr);
return *OrigUnit;
}
const DWARFDebugInfoEntry *
getFirstChildEntry(const DWARFDebugInfoEntry *Die) const {
assert(OrigUnit != nullptr);
return OrigUnit->getFirstChildEntry(Die);
}
const DWARFDebugInfoEntry *
getSiblingEntry(const DWARFDebugInfoEntry *Die) const {
assert(OrigUnit != nullptr);
return OrigUnit->getSiblingEntry(Die);
}
DWARFDie getParent(const DWARFDebugInfoEntry *Die) {
assert(OrigUnit != nullptr);
return OrigUnit->getParent(Die);
}
DWARFDie getDIEAtIndex(unsigned Index) {
assert(OrigUnit != nullptr);
return OrigUnit->getDIEAtIndex(Index);
}
const DWARFDebugInfoEntry *getDebugInfoEntry(unsigned Index) const {
assert(OrigUnit != nullptr);
return OrigUnit->getDebugInfoEntry(Index);
}
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) {
assert(OrigUnit != nullptr);
return OrigUnit->getUnitDIE(ExtractUnitDIEOnly);
}
DWARFDie getDIE(const DWARFDebugInfoEntry *Die) {
assert(OrigUnit != nullptr);
return DWARFDie(OrigUnit, Die);
}
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const {
assert(OrigUnit != nullptr);
return OrigUnit->getDIEIndex(Die);
}
uint32_t getDIEIndex(const DWARFDie &Die) const {
assert(OrigUnit != nullptr);
return OrigUnit->getDIEIndex(Die);
}
std::optional<DWARFFormValue> find(uint32_t DieIdx,
ArrayRef<dwarf::Attribute> Attrs) const {
assert(OrigUnit != nullptr);
return find(OrigUnit->getDebugInfoEntry(DieIdx), Attrs);
}
std::optional<DWARFFormValue> find(const DWARFDebugInfoEntry *Die,
ArrayRef<dwarf::Attribute> Attrs) const {
if (!Die)
return std::nullopt;
auto AbbrevDecl = Die->getAbbreviationDeclarationPtr();
if (AbbrevDecl) {
for (auto Attr : Attrs) {
if (auto Value = AbbrevDecl->getAttributeValue(Die->getOffset(), Attr,
*OrigUnit))
return Value;
}
}
return std::nullopt;
}
std::optional<uint32_t> getDIEIndexForOffset(uint64_t Offset) {
return OrigUnit->getDIEIndexForOffset(Offset);
}
/// @}
private:
/// DWARFFile containing this compile unit.
DWARFFile &ContaingFile;
/// Pointer to the paired compile unit from the input DWARF.
DWARFUnit *OrigUnit = nullptr;
};
} // end of namespace dwarflinker_parallel
} // end namespace llvm
#endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
|