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 "llvm/DebugInfo/DIContext.h"
15 #include "llvm/ADT/OwningPtr.h"
16 #include "llvm/ADT/SmallVector.h"
20 class DWARFDebugAbbrev;
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;
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 bool isLittleEndian() const { return IsLittleEndian; }
59 virtual StringRef getInfoSection() = 0;
60 virtual StringRef getAbbrevSection() = 0;
61 virtual StringRef getARangeSection() = 0;
62 virtual StringRef getLineSection() = 0;
63 virtual StringRef getStringSection() = 0;
65 static bool isSupportedVersion(unsigned version) {
66 return version == 2 || version == 3;
71 /// DWARFContextInMemory is the simplest possible implementation of a
72 /// DWARFContext. It assumes all content is available in memory and stores
74 class DWARFContextInMemory : public DWARFContext {
75 StringRef InfoSection;
76 StringRef AbbrevSection;
77 StringRef ARangeSection;
78 StringRef LineSection;
79 StringRef StringSection;
81 DWARFContextInMemory(bool isLittleEndian,
82 StringRef infoSection,
83 StringRef abbrevSection,
84 StringRef aRangeSection,
85 StringRef lineSection,
86 StringRef stringSection)
87 : DWARFContext(isLittleEndian),
88 InfoSection(infoSection),
89 AbbrevSection(abbrevSection),
90 ARangeSection(aRangeSection),
91 LineSection(lineSection),
92 StringSection(stringSection)
95 virtual StringRef getInfoSection() { return InfoSection; }
96 virtual StringRef getAbbrevSection() { return AbbrevSection; }
97 virtual StringRef getARangeSection() { return ARangeSection; }
98 virtual StringRef getLineSection() { return LineSection; }
99 virtual StringRef getStringSection() { return StringSection; }