LLVM  3.7.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/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Object/ObjectFile.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 
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 
50 
51 /// DIInliningInfo - a format-neutral container for inlined code description.
54  public:
56  DILineInfo getFrame(unsigned Index) const {
57  assert(Index < Frames.size());
58  return Frames[Index];
59  }
60  uint32_t getNumberOfFrames() const {
61  return Frames.size();
62  }
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.
71 
72 /// DILineInfoSpecifier - controls which fields of DILineInfo container
73 /// should be filled with data.
77 
80 
84 };
85 
86 /// Selects which debug sections get dumped.
87 enum DIDumpType {
114 };
115 
116 class DIContext {
117 public:
121  };
122  DIContextKind getKind() const { return Kind; }
123 
124  DIContext(DIContextKind K) : Kind(K) {}
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.
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.
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
std::string FileName
Definition: DIContext.h:32
virtual bool getLoadedSectionContents(StringRef Name, StringRef &Data) const
If conveniently available, return the content of the given Section.
Definition: DIContext.h:165
bool operator==(const DILineInfo &RHS) const
Definition: DIContext.h:40
virtual ~DIContext()
Definition: DIContext.h:125
void addFrame(const DILineInfo &Frame)
Definition: DIContext.h:63
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:70
virtual ~LoadedObjectInfo()=default
virtual uint64_t getSectionLoadAddress(StringRef Name) const =0
Obtain the Load Address of a section by Name.
DILineInfo - a format-neutral container for source line information.
Definition: DIContext.h:31
DIContextKind getKind() const
Definition: DIContext.h:122
FunctionNameKind FNKind
Definition: DIContext.h:79
virtual DILineInfo getLineInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
FileLineInfoKind FLIKind
Definition: DIContext.h:78
uint32_t getNumberOfFrames() const
Definition: DIContext.h:60
uint32_t Column
Definition: DIContext.h:35
DILineInfoSpecifier - controls which fields of DILineInfo container should be filled with data...
Definition: DIContext.h:74
DILineInfo getFrame(unsigned Index) const
Definition: DIContext.h:56
DIContext(DIContextKind K)
Definition: DIContext.h:124
DIInliningInfo - a format-neutral container for inlined code description.
Definition: DIContext.h:52
DIDumpType
Selects which debug sections get dumped.
Definition: DIContext.h:87
bool operator!=(const DILineInfo &RHS) const
Definition: DIContext.h:44
virtual void dump(raw_ostream &OS, DIDumpType DumpType=DIDT_All)=0
DILineInfoSpecifier(FileLineInfoKind FLIKind=FileLineInfoKind::Default, FunctionNameKind FNKind=FunctionNameKind::None)
Definition: DIContext.h:81
uint32_t Line
Definition: DIContext.h:34
SmallVector< std::pair< uint64_t, DILineInfo >, 16 > DILineInfoTable
Definition: DIContext.h:49
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
std::string FunctionName
Definition: DIContext.h:33
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
Definition: DIContext.h:142
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
DINameKind FunctionNameKind
Definition: DIContext.h:76
virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40