1 //===-- DIContext.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines DIContext, an abstract data structure that holds
11 // debug information data.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_DEBUGINFO_DICONTEXT_H
16 #define LLVM_DEBUGINFO_DICONTEXT_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Object/ObjectFile.h"
21 #include "llvm/Object/RelocVisitor.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/DataTypes.h"
30 /// DILineInfo - a format-neutral container for source line information.
33 std::string FunctionName;
38 : FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0) {}
40 bool operator==(const DILineInfo &RHS) const {
41 return Line == RHS.Line && Column == RHS.Column &&
42 FileName == RHS.FileName && FunctionName == RHS.FunctionName;
44 bool operator!=(const DILineInfo &RHS) const {
45 return !(*this == RHS);
49 typedef SmallVector<std::pair<uint64_t, DILineInfo>, 16> DILineInfoTable;
51 /// DIInliningInfo - a format-neutral container for inlined code description.
52 class DIInliningInfo {
53 SmallVector<DILineInfo, 4> Frames;
56 DILineInfo getFrame(unsigned Index) const {
57 assert(Index < Frames.size());
60 DILineInfo *getMutableFrame(unsigned Index) {
61 assert(Index < Frames.size());
62 return &Frames[Index];
64 uint32_t getNumberOfFrames() const {
67 void addFrame(const DILineInfo &Frame) {
68 Frames.push_back(Frame);
72 /// DIGlobal - container for description of a global variable.
78 DIGlobal() : Name("<invalid>"), Start(0), Size(0) {}
81 /// A DINameKind is passed to name search methods to specify a
82 /// preference regarding the type of name resolution the caller wants.
83 enum class DINameKind { None, ShortName, LinkageName };
85 /// DILineInfoSpecifier - controls which fields of DILineInfo container
86 /// should be filled with data.
87 struct DILineInfoSpecifier {
88 enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
89 typedef DINameKind FunctionNameKind;
91 FileLineInfoKind FLIKind;
92 FunctionNameKind FNKind;
94 DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default,
95 FunctionNameKind FNKind = FunctionNameKind::None)
96 : FLIKind(FLIKind), FNKind(FNKind) {}
99 /// Selects which debug sections get dumped.
126 DIDT_AppleNamespaces,
138 DIContextKind getKind() const { return Kind; }
140 DIContext(DIContextKind K) : Kind(K) {}
141 virtual ~DIContext() {}
143 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
145 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
146 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
147 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
148 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
149 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
150 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
152 const DIContextKind Kind;
155 /// An inferface for inquiring the load address of a loaded object file
156 /// to be used by the DIContext implementations when applying relocations
158 class LoadedObjectInfo {
160 LoadedObjectInfo(const LoadedObjectInfo &) = default;
161 LoadedObjectInfo() = default;
164 virtual ~LoadedObjectInfo() = default;
166 /// Obtain the Load Address of a section by SectionRef.
168 /// Calculate the address of the given section.
169 /// The section need not be present in the local address space. The addresses
170 /// need to be consistent with the addresses used to query the DIContext and
171 /// the output of this function should be deterministic, i.e. repeated calls with
172 /// the same Sec should give the same address.
173 virtual uint64_t getSectionLoadAddress(const object::SectionRef &Sec) const = 0;
175 /// If conveniently available, return the content of the given Section.
177 /// When the section is available in the local address space, in relocated (loaded)
178 /// form, e.g. because it was relocated by a JIT for execution, this function
179 /// should provide the contents of said section in `Data`. If the loaded section
180 /// is not available, or the cost of retrieving it would be prohibitive, this
181 /// function should return false. In that case, relocations will be read from the
182 /// local (unrelocated) object file and applied on the fly. Note that this method
183 /// is used purely for optimzation purposes in the common case of JITting in the
184 /// local address space, so returning false should always be correct.
185 virtual bool getLoadedSectionContents(const object::SectionRef &Sec,
186 StringRef &Data) const {
190 /// Obtain a copy of this LoadedObjectInfo.
192 /// The caller is responsible for deallocation once the copy is no longer required.
193 virtual std::unique_ptr<LoadedObjectInfo> clone() const = 0;