Bug Summary

File:tools/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
Warning:line 1357, column 21
Value stored to 'class_symfile' is never read

Annotated Source Code

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