Benjamin Kramer | 72c0d7f | 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 | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 14 | #include "DWARFDebugAranges.h" |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 15 | #include "DWARFDebugFrame.h" |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 16 | #include "DWARFDebugLine.h" |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 17 | #include "DWARFDebugRangeList.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/OwningPtr.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | a1514e2 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 20 | #include "llvm/DebugInfo/DIContext.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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. |
| 28 | class DWARFContext : public DIContext { |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 29 | SmallVector<DWARFCompileUnit, 1> CUs; |
| 30 | OwningPtr<DWARFDebugAbbrev> Abbrev; |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 31 | OwningPtr<DWARFDebugAranges> Aranges; |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 32 | OwningPtr<DWARFDebugLine> Line; |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 33 | OwningPtr<DWARFDebugFrame> DebugFrame; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 34 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 35 | SmallVector<DWARFCompileUnit, 1> DWOCUs; |
| 36 | OwningPtr<DWARFDebugAbbrev> AbbrevDWO; |
| 37 | |
Craig Topper | c2945e4 | 2012-09-18 02:01:41 +0000 | [diff] [blame] | 38 | DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION; |
| 39 | DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 40 | |
| 41 | /// Read compile units from the debug_info section and store them in CUs. |
| 42 | void parseCompileUnits(); |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 43 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 44 | /// Read compile units from the debug_info.dwo section and store them in |
| 45 | /// DWOCUs. |
| 46 | void parseDWOCompileUnits(); |
| 47 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 48 | public: |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 49 | DWARFContext() {} |
Eli Bendersky | 939a4e8 | 2013-01-25 20:26:43 +0000 | [diff] [blame] | 50 | virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All); |
Eric Christopher | 806e03d | 2012-11-07 23:22:07 +0000 | [diff] [blame] | 51 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 52 | /// Get the number of compile units in this context. |
| 53 | unsigned getNumCompileUnits() { |
| 54 | if (CUs.empty()) |
| 55 | parseCompileUnits(); |
| 56 | return CUs.size(); |
| 57 | } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 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 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 80 | /// Get a pointer to the parsed DebugAbbrev object. |
| 81 | const DWARFDebugAbbrev *getDebugAbbrev(); |
| 82 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 83 | /// Get a pointer to the parsed dwo abbreviations object. |
| 84 | const DWARFDebugAbbrev *getDebugAbbrevDWO(); |
| 85 | |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 86 | /// Get a pointer to the parsed DebugAranges object. |
| 87 | const DWARFDebugAranges *getDebugAranges(); |
| 88 | |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 89 | /// Get a pointer to the parsed frame information object. |
| 90 | const DWARFDebugFrame *getDebugFrame(); |
| 91 | |
Benjamin Kramer | c26ed9b | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 92 | /// Get a pointer to a parsed line table corresponding to a compile unit. |
| 93 | const DWARFDebugLine::LineTable * |
| 94 | getLineTableForCompileUnit(DWARFCompileUnit *cu); |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 95 | |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 96 | virtual DILineInfo getLineInfoForAddress(uint64_t Address, |
| 97 | DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Andrew Kaylor | e27a787 | 2013-01-26 00:28:05 +0000 | [diff] [blame] | 98 | virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, |
| 99 | uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 100 | virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, |
| 101 | DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Benjamin Kramer | 101b1c5 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 102 | |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 103 | virtual bool isLittleEndian() const = 0; |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 104 | virtual uint8_t getAddressSize() const = 0; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 105 | virtual const RelocAddrMap &infoRelocMap() const = 0; |
Andrew Kaylor | ee7c0d2 | 2013-01-25 22:50:58 +0000 | [diff] [blame] | 106 | virtual const RelocAddrMap &lineRelocMap() const = 0; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 107 | virtual StringRef getInfoSection() = 0; |
| 108 | virtual StringRef getAbbrevSection() = 0; |
| 109 | virtual StringRef getARangeSection() = 0; |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 110 | virtual StringRef getDebugFrameSection() = 0; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 111 | virtual StringRef getLineSection() = 0; |
| 112 | virtual StringRef getStringSection() = 0; |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 113 | virtual StringRef getRangeSection() = 0; |
Krzysztof Parzyszek | e38825f | 2013-02-12 16:20:28 +0000 | [diff] [blame] | 114 | virtual StringRef getPubNamesSection() = 0; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 115 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 116 | // Sections for DWARF5 split dwarf proposal. |
| 117 | virtual StringRef getInfoDWOSection() = 0; |
| 118 | virtual StringRef getAbbrevDWOSection() = 0; |
| 119 | virtual StringRef getStringDWOSection() = 0; |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 120 | virtual StringRef getStringOffsetDWOSection() = 0; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 121 | virtual StringRef getRangeDWOSection() = 0; |
Eric Christopher | 72f7bfb | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 122 | virtual StringRef getAddrSection() = 0; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 123 | virtual const RelocAddrMap &infoDWORelocMap() const = 0; |
| 124 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 125 | static bool isSupportedVersion(unsigned version) { |
| 126 | return version == 2 || version == 3; |
| 127 | } |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 128 | private: |
| 129 | /// Return the compile unit that includes an offset (relative to .debug_info). |
| 130 | DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 131 | |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 132 | /// Return the compile unit which contains instruction with provided |
| 133 | /// address. |
| 134 | DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 135 | }; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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. |
| 140 | class DWARFContextInMemory : public DWARFContext { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 141 | virtual void anchor(); |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 142 | bool IsLittleEndian; |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 143 | uint8_t AddressSize; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 144 | RelocAddrMap InfoRelocMap; |
Andrew Kaylor | ee7c0d2 | 2013-01-25 22:50:58 +0000 | [diff] [blame] | 145 | RelocAddrMap LineRelocMap; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 146 | StringRef InfoSection; |
| 147 | StringRef AbbrevSection; |
| 148 | StringRef ARangeSection; |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 149 | StringRef DebugFrameSection; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 150 | StringRef LineSection; |
| 151 | StringRef StringSection; |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 152 | StringRef RangeSection; |
Krzysztof Parzyszek | e38825f | 2013-02-12 16:20:28 +0000 | [diff] [blame] | 153 | StringRef PubNamesSection; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 154 | |
| 155 | // Sections for DWARF5 split dwarf proposal. |
| 156 | RelocAddrMap InfoDWORelocMap; |
| 157 | StringRef InfoDWOSection; |
| 158 | StringRef AbbrevDWOSection; |
| 159 | StringRef StringDWOSection; |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 160 | StringRef StringOffsetDWOSection; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 161 | StringRef RangeDWOSection; |
Eric Christopher | 72f7bfb | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 162 | StringRef AddrSection; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 163 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 164 | public: |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 165 | DWARFContextInMemory(object::ObjectFile *); |
| 166 | virtual bool isLittleEndian() const { return IsLittleEndian; } |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 167 | virtual uint8_t getAddressSize() const { return AddressSize; } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 168 | virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; } |
Andrew Kaylor | ee7c0d2 | 2013-01-25 22:50:58 +0000 | [diff] [blame] | 169 | virtual const RelocAddrMap &lineRelocMap() const { return LineRelocMap; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 170 | virtual StringRef getInfoSection() { return InfoSection; } |
| 171 | virtual StringRef getAbbrevSection() { return AbbrevSection; } |
| 172 | virtual StringRef getARangeSection() { return ARangeSection; } |
Eli Bendersky | 60bdc5b | 2013-02-05 23:30:58 +0000 | [diff] [blame] | 173 | virtual StringRef getDebugFrameSection() { return DebugFrameSection; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 174 | virtual StringRef getLineSection() { return LineSection; } |
| 175 | virtual StringRef getStringSection() { return StringSection; } |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 176 | virtual StringRef getRangeSection() { return RangeSection; } |
Krzysztof Parzyszek | e38825f | 2013-02-12 16:20:28 +0000 | [diff] [blame] | 177 | virtual StringRef getPubNamesSection() { return PubNamesSection; } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 178 | |
| 179 | // Sections for DWARF5 split dwarf proposal. |
| 180 | virtual StringRef getInfoDWOSection() { return InfoDWOSection; } |
| 181 | virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; } |
| 182 | virtual StringRef getStringDWOSection() { return StringDWOSection; } |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 183 | virtual StringRef getStringOffsetDWOSection() { |
| 184 | return StringOffsetDWOSection; |
| 185 | } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 186 | virtual StringRef getRangeDWOSection() { return RangeDWOSection; } |
Eric Christopher | 72f7bfb | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 187 | virtual StringRef getAddrSection() { |
| 188 | return AddrSection; |
| 189 | } |
Eric Christopher | e7285c7 | 2013-01-07 22:40:48 +0000 | [diff] [blame] | 190 | virtual const RelocAddrMap &infoDWORelocMap() const { |
| 191 | return InfoDWORelocMap; |
| 192 | } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | } |
| 196 | |
| 197 | #endif |