• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "llvm/DebugInfo/DIContext.h"
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/ADT/SmallVector.h"
19 
20 namespace llvm {
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   OwningPtr<DWARFDebugAranges> Aranges;
32   OwningPtr<DWARFDebugLine> Line;
33 
34   DWARFContext(DWARFContext &); // = delete
35   DWARFContext &operator=(DWARFContext &); // = delete
36 
37   /// Read compile units from the debug_info section and store them in CUs.
38   void parseCompileUnits();
39 protected:
DWARFContext(bool isLittleEndian)40   DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {}
41 public:
42   virtual void dump(raw_ostream &OS);
43   /// Get the number of compile units in this context.
getNumCompileUnits()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.
getCompileUnitAtIndex(unsigned index)50   DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
51     if (CUs.empty())
52       parseCompileUnits();
53     return &CUs[index];
54   }
55 
56   /// Return the compile unit that includes an offset (relative to .debug_info).
57   DWARFCompileUnit *getCompileUnitForOffset(uint32_t offset);
58 
59   /// Get a pointer to the parsed DebugAbbrev object.
60   const DWARFDebugAbbrev *getDebugAbbrev();
61 
62   /// Get a pointer to the parsed DebugAranges object.
63   const DWARFDebugAranges *getDebugAranges();
64 
65   /// Get a pointer to a parsed line table corresponding to a compile unit.
66   const DWARFDebugLine::LineTable *
67   getLineTableForCompileUnit(DWARFCompileUnit *cu);
68 
69   virtual DILineInfo getLineInfoForAddress(uint64_t address);
70 
isLittleEndian()71   bool isLittleEndian() const { return IsLittleEndian; }
72 
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 
isSupportedVersion(unsigned version)79   static bool isSupportedVersion(unsigned version) {
80     return version == 2 || version == 3;
81   }
82 };
83 
84 
85 /// DWARFContextInMemory is the simplest possible implementation of a
86 /// DWARFContext. It assumes all content is available in memory and stores
87 /// pointers to it.
88 class DWARFContextInMemory : public DWARFContext {
89   StringRef InfoSection;
90   StringRef AbbrevSection;
91   StringRef ARangeSection;
92   StringRef LineSection;
93   StringRef StringSection;
94 public:
DWARFContextInMemory(bool isLittleEndian,StringRef infoSection,StringRef abbrevSection,StringRef aRangeSection,StringRef lineSection,StringRef stringSection)95   DWARFContextInMemory(bool isLittleEndian,
96                        StringRef infoSection,
97                        StringRef abbrevSection,
98                        StringRef aRangeSection,
99                        StringRef lineSection,
100                        StringRef stringSection)
101     : DWARFContext(isLittleEndian),
102       InfoSection(infoSection),
103       AbbrevSection(abbrevSection),
104       ARangeSection(aRangeSection),
105       LineSection(lineSection),
106       StringSection(stringSection)
107     {}
108 
getInfoSection()109   virtual StringRef getInfoSection() { return InfoSection; }
getAbbrevSection()110   virtual StringRef getAbbrevSection() { return AbbrevSection; }
getARangeSection()111   virtual StringRef getARangeSection() { return ARangeSection; }
getLineSection()112   virtual StringRef getLineSection() { return LineSection; }
getStringSection()113   virtual StringRef getStringSection() { return StringSection; }
114 };
115 
116 }
117 
118 #endif
119