DIContext.h 5.5 KB

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