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