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" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 16 | #include "llvm/DebugInfo/DIContext.h" |
| 17 | #include "llvm/ADT/OwningPtr.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 22 | /// DWARFContext |
| 23 | /// This data structure is the top level entity that deals with dwarf debug |
| 24 | /// information parsing. The actual data is supplied through pure virtual |
| 25 | /// methods that a concrete implementation provides. |
| 26 | class DWARFContext : public DIContext { |
| 27 | bool IsLittleEndian; |
| 28 | |
| 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; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 33 | |
| 34 | DWARFContext(DWARFContext &); // = delete |
| 35 | DWARFContext &operator=(DWARFContext &); // = delete |
| 36 | |
| 37 | /// Read compile units from the debug_info section and store them in CUs. |
| 38 | void parseCompileUnits(); |
| 39 | protected: |
| 40 | DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {} |
| 41 | public: |
| 42 | virtual void dump(raw_ostream &OS); |
| 43 | /// Get the number of compile units in this context. |
| 44 | unsigned getNumCompileUnits() { |
| 45 | if (CUs.empty()) |
| 46 | parseCompileUnits(); |
| 47 | return CUs.size(); |
| 48 | } |
| 49 | /// Get the compile unit at the specified index for this compile unit. |
| 50 | DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { |
| 51 | if (CUs.empty()) |
| 52 | parseCompileUnits(); |
| 53 | return &CUs[index]; |
| 54 | } |
| 55 | |
Benjamin Kramer | 101b1c5 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 56 | /// Return the compile unit that includes an offset (relative to .debug_info). |
| 57 | DWARFCompileUnit *getCompileUnitForOffset(uint32_t offset); |
| 58 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 59 | /// Get a pointer to the parsed DebugAbbrev object. |
| 60 | const DWARFDebugAbbrev *getDebugAbbrev(); |
| 61 | |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 62 | /// Get a pointer to the parsed DebugAranges object. |
| 63 | const DWARFDebugAranges *getDebugAranges(); |
| 64 | |
Benjamin Kramer | c26ed9b | 2011-09-15 20:43:18 +0000 | [diff] [blame] | 65 | /// Get a pointer to a parsed line table corresponding to a compile unit. |
| 66 | const DWARFDebugLine::LineTable * |
| 67 | getLineTableForCompileUnit(DWARFCompileUnit *cu); |
Benjamin Kramer | b848e97 | 2011-09-15 02:12:05 +0000 | [diff] [blame] | 68 | |
Alexey Samsonov | 3e25c4a | 2012-07-02 05:54:45 +0000 | [diff] [blame] | 69 | virtual DILineInfo getLineInfoForAddress(uint64_t address, |
| 70 | DILineInfoSpecifier specifier = DILineInfoSpecifier()); |
Benjamin Kramer | 101b1c5 | 2011-09-15 20:43:22 +0000 | [diff] [blame] | 71 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 72 | bool isLittleEndian() const { return IsLittleEndian; } |
| 73 | |
| 74 | virtual StringRef getInfoSection() = 0; |
| 75 | virtual StringRef getAbbrevSection() = 0; |
| 76 | virtual StringRef getARangeSection() = 0; |
| 77 | virtual StringRef getLineSection() = 0; |
| 78 | virtual StringRef getStringSection() = 0; |
| 79 | |
| 80 | static bool isSupportedVersion(unsigned version) { |
| 81 | return version == 2 || version == 3; |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | |
| 86 | /// DWARFContextInMemory is the simplest possible implementation of a |
| 87 | /// DWARFContext. It assumes all content is available in memory and stores |
| 88 | /// pointers to it. |
| 89 | class DWARFContextInMemory : public DWARFContext { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 90 | virtual void anchor(); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 91 | StringRef InfoSection; |
| 92 | StringRef AbbrevSection; |
| 93 | StringRef ARangeSection; |
| 94 | StringRef LineSection; |
| 95 | StringRef StringSection; |
| 96 | public: |
| 97 | DWARFContextInMemory(bool isLittleEndian, |
| 98 | StringRef infoSection, |
| 99 | StringRef abbrevSection, |
| 100 | StringRef aRangeSection, |
| 101 | StringRef lineSection, |
| 102 | StringRef stringSection) |
| 103 | : DWARFContext(isLittleEndian), |
| 104 | InfoSection(infoSection), |
| 105 | AbbrevSection(abbrevSection), |
| 106 | ARangeSection(aRangeSection), |
| 107 | LineSection(lineSection), |
| 108 | StringSection(stringSection) |
| 109 | {} |
| 110 | |
| 111 | virtual StringRef getInfoSection() { return InfoSection; } |
| 112 | virtual StringRef getAbbrevSection() { return AbbrevSection; } |
| 113 | virtual StringRef getARangeSection() { return ARangeSection; } |
| 114 | virtual StringRef getLineSection() { return LineSection; } |
| 115 | virtual StringRef getStringSection() { return StringSection; } |
| 116 | }; |
| 117 | |
| 118 | } |
| 119 | |
| 120 | #endif |