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 uint32_t getNumberOfFrames() const {
63 void addFrame(const DILineInfo &Frame) {
64 Frames.push_back(Frame);
68 /// A DINameKind is passed to name search methods to specify a
69 /// preference regarding the type of name resolution the caller wants.
70 enum class DINameKind { None, ShortName, LinkageName };
72 /// DILineInfoSpecifier - controls which fields of DILineInfo container
73 /// should be filled with data.
74 struct DILineInfoSpecifier {
75 enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
76 typedef DINameKind FunctionNameKind;
78 FileLineInfoKind FLIKind;
79 FunctionNameKind FNKind;
81 DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default,
82 FunctionNameKind FNKind = FunctionNameKind::None)
83 : FLIKind(FLIKind), FNKind(FNKind) {}
86 /// Selects which debug sections get dumped.
112 DIDT_AppleNamespaces,
116 // In place of applying the relocations to the data we've read from disk we use
117 // a separate mapping table to the side and checking that at locations in the
118 // dwarf where we expect relocated values. This adds a bit of complexity to the
119 // dwarf parsing/extraction at the benefit of not allocating memory for the
120 // entire size of the debug info sections.
121 typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
128 DIContextKind getKind() const { return Kind; }
130 DIContext(DIContextKind K) : Kind(K) {}
131 virtual ~DIContext();
133 /// getDWARFContext - get a context for binary DWARF data.
134 static DIContext *getDWARFContext(const object::ObjectFile &Obj);
136 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
138 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
139 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
140 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
141 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
142 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
143 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
145 const DIContextKind Kind;