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"
25 class DWARFDebugAbbrev;
30 const DWARFDebugAbbrev *Abbrev;
31 StringRef InfoSection;
32 StringRef RangeSection;
33 uint32_t RangeSectionBase;
34 StringRef StringSection;
35 StringRef StringOffsetSection;
36 StringRef AddrOffsetSection;
37 uint32_t AddrOffsetSectionBase;
38 const RelocAddrMap *RelocMap;
44 const DWARFAbbreviationDeclarationSet *Abbrevs;
47 // The compile unit debug information entry items.
48 std::vector<DWARFDebugInfoEntryMinimal> DieArray;
51 std::unique_ptr<object::ObjectFile> DWOFile;
52 std::unique_ptr<DWARFContext> DWOContext;
55 DWOHolder(object::ObjectFile *DWOFile);
56 DWARFUnit *getUnit() const { return DWOU; }
58 std::unique_ptr<DWOHolder> DWO;
61 virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr);
64 DWARFUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef RS,
65 StringRef SS, StringRef SOS, StringRef AOS, const RelocAddrMap *M,
70 StringRef getStringSection() const { return StringSection; }
71 StringRef getStringOffsetSection() const { return StringOffsetSection; }
72 void setAddrOffsetSection(StringRef AOS, uint32_t Base) {
73 AddrOffsetSection = AOS;
74 AddrOffsetSectionBase = Base;
76 void setRangesSection(StringRef RS, uint32_t Base) {
78 RangeSectionBase = Base;
81 bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
82 // FIXME: Result should be uint64_t in DWARF64.
83 bool getStringOffsetSectionItem(uint32_t Index, uint32_t &Result) const;
85 DataExtractor getDebugInfoExtractor() const {
86 return DataExtractor(InfoSection, isLittleEndian, AddrSize);
88 DataExtractor getStringExtractor() const {
89 return DataExtractor(StringSection, false, 0);
92 const RelocAddrMap *getRelocMap() const { return RelocMap; }
94 bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
96 /// extractRangeList - extracts the range list referenced by this compile
97 /// unit from .debug_ranges section. Returns true on success.
98 /// Requires that compile unit is already extracted.
99 bool extractRangeList(uint32_t RangeListOffset,
100 DWARFDebugRangeList &RangeList) const;
102 uint32_t getOffset() const { return Offset; }
103 /// Size in bytes of the compile unit header.
104 virtual uint32_t getSize() const { return 11; }
105 uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
106 uint32_t getNextUnitOffset() const { return Offset + Length + 4; }
107 /// Size in bytes of the .debug_info data associated with this compile unit.
108 size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
109 uint32_t getLength() const { return Length; }
110 uint16_t getVersion() const { return Version; }
111 const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
114 uint8_t getAddressByteSize() const { return AddrSize; }
115 uint64_t getBaseAddress() const { return BaseAddr; }
117 void setBaseAddress(uint64_t base_addr) {
118 BaseAddr = base_addr;
121 const DWARFDebugInfoEntryMinimal *
122 getCompileUnitDIE(bool extract_cu_die_only = true) {
123 extractDIEsIfNeeded(extract_cu_die_only);
124 return DieArray.empty() ? NULL : &DieArray[0];
127 const char *getCompilationDir();
130 void collectAddressRanges(DWARFAddressRangesVector &CURanges);
132 /// getInlinedChainForAddress - fetches inlined chain for a given address.
133 /// Returns empty chain if there is no subprogram containing address. The
134 /// chain is valid as long as parsed compile unit DIEs are not cleared.
135 DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
138 /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
139 /// hasn't already been done. Returns the number of DIEs parsed at this call.
140 size_t extractDIEsIfNeeded(bool CUDieOnly);
141 /// extractDIEsToVector - Appends all parsed DIEs to a vector.
142 void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
143 std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const;
144 /// setDIERelations - We read in all of the DIE entries into our flat list
145 /// of DIE entries and now we need to go back through all of them and set the
146 /// parent, sibling and child pointers for quick DIE navigation.
147 void setDIERelations();
148 /// clearDIEs - Clear parsed DIEs to keep memory usage low.
149 void clearDIEs(bool KeepCUDie);
151 /// parseDWO - Parses .dwo file for current compile unit. Returns true if
152 /// it was actually constructed.
155 /// getSubprogramForAddress - Returns subprogram DIE with address range
156 /// encompassing the provided address. The pointer is alive as long as parsed
157 /// compile unit DIEs are not cleared.
158 const DWARFDebugInfoEntryMinimal *getSubprogramForAddress(uint64_t Address);