Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:43

0001 //===-- LVDWARFReader.h -----------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the LVDWARFReader class, which is used to describe a
0010 // debug information (DWARF) reader.
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   // Indicates if ranges data are available; in the case of split DWARF any
0037   // reference to ranges is valid only if the skeleton DIE has been loaded.
0038   bool RangesDataAvailable = false;
0039   LVAddress CUBaseAddress = 0;
0040   LVAddress CUHighAddress = 0;
0041 
0042   // Current elements during the processing of a DIE.
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   // In DWARF v4, the files are 1-indexed.
0051   // In DWARF v5, the files are 0-indexed.
0052   // The DWARF reader expects the indexes as 1-indexed.
0053   bool IncrementFileIndex = false;
0054 
0055   // Address ranges collected for current DIE.
0056   std::vector<LVAddressRange> CurrentRanges;
0057 
0058   // Symbols with locations for current compile unit.
0059   LVSymbols SymbolsWithLocations;
0060 
0061   // Global Offsets (Offset, Element).
0062   LVOffsetElementMap GlobalOffsets;
0063 
0064   // Low PC and High PC values for DIE being processed.
0065   LVAddress CurrentLowPC = 0;
0066   LVAddress CurrentHighPC = 0;
0067   bool FoundLowPC = false;
0068   bool FoundHighPC = false;
0069 
0070   // Cross references (Elements).
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   // Process the attributes for the given DIE.
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   // Add offset to global map.
0097   void addGlobalOffset(LVOffset Offset) {
0098     if (GlobalOffsets.find(Offset) == GlobalOffsets.end())
0099       // Just associate the DIE offset with a null element, as we do not
0100       // know if the referenced element has been created.
0101       GlobalOffsets.emplace(Offset, nullptr);
0102   }
0103 
0104   // Remove offset from global map.
0105   void removeGlobalOffset(LVOffset Offset) {
0106     LVOffsetElementMap::iterator Iter = GlobalOffsets.find(Offset);
0107     if (Iter != GlobalOffsets.end())
0108       GlobalOffsets.erase(Iter);
0109   }
0110 
0111   // Get the location information for DW_AT_data_member_location.
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   // Get an element given the DIE offset.
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 } // end namespace logicalview
0159 } // end namespace llvm
0160 
0161 #endif // LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H