]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
Update LLDB snapshot to upstream r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / 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 SymbolFileDWARF_DWARFCompileUnit_h_
11 #define SymbolFileDWARF_DWARFCompileUnit_h_
12
13 #include "DWARFDebugInfoEntry.h"
14 #include "SymbolFileDWARF.h"
15
16 class NameToDIE;
17
18 class DWARFCompileUnit
19 {
20 public:
21     enum Producer 
22     {
23         eProducerInvalid = 0,
24         eProducerClang,
25         eProducerGCC,
26         eProducerLLVMGCC,
27         eProcucerOther
28     };
29
30     DWARFCompileUnit(SymbolFileDWARF* dwarf2Data);
31
32     bool        Extract(const lldb_private::DWARFDataExtractor &debug_info, lldb::offset_t *offset_ptr);
33     size_t      ExtractDIEsIfNeeded (bool cu_die_only);
34     bool        LookupAddress(
35                     const dw_addr_t address,
36                     DWARFDebugInfoEntry** function_die,
37                     DWARFDebugInfoEntry** block_die);
38
39     size_t      AppendDIEsWithTag (const dw_tag_t tag, DWARFDIECollection& matching_dies, uint32_t depth = UINT32_MAX) const;
40     void        Clear();
41     bool        Verify(lldb_private::Stream *s) const;
42     void        Dump(lldb_private::Stream *s) const;
43     dw_offset_t GetOffset() const { return m_offset; }
44     uint32_t    Size() const { return m_is_dwarf64 ? 23 : 11; /* Size in bytes of the compile unit header */ }
45     bool        ContainsDIEOffset(dw_offset_t die_offset) const { return die_offset >= GetFirstDIEOffset() && die_offset < GetNextCompileUnitOffset(); }
46     dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); }
47     dw_offset_t GetNextCompileUnitOffset() const { return m_offset + m_length + (m_is_dwarf64 ? 12 : 4); }
48     size_t      GetDebugInfoSize() const { return m_length + (m_is_dwarf64 ? 12 : 4) - Size(); /* Size in bytes of the .debug_info data associated with this compile unit. */ }
49     uint32_t    GetLength() const { return m_length; }
50     uint16_t    GetVersion() const { return m_version; }
51     const DWARFAbbreviationDeclarationSet*  GetAbbreviations() const { return m_abbrevs; }
52     dw_offset_t GetAbbrevOffset() const;
53     uint8_t     GetAddressByteSize() const { return m_addr_size; }
54     dw_addr_t   GetBaseAddress() const { return m_base_addr; }
55     void        ClearDIEs(bool keep_compile_unit_die);
56     void        BuildAddressRangeTable (SymbolFileDWARF* dwarf2Data,
57                                         DWARFDebugAranges* debug_aranges);
58
59     void
60     SetBaseAddress(dw_addr_t base_addr)
61     {
62         m_base_addr = base_addr;
63     }
64
65     const DWARFDebugInfoEntry*
66     GetCompileUnitDIEOnly()
67     {
68         ExtractDIEsIfNeeded (true);
69         if (m_die_array.empty())
70             return NULL;
71         return &m_die_array[0];
72     }
73
74     const DWARFDebugInfoEntry*
75     DIE()
76     {
77         ExtractDIEsIfNeeded (false);
78         if (m_die_array.empty())
79             return NULL;
80         return &m_die_array[0];
81     }
82
83     void
84     AddDIE (DWARFDebugInfoEntry& die)
85     {
86         // The average bytes per DIE entry has been seen to be
87         // around 14-20 so lets pre-reserve half of that since
88         // we are now stripping the NULL tags. 
89
90         // Only reserve the memory if we are adding children of
91         // the main compile unit DIE. The compile unit DIE is always
92         // the first entry, so if our size is 1, then we are adding
93         // the first compile unit child DIE and should reserve
94         // the memory.
95         if (m_die_array.empty())
96             m_die_array.reserve(GetDebugInfoSize() / 24);
97         m_die_array.push_back(die);
98     }
99
100     bool
101     HasDIEsParsed () const
102     {
103         return m_die_array.size() > 1;
104     }
105
106     DWARFDebugInfoEntry*
107     GetDIEAtIndexUnchecked (uint32_t idx)
108     {
109         return &m_die_array[idx];
110     }
111
112     DWARFDebugInfoEntry*
113     GetDIEPtr (dw_offset_t die_offset);
114
115     const DWARFDebugInfoEntry*
116     GetDIEPtrContainingOffset (dw_offset_t die_offset);
117
118     static uint8_t
119     GetAddressByteSize(const DWARFCompileUnit* cu);
120
121     static bool
122     IsDWARF64(const DWARFCompileUnit* cu);
123
124     static uint8_t
125     GetDefaultAddressSize();
126
127     static void
128     SetDefaultAddressSize(uint8_t addr_size);
129
130     void *
131     GetUserData() const
132     {
133         return m_user_data;
134     }
135
136     void
137     SetUserData(void *d)
138     {
139         m_user_data = d;
140     }
141
142     bool
143     Supports_DW_AT_APPLE_objc_complete_type ();
144
145     bool
146     DW_AT_decl_file_attributes_are_invalid();
147
148     bool
149     Supports_unnamed_objc_bitfields ();
150
151 //    void
152 //    AddGlobalDIEByIndex (uint32_t die_idx);
153 //
154 //    void
155 //    AddGlobal (const DWARFDebugInfoEntry* die);
156 //
157     void
158     Index (const uint32_t cu_idx,
159            NameToDIE& func_basenames,
160            NameToDIE& func_fullnames,
161            NameToDIE& func_methods,
162            NameToDIE& func_selectors,
163            NameToDIE& objc_class_selectors,
164            NameToDIE& globals,
165            NameToDIE& types,
166            NameToDIE& namespaces);
167
168     const DWARFDebugAranges &
169     GetFunctionAranges ();
170
171     SymbolFileDWARF*
172     GetSymbolFileDWARF () const
173     {
174         return m_dwarf2Data;
175     }
176     
177     Producer
178     GetProducer ();
179     
180     uint32_t
181     GetProducerVersionMajor();
182
183     uint32_t
184     GetProducerVersionMinor();
185     
186     uint32_t
187     GetProducerVersionUpdate();
188
189     bool
190     IsDWARF64() const;
191
192 protected:
193     SymbolFileDWARF*    m_dwarf2Data;
194     const DWARFAbbreviationDeclarationSet *m_abbrevs;
195     void *              m_user_data;
196     DWARFDebugInfoEntry::collection m_die_array;    // The compile unit debug information entry item
197     std::unique_ptr<DWARFDebugAranges> m_func_aranges_ap;   // A table similar to the .debug_aranges table, but this one points to the exact DW_TAG_subprogram DIEs
198     dw_addr_t           m_base_addr;
199     dw_offset_t         m_offset;
200     dw_offset_t         m_length;
201     uint16_t            m_version;
202     uint8_t             m_addr_size;
203     Producer            m_producer;
204     uint32_t            m_producer_version_major;
205     uint32_t            m_producer_version_minor;
206     uint32_t            m_producer_version_update;
207     bool                m_is_dwarf64;
208     
209     void
210     ParseProducerInfo ();
211 private:
212     DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit);
213 };
214
215 #endif  // SymbolFileDWARF_DWARFCompileUnit_h_