[mips][msa] Made the operand register sets optional for the VEC formats
[oota-llvm.git] / lib / DebugInfo / DWARFCompileUnit.h
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 "llvm/ADT/OwningPtr.h"
14 #include "DWARFDebugAbbrev.h"
15 #include "DWARFDebugInfoEntry.h"
16 #include "DWARFDebugRangeList.h"
17 #include "DWARFRelocMap.h"
18 #include <vector>
19
20 namespace llvm {
21
22 namespace object {
23 class ObjectFile;
24 }
25
26 class DWARFDebugAbbrev;
27 class StringRef;
28 class raw_ostream;
29
30 class DWARFCompileUnit {
31   DWARFCompileUnit(DWARFCompileUnit const &) LLVM_DELETED_FUNCTION;
32   DWARFCompileUnit &operator=(DWARFCompileUnit const &) LLVM_DELETED_FUNCTION;
33
34   const DWARFDebugAbbrev *Abbrev;
35   StringRef InfoSection;
36   StringRef AbbrevSection;
37   StringRef RangeSection;
38   uint32_t RangeSectionBase;
39   StringRef StringSection;
40   StringRef StringOffsetSection;
41   StringRef AddrOffsetSection;
42   uint32_t AddrOffsetSectionBase;
43   const RelocAddrMap *RelocMap;
44   bool isLittleEndian;
45
46   uint32_t Offset;
47   uint32_t Length;
48   uint16_t Version;
49   const DWARFAbbreviationDeclarationSet *Abbrevs;
50   uint8_t AddrSize;
51   uint64_t BaseAddr;
52   // The compile unit debug information entry items.
53   std::vector<DWARFDebugInfoEntryMinimal> DieArray;
54
55   class DWOHolder {
56     OwningPtr<object::ObjectFile> DWOFile;
57     OwningPtr<DWARFContext> DWOContext;
58     DWARFCompileUnit *DWOCU;
59   public:
60     DWOHolder(object::ObjectFile *DWOFile);
61     DWARFCompileUnit *getCU() const { return DWOCU; }
62   };
63   OwningPtr<DWOHolder> DWO;
64
65 public:
66
67   DWARFCompileUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS,
68                    StringRef RS, StringRef SS, StringRef SOS, StringRef AOS,
69                    const RelocAddrMap *M, bool LE) :
70     Abbrev(DA), InfoSection(IS), AbbrevSection(AS),
71     RangeSection(RS), StringSection(SS), StringOffsetSection(SOS),
72     AddrOffsetSection(AOS), RelocMap(M), isLittleEndian(LE) {
73     clear();
74   }
75
76   StringRef getStringSection() const { return StringSection; }
77   StringRef getStringOffsetSection() const { return StringOffsetSection; }
78   void setAddrOffsetSection(StringRef AOS, uint32_t Base) {
79     AddrOffsetSection = AOS;
80     AddrOffsetSectionBase = Base;
81   }
82   void setRangesSection(StringRef RS, uint32_t Base) {
83     RangeSection = RS;
84     RangeSectionBase = Base;
85   }
86
87   bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const;
88   // FIXME: Result should be uint64_t in DWARF64.
89   bool getStringOffsetSectionItem(uint32_t Index, uint32_t &Result) const;
90
91   DataExtractor getDebugInfoExtractor() const {
92     return DataExtractor(InfoSection, isLittleEndian, AddrSize);
93   }
94   DataExtractor getStringExtractor() const {
95     return DataExtractor(StringSection, false, 0);
96   }
97
98   const RelocAddrMap *getRelocMap() const { return RelocMap; }
99
100   bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
101   uint32_t extract(uint32_t offset, DataExtractor debug_info_data,
102                    const DWARFAbbreviationDeclarationSet *abbrevs);
103
104   /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
105   /// hasn't already been done. Returns the number of DIEs parsed at this call.
106   size_t extractDIEsIfNeeded(bool CUDieOnly);
107   /// extractRangeList - extracts the range list referenced by this compile
108   /// unit from .debug_ranges section. Returns true on success.
109   /// Requires that compile unit is already extracted.
110   bool extractRangeList(uint32_t RangeListOffset,
111                         DWARFDebugRangeList &RangeList) const;
112   void clear();
113   void dump(raw_ostream &OS);
114   uint32_t getOffset() const { return Offset; }
115   /// Size in bytes of the compile unit header.
116   uint32_t getSize() const { return 11; }
117   bool containsDIEOffset(uint32_t die_offset) const {
118     return die_offset >= getFirstDIEOffset() &&
119       die_offset < getNextCompileUnitOffset();
120   }
121   uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
122   uint32_t getNextCompileUnitOffset() const { return Offset + Length + 4; }
123   /// Size in bytes of the .debug_info data associated with this compile unit.
124   size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
125   uint32_t getLength() const { return Length; }
126   uint16_t getVersion() const { return Version; }
127   const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
128     return Abbrevs;
129   }
130   uint8_t getAddressByteSize() const { return AddrSize; }
131   uint64_t getBaseAddress() const { return BaseAddr; }
132
133   void setBaseAddress(uint64_t base_addr) {
134     BaseAddr = base_addr;
135   }
136
137   const DWARFDebugInfoEntryMinimal *
138   getCompileUnitDIE(bool extract_cu_die_only = true) {
139     extractDIEsIfNeeded(extract_cu_die_only);
140     return DieArray.empty() ? NULL : &DieArray[0];
141   }
142
143   const char *getCompilationDir();
144   uint64_t getDWOId();
145
146   /// setDIERelations - We read in all of the DIE entries into our flat list
147   /// of DIE entries and now we need to go back through all of them and set the
148   /// parent, sibling and child pointers for quick DIE navigation.
149   void setDIERelations();
150
151   void buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
152                               bool clear_dies_if_already_not_parsed,
153                               uint32_t CUOffsetInAranges);
154
155   /// getInlinedChainForAddress - fetches inlined chain for a given address.
156   /// Returns empty chain if there is no subprogram containing address. The
157   /// chain is valid as long as parsed compile unit DIEs are not cleared.
158   DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
159
160 private:
161   /// extractDIEsToVector - Appends all parsed DIEs to a vector.
162   void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
163                            std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const;
164   /// clearDIEs - Clear parsed DIEs to keep memory usage low.
165   void clearDIEs(bool KeepCUDie);
166
167   /// parseDWO - Parses .dwo file for current compile unit. Returns true if
168   /// it was actually constructed.
169   bool parseDWO();
170
171   /// getSubprogramForAddress - Returns subprogram DIE with address range
172   /// encompassing the provided address. The pointer is alive as long as parsed
173   /// compile unit DIEs are not cleared.
174   const DWARFDebugInfoEntryMinimal *getSubprogramForAddress(uint64_t Address);
175 };
176
177 }
178
179 #endif