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_LIB_DEBUGINFO_DWARFUNIT_H
11 #define LLVM_LIB_DEBUGINFO_DWARFUNIT_H
13 #include "DWARFDebugAbbrev.h"
14 #include "DWARFDebugInfoEntry.h"
15 #include "DWARFDebugRangeList.h"
16 #include "DWARFRelocMap.h"
26 class DWARFDebugAbbrev;
31 DWARFContext &Context;
33 const DWARFDebugAbbrev *Abbrev;
34 StringRef InfoSection;
35 StringRef RangeSection;
36 uint32_t RangeSectionBase;
37 StringRef StringSection;
38 StringRef StringOffsetSection;
39 StringRef AddrOffsetSection;
40 uint32_t AddrOffsetSectionBase;
41 const RelocAddrMap *RelocMap;
47 const DWARFAbbreviationDeclarationSet *Abbrevs;
50 // The compile unit debug information entry items.
51 std::vector<DWARFDebugInfoEntryMinimal> DieArray;
54 object::OwningBinary<object::ObjectFile> DWOFile;
55 std::unique_ptr<DWARFContext> DWOContext;
58 DWOHolder(StringRef DWOPath);
59 DWARFUnit *getUnit() const { return DWOU; }
61 std::unique_ptr<DWOHolder> DWO;
64 virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr);
65 /// Size in bytes of the unit header.
66 virtual uint32_t getHeaderSize() const { return 11; }
69 DWARFUnit(DWARFContext& Context, const DWARFDebugAbbrev *DA, StringRef IS,
70 StringRef RS, StringRef SS, StringRef SOS, StringRef AOS,
71 const RelocAddrMap *M, bool LE);
75 DWARFContext& getContext() const { return Context; }
77 StringRef getStringSection() const { return StringSection; }
78 StringRef getStringOffsetSection() const { return StringOffsetSection; }
79 void setAddrOffsetSection(StringRef AOS, uint32_t Base) {
80 AddrOffsetSection = AOS;
81 AddrOffsetSectionBase = Base;
83 void setRangesSection(StringRef RS, uint32_t Base) {
85 RangeSectionBase = Base;
88 bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
89 // FIXME: Result should be uint64_t in DWARF64.
90 bool getStringOffsetSectionItem(uint32_t Index, uint32_t &Result) const;
92 DataExtractor getDebugInfoExtractor() const {
93 return DataExtractor(InfoSection, isLittleEndian, AddrSize);
95 DataExtractor getStringExtractor() const {
96 return DataExtractor(StringSection, false, 0);
99 const RelocAddrMap *getRelocMap() const { return RelocMap; }
101 bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
103 /// extractRangeList - extracts the range list referenced by this compile
104 /// unit from .debug_ranges section. Returns true on success.
105 /// Requires that compile unit is already extracted.
106 bool extractRangeList(uint32_t RangeListOffset,
107 DWARFDebugRangeList &RangeList) const;
109 uint32_t getOffset() const { return Offset; }
110 uint32_t getNextUnitOffset() const { return Offset + Length + 4; }
111 uint32_t getLength() const { return Length; }
112 uint16_t getVersion() const { return Version; }
113 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
116 uint8_t getAddressByteSize() const { return AddrSize; }
117 uint64_t getBaseAddress() const { return BaseAddr; }
119 void setBaseAddress(uint64_t base_addr) {
120 BaseAddr = base_addr;
123 const DWARFDebugInfoEntryMinimal *
124 getCompileUnitDIE(bool extract_cu_die_only = true) {
125 extractDIEsIfNeeded(extract_cu_die_only);
126 return DieArray.empty() ? nullptr : &DieArray[0];
129 const char *getCompilationDir();
132 void collectAddressRanges(DWARFAddressRangesVector &CURanges);
134 /// getInlinedChainForAddress - fetches inlined chain for a given address.
135 /// Returns empty chain if there is no subprogram containing address. The
136 /// chain is valid as long as parsed compile unit DIEs are not cleared.
137 DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
140 /// Size in bytes of the .debug_info data associated with this compile unit.
141 size_t getDebugInfoSize() const { return Length + 4 - getHeaderSize(); }
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);