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 "llvm/DebugInfo/DIContext.h"
16 #include "llvm/ADT/OwningPtr.h"
17 #include "llvm/ADT/SmallVector.h"
22 /// This data structure is the top level entity that deals with dwarf debug
23 /// information parsing. The actual data is supplied through pure virtual
24 /// methods that a concrete implementation provides.
25 class DWARFContext : public DIContext {
28 SmallVector<DWARFCompileUnit, 1> CUs;
29 OwningPtr<DWARFDebugAbbrev> Abbrev;
30 OwningPtr<DWARFDebugAranges> Aranges;
32 DWARFContext(DWARFContext &); // = delete
33 DWARFContext &operator=(DWARFContext &); // = delete
35 /// Read compile units from the debug_info section and store them in CUs.
36 void parseCompileUnits();
38 DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {}
40 virtual void dump(raw_ostream &OS);
41 /// Get the number of compile units in this context.
42 unsigned getNumCompileUnits() {
47 /// Get the compile unit at the specified index for this compile unit.
48 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
54 /// Get a pointer to the parsed DebugAbbrev object.
55 const DWARFDebugAbbrev *getDebugAbbrev();
57 /// Get a pointer to the parsed DebugAranges object.
58 const DWARFDebugAranges *getDebugAranges();
60 bool isLittleEndian() const { return IsLittleEndian; }
62 virtual StringRef getInfoSection() = 0;
63 virtual StringRef getAbbrevSection() = 0;
64 virtual StringRef getARangeSection() = 0;
65 virtual StringRef getLineSection() = 0;
66 virtual StringRef getStringSection() = 0;
68 static bool isSupportedVersion(unsigned version) {
69 return version == 2 || version == 3;
74 /// DWARFContextInMemory is the simplest possible implementation of a
75 /// DWARFContext. It assumes all content is available in memory and stores
77 class DWARFContextInMemory : public DWARFContext {
78 StringRef InfoSection;
79 StringRef AbbrevSection;
80 StringRef ARangeSection;
81 StringRef LineSection;
82 StringRef StringSection;
84 DWARFContextInMemory(bool isLittleEndian,
85 StringRef infoSection,
86 StringRef abbrevSection,
87 StringRef aRangeSection,
88 StringRef lineSection,
89 StringRef stringSection)
90 : DWARFContext(isLittleEndian),
91 InfoSection(infoSection),
92 AbbrevSection(abbrevSection),
93 ARangeSection(aRangeSection),
94 LineSection(lineSection),
95 StringSection(stringSection)
98 virtual StringRef getInfoSection() { return InfoSection; }
99 virtual StringRef getAbbrevSection() { return AbbrevSection; }
100 virtual StringRef getARangeSection() { return ARangeSection; }
101 virtual StringRef getLineSection() { return LineSection; }
102 virtual StringRef getStringSection() { return StringSection; }