1 //===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===/
10 #ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H
11 #define LLVM_DEBUGINFO_DWARFCONTEXT_H
13 #include "DWARFCompileUnit.h"
14 #include "DWARFDebugAranges.h"
15 #include "DWARFDebugLine.h"
16 #include "DWARFDebugRangeList.h"
17 #include "llvm/DebugInfo/DIContext.h"
18 #include "llvm/ADT/OwningPtr.h"
19 #include "llvm/ADT/SmallVector.h"
24 /// This data structure is the top level entity that deals with dwarf debug
25 /// information parsing. The actual data is supplied through pure virtual
26 /// methods that a concrete implementation provides.
27 class DWARFContext : public DIContext {
29 const RelocAddrMap *RelocMap;
31 SmallVector<DWARFCompileUnit, 1> CUs;
32 OwningPtr<DWARFDebugAbbrev> Abbrev;
33 OwningPtr<DWARFDebugAranges> Aranges;
34 OwningPtr<DWARFDebugLine> Line;
36 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
37 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
39 /// Read compile units from the debug_info section and store them in CUs.
40 void parseCompileUnits();
42 DWARFContext(bool isLittleEndian, const RelocAddrMap *Map) :
43 IsLittleEndian(isLittleEndian), RelocMap(Map) {}
45 virtual void dump(raw_ostream &OS);
47 /// Get the number of compile units in this context.
48 unsigned getNumCompileUnits() {
53 /// Get the compile unit at the specified index for this compile unit.
54 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
60 /// Get a pointer to the parsed DebugAbbrev object.
61 const DWARFDebugAbbrev *getDebugAbbrev();
63 /// Get a pointer to the parsed DebugAranges object.
64 const DWARFDebugAranges *getDebugAranges();
66 /// Get a pointer to a parsed line table corresponding to a compile unit.
67 const DWARFDebugLine::LineTable *
68 getLineTableForCompileUnit(DWARFCompileUnit *cu);
70 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
71 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
72 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
73 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
75 bool isLittleEndian() const { return IsLittleEndian; }
76 const RelocAddrMap *relocMap() const { return RelocMap; }
78 virtual StringRef getInfoSection() = 0;
79 virtual StringRef getAbbrevSection() = 0;
80 virtual StringRef getARangeSection() = 0;
81 virtual StringRef getLineSection() = 0;
82 virtual StringRef getStringSection() = 0;
83 virtual StringRef getRangeSection() = 0;
85 static bool isSupportedVersion(unsigned version) {
86 return version == 2 || version == 3;
89 /// Return the compile unit that includes an offset (relative to .debug_info).
90 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
92 /// Return the compile unit which contains instruction with provided
94 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
97 /// DWARFContextInMemory is the simplest possible implementation of a
98 /// DWARFContext. It assumes all content is available in memory and stores
100 class DWARFContextInMemory : public DWARFContext {
101 virtual void anchor();
102 StringRef InfoSection;
103 StringRef AbbrevSection;
104 StringRef ARangeSection;
105 StringRef LineSection;
106 StringRef StringSection;
107 StringRef RangeSection;
109 DWARFContextInMemory(bool isLittleEndian,
110 StringRef infoSection,
111 StringRef abbrevSection,
112 StringRef aRangeSection,
113 StringRef lineSection,
114 StringRef stringSection,
115 StringRef rangeSection,
116 const RelocAddrMap *Map = 0)
117 : DWARFContext(isLittleEndian, Map),
118 InfoSection(infoSection),
119 AbbrevSection(abbrevSection),
120 ARangeSection(aRangeSection),
121 LineSection(lineSection),
122 StringSection(stringSection),
123 RangeSection(rangeSection)
126 virtual StringRef getInfoSection() { return InfoSection; }
127 virtual StringRef getAbbrevSection() { return AbbrevSection; }
128 virtual StringRef getARangeSection() { return ARangeSection; }
129 virtual StringRef getLineSection() { return LineSection; }
130 virtual StringRef getStringSection() { return StringSection; }
131 virtual StringRef getRangeSection() { return RangeSection; }