Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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" |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 14 | #include "DWARFDebugAranges.h" |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 15 | #include "DWARFDebugFrame.h" |
Benjamin Kramer | 5acab50 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 16 | #include "DWARFDebugLine.h" |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 17 | #include "DWARFDebugLoc.h" |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 18 | #include "DWARFDebugRangeList.h" |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/OwningPtr.h" |
| 20 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 21 | #include "llvm/DebugInfo/DIContext.h" |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 25 | /// DWARFContext |
| 26 | /// This data structure is the top level entity that deals with dwarf debug |
| 27 | /// information parsing. The actual data is supplied through pure virtual |
| 28 | /// methods that a concrete implementation provides. |
| 29 | class DWARFContext : public DIContext { |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 30 | SmallVector<DWARFCompileUnit, 1> CUs; |
| 31 | OwningPtr<DWARFDebugAbbrev> Abbrev; |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 32 | OwningPtr<DWARFDebugLoc> Loc; |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 33 | OwningPtr<DWARFDebugAranges> Aranges; |
Benjamin Kramer | 5acab50 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 34 | OwningPtr<DWARFDebugLine> Line; |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 35 | OwningPtr<DWARFDebugFrame> DebugFrame; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 36 | |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 37 | SmallVector<DWARFCompileUnit, 1> DWOCUs; |
| 38 | OwningPtr<DWARFDebugAbbrev> AbbrevDWO; |
| 39 | |
Craig Topper | b1d83e8 | 2012-09-18 02:01:41 +0000 | [diff] [blame] | 40 | DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION; |
| 41 | DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 42 | |
| 43 | /// Read compile units from the debug_info section and store them in CUs. |
| 44 | void parseCompileUnits(); |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 45 | |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 46 | /// Read compile units from the debug_info.dwo section and store them in |
| 47 | /// DWOCUs. |
| 48 | void parseDWOCompileUnits(); |
| 49 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 50 | public: |
Alexey Samsonov | c2e0087 | 2013-08-06 10:32:39 +0000 | [diff] [blame^] | 51 | DWARFContext() : DIContext(CK_DWARF) {} |
| 52 | |
| 53 | static bool classof(const DIContext *DICtx) { |
| 54 | return DICtx->getKind() == CK_DWARF; |
| 55 | } |
| 56 | |
Eli Bendersky | 7a94daa | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 57 | virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All); |
Eric Christopher | 7c678de | 2012-11-07 23:22:07 +0000 | [diff] [blame] | 58 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 59 | /// Get the number of compile units in this context. |
| 60 | unsigned getNumCompileUnits() { |
| 61 | if (CUs.empty()) |
| 62 | parseCompileUnits(); |
| 63 | return CUs.size(); |
| 64 | } |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 65 | |
| 66 | /// Get the number of compile units in the DWO context. |
| 67 | unsigned getNumDWOCompileUnits() { |
| 68 | if (DWOCUs.empty()) |
| 69 | parseDWOCompileUnits(); |
| 70 | return DWOCUs.size(); |
| 71 | } |
| 72 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 73 | /// Get the compile unit at the specified index for this compile unit. |
| 74 | DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { |
| 75 | if (CUs.empty()) |
| 76 | parseCompileUnits(); |
| 77 | return &CUs[index]; |
| 78 | } |
| 79 | |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 80 | /// Get the compile unit at the specified index for the DWO compile units. |
| 81 | DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { |
| 82 | if (DWOCUs.empty()) |
| 83 | parseDWOCompileUnits(); |
| 84 | return &DWOCUs[index]; |
| 85 | } |
| 86 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 87 | /// Get a pointer to the parsed DebugAbbrev object. |
| 88 | const DWARFDebugAbbrev *getDebugAbbrev(); |
| 89 | |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 90 | /// Get a pointer to the parsed DebugLoc object. |
| 91 | const DWARFDebugLoc *getDebugLoc(); |
| 92 | |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 93 | /// Get a pointer to the parsed dwo abbreviations object. |
| 94 | const DWARFDebugAbbrev *getDebugAbbrevDWO(); |
| 95 | |
Benjamin Kramer | a6002fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 96 | /// Get a pointer to the parsed DebugAranges object. |
| 97 | const DWARFDebugAranges *getDebugAranges(); |
| 98 | |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 99 | /// Get a pointer to the parsed frame information object. |
| 100 | const DWARFDebugFrame *getDebugFrame(); |
| 101 | |
Benjamin Kramer | 679e175 | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 102 | /// Get a pointer to a parsed line table corresponding to a compile unit. |
| 103 | const DWARFDebugLine::LineTable * |
| 104 | getLineTableForCompileUnit(DWARFCompileUnit *cu); |
Benjamin Kramer | 5acab50 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 105 | |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 106 | virtual DILineInfo getLineInfoForAddress(uint64_t Address, |
| 107 | DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Andrew Kaylor | 9a8ff81 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 108 | virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, |
| 109 | uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Alexey Samsonov | c942e6b | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 110 | virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, |
| 111 | DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Benjamin Kramer | 2602ca6 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 112 | |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 113 | virtual bool isLittleEndian() const = 0; |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 114 | virtual uint8_t getAddressSize() const = 0; |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 115 | virtual const RelocAddrMap &infoRelocMap() const = 0; |
Andrew Kaylor | d55d701 | 2013-01-25 22:50:58 +0000 | [diff] [blame] | 116 | virtual const RelocAddrMap &lineRelocMap() const = 0; |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 117 | virtual const RelocAddrMap &locRelocMap() const = 0; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 118 | virtual StringRef getInfoSection() = 0; |
| 119 | virtual StringRef getAbbrevSection() = 0; |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 120 | virtual StringRef getLocSection() = 0; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 121 | virtual StringRef getARangeSection() = 0; |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 122 | virtual StringRef getDebugFrameSection() = 0; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 123 | virtual StringRef getLineSection() = 0; |
| 124 | virtual StringRef getStringSection() = 0; |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 125 | virtual StringRef getRangeSection() = 0; |
Krzysztof Parzyszek | 97438dc | 2013-02-12 16:20:28 +0000 | [diff] [blame] | 126 | virtual StringRef getPubNamesSection() = 0; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 127 | |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 128 | // Sections for DWARF5 split dwarf proposal. |
| 129 | virtual StringRef getInfoDWOSection() = 0; |
| 130 | virtual StringRef getAbbrevDWOSection() = 0; |
| 131 | virtual StringRef getStringDWOSection() = 0; |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 132 | virtual StringRef getStringOffsetDWOSection() = 0; |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 133 | virtual StringRef getRangeDWOSection() = 0; |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 134 | virtual StringRef getAddrSection() = 0; |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 135 | virtual const RelocAddrMap &infoDWORelocMap() const = 0; |
| 136 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 137 | static bool isSupportedVersion(unsigned version) { |
Eric Christopher | f7d848d | 2013-08-06 01:38:27 +0000 | [diff] [blame] | 138 | return version == 2 || version == 3 || version == 4; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 139 | } |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 140 | private: |
| 141 | /// Return the compile unit that includes an offset (relative to .debug_info). |
| 142 | DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset); |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 143 | |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 144 | /// Return the compile unit which contains instruction with provided |
| 145 | /// address. |
| 146 | DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); |
Alexey Samsonov | 45be793 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 147 | }; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 148 | |
| 149 | /// DWARFContextInMemory is the simplest possible implementation of a |
| 150 | /// DWARFContext. It assumes all content is available in memory and stores |
| 151 | /// pointers to it. |
| 152 | class DWARFContextInMemory : public DWARFContext { |
David Blaikie | a379b181 | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 153 | virtual void anchor(); |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 154 | bool IsLittleEndian; |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 155 | uint8_t AddressSize; |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 156 | RelocAddrMap InfoRelocMap; |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 157 | RelocAddrMap LocRelocMap; |
Andrew Kaylor | d55d701 | 2013-01-25 22:50:58 +0000 | [diff] [blame] | 158 | RelocAddrMap LineRelocMap; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 159 | StringRef InfoSection; |
| 160 | StringRef AbbrevSection; |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 161 | StringRef LocSection; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 162 | StringRef ARangeSection; |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 163 | StringRef DebugFrameSection; |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 164 | StringRef LineSection; |
| 165 | StringRef StringSection; |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 166 | StringRef RangeSection; |
Krzysztof Parzyszek | 97438dc | 2013-02-12 16:20:28 +0000 | [diff] [blame] | 167 | StringRef PubNamesSection; |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 168 | |
| 169 | // Sections for DWARF5 split dwarf proposal. |
| 170 | RelocAddrMap InfoDWORelocMap; |
| 171 | StringRef InfoDWOSection; |
| 172 | StringRef AbbrevDWOSection; |
| 173 | StringRef StringDWOSection; |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 174 | StringRef StringOffsetDWOSection; |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 175 | StringRef RangeDWOSection; |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 176 | StringRef AddrSection; |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 177 | |
Alexey Samsonov | 068fc8a | 2013-04-23 10:17:34 +0000 | [diff] [blame] | 178 | SmallVector<MemoryBuffer*, 4> UncompressedSections; |
| 179 | |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 180 | public: |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 181 | DWARFContextInMemory(object::ObjectFile *); |
Alexey Samsonov | 068fc8a | 2013-04-23 10:17:34 +0000 | [diff] [blame] | 182 | ~DWARFContextInMemory(); |
Eric Christopher | 7370b55 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 183 | virtual bool isLittleEndian() const { return IsLittleEndian; } |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 184 | virtual uint8_t getAddressSize() const { return AddressSize; } |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 185 | virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; } |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 186 | virtual const RelocAddrMap &locRelocMap() const { return LocRelocMap; } |
Andrew Kaylor | d55d701 | 2013-01-25 22:50:58 +0000 | [diff] [blame] | 187 | virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; } |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 188 | virtual StringRef getInfoSection() { return InfoSection; } |
| 189 | virtual StringRef getAbbrevSection() { return AbbrevSection; } |
David Blaikie | 18e7350 | 2013-06-19 21:37:13 +0000 | [diff] [blame] | 190 | virtual StringRef getLocSection() { return LocSection; } |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 191 | virtual StringRef getARangeSection() { return ARangeSection; } |
Eli Bendersky | fd08bc1 | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 192 | virtual StringRef getDebugFrameSection() { return DebugFrameSection; } |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 193 | virtual StringRef getLineSection() { return LineSection; } |
| 194 | virtual StringRef getStringSection() { return StringSection; } |
Alexey Samsonov | 034e57a | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 195 | virtual StringRef getRangeSection() { return RangeSection; } |
Krzysztof Parzyszek | 97438dc | 2013-02-12 16:20:28 +0000 | [diff] [blame] | 196 | virtual StringRef getPubNamesSection() { return PubNamesSection; } |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 197 | |
| 198 | // Sections for DWARF5 split dwarf proposal. |
| 199 | virtual StringRef getInfoDWOSection() { return InfoDWOSection; } |
| 200 | virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; } |
| 201 | virtual StringRef getStringDWOSection() { return StringDWOSection; } |
Eric Christopher | 2cbd576 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 202 | virtual StringRef getStringOffsetDWOSection() { |
| 203 | return StringOffsetDWOSection; |
| 204 | } |
Eric Christopher | da4b219 | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 205 | virtual StringRef getRangeDWOSection() { return RangeDWOSection; } |
Eric Christopher | 962c908 | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 206 | virtual StringRef getAddrSection() { |
| 207 | return AddrSection; |
| 208 | } |
Eric Christopher | b2120fd | 2013-01-07 22:40:48 +0000 | [diff] [blame] | 209 | virtual const RelocAddrMap &infoDWORelocMap() const { |
| 210 | return InfoDWORelocMap; |
| 211 | } |
Benjamin Kramer | aa2f78f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | } |
| 215 | |
| 216 | #endif |