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; |
| 29 | |
| 30 | SmallVector<DWARFCompileUnit, 1> CUs; |
| 31 | OwningPtr<DWARFDebugAbbrev> Abbrev; |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 32 | OwningPtr<DWARFDebugAranges> Aranges; |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 33 | OwningPtr<DWARFDebugLine> Line; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 34 | |
| 35 | DWARFContext(DWARFContext &); // = delete |
| 36 | DWARFContext &operator=(DWARFContext &); // = delete |
| 37 | |
| 38 | /// Read compile units from the debug_info section and store them in CUs. |
| 39 | void parseCompileUnits(); |
| 40 | protected: |
| 41 | DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {} |
| 42 | public: |
| 43 | virtual void dump(raw_ostream &OS); |
| 44 | /// Get the number of compile units in this context. |
| 45 | unsigned getNumCompileUnits() { |
| 46 | if (CUs.empty()) |
| 47 | parseCompileUnits(); |
| 48 | return CUs.size(); |
| 49 | } |
| 50 | /// Get the compile unit at the specified index for this compile unit. |
| 51 | DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { |
| 52 | if (CUs.empty()) |
| 53 | parseCompileUnits(); |
| 54 | return &CUs[index]; |
| 55 | } |
| 56 | |
Benjamin Kramer | 101b1c5 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 57 | /// Return the compile unit that includes an offset (relative to .debug_info). |
| 58 | DWARFCompileUnit *getCompileUnitForOffset(uint32_t offset); |
| 59 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 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 | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 70 | virtual DILineInfo getLineInfoForAddress(uint64_t address, |
| 71 | DILineInfoSpecifier specifier = DILineInfoSpecifier()); |
Benjamin Kramer | 101b1c5 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 72 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 73 | bool isLittleEndian() const { return IsLittleEndian; } |
| 74 | |
| 75 | virtual StringRef getInfoSection() = 0; |
| 76 | virtual StringRef getAbbrevSection() = 0; |
| 77 | virtual StringRef getARangeSection() = 0; |
| 78 | virtual StringRef getLineSection() = 0; |
| 79 | virtual StringRef getStringSection() = 0; |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 80 | virtual StringRef getRangeSection() = 0; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 81 | |
| 82 | static bool isSupportedVersion(unsigned version) { |
| 83 | return version == 2 || version == 3; |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | /// DWARFContextInMemory is the simplest possible implementation of a |
| 89 | /// DWARFContext. It assumes all content is available in memory and stores |
| 90 | /// pointers to it. |
| 91 | class DWARFContextInMemory : public DWARFContext { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 92 | virtual void anchor(); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 93 | StringRef InfoSection; |
| 94 | StringRef AbbrevSection; |
| 95 | StringRef ARangeSection; |
| 96 | StringRef LineSection; |
| 97 | StringRef StringSection; |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 98 | StringRef RangeSection; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 99 | public: |
| 100 | DWARFContextInMemory(bool isLittleEndian, |
| 101 | StringRef infoSection, |
| 102 | StringRef abbrevSection, |
| 103 | StringRef aRangeSection, |
| 104 | StringRef lineSection, |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 105 | StringRef stringSection, |
| 106 | StringRef rangeSection) |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 107 | : DWARFContext(isLittleEndian), |
| 108 | InfoSection(infoSection), |
| 109 | AbbrevSection(abbrevSection), |
| 110 | ARangeSection(aRangeSection), |
| 111 | LineSection(lineSection), |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 112 | StringSection(stringSection), |
| 113 | RangeSection(rangeSection) |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 114 | {} |
| 115 | |
| 116 | virtual StringRef getInfoSection() { return InfoSection; } |
| 117 | virtual StringRef getAbbrevSection() { return AbbrevSection; } |
| 118 | virtual StringRef getARangeSection() { return ARangeSection; } |
| 119 | virtual StringRef getLineSection() { return LineSection; } |
| 120 | virtual StringRef getStringSection() { return StringSection; } |
Alexey Samsonov | eceb5b9 | 2012-08-27 07:17:47 +0000 | [diff] [blame] | 121 | virtual StringRef getRangeSection() { return RangeSection; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | } |
| 125 | |
| 126 | #endif |