llvm-dwarfdump: Support for debug_line.dwo section for file names for type units...
[oota-llvm.git] / include / llvm / DebugInfo / DIContext.h
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/SmallString.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Object/ObjectFile.h"
23 #include "llvm/Object/RelocVisitor.h"
24 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/DataTypes.h"
26
27 namespace llvm {
28
29 class raw_ostream;
30
31 /// DILineInfo - a format-neutral container for source line information.
32 class DILineInfo {
33   SmallString<16> FileName;
34   SmallString<16> FunctionName;
35   uint32_t Line;
36   uint32_t Column;
37 public:
38   DILineInfo()
39     : FileName("<invalid>"), FunctionName("<invalid>"),
40       Line(0), Column(0) {}
41   DILineInfo(StringRef fileName, StringRef functionName, uint32_t line,
42              uint32_t column)
43       : FileName(fileName), FunctionName(functionName), Line(line),
44         Column(column) {}
45
46   const char *getFileName() { return FileName.c_str(); }
47   const char *getFunctionName() { return FunctionName.c_str(); }
48   uint32_t getLine() const { return Line; }
49   uint32_t getColumn() const { return Column; }
50
51   bool operator==(const DILineInfo &RHS) const {
52     return Line == RHS.Line && Column == RHS.Column &&
53            FileName.equals(RHS.FileName) &&
54            FunctionName.equals(RHS.FunctionName);
55   }
56   bool operator!=(const DILineInfo &RHS) const {
57     return !(*this == RHS);
58   }
59 };
60
61 typedef SmallVector<std::pair<uint64_t, DILineInfo>, 16> DILineInfoTable;
62
63 /// DIInliningInfo - a format-neutral container for inlined code description.
64 class DIInliningInfo {
65   SmallVector<DILineInfo, 4> Frames;
66  public:
67   DIInliningInfo() {}
68   DILineInfo getFrame(unsigned Index) const {
69     assert(Index < Frames.size());
70     return Frames[Index];
71   }
72   uint32_t getNumberOfFrames() const {
73     return Frames.size();
74   }
75   void addFrame(const DILineInfo &Frame) {
76     Frames.push_back(Frame);
77   }
78 };
79
80 /// DILineInfoSpecifier - controls which fields of DILineInfo container
81 /// should be filled with data.
82 class DILineInfoSpecifier {
83   const uint32_t Flags;  // Or'ed flags that set the info we want to fetch.
84 public:
85   enum Specification {
86     FileLineInfo = 1 << 0,
87     AbsoluteFilePath = 1 << 1,
88     FunctionName = 1 << 2
89   };
90   // Use file/line info by default.
91   DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
92   bool needs(Specification spec) const {
93     return (Flags & spec) > 0;
94   }
95 };
96
97 /// Selects which debug sections get dumped.
98 enum DIDumpType {
99   DIDT_Null,
100   DIDT_All,
101   DIDT_Abbrev,
102   DIDT_AbbrevDwo,
103   DIDT_Aranges,
104   DIDT_Frames,
105   DIDT_Info,
106   DIDT_InfoDwo,
107   DIDT_Types,
108   DIDT_TypesDwo,
109   DIDT_Line,
110   DIDT_LineDwo,
111   DIDT_Loc,
112   DIDT_Ranges,
113   DIDT_Pubnames,
114   DIDT_Pubtypes,
115   DIDT_GnuPubnames,
116   DIDT_GnuPubtypes,
117   DIDT_Str,
118   DIDT_StrDwo,
119   DIDT_StrOffsetsDwo
120 };
121
122 // In place of applying the relocations to the data we've read from disk we use
123 // a separate mapping table to the side and checking that at locations in the
124 // dwarf where we expect relocated values. This adds a bit of complexity to the
125 // dwarf parsing/extraction at the benefit of not allocating memory for the
126 // entire size of the debug info sections.
127 typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
128
129 class DIContext {
130 public:
131   enum DIContextKind {
132     CK_DWARF
133   };
134   DIContextKind getKind() const { return Kind; }
135
136   DIContext(DIContextKind K) : Kind(K) {}
137   virtual ~DIContext();
138
139   /// getDWARFContext - get a context for binary DWARF data.
140   static DIContext *getDWARFContext(object::ObjectFile *);
141
142   virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
143
144   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
145       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
146   virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
147       uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
148   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
149       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
150 private:
151   const DIContextKind Kind;
152 };
153
154 }
155
156 #endif