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