ARM IAS: support .personalityindex
[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 "DWARFDebugFrame.h"
16 #include "DWARFDebugLine.h"
17 #include "DWARFDebugLoc.h"
18 #include "DWARFDebugRangeList.h"
19 #include "DWARFTypeUnit.h"
20 #include "llvm/ADT/MapVector.h"
21 #include "llvm/ADT/OwningPtr.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/DebugInfo/DIContext.h"
24
25 namespace llvm {
26
27 /// DWARFContext
28 /// This data structure is the top level entity that deals with dwarf debug
29 /// information parsing. The actual data is supplied through pure virtual
30 /// methods that a concrete implementation provides.
31 class DWARFContext : public DIContext {
32   SmallVector<DWARFCompileUnit *, 1> CUs;
33   SmallVector<DWARFTypeUnit *, 1> TUs;
34   OwningPtr<DWARFDebugAbbrev> Abbrev;
35   OwningPtr<DWARFDebugLoc> Loc;
36   OwningPtr<DWARFDebugAranges> Aranges;
37   OwningPtr<DWARFDebugLine> Line;
38   OwningPtr<DWARFDebugFrame> DebugFrame;
39
40   SmallVector<DWARFCompileUnit *, 1> DWOCUs;
41   SmallVector<DWARFTypeUnit *, 1> DWOTUs;
42   OwningPtr<DWARFDebugAbbrev> AbbrevDWO;
43
44   DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
45   DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
46
47   /// Read compile units from the debug_info section and store them in CUs.
48   void parseCompileUnits();
49
50   /// Read type units from the debug_types sections and store them in CUs.
51   void parseTypeUnits();
52
53   /// Read compile units from the debug_info.dwo section and store them in
54   /// DWOCUs.
55   void parseDWOCompileUnits();
56
57   /// Read type units from the debug_types.dwo section and store them in
58   /// DWOTUs.
59   void parseDWOTypeUnits();
60
61 public:
62   struct Section {
63     StringRef Data;
64     RelocAddrMap Relocs;
65   };
66
67   DWARFContext() : DIContext(CK_DWARF) {}
68   virtual ~DWARFContext();
69
70   static bool classof(const DIContext *DICtx) {
71     return DICtx->getKind() == CK_DWARF;
72   }
73
74   virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All);
75
76   /// Get the number of compile units in this context.
77   unsigned getNumCompileUnits() {
78     if (CUs.empty())
79       parseCompileUnits();
80     return CUs.size();
81   }
82
83   /// Get the number of compile units in this context.
84   unsigned getNumTypeUnits() {
85     if (TUs.empty())
86       parseTypeUnits();
87     return TUs.size();
88   }
89
90   /// Get the number of compile units in the DWO context.
91   unsigned getNumDWOCompileUnits() {
92     if (DWOCUs.empty())
93       parseDWOCompileUnits();
94     return DWOCUs.size();
95   }
96
97   /// Get the number of compile units in the DWO context.
98   unsigned getNumDWOTypeUnits() {
99     if (DWOTUs.empty())
100       parseDWOTypeUnits();
101     return DWOTUs.size();
102   }
103
104   /// Get the compile unit at the specified index for this compile unit.
105   DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
106     if (CUs.empty())
107       parseCompileUnits();
108     return CUs[index];
109   }
110
111   /// Get the type unit at the specified index for this compile unit.
112   DWARFTypeUnit *getTypeUnitAtIndex(unsigned index) {
113     if (TUs.empty())
114       parseTypeUnits();
115     return TUs[index];
116   }
117
118   /// Get the compile unit at the specified index for the DWO compile units.
119   DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
120     if (DWOCUs.empty())
121       parseDWOCompileUnits();
122     return DWOCUs[index];
123   }
124
125   /// Get the type unit at the specified index for the DWO type units.
126   DWARFTypeUnit *getDWOTypeUnitAtIndex(unsigned index) {
127     if (DWOTUs.empty())
128       parseDWOTypeUnits();
129     return DWOTUs[index];
130   }
131
132   /// Get a pointer to the parsed DebugAbbrev object.
133   const DWARFDebugAbbrev *getDebugAbbrev();
134
135   /// Get a pointer to the parsed DebugLoc object.
136   const DWARFDebugLoc *getDebugLoc();
137
138   /// Get a pointer to the parsed dwo abbreviations object.
139   const DWARFDebugAbbrev *getDebugAbbrevDWO();
140
141   /// Get a pointer to the parsed DebugAranges object.
142   const DWARFDebugAranges *getDebugAranges();
143
144   /// Get a pointer to the parsed frame information object.
145   const DWARFDebugFrame *getDebugFrame();
146
147   /// Get a pointer to a parsed line table corresponding to a compile unit.
148   const DWARFDebugLine::LineTable *
149   getLineTableForCompileUnit(DWARFCompileUnit *cu);
150
151   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
152       DILineInfoSpecifier Specifier = DILineInfoSpecifier());
153   virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
154       uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier());
155   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
156       DILineInfoSpecifier Specifier = DILineInfoSpecifier());
157
158   virtual bool isLittleEndian() const = 0;
159   virtual uint8_t getAddressSize() const = 0;
160   virtual const Section &getInfoSection() = 0;
161   typedef MapVector<object::SectionRef, Section,
162                     std::map<object::SectionRef, unsigned> > TypeSectionMap;
163   virtual const TypeSectionMap &getTypesSections() = 0;
164   virtual StringRef getAbbrevSection() = 0;
165   virtual const Section &getLocSection() = 0;
166   virtual StringRef getARangeSection() = 0;
167   virtual StringRef getDebugFrameSection() = 0;
168   virtual const Section &getLineSection() = 0;
169   virtual StringRef getStringSection() = 0;
170   virtual StringRef getRangeSection() = 0;
171   virtual StringRef getPubNamesSection() = 0;
172   virtual StringRef getPubTypesSection() = 0;
173   virtual StringRef getGnuPubNamesSection() = 0;
174   virtual StringRef getGnuPubTypesSection() = 0;
175
176   // Sections for DWARF5 split dwarf proposal.
177   virtual const Section &getInfoDWOSection() = 0;
178   virtual const TypeSectionMap &getTypesDWOSections() = 0;
179   virtual StringRef getAbbrevDWOSection() = 0;
180   virtual StringRef getStringDWOSection() = 0;
181   virtual StringRef getStringOffsetDWOSection() = 0;
182   virtual StringRef getRangeDWOSection() = 0;
183   virtual StringRef getAddrSection() = 0;
184
185   static bool isSupportedVersion(unsigned version) {
186     return version == 2 || version == 3 || version == 4;
187   }
188 private:
189   /// Return the compile unit that includes an offset (relative to .debug_info).
190   DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
191
192   /// Return the compile unit which contains instruction with provided
193   /// address.
194   DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
195 };
196
197 /// DWARFContextInMemory is the simplest possible implementation of a
198 /// DWARFContext. It assumes all content is available in memory and stores
199 /// pointers to it.
200 class DWARFContextInMemory : public DWARFContext {
201   virtual void anchor();
202   bool IsLittleEndian;
203   uint8_t AddressSize;
204   Section InfoSection;
205   TypeSectionMap TypesSections;
206   StringRef AbbrevSection;
207   Section LocSection;
208   StringRef ARangeSection;
209   StringRef DebugFrameSection;
210   Section LineSection;
211   StringRef StringSection;
212   StringRef RangeSection;
213   StringRef PubNamesSection;
214   StringRef PubTypesSection;
215   StringRef GnuPubNamesSection;
216   StringRef GnuPubTypesSection;
217
218   // Sections for DWARF5 split dwarf proposal.
219   Section InfoDWOSection;
220   TypeSectionMap TypesDWOSections;
221   StringRef AbbrevDWOSection;
222   StringRef StringDWOSection;
223   StringRef StringOffsetDWOSection;
224   StringRef RangeDWOSection;
225   StringRef AddrSection;
226
227   SmallVector<MemoryBuffer*, 4> UncompressedSections;
228
229 public:
230   DWARFContextInMemory(object::ObjectFile *);
231   ~DWARFContextInMemory();
232   virtual bool isLittleEndian() const { return IsLittleEndian; }
233   virtual uint8_t getAddressSize() const { return AddressSize; }
234   virtual const Section &getInfoSection() { return InfoSection; }
235   virtual const TypeSectionMap &getTypesSections() { return TypesSections; }
236   virtual StringRef getAbbrevSection() { return AbbrevSection; }
237   virtual const Section &getLocSection() { return LocSection; }
238   virtual StringRef getARangeSection() { return ARangeSection; }
239   virtual StringRef getDebugFrameSection() { return DebugFrameSection; }
240   virtual const Section &getLineSection() { return LineSection; }
241   virtual StringRef getStringSection() { return StringSection; }
242   virtual StringRef getRangeSection() { return RangeSection; }
243   virtual StringRef getPubNamesSection() { return PubNamesSection; }
244   virtual StringRef getPubTypesSection() { return PubTypesSection; }
245   virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
246   virtual StringRef getGnuPubTypesSection() { return GnuPubTypesSection; }
247
248   // Sections for DWARF5 split dwarf proposal.
249   virtual const Section &getInfoDWOSection() { return InfoDWOSection; }
250   virtual const TypeSectionMap &getTypesDWOSections() {
251     return TypesDWOSections;
252   }
253   virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; }
254   virtual StringRef getStringDWOSection() { return StringDWOSection; }
255   virtual StringRef getStringOffsetDWOSection() {
256     return StringOffsetDWOSection;
257   }
258   virtual StringRef getRangeDWOSection() { return RangeDWOSection; }
259   virtual StringRef getAddrSection() {
260     return AddrSection;
261   }
262 };
263
264 }
265
266 #endif