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 {
30 SmallVector<DWARFCompileUnit, 1> CUs;
31 OwningPtr<DWARFDebugAbbrev> Abbrev;
32 OwningPtr<DWARFDebugAranges> Aranges;
33 OwningPtr<DWARFDebugLine> Line;
35 DWARFContext(DWARFContext &); // = delete
36 DWARFContext &operator=(DWARFContext &); // = delete
38 /// Read compile units from the debug_info section and store them in CUs.
39 void parseCompileUnits();
41 DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {}
43 virtual void dump(raw_ostream &OS);
44 /// Get the number of compile units in this context.
45 unsigned getNumCompileUnits() {
50 /// Get the compile unit at the specified index for this compile unit.
51 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
57 /// Get a pointer to the parsed DebugAbbrev object.
58 const DWARFDebugAbbrev *getDebugAbbrev();
60 /// Get a pointer to the parsed DebugAranges object.
61 const DWARFDebugAranges *getDebugAranges();
63 /// Get a pointer to a parsed line table corresponding to a compile unit.
64 const DWARFDebugLine::LineTable *
65 getLineTableForCompileUnit(DWARFCompileUnit *cu);
67 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
68 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
70 bool isLittleEndian() const { return IsLittleEndian; }
72 virtual StringRef getInfoSection() = 0;
73 virtual StringRef getAbbrevSection() = 0;
74 virtual StringRef getARangeSection() = 0;
75 virtual StringRef getLineSection() = 0;
76 virtual StringRef getStringSection() = 0;
77 virtual StringRef getRangeSection() = 0;
79 static bool isSupportedVersion(unsigned version) {
80 return version == 2 || version == 3;
83 /// Return the compile unit that includes an offset (relative to .debug_info).
84 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
86 /// Return the compile unit which contains instruction with provided
88 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
90 /// Fetches filename, line and column number for given address and
91 /// compile unit. Returns true on success.
92 bool getFileLineInfoForCompileUnit(DWARFCompileUnit *CU,
94 bool NeedsAbsoluteFilePath,
95 std::string &FileName,
96 uint32_t &Line, uint32_t &Column);
99 /// DWARFContextInMemory is the simplest possible implementation of a
100 /// DWARFContext. It assumes all content is available in memory and stores
102 class DWARFContextInMemory : public DWARFContext {
103 virtual void anchor();
104 StringRef InfoSection;
105 StringRef AbbrevSection;
106 StringRef ARangeSection;
107 StringRef LineSection;
108 StringRef StringSection;
109 StringRef RangeSection;
111 DWARFContextInMemory(bool isLittleEndian,
112 StringRef infoSection,
113 StringRef abbrevSection,
114 StringRef aRangeSection,
115 StringRef lineSection,
116 StringRef stringSection,
117 StringRef rangeSection)
118 : DWARFContext(isLittleEndian),
119 InfoSection(infoSection),
120 AbbrevSection(abbrevSection),
121 ARangeSection(aRangeSection),
122 LineSection(lineSection),
123 StringSection(stringSection),
124 RangeSection(rangeSection)
127 virtual StringRef getInfoSection() { return InfoSection; }
128 virtual StringRef getAbbrevSection() { return AbbrevSection; }
129 virtual StringRef getARangeSection() { return ARangeSection; }
130 virtual StringRef getLineSection() { return LineSection; }
131 virtual StringRef getStringSection() { return StringSection; }
132 virtual StringRef getRangeSection() { return RangeSection; }