LLVM API Documentation

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