LLVM API Documentation
00001 //===-- DWARFContext.h ------------------------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===/ 00009 00010 #ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H 00011 #define LLVM_DEBUGINFO_DWARFCONTEXT_H 00012 00013 #include "DWARFCompileUnit.h" 00014 #include "DWARFDebugAranges.h" 00015 #include "DWARFDebugFrame.h" 00016 #include "DWARFDebugLine.h" 00017 #include "DWARFDebugRangeList.h" 00018 #include "llvm/ADT/OwningPtr.h" 00019 #include "llvm/ADT/SmallVector.h" 00020 #include "llvm/DebugInfo/DIContext.h" 00021 00022 namespace llvm { 00023 00024 /// DWARFContext 00025 /// This data structure is the top level entity that deals with dwarf debug 00026 /// information parsing. The actual data is supplied through pure virtual 00027 /// methods that a concrete implementation provides. 00028 class DWARFContext : public DIContext { 00029 SmallVector<DWARFCompileUnit, 1> CUs; 00030 OwningPtr<DWARFDebugAbbrev> Abbrev; 00031 OwningPtr<DWARFDebugAranges> Aranges; 00032 OwningPtr<DWARFDebugLine> Line; 00033 OwningPtr<DWARFDebugFrame> DebugFrame; 00034 00035 SmallVector<DWARFCompileUnit, 1> DWOCUs; 00036 OwningPtr<DWARFDebugAbbrev> AbbrevDWO; 00037 00038 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION; 00039 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION; 00040 00041 /// Read compile units from the debug_info section and store them in CUs. 00042 void parseCompileUnits(); 00043 00044 /// Read compile units from the debug_info.dwo section and store them in 00045 /// DWOCUs. 00046 void parseDWOCompileUnits(); 00047 00048 public: 00049 DWARFContext() {} 00050 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All); 00051 00052 /// Get the number of compile units in this context. 00053 unsigned getNumCompileUnits() { 00054 if (CUs.empty()) 00055 parseCompileUnits(); 00056 return CUs.size(); 00057 } 00058 00059 /// Get the number of compile units in the DWO context. 00060 unsigned getNumDWOCompileUnits() { 00061 if (DWOCUs.empty()) 00062 parseDWOCompileUnits(); 00063 return DWOCUs.size(); 00064 } 00065 00066 /// Get the compile unit at the specified index for this compile unit. 00067 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { 00068 if (CUs.empty()) 00069 parseCompileUnits(); 00070 return &CUs[index]; 00071 } 00072 00073 /// Get the compile unit at the specified index for the DWO compile units. 00074 DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { 00075 if (DWOCUs.empty()) 00076 parseDWOCompileUnits(); 00077 return &DWOCUs[index]; 00078 } 00079 00080 /// Get a pointer to the parsed DebugAbbrev object. 00081 const DWARFDebugAbbrev *getDebugAbbrev(); 00082 00083 /// Get a pointer to the parsed dwo abbreviations object. 00084 const DWARFDebugAbbrev *getDebugAbbrevDWO(); 00085 00086 /// Get a pointer to the parsed DebugAranges object. 00087 const DWARFDebugAranges *getDebugAranges(); 00088 00089 /// Get a pointer to the parsed frame information object. 00090 const DWARFDebugFrame *getDebugFrame(); 00091 00092 /// Get a pointer to a parsed line table corresponding to a compile unit. 00093 const DWARFDebugLine::LineTable * 00094 getLineTableForCompileUnit(DWARFCompileUnit *cu); 00095 00096 virtual DILineInfo getLineInfoForAddress(uint64_t Address, 00097 DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 00098 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, 00099 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 00100 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, 00101 DILineInfoSpecifier Specifier = DILineInfoSpecifier()); 00102 00103 virtual bool isLittleEndian() const = 0; 00104 virtual uint8_t getAddressSize() const = 0; 00105 virtual const RelocAddrMap &infoRelocMap() const = 0; 00106 virtual const RelocAddrMap &lineRelocMap() const = 0; 00107 virtual StringRef getInfoSection() = 0; 00108 virtual StringRef getAbbrevSection() = 0; 00109 virtual StringRef getARangeSection() = 0; 00110 virtual StringRef getDebugFrameSection() = 0; 00111 virtual StringRef getLineSection() = 0; 00112 virtual StringRef getStringSection() = 0; 00113 virtual StringRef getRangeSection() = 0; 00114 virtual StringRef getPubNamesSection() = 0; 00115 00116 // Sections for DWARF5 split dwarf proposal. 00117 virtual StringRef getInfoDWOSection() = 0; 00118 virtual StringRef getAbbrevDWOSection() = 0; 00119 virtual StringRef getStringDWOSection() = 0; 00120 virtual StringRef getStringOffsetDWOSection() = 0; 00121 virtual StringRef getRangeDWOSection() = 0; 00122 virtual StringRef getAddrSection() = 0; 00123 virtual const RelocAddrMap &infoDWORelocMap() const = 0; 00124 00125 static bool isSupportedVersion(unsigned version) { 00126 return version == 2 || version == 3; 00127 } 00128 private: 00129 /// Return the compile unit that includes an offset (relative to .debug_info). 00130 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset); 00131 00132 /// Return the compile unit which contains instruction with provided 00133 /// address. 00134 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); 00135 }; 00136 00137 /// DWARFContextInMemory is the simplest possible implementation of a 00138 /// DWARFContext. It assumes all content is available in memory and stores 00139 /// pointers to it. 00140 class DWARFContextInMemory : public DWARFContext { 00141 virtual void anchor(); 00142 bool IsLittleEndian; 00143 uint8_t AddressSize; 00144 RelocAddrMap InfoRelocMap; 00145 RelocAddrMap LineRelocMap; 00146 StringRef InfoSection; 00147 StringRef AbbrevSection; 00148 StringRef ARangeSection; 00149 StringRef DebugFrameSection; 00150 StringRef LineSection; 00151 StringRef StringSection; 00152 StringRef RangeSection; 00153 StringRef PubNamesSection; 00154 00155 // Sections for DWARF5 split dwarf proposal. 00156 RelocAddrMap InfoDWORelocMap; 00157 StringRef InfoDWOSection; 00158 StringRef AbbrevDWOSection; 00159 StringRef StringDWOSection; 00160 StringRef StringOffsetDWOSection; 00161 StringRef RangeDWOSection; 00162 StringRef AddrSection; 00163 00164 SmallVector<MemoryBuffer*, 4> UncompressedSections; 00165 00166 public: 00167 DWARFContextInMemory(object::ObjectFile *); 00168 ~DWARFContextInMemory(); 00169 virtual bool isLittleEndian() const { return IsLittleEndian; } 00170 virtual uint8_t getAddressSize() const { return AddressSize; } 00171 virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; } 00172 virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; } 00173 virtual StringRef getInfoSection() { return InfoSection; } 00174 virtual StringRef getAbbrevSection() { return AbbrevSection; } 00175 virtual StringRef getARangeSection() { return ARangeSection; } 00176 virtual StringRef getDebugFrameSection() { return DebugFrameSection; } 00177 virtual StringRef getLineSection() { return LineSection; } 00178 virtual StringRef getStringSection() { return StringSection; } 00179 virtual StringRef getRangeSection() { return RangeSection; } 00180 virtual StringRef getPubNamesSection() { return PubNamesSection; } 00181 00182 // Sections for DWARF5 split dwarf proposal. 00183 virtual StringRef getInfoDWOSection() { return InfoDWOSection; } 00184 virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; } 00185 virtual StringRef getStringDWOSection() { return StringDWOSection; } 00186 virtual StringRef getStringOffsetDWOSection() { 00187 return StringOffsetDWOSection; 00188 } 00189 virtual StringRef getRangeDWOSection() { return RangeDWOSection; } 00190 virtual StringRef getAddrSection() { 00191 return AddrSection; 00192 } 00193 virtual const RelocAddrMap &infoDWORelocMap() const { 00194 return InfoDWORelocMap; 00195 } 00196 }; 00197 00198 } 00199 00200 #endif