1 //===-- DIContext.h ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines DIContext, an abstract data structure that holds 11 // debug information data. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_DEBUGINFO_DICONTEXT_H 16 #define LLVM_DEBUGINFO_DICONTEXT_H 17 18 #include "llvm/ADT/DenseMap.h" 19 #include "llvm/ADT/SmallVector.h" 20 #include "llvm/Object/ObjectFile.h" 21 #include "llvm/Object/RelocVisitor.h" 22 #include "llvm/Support/Casting.h" 23 #include "llvm/Support/DataTypes.h" 24 #include <string> 25 26 namespace llvm { 27 28 class raw_ostream; 29 30 /// DILineInfo - a format-neutral container for source line information. 31 struct DILineInfo { 32 std::string FileName; 33 std::string FunctionName; 34 uint32_t Line; 35 uint32_t Column; 36 DILineInfoDILineInfo37 DILineInfo() 38 : FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0) {} 39 40 bool operator==(const DILineInfo &RHS) const { 41 return Line == RHS.Line && Column == RHS.Column && 42 FileName == RHS.FileName && FunctionName == RHS.FunctionName; 43 } 44 bool operator!=(const DILineInfo &RHS) const { 45 return !(*this == RHS); 46 } 47 }; 48 49 typedef SmallVector<std::pair<uint64_t, DILineInfo>, 16> DILineInfoTable; 50 51 /// DIInliningInfo - a format-neutral container for inlined code description. 52 class DIInliningInfo { 53 SmallVector<DILineInfo, 4> Frames; 54 public: DIInliningInfo()55 DIInliningInfo() {} getFrame(unsigned Index)56 DILineInfo getFrame(unsigned Index) const { 57 assert(Index < Frames.size()); 58 return Frames[Index]; 59 } getNumberOfFrames()60 uint32_t getNumberOfFrames() const { 61 return Frames.size(); 62 } addFrame(const DILineInfo & Frame)63 void addFrame(const DILineInfo &Frame) { 64 Frames.push_back(Frame); 65 } 66 }; 67 68 /// A DINameKind is passed to name search methods to specify a 69 /// preference regarding the type of name resolution the caller wants. 70 enum class DINameKind { None, ShortName, LinkageName }; 71 72 /// DILineInfoSpecifier - controls which fields of DILineInfo container 73 /// should be filled with data. 74 struct DILineInfoSpecifier { 75 enum class FileLineInfoKind { None, Default, AbsoluteFilePath }; 76 typedef DINameKind FunctionNameKind; 77 78 FileLineInfoKind FLIKind; 79 FunctionNameKind FNKind; 80 81 DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default, 82 FunctionNameKind FNKind = FunctionNameKind::None) FLIKindDILineInfoSpecifier83 : FLIKind(FLIKind), FNKind(FNKind) {} 84 }; 85 86 /// Selects which debug sections get dumped. 87 enum DIDumpType { 88 DIDT_Null, 89 DIDT_All, 90 DIDT_Abbrev, 91 DIDT_AbbrevDwo, 92 DIDT_Aranges, 93 DIDT_Frames, 94 DIDT_Info, 95 DIDT_InfoDwo, 96 DIDT_Types, 97 DIDT_TypesDwo, 98 DIDT_Line, 99 DIDT_LineDwo, 100 DIDT_Loc, 101 DIDT_LocDwo, 102 DIDT_Ranges, 103 DIDT_Pubnames, 104 DIDT_Pubtypes, 105 DIDT_GnuPubnames, 106 DIDT_GnuPubtypes, 107 DIDT_Str, 108 DIDT_StrDwo, 109 DIDT_StrOffsetsDwo, 110 DIDT_AppleNames, 111 DIDT_AppleTypes, 112 DIDT_AppleNamespaces, 113 DIDT_AppleObjC 114 }; 115 116 class DIContext { 117 public: 118 enum DIContextKind { 119 CK_DWARF, 120 CK_PDB 121 }; getKind()122 DIContextKind getKind() const { return Kind; } 123 DIContext(DIContextKind K)124 DIContext(DIContextKind K) : Kind(K) {} ~DIContext()125 virtual ~DIContext() {} 126 127 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0; 128 129 virtual DILineInfo getLineInfoForAddress(uint64_t Address, 130 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0; 131 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, 132 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0; 133 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, 134 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0; 135 private: 136 const DIContextKind Kind; 137 }; 138 139 /// An inferface for inquiring the load address of a loaded object file 140 /// to be used by the DIContext implementations when applying relocations 141 /// on the fly. 142 class LoadedObjectInfo { 143 public: 144 virtual ~LoadedObjectInfo() = default; 145 146 /// Obtain the Load Address of a section by Name. 147 /// 148 /// Calculate the address of the section identified by the passed in Name. 149 /// The section need not be present in the local address space. The addresses 150 /// need to be consistent with the addresses used to query the DIContext and 151 /// the output of this function should be deterministic, i.e. repeated calls with 152 /// the same Name should give the same address. 153 virtual uint64_t getSectionLoadAddress(StringRef Name) const = 0; 154 155 /// If conveniently available, return the content of the given Section. 156 /// 157 /// When the section is available in the local address space, in relocated (loaded) 158 /// form, e.g. because it was relocated by a JIT for execution, this function 159 /// should provide the contents of said section in `Data`. If the loaded section 160 /// is not available, or the cost of retrieving it would be prohibitive, this 161 /// function should return false. In that case, relocations will be read from the 162 /// local (unrelocated) object file and applied on the fly. Note that this method 163 /// is used purely for optimzation purposes in the common case of JITting in the 164 /// local address space, so returning false should always be correct. getLoadedSectionContents(StringRef Name,StringRef & Data)165 virtual bool getLoadedSectionContents(StringRef Name, StringRef &Data) const { 166 return false; 167 } 168 169 /// Obtain a copy of this LoadedObjectInfo. 170 /// 171 /// The caller is responsible for deallocation once the copy is no longer required. 172 virtual std::unique_ptr<LoadedObjectInfo> clone() const = 0; 173 }; 174 175 } 176 177 #endif 178