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" |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 15 | #include "DWARFDebugLine.h" |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 16 | #include "DWARFDebugRangeList.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/OwningPtr.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | a1514e2 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 19 | #include "llvm/DebugInfo/DIContext.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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 { |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 28 | SmallVector<DWARFCompileUnit, 1> CUs; |
| 29 | OwningPtr<DWARFDebugAbbrev> Abbrev; |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 30 | OwningPtr<DWARFDebugAranges> Aranges; |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 31 | OwningPtr<DWARFDebugLine> Line; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 32 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 33 | SmallVector<DWARFCompileUnit, 1> DWOCUs; |
| 34 | OwningPtr<DWARFDebugAbbrev> AbbrevDWO; |
| 35 | |
Craig Topper | c2945e4 | 2012-09-18 02:01:41 +0000 | [diff] [blame] | 36 | DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION; |
| 37 | DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 38 | |
| 39 | /// Read compile units from the debug_info section and store them in CUs. |
| 40 | void parseCompileUnits(); |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 41 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 42 | /// Read compile units from the debug_info.dwo section and store them in |
| 43 | /// DWOCUs. |
| 44 | void parseDWOCompileUnits(); |
| 45 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 46 | public: |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 47 | DWARFContext() {} |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 48 | virtual void dump(raw_ostream &OS); |
Eric Christopher | 806e03d | 2012-11-07 23:22:07 +0000 | [diff] [blame] | 49 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 50 | /// Get the number of compile units in this context. |
| 51 | unsigned getNumCompileUnits() { |
| 52 | if (CUs.empty()) |
| 53 | parseCompileUnits(); |
| 54 | return CUs.size(); |
| 55 | } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 56 | |
| 57 | /// Get the number of compile units in the DWO context. |
| 58 | unsigned getNumDWOCompileUnits() { |
| 59 | if (DWOCUs.empty()) |
| 60 | parseDWOCompileUnits(); |
| 61 | return DWOCUs.size(); |
| 62 | } |
| 63 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 64 | /// Get the compile unit at the specified index for this compile unit. |
| 65 | DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { |
| 66 | if (CUs.empty()) |
| 67 | parseCompileUnits(); |
| 68 | return &CUs[index]; |
| 69 | } |
| 70 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 71 | /// Get the compile unit at the specified index for the DWO compile units. |
| 72 | DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { |
| 73 | if (DWOCUs.empty()) |
| 74 | parseDWOCompileUnits(); |
| 75 | return &DWOCUs[index]; |
| 76 | } |
| 77 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 78 | /// Get a pointer to the parsed DebugAbbrev object. |
| 79 | const DWARFDebugAbbrev *getDebugAbbrev(); |
| 80 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 81 | /// Get a pointer to the parsed dwo abbreviations object. |
| 82 | const DWARFDebugAbbrev *getDebugAbbrevDWO(); |
| 83 | |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 84 | /// Get a pointer to the parsed DebugAranges object. |
| 85 | const DWARFDebugAranges *getDebugAranges(); |
| 86 | |
Benjamin Kramer | c26ed9b | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 87 | /// Get a pointer to a parsed line table corresponding to a compile unit. |
| 88 | const DWARFDebugLine::LineTable * |
| 89 | getLineTableForCompileUnit(DWARFCompileUnit *cu); |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 90 | |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 91 | virtual DILineInfo getLineInfoForAddress(uint64_t Address, |
| 92 | DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 93 | virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, |
| 94 | DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Benjamin Kramer | 101b1c5 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 95 | |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 96 | virtual bool isLittleEndian() const = 0; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 97 | virtual const RelocAddrMap &infoRelocMap() const = 0; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 98 | virtual StringRef getInfoSection() = 0; |
| 99 | virtual StringRef getAbbrevSection() = 0; |
| 100 | virtual StringRef getARangeSection() = 0; |
| 101 | virtual StringRef getLineSection() = 0; |
| 102 | virtual StringRef getStringSection() = 0; |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 103 | virtual StringRef getRangeSection() = 0; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 104 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 105 | // Sections for DWARF5 split dwarf proposal. |
| 106 | virtual StringRef getInfoDWOSection() = 0; |
| 107 | virtual StringRef getAbbrevDWOSection() = 0; |
| 108 | virtual StringRef getStringDWOSection() = 0; |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 109 | virtual StringRef getStringOffsetDWOSection() = 0; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 110 | virtual StringRef getRangeDWOSection() = 0; |
| 111 | virtual const RelocAddrMap &infoDWORelocMap() const = 0; |
| 112 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 113 | static bool isSupportedVersion(unsigned version) { |
| 114 | return version == 2 || version == 3; |
| 115 | } |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 116 | private: |
| 117 | /// Return the compile unit that includes an offset (relative to .debug_info). |
| 118 | DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 119 | |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 120 | /// Return the compile unit which contains instruction with provided |
| 121 | /// address. |
| 122 | DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 123 | }; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 124 | |
| 125 | /// DWARFContextInMemory is the simplest possible implementation of a |
| 126 | /// DWARFContext. It assumes all content is available in memory and stores |
| 127 | /// pointers to it. |
| 128 | class DWARFContextInMemory : public DWARFContext { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 129 | virtual void anchor(); |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 130 | bool IsLittleEndian; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 131 | RelocAddrMap InfoRelocMap; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 132 | StringRef InfoSection; |
| 133 | StringRef AbbrevSection; |
| 134 | StringRef ARangeSection; |
| 135 | StringRef LineSection; |
| 136 | StringRef StringSection; |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 137 | StringRef RangeSection; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 138 | |
| 139 | // Sections for DWARF5 split dwarf proposal. |
| 140 | RelocAddrMap InfoDWORelocMap; |
| 141 | StringRef InfoDWOSection; |
| 142 | StringRef AbbrevDWOSection; |
| 143 | StringRef StringDWOSection; |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 144 | StringRef StringOffsetDWOSection; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 145 | StringRef RangeDWOSection; |
| 146 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 147 | public: |
Eric Christopher | d1726a4 | 2012-11-12 21:40:38 +0000 | [diff] [blame] | 148 | DWARFContextInMemory(object::ObjectFile *); |
| 149 | virtual bool isLittleEndian() const { return IsLittleEndian; } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 150 | virtual const RelocAddrMap &infoRelocMap() const { return InfoRelocMap; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 151 | virtual StringRef getInfoSection() { return InfoSection; } |
| 152 | virtual StringRef getAbbrevSection() { return AbbrevSection; } |
| 153 | virtual StringRef getARangeSection() { return ARangeSection; } |
| 154 | virtual StringRef getLineSection() { return LineSection; } |
| 155 | virtual StringRef getStringSection() { return StringSection; } |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 156 | virtual StringRef getRangeSection() { return RangeSection; } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 157 | |
| 158 | // Sections for DWARF5 split dwarf proposal. |
| 159 | virtual StringRef getInfoDWOSection() { return InfoDWOSection; } |
| 160 | virtual StringRef getAbbrevDWOSection() { return AbbrevDWOSection; } |
| 161 | virtual StringRef getStringDWOSection() { return StringDWOSection; } |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 162 | virtual StringRef getStringOffsetDWOSection() { |
| 163 | return StringOffsetDWOSection; |
| 164 | } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 165 | virtual StringRef getRangeDWOSection() { return RangeDWOSection; } |
Eric Christopher | e7285c7 | 2013-01-07 22:40:48 +0000 | [diff] [blame^] | 166 | virtual const RelocAddrMap &infoDWORelocMap() const { |
| 167 | return InfoDWORelocMap; |
| 168 | } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | } |
| 172 | |
| 173 | #endif |