LLVM  4.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;
37 
38  // DWARF-specific.
40 
42  : FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0),
43  Discriminator(0) {}
44 
45  bool operator==(const DILineInfo &RHS) const {
46  return Line == RHS.Line && Column == RHS.Column &&
47  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) <
54  std::tie(RHS.FileName, RHS.FunctionName, RHS.Line, RHS.Column);
55  }
56 };
57 
59 
60 /// DIInliningInfo - a format-neutral container for inlined code description.
63 
64 public:
65  DIInliningInfo() = default;
66 
67  DILineInfo getFrame(unsigned Index) const {
68  assert(Index < Frames.size());
69  return Frames[Index];
70  }
71 
72  DILineInfo *getMutableFrame(unsigned Index) {
73  assert(Index < Frames.size());
74  return &Frames[Index];
75  }
76 
78  return Frames.size();
79  }
80 
81  void addFrame(const DILineInfo &Frame) {
82  Frames.push_back(Frame);
83  }
84 };
85 
86 /// DIGlobal - container for description of a global variable.
87 struct DIGlobal {
88  std::string Name;
89  uint64_t Start;
90  uint64_t Size;
91 
92  DIGlobal() : Name("<invalid>"), Start(0), Size(0) {}
93 };
94 
95 /// A DINameKind is passed to name search methods to specify a
96 /// preference regarding the type of name resolution the caller wants.
98 
99 /// DILineInfoSpecifier - controls which fields of DILineInfo container
100 /// should be filled with data.
104 
107 
110  : FLIKind(FLIKind), FNKind(FNKind) {}
111 };
112 
113 /// Selects which debug sections get dumped.
145 };
146 
147 class DIContext {
148 public:
152  };
153 
154  DIContext(DIContextKind K) : Kind(K) {}
155  virtual ~DIContext() = default;
156 
157  DIContextKind getKind() const { return Kind; }
158 
159  virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All,
160  bool DumpEH = false, bool SummarizeTypes = false) = 0;
161 
162  virtual DILineInfo getLineInfoForAddress(uint64_t Address,
163  DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
164  virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
165  uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
166  virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
167  DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
168 
169 private:
170  const DIContextKind Kind;
171 };
172 
173 /// An inferface for inquiring the load address of a loaded object file
174 /// to be used by the DIContext implementations when applying relocations
175 /// on the fly.
177 protected:
178  LoadedObjectInfo(const LoadedObjectInfo &) = default;
179  LoadedObjectInfo() = default;
180 
181 public:
182  virtual ~LoadedObjectInfo() = default;
183 
184  /// Obtain the Load Address of a section by SectionRef.
185  ///
186  /// Calculate the address of the given section.
187  /// The section need not be present in the local address space. The addresses
188  /// need to be consistent with the addresses used to query the DIContext and
189  /// the output of this function should be deterministic, i.e. repeated calls with
190  /// the same Sec should give the same address.
191  virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const = 0;
192 
193  /// If conveniently available, return the content of the given Section.
194  ///
195  /// When the section is available in the local address space, in relocated (loaded)
196  /// form, e.g. because it was relocated by a JIT for execution, this function
197  /// should provide the contents of said section in `Data`. If the loaded section
198  /// is not available, or the cost of retrieving it would be prohibitive, this
199  /// function should return false. In that case, relocations will be read from the
200  /// local (unrelocated) object file and applied on the fly. Note that this method
201  /// is used purely for optimzation purposes in the common case of JITting in the
202  /// local address space, so returning false should always be correct.
204  StringRef &Data) const {
205  return false;
206  }
207 
208  /// Obtain a copy of this LoadedObjectInfo.
209  ///
210  /// The caller is responsible for deallocation once the copy is no longer required.
211  virtual std::unique_ptr<LoadedObjectInfo> clone() const = 0;
212 };
213 
214 } // end namespace llvm
215 
216 #endif // LLVM_DEBUGINFO_DICONTEXT_H
uint32_t Discriminator
Definition: DIContext.h:39
virtual bool getLoadedSectionContents(const object::SectionRef &Sec, StringRef &Data) const
If conveniently available, return the content of the given Section.
Definition: DIContext.h:203
DILineInfo * getMutableFrame(unsigned Index)
Definition: DIContext.h:72
std::string FileName
Definition: DIContext.h:33
bool operator==(const DILineInfo &RHS) const
Definition: DIContext.h:45
bool operator<(const DILineInfo &RHS) const
Definition: DIContext.h:52
void addFrame(const DILineInfo &Frame)
Definition: DIContext.h:81
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:97
virtual ~LoadedObjectInfo()=default
DILineInfo - a format-neutral container for source line information.
Definition: DIContext.h:32
DIContextKind getKind() const
Definition: DIContext.h:157
FunctionNameKind FNKind
Definition: DIContext.h:106
virtual DILineInfo getLineInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
FileLineInfoKind FLIKind
Definition: DIContext.h:105
uint64_t Start
Definition: DIContext.h:89
uint32_t getNumberOfFrames() const
Definition: DIContext.h:77
uint32_t Column
Definition: DIContext.h:36
DILineInfoSpecifier - controls which fields of DILineInfo container should be filled with data...
Definition: DIContext.h:101
DILineInfo getFrame(unsigned Index) const
Definition: DIContext.h:67
DIContext(DIContextKind K)
Definition: DIContext.h:154
DIInliningInfo - a format-neutral container for inlined code description.
Definition: DIContext.h:61
DIDumpType
Selects which debug sections get dumped.
Definition: DIContext.h:114
bool operator!=(const DILineInfo &RHS) const
Definition: DIContext.h:49
DILineInfoSpecifier(FileLineInfoKind FLIKind=FileLineInfoKind::Default, FunctionNameKind FNKind=FunctionNameKind::None)
Definition: DIContext.h:108
virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const =0
Obtain the Load Address of a section by SectionRef.
uint32_t Line
Definition: DIContext.h:35
SmallVector< std::pair< uint64_t, DILineInfo >, 16 > DILineInfoTable
Definition: DIContext.h:58
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:843
std::string Name
Definition: DIContext.h:88
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:176
uint64_t Size
Definition: DIContext.h:90
virtual std::unique_ptr< LoadedObjectInfo > clone() const =0
Obtain a copy of this LoadedObjectInfo.
virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
DIInliningInfo()=default
DINameKind FunctionNameKind
Definition: DIContext.h:103
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 void dump(raw_ostream &OS, DIDumpType DumpType=DIDT_All, bool DumpEH=false, bool SummarizeTypes=false)=0
virtual ~DIContext()=default
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
DIGlobal - container for description of a global variable.
Definition: DIContext.h:87
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:70