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_LVBINARYREADER_H
0015 #define LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVBINARYREADER_H
0016
0017 #include "llvm/DebugInfo/LogicalView/Core/LVReader.h"
0018 #include "llvm/MC/MCAsmInfo.h"
0019 #include "llvm/MC/MCContext.h"
0020 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
0021 #include "llvm/MC/MCInstPrinter.h"
0022 #include "llvm/MC/MCInstrInfo.h"
0023 #include "llvm/MC/MCObjectFileInfo.h"
0024 #include "llvm/MC/MCRegisterInfo.h"
0025 #include "llvm/MC/MCSubtargetInfo.h"
0026 #include "llvm/MC/TargetRegistry.h"
0027 #include "llvm/Object/COFF.h"
0028 #include "llvm/Object/ObjectFile.h"
0029
0030 namespace llvm {
0031 namespace logicalview {
0032
0033 constexpr bool UpdateHighAddress = false;
0034
0035
0036 struct LVSymbolTableEntry final {
0037 LVScope *Scope = nullptr;
0038 LVAddress Address = 0;
0039 LVSectionIndex SectionIndex = 0;
0040 bool IsComdat = false;
0041 LVSymbolTableEntry() = default;
0042 LVSymbolTableEntry(LVScope *Scope, LVAddress Address,
0043 LVSectionIndex SectionIndex, bool IsComdat)
0044 : Scope(Scope), Address(Address), SectionIndex(SectionIndex),
0045 IsComdat(IsComdat) {}
0046 };
0047
0048
0049 class LVSymbolTable final {
0050 using LVSymbolNames = std::map<std::string, LVSymbolTableEntry, std::less<>>;
0051 LVSymbolNames SymbolNames;
0052
0053 public:
0054 LVSymbolTable() = default;
0055
0056 void add(StringRef Name, LVScope *Function, LVSectionIndex SectionIndex = 0);
0057 void add(StringRef Name, LVAddress Address, LVSectionIndex SectionIndex,
0058 bool IsComdat);
0059 LVSectionIndex update(LVScope *Function);
0060
0061 const LVSymbolTableEntry &getEntry(StringRef Name);
0062 LVAddress getAddress(StringRef Name);
0063 LVSectionIndex getIndex(StringRef Name);
0064 bool getIsComdat(StringRef Name);
0065
0066 void print(raw_ostream &OS);
0067 };
0068
0069 class LVBinaryReader : public LVReader {
0070
0071 LVSymbolTable SymbolTable;
0072
0073
0074
0075
0076 using LVInlineeLine = std::map<LVScope *, std::unique_ptr<LVLines>>;
0077 LVInlineeLine CUInlineeLines;
0078
0079
0080
0081 LVDoubleMap<LVSectionIndex, LVScope *, LVLines *> ScopeInstructions;
0082
0083
0084 LVDoubleMap<LVSectionIndex, LVAddress, LVScope *> AssemblerMappings;
0085
0086
0087
0088 using LVSectionAddresses = std::map<LVSectionIndex, object::SectionRef>;
0089 LVSectionAddresses SectionAddresses;
0090
0091 void addSectionAddress(const object::SectionRef &Section) {
0092 if (SectionAddresses.find(Section.getAddress()) == SectionAddresses.end())
0093 SectionAddresses.emplace(Section.getAddress(), Section);
0094 }
0095
0096
0097
0098
0099 using LVSectionRanges = std::map<LVSectionIndex, std::unique_ptr<LVRange>>;
0100 LVSectionRanges SectionRanges;
0101
0102
0103 uint64_t ImageBaseAddress = 0;
0104 uint64_t VirtualAddress = 0;
0105
0106
0107 using LVSections = std::map<LVSectionIndex, object::SectionRef>;
0108 LVSections Sections;
0109
0110 std::vector<std::unique_ptr<LVLines>> DiscoveredLines;
0111
0112 protected:
0113
0114
0115 LVLines CULines;
0116
0117 std::unique_ptr<const MCRegisterInfo> MRI;
0118 std::unique_ptr<const MCAsmInfo> MAI;
0119 std::unique_ptr<const MCSubtargetInfo> STI;
0120 std::unique_ptr<const MCInstrInfo> MII;
0121 std::unique_ptr<const MCDisassembler> MD;
0122 std::unique_ptr<MCContext> MC;
0123 std::unique_ptr<MCInstPrinter> MIP;
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 LVAddress WasmCodeSectionOffset = 0;
0166
0167
0168 Error loadGenericTargetInfo(StringRef TheTriple, StringRef TheFeatures);
0169
0170 virtual void mapRangeAddress(const object::ObjectFile &Obj) {}
0171 virtual void mapRangeAddress(const object::ObjectFile &Obj,
0172 const object::SectionRef &Section,
0173 bool IsComdat) {}
0174
0175
0176 void mapVirtualAddress(const object::ObjectFile &Obj);
0177 void mapVirtualAddress(const object::COFFObjectFile &COFFObj);
0178
0179 Expected<std::pair<LVSectionIndex, object::SectionRef>>
0180 getSection(LVScope *Scope, LVAddress Address, LVSectionIndex SectionIndex);
0181
0182 void addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope);
0183 void addSectionRange(LVSectionIndex SectionIndex, LVScope *Scope,
0184 LVAddress LowerAddress, LVAddress UpperAddress);
0185 LVRange *getSectionRanges(LVSectionIndex SectionIndex);
0186
0187 void includeInlineeLines(LVSectionIndex SectionIndex, LVScope *Function);
0188
0189 Error createInstructions();
0190 Error createInstructions(LVScope *Function, LVSectionIndex SectionIndex);
0191 Error createInstructions(LVScope *Function, LVSectionIndex SectionIndex,
0192 const LVNameInfo &NameInfo);
0193
0194 void processLines(LVLines *DebugLines, LVSectionIndex SectionIndex);
0195 void processLines(LVLines *DebugLines, LVSectionIndex SectionIndex,
0196 LVScope *Function);
0197
0198 public:
0199 LVBinaryReader() = delete;
0200 LVBinaryReader(StringRef Filename, StringRef FileFormatName, ScopedPrinter &W,
0201 LVBinaryType BinaryType)
0202 : LVReader(Filename, FileFormatName, W, BinaryType) {}
0203 LVBinaryReader(const LVBinaryReader &) = delete;
0204 LVBinaryReader &operator=(const LVBinaryReader &) = delete;
0205 virtual ~LVBinaryReader() = default;
0206
0207 void addInlineeLines(LVScope *Scope, LVLines &Lines) {
0208 CUInlineeLines.emplace(Scope, std::make_unique<LVLines>(std::move(Lines)));
0209 }
0210
0211
0212 LVAddress linearAddress(uint16_t Segment, uint32_t Offset,
0213 LVAddress Addendum = 0) {
0214 return ImageBaseAddress + (Segment * VirtualAddress) + Offset + Addendum;
0215 }
0216
0217 void addToSymbolTable(StringRef Name, LVScope *Function,
0218 LVSectionIndex SectionIndex = 0);
0219 void addToSymbolTable(StringRef Name, LVAddress Address,
0220 LVSectionIndex SectionIndex, bool IsComdat);
0221 LVSectionIndex updateSymbolTable(LVScope *Function);
0222
0223 const LVSymbolTableEntry &getSymbolTableEntry(StringRef Name);
0224 LVAddress getSymbolTableAddress(StringRef Name);
0225 LVSectionIndex getSymbolTableIndex(StringRef Name);
0226 bool getSymbolTableIsComdat(StringRef Name);
0227
0228 LVSectionIndex getSectionIndex(LVScope *Scope) override {
0229 return Scope ? getSymbolTableIndex(Scope->getLinkageName())
0230 : DotTextSectionIndex;
0231 }
0232
0233 void print(raw_ostream &OS) const;
0234
0235 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0236 void dump() const { print(dbgs()); }
0237 #endif
0238 };
0239
0240 }
0241 }
0242
0243 #endif