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