LLVM  5.0.0
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"
20 #include <cassert>
21 #include <cstdint>
22 #include <memory>
23 #include <string>
24 #include <tuple>
25 #include <utility>
26 
27 namespace llvm {
28 
29 class raw_ostream;
30 
31 /// DILineInfo - a format-neutral container for source line information.
32 struct DILineInfo {
33  std::string FileName;
34  std::string FunctionName;
38 
39  // DWARF-specific.
41 
42  DILineInfo() : FileName("<invalid>"), FunctionName("<invalid>") {}
43 
44  bool operator==(const DILineInfo &RHS) const {
45  return Line == RHS.Line && Column == RHS.Column &&
46  FileName == RHS.FileName && FunctionName == RHS.FunctionName &&
48  }
49  bool operator!=(const DILineInfo &RHS) const {
50  return !(*this == RHS);
51  }
52  bool operator<(const DILineInfo &RHS) const {
53  return std::tie(FileName, FunctionName, Line, Column, StartLine,
54  Discriminator) <
55  std::tie(RHS.FileName, RHS.FunctionName, RHS.Line, RHS.Column,
56  RHS.StartLine, RHS.Discriminator);
57  }
58 };
59 
61 
62 /// DIInliningInfo - a format-neutral container for inlined code description.
65 
66 public:
67  DIInliningInfo() = default;
68 
69  DILineInfo getFrame(unsigned Index) const {
70  assert(Index < Frames.size());
71  return Frames[Index];
72  }
73 
74  DILineInfo *getMutableFrame(unsigned Index) {
75  assert(Index < Frames.size());
76  return &Frames[Index];
77  }
78 
80  return Frames.size();
81  }
82 
83  void addFrame(const DILineInfo &Frame) {
84  Frames.push_back(Frame);
85  }
86 };
87 
88 /// DIGlobal - container for description of a global variable.
89 struct DIGlobal {
90  std::string Name;
91  uint64_t Start = 0;
92  uint64_t Size = 0;
93 
94  DIGlobal() : Name("<invalid>") {}
95 };
96 
97 /// A DINameKind is passed to name search methods to specify a
98 /// preference regarding the type of name resolution the caller wants.
100 
101 /// DILineInfoSpecifier - controls which fields of DILineInfo container
102 /// should be filled with data.
106 
109 
112  : FLIKind(FLIKind), FNKind(FNKind) {}
113 };
114 
115 /// Selects which debug sections get dumped.
148 };
149 
150 /// Container for dump options that control which debug information will be
151 /// dumped.
154  bool DumpEH = false;
155  bool SummarizeTypes = false;
156  bool Brief = false;
157 };
158 
159 class DIContext {
160 public:
164  };
165 
166  DIContext(DIContextKind K) : Kind(K) {}
167  virtual ~DIContext() = default;
168 
169  DIContextKind getKind() const { return Kind; }
170 
171  virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts) = 0;
172 
173  virtual bool verify(raw_ostream &OS, DIDumpType DumpType = DIDT_All) {
174  // No verifier? Just say things went well.
175  return true;
176  }
177 
178  virtual DILineInfo getLineInfoForAddress(uint64_t Address,
179  DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
180  virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
181  uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
182  virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
183  DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
184 
185 private:
186  const DIContextKind Kind;
187 };
188 
189 /// An inferface for inquiring the load address of a loaded object file
190 /// to be used by the DIContext implementations when applying relocations
191 /// on the fly.
193 protected:
194  LoadedObjectInfo() = default;
195  LoadedObjectInfo(const LoadedObjectInfo &) = default;
196 
197 public:
198  virtual ~LoadedObjectInfo() = default;
199 
200  /// Obtain the Load Address of a section by SectionRef.
201  ///
202  /// Calculate the address of the given section.
203  /// The section need not be present in the local address space. The addresses
204  /// need to be consistent with the addresses used to query the DIContext and
205  /// the output of this function should be deterministic, i.e. repeated calls with
206  /// the same Sec should give the same address.
207  virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const {
208  return 0;
209  }
210 
211  /// If conveniently available, return the content of the given Section.
212  ///
213  /// When the section is available in the local address space, in relocated (loaded)
214  /// form, e.g. because it was relocated by a JIT for execution, this function
215  /// should provide the contents of said section in `Data`. If the loaded section
216  /// is not available, or the cost of retrieving it would be prohibitive, this
217  /// function should return false. In that case, relocations will be read from the
218  /// local (unrelocated) object file and applied on the fly. Note that this method
219  /// is used purely for optimzation purposes in the common case of JITting in the
220  /// local address space, so returning false should always be correct.
222  StringRef &Data) const {
223  return false;
224  }
225 
226  // FIXME: This is untested and unused anywhere in the LLVM project, it's
227  // used/needed by Julia (an external project). It should have some coverage
228  // (at least tests, but ideally example functionality).
229  /// Obtain a copy of this LoadedObjectInfo.
230  virtual std::unique_ptr<LoadedObjectInfo> clone() const = 0;
231 };
232 
233 template <typename Derived, typename Base = LoadedObjectInfo>
235 protected:
237  LoadedObjectInfoHelper() = default;
238 
239 public:
240  template <typename... Ts>
241  LoadedObjectInfoHelper(Ts &&... Args) : Base(std::forward<Ts>(Args)...) {}
242 
243  std::unique_ptr<llvm::LoadedObjectInfo> clone() const override {
244  return llvm::make_unique<Derived>(static_cast<const Derived &>(*this));
245  }
246 };
247 
248 } // end namespace llvm
249 
250 #endif // LLVM_DEBUGINFO_DICONTEXT_H
uint32_t StartLine
Definition: DIContext.h:37
uint32_t Discriminator
Definition: DIContext.h:40
virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const
Obtain the Load Address of a section by SectionRef.
Definition: DIContext.h:207
virtual bool getLoadedSectionContents(const object::SectionRef &Sec, StringRef &Data) const
If conveniently available, return the content of the given Section.
Definition: DIContext.h:221
DILineInfo * getMutableFrame(unsigned Index)
Definition: DIContext.h:74
std::string FileName
Definition: DIContext.h:33
LoadedObjectInfoHelper(Ts &&...Args)
Definition: DIContext.h:241
DIDumpType DumpType
Definition: DIContext.h:153
bool operator==(const DILineInfo &RHS) const
Definition: DIContext.h:44
bool operator<(const DILineInfo &RHS) const
Definition: DIContext.h:52
void addFrame(const DILineInfo &Frame)
Definition: DIContext.h:83
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:99
virtual ~LoadedObjectInfo()=default
DILineInfo - a format-neutral container for source line information.
Definition: DIContext.h:32
DIContextKind getKind() const
Definition: DIContext.h:169
FunctionNameKind FNKind
Definition: DIContext.h:108
virtual DILineInfo getLineInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
FileLineInfoKind FLIKind
Definition: DIContext.h:107
uint64_t Start
Definition: DIContext.h:91
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:152
uint32_t getNumberOfFrames() const
Definition: DIContext.h:79
virtual bool verify(raw_ostream &OS, DIDumpType DumpType=DIDT_All)
Definition: DIContext.h:173
uint32_t Column
Definition: DIContext.h:36
DILineInfoSpecifier - controls which fields of DILineInfo container should be filled with data...
Definition: DIContext.h:103
DILineInfo getFrame(unsigned Index) const
Definition: DIContext.h:69
DIContext(DIContextKind K)
Definition: DIContext.h:166
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
DIInliningInfo - a format-neutral container for inlined code description.
Definition: DIContext.h:63
DIDumpType
Selects which debug sections get dumped.
Definition: DIContext.h:116
bool operator!=(const DILineInfo &RHS) const
Definition: DIContext.h:49
DILineInfoSpecifier(FileLineInfoKind FLIKind=FileLineInfoKind::Default, FunctionNameKind FNKind=FunctionNameKind::None)
Definition: DIContext.h:110
uint32_t Line
Definition: DIContext.h:35
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
std::string Name
Definition: DIContext.h:90
std::string FunctionName
Definition: DIContext.h:34
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
Definition: DIContext.h:192
uint64_t Size
Definition: DIContext.h:92
virtual std::unique_ptr< LoadedObjectInfo > clone() const =0
Obtain a copy of this LoadedObjectInfo.
std::unique_ptr< llvm::LoadedObjectInfo > clone() const override
Definition: DIContext.h:243
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
DIInliningInfo()=default
virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
virtual ~DIContext()=default
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
virtual void dump(raw_ostream &OS, DIDumpOptions DumpOpts)=0
DIGlobal - container for description of a global variable.
Definition: DIContext.h:89
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:81