1 //===-- DWARFUnit.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_DEBUGINFO_DWARFUNIT_H
11 #define LLVM_DEBUGINFO_DWARFUNIT_H
13 #include "llvm/ADT/OwningPtr.h"
14 #include "DWARFDebugAbbrev.h"
15 #include "DWARFDebugInfoEntry.h"
16 #include "DWARFDebugRangeList.h"
17 #include "DWARFRelocMap.h"
26 class DWARFDebugAbbrev;
31 const DWARFDebugAbbrev *Abbrev;
32 StringRef InfoSection;
33 StringRef AbbrevSection;
34 StringRef RangeSection;
35 uint32_t RangeSectionBase;
36 StringRef StringSection;
37 StringRef StringOffsetSection;
38 StringRef AddrOffsetSection;
39 uint32_t AddrOffsetSectionBase;
40 const RelocAddrMap *RelocMap;
46 const DWARFAbbreviationDeclarationSet *Abbrevs;
49 // The compile unit debug information entry items.
50 std::vector<DWARFDebugInfoEntryMinimal> DieArray;
53 OwningPtr<object::ObjectFile> DWOFile;
54 OwningPtr<DWARFContext> DWOContext;
57 DWOHolder(object::ObjectFile *DWOFile);
58 DWARFUnit *getUnit() const { return DWOU; }
60 OwningPtr<DWOHolder> DWO;
63 virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr);
67 DWARFUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS,
68 StringRef RS, StringRef SS, StringRef SOS, StringRef AOS,
69 const RelocAddrMap *M, bool LE);
73 StringRef getStringSection() const { return StringSection; }
74 StringRef getStringOffsetSection() const { return StringOffsetSection; }
75 void setAddrOffsetSection(StringRef AOS, uint32_t Base) {
76 AddrOffsetSection = AOS;
77 AddrOffsetSectionBase = Base;
79 void setRangesSection(StringRef RS, uint32_t Base) {
81 RangeSectionBase = Base;
84 bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
85 // FIXME: Result should be uint64_t in DWARF64.
86 bool getStringOffsetSectionItem(uint32_t Index, uint32_t &Result) const;
88 DataExtractor getDebugInfoExtractor() const {
89 return DataExtractor(InfoSection, isLittleEndian, AddrSize);
91 DataExtractor getStringExtractor() const {
92 return DataExtractor(StringSection, false, 0);
95 const RelocAddrMap *getRelocMap() const { return RelocMap; }
97 bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
98 uint32_t extract(uint32_t offset, DataExtractor debug_info_data,
99 const DWARFAbbreviationDeclarationSet *abbrevs);
101 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
102 /// hasn't already been done. Returns the number of DIEs parsed at this call.
103 size_t extractDIEsIfNeeded(bool CUDieOnly);
104 /// extractRangeList - extracts the range list referenced by this compile
105 /// unit from .debug_ranges section. Returns true on success.
106 /// Requires that compile unit is already extracted.
107 bool extractRangeList(uint32_t RangeListOffset,
108 DWARFDebugRangeList &RangeList) const;
110 uint32_t getOffset() const { return Offset; }
111 /// Size in bytes of the compile unit header.
112 virtual uint32_t getSize() const { return 11; }
113 bool containsDIEOffset(uint32_t die_offset) const {
114 return die_offset >= getFirstDIEOffset() &&
115 die_offset < getNextUnitOffset();
117 uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
118 uint32_t getNextUnitOffset() const { return Offset + Length + 4; }
119 /// Size in bytes of the .debug_info data associated with this compile unit.
120 size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
121 uint32_t getLength() const { return Length; }
122 uint16_t getVersion() const { return Version; }
123 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
126 uint8_t getAddressByteSize() const { return AddrSize; }
127 uint64_t getBaseAddress() const { return BaseAddr; }
129 void setBaseAddress(uint64_t base_addr) {
130 BaseAddr = base_addr;
133 const DWARFDebugInfoEntryMinimal *
134 getCompileUnitDIE(bool extract_cu_die_only = true) {
135 extractDIEsIfNeeded(extract_cu_die_only);
136 return DieArray.empty() ? NULL : &DieArray[0];
139 const char *getCompilationDir();
142 /// setDIERelations - We read in all of the DIE entries into our flat list
143 /// of DIE entries and now we need to go back through all of them and set the
144 /// parent, sibling and child pointers for quick DIE navigation.
145 void setDIERelations();
147 void buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
148 bool clear_dies_if_already_not_parsed,
149 uint32_t CUOffsetInAranges);
151 /// getInlinedChainForAddress - fetches inlined chain for a given address.
152 /// Returns empty chain if there is no subprogram containing address. The
153 /// chain is valid as long as parsed compile unit DIEs are not cleared.
154 DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
157 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
158 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
159 std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const;
160 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
161 void clearDIEs(bool KeepCUDie);
163 /// parseDWO - Parses .dwo file for current compile unit. Returns true if
164 /// it was actually constructed.
167 /// getSubprogramForAddress - Returns subprogram DIE with address range
168 /// encompassing the provided address. The pointer is alive as long as parsed
169 /// compile unit DIEs are not cleared.
170 const DWARFDebugInfoEntryMinimal *getSubprogramForAddress(uint64_t Address);