1 //===-- LVSymbol.h ----------------------------------------------*- C++ -*-===// 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 // 9 // This file defines the LVSymbol class, which is used to describe a debug 10 // information symbol. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H 15 #define LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H 16 17 #include "llvm/DebugInfo/LogicalView/Core/LVElement.h" 18 #include "llvm/Support/Compiler.h" 19 20 namespace llvm { 21 namespace logicalview { 22 23 enum class LVSymbolKind { 24 IsCallSiteParameter, 25 IsConstant, 26 IsInheritance, 27 IsMember, 28 IsParameter, 29 IsUnspecified, 30 IsVariable, 31 LastEntry 32 }; 33 using LVSymbolKindSet = std::set<LVSymbolKind>; 34 using LVSymbolDispatch = std::map<LVSymbolKind, LVSymbolGetFunction>; 35 using LVSymbolRequest = std::vector<LVSymbolGetFunction>; 36 37 class LLVM_ABI LVSymbol final : public LVElement { 38 enum class Property { HasLocation, FillGaps, LastEntry }; 39 40 // Typed bitvector with kinds and properties for this symbol. 41 LVProperties<LVSymbolKind> Kinds; 42 LVProperties<Property> Properties; 43 static LVSymbolDispatch Dispatch; 44 45 // CodeView symbol Linkage name. 46 size_t LinkageNameIndex = 0; 47 48 // Reference to DW_AT_specification, DW_AT_abstract_origin attribute. 49 LVSymbol *Reference = nullptr; 50 std::unique_ptr<LVLocations> Locations; 51 LVLocation *CurrentLocation = nullptr; 52 53 // Bitfields length. 54 uint32_t BitSize = 0; 55 56 // Index in the String pool representing any initial value. 57 size_t ValueIndex = 0; 58 59 // Coverage factor in units (bytes). 60 unsigned CoverageFactor = 0; 61 float CoveragePercentage = 0; 62 63 // Add a location gap into the location list. 64 LVLocations::iterator addLocationGap(LVLocations::iterator Pos, 65 LVAddress LowPC, LVAddress HighPC); 66 67 // Find the current symbol in the given 'Targets'. 68 LVSymbol *findIn(const LVSymbols *Targets) const; 69 70 public: LVSymbol()71 LVSymbol() : LVElement(LVSubclassID::LV_SYMBOL) { 72 setIsSymbol(); 73 setIncludeInPrint(); 74 } 75 LVSymbol(const LVSymbol &) = delete; 76 LVSymbol &operator=(const LVSymbol &) = delete; 77 ~LVSymbol() = default; 78 classof(const LVElement * Element)79 static bool classof(const LVElement *Element) { 80 return Element->getSubclassID() == LVSubclassID::LV_SYMBOL; 81 } 82 83 KIND(LVSymbolKind, IsCallSiteParameter); 84 KIND(LVSymbolKind, IsConstant); 85 KIND(LVSymbolKind, IsInheritance); 86 KIND(LVSymbolKind, IsMember); 87 KIND(LVSymbolKind, IsParameter); 88 KIND(LVSymbolKind, IsUnspecified); 89 KIND(LVSymbolKind, IsVariable); 90 91 PROPERTY(Property, HasLocation); 92 PROPERTY(Property, FillGaps); 93 94 const char *kind() const override; 95 96 // Access DW_AT_specification, DW_AT_abstract_origin reference. getReference()97 LVSymbol *getReference() const { return Reference; } setReference(LVSymbol * Symbol)98 void setReference(LVSymbol *Symbol) override { 99 Reference = Symbol; 100 setHasReference(); 101 } setReference(LVElement * Element)102 void setReference(LVElement *Element) override { 103 assert((!Element || isa<LVSymbol>(Element)) && "Invalid element"); 104 setReference(static_cast<LVSymbol *>(Element)); 105 } 106 setLinkageName(StringRef LinkageName)107 void setLinkageName(StringRef LinkageName) override { 108 LinkageNameIndex = getStringPool().getIndex(LinkageName); 109 } getLinkageName()110 StringRef getLinkageName() const override { 111 return getStringPool().getString(LinkageNameIndex); 112 } getLinkageNameIndex()113 size_t getLinkageNameIndex() const override { return LinkageNameIndex; } 114 getBitSize()115 uint32_t getBitSize() const override { return BitSize; } setBitSize(uint32_t Size)116 void setBitSize(uint32_t Size) override { BitSize = Size; } 117 118 // Process the values for a DW_AT_const_value. getValue()119 StringRef getValue() const override { 120 return getStringPool().getString(ValueIndex); 121 } setValue(StringRef Value)122 void setValue(StringRef Value) override { 123 ValueIndex = getStringPool().getIndex(Value); 124 } getValueIndex()125 size_t getValueIndex() const override { return ValueIndex; } 126 127 // Add a Location Entry. 128 void addLocationConstant(dwarf::Attribute Attr, LVUnsigned Constant, 129 uint64_t LocDescOffset); 130 void addLocationOperands(LVSmall Opcode, ArrayRef<uint64_t> Operands); 131 void addLocation(dwarf::Attribute Attr, LVAddress LowPC, LVAddress HighPC, 132 LVUnsigned SectionOffset, uint64_t LocDescOffset, 133 bool CallSiteLocation = false); 134 135 // Fill gaps in the location list. 136 void fillLocationGaps(); 137 138 // Get all the locations associated with symbols. 139 void getLocations(LVLocations &LocationList, LVValidLocation ValidLocation, 140 bool RecordInvalid = false); 141 void getLocations(LVLocations &LocationList) const; 142 143 // Calculate coverage factor. 144 void calculateCoverage(); 145 getCoverageFactor()146 unsigned getCoverageFactor() const { return CoverageFactor; } setCoverageFactor(unsigned Value)147 void setCoverageFactor(unsigned Value) { CoverageFactor = Value; } getCoveragePercentage()148 float getCoveragePercentage() const { return CoveragePercentage; } setCoveragePercentage(float Value)149 void setCoveragePercentage(float Value) { CoveragePercentage = Value; } 150 151 // Print location in raw format. 152 void printLocations(raw_ostream &OS, bool Full = true) const; 153 154 // Follow a chain of references given by DW_AT_abstract_origin and/or 155 // DW_AT_specification and update the symbol name. 156 StringRef resolveReferencesChain(); 157 158 void resolveName() override; 159 void resolveReferences() override; 160 getDispatch()161 static LVSymbolDispatch &getDispatch() { return Dispatch; } 162 163 static bool parametersMatch(const LVSymbols *References, 164 const LVSymbols *Targets); 165 166 static void getParameters(const LVSymbols *Symbols, LVSymbols *Parameters); 167 168 // Iterate through the 'References' set and check that all its elements 169 // are present in the 'Targets' set. For a missing element, mark its 170 // parents as missing. 171 static void markMissingParents(const LVSymbols *References, 172 const LVSymbols *Targets); 173 174 // Returns true if current type is logically equal to the given 'Symbol'. 175 bool equals(const LVSymbol *Symbol) const; 176 177 // Returns true if the given 'References' are logically equal to the 178 // given 'Targets'. 179 static bool equals(const LVSymbols *References, const LVSymbols *Targets); 180 181 // Report the current symbol as missing or added during comparison. 182 void report(LVComparePass Pass) override; 183 184 void print(raw_ostream &OS, bool Full = true) const override; 185 void printExtra(raw_ostream &OS, bool Full = true) const override; 186 }; 187 188 } // end namespace logicalview 189 } // end namespace llvm 190 191 #endif // LLVM_DEBUGINFO_LOGICALVIEW_CORE_LVSYMBOL_H 192