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"
31 /// DILineInfo - a format-neutral container for source line information.
34 std::string FunctionName;
39 : FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0) {}
41 bool operator==(const DILineInfo &RHS) const {
42 return Line == RHS.Line && Column == RHS.Column &&
43 FileName == RHS.FileName && FunctionName == RHS.FunctionName;
45 bool operator!=(const DILineInfo &RHS) const {
46 return !(*this == RHS);
50 typedef SmallVector<std::pair<uint64_t, DILineInfo>, 16> DILineInfoTable;
52 /// DIInliningInfo - a format-neutral container for inlined code description.
53 class DIInliningInfo {
54 SmallVector<DILineInfo, 4> Frames;
57 DILineInfo getFrame(unsigned Index) const {
58 assert(Index < Frames.size());
61 uint32_t getNumberOfFrames() const {
64 void addFrame(const DILineInfo &Frame) {
65 Frames.push_back(Frame);
69 /// DILineInfoSpecifier - controls which fields of DILineInfo container
70 /// should be filled with data.
71 class DILineInfoSpecifier {
72 const uint32_t Flags; // Or'ed flags that set the info we want to fetch.
75 FileLineInfo = 1 << 0,
76 AbsoluteFilePath = 1 << 1,
79 // Use file/line info by default.
80 DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
81 bool needs(Specification spec) const {
82 return (Flags & spec) > 0;
86 /// Selects which debug sections get dumped.
112 // In place of applying the relocations to the data we've read from disk we use
113 // a separate mapping table to the side and checking that at locations in the
114 // dwarf where we expect relocated values. This adds a bit of complexity to the
115 // dwarf parsing/extraction at the benefit of not allocating memory for the
116 // entire size of the debug info sections.
117 typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
124 DIContextKind getKind() const { return Kind; }
126 DIContext(DIContextKind K) : Kind(K) {}
127 virtual ~DIContext();
129 /// getDWARFContext - get a context for binary DWARF data.
130 static DIContext *getDWARFContext(object::ObjectFile *);
132 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
134 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
135 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
136 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
137 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
138 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
139 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
141 const DIContextKind Kind;