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 "DWARFDebugAbbrev.h"
14 #include "DWARFDebugInfoEntry.h"
15 #include "DWARFDebugRangeList.h"
16 #include "DWARFRelocMap.h"
17 #include "llvm/ADT/OwningPtr.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);
99 /// extractRangeList - extracts the range list referenced by this compile
100 /// unit from .debug_ranges section. Returns true on success.
101 /// Requires that compile unit is already extracted.
102 bool extractRangeList(uint32_t RangeListOffset,
103 DWARFDebugRangeList &RangeList) const;
105 uint32_t getOffset() const { return Offset; }
106 /// Size in bytes of the compile unit header.
107 virtual uint32_t getSize() const { return 11; }
108 uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
109 uint32_t getNextUnitOffset() const { return Offset + Length + 4; }
110 /// Size in bytes of the .debug_info data associated with this compile unit.
111 size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
112 uint32_t getLength() const { return Length; }
113 uint16_t getVersion() const { return Version; }
114 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
117 uint8_t getAddressByteSize() const { return AddrSize; }
118 uint64_t getBaseAddress() const { return BaseAddr; }
120 void setBaseAddress(uint64_t base_addr) {
121 BaseAddr = base_addr;
124 const DWARFDebugInfoEntryMinimal *
125 getCompileUnitDIE(bool extract_cu_die_only = true) {
126 extractDIEsIfNeeded(extract_cu_die_only);
127 return DieArray.empty() ? NULL : &DieArray[0];
130 const char *getCompilationDir();
133 void buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
134 bool clear_dies_if_already_not_parsed,
135 uint32_t CUOffsetInAranges);
137 /// getInlinedChainForAddress - fetches inlined chain for a given address.
138 /// Returns empty chain if there is no subprogram containing address. The
139 /// chain is valid as long as parsed compile unit DIEs are not cleared.
140 DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
143 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
144 /// hasn't already been done. Returns the number of DIEs parsed at this call.
145 size_t extractDIEsIfNeeded(bool CUDieOnly);
146 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
147 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
148 std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const;
149 /// setDIERelations - We read in all of the DIE entries into our flat list
150 /// of DIE entries and now we need to go back through all of them and set the
151 /// parent, sibling and child pointers for quick DIE navigation.
152 void setDIERelations();
153 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
154 void clearDIEs(bool KeepCUDie);
156 /// parseDWO - Parses .dwo file for current compile unit. Returns true if
157 /// it was actually constructed.
160 /// getSubprogramForAddress - Returns subprogram DIE with address range
161 /// encompassing the provided address. The pointer is alive as long as parsed
162 /// compile unit DIEs are not cleared.
163 const DWARFDebugInfoEntryMinimal *getSubprogramForAddress(uint64_t Address);