ff161e2aadd2ec4b7eee89d4cafeba29bb30e541
[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 "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"
20
21 namespace llvm {
22
23 /// DWARFContext
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 {
28   SmallVector<DWARFCompileUnit, 1> CUs;
29   OwningPtr<DWARFDebugAbbrev> Abbrev;
30   OwningPtr<DWARFDebugAranges> Aranges;
31   OwningPtr<DWARFDebugLine> Line;
32
33   DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
34   DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
35
36   /// Read compile units from the debug_info section and store them in CUs.
37   void parseCompileUnits();
38
39 public:
40   DWARFContext() {}
41   virtual void dump(raw_ostream &OS);
42
43   /// Get the number of compile units in this context.
44   unsigned getNumCompileUnits() {
45     if (CUs.empty())
46       parseCompileUnits();
47     return CUs.size();
48   }
49   /// Get the compile unit at the specified index for this compile unit.
50   DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
51     if (CUs.empty())
52       parseCompileUnits();
53     return &CUs[index];
54   }
55
56   /// Get a pointer to the parsed DebugAbbrev object.
57   const DWARFDebugAbbrev *getDebugAbbrev();
58
59   /// Get a pointer to the parsed DebugAranges object.
60   const DWARFDebugAranges *getDebugAranges();
61
62   /// Get a pointer to a parsed line table corresponding to a compile unit.
63   const DWARFDebugLine::LineTable *
64   getLineTableForCompileUnit(DWARFCompileUnit *cu);
65
66   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
67       DILineInfoSpecifier Specifier = DILineInfoSpecifier());
68   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
69       DILineInfoSpecifier Specifier = DILineInfoSpecifier());
70
71   virtual bool isLittleEndian() const = 0;
72   virtual const RelocAddrMap &relocMap() const = 0;
73   virtual StringRef getInfoSection() = 0;
74   virtual StringRef getAbbrevSection() = 0;
75   virtual StringRef getARangeSection() = 0;
76   virtual StringRef getLineSection() = 0;
77   virtual StringRef getStringSection() = 0;
78   virtual StringRef getRangeSection() = 0;
79
80   static bool isSupportedVersion(unsigned version) {
81     return version == 2 || version == 3;
82   }
83 private:
84   /// Return the compile unit that includes an offset (relative to .debug_info).
85   DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
86
87   /// Return the compile unit which contains instruction with provided
88   /// address.
89   DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
90 };
91
92 /// DWARFContextInMemory is the simplest possible implementation of a
93 /// DWARFContext. It assumes all content is available in memory and stores
94 /// pointers to it.
95 class DWARFContextInMemory : public DWARFContext {
96   virtual void anchor();
97   bool IsLittleEndian;
98   RelocAddrMap RelocMap;
99   StringRef InfoSection;
100   StringRef AbbrevSection;
101   StringRef ARangeSection;
102   StringRef LineSection;
103   StringRef StringSection;
104   StringRef RangeSection;
105 public:
106   DWARFContextInMemory(object::ObjectFile *);
107   virtual bool isLittleEndian() const { return IsLittleEndian; }
108   virtual const RelocAddrMap &relocMap() const { return RelocMap; }
109   virtual StringRef getInfoSection() { return InfoSection; }
110   virtual StringRef getAbbrevSection() { return AbbrevSection; }
111   virtual StringRef getARangeSection() { return ARangeSection; }
112   virtual StringRef getLineSection() { return LineSection; }
113   virtual StringRef getStringSection() { return StringSection; }
114   virtual StringRef getRangeSection() { return RangeSection; }
115 };
116
117 }
118
119 #endif