Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 1 | //===-- DWARFCompileUnit.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_DWARFCOMPILEUNIT_H |
| 11 | #define LLVM_DEBUGINFO_DWARFCOMPILEUNIT_H |
| 12 | |
| 13 | #include "DWARFDebugAbbrev.h" |
| 14 | #include "DWARFDebugInfoEntry.h" |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 15 | #include "DWARFDebugRangeList.h" |
Andrew Kaylor | ee7c0d2 | 2013-01-25 22:50:58 +0000 | [diff] [blame^] | 16 | #include "DWARFRelocMap.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 21 | class DWARFDebugAbbrev; |
| 22 | class StringRef; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 23 | class raw_ostream; |
| 24 | |
| 25 | class DWARFCompileUnit { |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 26 | const DWARFDebugAbbrev *Abbrev; |
| 27 | StringRef InfoSection; |
| 28 | StringRef AbbrevSection; |
| 29 | StringRef RangeSection; |
| 30 | StringRef StringSection; |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 31 | StringRef StringOffsetSection; |
Eric Christopher | 72f7bfb | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 32 | StringRef AddrOffsetSection; |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 33 | const RelocAddrMap *RelocMap; |
| 34 | bool isLittleEndian; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 35 | |
| 36 | uint32_t Offset; |
| 37 | uint32_t Length; |
| 38 | uint16_t Version; |
| 39 | const DWARFAbbreviationDeclarationSet *Abbrevs; |
| 40 | uint8_t AddrSize; |
| 41 | uint64_t BaseAddr; |
| 42 | // The compile unit debug information entry item. |
| 43 | std::vector<DWARFDebugInfoEntryMinimal> DieArray; |
| 44 | public: |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 45 | |
| 46 | DWARFCompileUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS, |
Eric Christopher | 72f7bfb | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 47 | StringRef RS, StringRef SS, StringRef SOS, StringRef AOS, |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 48 | const RelocAddrMap *M, bool LE) : |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 49 | Abbrev(DA), InfoSection(IS), AbbrevSection(AS), |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 50 | RangeSection(RS), StringSection(SS), StringOffsetSection(SOS), |
Eric Christopher | 72f7bfb | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 51 | AddrOffsetSection(AOS), RelocMap(M), isLittleEndian(LE) { |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 52 | clear(); |
| 53 | } |
| 54 | |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 55 | StringRef getStringSection() const { return StringSection; } |
Eric Christopher | dd8e9f3 | 2013-01-07 19:32:41 +0000 | [diff] [blame] | 56 | StringRef getStringOffsetSection() const { return StringOffsetSection; } |
Eric Christopher | 72f7bfb | 2013-01-15 23:56:56 +0000 | [diff] [blame] | 57 | StringRef getAddrOffsetSection() const { return AddrOffsetSection; } |
Eric Christopher | 82de10a | 2013-01-02 23:52:13 +0000 | [diff] [blame] | 58 | const RelocAddrMap *getRelocMap() const { return RelocMap; } |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 59 | DataExtractor getDebugInfoExtractor() const; |
| 60 | |
| 61 | bool extract(DataExtractor debug_info, uint32_t* offset_ptr); |
| 62 | uint32_t extract(uint32_t offset, DataExtractor debug_info_data, |
| 63 | const DWARFAbbreviationDeclarationSet *abbrevs); |
| 64 | |
| 65 | /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it |
Alexey Samsonov | a9543aa | 2012-07-04 09:42:54 +0000 | [diff] [blame] | 66 | /// hasn't already been done. Returns the number of DIEs parsed at this call. |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 67 | size_t extractDIEsIfNeeded(bool cu_die_only); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 68 | /// extractRangeList - extracts the range list referenced by this compile |
| 69 | /// unit from .debug_ranges section. Returns true on success. |
| 70 | /// Requires that compile unit is already extracted. |
| 71 | bool extractRangeList(uint32_t RangeListOffset, |
| 72 | DWARFDebugRangeList &RangeList) const; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 73 | void clear(); |
| 74 | void dump(raw_ostream &OS); |
| 75 | uint32_t getOffset() const { return Offset; } |
| 76 | /// Size in bytes of the compile unit header. |
| 77 | uint32_t getSize() const { return 11; } |
| 78 | bool containsDIEOffset(uint32_t die_offset) const { |
| 79 | return die_offset >= getFirstDIEOffset() && |
| 80 | die_offset < getNextCompileUnitOffset(); |
| 81 | } |
| 82 | uint32_t getFirstDIEOffset() const { return Offset + getSize(); } |
| 83 | uint32_t getNextCompileUnitOffset() const { return Offset + Length + 4; } |
| 84 | /// Size in bytes of the .debug_info data associated with this compile unit. |
| 85 | size_t getDebugInfoSize() const { return Length + 4 - getSize(); } |
| 86 | uint32_t getLength() const { return Length; } |
| 87 | uint16_t getVersion() const { return Version; } |
| 88 | const DWARFAbbreviationDeclarationSet *getAbbreviations() const { |
| 89 | return Abbrevs; |
| 90 | } |
| 91 | uint8_t getAddressByteSize() const { return AddrSize; } |
| 92 | uint64_t getBaseAddress() const { return BaseAddr; } |
| 93 | |
| 94 | void setBaseAddress(uint64_t base_addr) { |
| 95 | BaseAddr = base_addr; |
| 96 | } |
| 97 | |
Benjamin Kramer | fe80f1d | 2011-09-15 18:02:20 +0000 | [diff] [blame] | 98 | const DWARFDebugInfoEntryMinimal * |
| 99 | getCompileUnitDIE(bool extract_cu_die_only = true) { |
| 100 | extractDIEsIfNeeded(extract_cu_die_only); |
| 101 | if (DieArray.empty()) |
| 102 | return NULL; |
| 103 | return &DieArray[0]; |
| 104 | } |
| 105 | |
Alexey Samsonov | 71d94f8 | 2012-07-19 07:03:58 +0000 | [diff] [blame] | 106 | const char *getCompilationDir(); |
| 107 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 108 | /// setDIERelations - We read in all of the DIE entries into our flat list |
| 109 | /// of DIE entries and now we need to go back through all of them and set the |
| 110 | /// parent, sibling and child pointers for quick DIE navigation. |
| 111 | void setDIERelations(); |
| 112 | |
| 113 | void addDIE(DWARFDebugInfoEntryMinimal &die) { |
| 114 | // The average bytes per DIE entry has been seen to be |
| 115 | // around 14-20 so lets pre-reserve the needed memory for |
| 116 | // our DIE entries accordingly. Search forward for "Compute |
| 117 | // average bytes per DIE" to see #if'ed out code that does |
| 118 | // that determination. |
| 119 | |
| 120 | // Only reserve the memory if we are adding children of |
| 121 | // the main compile unit DIE. The compile unit DIE is always |
| 122 | // the first entry, so if our size is 1, then we are adding |
| 123 | // the first compile unit child DIE and should reserve |
| 124 | // the memory. |
| 125 | if (DieArray.empty()) |
| 126 | DieArray.reserve(getDebugInfoSize() / 14); |
| 127 | DieArray.push_back(die); |
| 128 | } |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame] | 129 | |
| 130 | void clearDIEs(bool keep_compile_unit_die); |
| 131 | |
| 132 | void buildAddressRangeTable(DWARFDebugAranges *debug_aranges, |
| 133 | bool clear_dies_if_already_not_parsed); |
Alexey Samsonov | 5eae90d | 2012-09-04 08:12:33 +0000 | [diff] [blame] | 134 | |
| 135 | /// getInlinedChainForAddress - fetches inlined chain for a given address. |
| 136 | /// Returns empty chain if there is no subprogram containing address. |
| 137 | DWARFDebugInfoEntryMinimal::InlinedChain getInlinedChainForAddress( |
| 138 | uint64_t Address); |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | } |
| 142 | |
| 143 | #endif |