David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 1 | //===-- DWARFUnit.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_DWARFUNIT_H |
| 11 | #define LLVM_DEBUGINFO_DWARFUNIT_H |
| 12 | |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 13 | #include "DWARFDebugAbbrev.h" |
| 14 | #include "DWARFDebugInfoEntry.h" |
| 15 | #include "DWARFDebugRangeList.h" |
| 16 | #include "DWARFRelocMap.h" |
| 17 | #include <vector> |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
| 21 | namespace object { |
| 22 | class ObjectFile; |
| 23 | } |
| 24 | |
| 25 | class DWARFDebugAbbrev; |
| 26 | class StringRef; |
| 27 | class raw_ostream; |
| 28 | |
| 29 | class DWARFUnit { |
| 30 | const DWARFDebugAbbrev *Abbrev; |
| 31 | StringRef InfoSection; |
| 32 | StringRef AbbrevSection; |
| 33 | StringRef RangeSection; |
| 34 | uint32_t RangeSectionBase; |
| 35 | StringRef StringSection; |
| 36 | StringRef StringOffsetSection; |
| 37 | StringRef AddrOffsetSection; |
| 38 | uint32_t AddrOffsetSectionBase; |
| 39 | const RelocAddrMap *RelocMap; |
| 40 | bool isLittleEndian; |
| 41 | |
| 42 | uint32_t Offset; |
| 43 | uint32_t Length; |
| 44 | uint16_t Version; |
| 45 | const DWARFAbbreviationDeclarationSet *Abbrevs; |
| 46 | uint8_t AddrSize; |
| 47 | uint64_t BaseAddr; |
| 48 | // The compile unit debug information entry items. |
| 49 | std::vector<DWARFDebugInfoEntryMinimal> DieArray; |
| 50 | |
| 51 | class DWOHolder { |
Ahmed Charles | 56440fd | 2014-03-06 05:51:42 +0000 | [diff] [blame] | 52 | std::unique_ptr<object::ObjectFile> DWOFile; |
| 53 | std::unique_ptr<DWARFContext> DWOContext; |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 54 | DWARFUnit *DWOU; |
| 55 | public: |
| 56 | DWOHolder(object::ObjectFile *DWOFile); |
| 57 | DWARFUnit *getUnit() const { return DWOU; } |
| 58 | }; |
Ahmed Charles | 56440fd | 2014-03-06 05:51:42 +0000 | [diff] [blame] | 59 | std::unique_ptr<DWOHolder> DWO; |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 60 | |
| 61 | protected: |
| 62 | virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr); |
| 63 | |
| 64 | public: |
| 65 | |
| 66 | DWARFUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS, |
| 67 | StringRef RS, StringRef SS, StringRef SOS, StringRef AOS, |
| 68 | const RelocAddrMap *M, bool LE); |
| 69 | |
| 70 | virtual ~DWARFUnit(); |
| 71 | |
| 72 | StringRef getStringSection() const { return StringSection; } |
| 73 | StringRef getStringOffsetSection() const { return StringOffsetSection; } |
| 74 | void setAddrOffsetSection(StringRef AOS, uint32_t Base) { |
| 75 | AddrOffsetSection = AOS; |
| 76 | AddrOffsetSectionBase = Base; |
| 77 | } |
| 78 | void setRangesSection(StringRef RS, uint32_t Base) { |
| 79 | RangeSection = RS; |
| 80 | RangeSectionBase = Base; |
| 81 | } |
| 82 | |
| 83 | bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const; |
| 84 | // FIXME: Result should be uint64_t in DWARF64. |
| 85 | bool getStringOffsetSectionItem(uint32_t Index, uint32_t &Result) const; |
| 86 | |
| 87 | DataExtractor getDebugInfoExtractor() const { |
| 88 | return DataExtractor(InfoSection, isLittleEndian, AddrSize); |
| 89 | } |
| 90 | DataExtractor getStringExtractor() const { |
| 91 | return DataExtractor(StringSection, false, 0); |
| 92 | } |
| 93 | |
| 94 | const RelocAddrMap *getRelocMap() const { return RelocMap; } |
| 95 | |
| 96 | bool extract(DataExtractor debug_info, uint32_t* offset_ptr); |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 97 | |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 98 | /// extractRangeList - extracts the range list referenced by this compile |
| 99 | /// unit from .debug_ranges section. Returns true on success. |
| 100 | /// Requires that compile unit is already extracted. |
| 101 | bool extractRangeList(uint32_t RangeListOffset, |
| 102 | DWARFDebugRangeList &RangeList) const; |
| 103 | void clear(); |
| 104 | uint32_t getOffset() const { return Offset; } |
| 105 | /// Size in bytes of the compile unit header. |
| 106 | virtual uint32_t getSize() const { return 11; } |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 107 | uint32_t getFirstDIEOffset() const { return Offset + getSize(); } |
| 108 | uint32_t getNextUnitOffset() const { return Offset + Length + 4; } |
| 109 | /// Size in bytes of the .debug_info data associated with this compile unit. |
| 110 | size_t getDebugInfoSize() const { return Length + 4 - getSize(); } |
| 111 | uint32_t getLength() const { return Length; } |
| 112 | uint16_t getVersion() const { return Version; } |
| 113 | const DWARFAbbreviationDeclarationSet *getAbbreviations() const { |
| 114 | return Abbrevs; |
| 115 | } |
| 116 | uint8_t getAddressByteSize() const { return AddrSize; } |
| 117 | uint64_t getBaseAddress() const { return BaseAddr; } |
| 118 | |
| 119 | void setBaseAddress(uint64_t base_addr) { |
| 120 | BaseAddr = base_addr; |
| 121 | } |
| 122 | |
| 123 | const DWARFDebugInfoEntryMinimal * |
| 124 | getCompileUnitDIE(bool extract_cu_die_only = true) { |
| 125 | extractDIEsIfNeeded(extract_cu_die_only); |
| 126 | return DieArray.empty() ? NULL : &DieArray[0]; |
| 127 | } |
| 128 | |
| 129 | const char *getCompilationDir(); |
| 130 | uint64_t getDWOId(); |
| 131 | |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 132 | void buildAddressRangeTable(DWARFDebugAranges *debug_aranges, |
| 133 | bool clear_dies_if_already_not_parsed, |
| 134 | uint32_t CUOffsetInAranges); |
| 135 | |
| 136 | /// getInlinedChainForAddress - fetches inlined chain for a given address. |
| 137 | /// Returns empty chain if there is no subprogram containing address. The |
| 138 | /// chain is valid as long as parsed compile unit DIEs are not cleared. |
| 139 | DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address); |
| 140 | |
| 141 | private: |
Alexey Samsonov | 0428d12 | 2013-10-31 18:05:02 +0000 | [diff] [blame] | 142 | /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it |
| 143 | /// hasn't already been done. Returns the number of DIEs parsed at this call. |
| 144 | size_t extractDIEsIfNeeded(bool CUDieOnly); |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 145 | /// extractDIEsToVector - Appends all parsed DIEs to a vector. |
| 146 | void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs, |
| 147 | std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const; |
Alexey Samsonov | 0428d12 | 2013-10-31 18:05:02 +0000 | [diff] [blame] | 148 | /// setDIERelations - We read in all of the DIE entries into our flat list |
| 149 | /// of DIE entries and now we need to go back through all of them and set the |
| 150 | /// parent, sibling and child pointers for quick DIE navigation. |
| 151 | void setDIERelations(); |
David Blaikie | 07e2244 | 2013-09-23 22:44:40 +0000 | [diff] [blame] | 152 | /// clearDIEs - Clear parsed DIEs to keep memory usage low. |
| 153 | void clearDIEs(bool KeepCUDie); |
| 154 | |
| 155 | /// parseDWO - Parses .dwo file for current compile unit. Returns true if |
| 156 | /// it was actually constructed. |
| 157 | bool parseDWO(); |
| 158 | |
| 159 | /// getSubprogramForAddress - Returns subprogram DIE with address range |
| 160 | /// encompassing the provided address. The pointer is alive as long as parsed |
| 161 | /// compile unit DIEs are not cleared. |
| 162 | const DWARFDebugInfoEntryMinimal *getSubprogramForAddress(uint64_t Address); |
| 163 | }; |
| 164 | |
| 165 | } |
| 166 | |
| 167 | #endif |