97f847962e27362a5f2c6b6311af8b788dfa7a3d
[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 "DWARFDebugAbbrev.h"
14 #include "DWARFDebugInfoEntry.h"
15 #include "DWARFDebugRangeList.h"
16 #include "DWARFRelocMap.h"
17 #include <vector>
18
19 namespace llvm {
20
21 class DWARFDebugAbbrev;
22 class StringRef;
23 class raw_ostream;
24
25 class DWARFCompileUnit {
26   DWARFCompileUnit(DWARFCompileUnit const &) LLVM_DELETED_FUNCTION;
27   DWARFCompileUnit &operator=(DWARFCompileUnit const &) LLVM_DELETED_FUNCTION;
28
29   const DWARFDebugAbbrev *Abbrev;
30   StringRef InfoSection;
31   StringRef AbbrevSection;
32   StringRef RangeSection;
33   StringRef StringSection;
34   StringRef StringOffsetSection;
35   StringRef AddrOffsetSection;
36   const RelocAddrMap *RelocMap;
37   bool isLittleEndian;
38
39   uint32_t Offset;
40   uint32_t Length;
41   uint16_t Version;
42   const DWARFAbbreviationDeclarationSet *Abbrevs;
43   uint8_t AddrSize;
44   uint64_t BaseAddr;
45   // The compile unit debug information entry items.
46   std::vector<DWARFDebugInfoEntryMinimal> DieArray;
47 public:
48
49   DWARFCompileUnit(const DWARFDebugAbbrev *DA, StringRef IS, StringRef AS,
50                    StringRef RS, StringRef SS, StringRef SOS, StringRef AOS,
51                    const RelocAddrMap *M, bool LE) :
52     Abbrev(DA), InfoSection(IS), AbbrevSection(AS),
53     RangeSection(RS), StringSection(SS), StringOffsetSection(SOS),
54     AddrOffsetSection(AOS), RelocMap(M), isLittleEndian(LE) {
55     clear();
56   }
57
58   StringRef getStringSection() const { return StringSection; }
59   StringRef getStringOffsetSection() const { return StringOffsetSection; }
60   StringRef getAddrOffsetSection() const { return AddrOffsetSection; }
61   const RelocAddrMap *getRelocMap() const { return RelocMap; }
62   DataExtractor getDebugInfoExtractor() const;
63
64   bool extract(DataExtractor debug_info, uint32_t* offset_ptr);
65   uint32_t extract(uint32_t offset, DataExtractor debug_info_data,
66                    const DWARFAbbreviationDeclarationSet *abbrevs);
67
68   /// extractDIEsIfNeeded - Parses a compile unit and indexes its DIEs if it
69   /// hasn't already been done. Returns the number of DIEs parsed at this call.
70   size_t extractDIEsIfNeeded(bool CUDieOnly);
71   /// extractRangeList - extracts the range list referenced by this compile
72   /// unit from .debug_ranges section. Returns true on success.
73   /// Requires that compile unit is already extracted.
74   bool extractRangeList(uint32_t RangeListOffset,
75                         DWARFDebugRangeList &RangeList) const;
76   void clear();
77   void dump(raw_ostream &OS);
78   uint32_t getOffset() const { return Offset; }
79   /// Size in bytes of the compile unit header.
80   uint32_t getSize() const { return 11; }
81   bool containsDIEOffset(uint32_t die_offset) const {
82     return die_offset >= getFirstDIEOffset() &&
83       die_offset < getNextCompileUnitOffset();
84   }
85   uint32_t getFirstDIEOffset() const { return Offset + getSize(); }
86   uint32_t getNextCompileUnitOffset() const { return Offset + Length + 4; }
87   /// Size in bytes of the .debug_info data associated with this compile unit.
88   size_t getDebugInfoSize() const { return Length + 4 - getSize(); }
89   uint32_t getLength() const { return Length; }
90   uint16_t getVersion() const { return Version; }
91   const DWARFAbbreviationDeclarationSet *getAbbreviations() const {
92     return Abbrevs;
93   }
94   uint8_t getAddressByteSize() const { return AddrSize; }
95   uint64_t getBaseAddress() const { return BaseAddr; }
96
97   void setBaseAddress(uint64_t base_addr) {
98     BaseAddr = base_addr;
99   }
100
101   const DWARFDebugInfoEntryMinimal *
102   getCompileUnitDIE(bool extract_cu_die_only = true) {
103     extractDIEsIfNeeded(extract_cu_die_only);
104     return DieArray.empty() ? NULL : &DieArray[0];
105   }
106
107   const char *getCompilationDir();
108
109   /// setDIERelations - We read in all of the DIE entries into our flat list
110   /// of DIE entries and now we need to go back through all of them and set the
111   /// parent, sibling and child pointers for quick DIE navigation.
112   void setDIERelations();
113
114   void buildAddressRangeTable(DWARFDebugAranges *debug_aranges,
115                               bool clear_dies_if_already_not_parsed);
116
117   /// getInlinedChainForAddress - fetches inlined chain for a given address.
118   /// Returns empty chain if there is no subprogram containing address. The
119   /// chain is valid as long as parsed compile unit DIEs are not cleared.
120   DWARFDebugInfoEntryInlinedChain getInlinedChainForAddress(uint64_t Address);
121
122 private:
123   /// extractDIEsToVector - Appends all parsed DIEs to a vector.
124   void extractDIEsToVector(bool AppendCUDie, bool AppendNonCUDIEs,
125                            std::vector<DWARFDebugInfoEntryMinimal> &DIEs) const;
126   /// clearDIEs - Clear parsed DIEs to keep memory usage low.
127   void clearDIEs(bool KeepCUDie);
128 };
129
130 }
131
132 #endif