LLVM  6.0.0svn
DIContext.h
Go to the documentation of this file.
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/SmallVector.h"
19 #include "llvm/Object/ObjectFile.h"
21 #include <cassert>
22 #include <cstdint>
23 #include <memory>
24 #include <string>
25 #include <tuple>
26 #include <utility>
27 
28 namespace llvm {
29 
30 /// A format-neutral container for source line information.
31 struct DILineInfo {
32  std::string FileName;
33  std::string FunctionName;
37 
38  // DWARF-specific.
40 
41  DILineInfo() : FileName("<invalid>"), FunctionName("<invalid>") {}
42 
43  bool operator==(const DILineInfo &RHS) const {
44  return Line == RHS.Line && Column == RHS.Column &&
45  FileName == RHS.FileName && FunctionName == RHS.FunctionName &&
46  StartLine == RHS.StartLine && Discriminator == RHS.Discriminator;
47  }
48 
49  bool operator!=(const DILineInfo &RHS) const {
50  return !(*this == RHS);
51  }
52 
53  bool operator<(const DILineInfo &RHS) const {
54  return std::tie(FileName, FunctionName, Line, Column, StartLine,
55  Discriminator) <
56  std::tie(RHS.FileName, RHS.FunctionName, RHS.Line, RHS.Column,
57  RHS.StartLine, RHS.Discriminator);
58  }
59 
60  explicit operator bool() const { return *this != DILineInfo(); }
61 
62  void dump(raw_ostream &OS) {
63  OS << "Line info: ";
64  if (FileName != "<invalid>")
65  OS << "file '" << FileName << "', ";
66  if (FunctionName != "<invalid>")
67  OS << "function '" << FunctionName << "', ";
68  OS << "line " << Line << ", ";
69  OS << "column " << Column << ", ";
70  OS << "start line " << StartLine << '\n';
71  }
72 };
73 
75 
76 /// A format-neutral container for inlined code description.
79 
80 public:
81  DIInliningInfo() = default;
82 
83  DILineInfo getFrame(unsigned Index) const {
84  assert(Index < Frames.size());
85  return Frames[Index];
86  }
87 
88  DILineInfo *getMutableFrame(unsigned Index) {
89  assert(Index < Frames.size());
90  return &Frames[Index];
91  }
92 
94  return Frames.size();
95  }
96 
97  void addFrame(const DILineInfo &Frame) {
98  Frames.push_back(Frame);
99  }
100 };
101 
102 /// Container for description of a global variable.
103 struct DIGlobal {
104  std::string Name;
105  uint64_t Start = 0;
106  uint64_t Size = 0;
107 
108  DIGlobal() : Name("<invalid>") {}
109 };
110 
111 /// A DINameKind is passed to name search methods to specify a
112 /// preference regarding the type of name resolution the caller wants.
114 
115 /// Controls which fields of DILineInfo container should be filled
116 /// with data.
118  enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
120 
123 
126  : FLIKind(FLIKind), FNKind(FNKind) {}
127 };
128 
129 /// This is just a helper to programmatically construct DIDumpType.
131 #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
132  DIDT_ID_##ENUM_NAME,
133 #include "llvm/BinaryFormat/Dwarf.def"
134 #undef HANDLE_DWARF_SECTION
137 };
138 static_assert(DIDT_ID_Count <= 32, "section types overflow storage");
139 
140 /// Selects which debug sections get dumped.
141 enum DIDumpType : unsigned {
143  DIDT_All = ~0U,
144 #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
145  DIDT_##ENUM_NAME = 1U << DIDT_ID_##ENUM_NAME,
146 #include "llvm/BinaryFormat/Dwarf.def"
147 #undef HANDLE_DWARF_SECTION
149 };
150 
151 /// Container for dump options that control which debug information will be
152 /// dumped.
154  unsigned DumpType = DIDT_All;
155  unsigned RecurseDepth = -1U;
156  bool ShowChildren = false;
157  bool ShowParents = false;
158  bool ShowForm = false;
159  bool SummarizeTypes = false;
160  bool Verbose = false;
161 
162  /// Return default option set for printing a single DIE without children.
164  DIDumpOptions Opts;
165  Opts.RecurseDepth = 0;
166  return Opts;
167  }
168 
169  /// Return the options with RecurseDepth set to 0 unless explicitly required.
171  DIDumpOptions Opts = *this;
172  if (RecurseDepth == -1U && !ShowChildren)
173  Opts.RecurseDepth = 0;
174  return Opts;
175  }
176 };
177 
178 class DIContext {
179 public:
182  CK_PDB
183  };
184 
186  virtual ~DIContext() = default;
187 
188  DIContextKind getKind() const { return Kind; }
189 
190  virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) = 0;
191 
192  virtual bool verify(raw_ostream &OS, DIDumpOptions DumpOpts = {}) {
193  // No verifier? Just say things went well.
194  return true;
195  }
196 
197  virtual DILineInfo getLineInfoForAddress(uint64_t Address,
198  DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
199  virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
200  uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
201  virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
202  DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
203 
204 private:
205  const DIContextKind Kind;
206 };
207 
208 /// An inferface for inquiring the load address of a loaded object file
209 /// to be used by the DIContext implementations when applying relocations
210 /// on the fly.
212 protected:
213  LoadedObjectInfo() = default;
214  LoadedObjectInfo(const LoadedObjectInfo &) = default;
215 
216 public:
217  virtual ~LoadedObjectInfo() = default;
218 
219  /// Obtain the Load Address of a section by SectionRef.
220  ///
221  /// Calculate the address of the given section.
222  /// The section need not be present in the local address space. The addresses
223  /// need to be consistent with the addresses used to query the DIContext and
224  /// the output of this function should be deterministic, i.e. repeated calls
225  /// with the same Sec should give the same address.
226  virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const {
227  return 0;
228  }
229 
230  /// If conveniently available, return the content of the given Section.
231  ///
232  /// When the section is available in the local address space, in relocated
233  /// (loaded) form, e.g. because it was relocated by a JIT for execution, this
234  /// function should provide the contents of said section in `Data`. If the
235  /// loaded section is not available, or the cost of retrieving it would be
236  /// prohibitive, this function should return false. In that case, relocations
237  /// will be read from the local (unrelocated) object file and applied on the
238  /// fly. Note that this method is used purely for optimzation purposes in the
239  /// common case of JITting in the local address space, so returning false
240  /// should always be correct.
242  StringRef &Data) const {
243  return false;
244  }
245 
246  // FIXME: This is untested and unused anywhere in the LLVM project, it's
247  // used/needed by Julia (an external project). It should have some coverage
248  // (at least tests, but ideally example functionality).
249  /// Obtain a copy of this LoadedObjectInfo.
250  virtual std::unique_ptr<LoadedObjectInfo> clone() const = 0;
251 };
252 
253 template <typename Derived, typename Base = LoadedObjectInfo>
255 protected:
257  LoadedObjectInfoHelper() = default;
258 
259 public:
260  template <typename... Ts>
261  LoadedObjectInfoHelper(Ts &&... Args) : Base(std::forward<Ts>(Args)...) {}
262 
263  std::unique_ptr<llvm::LoadedObjectInfo> clone() const override {
264  return llvm::make_unique<Derived>(static_cast<const Derived &>(*this));
265  }
266 };
267 
268 } // end namespace llvm
269 
270 #endif // LLVM_DEBUGINFO_DICONTEXT_H
uint32_t StartLine
Definition: DIContext.h:36
uint32_t Discriminator
Definition: DIContext.h:39
bool operator!=(const DILineInfo &RHS) const
Definition: DIContext.h:49
DILineInfo * getMutableFrame(unsigned Index)
Definition: DIContext.h:88
std::string FileName
Definition: DIContext.h:32
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
virtual bool getLoadedSectionContents(const object::SectionRef &Sec, StringRef &Data) const
If conveniently available, return the content of the given Section.
Definition: DIContext.h:241
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
void addFrame(const DILineInfo &Frame)
Definition: DIContext.h:97
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:113
A format-neutral container for source line information.
Definition: DIContext.h:31
Definition: BitVector.h:920
FunctionNameKind FNKind
Definition: DIContext.h:122
FileLineInfoKind FLIKind
Definition: DIContext.h:121
bool operator<(const DILineInfo &RHS) const
Definition: DIContext.h:53
virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const
Obtain the Load Address of a section by SectionRef.
Definition: DIContext.h:226
DIContextKind getKind() const
Definition: DIContext.h:188
virtual bool verify(raw_ostream &OS, DIDumpOptions DumpOpts={})
Definition: DIContext.h:192
uint32_t getNumberOfFrames() const
Definition: DIContext.h:93
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:153
uint32_t Column
Definition: DIContext.h:35
Controls which fields of DILineInfo container should be filled with data.
Definition: DIContext.h:117
DIDumpOptions noImplicitRecursion() const
Return the options with RecurseDepth set to 0 unless explicitly required.
Definition: DIContext.h:170
bool operator==(const DILineInfo &RHS) const
Definition: DIContext.h:43
DIContext(DIContextKind K)
Definition: DIContext.h:185
A format-neutral container for inlined code description.
Definition: DIContext.h:77
LoadedObjectInfoHelper(Ts &&... Args)
Definition: DIContext.h:261
void dump(raw_ostream &OS)
Definition: DIContext.h:62
DILineInfoSpecifier(FileLineInfoKind FLIKind=FileLineInfoKind::Default, FunctionNameKind FNKind=FunctionNameKind::None)
Definition: DIContext.h:124
uint32_t Line
Definition: DIContext.h:34
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
std::string Name
Definition: DIContext.h:104
std::string FunctionName
Definition: DIContext.h:33
DIDumpType
Selects which debug sections get dumped.
Definition: DIContext.h:141
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
Definition: DIContext.h:211
std::unique_ptr< llvm::LoadedObjectInfo > clone() const override
Definition: DIContext.h:263
unsigned RecurseDepth
Definition: DIContext.h:155
DIDumpTypeCounter
This is just a helper to programmatically construct DIDumpType.
Definition: DIContext.h:130
static DIDumpOptions getForSingleDIE()
Return default option set for printing a single DIE without children.
Definition: DIContext.h:163
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Container for description of a global variable.
Definition: DIContext.h:103
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:80
DILineInfo getFrame(unsigned Index) const
Definition: DIContext.h:83