File: | tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp |
Warning: | line 371, column 15 Null pointer passed as an argument to a 'nonnull' parameter |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===-- DWARFASTParserClang.cpp ---------------------------------*- 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 | #include <stdlib.h> | |||
11 | ||||
12 | #include "DWARFASTParserClang.h" | |||
13 | #include "DWARFDIE.h" | |||
14 | #include "DWARFDIECollection.h" | |||
15 | #include "DWARFDebugInfo.h" | |||
16 | #include "DWARFDeclContext.h" | |||
17 | #include "DWARFDefines.h" | |||
18 | #include "SymbolFileDWARF.h" | |||
19 | #include "SymbolFileDWARFDwo.h" | |||
20 | #include "SymbolFileDWARFDebugMap.h" | |||
21 | #include "UniqueDWARFASTType.h" | |||
22 | ||||
23 | #include "Plugins/Language/ObjC/ObjCLanguage.h" | |||
24 | #include "lldb/Core/Module.h" | |||
25 | #include "lldb/Core/Value.h" | |||
26 | #include "lldb/Host/Host.h" | |||
27 | #include "lldb/Symbol/ClangASTImporter.h" | |||
28 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" | |||
29 | #include "lldb/Symbol/ClangUtil.h" | |||
30 | #include "lldb/Symbol/CompileUnit.h" | |||
31 | #include "lldb/Symbol/Function.h" | |||
32 | #include "lldb/Symbol/ObjectFile.h" | |||
33 | #include "lldb/Symbol/SymbolVendor.h" | |||
34 | #include "lldb/Symbol/TypeList.h" | |||
35 | #include "lldb/Symbol/TypeMap.h" | |||
36 | #include "lldb/Target/Language.h" | |||
37 | #include "lldb/Utility/LLDBAssert.h" | |||
38 | #include "lldb/Utility/Log.h" | |||
39 | #include "lldb/Utility/StreamString.h" | |||
40 | ||||
41 | #include "clang/AST/CXXInheritance.h" | |||
42 | #include "clang/AST/DeclCXX.h" | |||
43 | #include "clang/AST/DeclObjC.h" | |||
44 | ||||
45 | #include <map> | |||
46 | #include <vector> | |||
47 | ||||
48 | //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN | |||
49 | ||||
50 | #ifdef ENABLE_DEBUG_PRINTF | |||
51 | #include <stdio.h> | |||
52 | #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__) | |||
53 | #else | |||
54 | #define DEBUG_PRINTF(fmt, ...) | |||
55 | #endif | |||
56 | ||||
57 | using namespace lldb; | |||
58 | using namespace lldb_private; | |||
59 | DWARFASTParserClang::DWARFASTParserClang(ClangASTContext &ast) | |||
60 | : m_ast(ast), m_die_to_decl_ctx(), m_decl_ctx_to_die() {} | |||
61 | ||||
62 | DWARFASTParserClang::~DWARFASTParserClang() {} | |||
63 | ||||
64 | static AccessType DW_ACCESS_to_AccessType(uint32_t dwarf_accessibility) { | |||
65 | switch (dwarf_accessibility) { | |||
66 | case DW_ACCESS_public: | |||
67 | return eAccessPublic; | |||
68 | case DW_ACCESS_private: | |||
69 | return eAccessPrivate; | |||
70 | case DW_ACCESS_protected: | |||
71 | return eAccessProtected; | |||
72 | default: | |||
73 | break; | |||
74 | } | |||
75 | return eAccessNone; | |||
76 | } | |||
77 | ||||
78 | static bool DeclKindIsCXXClass(clang::Decl::Kind decl_kind) { | |||
79 | switch (decl_kind) { | |||
80 | case clang::Decl::CXXRecord: | |||
81 | case clang::Decl::ClassTemplateSpecialization: | |||
82 | return true; | |||
83 | default: | |||
84 | break; | |||
85 | } | |||
86 | return false; | |||
87 | } | |||
88 | ||||
89 | struct BitfieldInfo { | |||
90 | uint64_t bit_size; | |||
91 | uint64_t bit_offset; | |||
92 | ||||
93 | BitfieldInfo() | |||
94 | : bit_size(LLDB_INVALID_ADDRESS(18446744073709551615UL)), bit_offset(LLDB_INVALID_ADDRESS(18446744073709551615UL)) {} | |||
95 | ||||
96 | void Clear() { | |||
97 | bit_size = LLDB_INVALID_ADDRESS(18446744073709551615UL); | |||
98 | bit_offset = LLDB_INVALID_ADDRESS(18446744073709551615UL); | |||
99 | } | |||
100 | ||||
101 | bool IsValid() const { | |||
102 | return (bit_size != LLDB_INVALID_ADDRESS(18446744073709551615UL)) && | |||
103 | (bit_offset != LLDB_INVALID_ADDRESS(18446744073709551615UL)); | |||
104 | } | |||
105 | ||||
106 | bool NextBitfieldOffsetIsValid(const uint64_t next_bit_offset) const { | |||
107 | if (IsValid()) { | |||
108 | // This bitfield info is valid, so any subsequent bitfields | |||
109 | // must not overlap and must be at a higher bit offset than | |||
110 | // any previous bitfield + size. | |||
111 | return (bit_size + bit_offset) <= next_bit_offset; | |||
112 | } else { | |||
113 | // If the this BitfieldInfo is not valid, then any offset isOK | |||
114 | return true; | |||
115 | } | |||
116 | } | |||
117 | }; | |||
118 | ||||
119 | ClangASTImporter &DWARFASTParserClang::GetClangASTImporter() { | |||
120 | if (!m_clang_ast_importer_ap) { | |||
121 | m_clang_ast_importer_ap.reset(new ClangASTImporter); | |||
122 | } | |||
123 | return *m_clang_ast_importer_ap; | |||
124 | } | |||
125 | ||||
126 | /// Detect a forward declaration that is nested in a DW_TAG_module. | |||
127 | static bool isClangModuleFwdDecl(const DWARFDIE &Die) { | |||
128 | if (!Die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0)) | |||
129 | return false; | |||
130 | auto Parent = Die.GetParent(); | |||
131 | while (Parent.IsValid()) { | |||
132 | if (Parent.Tag() == DW_TAG_module) | |||
133 | return true; | |||
134 | Parent = Parent.GetParent(); | |||
135 | } | |||
136 | return false; | |||
137 | } | |||
138 | ||||
139 | TypeSP DWARFASTParserClang::ParseTypeFromDWO(const DWARFDIE &die, Log *log) { | |||
140 | ModuleSP dwo_module_sp = die.GetContainingDWOModule(); | |||
141 | if (!dwo_module_sp) | |||
142 | return TypeSP(); | |||
143 | ||||
144 | // This type comes from an external DWO module. | |||
145 | std::vector<CompilerContext> dwo_context; | |||
146 | die.GetDWOContext(dwo_context); | |||
147 | TypeMap dwo_types; | |||
148 | ||||
149 | if (!dwo_module_sp->GetSymbolVendor()->FindTypes(dwo_context, true, | |||
150 | dwo_types)) { | |||
151 | if (!isClangModuleFwdDecl(die)) | |||
152 | return TypeSP(); | |||
153 | ||||
154 | // Since this this type is defined in one of the Clang modules | |||
155 | // imported by this symbol file, search all of them. | |||
156 | auto *SymFile = die.GetCU()->GetSymbolFileDWARF(); | |||
157 | for (const auto &NameModule : SymFile->getExternalTypeModules()) { | |||
158 | if (!NameModule.second) | |||
159 | continue; | |||
160 | SymbolVendor *SymVendor = NameModule.second->GetSymbolVendor(); | |||
161 | if (SymVendor->FindTypes(dwo_context, true, dwo_types)) | |||
162 | break; | |||
163 | } | |||
164 | } | |||
165 | ||||
166 | const size_t num_dwo_types = dwo_types.GetSize(); | |||
167 | if (num_dwo_types != 1) | |||
168 | return TypeSP(); | |||
169 | ||||
170 | // We found a real definition for this type in the Clang module, so | |||
171 | // lets use it and cache the fact that we found a complete type for | |||
172 | // this die. | |||
173 | TypeSP dwo_type_sp = dwo_types.GetTypeAtIndex(0); | |||
174 | if (!dwo_type_sp) | |||
175 | return TypeSP(); | |||
176 | ||||
177 | lldb_private::CompilerType dwo_type = dwo_type_sp->GetForwardCompilerType(); | |||
178 | ||||
179 | lldb_private::CompilerType type = | |||
180 | GetClangASTImporter().CopyType(m_ast, dwo_type); | |||
181 | ||||
182 | // printf ("copied_qual_type: ast = %p, clang_type = %p, name = | |||
183 | // '%s'\n", m_ast, copied_qual_type.getAsOpaquePtr(), | |||
184 | // external_type->GetName().GetCString()); | |||
185 | if (!type) | |||
186 | return TypeSP(); | |||
187 | ||||
188 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
189 | TypeSP type_sp(new Type( | |||
190 | die.GetID(), dwarf, dwo_type_sp->GetName(), dwo_type_sp->GetByteSize(), | |||
191 | NULL__null, LLDB_INVALID_UID(18446744073709551615UL), Type::eEncodingInvalid, | |||
192 | &dwo_type_sp->GetDeclaration(), type, Type::eResolveStateForward)); | |||
193 | ||||
194 | dwarf->GetTypeList()->Insert(type_sp); | |||
195 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); | |||
196 | clang::TagDecl *tag_decl = ClangASTContext::GetAsTagDecl(type); | |||
197 | if (tag_decl) | |||
198 | LinkDeclContextToDIE(tag_decl, die); | |||
199 | else { | |||
200 | clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(die); | |||
201 | if (defn_decl_ctx) | |||
202 | LinkDeclContextToDIE(defn_decl_ctx, die); | |||
203 | } | |||
204 | ||||
205 | return type_sp; | |||
206 | } | |||
207 | ||||
208 | TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc, | |||
209 | const DWARFDIE &die, Log *log, | |||
210 | bool *type_is_new_ptr) { | |||
211 | TypeSP type_sp; | |||
212 | ||||
213 | if (type_is_new_ptr) | |||
| ||||
214 | *type_is_new_ptr = false; | |||
215 | ||||
216 | AccessType accessibility = eAccessNone; | |||
217 | if (die) { | |||
218 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
219 | if (log) { | |||
220 | DWARFDIE context_die; | |||
221 | clang::DeclContext *context = | |||
222 | GetClangDeclContextContainingDIE(die, &context_die); | |||
223 | ||||
224 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
225 | log, "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die " | |||
226 | "0x%8.8x)) %s name = '%s')", | |||
227 | die.GetOffset(), static_cast<void *>(context), | |||
228 | context_die.GetOffset(), die.GetTagAsCString(), die.GetName()); | |||
229 | } | |||
230 | // | |||
231 | // Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | |||
232 | // if (log && dwarf_cu) | |||
233 | // { | |||
234 | // StreamString s; | |||
235 | // die->DumpLocation (this, dwarf_cu, s); | |||
236 | // dwarf->GetObjectFile()->GetModule()->LogMessage (log, | |||
237 | // "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData()); | |||
238 | // | |||
239 | // } | |||
240 | ||||
241 | Type *type_ptr = dwarf->GetDIEToType().lookup(die.GetDIE()); | |||
242 | TypeList *type_list = dwarf->GetTypeList(); | |||
243 | if (type_ptr == NULL__null) { | |||
244 | if (type_is_new_ptr) | |||
245 | *type_is_new_ptr = true; | |||
246 | ||||
247 | const dw_tag_t tag = die.Tag(); | |||
248 | ||||
249 | bool is_forward_declaration = false; | |||
250 | DWARFAttributes attributes; | |||
251 | const char *type_name_cstr = NULL__null; | |||
252 | ConstString type_name_const_str; | |||
253 | Type::ResolveState resolve_state = Type::eResolveStateUnresolved; | |||
254 | uint64_t byte_size = 0; | |||
255 | Declaration decl; | |||
256 | ||||
257 | Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID; | |||
258 | CompilerType clang_type; | |||
259 | DWARFFormValue form_value; | |||
260 | ||||
261 | dw_attr_t attr; | |||
262 | ||||
263 | switch (tag) { | |||
264 | case DW_TAG_typedef: | |||
265 | case DW_TAG_base_type: | |||
266 | case DW_TAG_pointer_type: | |||
267 | case DW_TAG_reference_type: | |||
268 | case DW_TAG_rvalue_reference_type: | |||
269 | case DW_TAG_const_type: | |||
270 | case DW_TAG_restrict_type: | |||
271 | case DW_TAG_volatile_type: | |||
272 | case DW_TAG_unspecified_type: { | |||
273 | // Set a bit that lets us know that we are currently parsing this | |||
274 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED((lldb_private::Type *)1); | |||
275 | ||||
276 | const size_t num_attributes = die.GetAttributes(attributes); | |||
277 | uint32_t encoding = 0; | |||
278 | DWARFFormValue encoding_uid; | |||
279 | ||||
280 | if (num_attributes > 0) { | |||
281 | uint32_t i; | |||
282 | for (i = 0; i < num_attributes; ++i) { | |||
283 | attr = attributes.AttributeAtIndex(i); | |||
284 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
285 | switch (attr) { | |||
286 | case DW_AT_decl_file: | |||
287 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
288 | form_value.Unsigned())); | |||
289 | break; | |||
290 | case DW_AT_decl_line: | |||
291 | decl.SetLine(form_value.Unsigned()); | |||
292 | break; | |||
293 | case DW_AT_decl_column: | |||
294 | decl.SetColumn(form_value.Unsigned()); | |||
295 | break; | |||
296 | case DW_AT_name: | |||
297 | ||||
298 | type_name_cstr = form_value.AsCString(); | |||
299 | // Work around a bug in llvm-gcc where they give a name to a | |||
300 | // reference type which doesn't | |||
301 | // include the "&"... | |||
302 | if (tag == DW_TAG_reference_type) { | |||
303 | if (strchr(type_name_cstr, '&') == NULL__null) | |||
304 | type_name_cstr = NULL__null; | |||
305 | } | |||
306 | if (type_name_cstr) | |||
307 | type_name_const_str.SetCString(type_name_cstr); | |||
308 | break; | |||
309 | case DW_AT_byte_size: | |||
310 | byte_size = form_value.Unsigned(); | |||
311 | break; | |||
312 | case DW_AT_encoding: | |||
313 | encoding = form_value.Unsigned(); | |||
314 | break; | |||
315 | case DW_AT_type: | |||
316 | encoding_uid = form_value; | |||
317 | break; | |||
318 | default: | |||
319 | case DW_AT_sibling: | |||
320 | break; | |||
321 | } | |||
322 | } | |||
323 | } | |||
324 | } | |||
325 | ||||
326 | if (tag == DW_TAG_typedef && encoding_uid.IsValid()) { | |||
327 | // Try to parse a typedef from the DWO file first as modules | |||
328 | // can contain typedef'ed structures that have no names like: | |||
329 | // | |||
330 | // typedef struct { int a; } Foo; | |||
331 | // | |||
332 | // In this case we will have a structure with no name and a | |||
333 | // typedef named "Foo" that points to this unnamed structure. | |||
334 | // The name in the typedef is the only identifier for the struct, | |||
335 | // so always try to get typedefs from DWO files if possible. | |||
336 | // | |||
337 | // The type_sp returned will be empty if the typedef doesn't exist | |||
338 | // in a DWO file, so it is cheap to call this function just to check. | |||
339 | // | |||
340 | // If we don't do this we end up creating a TypeSP that says this | |||
341 | // is a typedef to type 0x123 (the DW_AT_type value would be 0x123 | |||
342 | // in the DW_TAG_typedef), and this is the unnamed structure type. | |||
343 | // We will have a hard time tracking down an unnammed structure | |||
344 | // type in the module DWO file, so we make sure we don't get into | |||
345 | // this situation by always resolving typedefs from the DWO file. | |||
346 | const DWARFDIE encoding_die = dwarf->GetDIE(DIERef(encoding_uid)); | |||
347 | ||||
348 | // First make sure that the die that this is typedef'ed to _is_ | |||
349 | // just a declaration (DW_AT_declaration == 1), not a full definition | |||
350 | // since template types can't be represented in modules since only | |||
351 | // concrete instances of templates are ever emitted and modules | |||
352 | // won't contain those | |||
353 | if (encoding_die && | |||
354 | encoding_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == | |||
355 | 1) { | |||
356 | type_sp = ParseTypeFromDWO(die, log); | |||
357 | if (type_sp) | |||
358 | return type_sp; | |||
359 | } | |||
360 | } | |||
361 | ||||
362 | DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\") type => 0x%8.8lx\n", | |||
363 | die.GetID(), DW_TAG_value_to_name(tag), type_name_cstr, | |||
364 | encoding_uid.Reference()); | |||
365 | ||||
366 | switch (tag) { | |||
367 | default: | |||
368 | break; | |||
369 | ||||
370 | case DW_TAG_unspecified_type: | |||
371 | if (strcmp(type_name_cstr, "nullptr_t") == 0 || | |||
| ||||
372 | strcmp(type_name_cstr, "decltype(nullptr)") == 0) { | |||
373 | resolve_state = Type::eResolveStateFull; | |||
374 | clang_type = m_ast.GetBasicType(eBasicTypeNullPtr); | |||
375 | break; | |||
376 | } | |||
377 | // Fall through to base type below in case we can handle the type | |||
378 | // there... | |||
379 | LLVM_FALLTHROUGH[[clang::fallthrough]]; | |||
380 | ||||
381 | case DW_TAG_base_type: | |||
382 | resolve_state = Type::eResolveStateFull; | |||
383 | clang_type = m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize( | |||
384 | type_name_cstr, encoding, byte_size * 8); | |||
385 | break; | |||
386 | ||||
387 | case DW_TAG_pointer_type: | |||
388 | encoding_data_type = Type::eEncodingIsPointerUID; | |||
389 | break; | |||
390 | case DW_TAG_reference_type: | |||
391 | encoding_data_type = Type::eEncodingIsLValueReferenceUID; | |||
392 | break; | |||
393 | case DW_TAG_rvalue_reference_type: | |||
394 | encoding_data_type = Type::eEncodingIsRValueReferenceUID; | |||
395 | break; | |||
396 | case DW_TAG_typedef: | |||
397 | encoding_data_type = Type::eEncodingIsTypedefUID; | |||
398 | break; | |||
399 | case DW_TAG_const_type: | |||
400 | encoding_data_type = Type::eEncodingIsConstUID; | |||
401 | break; | |||
402 | case DW_TAG_restrict_type: | |||
403 | encoding_data_type = Type::eEncodingIsRestrictUID; | |||
404 | break; | |||
405 | case DW_TAG_volatile_type: | |||
406 | encoding_data_type = Type::eEncodingIsVolatileUID; | |||
407 | break; | |||
408 | } | |||
409 | ||||
410 | if (!clang_type && | |||
411 | (encoding_data_type == Type::eEncodingIsPointerUID || | |||
412 | encoding_data_type == Type::eEncodingIsTypedefUID) && | |||
413 | sc.comp_unit != NULL__null) { | |||
414 | if (tag == DW_TAG_pointer_type) { | |||
415 | DWARFDIE target_die = die.GetReferencedDIE(DW_AT_type); | |||
416 | ||||
417 | if (target_die.GetAttributeValueAsUnsigned(DW_AT_APPLE_block, 0)) { | |||
418 | // Blocks have a __FuncPtr inside them which is a pointer to a | |||
419 | // function of the proper type. | |||
420 | ||||
421 | for (DWARFDIE child_die = target_die.GetFirstChild(); | |||
422 | child_die.IsValid(); child_die = child_die.GetSibling()) { | |||
423 | if (!strcmp(child_die.GetAttributeValueAsString(DW_AT_name, ""), | |||
424 | "__FuncPtr")) { | |||
425 | DWARFDIE function_pointer_type = | |||
426 | child_die.GetReferencedDIE(DW_AT_type); | |||
427 | ||||
428 | if (function_pointer_type) { | |||
429 | DWARFDIE function_type = | |||
430 | function_pointer_type.GetReferencedDIE(DW_AT_type); | |||
431 | ||||
432 | bool function_type_is_new_pointer; | |||
433 | TypeSP lldb_function_type_sp = ParseTypeFromDWARF( | |||
434 | sc, function_type, log, &function_type_is_new_pointer); | |||
435 | ||||
436 | if (lldb_function_type_sp) { | |||
437 | clang_type = m_ast.CreateBlockPointerType( | |||
438 | lldb_function_type_sp->GetForwardCompilerType()); | |||
439 | encoding_data_type = Type::eEncodingIsUID; | |||
440 | encoding_uid.Clear(); | |||
441 | resolve_state = Type::eResolveStateFull; | |||
442 | } | |||
443 | } | |||
444 | ||||
445 | break; | |||
446 | } | |||
447 | } | |||
448 | } | |||
449 | } | |||
450 | ||||
451 | bool translation_unit_is_objc = | |||
452 | (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || | |||
453 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus); | |||
454 | ||||
455 | if (translation_unit_is_objc) { | |||
456 | if (type_name_cstr != NULL__null) { | |||
457 | static ConstString g_objc_type_name_id("id"); | |||
458 | static ConstString g_objc_type_name_Class("Class"); | |||
459 | static ConstString g_objc_type_name_selector("SEL"); | |||
460 | ||||
461 | if (type_name_const_str == g_objc_type_name_id) { | |||
462 | if (log) | |||
463 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
464 | log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' " | |||
465 | "is Objective C 'id' built-in type.", | |||
466 | die.GetOffset(), die.GetTagAsCString(), die.GetName()); | |||
467 | clang_type = m_ast.GetBasicType(eBasicTypeObjCID); | |||
468 | encoding_data_type = Type::eEncodingIsUID; | |||
469 | encoding_uid.Clear(); | |||
470 | resolve_state = Type::eResolveStateFull; | |||
471 | ||||
472 | } else if (type_name_const_str == g_objc_type_name_Class) { | |||
473 | if (log) | |||
474 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
475 | log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' " | |||
476 | "is Objective C 'Class' built-in type.", | |||
477 | die.GetOffset(), die.GetTagAsCString(), die.GetName()); | |||
478 | clang_type = m_ast.GetBasicType(eBasicTypeObjCClass); | |||
479 | encoding_data_type = Type::eEncodingIsUID; | |||
480 | encoding_uid.Clear(); | |||
481 | resolve_state = Type::eResolveStateFull; | |||
482 | } else if (type_name_const_str == g_objc_type_name_selector) { | |||
483 | if (log) | |||
484 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
485 | log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' " | |||
486 | "is Objective C 'selector' built-in type.", | |||
487 | die.GetOffset(), die.GetTagAsCString(), die.GetName()); | |||
488 | clang_type = m_ast.GetBasicType(eBasicTypeObjCSel); | |||
489 | encoding_data_type = Type::eEncodingIsUID; | |||
490 | encoding_uid.Clear(); | |||
491 | resolve_state = Type::eResolveStateFull; | |||
492 | } | |||
493 | } else if (encoding_data_type == Type::eEncodingIsPointerUID && | |||
494 | encoding_uid.IsValid()) { | |||
495 | // Clang sometimes erroneously emits id as objc_object*. In that | |||
496 | // case we fix up the type to "id". | |||
497 | ||||
498 | const DWARFDIE encoding_die = dwarf->GetDIE(DIERef(encoding_uid)); | |||
499 | ||||
500 | if (encoding_die && encoding_die.Tag() == DW_TAG_structure_type) { | |||
501 | if (const char *struct_name = encoding_die.GetName()) { | |||
502 | if (!strcmp(struct_name, "objc_object")) { | |||
503 | if (log) | |||
504 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
505 | log, "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s " | |||
506 | "'%s' is 'objc_object*', which we overrode to " | |||
507 | "'id'.", | |||
508 | die.GetOffset(), die.GetTagAsCString(), | |||
509 | die.GetName()); | |||
510 | clang_type = m_ast.GetBasicType(eBasicTypeObjCID); | |||
511 | encoding_data_type = Type::eEncodingIsUID; | |||
512 | encoding_uid.Clear(); | |||
513 | resolve_state = Type::eResolveStateFull; | |||
514 | } | |||
515 | } | |||
516 | } | |||
517 | } | |||
518 | } | |||
519 | } | |||
520 | ||||
521 | type_sp.reset( | |||
522 | new Type(die.GetID(), dwarf, type_name_const_str, byte_size, NULL__null, | |||
523 | DIERef(encoding_uid).GetUID(dwarf), encoding_data_type, | |||
524 | &decl, clang_type, resolve_state)); | |||
525 | ||||
526 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); | |||
527 | ||||
528 | // Type* encoding_type = | |||
529 | // GetUniquedTypeForDIEOffset(encoding_uid, type_sp, | |||
530 | // NULL, 0, 0, false); | |||
531 | // if (encoding_type != NULL) | |||
532 | // { | |||
533 | // if (encoding_type != DIE_IS_BEING_PARSED) | |||
534 | // type_sp->SetEncodingType(encoding_type); | |||
535 | // else | |||
536 | // m_indirect_fixups.push_back(type_sp.get()); | |||
537 | // } | |||
538 | } break; | |||
539 | ||||
540 | case DW_TAG_structure_type: | |||
541 | case DW_TAG_union_type: | |||
542 | case DW_TAG_class_type: { | |||
543 | // Set a bit that lets us know that we are currently parsing this | |||
544 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED((lldb_private::Type *)1); | |||
545 | bool byte_size_valid = false; | |||
546 | ||||
547 | LanguageType class_language = eLanguageTypeUnknown; | |||
548 | bool is_complete_objc_class = false; | |||
549 | // bool struct_is_class = false; | |||
550 | const size_t num_attributes = die.GetAttributes(attributes); | |||
551 | if (num_attributes > 0) { | |||
552 | uint32_t i; | |||
553 | for (i = 0; i < num_attributes; ++i) { | |||
554 | attr = attributes.AttributeAtIndex(i); | |||
555 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
556 | switch (attr) { | |||
557 | case DW_AT_decl_file: | |||
558 | if (die.GetCU()->DW_AT_decl_file_attributes_are_invalid()) { | |||
559 | // llvm-gcc outputs invalid DW_AT_decl_file attributes that | |||
560 | // always | |||
561 | // point to the compile unit file, so we clear this invalid | |||
562 | // value | |||
563 | // so that we can still unique types efficiently. | |||
564 | decl.SetFile(FileSpec("<invalid>", false)); | |||
565 | } else | |||
566 | decl.SetFile( | |||
567 | sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
568 | form_value.Unsigned())); | |||
569 | break; | |||
570 | ||||
571 | case DW_AT_decl_line: | |||
572 | decl.SetLine(form_value.Unsigned()); | |||
573 | break; | |||
574 | ||||
575 | case DW_AT_decl_column: | |||
576 | decl.SetColumn(form_value.Unsigned()); | |||
577 | break; | |||
578 | ||||
579 | case DW_AT_name: | |||
580 | type_name_cstr = form_value.AsCString(); | |||
581 | type_name_const_str.SetCString(type_name_cstr); | |||
582 | break; | |||
583 | ||||
584 | case DW_AT_byte_size: | |||
585 | byte_size = form_value.Unsigned(); | |||
586 | byte_size_valid = true; | |||
587 | break; | |||
588 | ||||
589 | case DW_AT_accessibility: | |||
590 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | |||
591 | break; | |||
592 | ||||
593 | case DW_AT_declaration: | |||
594 | is_forward_declaration = form_value.Boolean(); | |||
595 | break; | |||
596 | ||||
597 | case DW_AT_APPLE_runtime_class: | |||
598 | class_language = (LanguageType)form_value.Signed(); | |||
599 | break; | |||
600 | ||||
601 | case DW_AT_APPLE_objc_complete_type: | |||
602 | is_complete_objc_class = form_value.Signed(); | |||
603 | break; | |||
604 | ||||
605 | case DW_AT_allocated: | |||
606 | case DW_AT_associated: | |||
607 | case DW_AT_data_location: | |||
608 | case DW_AT_description: | |||
609 | case DW_AT_start_scope: | |||
610 | case DW_AT_visibility: | |||
611 | default: | |||
612 | case DW_AT_sibling: | |||
613 | break; | |||
614 | } | |||
615 | } | |||
616 | } | |||
617 | } | |||
618 | ||||
619 | // UniqueDWARFASTType is large, so don't create a local variables on the | |||
620 | // stack, put it on the heap. This function is often called recursively | |||
621 | // and clang isn't good and sharing the stack space for variables in | |||
622 | // different blocks. | |||
623 | std::unique_ptr<UniqueDWARFASTType> unique_ast_entry_ap( | |||
624 | new UniqueDWARFASTType()); | |||
625 | ||||
626 | ConstString unique_typename(type_name_const_str); | |||
627 | Declaration unique_decl(decl); | |||
628 | ||||
629 | if (type_name_const_str) { | |||
630 | LanguageType die_language = die.GetLanguage(); | |||
631 | if (Language::LanguageIsCPlusPlus(die_language)) { | |||
632 | // For C++, we rely solely upon the one definition rule that says | |||
633 | // only | |||
634 | // one thing can exist at a given decl context. We ignore the file | |||
635 | // and | |||
636 | // line that things are declared on. | |||
637 | std::string qualified_name; | |||
638 | if (die.GetQualifiedName(qualified_name)) | |||
639 | unique_typename = ConstString(qualified_name); | |||
640 | unique_decl.Clear(); | |||
641 | } | |||
642 | ||||
643 | if (dwarf->GetUniqueDWARFASTTypeMap().Find( | |||
644 | unique_typename, die, unique_decl, | |||
645 | byte_size_valid ? byte_size : -1, *unique_ast_entry_ap)) { | |||
646 | type_sp = unique_ast_entry_ap->m_type_sp; | |||
647 | if (type_sp) { | |||
648 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); | |||
649 | return type_sp; | |||
650 | } | |||
651 | } | |||
652 | } | |||
653 | ||||
654 | DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), | |||
655 | DW_TAG_value_to_name(tag), type_name_cstr); | |||
656 | ||||
657 | int tag_decl_kind = -1; | |||
658 | AccessType default_accessibility = eAccessNone; | |||
659 | if (tag == DW_TAG_structure_type) { | |||
660 | tag_decl_kind = clang::TTK_Struct; | |||
661 | default_accessibility = eAccessPublic; | |||
662 | } else if (tag == DW_TAG_union_type) { | |||
663 | tag_decl_kind = clang::TTK_Union; | |||
664 | default_accessibility = eAccessPublic; | |||
665 | } else if (tag == DW_TAG_class_type) { | |||
666 | tag_decl_kind = clang::TTK_Class; | |||
667 | default_accessibility = eAccessPrivate; | |||
668 | } | |||
669 | ||||
670 | if (byte_size_valid && byte_size == 0 && type_name_cstr && | |||
671 | die.HasChildren() == false && | |||
672 | sc.comp_unit->GetLanguage() == eLanguageTypeObjC) { | |||
673 | // Work around an issue with clang at the moment where | |||
674 | // forward declarations for objective C classes are emitted | |||
675 | // as: | |||
676 | // DW_TAG_structure_type [2] | |||
677 | // DW_AT_name( "ForwardObjcClass" ) | |||
678 | // DW_AT_byte_size( 0x00 ) | |||
679 | // DW_AT_decl_file( "..." ) | |||
680 | // DW_AT_decl_line( 1 ) | |||
681 | // | |||
682 | // Note that there is no DW_AT_declaration and there are | |||
683 | // no children, and the byte size is zero. | |||
684 | is_forward_declaration = true; | |||
685 | } | |||
686 | ||||
687 | if (class_language == eLanguageTypeObjC || | |||
688 | class_language == eLanguageTypeObjC_plus_plus) { | |||
689 | if (!is_complete_objc_class && | |||
690 | die.Supports_DW_AT_APPLE_objc_complete_type()) { | |||
691 | // We have a valid eSymbolTypeObjCClass class symbol whose | |||
692 | // name matches the current objective C class that we | |||
693 | // are trying to find and this DIE isn't the complete | |||
694 | // definition (we checked is_complete_objc_class above and | |||
695 | // know it is false), so the real definition is in here somewhere | |||
696 | type_sp = dwarf->FindCompleteObjCDefinitionTypeForDIE( | |||
697 | die, type_name_const_str, true); | |||
698 | ||||
699 | if (!type_sp) { | |||
700 | SymbolFileDWARFDebugMap *debug_map_symfile = | |||
701 | dwarf->GetDebugMapSymfile(); | |||
702 | if (debug_map_symfile) { | |||
703 | // We weren't able to find a full declaration in | |||
704 | // this DWARF, see if we have a declaration anywhere | |||
705 | // else... | |||
706 | type_sp = | |||
707 | debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE( | |||
708 | die, type_name_const_str, true); | |||
709 | } | |||
710 | } | |||
711 | ||||
712 | if (type_sp) { | |||
713 | if (log) { | |||
714 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
715 | log, "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an " | |||
716 | "incomplete objc type, complete type is 0x%8.8" PRIx64"l" "x", | |||
717 | static_cast<void *>(this), die.GetOffset(), | |||
718 | DW_TAG_value_to_name(tag), type_name_cstr, | |||
719 | type_sp->GetID()); | |||
720 | } | |||
721 | ||||
722 | // We found a real definition for this type elsewhere | |||
723 | // so lets use it and cache the fact that we found | |||
724 | // a complete type for this die | |||
725 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); | |||
726 | return type_sp; | |||
727 | } | |||
728 | } | |||
729 | } | |||
730 | ||||
731 | if (is_forward_declaration) { | |||
732 | // We have a forward declaration to a type and we need | |||
733 | // to try and find a full declaration. We look in the | |||
734 | // current type index just in case we have a forward | |||
735 | // declaration followed by an actual declarations in the | |||
736 | // DWARF. If this fails, we need to look elsewhere... | |||
737 | if (log) { | |||
738 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
739 | log, "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a " | |||
740 | "forward declaration, trying to find complete type", | |||
741 | static_cast<void *>(this), die.GetOffset(), | |||
742 | DW_TAG_value_to_name(tag), type_name_cstr); | |||
743 | } | |||
744 | ||||
745 | // See if the type comes from a DWO module and if so, track down that | |||
746 | // type. | |||
747 | type_sp = ParseTypeFromDWO(die, log); | |||
748 | if (type_sp) | |||
749 | return type_sp; | |||
750 | ||||
751 | DWARFDeclContext die_decl_ctx; | |||
752 | die.GetDWARFDeclContext(die_decl_ctx); | |||
753 | ||||
754 | // type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, | |||
755 | // type_name_const_str); | |||
756 | type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx); | |||
757 | ||||
758 | if (!type_sp) { | |||
759 | SymbolFileDWARFDebugMap *debug_map_symfile = | |||
760 | dwarf->GetDebugMapSymfile(); | |||
761 | if (debug_map_symfile) { | |||
762 | // We weren't able to find a full declaration in | |||
763 | // this DWARF, see if we have a declaration anywhere | |||
764 | // else... | |||
765 | type_sp = | |||
766 | debug_map_symfile->FindDefinitionTypeForDWARFDeclContext( | |||
767 | die_decl_ctx); | |||
768 | } | |||
769 | } | |||
770 | ||||
771 | if (type_sp) { | |||
772 | if (log) { | |||
773 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
774 | log, "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a " | |||
775 | "forward declaration, complete type is 0x%8.8" PRIx64"l" "x", | |||
776 | static_cast<void *>(this), die.GetOffset(), | |||
777 | DW_TAG_value_to_name(tag), type_name_cstr, type_sp->GetID()); | |||
778 | } | |||
779 | ||||
780 | // We found a real definition for this type elsewhere | |||
781 | // so lets use it and cache the fact that we found | |||
782 | // a complete type for this die | |||
783 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); | |||
784 | clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE( | |||
785 | dwarf->DebugInfo()->GetDIE(DIERef(type_sp->GetID(), dwarf))); | |||
786 | if (defn_decl_ctx) | |||
787 | LinkDeclContextToDIE(defn_decl_ctx, die); | |||
788 | return type_sp; | |||
789 | } | |||
790 | } | |||
791 | assert(tag_decl_kind != -1)(static_cast <bool> (tag_decl_kind != -1) ? void (0) : __assert_fail ("tag_decl_kind != -1", "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 791, __extension__ __PRETTY_FUNCTION__)); | |||
792 | bool clang_type_was_created = false; | |||
793 | clang_type.SetCompilerType( | |||
794 | &m_ast, dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); | |||
795 | if (!clang_type) { | |||
796 | clang::DeclContext *decl_ctx = | |||
797 | GetClangDeclContextContainingDIE(die, nullptr); | |||
798 | if (accessibility == eAccessNone && decl_ctx) { | |||
799 | // Check the decl context that contains this class/struct/union. | |||
800 | // If it is a class we must give it an accessibility. | |||
801 | const clang::Decl::Kind containing_decl_kind = | |||
802 | decl_ctx->getDeclKind(); | |||
803 | if (DeclKindIsCXXClass(containing_decl_kind)) | |||
804 | accessibility = default_accessibility; | |||
805 | } | |||
806 | ||||
807 | ClangASTMetadata metadata; | |||
808 | metadata.SetUserID(die.GetID()); | |||
809 | metadata.SetIsDynamicCXXType(dwarf->ClassOrStructIsVirtual(die)); | |||
810 | ||||
811 | if (type_name_cstr && strchr(type_name_cstr, '<')) { | |||
812 | ClangASTContext::TemplateParameterInfos template_param_infos; | |||
813 | if (ParseTemplateParameterInfos(die, template_param_infos)) { | |||
814 | clang::ClassTemplateDecl *class_template_decl = | |||
815 | m_ast.ParseClassTemplateDecl(decl_ctx, accessibility, | |||
816 | type_name_cstr, tag_decl_kind, | |||
817 | template_param_infos); | |||
818 | if (!class_template_decl) { | |||
819 | if (log) { | |||
820 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
821 | log, "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" " | |||
822 | "clang::ClassTemplateDecl failed to return a decl.", | |||
823 | static_cast<void *>(this), die.GetOffset(), | |||
824 | DW_TAG_value_to_name(tag), type_name_cstr); | |||
825 | } | |||
826 | return TypeSP(); | |||
827 | } | |||
828 | ||||
829 | clang::ClassTemplateSpecializationDecl | |||
830 | *class_specialization_decl = | |||
831 | m_ast.CreateClassTemplateSpecializationDecl( | |||
832 | decl_ctx, class_template_decl, tag_decl_kind, | |||
833 | template_param_infos); | |||
834 | clang_type = m_ast.CreateClassTemplateSpecializationType( | |||
835 | class_specialization_decl); | |||
836 | clang_type_was_created = true; | |||
837 | ||||
838 | m_ast.SetMetadata(class_template_decl, metadata); | |||
839 | m_ast.SetMetadata(class_specialization_decl, metadata); | |||
840 | } | |||
841 | } | |||
842 | ||||
843 | if (!clang_type_was_created) { | |||
844 | clang_type_was_created = true; | |||
845 | clang_type = m_ast.CreateRecordType(decl_ctx, accessibility, | |||
846 | type_name_cstr, tag_decl_kind, | |||
847 | class_language, &metadata); | |||
848 | } | |||
849 | } | |||
850 | ||||
851 | // Store a forward declaration to this class type in case any | |||
852 | // parameters in any class methods need it for the clang | |||
853 | // types for function prototypes. | |||
854 | LinkDeclContextToDIE(m_ast.GetDeclContextForType(clang_type), die); | |||
855 | type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, | |||
856 | byte_size, NULL__null, LLDB_INVALID_UID(18446744073709551615UL), | |||
857 | Type::eEncodingIsUID, &decl, clang_type, | |||
858 | Type::eResolveStateForward)); | |||
859 | ||||
860 | type_sp->SetIsCompleteObjCClass(is_complete_objc_class); | |||
861 | ||||
862 | // Add our type to the unique type map so we don't | |||
863 | // end up creating many copies of the same type over | |||
864 | // and over in the ASTContext for our module | |||
865 | unique_ast_entry_ap->m_type_sp = type_sp; | |||
866 | unique_ast_entry_ap->m_die = die; | |||
867 | unique_ast_entry_ap->m_declaration = unique_decl; | |||
868 | unique_ast_entry_ap->m_byte_size = byte_size; | |||
869 | dwarf->GetUniqueDWARFASTTypeMap().Insert(unique_typename, | |||
870 | *unique_ast_entry_ap); | |||
871 | ||||
872 | if (is_forward_declaration && die.HasChildren()) { | |||
873 | // Check to see if the DIE actually has a definition, some version of | |||
874 | // GCC will | |||
875 | // emit DIEs with DW_AT_declaration set to true, but yet still have | |||
876 | // subprogram, | |||
877 | // members, or inheritance, so we can't trust it | |||
878 | DWARFDIE child_die = die.GetFirstChild(); | |||
879 | while (child_die) { | |||
880 | switch (child_die.Tag()) { | |||
881 | case DW_TAG_inheritance: | |||
882 | case DW_TAG_subprogram: | |||
883 | case DW_TAG_member: | |||
884 | case DW_TAG_APPLE_property: | |||
885 | case DW_TAG_class_type: | |||
886 | case DW_TAG_structure_type: | |||
887 | case DW_TAG_enumeration_type: | |||
888 | case DW_TAG_typedef: | |||
889 | case DW_TAG_union_type: | |||
890 | child_die.Clear(); | |||
891 | is_forward_declaration = false; | |||
892 | break; | |||
893 | default: | |||
894 | child_die = child_die.GetSibling(); | |||
895 | break; | |||
896 | } | |||
897 | } | |||
898 | } | |||
899 | ||||
900 | if (!is_forward_declaration) { | |||
901 | // Always start the definition for a class type so that | |||
902 | // if the class has child classes or types that require | |||
903 | // the class to be created for use as their decl contexts | |||
904 | // the class will be ready to accept these child definitions. | |||
905 | if (die.HasChildren() == false) { | |||
906 | // No children for this struct/union/class, lets finish it | |||
907 | if (ClangASTContext::StartTagDeclarationDefinition(clang_type)) { | |||
908 | ClangASTContext::CompleteTagDeclarationDefinition(clang_type); | |||
909 | } else { | |||
910 | dwarf->GetObjectFile()->GetModule()->ReportError( | |||
911 | "DWARF DIE at 0x%8.8x named \"%s\" was not able to start its " | |||
912 | "definition.\nPlease file a bug and attach the file at the " | |||
913 | "start of this error message", | |||
914 | die.GetOffset(), type_name_cstr); | |||
915 | } | |||
916 | ||||
917 | if (tag == DW_TAG_structure_type) // this only applies in C | |||
918 | { | |||
919 | clang::RecordDecl *record_decl = | |||
920 | ClangASTContext::GetAsRecordDecl(clang_type); | |||
921 | ||||
922 | if (record_decl) { | |||
923 | GetClangASTImporter().InsertRecordDecl( | |||
924 | record_decl, ClangASTImporter::LayoutInfo()); | |||
925 | } | |||
926 | } | |||
927 | } else if (clang_type_was_created) { | |||
928 | // Start the definition if the class is not objective C since | |||
929 | // the underlying decls respond to isCompleteDefinition(). Objective | |||
930 | // C decls don't respond to isCompleteDefinition() so we can't | |||
931 | // start the declaration definition right away. For C++ | |||
932 | // class/union/structs | |||
933 | // we want to start the definition in case the class is needed as | |||
934 | // the | |||
935 | // declaration context for a contained class or type without the | |||
936 | // need | |||
937 | // to complete that type.. | |||
938 | ||||
939 | if (class_language != eLanguageTypeObjC && | |||
940 | class_language != eLanguageTypeObjC_plus_plus) | |||
941 | ClangASTContext::StartTagDeclarationDefinition(clang_type); | |||
942 | ||||
943 | // Leave this as a forward declaration until we need | |||
944 | // to know the details of the type. lldb_private::Type | |||
945 | // will automatically call the SymbolFile virtual function | |||
946 | // "SymbolFileDWARF::CompleteType(Type *)" | |||
947 | // When the definition needs to be defined. | |||
948 | assert(!dwarf->GetForwardDeclClangTypeToDie().count((static_cast <bool> (!dwarf->GetForwardDeclClangTypeToDie ().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType ()) && "Type already in the forward declaration map!" ) ? void (0) : __assert_fail ("!dwarf->GetForwardDeclClangTypeToDie().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType()) && \"Type already in the forward declaration map!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 951, __extension__ __PRETTY_FUNCTION__)) | |||
949 | ClangUtil::RemoveFastQualifiers(clang_type)(static_cast <bool> (!dwarf->GetForwardDeclClangTypeToDie ().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType ()) && "Type already in the forward declaration map!" ) ? void (0) : __assert_fail ("!dwarf->GetForwardDeclClangTypeToDie().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType()) && \"Type already in the forward declaration map!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 951, __extension__ __PRETTY_FUNCTION__)) | |||
950 | .GetOpaqueQualType()) &&(static_cast <bool> (!dwarf->GetForwardDeclClangTypeToDie ().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType ()) && "Type already in the forward declaration map!" ) ? void (0) : __assert_fail ("!dwarf->GetForwardDeclClangTypeToDie().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType()) && \"Type already in the forward declaration map!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 951, __extension__ __PRETTY_FUNCTION__)) | |||
951 | "Type already in the forward declaration map!")(static_cast <bool> (!dwarf->GetForwardDeclClangTypeToDie ().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType ()) && "Type already in the forward declaration map!" ) ? void (0) : __assert_fail ("!dwarf->GetForwardDeclClangTypeToDie().count( ClangUtil::RemoveFastQualifiers(clang_type) .GetOpaqueQualType()) && \"Type already in the forward declaration map!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 951, __extension__ __PRETTY_FUNCTION__)); | |||
952 | // Can't assume m_ast.GetSymbolFile() is actually a SymbolFileDWARF, | |||
953 | // it can be a | |||
954 | // SymbolFileDWARFDebugMap for Apple binaries. | |||
955 | dwarf->GetForwardDeclDieToClangType()[die.GetDIE()] = | |||
956 | clang_type.GetOpaqueQualType(); | |||
957 | dwarf->GetForwardDeclClangTypeToDie() | |||
958 | [ClangUtil::RemoveFastQualifiers(clang_type) | |||
959 | .GetOpaqueQualType()] = die.GetDIERef(); | |||
960 | m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), true); | |||
961 | } | |||
962 | } | |||
963 | } break; | |||
964 | ||||
965 | case DW_TAG_enumeration_type: { | |||
966 | // Set a bit that lets us know that we are currently parsing this | |||
967 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED((lldb_private::Type *)1); | |||
968 | ||||
969 | bool is_scoped = false; | |||
970 | DWARFFormValue encoding_form; | |||
971 | ||||
972 | const size_t num_attributes = die.GetAttributes(attributes); | |||
973 | if (num_attributes > 0) { | |||
974 | uint32_t i; | |||
975 | ||||
976 | for (i = 0; i < num_attributes; ++i) { | |||
977 | attr = attributes.AttributeAtIndex(i); | |||
978 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
979 | switch (attr) { | |||
980 | case DW_AT_decl_file: | |||
981 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
982 | form_value.Unsigned())); | |||
983 | break; | |||
984 | case DW_AT_decl_line: | |||
985 | decl.SetLine(form_value.Unsigned()); | |||
986 | break; | |||
987 | case DW_AT_decl_column: | |||
988 | decl.SetColumn(form_value.Unsigned()); | |||
989 | break; | |||
990 | case DW_AT_name: | |||
991 | type_name_cstr = form_value.AsCString(); | |||
992 | type_name_const_str.SetCString(type_name_cstr); | |||
993 | break; | |||
994 | case DW_AT_type: | |||
995 | encoding_form = form_value; | |||
996 | break; | |||
997 | case DW_AT_byte_size: | |||
998 | byte_size = form_value.Unsigned(); | |||
999 | break; | |||
1000 | case DW_AT_accessibility: | |||
1001 | break; // accessibility = | |||
1002 | // DW_ACCESS_to_AccessType(form_value.Unsigned()); break; | |||
1003 | case DW_AT_declaration: | |||
1004 | is_forward_declaration = form_value.Boolean(); | |||
1005 | break; | |||
1006 | case DW_AT_enum_class: | |||
1007 | is_scoped = form_value.Boolean(); | |||
1008 | break; | |||
1009 | case DW_AT_allocated: | |||
1010 | case DW_AT_associated: | |||
1011 | case DW_AT_bit_stride: | |||
1012 | case DW_AT_byte_stride: | |||
1013 | case DW_AT_data_location: | |||
1014 | case DW_AT_description: | |||
1015 | case DW_AT_start_scope: | |||
1016 | case DW_AT_visibility: | |||
1017 | case DW_AT_specification: | |||
1018 | case DW_AT_abstract_origin: | |||
1019 | case DW_AT_sibling: | |||
1020 | break; | |||
1021 | } | |||
1022 | } | |||
1023 | } | |||
1024 | ||||
1025 | if (is_forward_declaration) { | |||
1026 | type_sp = ParseTypeFromDWO(die, log); | |||
1027 | if (type_sp) | |||
1028 | return type_sp; | |||
1029 | ||||
1030 | DWARFDeclContext die_decl_ctx; | |||
1031 | die.GetDWARFDeclContext(die_decl_ctx); | |||
1032 | ||||
1033 | type_sp = | |||
1034 | dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx); | |||
1035 | ||||
1036 | if (!type_sp) { | |||
1037 | SymbolFileDWARFDebugMap *debug_map_symfile = | |||
1038 | dwarf->GetDebugMapSymfile(); | |||
1039 | if (debug_map_symfile) { | |||
1040 | // We weren't able to find a full declaration in | |||
1041 | // this DWARF, see if we have a declaration anywhere | |||
1042 | // else... | |||
1043 | type_sp = | |||
1044 | debug_map_symfile->FindDefinitionTypeForDWARFDeclContext( | |||
1045 | die_decl_ctx); | |||
1046 | } | |||
1047 | } | |||
1048 | ||||
1049 | if (type_sp) { | |||
1050 | if (log) { | |||
1051 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
1052 | log, "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a " | |||
1053 | "forward declaration, complete type is 0x%8.8" PRIx64"l" "x", | |||
1054 | static_cast<void *>(this), die.GetOffset(), | |||
1055 | DW_TAG_value_to_name(tag), type_name_cstr, | |||
1056 | type_sp->GetID()); | |||
1057 | } | |||
1058 | ||||
1059 | // We found a real definition for this type elsewhere | |||
1060 | // so lets use it and cache the fact that we found | |||
1061 | // a complete type for this die | |||
1062 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); | |||
1063 | clang::DeclContext *defn_decl_ctx = | |||
1064 | GetCachedClangDeclContextForDIE(dwarf->DebugInfo()->GetDIE( | |||
1065 | DIERef(type_sp->GetID(), dwarf))); | |||
1066 | if (defn_decl_ctx) | |||
1067 | LinkDeclContextToDIE(defn_decl_ctx, die); | |||
1068 | return type_sp; | |||
1069 | } | |||
1070 | } | |||
1071 | DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), | |||
1072 | DW_TAG_value_to_name(tag), type_name_cstr); | |||
1073 | ||||
1074 | CompilerType enumerator_clang_type; | |||
1075 | clang_type.SetCompilerType( | |||
1076 | &m_ast, | |||
1077 | dwarf->GetForwardDeclDieToClangType().lookup(die.GetDIE())); | |||
1078 | if (!clang_type) { | |||
1079 | if (encoding_form.IsValid()) { | |||
1080 | Type *enumerator_type = | |||
1081 | dwarf->ResolveTypeUID(DIERef(encoding_form)); | |||
1082 | if (enumerator_type) | |||
1083 | enumerator_clang_type = enumerator_type->GetFullCompilerType(); | |||
1084 | } | |||
1085 | ||||
1086 | if (!enumerator_clang_type) { | |||
1087 | if (byte_size > 0) { | |||
1088 | enumerator_clang_type = | |||
1089 | m_ast.GetBuiltinTypeForDWARFEncodingAndBitSize( | |||
1090 | NULL__null, DW_ATE_signed, byte_size * 8); | |||
1091 | } else { | |||
1092 | enumerator_clang_type = m_ast.GetBasicType(eBasicTypeInt); | |||
1093 | } | |||
1094 | } | |||
1095 | ||||
1096 | clang_type = m_ast.CreateEnumerationType( | |||
1097 | type_name_cstr, GetClangDeclContextContainingDIE(die, nullptr), | |||
1098 | decl, enumerator_clang_type, is_scoped); | |||
1099 | } else { | |||
1100 | enumerator_clang_type = | |||
1101 | m_ast.GetEnumerationIntegerType(clang_type.GetOpaqueQualType()); | |||
1102 | } | |||
1103 | ||||
1104 | LinkDeclContextToDIE( | |||
1105 | ClangASTContext::GetDeclContextForType(clang_type), die); | |||
1106 | ||||
1107 | type_sp.reset(new Type( | |||
1108 | die.GetID(), dwarf, type_name_const_str, byte_size, NULL__null, | |||
1109 | DIERef(encoding_form).GetUID(dwarf), Type::eEncodingIsUID, &decl, | |||
1110 | clang_type, Type::eResolveStateForward)); | |||
1111 | ||||
1112 | if (ClangASTContext::StartTagDeclarationDefinition(clang_type)) { | |||
1113 | if (die.HasChildren()) { | |||
1114 | SymbolContext cu_sc(die.GetLLDBCompileUnit()); | |||
1115 | bool is_signed = false; | |||
1116 | enumerator_clang_type.IsIntegerType(is_signed); | |||
1117 | ParseChildEnumerators(cu_sc, clang_type, is_signed, | |||
1118 | type_sp->GetByteSize(), die); | |||
1119 | } | |||
1120 | ClangASTContext::CompleteTagDeclarationDefinition(clang_type); | |||
1121 | } else { | |||
1122 | dwarf->GetObjectFile()->GetModule()->ReportError( | |||
1123 | "DWARF DIE at 0x%8.8x named \"%s\" was not able to start its " | |||
1124 | "definition.\nPlease file a bug and attach the file at the " | |||
1125 | "start of this error message", | |||
1126 | die.GetOffset(), type_name_cstr); | |||
1127 | } | |||
1128 | } | |||
1129 | } break; | |||
1130 | ||||
1131 | case DW_TAG_inlined_subroutine: | |||
1132 | case DW_TAG_subprogram: | |||
1133 | case DW_TAG_subroutine_type: { | |||
1134 | // Set a bit that lets us know that we are currently parsing this | |||
1135 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED((lldb_private::Type *)1); | |||
1136 | ||||
1137 | DWARFFormValue type_die_form; | |||
1138 | bool is_variadic = false; | |||
1139 | bool is_inline = false; | |||
1140 | bool is_static = false; | |||
1141 | bool is_virtual = false; | |||
1142 | bool is_explicit = false; | |||
1143 | bool is_artificial = false; | |||
1144 | bool has_template_params = false; | |||
1145 | DWARFFormValue specification_die_form; | |||
1146 | DWARFFormValue abstract_origin_die_form; | |||
1147 | dw_offset_t object_pointer_die_offset = DW_INVALID_OFFSET(~(dw_offset_t)0); | |||
1148 | ||||
1149 | unsigned type_quals = 0; | |||
1150 | clang::StorageClass storage = | |||
1151 | clang::SC_None; //, Extern, Static, PrivateExtern | |||
1152 | ||||
1153 | const size_t num_attributes = die.GetAttributes(attributes); | |||
1154 | if (num_attributes > 0) { | |||
1155 | uint32_t i; | |||
1156 | for (i = 0; i < num_attributes; ++i) { | |||
1157 | attr = attributes.AttributeAtIndex(i); | |||
1158 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
1159 | switch (attr) { | |||
1160 | case DW_AT_decl_file: | |||
1161 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
1162 | form_value.Unsigned())); | |||
1163 | break; | |||
1164 | case DW_AT_decl_line: | |||
1165 | decl.SetLine(form_value.Unsigned()); | |||
1166 | break; | |||
1167 | case DW_AT_decl_column: | |||
1168 | decl.SetColumn(form_value.Unsigned()); | |||
1169 | break; | |||
1170 | case DW_AT_name: | |||
1171 | type_name_cstr = form_value.AsCString(); | |||
1172 | type_name_const_str.SetCString(type_name_cstr); | |||
1173 | break; | |||
1174 | ||||
1175 | case DW_AT_linkage_name: | |||
1176 | case DW_AT_MIPS_linkage_name: | |||
1177 | break; // mangled = | |||
1178 | // form_value.AsCString(&dwarf->get_debug_str_data()); | |||
1179 | // break; | |||
1180 | case DW_AT_type: | |||
1181 | type_die_form = form_value; | |||
1182 | break; | |||
1183 | case DW_AT_accessibility: | |||
1184 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | |||
1185 | break; | |||
1186 | case DW_AT_declaration: | |||
1187 | break; // is_forward_declaration = form_value.Boolean(); break; | |||
1188 | case DW_AT_inline: | |||
1189 | is_inline = form_value.Boolean(); | |||
1190 | break; | |||
1191 | case DW_AT_virtuality: | |||
1192 | is_virtual = form_value.Boolean(); | |||
1193 | break; | |||
1194 | case DW_AT_explicit: | |||
1195 | is_explicit = form_value.Boolean(); | |||
1196 | break; | |||
1197 | case DW_AT_artificial: | |||
1198 | is_artificial = form_value.Boolean(); | |||
1199 | break; | |||
1200 | ||||
1201 | case DW_AT_external: | |||
1202 | if (form_value.Unsigned()) { | |||
1203 | if (storage == clang::SC_None) | |||
1204 | storage = clang::SC_Extern; | |||
1205 | else | |||
1206 | storage = clang::SC_PrivateExtern; | |||
1207 | } | |||
1208 | break; | |||
1209 | ||||
1210 | case DW_AT_specification: | |||
1211 | specification_die_form = form_value; | |||
1212 | break; | |||
1213 | ||||
1214 | case DW_AT_abstract_origin: | |||
1215 | abstract_origin_die_form = form_value; | |||
1216 | break; | |||
1217 | ||||
1218 | case DW_AT_object_pointer: | |||
1219 | object_pointer_die_offset = form_value.Reference(); | |||
1220 | break; | |||
1221 | ||||
1222 | case DW_AT_allocated: | |||
1223 | case DW_AT_associated: | |||
1224 | case DW_AT_address_class: | |||
1225 | case DW_AT_calling_convention: | |||
1226 | case DW_AT_data_location: | |||
1227 | case DW_AT_elemental: | |||
1228 | case DW_AT_entry_pc: | |||
1229 | case DW_AT_frame_base: | |||
1230 | case DW_AT_high_pc: | |||
1231 | case DW_AT_low_pc: | |||
1232 | case DW_AT_prototyped: | |||
1233 | case DW_AT_pure: | |||
1234 | case DW_AT_ranges: | |||
1235 | case DW_AT_recursive: | |||
1236 | case DW_AT_return_addr: | |||
1237 | case DW_AT_segment: | |||
1238 | case DW_AT_start_scope: | |||
1239 | case DW_AT_static_link: | |||
1240 | case DW_AT_trampoline: | |||
1241 | case DW_AT_visibility: | |||
1242 | case DW_AT_vtable_elem_location: | |||
1243 | case DW_AT_description: | |||
1244 | case DW_AT_sibling: | |||
1245 | break; | |||
1246 | } | |||
1247 | } | |||
1248 | } | |||
1249 | } | |||
1250 | ||||
1251 | std::string object_pointer_name; | |||
1252 | if (object_pointer_die_offset != DW_INVALID_OFFSET(~(dw_offset_t)0)) { | |||
1253 | DWARFDIE object_pointer_die = die.GetDIE(object_pointer_die_offset); | |||
1254 | if (object_pointer_die) { | |||
1255 | const char *object_pointer_name_cstr = object_pointer_die.GetName(); | |||
1256 | if (object_pointer_name_cstr) | |||
1257 | object_pointer_name = object_pointer_name_cstr; | |||
1258 | } | |||
1259 | } | |||
1260 | ||||
1261 | DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), | |||
1262 | DW_TAG_value_to_name(tag), type_name_cstr); | |||
1263 | ||||
1264 | CompilerType return_clang_type; | |||
1265 | Type *func_type = NULL__null; | |||
1266 | ||||
1267 | if (type_die_form.IsValid()) | |||
1268 | func_type = dwarf->ResolveTypeUID(DIERef(type_die_form)); | |||
1269 | ||||
1270 | if (func_type) | |||
1271 | return_clang_type = func_type->GetForwardCompilerType(); | |||
1272 | else | |||
1273 | return_clang_type = m_ast.GetBasicType(eBasicTypeVoid); | |||
1274 | ||||
1275 | std::vector<CompilerType> function_param_types; | |||
1276 | std::vector<clang::ParmVarDecl *> function_param_decls; | |||
1277 | ||||
1278 | // Parse the function children for the parameters | |||
1279 | ||||
1280 | DWARFDIE decl_ctx_die; | |||
1281 | clang::DeclContext *containing_decl_ctx = | |||
1282 | GetClangDeclContextContainingDIE(die, &decl_ctx_die); | |||
1283 | const clang::Decl::Kind containing_decl_kind = | |||
1284 | containing_decl_ctx->getDeclKind(); | |||
1285 | ||||
1286 | bool is_cxx_method = DeclKindIsCXXClass(containing_decl_kind); | |||
1287 | // Start off static. This will be set to false in | |||
1288 | // ParseChildParameters(...) | |||
1289 | // if we find a "this" parameters as the first parameter | |||
1290 | if (is_cxx_method) { | |||
1291 | is_static = true; | |||
1292 | } | |||
1293 | ||||
1294 | if (die.HasChildren()) { | |||
1295 | bool skip_artificial = true; | |||
1296 | ParseChildParameters(sc, containing_decl_ctx, die, skip_artificial, | |||
1297 | is_static, is_variadic, has_template_params, | |||
1298 | function_param_types, function_param_decls, | |||
1299 | type_quals); | |||
1300 | } | |||
1301 | ||||
1302 | bool ignore_containing_context = false; | |||
1303 | // Check for templatized class member functions. If we had any | |||
1304 | // DW_TAG_template_type_parameter | |||
1305 | // or DW_TAG_template_value_parameter the DW_TAG_subprogram DIE, then we | |||
1306 | // can't let this become | |||
1307 | // a method in a class. Why? Because templatized functions are only | |||
1308 | // emitted if one of the | |||
1309 | // templatized methods is used in the current compile unit and we will | |||
1310 | // end up with classes | |||
1311 | // that may or may not include these member functions and this means one | |||
1312 | // class won't match another | |||
1313 | // class definition and it affects our ability to use a class in the | |||
1314 | // clang expression parser. So | |||
1315 | // for the greater good, we currently must not allow any template member | |||
1316 | // functions in a class definition. | |||
1317 | if (is_cxx_method && has_template_params) { | |||
1318 | ignore_containing_context = true; | |||
1319 | is_cxx_method = false; | |||
1320 | } | |||
1321 | ||||
1322 | // clang_type will get the function prototype clang type after this call | |||
1323 | clang_type = m_ast.CreateFunctionType( | |||
1324 | return_clang_type, function_param_types.data(), | |||
1325 | function_param_types.size(), is_variadic, type_quals); | |||
1326 | ||||
1327 | if (type_name_cstr) { | |||
1328 | bool type_handled = false; | |||
1329 | if (tag == DW_TAG_subprogram || tag == DW_TAG_inlined_subroutine) { | |||
1330 | ObjCLanguage::MethodName objc_method(type_name_cstr, true); | |||
1331 | if (objc_method.IsValid(true)) { | |||
1332 | CompilerType class_opaque_type; | |||
1333 | ConstString class_name(objc_method.GetClassName()); | |||
1334 | if (class_name) { | |||
1335 | TypeSP complete_objc_class_type_sp( | |||
1336 | dwarf->FindCompleteObjCDefinitionTypeForDIE( | |||
1337 | DWARFDIE(), class_name, false)); | |||
1338 | ||||
1339 | if (complete_objc_class_type_sp) { | |||
1340 | CompilerType type_clang_forward_type = | |||
1341 | complete_objc_class_type_sp->GetForwardCompilerType(); | |||
1342 | if (ClangASTContext::IsObjCObjectOrInterfaceType( | |||
1343 | type_clang_forward_type)) | |||
1344 | class_opaque_type = type_clang_forward_type; | |||
1345 | } | |||
1346 | } | |||
1347 | ||||
1348 | if (class_opaque_type) { | |||
1349 | // If accessibility isn't set to anything valid, assume public | |||
1350 | // for | |||
1351 | // now... | |||
1352 | if (accessibility == eAccessNone) | |||
1353 | accessibility = eAccessPublic; | |||
1354 | ||||
1355 | clang::ObjCMethodDecl *objc_method_decl = | |||
1356 | m_ast.AddMethodToObjCObjectType( | |||
1357 | class_opaque_type, type_name_cstr, clang_type, | |||
1358 | accessibility, is_artificial, is_variadic); | |||
1359 | type_handled = objc_method_decl != NULL__null; | |||
1360 | if (type_handled) { | |||
1361 | LinkDeclContextToDIE( | |||
1362 | ClangASTContext::GetAsDeclContext(objc_method_decl), die); | |||
1363 | m_ast.SetMetadataAsUserID(objc_method_decl, die.GetID()); | |||
1364 | } else { | |||
1365 | dwarf->GetObjectFile()->GetModule()->ReportError( | |||
1366 | "{0x%8.8x}: invalid Objective-C method 0x%4.4x (%s), " | |||
1367 | "please file a bug and attach the file at the start of " | |||
1368 | "this error message", | |||
1369 | die.GetOffset(), tag, DW_TAG_value_to_name(tag)); | |||
1370 | } | |||
1371 | } | |||
1372 | } else if (is_cxx_method) { | |||
1373 | // Look at the parent of this DIE and see if is is | |||
1374 | // a class or struct and see if this is actually a | |||
1375 | // C++ method | |||
1376 | Type *class_type = dwarf->ResolveType(decl_ctx_die); | |||
1377 | if (class_type) { | |||
1378 | bool alternate_defn = false; | |||
1379 | if (class_type->GetID() != decl_ctx_die.GetID() || | |||
1380 | decl_ctx_die.GetContainingDWOModuleDIE()) { | |||
1381 | alternate_defn = true; | |||
1382 | ||||
1383 | // We uniqued the parent class of this function to another | |||
1384 | // class | |||
1385 | // so we now need to associate all dies under "decl_ctx_die" | |||
1386 | // to | |||
1387 | // DIEs in the DIE for "class_type"... | |||
1388 | SymbolFileDWARF *class_symfile = NULL__null; | |||
1389 | DWARFDIE class_type_die; | |||
1390 | ||||
1391 | SymbolFileDWARFDebugMap *debug_map_symfile = | |||
1392 | dwarf->GetDebugMapSymfile(); | |||
1393 | if (debug_map_symfile) { | |||
1394 | class_symfile = debug_map_symfile->GetSymbolFileByOSOIndex( | |||
1395 | SymbolFileDWARFDebugMap::GetOSOIndexFromUserID( | |||
1396 | class_type->GetID())); | |||
1397 | class_type_die = class_symfile->DebugInfo()->GetDIE( | |||
1398 | DIERef(class_type->GetID(), dwarf)); | |||
1399 | } else { | |||
1400 | class_symfile = dwarf; | |||
1401 | class_type_die = dwarf->DebugInfo()->GetDIE( | |||
1402 | DIERef(class_type->GetID(), dwarf)); | |||
1403 | } | |||
1404 | if (class_type_die) { | |||
1405 | DWARFDIECollection failures; | |||
1406 | ||||
1407 | CopyUniqueClassMethodTypes(decl_ctx_die, class_type_die, | |||
1408 | class_type, failures); | |||
1409 | ||||
1410 | // FIXME do something with these failures that's smarter | |||
1411 | // than | |||
1412 | // just dropping them on the ground. Unfortunately classes | |||
1413 | // don't | |||
1414 | // like having stuff added to them after their definitions | |||
1415 | // are | |||
1416 | // complete... | |||
1417 | ||||
1418 | type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; | |||
1419 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED((lldb_private::Type *)1)) { | |||
1420 | type_sp = type_ptr->shared_from_this(); | |||
1421 | break; | |||
1422 | } | |||
1423 | } | |||
1424 | } | |||
1425 | ||||
1426 | if (specification_die_form.IsValid()) { | |||
1427 | // We have a specification which we are going to base our | |||
1428 | // function | |||
1429 | // prototype off of, so we need this type to be completed so | |||
1430 | // that the | |||
1431 | // m_die_to_decl_ctx for the method in the specification has a | |||
1432 | // valid | |||
1433 | // clang decl context. | |||
1434 | class_type->GetForwardCompilerType(); | |||
1435 | // If we have a specification, then the function type should | |||
1436 | // have been | |||
1437 | // made with the specification and not with this die. | |||
1438 | DWARFDIE spec_die = dwarf->DebugInfo()->GetDIE( | |||
1439 | DIERef(specification_die_form)); | |||
1440 | clang::DeclContext *spec_clang_decl_ctx = | |||
1441 | GetClangDeclContextForDIE(spec_die); | |||
1442 | if (spec_clang_decl_ctx) { | |||
1443 | LinkDeclContextToDIE(spec_clang_decl_ctx, die); | |||
1444 | } else { | |||
1445 | dwarf->GetObjectFile()->GetModule()->ReportWarning( | |||
1446 | "0x%8.8" PRIx64"l" "x" ": DW_AT_specification(0x%8.8" PRIx64"l" "x" | |||
1447 | ") has no decl\n", | |||
1448 | die.GetID(), specification_die_form.Reference()); | |||
1449 | } | |||
1450 | type_handled = true; | |||
1451 | } else if (abstract_origin_die_form.IsValid()) { | |||
1452 | // We have a specification which we are going to base our | |||
1453 | // function | |||
1454 | // prototype off of, so we need this type to be completed so | |||
1455 | // that the | |||
1456 | // m_die_to_decl_ctx for the method in the abstract origin has | |||
1457 | // a valid | |||
1458 | // clang decl context. | |||
1459 | class_type->GetForwardCompilerType(); | |||
1460 | ||||
1461 | DWARFDIE abs_die = dwarf->DebugInfo()->GetDIE( | |||
1462 | DIERef(abstract_origin_die_form)); | |||
1463 | clang::DeclContext *abs_clang_decl_ctx = | |||
1464 | GetClangDeclContextForDIE(abs_die); | |||
1465 | if (abs_clang_decl_ctx) { | |||
1466 | LinkDeclContextToDIE(abs_clang_decl_ctx, die); | |||
1467 | } else { | |||
1468 | dwarf->GetObjectFile()->GetModule()->ReportWarning( | |||
1469 | "0x%8.8" PRIx64"l" "x" ": DW_AT_abstract_origin(0x%8.8" PRIx64"l" "x" | |||
1470 | ") has no decl\n", | |||
1471 | die.GetID(), abstract_origin_die_form.Reference()); | |||
1472 | } | |||
1473 | type_handled = true; | |||
1474 | } else { | |||
1475 | CompilerType class_opaque_type = | |||
1476 | class_type->GetForwardCompilerType(); | |||
1477 | if (ClangASTContext::IsCXXClassType(class_opaque_type)) { | |||
1478 | if (class_opaque_type.IsBeingDefined() || alternate_defn) { | |||
1479 | if (!is_static && !die.HasChildren()) { | |||
1480 | // We have a C++ member function with no children (this | |||
1481 | // pointer!) | |||
1482 | // and clang will get mad if we try and make a function | |||
1483 | // that isn't | |||
1484 | // well formed in the DWARF, so we will just skip it... | |||
1485 | type_handled = true; | |||
1486 | } else { | |||
1487 | bool add_method = true; | |||
1488 | if (alternate_defn) { | |||
1489 | // If an alternate definition for the class exists, | |||
1490 | // then add the method only if an | |||
1491 | // equivalent is not already present. | |||
1492 | clang::CXXRecordDecl *record_decl = | |||
1493 | m_ast.GetAsCXXRecordDecl( | |||
1494 | class_opaque_type.GetOpaqueQualType()); | |||
1495 | if (record_decl) { | |||
1496 | for (auto method_iter = record_decl->method_begin(); | |||
1497 | method_iter != record_decl->method_end(); | |||
1498 | method_iter++) { | |||
1499 | clang::CXXMethodDecl *method_decl = *method_iter; | |||
1500 | if (method_decl->getNameInfo().getAsString() == | |||
1501 | std::string(type_name_cstr)) { | |||
1502 | if (method_decl->getType() == | |||
1503 | ClangUtil::GetQualType(clang_type)) { | |||
1504 | add_method = false; | |||
1505 | LinkDeclContextToDIE( | |||
1506 | ClangASTContext::GetAsDeclContext( | |||
1507 | method_decl), | |||
1508 | die); | |||
1509 | type_handled = true; | |||
1510 | ||||
1511 | break; | |||
1512 | } | |||
1513 | } | |||
1514 | } | |||
1515 | } | |||
1516 | } | |||
1517 | ||||
1518 | if (add_method) { | |||
1519 | llvm::PrettyStackTraceFormat stack_trace( | |||
1520 | "SymbolFileDWARF::ParseType() is adding a method " | |||
1521 | "%s to class %s in DIE 0x%8.8" PRIx64"l" "x" " from %s", | |||
1522 | type_name_cstr, | |||
1523 | class_type->GetName().GetCString(), die.GetID(), | |||
1524 | dwarf->GetObjectFile() | |||
1525 | ->GetFileSpec() | |||
1526 | .GetPath() | |||
1527 | .c_str()); | |||
1528 | ||||
1529 | const bool is_attr_used = false; | |||
1530 | // Neither GCC 4.2 nor clang++ currently set a valid | |||
1531 | // accessibility | |||
1532 | // in the DWARF for C++ methods... Default to public | |||
1533 | // for now... | |||
1534 | if (accessibility == eAccessNone) | |||
1535 | accessibility = eAccessPublic; | |||
1536 | ||||
1537 | clang::CXXMethodDecl *cxx_method_decl = | |||
1538 | m_ast.AddMethodToCXXRecordType( | |||
1539 | class_opaque_type.GetOpaqueQualType(), | |||
1540 | type_name_cstr, clang_type, accessibility, | |||
1541 | is_virtual, is_static, is_inline, is_explicit, | |||
1542 | is_attr_used, is_artificial); | |||
1543 | ||||
1544 | type_handled = cxx_method_decl != NULL__null; | |||
1545 | ||||
1546 | if (type_handled) { | |||
1547 | LinkDeclContextToDIE( | |||
1548 | ClangASTContext::GetAsDeclContext( | |||
1549 | cxx_method_decl), | |||
1550 | die); | |||
1551 | ||||
1552 | ClangASTMetadata metadata; | |||
1553 | metadata.SetUserID(die.GetID()); | |||
1554 | ||||
1555 | if (!object_pointer_name.empty()) { | |||
1556 | metadata.SetObjectPtrName( | |||
1557 | object_pointer_name.c_str()); | |||
1558 | if (log) | |||
1559 | log->Printf( | |||
1560 | "Setting object pointer name: %s on method " | |||
1561 | "object %p.\n", | |||
1562 | object_pointer_name.c_str(), | |||
1563 | static_cast<void *>(cxx_method_decl)); | |||
1564 | } | |||
1565 | m_ast.SetMetadata(cxx_method_decl, metadata); | |||
1566 | } else { | |||
1567 | ignore_containing_context = true; | |||
1568 | } | |||
1569 | } | |||
1570 | } | |||
1571 | } else { | |||
1572 | // We were asked to parse the type for a method in a | |||
1573 | // class, yet the | |||
1574 | // class hasn't been asked to complete itself through the | |||
1575 | // clang::ExternalASTSource protocol, so we need to just | |||
1576 | // have the | |||
1577 | // class complete itself and do things the right way, then | |||
1578 | // our | |||
1579 | // DIE should then have an entry in the | |||
1580 | // dwarf->GetDIEToType() map. First | |||
1581 | // we need to modify the dwarf->GetDIEToType() so it | |||
1582 | // doesn't think we are | |||
1583 | // trying to parse this DIE anymore... | |||
1584 | dwarf->GetDIEToType()[die.GetDIE()] = NULL__null; | |||
1585 | ||||
1586 | // Now we get the full type to force our class type to | |||
1587 | // complete itself | |||
1588 | // using the clang::ExternalASTSource protocol which will | |||
1589 | // parse all | |||
1590 | // base classes and all methods (including the method for | |||
1591 | // this DIE). | |||
1592 | class_type->GetFullCompilerType(); | |||
1593 | ||||
1594 | // The type for this DIE should have been filled in the | |||
1595 | // function call above | |||
1596 | type_ptr = dwarf->GetDIEToType()[die.GetDIE()]; | |||
1597 | if (type_ptr && type_ptr != DIE_IS_BEING_PARSED((lldb_private::Type *)1)) { | |||
1598 | type_sp = type_ptr->shared_from_this(); | |||
1599 | break; | |||
1600 | } | |||
1601 | ||||
1602 | // FIXME This is fixing some even uglier behavior but we | |||
1603 | // really need to | |||
1604 | // uniq the methods of each class as well as the class | |||
1605 | // itself. | |||
1606 | // <rdar://problem/11240464> | |||
1607 | type_handled = true; | |||
1608 | } | |||
1609 | } | |||
1610 | } | |||
1611 | } | |||
1612 | } | |||
1613 | } | |||
1614 | ||||
1615 | if (!type_handled) { | |||
1616 | clang::FunctionDecl *function_decl = nullptr; | |||
1617 | ||||
1618 | if (abstract_origin_die_form.IsValid()) { | |||
1619 | DWARFDIE abs_die = | |||
1620 | dwarf->DebugInfo()->GetDIE(DIERef(abstract_origin_die_form)); | |||
1621 | ||||
1622 | SymbolContext sc; | |||
1623 | ||||
1624 | if (dwarf->ResolveType(abs_die)) { | |||
1625 | function_decl = llvm::dyn_cast_or_null<clang::FunctionDecl>( | |||
1626 | GetCachedClangDeclContextForDIE(abs_die)); | |||
1627 | ||||
1628 | if (function_decl) { | |||
1629 | LinkDeclContextToDIE(function_decl, die); | |||
1630 | } | |||
1631 | } | |||
1632 | } | |||
1633 | ||||
1634 | if (!function_decl) { | |||
1635 | // We just have a function that isn't part of a class | |||
1636 | function_decl = m_ast.CreateFunctionDeclaration( | |||
1637 | ignore_containing_context ? m_ast.GetTranslationUnitDecl() | |||
1638 | : containing_decl_ctx, | |||
1639 | type_name_cstr, clang_type, storage, is_inline); | |||
1640 | ||||
1641 | if (has_template_params) { | |||
1642 | ClangASTContext::TemplateParameterInfos template_param_infos; | |||
1643 | ParseTemplateParameterInfos(die, template_param_infos); | |||
1644 | clang::FunctionTemplateDecl *func_template_decl = | |||
1645 | m_ast.CreateFunctionTemplateDecl( | |||
1646 | containing_decl_ctx, function_decl, type_name_cstr, | |||
1647 | template_param_infos); | |||
1648 | m_ast.CreateFunctionTemplateSpecializationInfo( | |||
1649 | function_decl, func_template_decl, template_param_infos); | |||
1650 | } | |||
1651 | ||||
1652 | lldbassert(function_decl)lldb_private::lldb_assert(function_decl, "function_decl", __FUNCTION__ , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 1652); | |||
1653 | ||||
1654 | if (function_decl) { | |||
1655 | LinkDeclContextToDIE(function_decl, die); | |||
1656 | ||||
1657 | if (!function_param_decls.empty()) | |||
1658 | m_ast.SetFunctionParameters(function_decl, | |||
1659 | &function_param_decls.front(), | |||
1660 | function_param_decls.size()); | |||
1661 | ||||
1662 | ClangASTMetadata metadata; | |||
1663 | metadata.SetUserID(die.GetID()); | |||
1664 | ||||
1665 | if (!object_pointer_name.empty()) { | |||
1666 | metadata.SetObjectPtrName(object_pointer_name.c_str()); | |||
1667 | if (log) | |||
1668 | log->Printf("Setting object pointer name: %s on function " | |||
1669 | "object %p.", | |||
1670 | object_pointer_name.c_str(), | |||
1671 | static_cast<void *>(function_decl)); | |||
1672 | } | |||
1673 | m_ast.SetMetadata(function_decl, metadata); | |||
1674 | } | |||
1675 | } | |||
1676 | } | |||
1677 | } | |||
1678 | type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, 0, NULL__null, | |||
1679 | LLDB_INVALID_UID(18446744073709551615UL), Type::eEncodingIsUID, &decl, | |||
1680 | clang_type, Type::eResolveStateFull)); | |||
1681 | assert(type_sp.get())(static_cast <bool> (type_sp.get()) ? void (0) : __assert_fail ("type_sp.get()", "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 1681, __extension__ __PRETTY_FUNCTION__)); | |||
1682 | } break; | |||
1683 | ||||
1684 | case DW_TAG_array_type: { | |||
1685 | // Set a bit that lets us know that we are currently parsing this | |||
1686 | dwarf->GetDIEToType()[die.GetDIE()] = DIE_IS_BEING_PARSED((lldb_private::Type *)1); | |||
1687 | ||||
1688 | DWARFFormValue type_die_form; | |||
1689 | int64_t first_index = 0; | |||
1690 | uint32_t byte_stride = 0; | |||
1691 | uint32_t bit_stride = 0; | |||
1692 | bool is_vector = false; | |||
1693 | const size_t num_attributes = die.GetAttributes(attributes); | |||
1694 | ||||
1695 | if (num_attributes > 0) { | |||
1696 | uint32_t i; | |||
1697 | for (i = 0; i < num_attributes; ++i) { | |||
1698 | attr = attributes.AttributeAtIndex(i); | |||
1699 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
1700 | switch (attr) { | |||
1701 | case DW_AT_decl_file: | |||
1702 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
1703 | form_value.Unsigned())); | |||
1704 | break; | |||
1705 | case DW_AT_decl_line: | |||
1706 | decl.SetLine(form_value.Unsigned()); | |||
1707 | break; | |||
1708 | case DW_AT_decl_column: | |||
1709 | decl.SetColumn(form_value.Unsigned()); | |||
1710 | break; | |||
1711 | case DW_AT_name: | |||
1712 | type_name_cstr = form_value.AsCString(); | |||
1713 | type_name_const_str.SetCString(type_name_cstr); | |||
1714 | break; | |||
1715 | ||||
1716 | case DW_AT_type: | |||
1717 | type_die_form = form_value; | |||
1718 | break; | |||
1719 | case DW_AT_byte_size: | |||
1720 | break; // byte_size = form_value.Unsigned(); break; | |||
1721 | case DW_AT_byte_stride: | |||
1722 | byte_stride = form_value.Unsigned(); | |||
1723 | break; | |||
1724 | case DW_AT_bit_stride: | |||
1725 | bit_stride = form_value.Unsigned(); | |||
1726 | break; | |||
1727 | case DW_AT_GNU_vector: | |||
1728 | is_vector = form_value.Boolean(); | |||
1729 | break; | |||
1730 | case DW_AT_accessibility: | |||
1731 | break; // accessibility = | |||
1732 | // DW_ACCESS_to_AccessType(form_value.Unsigned()); break; | |||
1733 | case DW_AT_declaration: | |||
1734 | break; // is_forward_declaration = form_value.Boolean(); break; | |||
1735 | case DW_AT_allocated: | |||
1736 | case DW_AT_associated: | |||
1737 | case DW_AT_data_location: | |||
1738 | case DW_AT_description: | |||
1739 | case DW_AT_ordering: | |||
1740 | case DW_AT_start_scope: | |||
1741 | case DW_AT_visibility: | |||
1742 | case DW_AT_specification: | |||
1743 | case DW_AT_abstract_origin: | |||
1744 | case DW_AT_sibling: | |||
1745 | break; | |||
1746 | } | |||
1747 | } | |||
1748 | } | |||
1749 | ||||
1750 | DEBUG_PRINTF("0x%8.8" PRIx64 ": %s (\"%s\")\n", die.GetID(), | |||
1751 | DW_TAG_value_to_name(tag), type_name_cstr); | |||
1752 | ||||
1753 | DIERef type_die_ref(type_die_form); | |||
1754 | Type *element_type = dwarf->ResolveTypeUID(type_die_ref); | |||
1755 | ||||
1756 | if (element_type) { | |||
1757 | std::vector<uint64_t> element_orders; | |||
1758 | ParseChildArrayInfo(sc, die, first_index, element_orders, | |||
1759 | byte_stride, bit_stride); | |||
1760 | if (byte_stride == 0 && bit_stride == 0) | |||
1761 | byte_stride = element_type->GetByteSize(); | |||
1762 | CompilerType array_element_type = | |||
1763 | element_type->GetForwardCompilerType(); | |||
1764 | ||||
1765 | if (ClangASTContext::IsCXXClassType(array_element_type) && | |||
1766 | array_element_type.GetCompleteType() == false) { | |||
1767 | ModuleSP module_sp = die.GetModule(); | |||
1768 | if (module_sp) { | |||
1769 | if (die.GetCU()->GetProducer() == eProducerClang) | |||
1770 | module_sp->ReportError( | |||
1771 | "DWARF DW_TAG_array_type DIE at 0x%8.8x has a " | |||
1772 | "class/union/struct element type DIE 0x%8.8x that is a " | |||
1773 | "forward declaration, not a complete definition.\nTry " | |||
1774 | "compiling the source file with -fstandalone-debug or " | |||
1775 | "disable -gmodules", | |||
1776 | die.GetOffset(), type_die_ref.die_offset); | |||
1777 | else | |||
1778 | module_sp->ReportError( | |||
1779 | "DWARF DW_TAG_array_type DIE at 0x%8.8x has a " | |||
1780 | "class/union/struct element type DIE 0x%8.8x that is a " | |||
1781 | "forward declaration, not a complete definition.\nPlease " | |||
1782 | "file a bug against the compiler and include the " | |||
1783 | "preprocessed output for %s", | |||
1784 | die.GetOffset(), type_die_ref.die_offset, | |||
1785 | die.GetLLDBCompileUnit() | |||
1786 | ? die.GetLLDBCompileUnit()->GetPath().c_str() | |||
1787 | : "the source file"); | |||
1788 | } | |||
1789 | ||||
1790 | // We have no choice other than to pretend that the element class | |||
1791 | // type | |||
1792 | // is complete. If we don't do this, clang will crash when trying | |||
1793 | // to layout the class. Since we provide layout assistance, all | |||
1794 | // ivars in this class and other classes will be fine, this is | |||
1795 | // the best we can do short of crashing. | |||
1796 | if (ClangASTContext::StartTagDeclarationDefinition( | |||
1797 | array_element_type)) { | |||
1798 | ClangASTContext::CompleteTagDeclarationDefinition( | |||
1799 | array_element_type); | |||
1800 | } else { | |||
1801 | module_sp->ReportError("DWARF DIE at 0x%8.8x was not able to " | |||
1802 | "start its definition.\nPlease file a " | |||
1803 | "bug and attach the file at the start " | |||
1804 | "of this error message", | |||
1805 | type_die_ref.die_offset); | |||
1806 | } | |||
1807 | } | |||
1808 | ||||
1809 | uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride; | |||
1810 | if (element_orders.size() > 0) { | |||
1811 | uint64_t num_elements = 0; | |||
1812 | std::vector<uint64_t>::const_reverse_iterator pos; | |||
1813 | std::vector<uint64_t>::const_reverse_iterator end = | |||
1814 | element_orders.rend(); | |||
1815 | for (pos = element_orders.rbegin(); pos != end; ++pos) { | |||
1816 | num_elements = *pos; | |||
1817 | clang_type = m_ast.CreateArrayType(array_element_type, | |||
1818 | num_elements, is_vector); | |||
1819 | array_element_type = clang_type; | |||
1820 | array_element_bit_stride = | |||
1821 | num_elements ? array_element_bit_stride * num_elements | |||
1822 | : array_element_bit_stride; | |||
1823 | } | |||
1824 | } else { | |||
1825 | clang_type = | |||
1826 | m_ast.CreateArrayType(array_element_type, 0, is_vector); | |||
1827 | } | |||
1828 | ConstString empty_name; | |||
1829 | type_sp.reset(new Type( | |||
1830 | die.GetID(), dwarf, empty_name, array_element_bit_stride / 8, | |||
1831 | NULL__null, DIERef(type_die_form).GetUID(dwarf), Type::eEncodingIsUID, | |||
1832 | &decl, clang_type, Type::eResolveStateFull)); | |||
1833 | type_sp->SetEncodingType(element_type); | |||
1834 | } | |||
1835 | } | |||
1836 | } break; | |||
1837 | ||||
1838 | case DW_TAG_ptr_to_member_type: { | |||
1839 | DWARFFormValue type_die_form; | |||
1840 | DWARFFormValue containing_type_die_form; | |||
1841 | ||||
1842 | const size_t num_attributes = die.GetAttributes(attributes); | |||
1843 | ||||
1844 | if (num_attributes > 0) { | |||
1845 | uint32_t i; | |||
1846 | for (i = 0; i < num_attributes; ++i) { | |||
1847 | attr = attributes.AttributeAtIndex(i); | |||
1848 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
1849 | switch (attr) { | |||
1850 | case DW_AT_type: | |||
1851 | type_die_form = form_value; | |||
1852 | break; | |||
1853 | case DW_AT_containing_type: | |||
1854 | containing_type_die_form = form_value; | |||
1855 | break; | |||
1856 | } | |||
1857 | } | |||
1858 | } | |||
1859 | ||||
1860 | Type *pointee_type = dwarf->ResolveTypeUID(DIERef(type_die_form)); | |||
1861 | Type *class_type = | |||
1862 | dwarf->ResolveTypeUID(DIERef(containing_type_die_form)); | |||
1863 | ||||
1864 | CompilerType pointee_clang_type = | |||
1865 | pointee_type->GetForwardCompilerType(); | |||
1866 | CompilerType class_clang_type = class_type->GetLayoutCompilerType(); | |||
1867 | ||||
1868 | clang_type = ClangASTContext::CreateMemberPointerType( | |||
1869 | class_clang_type, pointee_clang_type); | |||
1870 | ||||
1871 | byte_size = clang_type.GetByteSize(nullptr); | |||
1872 | ||||
1873 | type_sp.reset(new Type(die.GetID(), dwarf, type_name_const_str, | |||
1874 | byte_size, NULL__null, LLDB_INVALID_UID(18446744073709551615UL), | |||
1875 | Type::eEncodingIsUID, NULL__null, clang_type, | |||
1876 | Type::eResolveStateForward)); | |||
1877 | } | |||
1878 | ||||
1879 | break; | |||
1880 | } | |||
1881 | default: | |||
1882 | dwarf->GetObjectFile()->GetModule()->ReportError( | |||
1883 | "{0x%8.8x}: unhandled type tag 0x%4.4x (%s), please file a bug and " | |||
1884 | "attach the file at the start of this error message", | |||
1885 | die.GetOffset(), tag, DW_TAG_value_to_name(tag)); | |||
1886 | break; | |||
1887 | } | |||
1888 | ||||
1889 | if (type_sp.get()) { | |||
1890 | DWARFDIE sc_parent_die = | |||
1891 | SymbolFileDWARF::GetParentSymbolContextDIE(die); | |||
1892 | dw_tag_t sc_parent_tag = sc_parent_die.Tag(); | |||
1893 | ||||
1894 | SymbolContextScope *symbol_context_scope = NULL__null; | |||
1895 | if (sc_parent_tag == DW_TAG_compile_unit) { | |||
1896 | symbol_context_scope = sc.comp_unit; | |||
1897 | } else if (sc.function != NULL__null && sc_parent_die) { | |||
1898 | symbol_context_scope = | |||
1899 | sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID()); | |||
1900 | if (symbol_context_scope == NULL__null) | |||
1901 | symbol_context_scope = sc.function; | |||
1902 | } | |||
1903 | ||||
1904 | if (symbol_context_scope != NULL__null) { | |||
1905 | type_sp->SetSymbolContextScope(symbol_context_scope); | |||
1906 | } | |||
1907 | ||||
1908 | // We are ready to put this type into the uniqued list up at the module | |||
1909 | // level | |||
1910 | type_list->Insert(type_sp); | |||
1911 | ||||
1912 | dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); | |||
1913 | } | |||
1914 | } else if (type_ptr != DIE_IS_BEING_PARSED((lldb_private::Type *)1)) { | |||
1915 | type_sp = type_ptr->shared_from_this(); | |||
1916 | } | |||
1917 | } | |||
1918 | return type_sp; | |||
1919 | } | |||
1920 | ||||
1921 | // DWARF parsing functions | |||
1922 | ||||
1923 | class DWARFASTParserClang::DelayedAddObjCClassProperty { | |||
1924 | public: | |||
1925 | DelayedAddObjCClassProperty( | |||
1926 | const CompilerType &class_opaque_type, const char *property_name, | |||
1927 | const CompilerType &property_opaque_type, // The property type is only | |||
1928 | // required if you don't have an | |||
1929 | // ivar decl | |||
1930 | clang::ObjCIvarDecl *ivar_decl, const char *property_setter_name, | |||
1931 | const char *property_getter_name, uint32_t property_attributes, | |||
1932 | const ClangASTMetadata *metadata) | |||
1933 | : m_class_opaque_type(class_opaque_type), m_property_name(property_name), | |||
1934 | m_property_opaque_type(property_opaque_type), m_ivar_decl(ivar_decl), | |||
1935 | m_property_setter_name(property_setter_name), | |||
1936 | m_property_getter_name(property_getter_name), | |||
1937 | m_property_attributes(property_attributes) { | |||
1938 | if (metadata != NULL__null) { | |||
1939 | m_metadata_ap.reset(new ClangASTMetadata()); | |||
1940 | *m_metadata_ap = *metadata; | |||
1941 | } | |||
1942 | } | |||
1943 | ||||
1944 | DelayedAddObjCClassProperty(const DelayedAddObjCClassProperty &rhs) { | |||
1945 | *this = rhs; | |||
1946 | } | |||
1947 | ||||
1948 | DelayedAddObjCClassProperty & | |||
1949 | operator=(const DelayedAddObjCClassProperty &rhs) { | |||
1950 | m_class_opaque_type = rhs.m_class_opaque_type; | |||
1951 | m_property_name = rhs.m_property_name; | |||
1952 | m_property_opaque_type = rhs.m_property_opaque_type; | |||
1953 | m_ivar_decl = rhs.m_ivar_decl; | |||
1954 | m_property_setter_name = rhs.m_property_setter_name; | |||
1955 | m_property_getter_name = rhs.m_property_getter_name; | |||
1956 | m_property_attributes = rhs.m_property_attributes; | |||
1957 | ||||
1958 | if (rhs.m_metadata_ap.get()) { | |||
1959 | m_metadata_ap.reset(new ClangASTMetadata()); | |||
1960 | *m_metadata_ap = *rhs.m_metadata_ap; | |||
1961 | } | |||
1962 | return *this; | |||
1963 | } | |||
1964 | ||||
1965 | bool Finalize() { | |||
1966 | return ClangASTContext::AddObjCClassProperty( | |||
1967 | m_class_opaque_type, m_property_name, m_property_opaque_type, | |||
1968 | m_ivar_decl, m_property_setter_name, m_property_getter_name, | |||
1969 | m_property_attributes, m_metadata_ap.get()); | |||
1970 | } | |||
1971 | ||||
1972 | private: | |||
1973 | CompilerType m_class_opaque_type; | |||
1974 | const char *m_property_name; | |||
1975 | CompilerType m_property_opaque_type; | |||
1976 | clang::ObjCIvarDecl *m_ivar_decl; | |||
1977 | const char *m_property_setter_name; | |||
1978 | const char *m_property_getter_name; | |||
1979 | uint32_t m_property_attributes; | |||
1980 | std::unique_ptr<ClangASTMetadata> m_metadata_ap; | |||
1981 | }; | |||
1982 | ||||
1983 | bool DWARFASTParserClang::ParseTemplateDIE( | |||
1984 | const DWARFDIE &die, | |||
1985 | ClangASTContext::TemplateParameterInfos &template_param_infos) { | |||
1986 | const dw_tag_t tag = die.Tag(); | |||
1987 | ||||
1988 | switch (tag) { | |||
1989 | case DW_TAG_GNU_template_parameter_pack: { | |||
1990 | template_param_infos.packed_args.reset( | |||
1991 | new ClangASTContext::TemplateParameterInfos); | |||
1992 | for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid(); | |||
1993 | child_die = child_die.GetSibling()) { | |||
1994 | if (!ParseTemplateDIE(child_die, *template_param_infos.packed_args)) | |||
1995 | return false; | |||
1996 | } | |||
1997 | if (const char *name = die.GetName()) { | |||
1998 | template_param_infos.pack_name = name; | |||
1999 | } | |||
2000 | return true; | |||
2001 | } | |||
2002 | case DW_TAG_template_type_parameter: | |||
2003 | case DW_TAG_template_value_parameter: { | |||
2004 | DWARFAttributes attributes; | |||
2005 | const size_t num_attributes = die.GetAttributes(attributes); | |||
2006 | const char *name = nullptr; | |||
2007 | CompilerType clang_type; | |||
2008 | uint64_t uval64 = 0; | |||
2009 | bool uval64_valid = false; | |||
2010 | if (num_attributes > 0) { | |||
2011 | DWARFFormValue form_value; | |||
2012 | for (size_t i = 0; i < num_attributes; ++i) { | |||
2013 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | |||
2014 | ||||
2015 | switch (attr) { | |||
2016 | case DW_AT_name: | |||
2017 | if (attributes.ExtractFormValueAtIndex(i, form_value)) | |||
2018 | name = form_value.AsCString(); | |||
2019 | break; | |||
2020 | ||||
2021 | case DW_AT_type: | |||
2022 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
2023 | Type *lldb_type = die.ResolveTypeUID(DIERef(form_value)); | |||
2024 | if (lldb_type) | |||
2025 | clang_type = lldb_type->GetForwardCompilerType(); | |||
2026 | } | |||
2027 | break; | |||
2028 | ||||
2029 | case DW_AT_const_value: | |||
2030 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
2031 | uval64_valid = true; | |||
2032 | uval64 = form_value.Unsigned(); | |||
2033 | } | |||
2034 | break; | |||
2035 | default: | |||
2036 | break; | |||
2037 | } | |||
2038 | } | |||
2039 | ||||
2040 | clang::ASTContext *ast = m_ast.getASTContext(); | |||
2041 | if (!clang_type) | |||
2042 | clang_type = m_ast.GetBasicType(eBasicTypeVoid); | |||
2043 | ||||
2044 | if (clang_type) { | |||
2045 | bool is_signed = false; | |||
2046 | if (name && name[0]) | |||
2047 | template_param_infos.names.push_back(name); | |||
2048 | else | |||
2049 | template_param_infos.names.push_back(NULL__null); | |||
2050 | ||||
2051 | // Get the signed value for any integer or enumeration if available | |||
2052 | clang_type.IsIntegerOrEnumerationType(is_signed); | |||
2053 | ||||
2054 | if (tag == DW_TAG_template_value_parameter && uval64_valid) { | |||
2055 | llvm::APInt apint(clang_type.GetBitSize(nullptr), uval64, is_signed); | |||
2056 | template_param_infos.args.push_back( | |||
2057 | clang::TemplateArgument(*ast, llvm::APSInt(apint, !is_signed), | |||
2058 | ClangUtil::GetQualType(clang_type))); | |||
2059 | } else { | |||
2060 | template_param_infos.args.push_back( | |||
2061 | clang::TemplateArgument(ClangUtil::GetQualType(clang_type))); | |||
2062 | } | |||
2063 | } else { | |||
2064 | return false; | |||
2065 | } | |||
2066 | } | |||
2067 | } | |||
2068 | return true; | |||
2069 | ||||
2070 | default: | |||
2071 | break; | |||
2072 | } | |||
2073 | return false; | |||
2074 | } | |||
2075 | ||||
2076 | bool DWARFASTParserClang::ParseTemplateParameterInfos( | |||
2077 | const DWARFDIE &parent_die, | |||
2078 | ClangASTContext::TemplateParameterInfos &template_param_infos) { | |||
2079 | ||||
2080 | if (!parent_die) | |||
2081 | return false; | |||
2082 | ||||
2083 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); | |||
2084 | die = die.GetSibling()) { | |||
2085 | const dw_tag_t tag = die.Tag(); | |||
2086 | ||||
2087 | switch (tag) { | |||
2088 | case DW_TAG_template_type_parameter: | |||
2089 | case DW_TAG_template_value_parameter: | |||
2090 | case DW_TAG_GNU_template_parameter_pack: | |||
2091 | ParseTemplateDIE(die, template_param_infos); | |||
2092 | break; | |||
2093 | ||||
2094 | default: | |||
2095 | break; | |||
2096 | } | |||
2097 | } | |||
2098 | if (template_param_infos.args.empty()) | |||
2099 | return false; | |||
2100 | return template_param_infos.args.size() == template_param_infos.names.size(); | |||
2101 | } | |||
2102 | ||||
2103 | // Checks whether m1 is an overload of m2 (as opposed to an override). | |||
2104 | // This is called by addOverridesForMethod to distinguish overrides (which share | |||
2105 | // a vtable entry) from overloads (which require distinct entries). | |||
2106 | static bool isOverload(clang::CXXMethodDecl *m1, clang::CXXMethodDecl *m2) { | |||
2107 | // FIXME: This should detect covariant return types, but currently doesn't. | |||
2108 | lldbassert(&m1->getASTContext() == &m2->getASTContext() &&lldb_private::lldb_assert(&m1->getASTContext() == & m2->getASTContext() && "Methods should have the same AST context" , "&m1->getASTContext() == &m2->getASTContext() && \"Methods should have the same AST context\"" , __FUNCTION__, "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 2109) | |||
2109 | "Methods should have the same AST context")lldb_private::lldb_assert(&m1->getASTContext() == & m2->getASTContext() && "Methods should have the same AST context" , "&m1->getASTContext() == &m2->getASTContext() && \"Methods should have the same AST context\"" , __FUNCTION__, "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 2109); | |||
2110 | clang::ASTContext &context = m1->getASTContext(); | |||
2111 | ||||
2112 | const auto *m1Type = | |||
2113 | llvm::cast<clang::FunctionProtoType>( | |||
2114 | context.getCanonicalType(m1->getType())); | |||
2115 | ||||
2116 | const auto *m2Type = | |||
2117 | llvm::cast<clang::FunctionProtoType>( | |||
2118 | context.getCanonicalType(m2->getType())); | |||
2119 | ||||
2120 | auto compareArgTypes = | |||
2121 | [&context](const clang::QualType &m1p, const clang::QualType &m2p) { | |||
2122 | return context.hasSameType(m1p.getUnqualifiedType(), | |||
2123 | m2p.getUnqualifiedType()); | |||
2124 | }; | |||
2125 | ||||
2126 | return !std::equal(m1Type->param_type_begin(), m1Type->param_type_end(), | |||
2127 | m2Type->param_type_begin(), compareArgTypes); | |||
2128 | } | |||
2129 | ||||
2130 | // If decl is a virtual method, walk the base classes looking for methods that | |||
2131 | // decl overrides. This table of overridden methods is used by IRGen to determine | |||
2132 | // the vtable layout for decl's parent class. | |||
2133 | static void addOverridesForMethod(clang::CXXMethodDecl *decl) { | |||
2134 | if (!decl->isVirtual()) | |||
2135 | return; | |||
2136 | ||||
2137 | clang::CXXBasePaths paths; | |||
2138 | ||||
2139 | auto find_overridden_methods = | |||
2140 | [decl](const clang::CXXBaseSpecifier *specifier, clang::CXXBasePath &path) { | |||
2141 | if (auto *base_record = | |||
2142 | llvm::dyn_cast<clang::CXXRecordDecl>( | |||
2143 | specifier->getType()->getAs<clang::RecordType>()->getDecl())) { | |||
2144 | ||||
2145 | clang::DeclarationName name = decl->getDeclName(); | |||
2146 | ||||
2147 | // If this is a destructor, check whether the base class destructor is | |||
2148 | // virtual. | |||
2149 | if (name.getNameKind() == clang::DeclarationName::CXXDestructorName) | |||
2150 | if (auto *baseDtorDecl = base_record->getDestructor()) { | |||
2151 | if (baseDtorDecl->isVirtual()) { | |||
2152 | path.Decls = baseDtorDecl; | |||
2153 | return true; | |||
2154 | } else | |||
2155 | return false; | |||
2156 | } | |||
2157 | ||||
2158 | // Otherwise, search for name in the base class. | |||
2159 | for (path.Decls = base_record->lookup(name); !path.Decls.empty(); | |||
2160 | path.Decls = path.Decls.slice(1)) { | |||
2161 | if (auto *method_decl = | |||
2162 | llvm::dyn_cast<clang::CXXMethodDecl>(path.Decls.front())) | |||
2163 | if (method_decl->isVirtual() && !isOverload(decl, method_decl)) { | |||
2164 | path.Decls = method_decl; | |||
2165 | return true; | |||
2166 | } | |||
2167 | } | |||
2168 | } | |||
2169 | ||||
2170 | return false; | |||
2171 | }; | |||
2172 | ||||
2173 | if (decl->getParent()->lookupInBases(find_overridden_methods, paths)) { | |||
2174 | for (auto *overridden_decl : paths.found_decls()) | |||
2175 | decl->addOverriddenMethod( | |||
2176 | llvm::cast<clang::CXXMethodDecl>(overridden_decl)); | |||
2177 | } | |||
2178 | } | |||
2179 | ||||
2180 | // If clang_type is a CXXRecordDecl, builds the method override list for each | |||
2181 | // of its virtual methods. | |||
2182 | static void addMethodOverrides(ClangASTContext &ast, CompilerType &clang_type) { | |||
2183 | if (auto *record = | |||
2184 | ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType())) | |||
2185 | for (auto *method : record->methods()) | |||
2186 | addOverridesForMethod(method); | |||
2187 | } | |||
2188 | ||||
2189 | bool DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, | |||
2190 | lldb_private::Type *type, | |||
2191 | CompilerType &clang_type) { | |||
2192 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
2193 | ||||
2194 | std::lock_guard<std::recursive_mutex> guard( | |||
2195 | dwarf->GetObjectFile()->GetModule()->GetMutex()); | |||
2196 | ||||
2197 | // Disable external storage for this type so we don't get anymore | |||
2198 | // clang::ExternalASTSource queries for this type. | |||
2199 | m_ast.SetHasExternalStorage(clang_type.GetOpaqueQualType(), false); | |||
2200 | ||||
2201 | if (!die) | |||
2202 | return false; | |||
2203 | ||||
2204 | #if defined LLDB_CONFIGURATION_DEBUG | |||
2205 | //---------------------------------------------------------------------- | |||
2206 | // For debugging purposes, the LLDB_DWARF_DONT_COMPLETE_TYPENAMES | |||
2207 | // environment variable can be set with one or more typenames separated | |||
2208 | // by ';' characters. This will cause this function to not complete any | |||
2209 | // types whose names match. | |||
2210 | // | |||
2211 | // Examples of setting this environment variable: | |||
2212 | // | |||
2213 | // LLDB_DWARF_DONT_COMPLETE_TYPENAMES=Foo | |||
2214 | // LLDB_DWARF_DONT_COMPLETE_TYPENAMES=Foo;Bar;Baz | |||
2215 | //---------------------------------------------------------------------- | |||
2216 | const char *dont_complete_typenames_cstr = | |||
2217 | getenv("LLDB_DWARF_DONT_COMPLETE_TYPENAMES"); | |||
2218 | if (dont_complete_typenames_cstr && dont_complete_typenames_cstr[0]) { | |||
2219 | const char *die_name = die.GetName(); | |||
2220 | if (die_name && die_name[0]) { | |||
2221 | const char *match = strstr(dont_complete_typenames_cstr, die_name); | |||
2222 | if (match) { | |||
2223 | size_t die_name_length = strlen(die_name); | |||
2224 | while (match) { | |||
2225 | const char separator_char = ';'; | |||
2226 | const char next_char = match[die_name_length]; | |||
2227 | if (next_char == '\0' || next_char == separator_char) { | |||
2228 | if (match == dont_complete_typenames_cstr || | |||
2229 | match[-1] == separator_char) | |||
2230 | return false; | |||
2231 | } | |||
2232 | match = strstr(match + 1, die_name); | |||
2233 | } | |||
2234 | } | |||
2235 | } | |||
2236 | } | |||
2237 | #endif | |||
2238 | ||||
2239 | const dw_tag_t tag = die.Tag(); | |||
2240 | ||||
2241 | Log *log = | |||
2242 | nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION)); | |||
2243 | if (log) | |||
2244 | dwarf->GetObjectFile()->GetModule()->LogMessageVerboseBacktrace( | |||
2245 | log, "0x%8.8" PRIx64"l" "x" ": %s '%s' resolving forward declaration...", | |||
2246 | die.GetID(), die.GetTagAsCString(), type->GetName().AsCString()); | |||
2247 | assert(clang_type)(static_cast <bool> (clang_type) ? void (0) : __assert_fail ("clang_type", "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 2247, __extension__ __PRETTY_FUNCTION__)); | |||
2248 | DWARFAttributes attributes; | |||
2249 | switch (tag) { | |||
2250 | case DW_TAG_structure_type: | |||
2251 | case DW_TAG_union_type: | |||
2252 | case DW_TAG_class_type: { | |||
2253 | ClangASTImporter::LayoutInfo layout_info; | |||
2254 | ||||
2255 | { | |||
2256 | if (die.HasChildren()) { | |||
2257 | LanguageType class_language = eLanguageTypeUnknown; | |||
2258 | if (ClangASTContext::IsObjCObjectOrInterfaceType(clang_type)) { | |||
2259 | class_language = eLanguageTypeObjC; | |||
2260 | // For objective C we don't start the definition when | |||
2261 | // the class is created. | |||
2262 | ClangASTContext::StartTagDeclarationDefinition(clang_type); | |||
2263 | } | |||
2264 | ||||
2265 | int tag_decl_kind = -1; | |||
2266 | AccessType default_accessibility = eAccessNone; | |||
2267 | if (tag == DW_TAG_structure_type) { | |||
2268 | tag_decl_kind = clang::TTK_Struct; | |||
2269 | default_accessibility = eAccessPublic; | |||
2270 | } else if (tag == DW_TAG_union_type) { | |||
2271 | tag_decl_kind = clang::TTK_Union; | |||
2272 | default_accessibility = eAccessPublic; | |||
2273 | } else if (tag == DW_TAG_class_type) { | |||
2274 | tag_decl_kind = clang::TTK_Class; | |||
2275 | default_accessibility = eAccessPrivate; | |||
2276 | } | |||
2277 | ||||
2278 | SymbolContext sc(die.GetLLDBCompileUnit()); | |||
2279 | std::vector<clang::CXXBaseSpecifier *> base_classes; | |||
2280 | std::vector<int> member_accessibilities; | |||
2281 | bool is_a_class = false; | |||
2282 | // Parse members and base classes first | |||
2283 | DWARFDIECollection member_function_dies; | |||
2284 | ||||
2285 | DelayedPropertyList delayed_properties; | |||
2286 | ParseChildMembers(sc, die, clang_type, class_language, base_classes, | |||
2287 | member_accessibilities, member_function_dies, | |||
2288 | delayed_properties, default_accessibility, is_a_class, | |||
2289 | layout_info); | |||
2290 | ||||
2291 | // Now parse any methods if there were any... | |||
2292 | size_t num_functions = member_function_dies.Size(); | |||
2293 | if (num_functions > 0) { | |||
2294 | for (size_t i = 0; i < num_functions; ++i) { | |||
2295 | dwarf->ResolveType(member_function_dies.GetDIEAtIndex(i)); | |||
2296 | } | |||
2297 | } | |||
2298 | ||||
2299 | if (class_language == eLanguageTypeObjC) { | |||
2300 | ConstString class_name(clang_type.GetTypeName()); | |||
2301 | if (class_name) { | |||
2302 | DIEArray method_die_offsets; | |||
2303 | dwarf->GetObjCMethodDIEOffsets(class_name, method_die_offsets); | |||
2304 | ||||
2305 | if (!method_die_offsets.empty()) { | |||
2306 | DWARFDebugInfo *debug_info = dwarf->DebugInfo(); | |||
2307 | ||||
2308 | const size_t num_matches = method_die_offsets.size(); | |||
2309 | for (size_t i = 0; i < num_matches; ++i) { | |||
2310 | const DIERef &die_ref = method_die_offsets[i]; | |||
2311 | DWARFDIE method_die = debug_info->GetDIE(die_ref); | |||
2312 | ||||
2313 | if (method_die) | |||
2314 | method_die.ResolveType(); | |||
2315 | } | |||
2316 | } | |||
2317 | ||||
2318 | for (DelayedPropertyList::iterator pi = delayed_properties.begin(), | |||
2319 | pe = delayed_properties.end(); | |||
2320 | pi != pe; ++pi) | |||
2321 | pi->Finalize(); | |||
2322 | } | |||
2323 | } | |||
2324 | ||||
2325 | // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we | |||
2326 | // need to tell the clang type it is actually a class. | |||
2327 | if (class_language != eLanguageTypeObjC) { | |||
2328 | if (is_a_class && tag_decl_kind != clang::TTK_Class) | |||
2329 | m_ast.SetTagTypeKind(ClangUtil::GetQualType(clang_type), | |||
2330 | clang::TTK_Class); | |||
2331 | } | |||
2332 | ||||
2333 | // Since DW_TAG_structure_type gets used for both classes | |||
2334 | // and structures, we may need to set any DW_TAG_member | |||
2335 | // fields to have a "private" access if none was specified. | |||
2336 | // When we parsed the child members we tracked that actual | |||
2337 | // accessibility value for each DW_TAG_member in the | |||
2338 | // "member_accessibilities" array. If the value for the | |||
2339 | // member is zero, then it was set to the "default_accessibility" | |||
2340 | // which for structs was "public". Below we correct this | |||
2341 | // by setting any fields to "private" that weren't correctly | |||
2342 | // set. | |||
2343 | if (is_a_class && !member_accessibilities.empty()) { | |||
2344 | // This is a class and all members that didn't have | |||
2345 | // their access specified are private. | |||
2346 | m_ast.SetDefaultAccessForRecordFields( | |||
2347 | m_ast.GetAsRecordDecl(clang_type), eAccessPrivate, | |||
2348 | &member_accessibilities.front(), member_accessibilities.size()); | |||
2349 | } | |||
2350 | ||||
2351 | if (!base_classes.empty()) { | |||
2352 | // Make sure all base classes refer to complete types and not | |||
2353 | // forward declarations. If we don't do this, clang will crash | |||
2354 | // with an assertion in the call to | |||
2355 | // clang_type.SetBaseClassesForClassType() | |||
2356 | for (auto &base_class : base_classes) { | |||
2357 | clang::TypeSourceInfo *type_source_info = | |||
2358 | base_class->getTypeSourceInfo(); | |||
2359 | if (type_source_info) { | |||
2360 | CompilerType base_class_type( | |||
2361 | &m_ast, type_source_info->getType().getAsOpaquePtr()); | |||
2362 | if (base_class_type.GetCompleteType() == false) { | |||
2363 | auto module = dwarf->GetObjectFile()->GetModule(); | |||
2364 | module->ReportError(":: Class '%s' has a base class '%s' which " | |||
2365 | "does not have a complete definition.", | |||
2366 | die.GetName(), | |||
2367 | base_class_type.GetTypeName().GetCString()); | |||
2368 | if (die.GetCU()->GetProducer() == eProducerClang) | |||
2369 | module->ReportError(":: Try compiling the source file with " | |||
2370 | "-fstandalone-debug."); | |||
2371 | ||||
2372 | // We have no choice other than to pretend that the base class | |||
2373 | // is complete. If we don't do this, clang will crash when we | |||
2374 | // call setBases() inside of | |||
2375 | // "clang_type.SetBaseClassesForClassType()" | |||
2376 | // below. Since we provide layout assistance, all ivars in this | |||
2377 | // class and other classes will be fine, this is the best we can | |||
2378 | // do | |||
2379 | // short of crashing. | |||
2380 | if (ClangASTContext::StartTagDeclarationDefinition( | |||
2381 | base_class_type)) { | |||
2382 | ClangASTContext::CompleteTagDeclarationDefinition( | |||
2383 | base_class_type); | |||
2384 | } | |||
2385 | } | |||
2386 | } | |||
2387 | } | |||
2388 | m_ast.SetBaseClassesForClassType(clang_type.GetOpaqueQualType(), | |||
2389 | &base_classes.front(), | |||
2390 | base_classes.size()); | |||
2391 | ||||
2392 | // Clang will copy each CXXBaseSpecifier in "base_classes" | |||
2393 | // so we have to free them all. | |||
2394 | ClangASTContext::DeleteBaseClassSpecifiers(&base_classes.front(), | |||
2395 | base_classes.size()); | |||
2396 | } | |||
2397 | } | |||
2398 | } | |||
2399 | ||||
2400 | addMethodOverrides(m_ast, clang_type); | |||
2401 | ClangASTContext::BuildIndirectFields(clang_type); | |||
2402 | ClangASTContext::CompleteTagDeclarationDefinition(clang_type); | |||
2403 | ||||
2404 | if (!layout_info.field_offsets.empty() || | |||
2405 | !layout_info.base_offsets.empty() || | |||
2406 | !layout_info.vbase_offsets.empty()) { | |||
2407 | if (type) | |||
2408 | layout_info.bit_size = type->GetByteSize() * 8; | |||
2409 | if (layout_info.bit_size == 0) | |||
2410 | layout_info.bit_size = | |||
2411 | die.GetAttributeValueAsUnsigned(DW_AT_byte_size, 0) * 8; | |||
2412 | ||||
2413 | clang::CXXRecordDecl *record_decl = | |||
2414 | m_ast.GetAsCXXRecordDecl(clang_type.GetOpaqueQualType()); | |||
2415 | if (record_decl) { | |||
2416 | if (log) { | |||
2417 | ModuleSP module_sp = dwarf->GetObjectFile()->GetModule(); | |||
2418 | ||||
2419 | if (module_sp) { | |||
2420 | module_sp->LogMessage( | |||
2421 | log, | |||
2422 | "ClangASTContext::CompleteTypeFromDWARF (clang_type = %p) " | |||
2423 | "caching layout info for record_decl = %p, bit_size = %" PRIu64"l" "u" | |||
2424 | ", alignment = %" PRIu64"l" "u" | |||
2425 | ", field_offsets[%u], base_offsets[%u], vbase_offsets[%u])", | |||
2426 | static_cast<void *>(clang_type.GetOpaqueQualType()), | |||
2427 | static_cast<void *>(record_decl), layout_info.bit_size, | |||
2428 | layout_info.alignment, | |||
2429 | static_cast<uint32_t>(layout_info.field_offsets.size()), | |||
2430 | static_cast<uint32_t>(layout_info.base_offsets.size()), | |||
2431 | static_cast<uint32_t>(layout_info.vbase_offsets.size())); | |||
2432 | ||||
2433 | uint32_t idx; | |||
2434 | { | |||
2435 | llvm::DenseMap<const clang::FieldDecl *, uint64_t>::const_iterator | |||
2436 | pos, | |||
2437 | end = layout_info.field_offsets.end(); | |||
2438 | for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; | |||
2439 | ++pos, ++idx) { | |||
2440 | module_sp->LogMessage( | |||
2441 | log, "ClangASTContext::CompleteTypeFromDWARF (clang_type = " | |||
2442 | "%p) field[%u] = { bit_offset=%u, name='%s' }", | |||
2443 | static_cast<void *>(clang_type.GetOpaqueQualType()), idx, | |||
2444 | static_cast<uint32_t>(pos->second), | |||
2445 | pos->first->getNameAsString().c_str()); | |||
2446 | } | |||
2447 | } | |||
2448 | ||||
2449 | { | |||
2450 | llvm::DenseMap<const clang::CXXRecordDecl *, | |||
2451 | clang::CharUnits>::const_iterator base_pos, | |||
2452 | base_end = layout_info.base_offsets.end(); | |||
2453 | for (idx = 0, base_pos = layout_info.base_offsets.begin(); | |||
2454 | base_pos != base_end; ++base_pos, ++idx) { | |||
2455 | module_sp->LogMessage( | |||
2456 | log, "ClangASTContext::CompleteTypeFromDWARF (clang_type = " | |||
2457 | "%p) base[%u] = { byte_offset=%u, name='%s' }", | |||
2458 | clang_type.GetOpaqueQualType(), idx, | |||
2459 | (uint32_t)base_pos->second.getQuantity(), | |||
2460 | base_pos->first->getNameAsString().c_str()); | |||
2461 | } | |||
2462 | } | |||
2463 | { | |||
2464 | llvm::DenseMap<const clang::CXXRecordDecl *, | |||
2465 | clang::CharUnits>::const_iterator vbase_pos, | |||
2466 | vbase_end = layout_info.vbase_offsets.end(); | |||
2467 | for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); | |||
2468 | vbase_pos != vbase_end; ++vbase_pos, ++idx) { | |||
2469 | module_sp->LogMessage( | |||
2470 | log, "ClangASTContext::CompleteTypeFromDWARF (clang_type = " | |||
2471 | "%p) vbase[%u] = { byte_offset=%u, name='%s' }", | |||
2472 | static_cast<void *>(clang_type.GetOpaqueQualType()), idx, | |||
2473 | static_cast<uint32_t>(vbase_pos->second.getQuantity()), | |||
2474 | vbase_pos->first->getNameAsString().c_str()); | |||
2475 | } | |||
2476 | } | |||
2477 | } | |||
2478 | } | |||
2479 | GetClangASTImporter().InsertRecordDecl(record_decl, layout_info); | |||
2480 | } | |||
2481 | } | |||
2482 | } | |||
2483 | ||||
2484 | return (bool)clang_type; | |||
2485 | ||||
2486 | case DW_TAG_enumeration_type: | |||
2487 | if (ClangASTContext::StartTagDeclarationDefinition(clang_type)) { | |||
2488 | if (die.HasChildren()) { | |||
2489 | SymbolContext sc(die.GetLLDBCompileUnit()); | |||
2490 | bool is_signed = false; | |||
2491 | clang_type.IsIntegerType(is_signed); | |||
2492 | ParseChildEnumerators(sc, clang_type, is_signed, type->GetByteSize(), | |||
2493 | die); | |||
2494 | } | |||
2495 | ClangASTContext::CompleteTagDeclarationDefinition(clang_type); | |||
2496 | } | |||
2497 | return (bool)clang_type; | |||
2498 | ||||
2499 | default: | |||
2500 | assert(false && "not a forward clang type decl!")(static_cast <bool> (false && "not a forward clang type decl!" ) ? void (0) : __assert_fail ("false && \"not a forward clang type decl!\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 2500, __extension__ __PRETTY_FUNCTION__)); | |||
2501 | break; | |||
2502 | } | |||
2503 | ||||
2504 | return false; | |||
2505 | } | |||
2506 | ||||
2507 | std::vector<DWARFDIE> DWARFASTParserClang::GetDIEForDeclContext( | |||
2508 | lldb_private::CompilerDeclContext decl_context) { | |||
2509 | std::vector<DWARFDIE> result; | |||
2510 | for (auto it = m_decl_ctx_to_die.find( | |||
2511 | (clang::DeclContext *)decl_context.GetOpaqueDeclContext()); | |||
2512 | it != m_decl_ctx_to_die.end(); it++) | |||
2513 | result.push_back(it->second); | |||
2514 | return result; | |||
2515 | } | |||
2516 | ||||
2517 | CompilerDecl DWARFASTParserClang::GetDeclForUIDFromDWARF(const DWARFDIE &die) { | |||
2518 | clang::Decl *clang_decl = GetClangDeclForDIE(die); | |||
2519 | if (clang_decl != nullptr) | |||
2520 | return CompilerDecl(&m_ast, clang_decl); | |||
2521 | return CompilerDecl(); | |||
2522 | } | |||
2523 | ||||
2524 | CompilerDeclContext | |||
2525 | DWARFASTParserClang::GetDeclContextForUIDFromDWARF(const DWARFDIE &die) { | |||
2526 | clang::DeclContext *clang_decl_ctx = GetClangDeclContextForDIE(die); | |||
2527 | if (clang_decl_ctx) | |||
2528 | return CompilerDeclContext(&m_ast, clang_decl_ctx); | |||
2529 | return CompilerDeclContext(); | |||
2530 | } | |||
2531 | ||||
2532 | CompilerDeclContext | |||
2533 | DWARFASTParserClang::GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) { | |||
2534 | clang::DeclContext *clang_decl_ctx = | |||
2535 | GetClangDeclContextContainingDIE(die, nullptr); | |||
2536 | if (clang_decl_ctx) | |||
2537 | return CompilerDeclContext(&m_ast, clang_decl_ctx); | |||
2538 | return CompilerDeclContext(); | |||
2539 | } | |||
2540 | ||||
2541 | size_t DWARFASTParserClang::ParseChildEnumerators( | |||
2542 | const SymbolContext &sc, lldb_private::CompilerType &clang_type, | |||
2543 | bool is_signed, uint32_t enumerator_byte_size, const DWARFDIE &parent_die) { | |||
2544 | if (!parent_die) | |||
2545 | return 0; | |||
2546 | ||||
2547 | size_t enumerators_added = 0; | |||
2548 | ||||
2549 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); | |||
2550 | die = die.GetSibling()) { | |||
2551 | const dw_tag_t tag = die.Tag(); | |||
2552 | if (tag == DW_TAG_enumerator) { | |||
2553 | DWARFAttributes attributes; | |||
2554 | const size_t num_child_attributes = die.GetAttributes(attributes); | |||
2555 | if (num_child_attributes > 0) { | |||
2556 | const char *name = NULL__null; | |||
2557 | bool got_value = false; | |||
2558 | int64_t enum_value = 0; | |||
2559 | Declaration decl; | |||
2560 | ||||
2561 | uint32_t i; | |||
2562 | for (i = 0; i < num_child_attributes; ++i) { | |||
2563 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | |||
2564 | DWARFFormValue form_value; | |||
2565 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
2566 | switch (attr) { | |||
2567 | case DW_AT_const_value: | |||
2568 | got_value = true; | |||
2569 | if (is_signed) | |||
2570 | enum_value = form_value.Signed(); | |||
2571 | else | |||
2572 | enum_value = form_value.Unsigned(); | |||
2573 | break; | |||
2574 | ||||
2575 | case DW_AT_name: | |||
2576 | name = form_value.AsCString(); | |||
2577 | break; | |||
2578 | ||||
2579 | case DW_AT_description: | |||
2580 | default: | |||
2581 | case DW_AT_decl_file: | |||
2582 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
2583 | form_value.Unsigned())); | |||
2584 | break; | |||
2585 | case DW_AT_decl_line: | |||
2586 | decl.SetLine(form_value.Unsigned()); | |||
2587 | break; | |||
2588 | case DW_AT_decl_column: | |||
2589 | decl.SetColumn(form_value.Unsigned()); | |||
2590 | break; | |||
2591 | case DW_AT_sibling: | |||
2592 | break; | |||
2593 | } | |||
2594 | } | |||
2595 | } | |||
2596 | ||||
2597 | if (name && name[0] && got_value) { | |||
2598 | m_ast.AddEnumerationValueToEnumerationType( | |||
2599 | clang_type.GetOpaqueQualType(), | |||
2600 | m_ast.GetEnumerationIntegerType(clang_type.GetOpaqueQualType()), | |||
2601 | decl, name, enum_value, enumerator_byte_size * 8); | |||
2602 | ++enumerators_added; | |||
2603 | } | |||
2604 | } | |||
2605 | } | |||
2606 | } | |||
2607 | return enumerators_added; | |||
2608 | } | |||
2609 | ||||
2610 | #if defined(LLDB_CONFIGURATION_DEBUG) || defined(LLDB_CONFIGURATION_RELEASE1) | |||
2611 | ||||
2612 | class DIEStack { | |||
2613 | public: | |||
2614 | void Push(const DWARFDIE &die) { m_dies.push_back(die); } | |||
2615 | ||||
2616 | void LogDIEs(Log *log) { | |||
2617 | StreamString log_strm; | |||
2618 | const size_t n = m_dies.size(); | |||
2619 | log_strm.Printf("DIEStack[%" PRIu64"l" "u" "]:\n", (uint64_t)n); | |||
2620 | for (size_t i = 0; i < n; i++) { | |||
2621 | std::string qualified_name; | |||
2622 | const DWARFDIE &die = m_dies[i]; | |||
2623 | die.GetQualifiedName(qualified_name); | |||
2624 | log_strm.Printf("[%" PRIu64"l" "u" "] 0x%8.8x: %s name='%s'\n", (uint64_t)i, | |||
2625 | die.GetOffset(), die.GetTagAsCString(), | |||
2626 | qualified_name.c_str()); | |||
2627 | } | |||
2628 | log->PutCString(log_strm.GetData()); | |||
2629 | } | |||
2630 | void Pop() { m_dies.pop_back(); } | |||
2631 | ||||
2632 | class ScopedPopper { | |||
2633 | public: | |||
2634 | ScopedPopper(DIEStack &die_stack) | |||
2635 | : m_die_stack(die_stack), m_valid(false) {} | |||
2636 | ||||
2637 | void Push(const DWARFDIE &die) { | |||
2638 | m_valid = true; | |||
2639 | m_die_stack.Push(die); | |||
2640 | } | |||
2641 | ||||
2642 | ~ScopedPopper() { | |||
2643 | if (m_valid) | |||
2644 | m_die_stack.Pop(); | |||
2645 | } | |||
2646 | ||||
2647 | protected: | |||
2648 | DIEStack &m_die_stack; | |||
2649 | bool m_valid; | |||
2650 | }; | |||
2651 | ||||
2652 | protected: | |||
2653 | typedef std::vector<DWARFDIE> Stack; | |||
2654 | Stack m_dies; | |||
2655 | }; | |||
2656 | #endif | |||
2657 | ||||
2658 | Function *DWARFASTParserClang::ParseFunctionFromDWARF(const SymbolContext &sc, | |||
2659 | const DWARFDIE &die) { | |||
2660 | DWARFRangeList func_ranges; | |||
2661 | const char *name = NULL__null; | |||
2662 | const char *mangled = NULL__null; | |||
2663 | int decl_file = 0; | |||
2664 | int decl_line = 0; | |||
2665 | int decl_column = 0; | |||
2666 | int call_file = 0; | |||
2667 | int call_line = 0; | |||
2668 | int call_column = 0; | |||
2669 | DWARFExpression frame_base(die.GetCU()); | |||
2670 | ||||
2671 | const dw_tag_t tag = die.Tag(); | |||
2672 | ||||
2673 | if (tag != DW_TAG_subprogram) | |||
2674 | return NULL__null; | |||
2675 | ||||
2676 | if (die.GetDIENamesAndRanges(name, mangled, func_ranges, decl_file, decl_line, | |||
2677 | decl_column, call_file, call_line, call_column, | |||
2678 | &frame_base)) { | |||
2679 | ||||
2680 | // Union of all ranges in the function DIE (if the function is | |||
2681 | // discontiguous) | |||
2682 | AddressRange func_range; | |||
2683 | lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase(0); | |||
2684 | lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd(0); | |||
2685 | if (lowest_func_addr != LLDB_INVALID_ADDRESS(18446744073709551615UL) && | |||
2686 | lowest_func_addr <= highest_func_addr) { | |||
2687 | ModuleSP module_sp(die.GetModule()); | |||
2688 | func_range.GetBaseAddress().ResolveAddressUsingFileSections( | |||
2689 | lowest_func_addr, module_sp->GetSectionList()); | |||
2690 | if (func_range.GetBaseAddress().IsValid()) | |||
2691 | func_range.SetByteSize(highest_func_addr - lowest_func_addr); | |||
2692 | } | |||
2693 | ||||
2694 | if (func_range.GetBaseAddress().IsValid()) { | |||
2695 | Mangled func_name; | |||
2696 | if (mangled) | |||
2697 | func_name.SetValue(ConstString(mangled), true); | |||
2698 | else if (die.GetParent().Tag() == DW_TAG_compile_unit && | |||
2699 | Language::LanguageIsCPlusPlus(die.GetLanguage()) && name && | |||
2700 | strcmp(name, "main") != 0) { | |||
2701 | // If the mangled name is not present in the DWARF, generate the | |||
2702 | // demangled name | |||
2703 | // using the decl context. We skip if the function is "main" as its name | |||
2704 | // is | |||
2705 | // never mangled. | |||
2706 | bool is_static = false; | |||
2707 | bool is_variadic = false; | |||
2708 | bool has_template_params = false; | |||
2709 | unsigned type_quals = 0; | |||
2710 | std::vector<CompilerType> param_types; | |||
2711 | std::vector<clang::ParmVarDecl *> param_decls; | |||
2712 | DWARFDeclContext decl_ctx; | |||
2713 | StreamString sstr; | |||
2714 | ||||
2715 | die.GetDWARFDeclContext(decl_ctx); | |||
2716 | sstr << decl_ctx.GetQualifiedName(); | |||
2717 | ||||
2718 | clang::DeclContext *containing_decl_ctx = | |||
2719 | GetClangDeclContextContainingDIE(die, nullptr); | |||
2720 | ParseChildParameters(sc, containing_decl_ctx, die, true, is_static, | |||
2721 | is_variadic, has_template_params, param_types, | |||
2722 | param_decls, type_quals); | |||
2723 | sstr << "("; | |||
2724 | for (size_t i = 0; i < param_types.size(); i++) { | |||
2725 | if (i > 0) | |||
2726 | sstr << ", "; | |||
2727 | sstr << param_types[i].GetTypeName(); | |||
2728 | } | |||
2729 | if (is_variadic) | |||
2730 | sstr << ", ..."; | |||
2731 | sstr << ")"; | |||
2732 | if (type_quals & clang::Qualifiers::Const) | |||
2733 | sstr << " const"; | |||
2734 | ||||
2735 | func_name.SetValue(ConstString(sstr.GetString()), false); | |||
2736 | } else | |||
2737 | func_name.SetValue(ConstString(name), false); | |||
2738 | ||||
2739 | FunctionSP func_sp; | |||
2740 | std::unique_ptr<Declaration> decl_ap; | |||
2741 | if (decl_file != 0 || decl_line != 0 || decl_column != 0) | |||
2742 | decl_ap.reset(new Declaration( | |||
2743 | sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file), | |||
2744 | decl_line, decl_column)); | |||
2745 | ||||
2746 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
2747 | // Supply the type _only_ if it has already been parsed | |||
2748 | Type *func_type = dwarf->GetDIEToType().lookup(die.GetDIE()); | |||
2749 | ||||
2750 | assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED)(static_cast <bool> (func_type == __null || func_type != ((lldb_private::Type *)1)) ? void (0) : __assert_fail ("func_type == NULL || func_type != DIE_IS_BEING_PARSED" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 2750, __extension__ __PRETTY_FUNCTION__)); | |||
2751 | ||||
2752 | if (dwarf->FixupAddress(func_range.GetBaseAddress())) { | |||
2753 | const user_id_t func_user_id = die.GetID(); | |||
2754 | func_sp.reset(new Function(sc.comp_unit, | |||
2755 | func_user_id, // UserID is the DIE offset | |||
2756 | func_user_id, func_name, func_type, | |||
2757 | func_range)); // first address range | |||
2758 | ||||
2759 | if (func_sp.get() != NULL__null) { | |||
2760 | if (frame_base.IsValid()) | |||
2761 | func_sp->GetFrameBaseExpression() = frame_base; | |||
2762 | sc.comp_unit->AddFunction(func_sp); | |||
2763 | return func_sp.get(); | |||
2764 | } | |||
2765 | } | |||
2766 | } | |||
2767 | } | |||
2768 | return NULL__null; | |||
2769 | } | |||
2770 | ||||
2771 | bool DWARFASTParserClang::ParseChildMembers( | |||
2772 | const SymbolContext &sc, const DWARFDIE &parent_die, | |||
2773 | CompilerType &class_clang_type, const LanguageType class_language, | |||
2774 | std::vector<clang::CXXBaseSpecifier *> &base_classes, | |||
2775 | std::vector<int> &member_accessibilities, | |||
2776 | DWARFDIECollection &member_function_dies, | |||
2777 | DelayedPropertyList &delayed_properties, AccessType &default_accessibility, | |||
2778 | bool &is_a_class, ClangASTImporter::LayoutInfo &layout_info) { | |||
2779 | if (!parent_die) | |||
2780 | return 0; | |||
2781 | ||||
2782 | // Get the parent byte size so we can verify any members will fit | |||
2783 | const uint64_t parent_byte_size = | |||
2784 | parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, UINT64_MAX(18446744073709551615UL)); | |||
2785 | const uint64_t parent_bit_size = | |||
2786 | parent_byte_size == UINT64_MAX(18446744073709551615UL) ? UINT64_MAX(18446744073709551615UL) : parent_byte_size * 8; | |||
2787 | ||||
2788 | uint32_t member_idx = 0; | |||
2789 | BitfieldInfo last_field_info; | |||
2790 | ||||
2791 | ModuleSP module_sp = parent_die.GetDWARF()->GetObjectFile()->GetModule(); | |||
2792 | ClangASTContext *ast = | |||
2793 | llvm::dyn_cast_or_null<ClangASTContext>(class_clang_type.GetTypeSystem()); | |||
2794 | if (ast == nullptr) | |||
2795 | return 0; | |||
2796 | ||||
2797 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); | |||
2798 | die = die.GetSibling()) { | |||
2799 | dw_tag_t tag = die.Tag(); | |||
2800 | ||||
2801 | switch (tag) { | |||
2802 | case DW_TAG_member: | |||
2803 | case DW_TAG_APPLE_property: { | |||
2804 | DWARFAttributes attributes; | |||
2805 | const size_t num_attributes = die.GetAttributes(attributes); | |||
2806 | if (num_attributes > 0) { | |||
2807 | Declaration decl; | |||
2808 | // DWARFExpression location; | |||
2809 | const char *name = NULL__null; | |||
2810 | const char *prop_name = NULL__null; | |||
2811 | const char *prop_getter_name = NULL__null; | |||
2812 | const char *prop_setter_name = NULL__null; | |||
2813 | uint32_t prop_attributes = 0; | |||
2814 | ||||
2815 | bool is_artificial = false; | |||
2816 | DWARFFormValue encoding_form; | |||
2817 | AccessType accessibility = eAccessNone; | |||
2818 | uint32_t member_byte_offset = | |||
2819 | (parent_die.Tag() == DW_TAG_union_type) ? 0 : UINT32_MAX(4294967295U); | |||
2820 | size_t byte_size = 0; | |||
2821 | int64_t bit_offset = 0; | |||
2822 | uint64_t data_bit_offset = UINT64_MAX(18446744073709551615UL); | |||
2823 | size_t bit_size = 0; | |||
2824 | bool is_external = | |||
2825 | false; // On DW_TAG_members, this means the member is static | |||
2826 | uint32_t i; | |||
2827 | for (i = 0; i < num_attributes && !is_artificial; ++i) { | |||
2828 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | |||
2829 | DWARFFormValue form_value; | |||
2830 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
2831 | switch (attr) { | |||
2832 | case DW_AT_decl_file: | |||
2833 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
2834 | form_value.Unsigned())); | |||
2835 | break; | |||
2836 | case DW_AT_decl_line: | |||
2837 | decl.SetLine(form_value.Unsigned()); | |||
2838 | break; | |||
2839 | case DW_AT_decl_column: | |||
2840 | decl.SetColumn(form_value.Unsigned()); | |||
2841 | break; | |||
2842 | case DW_AT_name: | |||
2843 | name = form_value.AsCString(); | |||
2844 | break; | |||
2845 | case DW_AT_type: | |||
2846 | encoding_form = form_value; | |||
2847 | break; | |||
2848 | case DW_AT_bit_offset: | |||
2849 | bit_offset = form_value.Signed(); | |||
2850 | break; | |||
2851 | case DW_AT_bit_size: | |||
2852 | bit_size = form_value.Unsigned(); | |||
2853 | break; | |||
2854 | case DW_AT_byte_size: | |||
2855 | byte_size = form_value.Unsigned(); | |||
2856 | break; | |||
2857 | case DW_AT_data_bit_offset: | |||
2858 | data_bit_offset = form_value.Unsigned(); | |||
2859 | break; | |||
2860 | case DW_AT_data_member_location: | |||
2861 | if (form_value.BlockData()) { | |||
2862 | Value initialValue(0); | |||
2863 | Value memberOffset(0); | |||
2864 | const DWARFDataExtractor &debug_info_data = | |||
2865 | die.GetDWARF()->get_debug_info_data(); | |||
2866 | uint32_t block_length = form_value.Unsigned(); | |||
2867 | uint32_t block_offset = | |||
2868 | form_value.BlockData() - debug_info_data.GetDataStart(); | |||
2869 | if (DWARFExpression::Evaluate( | |||
2870 | nullptr, // ExecutionContext * | |||
2871 | nullptr, // RegisterContext * | |||
2872 | module_sp, debug_info_data, die.GetCU(), block_offset, | |||
2873 | block_length, eRegisterKindDWARF, &initialValue, | |||
2874 | nullptr, memberOffset, nullptr)) { | |||
2875 | member_byte_offset = memberOffset.ResolveValue(NULL__null).UInt(); | |||
2876 | } | |||
2877 | } else { | |||
2878 | // With DWARF 3 and later, if the value is an integer constant, | |||
2879 | // this form value is the offset in bytes from the beginning | |||
2880 | // of the containing entity. | |||
2881 | member_byte_offset = form_value.Unsigned(); | |||
2882 | } | |||
2883 | break; | |||
2884 | ||||
2885 | case DW_AT_accessibility: | |||
2886 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | |||
2887 | break; | |||
2888 | case DW_AT_artificial: | |||
2889 | is_artificial = form_value.Boolean(); | |||
2890 | break; | |||
2891 | case DW_AT_APPLE_property_name: | |||
2892 | prop_name = form_value.AsCString(); | |||
2893 | break; | |||
2894 | case DW_AT_APPLE_property_getter: | |||
2895 | prop_getter_name = form_value.AsCString(); | |||
2896 | break; | |||
2897 | case DW_AT_APPLE_property_setter: | |||
2898 | prop_setter_name = form_value.AsCString(); | |||
2899 | break; | |||
2900 | case DW_AT_APPLE_property_attribute: | |||
2901 | prop_attributes = form_value.Unsigned(); | |||
2902 | break; | |||
2903 | case DW_AT_external: | |||
2904 | is_external = form_value.Boolean(); | |||
2905 | break; | |||
2906 | ||||
2907 | default: | |||
2908 | case DW_AT_declaration: | |||
2909 | case DW_AT_description: | |||
2910 | case DW_AT_mutable: | |||
2911 | case DW_AT_visibility: | |||
2912 | case DW_AT_sibling: | |||
2913 | break; | |||
2914 | } | |||
2915 | } | |||
2916 | } | |||
2917 | ||||
2918 | if (prop_name) { | |||
2919 | ConstString fixed_getter; | |||
2920 | ConstString fixed_setter; | |||
2921 | ||||
2922 | // Check if the property getter/setter were provided as full | |||
2923 | // names. We want basenames, so we extract them. | |||
2924 | ||||
2925 | if (prop_getter_name && prop_getter_name[0] == '-') { | |||
2926 | ObjCLanguage::MethodName prop_getter_method(prop_getter_name, true); | |||
2927 | prop_getter_name = prop_getter_method.GetSelector().GetCString(); | |||
2928 | } | |||
2929 | ||||
2930 | if (prop_setter_name && prop_setter_name[0] == '-') { | |||
2931 | ObjCLanguage::MethodName prop_setter_method(prop_setter_name, true); | |||
2932 | prop_setter_name = prop_setter_method.GetSelector().GetCString(); | |||
2933 | } | |||
2934 | ||||
2935 | // If the names haven't been provided, they need to be | |||
2936 | // filled in. | |||
2937 | ||||
2938 | if (!prop_getter_name) { | |||
2939 | prop_getter_name = prop_name; | |||
2940 | } | |||
2941 | if (!prop_setter_name && prop_name[0] && | |||
2942 | !(prop_attributes & DW_APPLE_PROPERTY_readonly)) { | |||
2943 | StreamString ss; | |||
2944 | ||||
2945 | ss.Printf("set%c%s:", toupper(prop_name[0]), &prop_name[1]); | |||
2946 | ||||
2947 | fixed_setter.SetString(ss.GetString()); | |||
2948 | prop_setter_name = fixed_setter.GetCString(); | |||
2949 | } | |||
2950 | } | |||
2951 | ||||
2952 | // Clang has a DWARF generation bug where sometimes it | |||
2953 | // represents fields that are references with bad byte size | |||
2954 | // and bit size/offset information such as: | |||
2955 | // | |||
2956 | // DW_AT_byte_size( 0x00 ) | |||
2957 | // DW_AT_bit_size( 0x40 ) | |||
2958 | // DW_AT_bit_offset( 0xffffffffffffffc0 ) | |||
2959 | // | |||
2960 | // So check the bit offset to make sure it is sane, and if | |||
2961 | // the values are not sane, remove them. If we don't do this | |||
2962 | // then we will end up with a crash if we try to use this | |||
2963 | // type in an expression when clang becomes unhappy with its | |||
2964 | // recycled debug info. | |||
2965 | ||||
2966 | if (byte_size == 0 && bit_offset < 0) { | |||
2967 | bit_size = 0; | |||
2968 | bit_offset = 0; | |||
2969 | } | |||
2970 | ||||
2971 | // FIXME: Make Clang ignore Objective-C accessibility for expressions | |||
2972 | if (class_language == eLanguageTypeObjC || | |||
2973 | class_language == eLanguageTypeObjC_plus_plus) | |||
2974 | accessibility = eAccessNone; | |||
2975 | ||||
2976 | if (member_idx == 0 && !is_artificial && name && | |||
2977 | (strstr(name, "_vptr$") == name)) { | |||
2978 | // Not all compilers will mark the vtable pointer | |||
2979 | // member as artificial (llvm-gcc). We can't have | |||
2980 | // the virtual members in our classes otherwise it | |||
2981 | // throws off all child offsets since we end up | |||
2982 | // having and extra pointer sized member in our | |||
2983 | // class layouts. | |||
2984 | is_artificial = true; | |||
2985 | } | |||
2986 | ||||
2987 | // Handle static members | |||
2988 | if (is_external && member_byte_offset == UINT32_MAX(4294967295U)) { | |||
2989 | Type *var_type = die.ResolveTypeUID(DIERef(encoding_form)); | |||
2990 | ||||
2991 | if (var_type) { | |||
2992 | if (accessibility == eAccessNone) | |||
2993 | accessibility = eAccessPublic; | |||
2994 | ClangASTContext::AddVariableToRecordType( | |||
2995 | class_clang_type, name, var_type->GetLayoutCompilerType(), | |||
2996 | accessibility); | |||
2997 | } | |||
2998 | break; | |||
2999 | } | |||
3000 | ||||
3001 | if (is_artificial == false) { | |||
3002 | Type *member_type = die.ResolveTypeUID(DIERef(encoding_form)); | |||
3003 | ||||
3004 | clang::FieldDecl *field_decl = NULL__null; | |||
3005 | if (tag == DW_TAG_member) { | |||
3006 | if (member_type) { | |||
3007 | if (accessibility == eAccessNone) | |||
3008 | accessibility = default_accessibility; | |||
3009 | member_accessibilities.push_back(accessibility); | |||
3010 | ||||
3011 | uint64_t field_bit_offset = | |||
3012 | (member_byte_offset == UINT32_MAX(4294967295U) ? 0 | |||
3013 | : (member_byte_offset * 8)); | |||
3014 | if (bit_size > 0) { | |||
3015 | ||||
3016 | BitfieldInfo this_field_info; | |||
3017 | this_field_info.bit_offset = field_bit_offset; | |||
3018 | this_field_info.bit_size = bit_size; | |||
3019 | ||||
3020 | ///////////////////////////////////////////////////////////// | |||
3021 | // How to locate a field given the DWARF debug information | |||
3022 | // | |||
3023 | // AT_byte_size indicates the size of the word in which the | |||
3024 | // bit offset must be interpreted. | |||
3025 | // | |||
3026 | // AT_data_member_location indicates the byte offset of the | |||
3027 | // word from the base address of the structure. | |||
3028 | // | |||
3029 | // AT_bit_offset indicates how many bits into the word | |||
3030 | // (according to the host endianness) the low-order bit of | |||
3031 | // the field starts. AT_bit_offset can be negative. | |||
3032 | // | |||
3033 | // AT_bit_size indicates the size of the field in bits. | |||
3034 | ///////////////////////////////////////////////////////////// | |||
3035 | ||||
3036 | if (data_bit_offset != UINT64_MAX(18446744073709551615UL)) { | |||
3037 | this_field_info.bit_offset = data_bit_offset; | |||
3038 | } else { | |||
3039 | if (byte_size == 0) | |||
3040 | byte_size = member_type->GetByteSize(); | |||
3041 | ||||
3042 | ObjectFile *objfile = die.GetDWARF()->GetObjectFile(); | |||
3043 | if (objfile->GetByteOrder() == eByteOrderLittle) { | |||
3044 | this_field_info.bit_offset += byte_size * 8; | |||
3045 | this_field_info.bit_offset -= (bit_offset + bit_size); | |||
3046 | } else { | |||
3047 | this_field_info.bit_offset += bit_offset; | |||
3048 | } | |||
3049 | } | |||
3050 | ||||
3051 | if ((this_field_info.bit_offset >= parent_bit_size) || | |||
3052 | !last_field_info.NextBitfieldOffsetIsValid( | |||
3053 | this_field_info.bit_offset)) { | |||
3054 | ObjectFile *objfile = die.GetDWARF()->GetObjectFile(); | |||
3055 | objfile->GetModule()->ReportWarning( | |||
3056 | "0x%8.8" PRIx64"l" "x" ": %s bitfield named \"%s\" has invalid " | |||
3057 | "bit offset (0x%8.8" PRIx64"l" "x" | |||
3058 | ") member will be ignored. Please file a bug against the " | |||
3059 | "compiler and include the preprocessed output for %s\n", | |||
3060 | die.GetID(), DW_TAG_value_to_name(tag), name, | |||
3061 | this_field_info.bit_offset, | |||
3062 | sc.comp_unit ? sc.comp_unit->GetPath().c_str() | |||
3063 | : "the source file"); | |||
3064 | this_field_info.Clear(); | |||
3065 | continue; | |||
3066 | } | |||
3067 | ||||
3068 | // Update the field bit offset we will report for layout | |||
3069 | field_bit_offset = this_field_info.bit_offset; | |||
3070 | ||||
3071 | // If the member to be emitted did not start on a character | |||
3072 | // boundary and there is | |||
3073 | // empty space between the last field and this one, then we need | |||
3074 | // to emit an | |||
3075 | // anonymous member filling up the space up to its start. There | |||
3076 | // are three cases | |||
3077 | // here: | |||
3078 | // | |||
3079 | // 1 If the previous member ended on a character boundary, then | |||
3080 | // we can emit an | |||
3081 | // anonymous member starting at the most recent character | |||
3082 | // boundary. | |||
3083 | // | |||
3084 | // 2 If the previous member did not end on a character boundary | |||
3085 | // and the distance | |||
3086 | // from the end of the previous member to the current member | |||
3087 | // is less than a | |||
3088 | // word width, then we can emit an anonymous member starting | |||
3089 | // right after the | |||
3090 | // previous member and right before this member. | |||
3091 | // | |||
3092 | // 3 If the previous member did not end on a character boundary | |||
3093 | // and the distance | |||
3094 | // from the end of the previous member to the current member | |||
3095 | // is greater than | |||
3096 | // or equal a word width, then we act as in Case 1. | |||
3097 | ||||
3098 | const uint64_t character_width = 8; | |||
3099 | const uint64_t word_width = 32; | |||
3100 | ||||
3101 | // Objective-C has invalid DW_AT_bit_offset values in older | |||
3102 | // versions | |||
3103 | // of clang, so we have to be careful and only insert unnamed | |||
3104 | // bitfields | |||
3105 | // if we have a new enough clang. | |||
3106 | bool detect_unnamed_bitfields = true; | |||
3107 | ||||
3108 | if (class_language == eLanguageTypeObjC || | |||
3109 | class_language == eLanguageTypeObjC_plus_plus) | |||
3110 | detect_unnamed_bitfields = | |||
3111 | die.GetCU()->Supports_unnamed_objc_bitfields(); | |||
3112 | ||||
3113 | if (detect_unnamed_bitfields) { | |||
3114 | BitfieldInfo anon_field_info; | |||
3115 | ||||
3116 | if ((this_field_info.bit_offset % character_width) != | |||
3117 | 0) // not char aligned | |||
3118 | { | |||
3119 | uint64_t last_field_end = 0; | |||
3120 | ||||
3121 | if (last_field_info.IsValid()) | |||
3122 | last_field_end = | |||
3123 | last_field_info.bit_offset + last_field_info.bit_size; | |||
3124 | ||||
3125 | if (this_field_info.bit_offset != last_field_end) { | |||
3126 | if (((last_field_end % character_width) == 0) || // case 1 | |||
3127 | (this_field_info.bit_offset - last_field_end >= | |||
3128 | word_width)) // case 3 | |||
3129 | { | |||
3130 | anon_field_info.bit_size = | |||
3131 | this_field_info.bit_offset % character_width; | |||
3132 | anon_field_info.bit_offset = | |||
3133 | this_field_info.bit_offset - | |||
3134 | anon_field_info.bit_size; | |||
3135 | } else // case 2 | |||
3136 | { | |||
3137 | anon_field_info.bit_size = | |||
3138 | this_field_info.bit_offset - last_field_end; | |||
3139 | anon_field_info.bit_offset = last_field_end; | |||
3140 | } | |||
3141 | } | |||
3142 | } | |||
3143 | ||||
3144 | if (anon_field_info.IsValid()) { | |||
3145 | clang::FieldDecl *unnamed_bitfield_decl = | |||
3146 | ClangASTContext::AddFieldToRecordType( | |||
3147 | class_clang_type, NULL__null, | |||
3148 | m_ast.GetBuiltinTypeForEncodingAndBitSize( | |||
3149 | eEncodingSint, word_width), | |||
3150 | accessibility, anon_field_info.bit_size); | |||
3151 | ||||
3152 | layout_info.field_offsets.insert(std::make_pair( | |||
3153 | unnamed_bitfield_decl, anon_field_info.bit_offset)); | |||
3154 | } | |||
3155 | } | |||
3156 | last_field_info = this_field_info; | |||
3157 | } else { | |||
3158 | last_field_info.Clear(); | |||
3159 | } | |||
3160 | ||||
3161 | CompilerType member_clang_type = | |||
3162 | member_type->GetLayoutCompilerType(); | |||
3163 | if (!member_clang_type.IsCompleteType()) | |||
3164 | member_clang_type.GetCompleteType(); | |||
3165 | ||||
3166 | { | |||
3167 | // Older versions of clang emit array[0] and array[1] in the | |||
3168 | // same way (<rdar://problem/12566646>). | |||
3169 | // If the current field is at the end of the structure, then | |||
3170 | // there is definitely no room for extra | |||
3171 | // elements and we override the type to array[0]. | |||
3172 | ||||
3173 | CompilerType member_array_element_type; | |||
3174 | uint64_t member_array_size; | |||
3175 | bool member_array_is_incomplete; | |||
3176 | ||||
3177 | if (member_clang_type.IsArrayType( | |||
3178 | &member_array_element_type, &member_array_size, | |||
3179 | &member_array_is_incomplete) && | |||
3180 | !member_array_is_incomplete) { | |||
3181 | uint64_t parent_byte_size = | |||
3182 | parent_die.GetAttributeValueAsUnsigned(DW_AT_byte_size, | |||
3183 | UINT64_MAX(18446744073709551615UL)); | |||
3184 | ||||
3185 | if (member_byte_offset >= parent_byte_size) { | |||
3186 | if (member_array_size != 1 && | |||
3187 | (member_array_size != 0 || | |||
3188 | member_byte_offset > parent_byte_size)) { | |||
3189 | module_sp->ReportError( | |||
3190 | "0x%8.8" PRIx64"l" "x" | |||
3191 | ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64"l" "x" | |||
3192 | " which extends beyond the bounds of 0x%8.8" PRIx64"l" "x", | |||
3193 | die.GetID(), name, encoding_form.Reference(), | |||
3194 | parent_die.GetID()); | |||
3195 | } | |||
3196 | ||||
3197 | member_clang_type = m_ast.CreateArrayType( | |||
3198 | member_array_element_type, 0, false); | |||
3199 | } | |||
3200 | } | |||
3201 | } | |||
3202 | ||||
3203 | if (ClangASTContext::IsCXXClassType(member_clang_type) && | |||
3204 | member_clang_type.GetCompleteType() == false) { | |||
3205 | if (die.GetCU()->GetProducer() == eProducerClang) | |||
3206 | module_sp->ReportError( | |||
3207 | "DWARF DIE at 0x%8.8x (class %s) has a member variable " | |||
3208 | "0x%8.8x (%s) whose type is a forward declaration, not a " | |||
3209 | "complete definition.\nTry compiling the source file " | |||
3210 | "with -fstandalone-debug", | |||
3211 | parent_die.GetOffset(), parent_die.GetName(), | |||
3212 | die.GetOffset(), name); | |||
3213 | else | |||
3214 | module_sp->ReportError( | |||
3215 | "DWARF DIE at 0x%8.8x (class %s) has a member variable " | |||
3216 | "0x%8.8x (%s) whose type is a forward declaration, not a " | |||
3217 | "complete definition.\nPlease file a bug against the " | |||
3218 | "compiler and include the preprocessed output for %s", | |||
3219 | parent_die.GetOffset(), parent_die.GetName(), | |||
3220 | die.GetOffset(), name, | |||
3221 | sc.comp_unit ? sc.comp_unit->GetPath().c_str() | |||
3222 | : "the source file"); | |||
3223 | // We have no choice other than to pretend that the member class | |||
3224 | // is complete. If we don't do this, clang will crash when | |||
3225 | // trying | |||
3226 | // to layout the class. Since we provide layout assistance, all | |||
3227 | // ivars in this class and other classes will be fine, this is | |||
3228 | // the best we can do short of crashing. | |||
3229 | if (ClangASTContext::StartTagDeclarationDefinition( | |||
3230 | member_clang_type)) { | |||
3231 | ClangASTContext::CompleteTagDeclarationDefinition( | |||
3232 | member_clang_type); | |||
3233 | } else { | |||
3234 | module_sp->ReportError( | |||
3235 | "DWARF DIE at 0x%8.8x (class %s) has a member variable " | |||
3236 | "0x%8.8x (%s) whose type claims to be a C++ class but we " | |||
3237 | "were not able to start its definition.\nPlease file a " | |||
3238 | "bug and attach the file at the start of this error " | |||
3239 | "message", | |||
3240 | parent_die.GetOffset(), parent_die.GetName(), | |||
3241 | die.GetOffset(), name); | |||
3242 | } | |||
3243 | } | |||
3244 | ||||
3245 | field_decl = ClangASTContext::AddFieldToRecordType( | |||
3246 | class_clang_type, name, member_clang_type, accessibility, | |||
3247 | bit_size); | |||
3248 | ||||
3249 | m_ast.SetMetadataAsUserID(field_decl, die.GetID()); | |||
3250 | ||||
3251 | layout_info.field_offsets.insert( | |||
3252 | std::make_pair(field_decl, field_bit_offset)); | |||
3253 | } else { | |||
3254 | if (name) | |||
3255 | module_sp->ReportError( | |||
3256 | "0x%8.8" PRIx64"l" "x" | |||
3257 | ": DW_TAG_member '%s' refers to type 0x%8.8" PRIx64"l" "x" | |||
3258 | " which was unable to be parsed", | |||
3259 | die.GetID(), name, encoding_form.Reference()); | |||
3260 | else | |||
3261 | module_sp->ReportError( | |||
3262 | "0x%8.8" PRIx64"l" "x" | |||
3263 | ": DW_TAG_member refers to type 0x%8.8" PRIx64"l" "x" | |||
3264 | " which was unable to be parsed", | |||
3265 | die.GetID(), encoding_form.Reference()); | |||
3266 | } | |||
3267 | } | |||
3268 | ||||
3269 | if (prop_name != NULL__null && member_type) { | |||
3270 | clang::ObjCIvarDecl *ivar_decl = NULL__null; | |||
3271 | ||||
3272 | if (field_decl) { | |||
3273 | ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl); | |||
3274 | assert(ivar_decl != NULL)(static_cast <bool> (ivar_decl != __null) ? void (0) : __assert_fail ("ivar_decl != NULL", "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 3274, __extension__ __PRETTY_FUNCTION__)); | |||
3275 | } | |||
3276 | ||||
3277 | ClangASTMetadata metadata; | |||
3278 | metadata.SetUserID(die.GetID()); | |||
3279 | delayed_properties.push_back(DelayedAddObjCClassProperty( | |||
3280 | class_clang_type, prop_name, | |||
3281 | member_type->GetLayoutCompilerType(), ivar_decl, | |||
3282 | prop_setter_name, prop_getter_name, prop_attributes, | |||
3283 | &metadata)); | |||
3284 | ||||
3285 | if (ivar_decl) | |||
3286 | m_ast.SetMetadataAsUserID(ivar_decl, die.GetID()); | |||
3287 | } | |||
3288 | } | |||
3289 | } | |||
3290 | ++member_idx; | |||
3291 | } break; | |||
3292 | ||||
3293 | case DW_TAG_subprogram: | |||
3294 | // Let the type parsing code handle this one for us. | |||
3295 | member_function_dies.Append(die); | |||
3296 | break; | |||
3297 | ||||
3298 | case DW_TAG_inheritance: { | |||
3299 | is_a_class = true; | |||
3300 | if (default_accessibility == eAccessNone) | |||
3301 | default_accessibility = eAccessPrivate; | |||
3302 | // TODO: implement DW_TAG_inheritance type parsing | |||
3303 | DWARFAttributes attributes; | |||
3304 | const size_t num_attributes = die.GetAttributes(attributes); | |||
3305 | if (num_attributes > 0) { | |||
3306 | Declaration decl; | |||
3307 | DWARFExpression location(die.GetCU()); | |||
3308 | DWARFFormValue encoding_form; | |||
3309 | AccessType accessibility = default_accessibility; | |||
3310 | bool is_virtual = false; | |||
3311 | bool is_base_of_class = true; | |||
3312 | off_t member_byte_offset = 0; | |||
3313 | uint32_t i; | |||
3314 | for (i = 0; i < num_attributes; ++i) { | |||
3315 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | |||
3316 | DWARFFormValue form_value; | |||
3317 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
3318 | switch (attr) { | |||
3319 | case DW_AT_decl_file: | |||
3320 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
3321 | form_value.Unsigned())); | |||
3322 | break; | |||
3323 | case DW_AT_decl_line: | |||
3324 | decl.SetLine(form_value.Unsigned()); | |||
3325 | break; | |||
3326 | case DW_AT_decl_column: | |||
3327 | decl.SetColumn(form_value.Unsigned()); | |||
3328 | break; | |||
3329 | case DW_AT_type: | |||
3330 | encoding_form = form_value; | |||
3331 | break; | |||
3332 | case DW_AT_data_member_location: | |||
3333 | if (form_value.BlockData()) { | |||
3334 | Value initialValue(0); | |||
3335 | Value memberOffset(0); | |||
3336 | const DWARFDataExtractor &debug_info_data = | |||
3337 | die.GetDWARF()->get_debug_info_data(); | |||
3338 | uint32_t block_length = form_value.Unsigned(); | |||
3339 | uint32_t block_offset = | |||
3340 | form_value.BlockData() - debug_info_data.GetDataStart(); | |||
3341 | if (DWARFExpression::Evaluate(nullptr, nullptr, module_sp, | |||
3342 | debug_info_data, die.GetCU(), | |||
3343 | block_offset, block_length, | |||
3344 | eRegisterKindDWARF, &initialValue, | |||
3345 | nullptr, memberOffset, nullptr)) { | |||
3346 | member_byte_offset = memberOffset.ResolveValue(NULL__null).UInt(); | |||
3347 | } | |||
3348 | } else { | |||
3349 | // With DWARF 3 and later, if the value is an integer constant, | |||
3350 | // this form value is the offset in bytes from the beginning | |||
3351 | // of the containing entity. | |||
3352 | member_byte_offset = form_value.Unsigned(); | |||
3353 | } | |||
3354 | break; | |||
3355 | ||||
3356 | case DW_AT_accessibility: | |||
3357 | accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); | |||
3358 | break; | |||
3359 | ||||
3360 | case DW_AT_virtuality: | |||
3361 | is_virtual = form_value.Boolean(); | |||
3362 | break; | |||
3363 | ||||
3364 | case DW_AT_sibling: | |||
3365 | break; | |||
3366 | ||||
3367 | default: | |||
3368 | break; | |||
3369 | } | |||
3370 | } | |||
3371 | } | |||
3372 | ||||
3373 | Type *base_class_type = die.ResolveTypeUID(DIERef(encoding_form)); | |||
3374 | if (base_class_type == NULL__null) { | |||
3375 | module_sp->ReportError("0x%8.8x: DW_TAG_inheritance failed to " | |||
3376 | "resolve the base class at 0x%8.8" PRIx64"l" "x" | |||
3377 | " from enclosing type 0x%8.8x. \nPlease file " | |||
3378 | "a bug and attach the file at the start of " | |||
3379 | "this error message", | |||
3380 | die.GetOffset(), encoding_form.Reference(), | |||
3381 | parent_die.GetOffset()); | |||
3382 | break; | |||
3383 | } | |||
3384 | ||||
3385 | CompilerType base_class_clang_type = | |||
3386 | base_class_type->GetFullCompilerType(); | |||
3387 | assert(base_class_clang_type)(static_cast <bool> (base_class_clang_type) ? void (0) : __assert_fail ("base_class_clang_type", "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 3387, __extension__ __PRETTY_FUNCTION__)); | |||
3388 | if (class_language == eLanguageTypeObjC) { | |||
3389 | ast->SetObjCSuperClass(class_clang_type, base_class_clang_type); | |||
3390 | } else { | |||
3391 | base_classes.push_back(ast->CreateBaseClassSpecifier( | |||
3392 | base_class_clang_type.GetOpaqueQualType(), accessibility, | |||
3393 | is_virtual, is_base_of_class)); | |||
3394 | ||||
3395 | if (is_virtual) { | |||
3396 | // Do not specify any offset for virtual inheritance. The DWARF | |||
3397 | // produced by clang doesn't | |||
3398 | // give us a constant offset, but gives us a DWARF expressions that | |||
3399 | // requires an actual object | |||
3400 | // in memory. the DW_AT_data_member_location for a virtual base | |||
3401 | // class looks like: | |||
3402 | // DW_AT_data_member_location( DW_OP_dup, DW_OP_deref, | |||
3403 | // DW_OP_constu(0x00000018), DW_OP_minus, DW_OP_deref, | |||
3404 | // DW_OP_plus ) | |||
3405 | // Given this, there is really no valid response we can give to | |||
3406 | // clang for virtual base | |||
3407 | // class offsets, and this should eventually be removed from | |||
3408 | // LayoutRecordType() in the external | |||
3409 | // AST source in clang. | |||
3410 | } else { | |||
3411 | layout_info.base_offsets.insert(std::make_pair( | |||
3412 | ast->GetAsCXXRecordDecl( | |||
3413 | base_class_clang_type.GetOpaqueQualType()), | |||
3414 | clang::CharUnits::fromQuantity(member_byte_offset))); | |||
3415 | } | |||
3416 | } | |||
3417 | } | |||
3418 | } break; | |||
3419 | ||||
3420 | default: | |||
3421 | break; | |||
3422 | } | |||
3423 | } | |||
3424 | ||||
3425 | return true; | |||
3426 | } | |||
3427 | ||||
3428 | size_t DWARFASTParserClang::ParseChildParameters( | |||
3429 | const SymbolContext &sc, clang::DeclContext *containing_decl_ctx, | |||
3430 | const DWARFDIE &parent_die, bool skip_artificial, bool &is_static, | |||
3431 | bool &is_variadic, bool &has_template_params, | |||
3432 | std::vector<CompilerType> &function_param_types, | |||
3433 | std::vector<clang::ParmVarDecl *> &function_param_decls, | |||
3434 | unsigned &type_quals) { | |||
3435 | if (!parent_die) | |||
3436 | return 0; | |||
3437 | ||||
3438 | size_t arg_idx = 0; | |||
3439 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); | |||
3440 | die = die.GetSibling()) { | |||
3441 | const dw_tag_t tag = die.Tag(); | |||
3442 | switch (tag) { | |||
3443 | case DW_TAG_formal_parameter: { | |||
3444 | DWARFAttributes attributes; | |||
3445 | const size_t num_attributes = die.GetAttributes(attributes); | |||
3446 | if (num_attributes > 0) { | |||
3447 | const char *name = NULL__null; | |||
3448 | Declaration decl; | |||
3449 | DWARFFormValue param_type_die_form; | |||
3450 | bool is_artificial = false; | |||
3451 | // one of None, Auto, Register, Extern, Static, PrivateExtern | |||
3452 | ||||
3453 | clang::StorageClass storage = clang::SC_None; | |||
3454 | uint32_t i; | |||
3455 | for (i = 0; i < num_attributes; ++i) { | |||
3456 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | |||
3457 | DWARFFormValue form_value; | |||
3458 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
3459 | switch (attr) { | |||
3460 | case DW_AT_decl_file: | |||
3461 | decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex( | |||
3462 | form_value.Unsigned())); | |||
3463 | break; | |||
3464 | case DW_AT_decl_line: | |||
3465 | decl.SetLine(form_value.Unsigned()); | |||
3466 | break; | |||
3467 | case DW_AT_decl_column: | |||
3468 | decl.SetColumn(form_value.Unsigned()); | |||
3469 | break; | |||
3470 | case DW_AT_name: | |||
3471 | name = form_value.AsCString(); | |||
3472 | break; | |||
3473 | case DW_AT_type: | |||
3474 | param_type_die_form = form_value; | |||
3475 | break; | |||
3476 | case DW_AT_artificial: | |||
3477 | is_artificial = form_value.Boolean(); | |||
3478 | break; | |||
3479 | case DW_AT_location: | |||
3480 | // if (form_value.BlockData()) | |||
3481 | // { | |||
3482 | // const DWARFDataExtractor& | |||
3483 | // debug_info_data = debug_info(); | |||
3484 | // uint32_t block_length = | |||
3485 | // form_value.Unsigned(); | |||
3486 | // DWARFDataExtractor | |||
3487 | // location(debug_info_data, | |||
3488 | // form_value.BlockData() - | |||
3489 | // debug_info_data.GetDataStart(), | |||
3490 | // block_length); | |||
3491 | // } | |||
3492 | // else | |||
3493 | // { | |||
3494 | // } | |||
3495 | // break; | |||
3496 | case DW_AT_const_value: | |||
3497 | case DW_AT_default_value: | |||
3498 | case DW_AT_description: | |||
3499 | case DW_AT_endianity: | |||
3500 | case DW_AT_is_optional: | |||
3501 | case DW_AT_segment: | |||
3502 | case DW_AT_variable_parameter: | |||
3503 | default: | |||
3504 | case DW_AT_abstract_origin: | |||
3505 | case DW_AT_sibling: | |||
3506 | break; | |||
3507 | } | |||
3508 | } | |||
3509 | } | |||
3510 | ||||
3511 | bool skip = false; | |||
3512 | if (skip_artificial) { | |||
3513 | if (is_artificial) { | |||
3514 | // In order to determine if a C++ member function is | |||
3515 | // "const" we have to look at the const-ness of "this"... | |||
3516 | // Ugly, but that | |||
3517 | if (arg_idx == 0) { | |||
3518 | if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind())) { | |||
3519 | // Often times compilers omit the "this" name for the | |||
3520 | // specification DIEs, so we can't rely upon the name | |||
3521 | // being in the formal parameter DIE... | |||
3522 | if (name == NULL__null || ::strcmp(name, "this") == 0) { | |||
3523 | Type *this_type = | |||
3524 | die.ResolveTypeUID(DIERef(param_type_die_form)); | |||
3525 | if (this_type) { | |||
3526 | uint32_t encoding_mask = this_type->GetEncodingMask(); | |||
3527 | if (encoding_mask & Type::eEncodingIsPointerUID) { | |||
3528 | is_static = false; | |||
3529 | ||||
3530 | if (encoding_mask & (1u << Type::eEncodingIsConstUID)) | |||
3531 | type_quals |= clang::Qualifiers::Const; | |||
3532 | if (encoding_mask & (1u << Type::eEncodingIsVolatileUID)) | |||
3533 | type_quals |= clang::Qualifiers::Volatile; | |||
3534 | } | |||
3535 | } | |||
3536 | } | |||
3537 | } | |||
3538 | } | |||
3539 | skip = true; | |||
3540 | } else { | |||
3541 | ||||
3542 | // HACK: Objective C formal parameters "self" and "_cmd" | |||
3543 | // are not marked as artificial in the DWARF... | |||
3544 | CompileUnit *comp_unit = die.GetLLDBCompileUnit(); | |||
3545 | if (comp_unit) { | |||
3546 | switch (comp_unit->GetLanguage()) { | |||
3547 | case eLanguageTypeObjC: | |||
3548 | case eLanguageTypeObjC_plus_plus: | |||
3549 | if (name && name[0] && | |||
3550 | (strcmp(name, "self") == 0 || strcmp(name, "_cmd") == 0)) | |||
3551 | skip = true; | |||
3552 | break; | |||
3553 | default: | |||
3554 | break; | |||
3555 | } | |||
3556 | } | |||
3557 | } | |||
3558 | } | |||
3559 | ||||
3560 | if (!skip) { | |||
3561 | Type *type = die.ResolveTypeUID(DIERef(param_type_die_form)); | |||
3562 | if (type) { | |||
3563 | function_param_types.push_back(type->GetForwardCompilerType()); | |||
3564 | ||||
3565 | clang::ParmVarDecl *param_var_decl = | |||
3566 | m_ast.CreateParameterDeclaration( | |||
3567 | name, type->GetForwardCompilerType(), storage); | |||
3568 | assert(param_var_decl)(static_cast <bool> (param_var_decl) ? void (0) : __assert_fail ("param_var_decl", "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 3568, __extension__ __PRETTY_FUNCTION__)); | |||
3569 | function_param_decls.push_back(param_var_decl); | |||
3570 | ||||
3571 | m_ast.SetMetadataAsUserID(param_var_decl, die.GetID()); | |||
3572 | } | |||
3573 | } | |||
3574 | } | |||
3575 | arg_idx++; | |||
3576 | } break; | |||
3577 | ||||
3578 | case DW_TAG_unspecified_parameters: | |||
3579 | is_variadic = true; | |||
3580 | break; | |||
3581 | ||||
3582 | case DW_TAG_template_type_parameter: | |||
3583 | case DW_TAG_template_value_parameter: | |||
3584 | case DW_TAG_GNU_template_parameter_pack: | |||
3585 | // The one caller of this was never using the template_param_infos, | |||
3586 | // and the local variable was taking up a large amount of stack space | |||
3587 | // in SymbolFileDWARF::ParseType() so this was removed. If we ever need | |||
3588 | // the template params back, we can add them back. | |||
3589 | // ParseTemplateDIE (dwarf_cu, die, template_param_infos); | |||
3590 | has_template_params = true; | |||
3591 | break; | |||
3592 | ||||
3593 | default: | |||
3594 | break; | |||
3595 | } | |||
3596 | } | |||
3597 | return arg_idx; | |||
3598 | } | |||
3599 | ||||
3600 | void DWARFASTParserClang::ParseChildArrayInfo( | |||
3601 | const SymbolContext &sc, const DWARFDIE &parent_die, int64_t &first_index, | |||
3602 | std::vector<uint64_t> &element_orders, uint32_t &byte_stride, | |||
3603 | uint32_t &bit_stride) { | |||
3604 | if (!parent_die) | |||
3605 | return; | |||
3606 | ||||
3607 | for (DWARFDIE die = parent_die.GetFirstChild(); die.IsValid(); | |||
3608 | die = die.GetSibling()) { | |||
3609 | const dw_tag_t tag = die.Tag(); | |||
3610 | switch (tag) { | |||
3611 | case DW_TAG_subrange_type: { | |||
3612 | DWARFAttributes attributes; | |||
3613 | const size_t num_child_attributes = die.GetAttributes(attributes); | |||
3614 | if (num_child_attributes > 0) { | |||
3615 | uint64_t num_elements = 0; | |||
3616 | uint64_t lower_bound = 0; | |||
3617 | uint64_t upper_bound = 0; | |||
3618 | bool upper_bound_valid = false; | |||
3619 | uint32_t i; | |||
3620 | for (i = 0; i < num_child_attributes; ++i) { | |||
3621 | const dw_attr_t attr = attributes.AttributeAtIndex(i); | |||
3622 | DWARFFormValue form_value; | |||
3623 | if (attributes.ExtractFormValueAtIndex(i, form_value)) { | |||
3624 | switch (attr) { | |||
3625 | case DW_AT_name: | |||
3626 | break; | |||
3627 | ||||
3628 | case DW_AT_count: | |||
3629 | num_elements = form_value.Unsigned(); | |||
3630 | break; | |||
3631 | ||||
3632 | case DW_AT_bit_stride: | |||
3633 | bit_stride = form_value.Unsigned(); | |||
3634 | break; | |||
3635 | ||||
3636 | case DW_AT_byte_stride: | |||
3637 | byte_stride = form_value.Unsigned(); | |||
3638 | break; | |||
3639 | ||||
3640 | case DW_AT_lower_bound: | |||
3641 | lower_bound = form_value.Unsigned(); | |||
3642 | break; | |||
3643 | ||||
3644 | case DW_AT_upper_bound: | |||
3645 | upper_bound_valid = true; | |||
3646 | upper_bound = form_value.Unsigned(); | |||
3647 | break; | |||
3648 | ||||
3649 | default: | |||
3650 | case DW_AT_abstract_origin: | |||
3651 | case DW_AT_accessibility: | |||
3652 | case DW_AT_allocated: | |||
3653 | case DW_AT_associated: | |||
3654 | case DW_AT_data_location: | |||
3655 | case DW_AT_declaration: | |||
3656 | case DW_AT_description: | |||
3657 | case DW_AT_sibling: | |||
3658 | case DW_AT_threads_scaled: | |||
3659 | case DW_AT_type: | |||
3660 | case DW_AT_visibility: | |||
3661 | break; | |||
3662 | } | |||
3663 | } | |||
3664 | } | |||
3665 | ||||
3666 | if (num_elements == 0) { | |||
3667 | if (upper_bound_valid && upper_bound >= lower_bound) | |||
3668 | num_elements = upper_bound - lower_bound + 1; | |||
3669 | } | |||
3670 | ||||
3671 | element_orders.push_back(num_elements); | |||
3672 | } | |||
3673 | } break; | |||
3674 | } | |||
3675 | } | |||
3676 | } | |||
3677 | ||||
3678 | Type *DWARFASTParserClang::GetTypeForDIE(const DWARFDIE &die) { | |||
3679 | if (die) { | |||
3680 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
3681 | DWARFAttributes attributes; | |||
3682 | const size_t num_attributes = die.GetAttributes(attributes); | |||
3683 | if (num_attributes > 0) { | |||
3684 | DWARFFormValue type_die_form; | |||
3685 | for (size_t i = 0; i < num_attributes; ++i) { | |||
3686 | dw_attr_t attr = attributes.AttributeAtIndex(i); | |||
3687 | DWARFFormValue form_value; | |||
3688 | ||||
3689 | if (attr == DW_AT_type && | |||
3690 | attributes.ExtractFormValueAtIndex(i, form_value)) | |||
3691 | return dwarf->ResolveTypeUID(dwarf->GetDIE(DIERef(form_value)), true); | |||
3692 | } | |||
3693 | } | |||
3694 | } | |||
3695 | ||||
3696 | return nullptr; | |||
3697 | } | |||
3698 | ||||
3699 | clang::Decl *DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) { | |||
3700 | if (!die) | |||
3701 | return nullptr; | |||
3702 | ||||
3703 | switch (die.Tag()) { | |||
3704 | case DW_TAG_variable: | |||
3705 | case DW_TAG_constant: | |||
3706 | case DW_TAG_formal_parameter: | |||
3707 | case DW_TAG_imported_declaration: | |||
3708 | case DW_TAG_imported_module: | |||
3709 | break; | |||
3710 | default: | |||
3711 | return nullptr; | |||
3712 | } | |||
3713 | ||||
3714 | DIEToDeclMap::iterator cache_pos = m_die_to_decl.find(die.GetDIE()); | |||
3715 | if (cache_pos != m_die_to_decl.end()) | |||
3716 | return cache_pos->second; | |||
3717 | ||||
3718 | if (DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification)) { | |||
3719 | clang::Decl *decl = GetClangDeclForDIE(spec_die); | |||
3720 | m_die_to_decl[die.GetDIE()] = decl; | |||
3721 | m_decl_to_die[decl].insert(die.GetDIE()); | |||
3722 | return decl; | |||
3723 | } | |||
3724 | ||||
3725 | if (DWARFDIE abstract_origin_die = | |||
3726 | die.GetReferencedDIE(DW_AT_abstract_origin)) { | |||
3727 | clang::Decl *decl = GetClangDeclForDIE(abstract_origin_die); | |||
3728 | m_die_to_decl[die.GetDIE()] = decl; | |||
3729 | m_decl_to_die[decl].insert(die.GetDIE()); | |||
3730 | return decl; | |||
3731 | } | |||
3732 | ||||
3733 | clang::Decl *decl = nullptr; | |||
3734 | switch (die.Tag()) { | |||
3735 | case DW_TAG_variable: | |||
3736 | case DW_TAG_constant: | |||
3737 | case DW_TAG_formal_parameter: { | |||
3738 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
3739 | Type *type = GetTypeForDIE(die); | |||
3740 | if (dwarf && type) { | |||
3741 | const char *name = die.GetName(); | |||
3742 | clang::DeclContext *decl_context = | |||
3743 | ClangASTContext::DeclContextGetAsDeclContext( | |||
3744 | dwarf->GetDeclContextContainingUID(die.GetID())); | |||
3745 | decl = m_ast.CreateVariableDeclaration( | |||
3746 | decl_context, name, | |||
3747 | ClangUtil::GetQualType(type->GetForwardCompilerType())); | |||
3748 | } | |||
3749 | break; | |||
3750 | } | |||
3751 | case DW_TAG_imported_declaration: { | |||
3752 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
3753 | DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); | |||
3754 | if (imported_uid) { | |||
3755 | CompilerDecl imported_decl = imported_uid.GetDecl(); | |||
3756 | if (imported_decl) { | |||
3757 | clang::DeclContext *decl_context = | |||
3758 | ClangASTContext::DeclContextGetAsDeclContext( | |||
3759 | dwarf->GetDeclContextContainingUID(die.GetID())); | |||
3760 | if (clang::NamedDecl *clang_imported_decl = | |||
3761 | llvm::dyn_cast<clang::NamedDecl>( | |||
3762 | (clang::Decl *)imported_decl.GetOpaqueDecl())) | |||
3763 | decl = | |||
3764 | m_ast.CreateUsingDeclaration(decl_context, clang_imported_decl); | |||
3765 | } | |||
3766 | } | |||
3767 | break; | |||
3768 | } | |||
3769 | case DW_TAG_imported_module: { | |||
3770 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
3771 | DWARFDIE imported_uid = die.GetAttributeValueAsReferenceDIE(DW_AT_import); | |||
3772 | ||||
3773 | if (imported_uid) { | |||
3774 | CompilerDeclContext imported_decl_ctx = imported_uid.GetDeclContext(); | |||
3775 | if (imported_decl_ctx) { | |||
3776 | clang::DeclContext *decl_context = | |||
3777 | ClangASTContext::DeclContextGetAsDeclContext( | |||
3778 | dwarf->GetDeclContextContainingUID(die.GetID())); | |||
3779 | if (clang::NamespaceDecl *ns_decl = | |||
3780 | ClangASTContext::DeclContextGetAsNamespaceDecl( | |||
3781 | imported_decl_ctx)) | |||
3782 | decl = m_ast.CreateUsingDirectiveDeclaration(decl_context, ns_decl); | |||
3783 | } | |||
3784 | } | |||
3785 | break; | |||
3786 | } | |||
3787 | default: | |||
3788 | break; | |||
3789 | } | |||
3790 | ||||
3791 | m_die_to_decl[die.GetDIE()] = decl; | |||
3792 | m_decl_to_die[decl].insert(die.GetDIE()); | |||
3793 | ||||
3794 | return decl; | |||
3795 | } | |||
3796 | ||||
3797 | clang::DeclContext * | |||
3798 | DWARFASTParserClang::GetClangDeclContextForDIE(const DWARFDIE &die) { | |||
3799 | if (die) { | |||
3800 | clang::DeclContext *decl_ctx = GetCachedClangDeclContextForDIE(die); | |||
3801 | if (decl_ctx) | |||
3802 | return decl_ctx; | |||
3803 | ||||
3804 | bool try_parsing_type = true; | |||
3805 | switch (die.Tag()) { | |||
3806 | case DW_TAG_compile_unit: | |||
3807 | decl_ctx = m_ast.GetTranslationUnitDecl(); | |||
3808 | try_parsing_type = false; | |||
3809 | break; | |||
3810 | ||||
3811 | case DW_TAG_namespace: | |||
3812 | decl_ctx = ResolveNamespaceDIE(die); | |||
3813 | try_parsing_type = false; | |||
3814 | break; | |||
3815 | ||||
3816 | case DW_TAG_lexical_block: | |||
3817 | decl_ctx = GetDeclContextForBlock(die); | |||
3818 | try_parsing_type = false; | |||
3819 | break; | |||
3820 | ||||
3821 | default: | |||
3822 | break; | |||
3823 | } | |||
3824 | ||||
3825 | if (decl_ctx == nullptr && try_parsing_type) { | |||
3826 | Type *type = die.GetDWARF()->ResolveType(die); | |||
3827 | if (type) | |||
3828 | decl_ctx = GetCachedClangDeclContextForDIE(die); | |||
3829 | } | |||
3830 | ||||
3831 | if (decl_ctx) { | |||
3832 | LinkDeclContextToDIE(decl_ctx, die); | |||
3833 | return decl_ctx; | |||
3834 | } | |||
3835 | } | |||
3836 | return nullptr; | |||
3837 | } | |||
3838 | ||||
3839 | static bool IsSubroutine(const DWARFDIE &die) { | |||
3840 | switch (die.Tag()) { | |||
3841 | case DW_TAG_subprogram: | |||
3842 | case DW_TAG_inlined_subroutine: | |||
3843 | return true; | |||
3844 | default: | |||
3845 | return false; | |||
3846 | } | |||
3847 | } | |||
3848 | ||||
3849 | static DWARFDIE GetContainingFunctionWithAbstractOrigin(const DWARFDIE &die) { | |||
3850 | for (DWARFDIE candidate = die; candidate; candidate = candidate.GetParent()) { | |||
3851 | if (IsSubroutine(candidate)) { | |||
3852 | if (candidate.GetReferencedDIE(DW_AT_abstract_origin)) { | |||
3853 | return candidate; | |||
3854 | } else { | |||
3855 | return DWARFDIE(); | |||
3856 | } | |||
3857 | } | |||
3858 | } | |||
3859 | assert(0 && "Shouldn't call GetContainingFunctionWithAbstractOrigin on "(static_cast <bool> (0 && "Shouldn't call GetContainingFunctionWithAbstractOrigin on " "something not in a function") ? void (0) : __assert_fail ("0 && \"Shouldn't call GetContainingFunctionWithAbstractOrigin on \" \"something not in a function\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 3860, __extension__ __PRETTY_FUNCTION__)) | |||
3860 | "something not in a function")(static_cast <bool> (0 && "Shouldn't call GetContainingFunctionWithAbstractOrigin on " "something not in a function") ? void (0) : __assert_fail ("0 && \"Shouldn't call GetContainingFunctionWithAbstractOrigin on \" \"something not in a function\"" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 3860, __extension__ __PRETTY_FUNCTION__)); | |||
3861 | return DWARFDIE(); | |||
3862 | } | |||
3863 | ||||
3864 | static DWARFDIE FindAnyChildWithAbstractOrigin(const DWARFDIE &context) { | |||
3865 | for (DWARFDIE candidate = context.GetFirstChild(); candidate.IsValid(); | |||
3866 | candidate = candidate.GetSibling()) { | |||
3867 | if (candidate.GetReferencedDIE(DW_AT_abstract_origin)) { | |||
3868 | return candidate; | |||
3869 | } | |||
3870 | } | |||
3871 | return DWARFDIE(); | |||
3872 | } | |||
3873 | ||||
3874 | static DWARFDIE FindFirstChildWithAbstractOrigin(const DWARFDIE &block, | |||
3875 | const DWARFDIE &function) { | |||
3876 | assert(IsSubroutine(function))(static_cast <bool> (IsSubroutine(function)) ? void (0) : __assert_fail ("IsSubroutine(function)", "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 3876, __extension__ __PRETTY_FUNCTION__)); | |||
3877 | for (DWARFDIE context = block; context != function.GetParent(); | |||
3878 | context = context.GetParent()) { | |||
3879 | assert(!IsSubroutine(context) || context == function)(static_cast <bool> (!IsSubroutine(context) || context == function) ? void (0) : __assert_fail ("!IsSubroutine(context) || context == function" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 3879, __extension__ __PRETTY_FUNCTION__)); | |||
3880 | if (DWARFDIE child = FindAnyChildWithAbstractOrigin(context)) { | |||
3881 | return child; | |||
3882 | } | |||
3883 | } | |||
3884 | return DWARFDIE(); | |||
3885 | } | |||
3886 | ||||
3887 | clang::DeclContext * | |||
3888 | DWARFASTParserClang::GetDeclContextForBlock(const DWARFDIE &die) { | |||
3889 | assert(die.Tag() == DW_TAG_lexical_block)(static_cast <bool> (die.Tag() == DW_TAG_lexical_block) ? void (0) : __assert_fail ("die.Tag() == DW_TAG_lexical_block" , "/build/llvm-toolchain-snapshot-7~svn326551/tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp" , 3889, __extension__ __PRETTY_FUNCTION__)); | |||
3890 | DWARFDIE containing_function_with_abstract_origin = | |||
3891 | GetContainingFunctionWithAbstractOrigin(die); | |||
3892 | if (!containing_function_with_abstract_origin) { | |||
3893 | return (clang::DeclContext *)ResolveBlockDIE(die); | |||
3894 | } | |||
3895 | DWARFDIE child = FindFirstChildWithAbstractOrigin( | |||
3896 | die, containing_function_with_abstract_origin); | |||
3897 | CompilerDeclContext decl_context = | |||
3898 | GetDeclContextContainingUIDFromDWARF(child); | |||
3899 | return (clang::DeclContext *)decl_context.GetOpaqueDeclContext(); | |||
3900 | } | |||
3901 | ||||
3902 | clang::BlockDecl *DWARFASTParserClang::ResolveBlockDIE(const DWARFDIE &die) { | |||
3903 | if (die && die.Tag() == DW_TAG_lexical_block) { | |||
3904 | clang::BlockDecl *decl = | |||
3905 | llvm::cast_or_null<clang::BlockDecl>(m_die_to_decl_ctx[die.GetDIE()]); | |||
3906 | ||||
3907 | if (!decl) { | |||
3908 | DWARFDIE decl_context_die; | |||
3909 | clang::DeclContext *decl_context = | |||
3910 | GetClangDeclContextContainingDIE(die, &decl_context_die); | |||
3911 | decl = m_ast.CreateBlockDeclaration(decl_context); | |||
3912 | ||||
3913 | if (decl) | |||
3914 | LinkDeclContextToDIE((clang::DeclContext *)decl, die); | |||
3915 | } | |||
3916 | ||||
3917 | return decl; | |||
3918 | } | |||
3919 | return nullptr; | |||
3920 | } | |||
3921 | ||||
3922 | clang::NamespaceDecl * | |||
3923 | DWARFASTParserClang::ResolveNamespaceDIE(const DWARFDIE &die) { | |||
3924 | if (die && die.Tag() == DW_TAG_namespace) { | |||
3925 | // See if we already parsed this namespace DIE and associated it with a | |||
3926 | // uniqued namespace declaration | |||
3927 | clang::NamespaceDecl *namespace_decl = | |||
3928 | static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die.GetDIE()]); | |||
3929 | if (namespace_decl) | |||
3930 | return namespace_decl; | |||
3931 | else { | |||
3932 | const char *namespace_name = die.GetName(); | |||
3933 | clang::DeclContext *containing_decl_ctx = | |||
3934 | GetClangDeclContextContainingDIE(die, nullptr); | |||
3935 | namespace_decl = m_ast.GetUniqueNamespaceDeclaration(namespace_name, | |||
3936 | containing_decl_ctx); | |||
3937 | Log *log = | |||
3938 | nullptr; // (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); | |||
3939 | if (log) { | |||
3940 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
3941 | if (namespace_name) { | |||
3942 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
3943 | log, "ASTContext => %p: 0x%8.8" PRIx64"l" "x" | |||
3944 | ": DW_TAG_namespace with DW_AT_name(\"%s\") => " | |||
3945 | "clang::NamespaceDecl *%p (original = %p)", | |||
3946 | static_cast<void *>(m_ast.getASTContext()), die.GetID(), | |||
3947 | namespace_name, static_cast<void *>(namespace_decl), | |||
3948 | static_cast<void *>(namespace_decl->getOriginalNamespace())); | |||
3949 | } else { | |||
3950 | dwarf->GetObjectFile()->GetModule()->LogMessage( | |||
3951 | log, "ASTContext => %p: 0x%8.8" PRIx64"l" "x" | |||
3952 | ": DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p " | |||
3953 | "(original = %p)", | |||
3954 | static_cast<void *>(m_ast.getASTContext()), die.GetID(), | |||
3955 | static_cast<void *>(namespace_decl), | |||
3956 | static_cast<void *>(namespace_decl->getOriginalNamespace())); | |||
3957 | } | |||
3958 | } | |||
3959 | ||||
3960 | if (namespace_decl) | |||
3961 | LinkDeclContextToDIE((clang::DeclContext *)namespace_decl, die); | |||
3962 | return namespace_decl; | |||
3963 | } | |||
3964 | } | |||
3965 | return nullptr; | |||
3966 | } | |||
3967 | ||||
3968 | clang::DeclContext *DWARFASTParserClang::GetClangDeclContextContainingDIE( | |||
3969 | const DWARFDIE &die, DWARFDIE *decl_ctx_die_copy) { | |||
3970 | SymbolFileDWARF *dwarf = die.GetDWARF(); | |||
3971 | ||||
3972 | DWARFDIE decl_ctx_die = dwarf->GetDeclContextDIEContainingDIE(die); | |||
3973 | ||||
3974 | if (decl_ctx_die_copy) | |||
3975 | *decl_ctx_die_copy = decl_ctx_die; | |||
3976 | ||||
3977 | if (decl_ctx_die) { | |||
3978 | clang::DeclContext *clang_decl_ctx = | |||
3979 | GetClangDeclContextForDIE(decl_ctx_die); | |||
3980 | if (clang_decl_ctx) | |||
3981 | return clang_decl_ctx; | |||
3982 | } | |||
3983 | return m_ast.GetTranslationUnitDecl(); | |||
3984 | } | |||
3985 | ||||
3986 | clang::DeclContext * | |||
3987 | DWARFASTParserClang::GetCachedClangDeclContextForDIE(const DWARFDIE &die) { | |||
3988 | if (die) { | |||
3989 | DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find(die.GetDIE()); | |||
3990 | if (pos != m_die_to_decl_ctx.end()) | |||
3991 | return pos->second; | |||
3992 | } | |||
3993 | return nullptr; | |||
3994 | } | |||
3995 | ||||
3996 | void DWARFASTParserClang::LinkDeclContextToDIE(clang::DeclContext *decl_ctx, | |||
3997 | const DWARFDIE &die) { | |||
3998 | m_die_to_decl_ctx[die.GetDIE()] = decl_ctx; | |||
3999 | // There can be many DIEs for a single decl context | |||
4000 | // m_decl_ctx_to_die[decl_ctx].insert(die.GetDIE()); | |||
4001 | m_decl_ctx_to_die.insert(std::make_pair(decl_ctx, die)); | |||
4002 | } | |||
4003 | ||||
4004 | bool DWARFASTParserClang::CopyUniqueClassMethodTypes( | |||
4005 | const DWARFDIE &src_class_die, const DWARFDIE &dst_class_die, | |||
4006 | lldb_private::Type *class_type, DWARFDIECollection &failures) { | |||
4007 | if (!class_type || !src_class_die || !dst_class_die) | |||
4008 | return false; | |||
4009 | if (src_class_die.Tag() != dst_class_die.Tag()) | |||
4010 | return false; | |||
4011 | ||||
4012 | // We need to complete the class type so we can get all of the method types | |||
4013 | // parsed so we can then unique those types to their equivalent counterparts | |||
4014 | // in "dst_cu" and "dst_class_die" | |||
4015 | class_type->GetFullCompilerType(); | |||
4016 | ||||
4017 | DWARFDIE src_die; | |||
4018 | DWARFDIE dst_die; | |||
4019 | UniqueCStringMap<DWARFDIE> src_name_to_die; | |||
4020 | UniqueCStringMap<DWARFDIE> dst_name_to_die; | |||
4021 | UniqueCStringMap<DWARFDIE> src_name_to_die_artificial; | |||
4022 | UniqueCStringMap<DWARFDIE> dst_name_to_die_artificial; | |||
4023 | for (src_die = src_class_die.GetFirstChild(); src_die.IsValid(); | |||
4024 | src_die = src_die.GetSibling()) { | |||
4025 | if (src_die.Tag() == DW_TAG_subprogram) { | |||
4026 | // Make sure this is a declaration and not a concrete instance by looking | |||
4027 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | |||
4028 | // are placed inside the class definitions and shouldn't be included in | |||
4029 | // the list of things are are tracking here. | |||
4030 | if (src_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) { | |||
4031 | const char *src_name = src_die.GetMangledName(); | |||
4032 | if (src_name) { | |||
4033 | ConstString src_const_name(src_name); | |||
4034 | if (src_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) | |||
4035 | src_name_to_die_artificial.Append(src_const_name, src_die); | |||
4036 | else | |||
4037 | src_name_to_die.Append(src_const_name, src_die); | |||
4038 | } | |||
4039 | } | |||
4040 | } | |||
4041 | } | |||
4042 | for (dst_die = dst_class_die.GetFirstChild(); dst_die.IsValid(); | |||
4043 | dst_die = dst_die.GetSibling()) { | |||
4044 | if (dst_die.Tag() == DW_TAG_subprogram) { | |||
4045 | // Make sure this is a declaration and not a concrete instance by looking | |||
4046 | // for DW_AT_declaration set to 1. Sometimes concrete function instances | |||
4047 | // are placed inside the class definitions and shouldn't be included in | |||
4048 | // the list of things are are tracking here. | |||
4049 | if (dst_die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0) == 1) { | |||
4050 | const char *dst_name = dst_die.GetMangledName(); | |||
4051 | if (dst_name) { | |||
4052 | ConstString dst_const_name(dst_name); | |||
4053 | if (dst_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0)) | |||
4054 | dst_name_to_die_artificial.Append(dst_const_name, dst_die); | |||
4055 | else | |||
4056 | dst_name_to_die.Append(dst_const_name, dst_die); | |||
4057 | } | |||
4058 | } | |||
4059 | } | |||
4060 | } | |||
4061 | const uint32_t src_size = src_name_to_die.GetSize(); | |||
4062 | const uint32_t dst_size = dst_name_to_die.GetSize(); | |||
4063 | Log *log = nullptr; // (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO | | |||
4064 | // DWARF_LOG_TYPE_COMPLETION)); | |||
4065 | ||||
4066 | // Is everything kosher so we can go through the members at top speed? | |||
4067 | bool fast_path = true; | |||
4068 | ||||
4069 | if (src_size != dst_size) { | |||
4070 | if (src_size != 0 && dst_size != 0) { | |||
4071 | if (log) | |||
4072 | log->Printf("warning: trying to unique class DIE 0x%8.8x to 0x%8.8x, " | |||
4073 | "but they didn't have the same size (src=%d, dst=%d)", | |||
4074 | src_class_die.GetOffset(), dst_class_die.GetOffset(), | |||
4075 | src_size, dst_size); | |||
4076 | } | |||
4077 | ||||
4078 | fast_path = false; | |||
4079 | } | |||
4080 | ||||
4081 | uint32_t idx; | |||
4082 | ||||
4083 | if (fast_path) { | |||
4084 | for (idx = 0; idx < src_size; ++idx) { | |||
4085 | src_die = src_name_to_die.GetValueAtIndexUnchecked(idx); | |||
4086 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); | |||
4087 | ||||
4088 | if (src_die.Tag() != dst_die.Tag()) { | |||
4089 | if (log) | |||
4090 | log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, " | |||
4091 | "but 0x%8.8x (%s) tags didn't match 0x%8.8x (%s)", | |||
4092 | src_class_die.GetOffset(), dst_class_die.GetOffset(), | |||
4093 | src_die.GetOffset(), src_die.GetTagAsCString(), | |||
4094 | dst_die.GetOffset(), dst_die.GetTagAsCString()); | |||
4095 | fast_path = false; | |||
4096 | } | |||
4097 | ||||
4098 | const char *src_name = src_die.GetMangledName(); | |||
4099 | const char *dst_name = dst_die.GetMangledName(); | |||
4100 | ||||
4101 | // Make sure the names match | |||
4102 | if (src_name == dst_name || (strcmp(src_name, dst_name) == 0)) | |||
4103 | continue; | |||
4104 | ||||
4105 | if (log) | |||
4106 | log->Printf("warning: tried to unique class DIE 0x%8.8x to 0x%8.8x, " | |||
4107 | "but 0x%8.8x (%s) names didn't match 0x%8.8x (%s)", | |||
4108 | src_class_die.GetOffset(), dst_class_die.GetOffset(), | |||
4109 | src_die.GetOffset(), src_name, dst_die.GetOffset(), | |||
4110 | dst_name); | |||
4111 | ||||
4112 | fast_path = false; | |||
4113 | } | |||
4114 | } | |||
4115 | ||||
4116 | DWARFASTParserClang *src_dwarf_ast_parser = | |||
4117 | (DWARFASTParserClang *)src_die.GetDWARFParser(); | |||
4118 | DWARFASTParserClang *dst_dwarf_ast_parser = | |||
4119 | (DWARFASTParserClang *)dst_die.GetDWARFParser(); | |||
4120 | ||||
4121 | // Now do the work of linking the DeclContexts and Types. | |||
4122 | if (fast_path) { | |||
4123 | // We can do this quickly. Just run across the tables index-for-index since | |||
4124 | // we know each node has matching names and tags. | |||
4125 | for (idx = 0; idx < src_size; ++idx) { | |||
4126 | src_die = src_name_to_die.GetValueAtIndexUnchecked(idx); | |||
4127 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); | |||
4128 | ||||
4129 | clang::DeclContext *src_decl_ctx = | |||
4130 | src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; | |||
4131 | if (src_decl_ctx) { | |||
4132 | if (log) | |||
4133 | log->Printf("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | |||
4134 | static_cast<void *>(src_decl_ctx), src_die.GetOffset(), | |||
4135 | dst_die.GetOffset()); | |||
4136 | dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); | |||
4137 | } else { | |||
4138 | if (log) | |||
4139 | log->Printf("warning: tried to unique decl context from 0x%8.8x for " | |||
4140 | "0x%8.8x, but none was found", | |||
4141 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4142 | } | |||
4143 | ||||
4144 | Type *src_child_type = | |||
4145 | dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; | |||
4146 | if (src_child_type) { | |||
4147 | if (log) | |||
4148 | log->Printf( | |||
4149 | "uniquing type %p (uid=0x%" PRIx64"l" "x" ") from 0x%8.8x for 0x%8.8x", | |||
4150 | static_cast<void *>(src_child_type), src_child_type->GetID(), | |||
4151 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4152 | dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; | |||
4153 | } else { | |||
4154 | if (log) | |||
4155 | log->Printf("warning: tried to unique lldb_private::Type from " | |||
4156 | "0x%8.8x for 0x%8.8x, but none was found", | |||
4157 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4158 | } | |||
4159 | } | |||
4160 | } else { | |||
4161 | // We must do this slowly. For each member of the destination, look | |||
4162 | // up a member in the source with the same name, check its tag, and | |||
4163 | // unique them if everything matches up. Report failures. | |||
4164 | ||||
4165 | if (!src_name_to_die.IsEmpty() && !dst_name_to_die.IsEmpty()) { | |||
4166 | src_name_to_die.Sort(); | |||
4167 | ||||
4168 | for (idx = 0; idx < dst_size; ++idx) { | |||
4169 | ConstString dst_name = dst_name_to_die.GetCStringAtIndex(idx); | |||
4170 | dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx); | |||
4171 | src_die = src_name_to_die.Find(dst_name, DWARFDIE()); | |||
4172 | ||||
4173 | if (src_die && (src_die.Tag() == dst_die.Tag())) { | |||
4174 | clang::DeclContext *src_decl_ctx = | |||
4175 | src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; | |||
4176 | if (src_decl_ctx) { | |||
4177 | if (log) | |||
4178 | log->Printf("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | |||
4179 | static_cast<void *>(src_decl_ctx), | |||
4180 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4181 | dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); | |||
4182 | } else { | |||
4183 | if (log) | |||
4184 | log->Printf("warning: tried to unique decl context from 0x%8.8x " | |||
4185 | "for 0x%8.8x, but none was found", | |||
4186 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4187 | } | |||
4188 | ||||
4189 | Type *src_child_type = | |||
4190 | dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; | |||
4191 | if (src_child_type) { | |||
4192 | if (log) | |||
4193 | log->Printf("uniquing type %p (uid=0x%" PRIx64"l" "x" | |||
4194 | ") from 0x%8.8x for 0x%8.8x", | |||
4195 | static_cast<void *>(src_child_type), | |||
4196 | src_child_type->GetID(), src_die.GetOffset(), | |||
4197 | dst_die.GetOffset()); | |||
4198 | dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = | |||
4199 | src_child_type; | |||
4200 | } else { | |||
4201 | if (log) | |||
4202 | log->Printf("warning: tried to unique lldb_private::Type from " | |||
4203 | "0x%8.8x for 0x%8.8x, but none was found", | |||
4204 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4205 | } | |||
4206 | } else { | |||
4207 | if (log) | |||
4208 | log->Printf("warning: couldn't find a match for 0x%8.8x", | |||
4209 | dst_die.GetOffset()); | |||
4210 | ||||
4211 | failures.Append(dst_die); | |||
4212 | } | |||
4213 | } | |||
4214 | } | |||
4215 | } | |||
4216 | ||||
4217 | const uint32_t src_size_artificial = src_name_to_die_artificial.GetSize(); | |||
4218 | const uint32_t dst_size_artificial = dst_name_to_die_artificial.GetSize(); | |||
4219 | ||||
4220 | if (src_size_artificial && dst_size_artificial) { | |||
4221 | dst_name_to_die_artificial.Sort(); | |||
4222 | ||||
4223 | for (idx = 0; idx < src_size_artificial; ++idx) { | |||
4224 | ConstString src_name_artificial = | |||
4225 | src_name_to_die_artificial.GetCStringAtIndex(idx); | |||
4226 | src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked(idx); | |||
4227 | dst_die = | |||
4228 | dst_name_to_die_artificial.Find(src_name_artificial, DWARFDIE()); | |||
4229 | ||||
4230 | if (dst_die) { | |||
4231 | // Both classes have the artificial types, link them | |||
4232 | clang::DeclContext *src_decl_ctx = | |||
4233 | src_dwarf_ast_parser->m_die_to_decl_ctx[src_die.GetDIE()]; | |||
4234 | if (src_decl_ctx) { | |||
4235 | if (log) | |||
4236 | log->Printf("uniquing decl context %p from 0x%8.8x for 0x%8.8x", | |||
4237 | static_cast<void *>(src_decl_ctx), src_die.GetOffset(), | |||
4238 | dst_die.GetOffset()); | |||
4239 | dst_dwarf_ast_parser->LinkDeclContextToDIE(src_decl_ctx, dst_die); | |||
4240 | } else { | |||
4241 | if (log) | |||
4242 | log->Printf("warning: tried to unique decl context from 0x%8.8x " | |||
4243 | "for 0x%8.8x, but none was found", | |||
4244 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4245 | } | |||
4246 | ||||
4247 | Type *src_child_type = | |||
4248 | dst_die.GetDWARF()->GetDIEToType()[src_die.GetDIE()]; | |||
4249 | if (src_child_type) { | |||
4250 | if (log) | |||
4251 | log->Printf( | |||
4252 | "uniquing type %p (uid=0x%" PRIx64"l" "x" ") from 0x%8.8x for 0x%8.8x", | |||
4253 | static_cast<void *>(src_child_type), src_child_type->GetID(), | |||
4254 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4255 | dst_die.GetDWARF()->GetDIEToType()[dst_die.GetDIE()] = src_child_type; | |||
4256 | } else { | |||
4257 | if (log) | |||
4258 | log->Printf("warning: tried to unique lldb_private::Type from " | |||
4259 | "0x%8.8x for 0x%8.8x, but none was found", | |||
4260 | src_die.GetOffset(), dst_die.GetOffset()); | |||
4261 | } | |||
4262 | } | |||
4263 | } | |||
4264 | } | |||
4265 | ||||
4266 | if (dst_size_artificial) { | |||
4267 | for (idx = 0; idx < dst_size_artificial; ++idx) { | |||
4268 | ConstString dst_name_artificial = | |||
4269 | dst_name_to_die_artificial.GetCStringAtIndex(idx); | |||
4270 | dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked(idx); | |||
4271 | if (log) | |||
4272 | log->Printf("warning: need to create artificial method for 0x%8.8x for " | |||
4273 | "method '%s'", | |||
4274 | dst_die.GetOffset(), dst_name_artificial.GetCString()); | |||
4275 | ||||
4276 | failures.Append(dst_die); | |||
4277 | } | |||
4278 | } | |||
4279 | ||||
4280 | return (failures.Size() != 0); | |||
4281 | } |