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