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