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 "llvm/DebugInfo/DIContext.h"
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/ADT/SmallVector.h"
23 /// This data structure is the top level entity that deals with dwarf debug
24 /// information parsing. The actual data is supplied through pure virtual
25 /// methods that a concrete implementation provides.
26 class DWARFContext : public DIContext {
29 SmallVector<DWARFCompileUnit, 1> CUs;
30 OwningPtr<DWARFDebugAbbrev> Abbrev;
31 OwningPtr<DWARFDebugAranges> Aranges;
32 OwningPtr<DWARFDebugLine> Line;
34 DWARFContext(DWARFContext &); // = delete
35 DWARFContext &operator=(DWARFContext &); // = delete
37 /// Read compile units from the debug_info section and store them in CUs.
38 void parseCompileUnits();
40 DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {}
42 virtual void dump(raw_ostream &OS);
43 /// Get the number of compile units in this context.
44 unsigned getNumCompileUnits() {
49 /// Get the compile unit at the specified index for this compile unit.
50 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
56 /// Get a pointer to the parsed DebugAbbrev object.
57 const DWARFDebugAbbrev *getDebugAbbrev();
59 /// Get a pointer to the parsed DebugAranges object.
60 const DWARFDebugAranges *getDebugAranges();
62 /// Get a pointer to the parsed DWARFDebugLine object.
63 const DWARFDebugLine *getDebugLine();
65 bool isLittleEndian() const { return IsLittleEndian; }
67 virtual StringRef getInfoSection() = 0;
68 virtual StringRef getAbbrevSection() = 0;
69 virtual StringRef getARangeSection() = 0;
70 virtual StringRef getLineSection() = 0;
71 virtual StringRef getStringSection() = 0;
73 static bool isSupportedVersion(unsigned version) {
74 return version == 2 || version == 3;
79 /// DWARFContextInMemory is the simplest possible implementation of a
80 /// DWARFContext. It assumes all content is available in memory and stores
82 class DWARFContextInMemory : public DWARFContext {
83 StringRef InfoSection;
84 StringRef AbbrevSection;
85 StringRef ARangeSection;
86 StringRef LineSection;
87 StringRef StringSection;
89 DWARFContextInMemory(bool isLittleEndian,
90 StringRef infoSection,
91 StringRef abbrevSection,
92 StringRef aRangeSection,
93 StringRef lineSection,
94 StringRef stringSection)
95 : DWARFContext(isLittleEndian),
96 InfoSection(infoSection),
97 AbbrevSection(abbrevSection),
98 ARangeSection(aRangeSection),
99 LineSection(lineSection),
100 StringSection(stringSection)
103 virtual StringRef getInfoSection() { return InfoSection; }
104 virtual StringRef getAbbrevSection() { return AbbrevSection; }
105 virtual StringRef getARangeSection() { return ARangeSection; }
106 virtual StringRef getLineSection() { return LineSection; }
107 virtual StringRef getStringSection() { return StringSection; }