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