1a70f3feef916f32193690c565bd925e1f375605
[oota-llvm.git] / lib / DebugInfo / DWARFContext.h
1 //===-- DWARFContext.h ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===/
9
10 #ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H
11 #define LLVM_DEBUGINFO_DWARFCONTEXT_H
12
13 #include "DWARFCompileUnit.h"
14 #include "llvm/DebugInfo/DIContext.h"
15 #include "llvm/ADT/OwningPtr.h"
16 #include "llvm/ADT/SmallVector.h"
17
18 namespace llvm {
19
20 class DWARFDebugAbbrev;
21
22 /// DWARFContext
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 {
27   bool IsLittleEndian;
28
29   SmallVector<DWARFCompileUnit, 1> CUs;
30   OwningPtr<DWARFDebugAbbrev> Abbrev;
31
32   DWARFContext(DWARFContext &); // = delete
33   DWARFContext &operator=(DWARFContext &); // = delete
34
35   /// Read compile units from the debug_info section and store them in CUs.
36   void parseCompileUnits();
37 protected:
38   DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {}
39 public:
40   virtual void dump(raw_ostream &OS);
41   /// Get the number of compile units in this context.
42   unsigned getNumCompileUnits() {
43     if (CUs.empty())
44       parseCompileUnits();
45     return CUs.size();
46   }
47   /// Get the compile unit at the specified index for this compile unit.
48   DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
49     if (CUs.empty())
50       parseCompileUnits();
51     return &CUs[index];
52   }
53
54   /// Get a pointer to the parsed DebugAbbrev object.
55   const DWARFDebugAbbrev *getDebugAbbrev();
56
57   bool isLittleEndian() const { return IsLittleEndian; }
58
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;
64
65   static bool isSupportedVersion(unsigned version) {
66     return version == 2 || version == 3;
67   }
68 };
69
70
71 /// DWARFContextInMemory is the simplest possible implementation of a
72 /// DWARFContext. It assumes all content is available in memory and stores
73 /// pointers to it.
74 class DWARFContextInMemory : public DWARFContext {
75   StringRef InfoSection;
76   StringRef AbbrevSection;
77   StringRef ARangeSection;
78   StringRef LineSection;
79   StringRef StringSection;
80 public:
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)
93     {}
94
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; }
100 };
101
102 }
103
104 #endif