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/DebugInfo/DIContext.h" |
| 18 | #include "llvm/ADT/OwningPtr.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
| 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 { |
| 28 | bool IsLittleEndian; |
Alexey Samsonov | 4c0ae90 | 2012-11-12 14:25:36 +0000 | [diff] [blame] | 29 | const RelocAddrMap *RelocMap; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 30 | |
| 31 | SmallVector<DWARFCompileUnit, 1> CUs; |
| 32 | OwningPtr<DWARFDebugAbbrev> Abbrev; |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 33 | OwningPtr<DWARFDebugAranges> Aranges; |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 34 | OwningPtr<DWARFDebugLine> Line; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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(); |
| 41 | protected: |
Alexey Samsonov | 4c0ae90 | 2012-11-12 14:25:36 +0000 | [diff] [blame] | 42 | DWARFContext(bool isLittleEndian, const RelocAddrMap *Map) : |
Eric Christopher | 806e03d | 2012-11-07 23:22:07 +0000 | [diff] [blame] | 43 | IsLittleEndian(isLittleEndian), RelocMap(Map) {} |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 44 | public: |
| 45 | virtual void dump(raw_ostream &OS); |
Eric Christopher | 806e03d | 2012-11-07 23:22:07 +0000 | [diff] [blame] | 46 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 47 | /// Get the number of compile units in this context. |
| 48 | unsigned getNumCompileUnits() { |
| 49 | if (CUs.empty()) |
| 50 | parseCompileUnits(); |
| 51 | return CUs.size(); |
| 52 | } |
| 53 | /// Get the compile unit at the specified index for this compile unit. |
| 54 | DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { |
| 55 | if (CUs.empty()) |
| 56 | parseCompileUnits(); |
| 57 | return &CUs[index]; |
| 58 | } |
| 59 | |
| 60 | /// Get a pointer to the parsed DebugAbbrev object. |
| 61 | const DWARFDebugAbbrev *getDebugAbbrev(); |
| 62 | |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 63 | /// Get a pointer to the parsed DebugAranges object. |
| 64 | const DWARFDebugAranges *getDebugAranges(); |
| 65 | |
Benjamin Kramer | c26ed9b | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 66 | /// Get a pointer to a parsed line table corresponding to a compile unit. |
| 67 | const DWARFDebugLine::LineTable * |
| 68 | getLineTableForCompileUnit(DWARFCompileUnit *cu); |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 69 | |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 70 | virtual DILineInfo getLineInfoForAddress(uint64_t Address, |
| 71 | DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 72 | virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, |
| 73 | DILineInfoSpecifier Specifier = DILineInfoSpecifier()); |
Benjamin Kramer | 101b1c5 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 74 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 75 | bool isLittleEndian() const { return IsLittleEndian; } |
Alexey Samsonov | 4c0ae90 | 2012-11-12 14:25:36 +0000 | [diff] [blame] | 76 | const RelocAddrMap *relocMap() const { return RelocMap; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 77 | |
| 78 | virtual StringRef getInfoSection() = 0; |
| 79 | virtual StringRef getAbbrevSection() = 0; |
| 80 | virtual StringRef getARangeSection() = 0; |
| 81 | virtual StringRef getLineSection() = 0; |
| 82 | virtual StringRef getStringSection() = 0; |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 83 | virtual StringRef getRangeSection() = 0; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 84 | |
| 85 | static bool isSupportedVersion(unsigned version) { |
| 86 | return version == 2 || version == 3; |
| 87 | } |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 88 | private: |
| 89 | /// Return the compile unit that includes an offset (relative to .debug_info). |
| 90 | DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 91 | |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 92 | /// Return the compile unit which contains instruction with provided |
| 93 | /// address. |
| 94 | DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); |
Alexey Samsonov | 38a6381 | 2012-08-30 07:49:50 +0000 | [diff] [blame] | 95 | }; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 96 | |
| 97 | /// DWARFContextInMemory is the simplest possible implementation of a |
| 98 | /// DWARFContext. It assumes all content is available in memory and stores |
| 99 | /// pointers to it. |
| 100 | class DWARFContextInMemory : public DWARFContext { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 101 | virtual void anchor(); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 102 | StringRef InfoSection; |
| 103 | StringRef AbbrevSection; |
| 104 | StringRef ARangeSection; |
| 105 | StringRef LineSection; |
| 106 | StringRef StringSection; |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 107 | StringRef RangeSection; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 108 | public: |
| 109 | DWARFContextInMemory(bool isLittleEndian, |
| 110 | StringRef infoSection, |
| 111 | StringRef abbrevSection, |
| 112 | StringRef aRangeSection, |
| 113 | StringRef lineSection, |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 114 | StringRef stringSection, |
Eric Christopher | 806e03d | 2012-11-07 23:22:07 +0000 | [diff] [blame] | 115 | StringRef rangeSection, |
Alexey Samsonov | 4c0ae90 | 2012-11-12 14:25:36 +0000 | [diff] [blame] | 116 | const RelocAddrMap *Map = 0) |
Eric Christopher | 806e03d | 2012-11-07 23:22:07 +0000 | [diff] [blame] | 117 | : DWARFContext(isLittleEndian, Map), |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 118 | InfoSection(infoSection), |
| 119 | AbbrevSection(abbrevSection), |
| 120 | ARangeSection(aRangeSection), |
| 121 | LineSection(lineSection), |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 122 | StringSection(stringSection), |
| 123 | RangeSection(rangeSection) |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 124 | {} |
| 125 | |
| 126 | virtual StringRef getInfoSection() { return InfoSection; } |
| 127 | virtual StringRef getAbbrevSection() { return AbbrevSection; } |
| 128 | virtual StringRef getARangeSection() { return ARangeSection; } |
| 129 | virtual StringRef getLineSection() { return LineSection; } |
| 130 | virtual StringRef getStringSection() { return StringSection; } |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 131 | virtual StringRef getRangeSection() { return RangeSection; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | } |
| 135 | |
| 136 | #endif |