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