Add command-line flags for DWARF dumping.
[oota-llvm.git] / lib / DebugInfo / DWARFContext.h
1 //===-- DWARFContext.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 #ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H
11 #define LLVM_DEBUGINFO_DWARFCONTEXT_H
12
13 #include "DWARFCompileUnit.h"
14 #include "DWARFDebugAranges.h"
15 #include "DWARFDebugLine.h"
16 #include "DWARFDebugRangeList.h"
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/DebugInfo/DIContext.h"
20
21 namespace llvm {
22
23 /// DWARFContext
24 /// This data structure is the top level entity that deals with dwarf debug
25 /// information parsing. The actual data is supplied through pure virtual
26 /// methods that a concrete implementation provides.
27 class DWARFContext : public DIContext {
28   SmallVector<DWARFCompileUnit, 1> CUs;
29   OwningPtr<DWARFDebugAbbrev> Abbrev;
30   OwningPtr<DWARFDebugAranges> Aranges;
31   OwningPtr<DWARFDebugLine> Line;
32
33   SmallVector<DWARFCompileUnit, 1> DWOCUs;
34   OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
35
36   DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
37   DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
38
39   /// Read compile units from the debug_info section and store them in CUs.
40   void parseCompileUnits();
41
42   /// Read compile units from the debug_info.dwo section and store them in
43   /// DWOCUs.
44   void parseDWOCompileUnits();
45
46 public:
47   DWARFContext() {}
48   virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
49
50   /// Get the number of compile units in this context.
51   unsigned getNumCompileUnits() {
52     if (CUs.empty())
53       parseCompileUnits();
54     return CUs.size();
55   }
56
57   /// Get the number of compile units in the DWO context.
58   unsigned getNumDWOCompileUnits() {
59     if (DWOCUs.empty())
60       parseDWOCompileUnits();
61     return DWOCUs.size();
62   }
63
64   /// Get the compile unit at the specified index for this compile unit.
65   DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
66     if (CUs.empty())
67       parseCompileUnits();
68     return &CUs[index];
69   }
70
71   /// Get the compile unit at the specified index for the DWO compile units.
72   DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
73     if (DWOCUs.empty())
74       parseDWOCompileUnits();
75     return &DWOCUs[index];
76   }
77
78   /// Get a pointer to the parsed DebugAbbrev object.
79   const DWARFDebugAbbrev *getDebugAbbrev();
80
81   /// Get a pointer to the parsed dwo abbreviations object.
82   const DWARFDebugAbbrev *getDebugAbbrevDWO();
83
84   /// Get a pointer to the parsed DebugAranges object.
85   const DWARFDebugAranges *getDebugAranges();
86
87   /// Get a pointer to a parsed line table corresponding to a compile unit.
88   const DWARFDebugLine::LineTable *
89   getLineTableForCompileUnit(DWARFCompileUnit *cu);
90
91   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
92       DILineInfoSpecifier Specifier = DILineInfoSpecifier());
93   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
94       DILineInfoSpecifier Specifier = DILineInfoSpecifier());
95
96   virtual bool isLittleEndian() const = 0;
97   virtual const RelocAddrMap &infoRelocMap() const = 0;
98   virtual StringRef getInfoSection() = 0;
99   virtual StringRef getAbbrevSection() = 0;
100   virtual StringRef getARangeSection() = 0;
101   virtual StringRef getLineSection() = 0;
102   virtual StringRef getStringSection() = 0;
103   virtual StringRef getRangeSection() = 0;
104
105   // Sections for DWARF5 split dwarf proposal.
106   virtual StringRef getInfoDWOSection() = 0;
107   virtual StringRef getAbbrevDWOSection() = 0;
108   virtual StringRef getStringDWOSection() = 0;
109   virtual StringRef getStringOffsetDWOSection() = 0;
110   virtual StringRef getRangeDWOSection() = 0;
111   virtual StringRef getAddrSection() = 0;
112   virtual const RelocAddrMap &infoDWORelocMap() const = 0;
113
114   static bool isSupportedVersion(unsigned version) {
115     return version == 2 || version == 3;
116   }
117 private:
118   /// Return the compile unit that includes an offset (relative to .debug_info).
119   DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
120
121   /// Return the compile unit which contains instruction with provided
122   /// address.
123   DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
124 };
125
126 /// DWARFContextInMemory is the simplest possible implementation of a
127 /// DWARFContext. It assumes all content is available in memory and stores
128 /// pointers to it.
129 class DWARFContextInMemory : public DWARFContext {
130   virtual void anchor();
131   bool IsLittleEndian;
132   RelocAddrMap InfoRelocMap;
133   StringRef InfoSection;
134   StringRef AbbrevSection;
135   StringRef ARangeSection;
136   StringRef LineSection;
137   StringRef StringSection;
138   StringRef RangeSection;
139
140   // Sections for DWARF5 split dwarf proposal.
141   RelocAddrMap InfoDWORelocMap;
142   StringRef InfoDWOSection;
143   StringRef AbbrevDWOSection;
144   StringRef StringDWOSection;
145   StringRef StringOffsetDWOSection;
146   StringRef RangeDWOSection;
147   StringRef AddrSection;
148
149 public:
150   DWARFContextInMemory(object::ObjectFile *);
151   virtual bool isLittleEndian() const { return IsLittleEndian; }
152   virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; }
153   virtual StringRef getInfoSection() { return InfoSection; }
154   virtual StringRef getAbbrevSection() { return AbbrevSection; }
155   virtual StringRef getARangeSection() { return ARangeSection; }
156   virtual StringRef getLineSection() { return LineSection; }
157   virtual StringRef getStringSection() { return StringSection; }
158   virtual StringRef getRangeSection() { return RangeSection; }
159
160   // Sections for DWARF5 split dwarf proposal.
161   virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
162   virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
163   virtual StringRef getStringDWOSection() { return StringDWOSection; }
164   virtual StringRef getStringOffsetDWOSection() {
165     return StringOffsetDWOSection;
166   }
167   virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
168   virtual StringRef getAddrSection() {
169     return AddrSection;
170   }
171   virtual const RelocAddrMap &infoDWORelocMap() const {
172     return InfoDWORelocMap;
173   }
174 };
175
176 }
177
178 #endif