DWARFContext.h revision 251662
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 "DWARFDebugFrame.h" 16#include "DWARFDebugLine.h" 17#include "DWARFDebugRangeList.h" 18#include "llvm/ADT/OwningPtr.h" 19#include "llvm/ADT/SmallVector.h" 20#include "llvm/DebugInfo/DIContext.h" 21 22namespace llvm { 23 24/// DWARFContext 25/// This data structure is the top level entity that deals with dwarf debug 26/// information parsing. The actual data is supplied through pure virtual 27/// methods that a concrete implementation provides. 28class DWARFContext : public DIContext { 29 SmallVector<DWARFCompileUnit, 1> CUs; 30 OwningPtr<DWARFDebugAbbrev> Abbrev; 31 OwningPtr<DWARFDebugAranges> Aranges; 32 OwningPtr<DWARFDebugLine> Line; 33 OwningPtr<DWARFDebugFrame> DebugFrame; 34 35 SmallVector<DWARFCompileUnit, 1> DWOCUs; 36 OwningPtr<DWARFDebugAbbrev> AbbrevDWO; 37 38 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION; 39 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION; 40 41 /// Read compile units from the debug_info section and store them in CUs. 42 void parseCompileUnits(); 43 44 /// Read compile units from the debug_info.dwo section and store them in 45 /// DWOCUs. 46 void parseDWOCompileUnits(); 47 48public: 49 DWARFContext() {} 50 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All); 51 52 /// Get the number of compile units in this context. 53 unsigned getNumCompileUnits() { 54 if (CUs.empty()) 55 parseCompileUnits(); 56 return CUs.size(); 57 } 58 59 /// Get the number of compile units in the DWO context. 60 unsigned getNumDWOCompileUnits() { 61 if (DWOCUs.empty()) 62 parseDWOCompileUnits(); 63 return DWOCUs.size(); 64 } 65 66 /// Get the compile unit at the specified index for this compile unit. 67 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { 68 if (CUs.empty()) 69 parseCompileUnits(); 70 return &CUs[index]; 71 } 72 73 /// Get the compile unit at the specified index for the DWO compile units. 74 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { 75 if (DWOCUs.empty()) 76 parseDWOCompileUnits(); 77 return &DWOCUs[index]; 78 } 79 80 /// Get a pointer to the parsed DebugAbbrev object. 81 const DWARFDebugAbbrev *getDebugAbbrev(); 82 83 /// Get a pointer to the parsed dwo abbreviations object. 84 const DWARFDebugAbbrev *getDebugAbbrevDWO(); 85 86 /// Get a pointer to the parsed DebugAranges object. 87 const DWARFDebugAranges *getDebugAranges(); 88 89 /// Get a pointer to the parsed frame information object. 90 const DWARFDebugFrame *getDebugFrame(); 91 92 /// Get a pointer to a parsed line table corresponding to a compile unit. 93 const DWARFDebugLine::LineTable * 94 getLineTableForCompileUnit(DWARFCompileUnit *cu); 95 96 virtual DILineInfo getLineInfoForAddress(uint64_t Address, 97 DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 98 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, 99 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 100 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, 101 DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 102 103 virtual bool isLittleEndian() const = 0; 104 virtual uint8_t getAddressSize() const = 0; 105 virtual const RelocAddrMap &infoRelocMap() const = 0; 106 virtual const RelocAddrMap &lineRelocMap() const = 0; 107 virtual StringRef getInfoSection() = 0; 108 virtual StringRef getAbbrevSection() = 0; 109 virtual StringRef getARangeSection() = 0; 110 virtual StringRef getDebugFrameSection() = 0; 111 virtual StringRef getLineSection() = 0; 112 virtual StringRef getStringSection() = 0; 113 virtual StringRef getRangeSection() = 0; 114 virtual StringRef getPubNamesSection() = 0; 115 116 // Sections for DWARF5 split dwarf proposal. 117 virtual StringRef getInfoDWOSection() = 0; 118 virtual StringRef getAbbrevDWOSection() = 0; 119 virtual StringRef getStringDWOSection() = 0; 120 virtual StringRef getStringOffsetDWOSection() = 0; 121 virtual StringRef getRangeDWOSection() = 0; 122 virtual StringRef getAddrSection() = 0; 123 virtual const RelocAddrMap &infoDWORelocMap() const = 0; 124 125 static bool isSupportedVersion(unsigned version) { 126 return version == 2 || version == 3; 127 } 128private: 129 /// Return the compile unit that includes an offset (relative to .debug_info). 130 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset); 131 132 /// Return the compile unit which contains instruction with provided 133 /// address. 134 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); 135}; 136 137/// DWARFContextInMemory is the simplest possible implementation of a 138/// DWARFContext. It assumes all content is available in memory and stores 139/// pointers to it. 140class DWARFContextInMemory : public DWARFContext { 141 virtual void anchor(); 142 bool IsLittleEndian; 143 uint8_t AddressSize; 144 RelocAddrMap InfoRelocMap; 145 RelocAddrMap LineRelocMap; 146 StringRef InfoSection; 147 StringRef AbbrevSection; 148 StringRef ARangeSection; 149 StringRef DebugFrameSection; 150 StringRef LineSection; 151 StringRef StringSection; 152 StringRef RangeSection; 153 StringRef PubNamesSection; 154 155 // Sections for DWARF5 split dwarf proposal. 156 RelocAddrMap InfoDWORelocMap; 157 StringRef InfoDWOSection; 158 StringRef AbbrevDWOSection; 159 StringRef StringDWOSection; 160 StringRef StringOffsetDWOSection; 161 StringRef RangeDWOSection; 162 StringRef AddrSection; 163 164 SmallVector<MemoryBuffer*, 4> UncompressedSections; 165 166public: 167 DWARFContextInMemory(object::ObjectFile *); 168 ~DWARFContextInMemory(); 169 virtual bool isLittleEndian() const { return IsLittleEndian; } 170 virtual uint8_t getAddressSize() const { return AddressSize; } 171 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; } 172 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; } 173 virtual StringRef getInfoSection() { return InfoSection; } 174 virtual StringRef getAbbrevSection() { return AbbrevSection; } 175 virtual StringRef getARangeSection() { return ARangeSection; } 176 virtual StringRef getDebugFrameSection() { return DebugFrameSection; } 177 virtual StringRef getLineSection() { return LineSection; } 178 virtual StringRef getStringSection() { return StringSection; } 179 virtual StringRef getRangeSection() { return RangeSection; } 180 virtual StringRef getPubNamesSection() { return PubNamesSection; } 181 182 // Sections for DWARF5 split dwarf proposal. 183 virtual StringRef getInfoDWOSection() { return InfoDWOSection; } 184 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; } 185 virtual StringRef getStringDWOSection() { return StringDWOSection; } 186 virtual StringRef getStringOffsetDWOSection() { 187 return StringOffsetDWOSection; 188 } 189 virtual StringRef getRangeDWOSection() { return RangeDWOSection; } 190 virtual StringRef getAddrSection() { 191 return AddrSection; 192 } 193 virtual const RelocAddrMap &infoDWORelocMap() const { 194 return InfoDWORelocMap; 195 } 196}; 197 198} 199 200#endif 201