File indexing completed on 2026-05-10 08:43:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
0015 #define LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
0016
0017 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
0018 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
0019 #include "llvm/DebugInfo/LogicalView/Readers/LVBinaryReader.h"
0020 #include <unordered_set>
0021
0022 namespace llvm {
0023 namespace logicalview {
0024
0025 class LVElement;
0026 class LVLine;
0027 class LVScopeCompileUnit;
0028 class LVSymbol;
0029 class LVType;
0030
0031 using AttributeSpec = DWARFAbbreviationDeclaration::AttributeSpec;
0032
0033 class LVDWARFReader final : public LVBinaryReader {
0034 object::ObjectFile &Obj;
0035
0036
0037
0038 bool RangesDataAvailable = false;
0039 LVAddress CUBaseAddress = 0;
0040 LVAddress CUHighAddress = 0;
0041
0042
0043 LVElement *CurrentElement = nullptr;
0044 LVScope *CurrentScope = nullptr;
0045 LVSymbol *CurrentSymbol = nullptr;
0046 LVType *CurrentType = nullptr;
0047 LVOffset CurrentOffset = 0;
0048 LVOffset CurrentEndOffset = 0;
0049
0050
0051
0052
0053 bool IncrementFileIndex = false;
0054
0055
0056 std::vector<LVAddressRange> CurrentRanges;
0057
0058
0059 LVSymbols SymbolsWithLocations;
0060
0061
0062 LVOffsetElementMap GlobalOffsets;
0063
0064
0065 LVAddress CurrentLowPC = 0;
0066 LVAddress CurrentHighPC = 0;
0067 bool FoundLowPC = false;
0068 bool FoundHighPC = false;
0069
0070
0071 using LVElementSet = std::unordered_set<LVElement *>;
0072 struct LVElementEntry {
0073 LVElement *Element;
0074 LVElementSet References;
0075 LVElementSet Types;
0076 LVElementEntry(LVElement *Element = nullptr) : Element(Element) {}
0077 };
0078 using LVElementReference = std::unordered_map<LVOffset, LVElementEntry>;
0079 LVElementReference ElementTable;
0080
0081 Error loadTargetInfo(const object::ObjectFile &Obj);
0082
0083 void mapRangeAddress(const object::ObjectFile &Obj) override;
0084
0085 LVElement *createElement(dwarf::Tag Tag);
0086 void traverseDieAndChildren(DWARFDie &DIE, LVScope *Parent,
0087 DWARFDie &SkeletonDie);
0088
0089 LVScope *processOneDie(const DWARFDie &InputDIE, LVScope *Parent,
0090 DWARFDie &SkeletonDie);
0091 void processOneAttribute(const DWARFDie &Die, LVOffset *OffsetPtr,
0092 const AttributeSpec &AttrSpec);
0093 void createLineAndFileRecords(const DWARFDebugLine::LineTable *Lines);
0094 void processLocationGaps();
0095
0096
0097 void addGlobalOffset(LVOffset Offset) {
0098 if (GlobalOffsets.find(Offset) == GlobalOffsets.end())
0099
0100
0101 GlobalOffsets.emplace(Offset, nullptr);
0102 }
0103
0104
0105 void removeGlobalOffset(LVOffset Offset) {
0106 LVOffsetElementMap::iterator Iter = GlobalOffsets.find(Offset);
0107 if (Iter != GlobalOffsets.end())
0108 GlobalOffsets.erase(Iter);
0109 }
0110
0111
0112 void processLocationMember(dwarf::Attribute Attr,
0113 const DWARFFormValue &FormValue,
0114 const DWARFDie &Die, uint64_t OffsetOnEntry);
0115 void processLocationList(dwarf::Attribute Attr,
0116 const DWARFFormValue &FormValue, const DWARFDie &Die,
0117 uint64_t OffsetOnEntry,
0118 bool CallSiteLocation = false);
0119 void updateReference(dwarf::Attribute Attr, const DWARFFormValue &FormValue);
0120
0121
0122 LVElement *getElementForOffset(LVOffset offset, LVElement *Element,
0123 bool IsType);
0124
0125 protected:
0126 Error createScopes() override;
0127 void sortScopes() override;
0128
0129 public:
0130 LVDWARFReader() = delete;
0131 LVDWARFReader(StringRef Filename, StringRef FileFormatName,
0132 object::ObjectFile &Obj, ScopedPrinter &W)
0133 : LVBinaryReader(Filename, FileFormatName, W, LVBinaryType::ELF),
0134 Obj(Obj) {}
0135 LVDWARFReader(const LVDWARFReader &) = delete;
0136 LVDWARFReader &operator=(const LVDWARFReader &) = delete;
0137 ~LVDWARFReader() = default;
0138
0139 LVAddress getCUBaseAddress() const { return CUBaseAddress; }
0140 void setCUBaseAddress(LVAddress Address) { CUBaseAddress = Address; }
0141 LVAddress getCUHighAddress() const { return CUHighAddress; }
0142 void setCUHighAddress(LVAddress Address) { CUHighAddress = Address; }
0143
0144 const LVSymbols &GetSymbolsWithLocations() const {
0145 return SymbolsWithLocations;
0146 }
0147
0148 std::string getRegisterName(LVSmall Opcode,
0149 ArrayRef<uint64_t> Operands) override;
0150
0151 void print(raw_ostream &OS) const;
0152
0153 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0154 void dump() const { print(dbgs()); }
0155 #endif
0156 };
0157
0158 }
0159 }
0160
0161 #endif