xref: /trueos/contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h (revision 958843c32b7a29741f2e45996b5b3e89f9e108b0)
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;
GetOffset()43     dw_offset_t GetOffset() const { return m_offset; }
Size()44     uint32_t    Size() const { return 11; /* Size in bytes of the compile unit header */ }
ContainsDIEOffset(dw_offset_t die_offset)45     bool        ContainsDIEOffset(dw_offset_t die_offset) const { return die_offset >= GetFirstDIEOffset() && die_offset < GetNextCompileUnitOffset(); }
GetFirstDIEOffset()46     dw_offset_t GetFirstDIEOffset() const { return m_offset + Size(); }
GetNextCompileUnitOffset()47     dw_offset_t GetNextCompileUnitOffset() const { return m_offset + m_length + 4; }
GetDebugInfoSize()48     size_t      GetDebugInfoSize() const { return m_length + 4 - Size(); /* Size in bytes of the .debug_info data associated with this compile unit. */ }
GetLength()49     uint32_t    GetLength() const { return m_length; }
GetVersion()50     uint16_t    GetVersion() const { return m_version; }
GetAbbreviations()51     const DWARFAbbreviationDeclarationSet*  GetAbbreviations() const { return m_abbrevs; }
52     dw_offset_t GetAbbrevOffset() const;
GetAddressByteSize()53     uint8_t     GetAddressByteSize() const { return m_addr_size; }
GetBaseAddress()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                                         bool clear_dies_if_already_not_parsed);
59 
60     void
SetBaseAddress(dw_addr_t base_addr)61     SetBaseAddress(dw_addr_t base_addr)
62     {
63         m_base_addr = base_addr;
64     }
65 
66     const DWARFDebugInfoEntry*
GetCompileUnitDIEOnly()67     GetCompileUnitDIEOnly()
68     {
69         ExtractDIEsIfNeeded (true);
70         if (m_die_array.empty())
71             return NULL;
72         return &m_die_array[0];
73     }
74 
75     const DWARFDebugInfoEntry*
DIE()76     DIE()
77     {
78         ExtractDIEsIfNeeded (false);
79         if (m_die_array.empty())
80             return NULL;
81         return &m_die_array[0];
82     }
83 
84     void
AddDIE(DWARFDebugInfoEntry & die)85     AddDIE (DWARFDebugInfoEntry& die)
86     {
87         // The average bytes per DIE entry has been seen to be
88         // around 14-20 so lets pre-reserve half of that since
89         // we are now stripping the NULL tags.
90 
91         // Only reserve the memory if we are adding children of
92         // the main compile unit DIE. The compile unit DIE is always
93         // the first entry, so if our size is 1, then we are adding
94         // the first compile unit child DIE and should reserve
95         // the memory.
96         if (m_die_array.empty())
97             m_die_array.reserve(GetDebugInfoSize() / 24);
98         m_die_array.push_back(die);
99     }
100 
101     bool
HasDIEsParsed()102     HasDIEsParsed () const
103     {
104         return m_die_array.size() > 1;
105     }
106 
107     DWARFDebugInfoEntry*
GetDIEAtIndexUnchecked(uint32_t idx)108     GetDIEAtIndexUnchecked (uint32_t idx)
109     {
110         return &m_die_array[idx];
111     }
112 
113     DWARFDebugInfoEntry*
114     GetDIEPtr (dw_offset_t die_offset);
115 
116     const DWARFDebugInfoEntry*
117     GetDIEPtrContainingOffset (dw_offset_t die_offset);
118 
119     static uint8_t
120     GetAddressByteSize(const DWARFCompileUnit* cu);
121 
122     static uint8_t
123     GetDefaultAddressSize();
124 
125     static void
126     SetDefaultAddressSize(uint8_t addr_size);
127 
128     void *
GetUserData()129     GetUserData() const
130     {
131         return m_user_data;
132     }
133 
134     void
SetUserData(void * d)135     SetUserData(void *d)
136     {
137         m_user_data = d;
138     }
139 
140     bool
141     Supports_DW_AT_APPLE_objc_complete_type ();
142 
143     bool
144     DW_AT_decl_file_attributes_are_invalid();
145 
146     bool
147     Supports_unnamed_objc_bitfields ();
148 
149 //    void
150 //    AddGlobalDIEByIndex (uint32_t die_idx);
151 //
152 //    void
153 //    AddGlobal (const DWARFDebugInfoEntry* die);
154 //
155     void
156     Index (const uint32_t cu_idx,
157            NameToDIE& func_basenames,
158            NameToDIE& func_fullnames,
159            NameToDIE& func_methods,
160            NameToDIE& func_selectors,
161            NameToDIE& objc_class_selectors,
162            NameToDIE& globals,
163            NameToDIE& types,
164            NameToDIE& namespaces);
165 
166     const DWARFDebugAranges &
167     GetFunctionAranges ();
168 
169     SymbolFileDWARF*
GetSymbolFileDWARF()170     GetSymbolFileDWARF () const
171     {
172         return m_dwarf2Data;
173     }
174 
175     Producer
176     GetProducer ();
177 
178     uint32_t
179     GetProducerVersionMajor();
180 
181     uint32_t
182     GetProducerVersionMinor();
183 
184     uint32_t
185     GetProducerVersionUpdate();
186 
187 protected:
188     SymbolFileDWARF*    m_dwarf2Data;
189     const DWARFAbbreviationDeclarationSet *m_abbrevs;
190     void *              m_user_data;
191     DWARFDebugInfoEntry::collection m_die_array;    // The compile unit debug information entry item
192     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
193     dw_addr_t           m_base_addr;
194     dw_offset_t         m_offset;
195     uint32_t            m_length;
196     uint16_t            m_version;
197     uint8_t             m_addr_size;
198     Producer            m_producer;
199     uint32_t            m_producer_version_major;
200     uint32_t            m_producer_version_minor;
201     uint32_t            m_producer_version_update;
202 
203     void
204     ParseProducerInfo ();
205 private:
206     DISALLOW_COPY_AND_ASSIGN (DWARFCompileUnit);
207 };
208 
209 #endif  // SymbolFileDWARF_DWARFCompileUnit_h_
210