1 //===-- SymbolFileDWARF.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 "SymbolFileDWARF.h"
11 
12 // Other libraries and framework includes
13 #include "clang/AST/ASTConsumer.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/DeclGroup.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/DeclTemplate.h"
19 #include "clang/Basic/Builtins.h"
20 #include "clang/Basic/IdentifierTable.h"
21 #include "clang/Basic/LangOptions.h"
22 #include "clang/Basic/SourceManager.h"
23 #include "clang/Basic/TargetInfo.h"
24 #include "clang/Basic/Specifiers.h"
25 #include "clang/Sema/DeclSpec.h"
26 
27 #include "llvm/Support/Casting.h"
28 
29 #include "lldb/Core/Module.h"
30 #include "lldb/Core/PluginManager.h"
31 #include "lldb/Core/RegularExpression.h"
32 #include "lldb/Core/Scalar.h"
33 #include "lldb/Core/Section.h"
34 #include "lldb/Core/StreamFile.h"
35 #include "lldb/Core/StreamString.h"
36 #include "lldb/Core/Timer.h"
37 #include "lldb/Core/Value.h"
38 
39 #include "lldb/Host/Host.h"
40 
41 #include "lldb/Symbol/Block.h"
42 #include "lldb/Symbol/ClangExternalASTSourceCallbacks.h"
43 #include "lldb/Symbol/CompileUnit.h"
44 #include "lldb/Symbol/LineTable.h"
45 #include "lldb/Symbol/ObjectFile.h"
46 #include "lldb/Symbol/SymbolVendor.h"
47 #include "lldb/Symbol/VariableList.h"
48 
49 #include "lldb/Target/ObjCLanguageRuntime.h"
50 #include "lldb/Target/CPPLanguageRuntime.h"
51 
52 #include "DWARFCompileUnit.h"
53 #include "DWARFDebugAbbrev.h"
54 #include "DWARFDebugAranges.h"
55 #include "DWARFDebugInfo.h"
56 #include "DWARFDebugInfoEntry.h"
57 #include "DWARFDebugLine.h"
58 #include "DWARFDebugPubnames.h"
59 #include "DWARFDebugRanges.h"
60 #include "DWARFDIECollection.h"
61 #include "DWARFFormValue.h"
62 #include "DWARFLocationList.h"
63 #include "LogChannelDWARF.h"
64 #include "SymbolFileDWARFDebugMap.h"
65 
66 #include <map>
67 
68 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
69 
70 #ifdef ENABLE_DEBUG_PRINTF
71 #include <stdio.h>
72 #define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
73 #else
74 #define DEBUG_PRINTF(fmt, ...)
75 #endif
76 
77 #define DIE_IS_BEING_PARSED ((lldb_private::Type*)1)
78 
79 using namespace lldb;
80 using namespace lldb_private;
81 
82 //static inline bool
83 //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
84 //{
85 //    switch (tag)
86 //    {
87 //    default:
88 //        break;
89 //    case DW_TAG_subprogram:
90 //    case DW_TAG_inlined_subroutine:
91 //    case DW_TAG_class_type:
92 //    case DW_TAG_structure_type:
93 //    case DW_TAG_union_type:
94 //        return true;
95 //    }
96 //    return false;
97 //}
98 //
99 static AccessType
100 DW_ACCESS_to_AccessType (uint32_t dwarf_accessibility)
101 {
102     switch (dwarf_accessibility)
103     {
104         case DW_ACCESS_public:      return eAccessPublic;
105         case DW_ACCESS_private:     return eAccessPrivate;
106         case DW_ACCESS_protected:   return eAccessProtected;
107         default:                    break;
108     }
109     return eAccessNone;
110 }
111 
112 #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
113 
114 class DIEStack
115 {
116 public:
117 
118     void Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
119     {
120         m_dies.push_back (DIEInfo(cu, die));
121     }
122 
123 
124     void LogDIEs (Log *log, SymbolFileDWARF *dwarf)
125     {
126         StreamString log_strm;
127         const size_t n = m_dies.size();
128         log_strm.Printf("DIEStack[%zu]:\n", n);
129         for (size_t i=0; i<n; i++)
130         {
131             DWARFCompileUnit *cu = m_dies[i].cu;
132             const DWARFDebugInfoEntry *die = m_dies[i].die;
133             std::string qualified_name;
134             die->GetQualifiedName(dwarf, cu, qualified_name);
135             log_strm.Printf ("[%zu] 0x%8.8x: %s name='%s'\n",
136                              i,
137                              die->GetOffset(),
138                              DW_TAG_value_to_name(die->Tag()),
139                              qualified_name.c_str());
140         }
141         log->PutCString(log_strm.GetData());
142     }
143     void Pop ()
144     {
145         m_dies.pop_back();
146     }
147 
148     class ScopedPopper
149     {
150     public:
151         ScopedPopper (DIEStack &die_stack) :
152             m_die_stack (die_stack),
153             m_valid (false)
154         {
155         }
156 
157         void
158         Push (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
159         {
160             m_valid = true;
161             m_die_stack.Push (cu, die);
162         }
163 
164         ~ScopedPopper ()
165         {
166             if (m_valid)
167                 m_die_stack.Pop();
168         }
169 
170 
171 
172     protected:
173         DIEStack &m_die_stack;
174         bool m_valid;
175     };
176 
177 protected:
178     struct DIEInfo {
179         DIEInfo (DWARFCompileUnit *c, const DWARFDebugInfoEntry *d) :
180             cu(c),
181             die(d)
182         {
183         }
184         DWARFCompileUnit *cu;
185         const DWARFDebugInfoEntry *die;
186     };
187     typedef std::vector<DIEInfo> Stack;
188     Stack m_dies;
189 };
190 #endif
191 
192 void
193 SymbolFileDWARF::Initialize()
194 {
195     LogChannelDWARF::Initialize();
196     PluginManager::RegisterPlugin (GetPluginNameStatic(),
197                                    GetPluginDescriptionStatic(),
198                                    CreateInstance);
199 }
200 
201 void
202 SymbolFileDWARF::Terminate()
203 {
204     PluginManager::UnregisterPlugin (CreateInstance);
205     LogChannelDWARF::Initialize();
206 }
207 
208 
209 const char *
210 SymbolFileDWARF::GetPluginNameStatic()
211 {
212     return "dwarf";
213 }
214 
215 const char *
216 SymbolFileDWARF::GetPluginDescriptionStatic()
217 {
218     return "DWARF and DWARF3 debug symbol file reader.";
219 }
220 
221 
222 SymbolFile*
223 SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
224 {
225     return new SymbolFileDWARF(obj_file);
226 }
227 
228 TypeList *
229 SymbolFileDWARF::GetTypeList ()
230 {
231     if (m_debug_map_symfile)
232         return m_debug_map_symfile->GetTypeList();
233     return m_obj_file->GetModule()->GetTypeList();
234 
235 }
236 
237 //----------------------------------------------------------------------
238 // Gets the first parent that is a lexical block, function or inlined
239 // subroutine, or compile unit.
240 //----------------------------------------------------------------------
241 static const DWARFDebugInfoEntry *
242 GetParentSymbolContextDIE(const DWARFDebugInfoEntry *child_die)
243 {
244     const DWARFDebugInfoEntry *die;
245     for (die = child_die->GetParent(); die != NULL; die = die->GetParent())
246     {
247         dw_tag_t tag = die->Tag();
248 
249         switch (tag)
250         {
251         case DW_TAG_compile_unit:
252         case DW_TAG_subprogram:
253         case DW_TAG_inlined_subroutine:
254         case DW_TAG_lexical_block:
255             return die;
256         }
257     }
258     return NULL;
259 }
260 
261 
262 SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
263     SymbolFile (objfile),
264     UserID (0),  // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
265     m_debug_map_symfile (NULL),
266     m_clang_tu_decl (NULL),
267     m_flags(),
268     m_data_debug_abbrev (),
269     m_data_debug_aranges (),
270     m_data_debug_frame (),
271     m_data_debug_info (),
272     m_data_debug_line (),
273     m_data_debug_loc (),
274     m_data_debug_ranges (),
275     m_data_debug_str (),
276     m_data_apple_names (),
277     m_data_apple_types (),
278     m_data_apple_namespaces (),
279     m_abbr(),
280     m_info(),
281     m_line(),
282     m_apple_names_ap (),
283     m_apple_types_ap (),
284     m_apple_namespaces_ap (),
285     m_apple_objc_ap (),
286     m_function_basename_index(),
287     m_function_fullname_index(),
288     m_function_method_index(),
289     m_function_selector_index(),
290     m_objc_class_selectors_index(),
291     m_global_index(),
292     m_type_index(),
293     m_namespace_index(),
294     m_indexed (false),
295     m_is_external_ast_source (false),
296     m_using_apple_tables (false),
297     m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
298     m_ranges(),
299     m_unique_ast_type_map ()
300 {
301 }
302 
303 SymbolFileDWARF::~SymbolFileDWARF()
304 {
305     if (m_is_external_ast_source)
306     {
307         ModuleSP module_sp (m_obj_file->GetModule());
308         if (module_sp)
309             module_sp->GetClangASTContext().RemoveExternalSource ();
310     }
311 }
312 
313 static const ConstString &
314 GetDWARFMachOSegmentName ()
315 {
316     static ConstString g_dwarf_section_name ("__DWARF");
317     return g_dwarf_section_name;
318 }
319 
320 UniqueDWARFASTTypeMap &
321 SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
322 {
323     if (m_debug_map_symfile)
324         return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
325     return m_unique_ast_type_map;
326 }
327 
328 ClangASTContext &
329 SymbolFileDWARF::GetClangASTContext ()
330 {
331     if (m_debug_map_symfile)
332         return m_debug_map_symfile->GetClangASTContext ();
333 
334     ClangASTContext &ast = m_obj_file->GetModule()->GetClangASTContext();
335     if (!m_is_external_ast_source)
336     {
337         m_is_external_ast_source = true;
338         llvm::OwningPtr<clang::ExternalASTSource> ast_source_ap (
339             new ClangExternalASTSourceCallbacks (SymbolFileDWARF::CompleteTagDecl,
340                                                  SymbolFileDWARF::CompleteObjCInterfaceDecl,
341                                                  SymbolFileDWARF::FindExternalVisibleDeclsByName,
342                                                  SymbolFileDWARF::LayoutRecordType,
343                                                  this));
344         ast.SetExternalSource (ast_source_ap);
345     }
346     return ast;
347 }
348 
349 void
350 SymbolFileDWARF::InitializeObject()
351 {
352     // Install our external AST source callbacks so we can complete Clang types.
353     ModuleSP module_sp (m_obj_file->GetModule());
354     if (module_sp)
355     {
356         const SectionList *section_list = m_obj_file->GetSectionList();
357 
358         const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
359 
360         // Memory map the DWARF mach-o segment so we have everything mmap'ed
361         // to keep our heap memory usage down.
362         if (section)
363             m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
364     }
365     get_apple_names_data();
366     if (m_data_apple_names.GetByteSize() > 0)
367     {
368         m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names, get_debug_str_data(), ".apple_names"));
369         if (m_apple_names_ap->IsValid())
370             m_using_apple_tables = true;
371         else
372             m_apple_names_ap.reset();
373     }
374     get_apple_types_data();
375     if (m_data_apple_types.GetByteSize() > 0)
376     {
377         m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types, get_debug_str_data(), ".apple_types"));
378         if (m_apple_types_ap->IsValid())
379             m_using_apple_tables = true;
380         else
381             m_apple_types_ap.reset();
382     }
383 
384     get_apple_namespaces_data();
385     if (m_data_apple_namespaces.GetByteSize() > 0)
386     {
387         m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces, get_debug_str_data(), ".apple_namespaces"));
388         if (m_apple_namespaces_ap->IsValid())
389             m_using_apple_tables = true;
390         else
391             m_apple_namespaces_ap.reset();
392     }
393 
394     get_apple_objc_data();
395     if (m_data_apple_objc.GetByteSize() > 0)
396     {
397         m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc, get_debug_str_data(), ".apple_objc"));
398         if (m_apple_objc_ap->IsValid())
399             m_using_apple_tables = true;
400         else
401             m_apple_objc_ap.reset();
402     }
403 }
404 
405 bool
406 SymbolFileDWARF::SupportedVersion(uint16_t version)
407 {
408     return version == 2 || version == 3;
409 }
410 
411 uint32_t
412 SymbolFileDWARF::CalculateAbilities ()
413 {
414     uint32_t abilities = 0;
415     if (m_obj_file != NULL)
416     {
417         const Section* section = NULL;
418         const SectionList *section_list = m_obj_file->GetSectionList();
419         if (section_list == NULL)
420             return 0;
421 
422         uint64_t debug_abbrev_file_size = 0;
423         uint64_t debug_aranges_file_size = 0;
424         uint64_t debug_frame_file_size = 0;
425         uint64_t debug_info_file_size = 0;
426         uint64_t debug_line_file_size = 0;
427         uint64_t debug_loc_file_size = 0;
428         uint64_t debug_macinfo_file_size = 0;
429         uint64_t debug_pubnames_file_size = 0;
430         uint64_t debug_pubtypes_file_size = 0;
431         uint64_t debug_ranges_file_size = 0;
432         uint64_t debug_str_file_size = 0;
433 
434         section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
435 
436         if (section)
437             section_list = &section->GetChildren ();
438 
439         section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
440         if (section != NULL)
441         {
442             debug_info_file_size = section->GetFileSize();
443 
444             section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
445             if (section)
446                 debug_abbrev_file_size = section->GetFileSize();
447             else
448                 m_flags.Set (flagsGotDebugAbbrevData);
449 
450             section = section_list->FindSectionByType (eSectionTypeDWARFDebugAranges, true).get();
451             if (section)
452                 debug_aranges_file_size = section->GetFileSize();
453             else
454                 m_flags.Set (flagsGotDebugArangesData);
455 
456             section = section_list->FindSectionByType (eSectionTypeDWARFDebugFrame, true).get();
457             if (section)
458                 debug_frame_file_size = section->GetFileSize();
459             else
460                 m_flags.Set (flagsGotDebugFrameData);
461 
462             section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
463             if (section)
464                 debug_line_file_size = section->GetFileSize();
465             else
466                 m_flags.Set (flagsGotDebugLineData);
467 
468             section = section_list->FindSectionByType (eSectionTypeDWARFDebugLoc, true).get();
469             if (section)
470                 debug_loc_file_size = section->GetFileSize();
471             else
472                 m_flags.Set (flagsGotDebugLocData);
473 
474             section = section_list->FindSectionByType (eSectionTypeDWARFDebugMacInfo, true).get();
475             if (section)
476                 debug_macinfo_file_size = section->GetFileSize();
477             else
478                 m_flags.Set (flagsGotDebugMacInfoData);
479 
480             section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubNames, true).get();
481             if (section)
482                 debug_pubnames_file_size = section->GetFileSize();
483             else
484                 m_flags.Set (flagsGotDebugPubNamesData);
485 
486             section = section_list->FindSectionByType (eSectionTypeDWARFDebugPubTypes, true).get();
487             if (section)
488                 debug_pubtypes_file_size = section->GetFileSize();
489             else
490                 m_flags.Set (flagsGotDebugPubTypesData);
491 
492             section = section_list->FindSectionByType (eSectionTypeDWARFDebugRanges, true).get();
493             if (section)
494                 debug_ranges_file_size = section->GetFileSize();
495             else
496                 m_flags.Set (flagsGotDebugRangesData);
497 
498             section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
499             if (section)
500                 debug_str_file_size = section->GetFileSize();
501             else
502                 m_flags.Set (flagsGotDebugStrData);
503         }
504 
505         if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
506             abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
507 
508         if (debug_line_file_size > 0)
509             abilities |= LineTables;
510 
511         if (debug_aranges_file_size > 0)
512             abilities |= AddressAcceleratorTable;
513 
514         if (debug_pubnames_file_size > 0)
515             abilities |= FunctionAcceleratorTable;
516 
517         if (debug_pubtypes_file_size > 0)
518             abilities |= TypeAcceleratorTable;
519 
520         if (debug_macinfo_file_size > 0)
521             abilities |= MacroInformation;
522 
523         if (debug_frame_file_size > 0)
524             abilities |= CallFrameInformation;
525     }
526     return abilities;
527 }
528 
529 const DataExtractor&
530 SymbolFileDWARF::GetCachedSectionData (uint32_t got_flag, SectionType sect_type, DataExtractor &data)
531 {
532     if (m_flags.IsClear (got_flag))
533     {
534         m_flags.Set (got_flag);
535         const SectionList *section_list = m_obj_file->GetSectionList();
536         if (section_list)
537         {
538             SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
539             if (section_sp)
540             {
541                 // See if we memory mapped the DWARF segment?
542                 if (m_dwarf_data.GetByteSize())
543                 {
544                     data.SetData(m_dwarf_data, section_sp->GetOffset (), section_sp->GetFileSize());
545                 }
546                 else
547                 {
548                     if (m_obj_file->ReadSectionData (section_sp.get(), data) == 0)
549                         data.Clear();
550                 }
551             }
552         }
553     }
554     return data;
555 }
556 
557 const DataExtractor&
558 SymbolFileDWARF::get_debug_abbrev_data()
559 {
560     return GetCachedSectionData (flagsGotDebugAbbrevData, eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
561 }
562 
563 const DataExtractor&
564 SymbolFileDWARF::get_debug_aranges_data()
565 {
566     return GetCachedSectionData (flagsGotDebugArangesData, eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
567 }
568 
569 const DataExtractor&
570 SymbolFileDWARF::get_debug_frame_data()
571 {
572     return GetCachedSectionData (flagsGotDebugFrameData, eSectionTypeDWARFDebugFrame, m_data_debug_frame);
573 }
574 
575 const DataExtractor&
576 SymbolFileDWARF::get_debug_info_data()
577 {
578     return GetCachedSectionData (flagsGotDebugInfoData, eSectionTypeDWARFDebugInfo, m_data_debug_info);
579 }
580 
581 const DataExtractor&
582 SymbolFileDWARF::get_debug_line_data()
583 {
584     return GetCachedSectionData (flagsGotDebugLineData, eSectionTypeDWARFDebugLine, m_data_debug_line);
585 }
586 
587 const DataExtractor&
588 SymbolFileDWARF::get_debug_loc_data()
589 {
590     return GetCachedSectionData (flagsGotDebugLocData, eSectionTypeDWARFDebugLoc, m_data_debug_loc);
591 }
592 
593 const DataExtractor&
594 SymbolFileDWARF::get_debug_ranges_data()
595 {
596     return GetCachedSectionData (flagsGotDebugRangesData, eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
597 }
598 
599 const DataExtractor&
600 SymbolFileDWARF::get_debug_str_data()
601 {
602     return GetCachedSectionData (flagsGotDebugStrData, eSectionTypeDWARFDebugStr, m_data_debug_str);
603 }
604 
605 const DataExtractor&
606 SymbolFileDWARF::get_apple_names_data()
607 {
608     return GetCachedSectionData (flagsGotAppleNamesData, eSectionTypeDWARFAppleNames, m_data_apple_names);
609 }
610 
611 const DataExtractor&
612 SymbolFileDWARF::get_apple_types_data()
613 {
614     return GetCachedSectionData (flagsGotAppleTypesData, eSectionTypeDWARFAppleTypes, m_data_apple_types);
615 }
616 
617 const DataExtractor&
618 SymbolFileDWARF::get_apple_namespaces_data()
619 {
620     return GetCachedSectionData (flagsGotAppleNamespacesData, eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
621 }
622 
623 const DataExtractor&
624 SymbolFileDWARF::get_apple_objc_data()
625 {
626     return GetCachedSectionData (flagsGotAppleObjCData, eSectionTypeDWARFAppleObjC, m_data_apple_objc);
627 }
628 
629 
630 DWARFDebugAbbrev*
631 SymbolFileDWARF::DebugAbbrev()
632 {
633     if (m_abbr.get() == NULL)
634     {
635         const DataExtractor &debug_abbrev_data = get_debug_abbrev_data();
636         if (debug_abbrev_data.GetByteSize() > 0)
637         {
638             m_abbr.reset(new DWARFDebugAbbrev());
639             if (m_abbr.get())
640                 m_abbr->Parse(debug_abbrev_data);
641         }
642     }
643     return m_abbr.get();
644 }
645 
646 const DWARFDebugAbbrev*
647 SymbolFileDWARF::DebugAbbrev() const
648 {
649     return m_abbr.get();
650 }
651 
652 
653 DWARFDebugInfo*
654 SymbolFileDWARF::DebugInfo()
655 {
656     if (m_info.get() == NULL)
657     {
658         Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
659         if (get_debug_info_data().GetByteSize() > 0)
660         {
661             m_info.reset(new DWARFDebugInfo());
662             if (m_info.get())
663             {
664                 m_info->SetDwarfData(this);
665             }
666         }
667     }
668     return m_info.get();
669 }
670 
671 const DWARFDebugInfo*
672 SymbolFileDWARF::DebugInfo() const
673 {
674     return m_info.get();
675 }
676 
677 DWARFCompileUnit*
678 SymbolFileDWARF::GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid)
679 {
680     DWARFDebugInfo* info = DebugInfo();
681     if (info && UserIDMatches(cu_uid))
682         return info->GetCompileUnit((dw_offset_t)cu_uid).get();
683     return NULL;
684 }
685 
686 
687 DWARFDebugRanges*
688 SymbolFileDWARF::DebugRanges()
689 {
690     if (m_ranges.get() == NULL)
691     {
692         Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p", __PRETTY_FUNCTION__, this);
693         if (get_debug_ranges_data().GetByteSize() > 0)
694         {
695             m_ranges.reset(new DWARFDebugRanges());
696             if (m_ranges.get())
697                 m_ranges->Extract(this);
698         }
699     }
700     return m_ranges.get();
701 }
702 
703 const DWARFDebugRanges*
704 SymbolFileDWARF::DebugRanges() const
705 {
706     return m_ranges.get();
707 }
708 
709 lldb::CompUnitSP
710 SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
711 {
712     CompUnitSP cu_sp;
713     if (dwarf_cu)
714     {
715         CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
716         if (comp_unit)
717         {
718             // We already parsed this compile unit, had out a shared pointer to it
719             cu_sp = comp_unit->shared_from_this();
720         }
721         else
722         {
723             ModuleSP module_sp (m_obj_file->GetModule());
724             if (module_sp)
725             {
726                 const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
727                 if (cu_die)
728                 {
729                     const char * cu_die_name = cu_die->GetName(this, dwarf_cu);
730                     const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
731                     LanguageType cu_language = (LanguageType)cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_language, 0);
732                     if (cu_die_name)
733                     {
734                         std::string ramapped_file;
735                         FileSpec cu_file_spec;
736 
737                         if (cu_die_name[0] == '/' || cu_comp_dir == NULL || cu_comp_dir[0] == '\0')
738                         {
739                             // If we have a full path to the compile unit, we don't need to resolve
740                             // the file.  This can be expensive e.g. when the source files are NFS mounted.
741                             if (module_sp->RemapSourceFile(cu_die_name, ramapped_file))
742                                 cu_file_spec.SetFile (ramapped_file.c_str(), false);
743                             else
744                                 cu_file_spec.SetFile (cu_die_name, false);
745                         }
746                         else
747                         {
748                             std::string fullpath(cu_comp_dir);
749                             if (*fullpath.rbegin() != '/')
750                                 fullpath += '/';
751                             fullpath += cu_die_name;
752                             if (module_sp->RemapSourceFile (fullpath.c_str(), ramapped_file))
753                                 cu_file_spec.SetFile (ramapped_file.c_str(), false);
754                             else
755                                 cu_file_spec.SetFile (fullpath.c_str(), false);
756                         }
757 
758                         cu_sp.reset(new CompileUnit (module_sp,
759                                                      dwarf_cu,
760                                                      cu_file_spec,
761                                                      MakeUserID(dwarf_cu->GetOffset()),
762                                                      cu_language));
763                         if (cu_sp)
764                         {
765                             dwarf_cu->SetUserData(cu_sp.get());
766 
767                             if (m_debug_map_symfile)
768                             {
769                                 // Let the symbol file register the compile unit with
770                                 // the symbol vendor using its compile unit index
771                                 // when we are doing DWARF in .o files + debug map
772                                 m_debug_map_symfile->SetCompileUnit(this, cu_sp);
773                             }
774                             else
775                             {
776                                 // Figure out the compile unit index if we weren't given one
777                                 if (cu_idx == UINT32_MAX)
778                                     DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
779 
780                                 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
781                             }
782                         }
783                     }
784                 }
785             }
786         }
787     }
788     return cu_sp;
789 }
790 
791 uint32_t
792 SymbolFileDWARF::GetNumCompileUnits()
793 {
794     DWARFDebugInfo* info = DebugInfo();
795     if (info)
796         return info->GetNumCompileUnits();
797     return 0;
798 }
799 
800 CompUnitSP
801 SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
802 {
803     CompUnitSP cu_sp;
804     DWARFDebugInfo* info = DebugInfo();
805     if (info)
806     {
807         DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
808         if (dwarf_cu)
809             cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
810     }
811     return cu_sp;
812 }
813 
814 static void
815 AddRangesToBlock (Block& block,
816                   DWARFDebugRanges::RangeList& ranges,
817                   addr_t block_base_addr)
818 {
819     const size_t num_ranges = ranges.GetSize();
820     for (size_t i = 0; i<num_ranges; ++i)
821     {
822         const DWARFDebugRanges::Range &range = ranges.GetEntryRef (i);
823         const addr_t range_base = range.GetRangeBase();
824         assert (range_base >= block_base_addr);
825         block.AddRange(Block::Range (range_base - block_base_addr, range.GetByteSize()));;
826     }
827     block.FinalizeRanges ();
828 }
829 
830 
831 Function *
832 SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die)
833 {
834     DWARFDebugRanges::RangeList func_ranges;
835     const char *name = NULL;
836     const char *mangled = NULL;
837     int decl_file = 0;
838     int decl_line = 0;
839     int decl_column = 0;
840     int call_file = 0;
841     int call_line = 0;
842     int call_column = 0;
843     DWARFExpression frame_base;
844 
845     assert (die->Tag() == DW_TAG_subprogram);
846 
847     if (die->Tag() != DW_TAG_subprogram)
848         return NULL;
849 
850     if (die->GetDIENamesAndRanges (this,
851                                    dwarf_cu,
852                                    name,
853                                    mangled,
854                                    func_ranges,
855                                    decl_file,
856                                    decl_line,
857                                    decl_column,
858                                    call_file,
859                                    call_line,
860                                    call_column,
861                                    &frame_base))
862     {
863         // Union of all ranges in the function DIE (if the function is discontiguous)
864         AddressRange func_range;
865         lldb::addr_t lowest_func_addr = func_ranges.GetMinRangeBase (0);
866         lldb::addr_t highest_func_addr = func_ranges.GetMaxRangeEnd (0);
867         if (lowest_func_addr != LLDB_INVALID_ADDRESS && lowest_func_addr <= highest_func_addr)
868         {
869             func_range.GetBaseAddress().ResolveAddressUsingFileSections (lowest_func_addr, m_obj_file->GetSectionList());
870             if (func_range.GetBaseAddress().IsValid())
871                 func_range.SetByteSize(highest_func_addr - lowest_func_addr);
872         }
873 
874         if (func_range.GetBaseAddress().IsValid())
875         {
876             Mangled func_name;
877             if (mangled)
878                 func_name.SetValue(mangled, true);
879             else if (name)
880                 func_name.SetValue(name, false);
881 
882             FunctionSP func_sp;
883             std::auto_ptr<Declaration> decl_ap;
884             if (decl_file != 0 || decl_line != 0 || decl_column != 0)
885                 decl_ap.reset(new Declaration (sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
886                                                decl_line,
887                                                decl_column));
888 
889             // Supply the type _only_ if it has already been parsed
890             Type *func_type = m_die_to_type.lookup (die);
891 
892             assert(func_type == NULL || func_type != DIE_IS_BEING_PARSED);
893 
894             func_range.GetBaseAddress().ResolveLinkedAddress();
895 
896             const user_id_t func_user_id = MakeUserID(die->GetOffset());
897             func_sp.reset(new Function (sc.comp_unit,
898                                         func_user_id,       // UserID is the DIE offset
899                                         func_user_id,
900                                         func_name,
901                                         func_type,
902                                         func_range));           // first address range
903 
904             if (func_sp.get() != NULL)
905             {
906                 if (frame_base.IsValid())
907                     func_sp->GetFrameBaseExpression() = frame_base;
908                 sc.comp_unit->AddFunction(func_sp);
909                 return func_sp.get();
910             }
911         }
912     }
913     return NULL;
914 }
915 
916 size_t
917 SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
918 {
919     assert (sc.comp_unit);
920     size_t functions_added = 0;
921     DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
922     if (dwarf_cu)
923     {
924         DWARFDIECollection function_dies;
925         const size_t num_funtions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
926         size_t func_idx;
927         for (func_idx = 0; func_idx < num_funtions; ++func_idx)
928         {
929             const DWARFDebugInfoEntry *die = function_dies.GetDIEPtrAtIndex(func_idx);
930             if (sc.comp_unit->FindFunctionByUID (MakeUserID(die->GetOffset())).get() == NULL)
931             {
932                 if (ParseCompileUnitFunction(sc, dwarf_cu, die))
933                     ++functions_added;
934             }
935         }
936         //FixupTypes();
937     }
938     return functions_added;
939 }
940 
941 bool
942 SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
943 {
944     assert (sc.comp_unit);
945     DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
946     assert (dwarf_cu);
947     const DWARFDebugInfoEntry * cu_die = dwarf_cu->GetCompileUnitDIEOnly();
948 
949     if (cu_die)
950     {
951         const char * cu_comp_dir = cu_die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_comp_dir, NULL);
952         dw_offset_t stmt_list = cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
953 
954         // All file indexes in DWARF are one based and a file of index zero is
955         // supposed to be the compile unit itself.
956         support_files.Append (*sc.comp_unit);
957 
958         return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir, stmt_list, support_files);
959     }
960     return false;
961 }
962 
963 struct ParseDWARFLineTableCallbackInfo
964 {
965     LineTable* line_table;
966     const SectionList *section_list;
967     lldb::addr_t prev_sect_file_base_addr;
968     lldb::addr_t curr_sect_file_base_addr;
969     bool is_oso_for_debug_map;
970     bool prev_in_final_executable;
971     DWARFDebugLine::Row prev_row;
972     SectionSP prev_section_sp;
973     SectionSP curr_section_sp;
974 };
975 
976 //----------------------------------------------------------------------
977 // ParseStatementTableCallback
978 //----------------------------------------------------------------------
979 static void
980 ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
981 {
982     LineTable* line_table = ((ParseDWARFLineTableCallbackInfo*)userData)->line_table;
983     if (state.row == DWARFDebugLine::State::StartParsingLineTable)
984     {
985         // Just started parsing the line table
986     }
987     else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
988     {
989         // Done parsing line table, nothing to do for the cleanup
990     }
991     else
992     {
993         ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
994         // We have a new row, lets append it
995 
996         if (info->curr_section_sp.get() == NULL || info->curr_section_sp->ContainsFileAddress(state.address) == false)
997         {
998             info->prev_section_sp = info->curr_section_sp;
999             info->prev_sect_file_base_addr = info->curr_sect_file_base_addr;
1000             // If this is an end sequence entry, then we subtract one from the
1001             // address to make sure we get an address that is not the end of
1002             // a section.
1003             if (state.end_sequence && state.address != 0)
1004                 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address - 1);
1005             else
1006                 info->curr_section_sp = info->section_list->FindSectionContainingFileAddress (state.address);
1007 
1008             if (info->curr_section_sp.get())
1009                 info->curr_sect_file_base_addr = info->curr_section_sp->GetFileAddress ();
1010             else
1011                 info->curr_sect_file_base_addr = 0;
1012         }
1013         if (info->curr_section_sp.get())
1014         {
1015             lldb::addr_t curr_line_section_offset = state.address - info->curr_sect_file_base_addr;
1016             // Check for the fancy section magic to determine if we
1017 
1018             if (info->is_oso_for_debug_map)
1019             {
1020                 // When this is a debug map object file that contains DWARF
1021                 // (referenced from an N_OSO debug map nlist entry) we will have
1022                 // a file address in the file range for our section from the
1023                 // original .o file, and a load address in the executable that
1024                 // contains the debug map.
1025                 //
1026                 // If the sections for the file range and load range are
1027                 // different, we have a remapped section for the function and
1028                 // this address is resolved. If they are the same, then the
1029                 // function for this address didn't make it into the final
1030                 // executable.
1031                 bool curr_in_final_executable = info->curr_section_sp->GetLinkedSection () != NULL;
1032 
1033                 // If we are doing DWARF with debug map, then we need to carefully
1034                 // add each line table entry as there may be gaps as functions
1035                 // get moved around or removed.
1036                 if (!info->prev_row.end_sequence && info->prev_section_sp.get())
1037                 {
1038                     if (info->prev_in_final_executable)
1039                     {
1040                         bool terminate_previous_entry = false;
1041                         if (!curr_in_final_executable)
1042                         {
1043                             // Check for the case where the previous line entry
1044                             // in a function made it into the final executable,
1045                             // yet the current line entry falls in a function
1046                             // that didn't. The line table used to be contiguous
1047                             // through this address range but now it isn't. We
1048                             // need to terminate the previous line entry so
1049                             // that we can reconstruct the line range correctly
1050                             // for it and to keep the line table correct.
1051                             terminate_previous_entry = true;
1052                         }
1053                         else if (info->curr_section_sp.get() != info->prev_section_sp.get())
1054                         {
1055                             // Check for cases where the line entries used to be
1056                             // contiguous address ranges, but now they aren't.
1057                             // This can happen when order files specify the
1058                             // ordering of the functions.
1059                             lldb::addr_t prev_line_section_offset = info->prev_row.address - info->prev_sect_file_base_addr;
1060                             Section *curr_sect = info->curr_section_sp.get();
1061                             Section *prev_sect = info->prev_section_sp.get();
1062                             assert (curr_sect->GetLinkedSection());
1063                             assert (prev_sect->GetLinkedSection());
1064                             lldb::addr_t object_file_addr_delta = state.address - info->prev_row.address;
1065                             lldb::addr_t curr_linked_file_addr = curr_sect->GetLinkedFileAddress() + curr_line_section_offset;
1066                             lldb::addr_t prev_linked_file_addr = prev_sect->GetLinkedFileAddress() + prev_line_section_offset;
1067                             lldb::addr_t linked_file_addr_delta = curr_linked_file_addr - prev_linked_file_addr;
1068                             if (object_file_addr_delta != linked_file_addr_delta)
1069                                 terminate_previous_entry = true;
1070                         }
1071 
1072                         if (terminate_previous_entry)
1073                         {
1074                             line_table->InsertLineEntry (info->prev_section_sp,
1075                                                          state.address - info->prev_sect_file_base_addr,
1076                                                          info->prev_row.line,
1077                                                          info->prev_row.column,
1078                                                          info->prev_row.file,
1079                                                          false,                 // is_stmt
1080                                                          false,                 // basic_block
1081                                                          false,                 // state.prologue_end
1082                                                          false,                 // state.epilogue_begin
1083                                                          true);                 // end_sequence);
1084                         }
1085                     }
1086                 }
1087 
1088                 if (curr_in_final_executable)
1089                 {
1090                     line_table->InsertLineEntry (info->curr_section_sp,
1091                                                  curr_line_section_offset,
1092                                                  state.line,
1093                                                  state.column,
1094                                                  state.file,
1095                                                  state.is_stmt,
1096                                                  state.basic_block,
1097                                                  state.prologue_end,
1098                                                  state.epilogue_begin,
1099                                                  state.end_sequence);
1100                     info->prev_section_sp = info->curr_section_sp;
1101                 }
1102                 else
1103                 {
1104                     // If the current address didn't make it into the final
1105                     // executable, the current section will be the __text
1106                     // segment in the .o file, so we need to clear this so
1107                     // we can catch the next function that did make it into
1108                     // the final executable.
1109                     info->prev_section_sp.reset();
1110                     info->curr_section_sp.reset();
1111                 }
1112 
1113                 info->prev_in_final_executable = curr_in_final_executable;
1114             }
1115             else
1116             {
1117                 // We are not in an object file that contains DWARF for an
1118                 // N_OSO, this is just a normal DWARF file. The DWARF spec
1119                 // guarantees that the addresses will be in increasing order
1120                 // so, since we store line tables in file address order, we
1121                 // can always just append the line entry without needing to
1122                 // search for the correct insertion point (we don't need to
1123                 // use LineEntry::InsertLineEntry()).
1124                 line_table->AppendLineEntry (info->curr_section_sp,
1125                                              curr_line_section_offset,
1126                                              state.line,
1127                                              state.column,
1128                                              state.file,
1129                                              state.is_stmt,
1130                                              state.basic_block,
1131                                              state.prologue_end,
1132                                              state.epilogue_begin,
1133                                              state.end_sequence);
1134             }
1135         }
1136 
1137         info->prev_row = state;
1138     }
1139 }
1140 
1141 bool
1142 SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1143 {
1144     assert (sc.comp_unit);
1145     if (sc.comp_unit->GetLineTable() != NULL)
1146         return true;
1147 
1148     DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
1149     if (dwarf_cu)
1150     {
1151         const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1152         if (dwarf_cu_die)
1153         {
1154             const dw_offset_t cu_line_offset = dwarf_cu_die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_stmt_list, DW_INVALID_OFFSET);
1155             if (cu_line_offset != DW_INVALID_OFFSET)
1156             {
1157                 std::auto_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1158                 if (line_table_ap.get())
1159                 {
1160                     ParseDWARFLineTableCallbackInfo info = {
1161                         line_table_ap.get(),
1162                         m_obj_file->GetSectionList(),
1163                         0,
1164                         0,
1165                         m_debug_map_symfile != NULL,
1166                         false,
1167                         DWARFDebugLine::Row(),
1168                         SectionSP(),
1169                         SectionSP()
1170                     };
1171                     uint32_t offset = cu_line_offset;
1172                     DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1173                     sc.comp_unit->SetLineTable(line_table_ap.release());
1174                     return true;
1175                 }
1176             }
1177         }
1178     }
1179     return false;
1180 }
1181 
1182 size_t
1183 SymbolFileDWARF::ParseFunctionBlocks
1184 (
1185     const SymbolContext& sc,
1186     Block *parent_block,
1187     DWARFCompileUnit* dwarf_cu,
1188     const DWARFDebugInfoEntry *die,
1189     addr_t subprogram_low_pc,
1190     uint32_t depth
1191 )
1192 {
1193     size_t blocks_added = 0;
1194     while (die != NULL)
1195     {
1196         dw_tag_t tag = die->Tag();
1197 
1198         switch (tag)
1199         {
1200         case DW_TAG_inlined_subroutine:
1201         case DW_TAG_subprogram:
1202         case DW_TAG_lexical_block:
1203             {
1204                 Block *block = NULL;
1205                 if (tag == DW_TAG_subprogram)
1206                 {
1207                     // Skip any DW_TAG_subprogram DIEs that are inside
1208                     // of a normal or inlined functions. These will be
1209                     // parsed on their own as separate entities.
1210 
1211                     if (depth > 0)
1212                         break;
1213 
1214                     block = parent_block;
1215                 }
1216                 else
1217                 {
1218                     BlockSP block_sp(new Block (MakeUserID(die->GetOffset())));
1219                     parent_block->AddChild(block_sp);
1220                     block = block_sp.get();
1221                 }
1222                 DWARFDebugRanges::RangeList ranges;
1223                 const char *name = NULL;
1224                 const char *mangled_name = NULL;
1225 
1226                 int decl_file = 0;
1227                 int decl_line = 0;
1228                 int decl_column = 0;
1229                 int call_file = 0;
1230                 int call_line = 0;
1231                 int call_column = 0;
1232                 if (die->GetDIENamesAndRanges (this,
1233                                                dwarf_cu,
1234                                                name,
1235                                                mangled_name,
1236                                                ranges,
1237                                                decl_file, decl_line, decl_column,
1238                                                call_file, call_line, call_column))
1239                 {
1240                     if (tag == DW_TAG_subprogram)
1241                     {
1242                         assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1243                         subprogram_low_pc = ranges.GetMinRangeBase(0);
1244                     }
1245                     else if (tag == DW_TAG_inlined_subroutine)
1246                     {
1247                         // We get called here for inlined subroutines in two ways.
1248                         // The first time is when we are making the Function object
1249                         // for this inlined concrete instance.  Since we're creating a top level block at
1250                         // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS.  So we need to
1251                         // adjust the containing address.
1252                         // The second time is when we are parsing the blocks inside the function that contains
1253                         // the inlined concrete instance.  Since these will be blocks inside the containing "real"
1254                         // function the offset will be for that function.
1255                         if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1256                         {
1257                             subprogram_low_pc = ranges.GetMinRangeBase(0);
1258                         }
1259                     }
1260 
1261                     AddRangesToBlock (*block, ranges, subprogram_low_pc);
1262 
1263                     if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1264                     {
1265                         std::auto_ptr<Declaration> decl_ap;
1266                         if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1267                             decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1268                                                           decl_line, decl_column));
1269 
1270                         std::auto_ptr<Declaration> call_ap;
1271                         if (call_file != 0 || call_line != 0 || call_column != 0)
1272                             call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1273                                                           call_line, call_column));
1274 
1275                         block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
1276                     }
1277 
1278                     ++blocks_added;
1279 
1280                     if (die->HasChildren())
1281                     {
1282                         blocks_added += ParseFunctionBlocks (sc,
1283                                                              block,
1284                                                              dwarf_cu,
1285                                                              die->GetFirstChild(),
1286                                                              subprogram_low_pc,
1287                                                              depth + 1);
1288                     }
1289                 }
1290             }
1291             break;
1292         default:
1293             break;
1294         }
1295 
1296         // Only parse siblings of the block if we are not at depth zero. A depth
1297         // of zero indicates we are currently parsing the top level
1298         // DW_TAG_subprogram DIE
1299 
1300         if (depth == 0)
1301             die = NULL;
1302         else
1303             die = die->GetSibling();
1304     }
1305     return blocks_added;
1306 }
1307 
1308 bool
1309 SymbolFileDWARF::ParseTemplateDIE (DWARFCompileUnit* dwarf_cu,
1310                                    const DWARFDebugInfoEntry *die,
1311                                    ClangASTContext::TemplateParameterInfos &template_param_infos)
1312 {
1313     const dw_tag_t tag = die->Tag();
1314 
1315     switch (tag)
1316     {
1317     case DW_TAG_template_type_parameter:
1318     case DW_TAG_template_value_parameter:
1319         {
1320             const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1321 
1322             DWARFDebugInfoEntry::Attributes attributes;
1323             const size_t num_attributes = die->GetAttributes (this,
1324                                                               dwarf_cu,
1325                                                               fixed_form_sizes,
1326                                                               attributes);
1327             const char *name = NULL;
1328             Type *lldb_type = NULL;
1329             clang_type_t clang_type = NULL;
1330             uint64_t uval64 = 0;
1331             bool uval64_valid = false;
1332             if (num_attributes > 0)
1333             {
1334                 DWARFFormValue form_value;
1335                 for (size_t i=0; i<num_attributes; ++i)
1336                 {
1337                     const dw_attr_t attr = attributes.AttributeAtIndex(i);
1338 
1339                     switch (attr)
1340                     {
1341                         case DW_AT_name:
1342                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1343                                 name = form_value.AsCString(&get_debug_str_data());
1344                             break;
1345 
1346                         case DW_AT_type:
1347                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1348                             {
1349                                 const dw_offset_t type_die_offset = form_value.Reference(dwarf_cu);
1350                                 lldb_type = ResolveTypeUID(type_die_offset);
1351                                 if (lldb_type)
1352                                     clang_type = lldb_type->GetClangForwardType();
1353                             }
1354                             break;
1355 
1356                         case DW_AT_const_value:
1357                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1358                             {
1359                                 uval64_valid = true;
1360                                 uval64 = form_value.Unsigned();
1361                             }
1362                             break;
1363                         default:
1364                             break;
1365                     }
1366                 }
1367 
1368                 if (name && lldb_type && clang_type)
1369                 {
1370                     bool is_signed = false;
1371                     template_param_infos.names.push_back(name);
1372                     clang::QualType clang_qual_type (clang::QualType::getFromOpaquePtr (clang_type));
1373                     if (tag == DW_TAG_template_value_parameter && ClangASTContext::IsIntegerType (clang_type, is_signed) && uval64_valid)
1374                     {
1375                         llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed);
1376                         template_param_infos.args.push_back (clang::TemplateArgument (llvm::APSInt(apint), clang_qual_type));
1377                     }
1378                     else
1379                     {
1380                         template_param_infos.args.push_back (clang::TemplateArgument (clang_qual_type));
1381                     }
1382                 }
1383                 else
1384                 {
1385                     return false;
1386                 }
1387 
1388             }
1389         }
1390         return true;
1391 
1392     default:
1393         break;
1394     }
1395     return false;
1396 }
1397 
1398 bool
1399 SymbolFileDWARF::ParseTemplateParameterInfos (DWARFCompileUnit* dwarf_cu,
1400                                               const DWARFDebugInfoEntry *parent_die,
1401                                               ClangASTContext::TemplateParameterInfos &template_param_infos)
1402 {
1403 
1404     if (parent_die == NULL)
1405         return NULL;
1406 
1407     Args template_parameter_names;
1408     for (const DWARFDebugInfoEntry *die = parent_die->GetFirstChild();
1409          die != NULL;
1410          die = die->GetSibling())
1411     {
1412         const dw_tag_t tag = die->Tag();
1413 
1414         switch (tag)
1415         {
1416             case DW_TAG_template_type_parameter:
1417             case DW_TAG_template_value_parameter:
1418                 ParseTemplateDIE (dwarf_cu, die, template_param_infos);
1419             break;
1420 
1421         default:
1422             break;
1423         }
1424     }
1425     if (template_param_infos.args.empty())
1426         return false;
1427     return template_param_infos.args.size() == template_param_infos.names.size();
1428 }
1429 
1430 clang::ClassTemplateDecl *
1431 SymbolFileDWARF::ParseClassTemplateDecl (clang::DeclContext *decl_ctx,
1432                                          lldb::AccessType access_type,
1433                                          const char *parent_name,
1434                                          int tag_decl_kind,
1435                                          const ClangASTContext::TemplateParameterInfos &template_param_infos)
1436 {
1437     if (template_param_infos.IsValid())
1438     {
1439         std::string template_basename(parent_name);
1440         template_basename.erase (template_basename.find('<'));
1441         ClangASTContext &ast = GetClangASTContext();
1442 
1443         return ast.CreateClassTemplateDecl (decl_ctx,
1444                                             access_type,
1445                                             template_basename.c_str(),
1446                                             tag_decl_kind,
1447                                             template_param_infos);
1448     }
1449     return NULL;
1450 }
1451 
1452 size_t
1453 SymbolFileDWARF::ParseChildMembers
1454 (
1455     const SymbolContext& sc,
1456     DWARFCompileUnit* dwarf_cu,
1457     const DWARFDebugInfoEntry *parent_die,
1458     clang_type_t class_clang_type,
1459     const LanguageType class_language,
1460     std::vector<clang::CXXBaseSpecifier *>& base_classes,
1461     std::vector<int>& member_accessibilities,
1462     DWARFDIECollection& member_function_dies,
1463     AccessType& default_accessibility,
1464     bool &is_a_class,
1465     LayoutInfo &layout_info
1466 )
1467 {
1468     if (parent_die == NULL)
1469         return 0;
1470 
1471     size_t count = 0;
1472     const DWARFDebugInfoEntry *die;
1473     const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
1474     uint32_t member_idx = 0;
1475 
1476     for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
1477     {
1478         dw_tag_t tag = die->Tag();
1479 
1480         switch (tag)
1481         {
1482         case DW_TAG_member:
1483         case DW_TAG_APPLE_Property:
1484             {
1485                 DWARFDebugInfoEntry::Attributes attributes;
1486                 const size_t num_attributes = die->GetAttributes (this,
1487                                                                   dwarf_cu,
1488                                                                   fixed_form_sizes,
1489                                                                   attributes);
1490                 if (num_attributes > 0)
1491                 {
1492                     Declaration decl;
1493                     //DWARFExpression location;
1494                     const char *name = NULL;
1495                     const char *prop_name = NULL;
1496                     const char *prop_getter_name = NULL;
1497                     const char *prop_setter_name = NULL;
1498                     uint32_t        prop_attributes = 0;
1499 
1500 
1501                     bool is_artificial = false;
1502                     lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
1503                     AccessType accessibility = eAccessNone;
1504                     uint32_t member_byte_offset = UINT32_MAX;
1505                     size_t byte_size = 0;
1506                     size_t bit_offset = 0;
1507                     size_t bit_size = 0;
1508                     uint32_t i;
1509                     for (i=0; i<num_attributes && !is_artificial; ++i)
1510                     {
1511                         const dw_attr_t attr = attributes.AttributeAtIndex(i);
1512                         DWARFFormValue form_value;
1513                         if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1514                         {
1515                             switch (attr)
1516                             {
1517                             case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1518                             case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
1519                             case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1520                             case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break;
1521                             case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break;
1522                             case DW_AT_bit_offset:  bit_offset = form_value.Unsigned(); break;
1523                             case DW_AT_bit_size:    bit_size = form_value.Unsigned(); break;
1524                             case DW_AT_byte_size:   byte_size = form_value.Unsigned(); break;
1525                             case DW_AT_data_member_location:
1526                                 if (form_value.BlockData())
1527                                 {
1528                                     Value initialValue(0);
1529                                     Value memberOffset(0);
1530                                     const DataExtractor& debug_info_data = get_debug_info_data();
1531                                     uint32_t block_length = form_value.Unsigned();
1532                                     uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1533                                     if (DWARFExpression::Evaluate(NULL, // ExecutionContext *
1534                                                                   NULL, // clang::ASTContext *
1535                                                                   NULL, // ClangExpressionVariableList *
1536                                                                   NULL, // ClangExpressionDeclMap *
1537                                                                   NULL, // RegisterContext *
1538                                                                   debug_info_data,
1539                                                                   block_offset,
1540                                                                   block_length,
1541                                                                   eRegisterKindDWARF,
1542                                                                   &initialValue,
1543                                                                   memberOffset,
1544                                                                   NULL))
1545                                     {
1546                                         member_byte_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1547                                     }
1548                                 }
1549                                 break;
1550 
1551                             case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType (form_value.Unsigned()); break;
1552                             case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break;
1553                             case DW_AT_APPLE_property_name:      prop_name = form_value.AsCString(&get_debug_str_data()); break;
1554                             case DW_AT_APPLE_property_getter:    prop_getter_name = form_value.AsCString(&get_debug_str_data()); break;
1555                             case DW_AT_APPLE_property_setter:    prop_setter_name = form_value.AsCString(&get_debug_str_data()); break;
1556                             case DW_AT_APPLE_property_attribute: prop_attributes = form_value.Unsigned(); break;
1557 
1558                             default:
1559                             case DW_AT_declaration:
1560                             case DW_AT_description:
1561                             case DW_AT_mutable:
1562                             case DW_AT_visibility:
1563                             case DW_AT_sibling:
1564                                 break;
1565                             }
1566                         }
1567                     }
1568 
1569                     if (prop_name)
1570                     {
1571                         ConstString fixed_getter;
1572                         ConstString fixed_setter;
1573 
1574                         // Check if the property getter/setter were provided as full
1575                         // names.  We want basenames, so we extract them.
1576 
1577                         if (prop_getter_name && prop_getter_name[0] == '-')
1578                         {
1579                             ObjCLanguageRuntime::ParseMethodName (prop_getter_name,
1580                                                                   NULL,
1581                                                                   &fixed_getter,
1582                                                                   NULL,
1583                                                                   NULL);
1584                             prop_getter_name = fixed_getter.GetCString();
1585                         }
1586 
1587                         if (prop_setter_name && prop_setter_name[0] == '-')
1588                         {
1589                             ObjCLanguageRuntime::ParseMethodName (prop_setter_name,
1590                                                                   NULL,
1591                                                                   &fixed_setter,
1592                                                                   NULL,
1593                                                                   NULL);
1594                             prop_setter_name = fixed_setter.GetCString();
1595                         }
1596 
1597                         // If the names haven't been provided, they need to be
1598                         // filled in.
1599 
1600                         if (!prop_getter_name)
1601                         {
1602                             prop_getter_name = prop_name;
1603                         }
1604                         if (!prop_setter_name && prop_name[0] && !(prop_attributes & DW_APPLE_PROPERTY_readonly))
1605                         {
1606                             StreamString ss;
1607 
1608                             ss.Printf("set%c%s:",
1609                                       toupper(prop_name[0]),
1610                                       &prop_name[1]);
1611 
1612                             fixed_setter.SetCString(ss.GetData());
1613                             prop_setter_name = fixed_setter.GetCString();
1614                         }
1615                     }
1616 
1617                     // Clang has a DWARF generation bug where sometimes it
1618                     // represents fields that are references with bad byte size
1619                     // and bit size/offset information such as:
1620                     //
1621                     //  DW_AT_byte_size( 0x00 )
1622                     //  DW_AT_bit_size( 0x40 )
1623                     //  DW_AT_bit_offset( 0xffffffffffffffc0 )
1624                     //
1625                     // So check the bit offset to make sure it is sane, and if
1626                     // the values are not sane, remove them. If we don't do this
1627                     // then we will end up with a crash if we try to use this
1628                     // type in an expression when clang becomes unhappy with its
1629                     // recycled debug info.
1630 
1631                     if (bit_offset > 128)
1632                     {
1633                         bit_size = 0;
1634                         bit_offset = 0;
1635                     }
1636 
1637                     // FIXME: Make Clang ignore Objective-C accessibility for expressions
1638                     if (class_language == eLanguageTypeObjC ||
1639                         class_language == eLanguageTypeObjC_plus_plus)
1640                         accessibility = eAccessNone;
1641 
1642                     if (member_idx == 0 && !is_artificial && name && (strstr (name, "_vptr$") == name))
1643                     {
1644                         // Not all compilers will mark the vtable pointer
1645                         // member as artificial (llvm-gcc). We can't have
1646                         // the virtual members in our classes otherwise it
1647                         // throws off all child offsets since we end up
1648                         // having and extra pointer sized member in our
1649                         // class layouts.
1650                         is_artificial = true;
1651                     }
1652 
1653                     if (is_artificial == false)
1654                     {
1655                         Type *member_type = ResolveTypeUID(encoding_uid);
1656                         clang::FieldDecl *field_decl = NULL;
1657                         if (tag == DW_TAG_member)
1658                         {
1659                             if (member_type)
1660                             {
1661                                 if (accessibility == eAccessNone)
1662                                     accessibility = default_accessibility;
1663                                 member_accessibilities.push_back(accessibility);
1664 
1665                                 field_decl = GetClangASTContext().AddFieldToRecordType (class_clang_type,
1666                                                                                         name,
1667                                                                                         member_type->GetClangLayoutType(),
1668                                                                                         accessibility,
1669                                                                                         bit_size);
1670                             }
1671                             else
1672                             {
1673                                 if (name)
1674                                     GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member '%s' refers to type 0x%8.8llx which was unable to be parsed",
1675                                                                                MakeUserID(die->GetOffset()),
1676                                                                                name,
1677                                                                                encoding_uid);
1678                                 else
1679                                     GetObjectFile()->GetModule()->ReportError ("0x%8.8llx: DW_TAG_member refers to type 0x%8.8llx which was unable to be parsed",
1680                                                                                MakeUserID(die->GetOffset()),
1681                                                                                encoding_uid);
1682                             }
1683 
1684                             if (member_byte_offset != UINT32_MAX || bit_size != 0)
1685                             {
1686                                 /////////////////////////////////////////////////////////////
1687                                 // How to locate a field given the DWARF debug information
1688                                 //
1689                                 // AT_byte_size indicates the size of the word in which the
1690                                 // bit offset must be interpreted.
1691                                 //
1692                                 // AT_data_member_location indicates the byte offset of the
1693                                 // word from the base address of the structure.
1694                                 //
1695                                 // AT_bit_offset indicates how many bits into the word
1696                                 // (according to the host endianness) the low-order bit of
1697                                 // the field starts.  AT_bit_offset can be negative.
1698                                 //
1699                                 // AT_bit_size indicates the size of the field in bits.
1700                                 /////////////////////////////////////////////////////////////
1701 
1702                                 ByteOrder object_endian = GetObjectFile()->GetModule()->GetArchitecture().GetDefaultEndian();
1703 
1704                                 uint64_t total_bit_offset = 0;
1705 
1706                                 total_bit_offset += (member_byte_offset == UINT32_MAX ? 0 : (member_byte_offset * 8));
1707 
1708                                 if (object_endian == eByteOrderLittle)
1709                                 {
1710                                     total_bit_offset += byte_size * 8;
1711                                     total_bit_offset -= (bit_offset + bit_size);
1712                                 }
1713                                 else
1714                                 {
1715                                     total_bit_offset += bit_offset;
1716                                 }
1717 
1718                                 layout_info.field_offsets.insert(std::make_pair(field_decl, total_bit_offset));
1719                             }
1720                         }
1721 
1722                         if (prop_name != NULL)
1723                         {
1724                             clang::ObjCIvarDecl *ivar_decl = NULL;
1725 
1726                             if (field_decl)
1727                             {
1728                                 ivar_decl = clang::dyn_cast<clang::ObjCIvarDecl>(field_decl);
1729                                 assert (ivar_decl != NULL);
1730                             }
1731 
1732                             GetClangASTContext().AddObjCClassProperty (class_clang_type,
1733                                                                        prop_name,
1734                                                                        member_type->GetClangLayoutType(),
1735                                                                        ivar_decl,
1736                                                                        prop_setter_name,
1737                                                                        prop_getter_name,
1738                                                                        prop_attributes);
1739                         }
1740                     }
1741                 }
1742                 ++member_idx;
1743             }
1744             break;
1745 
1746         case DW_TAG_subprogram:
1747             // Let the type parsing code handle this one for us.
1748             member_function_dies.Append (die);
1749             break;
1750 
1751         case DW_TAG_inheritance:
1752             {
1753                 is_a_class = true;
1754                 if (default_accessibility == eAccessNone)
1755                     default_accessibility = eAccessPrivate;
1756                 // TODO: implement DW_TAG_inheritance type parsing
1757                 DWARFDebugInfoEntry::Attributes attributes;
1758                 const size_t num_attributes = die->GetAttributes (this,
1759                                                                   dwarf_cu,
1760                                                                   fixed_form_sizes,
1761                                                                   attributes);
1762                 if (num_attributes > 0)
1763                 {
1764                     Declaration decl;
1765                     DWARFExpression location;
1766                     lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
1767                     AccessType accessibility = default_accessibility;
1768                     bool is_virtual = false;
1769                     bool is_base_of_class = true;
1770                     off_t member_offset = 0;
1771                     uint32_t i;
1772                     for (i=0; i<num_attributes; ++i)
1773                     {
1774                         const dw_attr_t attr = attributes.AttributeAtIndex(i);
1775                         DWARFFormValue form_value;
1776                         if (attributes.ExtractFormValueAtIndex(this, i, form_value))
1777                         {
1778                             switch (attr)
1779                             {
1780                             case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
1781                             case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
1782                             case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
1783                             case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break;
1784                             case DW_AT_data_member_location:
1785                                 if (form_value.BlockData())
1786                                 {
1787                                     Value initialValue(0);
1788                                     Value memberOffset(0);
1789                                     const DataExtractor& debug_info_data = get_debug_info_data();
1790                                     uint32_t block_length = form_value.Unsigned();
1791                                     uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
1792                                     if (DWARFExpression::Evaluate (NULL,
1793                                                                    NULL,
1794                                                                    NULL,
1795                                                                    NULL,
1796                                                                    NULL,
1797                                                                    debug_info_data,
1798                                                                    block_offset,
1799                                                                    block_length,
1800                                                                    eRegisterKindDWARF,
1801                                                                    &initialValue,
1802                                                                    memberOffset,
1803                                                                    NULL))
1804                                     {
1805                                         member_offset = memberOffset.ResolveValue(NULL, NULL).UInt();
1806                                     }
1807                                 }
1808                                 break;
1809 
1810                             case DW_AT_accessibility:
1811                                 accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
1812                                 break;
1813 
1814                             case DW_AT_virtuality: is_virtual = form_value.Unsigned() != 0; break;
1815                             default:
1816                             case DW_AT_sibling:
1817                                 break;
1818                             }
1819                         }
1820                     }
1821 
1822                     Type *base_class_type = ResolveTypeUID(encoding_uid);
1823                     assert(base_class_type);
1824 
1825                     clang_type_t base_class_clang_type = base_class_type->GetClangFullType();
1826                     assert (base_class_clang_type);
1827                     if (class_language == eLanguageTypeObjC)
1828                     {
1829                         GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_clang_type);
1830                     }
1831                     else
1832                     {
1833                         base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_clang_type,
1834                                                                                                accessibility,
1835                                                                                                is_virtual,
1836                                                                                                is_base_of_class));
1837                     }
1838                 }
1839             }
1840             break;
1841 
1842         default:
1843             break;
1844         }
1845     }
1846     return count;
1847 }
1848 
1849 
1850 clang::DeclContext*
1851 SymbolFileDWARF::GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid)
1852 {
1853     DWARFDebugInfo* debug_info = DebugInfo();
1854     if (debug_info && UserIDMatches(type_uid))
1855     {
1856         DWARFCompileUnitSP cu_sp;
1857         const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1858         if (die)
1859             return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
1860     }
1861     return NULL;
1862 }
1863 
1864 clang::DeclContext*
1865 SymbolFileDWARF::GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid)
1866 {
1867     if (UserIDMatches(type_uid))
1868         return GetClangDeclContextForDIEOffset (sc, type_uid);
1869     return NULL;
1870 }
1871 
1872 Type*
1873 SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
1874 {
1875     if (UserIDMatches(type_uid))
1876     {
1877         DWARFDebugInfo* debug_info = DebugInfo();
1878         if (debug_info)
1879         {
1880             DWARFCompileUnitSP cu_sp;
1881             const DWARFDebugInfoEntry* type_die = debug_info->GetDIEPtr(type_uid, &cu_sp);
1882             const bool assert_not_being_parsed = true;
1883             return ResolveTypeUID (cu_sp.get(), type_die, assert_not_being_parsed);
1884         }
1885     }
1886     return NULL;
1887 }
1888 
1889 Type*
1890 SymbolFileDWARF::ResolveTypeUID (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* die, bool assert_not_being_parsed)
1891 {
1892     if (die != NULL)
1893     {
1894         LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1895         if (log)
1896             GetObjectFile()->GetModule()->LogMessage (log.get(),
1897                                                       "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1898                                                       die->GetOffset(),
1899                                                       DW_TAG_value_to_name(die->Tag()),
1900                                                       die->GetName(this, cu));
1901 
1902         // We might be coming in in the middle of a type tree (a class
1903         // withing a class, an enum within a class), so parse any needed
1904         // parent DIEs before we get to this one...
1905         const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
1906         switch (decl_ctx_die->Tag())
1907         {
1908             case DW_TAG_structure_type:
1909             case DW_TAG_union_type:
1910             case DW_TAG_class_type:
1911             {
1912                 // Get the type, which could be a forward declaration
1913                 if (log)
1914                     GetObjectFile()->GetModule()->LogMessage (log.get(),
1915                                                               "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1916                                                               die->GetOffset(),
1917                                                               DW_TAG_value_to_name(die->Tag()),
1918                                                               die->GetName(this, cu),
1919                                                               decl_ctx_die->GetOffset());
1920 //
1921 //                Type *parent_type = ResolveTypeUID (cu, decl_ctx_die, assert_not_being_parsed);
1922 //                if (child_requires_parent_class_union_or_struct_to_be_completed(die->Tag()))
1923 //                {
1924 //                    if (log)
1925 //                        GetObjectFile()->GetModule()->LogMessage (log.get(),
1926 //                                                                  "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent full type for 0x%8.8x since die is a function",
1927 //                                                                  die->GetOffset(),
1928 //                                                                  DW_TAG_value_to_name(die->Tag()),
1929 //                                                                  die->GetName(this, cu),
1930 //                                                                  decl_ctx_die->GetOffset());
1931 //                    // Ask the type to complete itself if it already hasn't since if we
1932 //                    // want a function (method or static) from a class, the class must
1933 //                    // create itself and add it's own methods and class functions.
1934 //                    if (parent_type)
1935 //                        parent_type->GetClangFullType();
1936 //                }
1937             }
1938             break;
1939 
1940             default:
1941                 break;
1942         }
1943         return ResolveType (cu, die);
1944     }
1945     return NULL;
1946 }
1947 
1948 // This function is used when SymbolFileDWARFDebugMap owns a bunch of
1949 // SymbolFileDWARF objects to detect if this DWARF file is the one that
1950 // can resolve a clang_type.
1951 bool
1952 SymbolFileDWARF::HasForwardDeclForClangType (lldb::clang_type_t clang_type)
1953 {
1954     clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1955     const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1956     return die != NULL;
1957 }
1958 
1959 
1960 lldb::clang_type_t
1961 SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_type)
1962 {
1963     // We have a struct/union/class/enum that needs to be fully resolved.
1964     clang_type_t clang_type_no_qualifiers = ClangASTType::RemoveFastQualifiers(clang_type);
1965     const DWARFDebugInfoEntry* die = m_forward_decl_clang_type_to_die.lookup (clang_type_no_qualifiers);
1966     if (die == NULL)
1967     {
1968         // We have already resolved this type...
1969         return clang_type;
1970     }
1971     // Once we start resolving this type, remove it from the forward declaration
1972     // map in case anyone child members or other types require this type to get resolved.
1973     // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1974     // are done.
1975     m_forward_decl_clang_type_to_die.erase (clang_type_no_qualifiers);
1976 
1977 
1978     // Disable external storage for this type so we don't get anymore
1979     // clang::ExternalASTSource queries for this type.
1980     ClangASTContext::SetHasExternalStorage (clang_type, false);
1981 
1982     DWARFDebugInfo* debug_info = DebugInfo();
1983 
1984     DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitContainingDIE (die->GetOffset()).get();
1985     Type *type = m_die_to_type.lookup (die);
1986 
1987     const dw_tag_t tag = die->Tag();
1988 
1989     LogSP log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
1990     if (log)
1991     {
1992         GetObjectFile()->GetModule()->LogMessage (log.get(),
1993                                                   "0x%8.8llx: %s '%s' resolving forward declaration...",
1994                                                   MakeUserID(die->GetOffset()),
1995                                                   DW_TAG_value_to_name(tag),
1996                                                   type->GetName().AsCString());
1997 
1998         if (log->GetVerbose())
1999         {
2000             StreamString strm;
2001             Host::Backtrace (strm, 1024);
2002             if (strm.GetData())
2003                 log->PutCString(strm.GetData());
2004         }
2005     }
2006     assert (clang_type);
2007     DWARFDebugInfoEntry::Attributes attributes;
2008 
2009     ClangASTContext &ast = GetClangASTContext();
2010 
2011     switch (tag)
2012     {
2013     case DW_TAG_structure_type:
2014     case DW_TAG_union_type:
2015     case DW_TAG_class_type:
2016         {
2017             LayoutInfo layout_info;
2018 
2019             {
2020                 if (die->HasChildren())
2021                 {
2022 
2023                     LanguageType class_language = eLanguageTypeUnknown;
2024                     bool is_objc_class = ClangASTContext::IsObjCClassType (clang_type);
2025                     if (is_objc_class)
2026                     {
2027                         class_language = eLanguageTypeObjC;
2028                         // For objective C we don't start the definition when
2029                         // the class is created.
2030                         ast.StartTagDeclarationDefinition (clang_type);
2031                     }
2032 
2033                     int tag_decl_kind = -1;
2034                     AccessType default_accessibility = eAccessNone;
2035                     if (tag == DW_TAG_structure_type)
2036                     {
2037                         tag_decl_kind = clang::TTK_Struct;
2038                         default_accessibility = eAccessPublic;
2039                     }
2040                     else if (tag == DW_TAG_union_type)
2041                     {
2042                         tag_decl_kind = clang::TTK_Union;
2043                         default_accessibility = eAccessPublic;
2044                     }
2045                     else if (tag == DW_TAG_class_type)
2046                     {
2047                         tag_decl_kind = clang::TTK_Class;
2048                         default_accessibility = eAccessPrivate;
2049                     }
2050 
2051                     SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2052                     std::vector<clang::CXXBaseSpecifier *> base_classes;
2053                     std::vector<int> member_accessibilities;
2054                     bool is_a_class = false;
2055                     // Parse members and base classes first
2056                     DWARFDIECollection member_function_dies;
2057 
2058                     ParseChildMembers (sc,
2059                                        dwarf_cu,
2060                                        die,
2061                                        clang_type,
2062                                        class_language,
2063                                        base_classes,
2064                                        member_accessibilities,
2065                                        member_function_dies,
2066                                        default_accessibility,
2067                                        is_a_class,
2068                                        layout_info);
2069 
2070                     // Now parse any methods if there were any...
2071                     size_t num_functions = member_function_dies.Size();
2072                     if (num_functions > 0)
2073                     {
2074                         for (size_t i=0; i<num_functions; ++i)
2075                         {
2076                             ResolveType(dwarf_cu, member_function_dies.GetDIEPtrAtIndex(i));
2077                         }
2078                     }
2079 
2080                     if (class_language == eLanguageTypeObjC)
2081                     {
2082                         std::string class_str (ClangASTType::GetTypeNameForOpaqueQualType(ast.getASTContext(), clang_type));
2083                         if (!class_str.empty())
2084                         {
2085 
2086                             DIEArray method_die_offsets;
2087                             if (m_using_apple_tables)
2088                             {
2089                                 if (m_apple_objc_ap.get())
2090                                     m_apple_objc_ap->FindByName(class_str.c_str(), method_die_offsets);
2091                             }
2092                             else
2093                             {
2094                                 if (!m_indexed)
2095                                     Index ();
2096 
2097                                 ConstString class_name (class_str.c_str());
2098                                 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
2099                             }
2100 
2101                             if (!method_die_offsets.empty())
2102                             {
2103                                 DWARFDebugInfo* debug_info = DebugInfo();
2104 
2105                                 DWARFCompileUnit* method_cu = NULL;
2106                                 const size_t num_matches = method_die_offsets.size();
2107                                 for (size_t i=0; i<num_matches; ++i)
2108                                 {
2109                                     const dw_offset_t die_offset = method_die_offsets[i];
2110                                     DWARFDebugInfoEntry *method_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &method_cu);
2111 
2112                                     if (method_die)
2113                                         ResolveType (method_cu, method_die);
2114                                     else
2115                                     {
2116                                         if (m_using_apple_tables)
2117                                         {
2118                                             GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_objc accelerator table had bad die 0x%8.8x for '%s')\n",
2119                                                                                                        die_offset, class_str.c_str());
2120                                         }
2121                                     }
2122                                 }
2123                             }
2124                         }
2125                     }
2126 
2127                     // If we have a DW_TAG_structure_type instead of a DW_TAG_class_type we
2128                     // need to tell the clang type it is actually a class.
2129                     if (class_language != eLanguageTypeObjC)
2130                     {
2131                         if (is_a_class && tag_decl_kind != clang::TTK_Class)
2132                             ast.SetTagTypeKind (clang_type, clang::TTK_Class);
2133                     }
2134 
2135                     // Since DW_TAG_structure_type gets used for both classes
2136                     // and structures, we may need to set any DW_TAG_member
2137                     // fields to have a "private" access if none was specified.
2138                     // When we parsed the child members we tracked that actual
2139                     // accessibility value for each DW_TAG_member in the
2140                     // "member_accessibilities" array. If the value for the
2141                     // member is zero, then it was set to the "default_accessibility"
2142                     // which for structs was "public". Below we correct this
2143                     // by setting any fields to "private" that weren't correctly
2144                     // set.
2145                     if (is_a_class && !member_accessibilities.empty())
2146                     {
2147                         // This is a class and all members that didn't have
2148                         // their access specified are private.
2149                         ast.SetDefaultAccessForRecordFields (clang_type,
2150                                                              eAccessPrivate,
2151                                                              &member_accessibilities.front(),
2152                                                              member_accessibilities.size());
2153                     }
2154 
2155                     if (!base_classes.empty())
2156                     {
2157                         ast.SetBaseClassesForClassType (clang_type,
2158                                                         &base_classes.front(),
2159                                                         base_classes.size());
2160 
2161                         // Clang will copy each CXXBaseSpecifier in "base_classes"
2162                         // so we have to free them all.
2163                         ClangASTContext::DeleteBaseClassSpecifiers (&base_classes.front(),
2164                                                                     base_classes.size());
2165                     }
2166                 }
2167             }
2168 
2169             ast.BuildIndirectFields (clang_type);
2170 
2171             ast.CompleteTagDeclarationDefinition (clang_type);
2172 
2173             if (!layout_info.field_offsets.empty())
2174             {
2175                 if (type)
2176                     layout_info.bit_size = type->GetByteSize() * 8;
2177                 if (layout_info.bit_size == 0)
2178                     layout_info.bit_size = die->GetAttributeValueAsUnsigned(this, dwarf_cu, DW_AT_byte_size, 0) * 8;
2179                 clang::QualType qual_type(clang::QualType::getFromOpaquePtr(clang_type));
2180                 const clang::RecordType *record_type = clang::dyn_cast<clang::RecordType>(qual_type.getTypePtr());
2181                 if (record_type)
2182                 {
2183                     const clang::RecordDecl *record_decl = record_type->getDecl();
2184 
2185                     if (log)
2186                     {
2187                         GetObjectFile()->GetModule()->LogMessage (log.get(),
2188                                                                   "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) caching layout info for record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u], base_offsets[0], vbase_offsets[0])",
2189                                                                   clang_type,
2190                                                                   record_decl,
2191                                                                   layout_info.bit_size,
2192                                                                   layout_info.alignment,
2193                                                                   (uint32_t)layout_info.field_offsets.size());
2194 
2195                         llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end();
2196                         for (pos = layout_info.field_offsets.begin(); pos != end; ++pos)
2197                         {
2198                             GetObjectFile()->GetModule()->LogMessage (log.get(),
2199                                                                       "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field = { bit_offset=%u, name='%s' }",
2200                                                                       clang_type,
2201                                                                       (uint32_t)pos->second,
2202                                                                       pos->first->getNameAsString().c_str());
2203                         }
2204                     }
2205                     m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
2206                 }
2207             }
2208         }
2209 
2210         return clang_type;
2211 
2212     case DW_TAG_enumeration_type:
2213         ast.StartTagDeclarationDefinition (clang_type);
2214         if (die->HasChildren())
2215         {
2216             SymbolContext sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
2217             ParseChildEnumerators(sc, clang_type, type->GetByteSize(), dwarf_cu, die);
2218         }
2219         ast.CompleteTagDeclarationDefinition (clang_type);
2220         return clang_type;
2221 
2222     default:
2223         assert(false && "not a forward clang type decl!");
2224         break;
2225     }
2226     return NULL;
2227 }
2228 
2229 Type*
2230 SymbolFileDWARF::ResolveType (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed)
2231 {
2232     if (type_die != NULL)
2233     {
2234         Type *type = m_die_to_type.lookup (type_die);
2235 
2236         if (type == NULL)
2237             type = GetTypeForDIE (dwarf_cu, type_die).get();
2238 
2239         if (assert_not_being_parsed)
2240         {
2241             if (type != DIE_IS_BEING_PARSED)
2242                 return type;
2243 
2244             GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
2245                                                        type_die->GetOffset(),
2246                                                        DW_TAG_value_to_name(type_die->Tag()),
2247                                                        type_die->GetName(this, dwarf_cu));
2248 
2249         }
2250         else
2251             return type;
2252     }
2253     return NULL;
2254 }
2255 
2256 CompileUnit*
2257 SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
2258 {
2259     // Check if the symbol vendor already knows about this compile unit?
2260     if (dwarf_cu->GetUserData() == NULL)
2261     {
2262         // The symbol vendor doesn't know about this compile unit, we
2263         // need to parse and add it to the symbol vendor object.
2264         return ParseCompileUnit(dwarf_cu, cu_idx).get();
2265     }
2266     return (CompileUnit*)dwarf_cu->GetUserData();
2267 }
2268 
2269 bool
2270 SymbolFileDWARF::GetFunction (DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry* func_die, SymbolContext& sc)
2271 {
2272     sc.Clear();
2273     // Check if the symbol vendor already knows about this compile unit?
2274     sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2275 
2276     sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(func_die->GetOffset())).get();
2277     if (sc.function == NULL)
2278         sc.function = ParseCompileUnitFunction(sc, dwarf_cu, func_die);
2279 
2280     if (sc.function)
2281     {
2282         sc.module_sp = sc.function->CalculateSymbolContextModule();
2283         return true;
2284     }
2285 
2286     return false;
2287 }
2288 
2289 uint32_t
2290 SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
2291 {
2292     Timer scoped_timer(__PRETTY_FUNCTION__,
2293                        "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%llx }, resolve_scope = 0x%8.8x)",
2294                        so_addr.GetSection().get(),
2295                        so_addr.GetOffset(),
2296                        resolve_scope);
2297     uint32_t resolved = 0;
2298     if (resolve_scope & (   eSymbolContextCompUnit |
2299                             eSymbolContextFunction |
2300                             eSymbolContextBlock |
2301                             eSymbolContextLineEntry))
2302     {
2303         lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
2304 
2305         DWARFDebugInfo* debug_info = DebugInfo();
2306         if (debug_info)
2307         {
2308             dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
2309             if (cu_offset != DW_INVALID_OFFSET)
2310             {
2311                 uint32_t cu_idx;
2312                 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx).get();
2313                 if (dwarf_cu)
2314                 {
2315                     sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
2316                     assert(sc.comp_unit != NULL);
2317                     resolved |= eSymbolContextCompUnit;
2318 
2319                     if (resolve_scope & eSymbolContextLineEntry)
2320                     {
2321                         LineTable *line_table = sc.comp_unit->GetLineTable();
2322                         if (line_table != NULL)
2323                         {
2324                             if (so_addr.IsLinkedAddress())
2325                             {
2326                                 Address linked_addr (so_addr);
2327                                 linked_addr.ResolveLinkedAddress();
2328                                 if (line_table->FindLineEntryByAddress (linked_addr, sc.line_entry))
2329                                 {
2330                                     resolved |= eSymbolContextLineEntry;
2331                                 }
2332                             }
2333                             else if (line_table->FindLineEntryByAddress (so_addr, sc.line_entry))
2334                             {
2335                                 resolved |= eSymbolContextLineEntry;
2336                             }
2337                         }
2338                     }
2339 
2340                     if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2341                     {
2342                         DWARFDebugInfoEntry *function_die = NULL;
2343                         DWARFDebugInfoEntry *block_die = NULL;
2344                         if (resolve_scope & eSymbolContextBlock)
2345                         {
2346                             dwarf_cu->LookupAddress(file_vm_addr, &function_die, &block_die);
2347                         }
2348                         else
2349                         {
2350                             dwarf_cu->LookupAddress(file_vm_addr, &function_die, NULL);
2351                         }
2352 
2353                         if (function_die != NULL)
2354                         {
2355                             sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2356                             if (sc.function == NULL)
2357                                 sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2358                         }
2359                         else
2360                         {
2361                             // We might have had a compile unit that had discontiguous
2362                             // address ranges where the gaps are symbols that don't have
2363                             // any debug info. Discontiguous compile unit address ranges
2364                             // should only happen when there aren't other functions from
2365                             // other compile units in these gaps. This helps keep the size
2366                             // of the aranges down.
2367                             sc.comp_unit = NULL;
2368                             resolved &= ~eSymbolContextCompUnit;
2369                         }
2370 
2371                         if (sc.function != NULL)
2372                         {
2373                             resolved |= eSymbolContextFunction;
2374 
2375                             if (resolve_scope & eSymbolContextBlock)
2376                             {
2377                                 Block& block = sc.function->GetBlock (true);
2378 
2379                                 if (block_die != NULL)
2380                                     sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2381                                 else
2382                                     sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2383                                 if (sc.block)
2384                                     resolved |= eSymbolContextBlock;
2385                             }
2386                         }
2387                     }
2388                 }
2389             }
2390         }
2391     }
2392     return resolved;
2393 }
2394 
2395 
2396 
2397 uint32_t
2398 SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
2399 {
2400     const uint32_t prev_size = sc_list.GetSize();
2401     if (resolve_scope & eSymbolContextCompUnit)
2402     {
2403         DWARFDebugInfo* debug_info = DebugInfo();
2404         if (debug_info)
2405         {
2406             uint32_t cu_idx;
2407             DWARFCompileUnit* dwarf_cu = NULL;
2408 
2409             for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
2410             {
2411                 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
2412                 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Compare(file_spec, *dc_cu, false) == 0;
2413                 if (check_inlines || file_spec_matches_cu_file_spec)
2414                 {
2415                     SymbolContext sc (m_obj_file->GetModule());
2416                     sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
2417                     assert(sc.comp_unit != NULL);
2418 
2419                     uint32_t file_idx = UINT32_MAX;
2420 
2421                     // If we are looking for inline functions only and we don't
2422                     // find it in the support files, we are done.
2423                     if (check_inlines)
2424                     {
2425                         file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2426                         if (file_idx == UINT32_MAX)
2427                             continue;
2428                     }
2429 
2430                     if (line != 0)
2431                     {
2432                         LineTable *line_table = sc.comp_unit->GetLineTable();
2433 
2434                         if (line_table != NULL && line != 0)
2435                         {
2436                             // We will have already looked up the file index if
2437                             // we are searching for inline entries.
2438                             if (!check_inlines)
2439                                 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2440 
2441                             if (file_idx != UINT32_MAX)
2442                             {
2443                                 uint32_t found_line;
2444                                 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2445                                 found_line = sc.line_entry.line;
2446 
2447                                 while (line_idx != UINT32_MAX)
2448                                 {
2449                                     sc.function = NULL;
2450                                     sc.block = NULL;
2451                                     if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2452                                     {
2453                                         const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2454                                         if (file_vm_addr != LLDB_INVALID_ADDRESS)
2455                                         {
2456                                             DWARFDebugInfoEntry *function_die = NULL;
2457                                             DWARFDebugInfoEntry *block_die = NULL;
2458                                             dwarf_cu->LookupAddress(file_vm_addr, &function_die, resolve_scope & eSymbolContextBlock ? &block_die : NULL);
2459 
2460                                             if (function_die != NULL)
2461                                             {
2462                                                 sc.function = sc.comp_unit->FindFunctionByUID (MakeUserID(function_die->GetOffset())).get();
2463                                                 if (sc.function == NULL)
2464                                                     sc.function = ParseCompileUnitFunction(sc, dwarf_cu, function_die);
2465                                             }
2466 
2467                                             if (sc.function != NULL)
2468                                             {
2469                                                 Block& block = sc.function->GetBlock (true);
2470 
2471                                                 if (block_die != NULL)
2472                                                     sc.block = block.FindBlockByID (MakeUserID(block_die->GetOffset()));
2473                                                 else
2474                                                     sc.block = block.FindBlockByID (MakeUserID(function_die->GetOffset()));
2475                                             }
2476                                         }
2477                                     }
2478 
2479                                     sc_list.Append(sc);
2480                                     line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2481                                 }
2482                             }
2483                         }
2484                         else if (file_spec_matches_cu_file_spec && !check_inlines)
2485                         {
2486                             // only append the context if we aren't looking for inline call sites
2487                             // by file and line and if the file spec matches that of the compile unit
2488                             sc_list.Append(sc);
2489                         }
2490                     }
2491                     else if (file_spec_matches_cu_file_spec && !check_inlines)
2492                     {
2493                         // only append the context if we aren't looking for inline call sites
2494                         // by file and line and if the file spec matches that of the compile unit
2495                         sc_list.Append(sc);
2496                     }
2497 
2498                     if (!check_inlines)
2499                         break;
2500                 }
2501             }
2502         }
2503     }
2504     return sc_list.GetSize() - prev_size;
2505 }
2506 
2507 void
2508 SymbolFileDWARF::Index ()
2509 {
2510     if (m_indexed)
2511         return;
2512     m_indexed = true;
2513     Timer scoped_timer (__PRETTY_FUNCTION__,
2514                         "SymbolFileDWARF::Index (%s)",
2515                         GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2516 
2517     DWARFDebugInfo* debug_info = DebugInfo();
2518     if (debug_info)
2519     {
2520         uint32_t cu_idx = 0;
2521         const uint32_t num_compile_units = GetNumCompileUnits();
2522         for (cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2523         {
2524             DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
2525 
2526             bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded (false) > 1;
2527 
2528             dwarf_cu->Index (cu_idx,
2529                              m_function_basename_index,
2530                              m_function_fullname_index,
2531                              m_function_method_index,
2532                              m_function_selector_index,
2533                              m_objc_class_selectors_index,
2534                              m_global_index,
2535                              m_type_index,
2536                              m_namespace_index);
2537 
2538             // Keep memory down by clearing DIEs if this generate function
2539             // caused them to be parsed
2540             if (clear_dies)
2541                 dwarf_cu->ClearDIEs (true);
2542         }
2543 
2544         m_function_basename_index.Finalize();
2545         m_function_fullname_index.Finalize();
2546         m_function_method_index.Finalize();
2547         m_function_selector_index.Finalize();
2548         m_objc_class_selectors_index.Finalize();
2549         m_global_index.Finalize();
2550         m_type_index.Finalize();
2551         m_namespace_index.Finalize();
2552 
2553 #if defined (ENABLE_DEBUG_PRINTF)
2554         StreamFile s(stdout, false);
2555         s.Printf ("DWARF index for '%s/%s':",
2556                   GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
2557                   GetObjectFile()->GetFileSpec().GetFilename().AsCString());
2558         s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s);
2559         s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s);
2560         s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s);
2561         s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s);
2562         s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s);
2563         s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s);
2564         s.Printf("\nTypes:\n");                 m_type_index.Dump (&s);
2565         s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s);
2566 #endif
2567     }
2568 }
2569 
2570 bool
2571 SymbolFileDWARF::NamespaceDeclMatchesThisSymbolFile (const ClangNamespaceDecl *namespace_decl)
2572 {
2573     if (namespace_decl == NULL)
2574     {
2575         // Invalid namespace decl which means we aren't matching only things
2576         // in this symbol file, so return true to indicate it matches this
2577         // symbol file.
2578         return true;
2579     }
2580 
2581     clang::ASTContext *namespace_ast = namespace_decl->GetASTContext();
2582 
2583     if (namespace_ast == NULL)
2584         return true;    // No AST in the "namespace_decl", return true since it
2585                         // could then match any symbol file, including this one
2586 
2587     if (namespace_ast == GetClangASTContext().getASTContext())
2588         return true;    // The ASTs match, return true
2589 
2590     // The namespace AST was valid, and it does not match...
2591     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2592 
2593     if (log)
2594         GetObjectFile()->GetModule()->LogMessage(log.get(), "Valid namespace does not match symbol file");
2595 
2596     return false;
2597 }
2598 
2599 bool
2600 SymbolFileDWARF::DIEIsInNamespace (const ClangNamespaceDecl *namespace_decl,
2601                                    DWARFCompileUnit* cu,
2602                                    const DWARFDebugInfoEntry* die)
2603 {
2604     // No namespace specified, so the answesr i
2605     if (namespace_decl == NULL)
2606         return true;
2607 
2608     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2609 
2610     const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
2611     if (decl_ctx_die)
2612     {
2613 
2614         clang::NamespaceDecl *clang_namespace_decl = namespace_decl->GetNamespaceDecl();
2615         if (clang_namespace_decl)
2616         {
2617             if (decl_ctx_die->Tag() != DW_TAG_namespace)
2618             {
2619                 if (log)
2620                     GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent is not a namespace");
2621                 return false;
2622             }
2623 
2624             DeclContextToDIEMap::iterator pos = m_decl_ctx_to_die.find(clang_namespace_decl);
2625 
2626             if (pos == m_decl_ctx_to_die.end())
2627             {
2628                 if (log)
2629                     GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match in a namespace, but its parent is not the requested namespace");
2630 
2631                 return false;
2632             }
2633 
2634             return pos->second.count (decl_ctx_die);
2635         }
2636         else
2637         {
2638             // We have a namespace_decl that was not NULL but it contained
2639             // a NULL "clang::NamespaceDecl", so this means the global namespace
2640             // So as long the the contained decl context DIE isn't a namespace
2641             // we should be ok.
2642             if (decl_ctx_die->Tag() != DW_TAG_namespace)
2643                 return true;
2644         }
2645     }
2646 
2647     if (log)
2648         GetObjectFile()->GetModule()->LogMessage(log.get(), "Found a match, but its parent doesn't exist");
2649 
2650     return false;
2651 }
2652 uint32_t
2653 SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, VariableList& variables)
2654 {
2655     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2656 
2657     if (log)
2658     {
2659         GetObjectFile()->GetModule()->LogMessage (log.get(),
2660                                                   "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", namespace_decl=%p, append=%u, max_matches=%u, variables)",
2661                                                   name.GetCString(),
2662                                                   namespace_decl,
2663                                                   append,
2664                                                   max_matches);
2665     }
2666 
2667     if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
2668 		return 0;
2669 
2670     DWARFDebugInfo* info = DebugInfo();
2671     if (info == NULL)
2672         return 0;
2673 
2674     // If we aren't appending the results to this list, then clear the list
2675     if (!append)
2676         variables.Clear();
2677 
2678     // Remember how many variables are in the list before we search in case
2679     // we are appending the results to a variable list.
2680     const uint32_t original_size = variables.GetSize();
2681 
2682     DIEArray die_offsets;
2683 
2684     if (m_using_apple_tables)
2685     {
2686         if (m_apple_names_ap.get())
2687         {
2688             const char *name_cstr = name.GetCString();
2689             const char *base_name_start;
2690             const char *base_name_end = NULL;
2691 
2692             if (!CPPLanguageRuntime::StripNamespacesFromVariableName(name_cstr, base_name_start, base_name_end))
2693                 base_name_start = name_cstr;
2694 
2695             m_apple_names_ap->FindByName (base_name_start, die_offsets);
2696         }
2697     }
2698     else
2699     {
2700         // Index the DWARF if we haven't already
2701         if (!m_indexed)
2702             Index ();
2703 
2704         m_global_index.Find (name, die_offsets);
2705     }
2706 
2707     const size_t num_matches = die_offsets.size();
2708     if (num_matches)
2709     {
2710         SymbolContext sc;
2711         sc.module_sp = m_obj_file->GetModule();
2712         assert (sc.module_sp);
2713 
2714         DWARFDebugInfo* debug_info = DebugInfo();
2715         DWARFCompileUnit* dwarf_cu = NULL;
2716         const DWARFDebugInfoEntry* die = NULL;
2717         for (size_t i=0; i<num_matches; ++i)
2718         {
2719             const dw_offset_t die_offset = die_offsets[i];
2720             die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2721 
2722             if (die)
2723             {
2724                 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2725                 assert(sc.comp_unit != NULL);
2726 
2727                 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
2728                     continue;
2729 
2730                 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
2731 
2732                 if (variables.GetSize() - original_size >= max_matches)
2733                     break;
2734             }
2735             else
2736             {
2737                 if (m_using_apple_tables)
2738                 {
2739                     GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2740                                                                                die_offset, name.GetCString());
2741                 }
2742             }
2743         }
2744     }
2745 
2746     // Return the number of variable that were appended to the list
2747     return variables.GetSize() - original_size;
2748 }
2749 
2750 uint32_t
2751 SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2752 {
2753     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2754 
2755     if (log)
2756     {
2757         GetObjectFile()->GetModule()->LogMessage (log.get(),
2758                                                   "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2759                                                   regex.GetText(),
2760                                                   append,
2761                                                   max_matches);
2762     }
2763 
2764     DWARFDebugInfo* info = DebugInfo();
2765     if (info == NULL)
2766         return 0;
2767 
2768     // If we aren't appending the results to this list, then clear the list
2769     if (!append)
2770         variables.Clear();
2771 
2772     // Remember how many variables are in the list before we search in case
2773     // we are appending the results to a variable list.
2774     const uint32_t original_size = variables.GetSize();
2775 
2776     DIEArray die_offsets;
2777 
2778     if (m_using_apple_tables)
2779     {
2780         if (m_apple_names_ap.get())
2781         {
2782             DWARFMappedHash::DIEInfoArray hash_data_array;
2783             if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2784                 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2785         }
2786     }
2787     else
2788     {
2789         // Index the DWARF if we haven't already
2790         if (!m_indexed)
2791             Index ();
2792 
2793         m_global_index.Find (regex, die_offsets);
2794     }
2795 
2796     SymbolContext sc;
2797     sc.module_sp = m_obj_file->GetModule();
2798     assert (sc.module_sp);
2799 
2800     DWARFCompileUnit* dwarf_cu = NULL;
2801     const DWARFDebugInfoEntry* die = NULL;
2802     const size_t num_matches = die_offsets.size();
2803     if (num_matches)
2804     {
2805         DWARFDebugInfo* debug_info = DebugInfo();
2806         for (size_t i=0; i<num_matches; ++i)
2807         {
2808             const dw_offset_t die_offset = die_offsets[i];
2809             die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2810 
2811             if (die)
2812             {
2813                 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
2814 
2815                 ParseVariables(sc, dwarf_cu, LLDB_INVALID_ADDRESS, die, false, false, &variables);
2816 
2817                 if (variables.GetSize() - original_size >= max_matches)
2818                     break;
2819             }
2820             else
2821             {
2822                 if (m_using_apple_tables)
2823                 {
2824                     GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2825                                                                                die_offset, regex.GetText());
2826                 }
2827             }
2828         }
2829     }
2830 
2831     // Return the number of variable that were appended to the list
2832     return variables.GetSize() - original_size;
2833 }
2834 
2835 
2836 bool
2837 SymbolFileDWARF::ResolveFunction (dw_offset_t die_offset,
2838                                   DWARFCompileUnit *&dwarf_cu,
2839                                   SymbolContextList& sc_list)
2840 {
2841     const DWARFDebugInfoEntry *die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
2842     return ResolveFunction (dwarf_cu, die, sc_list);
2843 }
2844 
2845 
2846 bool
2847 SymbolFileDWARF::ResolveFunction (DWARFCompileUnit *cu,
2848                                   const DWARFDebugInfoEntry *die,
2849                                   SymbolContextList& sc_list)
2850 {
2851     SymbolContext sc;
2852 
2853     if (die == NULL)
2854         return false;
2855 
2856     // If we were passed a die that is not a function, just return false...
2857     if (die->Tag() != DW_TAG_subprogram && die->Tag() != DW_TAG_inlined_subroutine)
2858         return false;
2859 
2860     const DWARFDebugInfoEntry* inlined_die = NULL;
2861     if (die->Tag() == DW_TAG_inlined_subroutine)
2862     {
2863         inlined_die = die;
2864 
2865         while ((die = die->GetParent()) != NULL)
2866         {
2867             if (die->Tag() == DW_TAG_subprogram)
2868                 break;
2869         }
2870     }
2871     assert (die->Tag() == DW_TAG_subprogram);
2872     if (GetFunction (cu, die, sc))
2873     {
2874         Address addr;
2875         // Parse all blocks if needed
2876         if (inlined_die)
2877         {
2878             sc.block = sc.function->GetBlock (true).FindBlockByID (MakeUserID(inlined_die->GetOffset()));
2879             assert (sc.block != NULL);
2880             if (sc.block->GetStartAddress (addr) == false)
2881                 addr.Clear();
2882         }
2883         else
2884         {
2885             sc.block = NULL;
2886             addr = sc.function->GetAddressRange().GetBaseAddress();
2887         }
2888 
2889         if (addr.IsValid())
2890         {
2891             sc_list.Append(sc);
2892             return true;
2893         }
2894     }
2895 
2896     return false;
2897 }
2898 
2899 void
2900 SymbolFileDWARF::FindFunctions (const ConstString &name,
2901                                 const NameToDIE &name_to_die,
2902                                 SymbolContextList& sc_list)
2903 {
2904     DIEArray die_offsets;
2905     if (name_to_die.Find (name, die_offsets))
2906     {
2907         ParseFunctions (die_offsets, sc_list);
2908     }
2909 }
2910 
2911 
2912 void
2913 SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2914                                 const NameToDIE &name_to_die,
2915                                 SymbolContextList& sc_list)
2916 {
2917     DIEArray die_offsets;
2918     if (name_to_die.Find (regex, die_offsets))
2919     {
2920         ParseFunctions (die_offsets, sc_list);
2921     }
2922 }
2923 
2924 
2925 void
2926 SymbolFileDWARF::FindFunctions (const RegularExpression &regex,
2927                                 const DWARFMappedHash::MemoryTable &memory_table,
2928                                 SymbolContextList& sc_list)
2929 {
2930     DIEArray die_offsets;
2931     DWARFMappedHash::DIEInfoArray hash_data_array;
2932     if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2933     {
2934         DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2935         ParseFunctions (die_offsets, sc_list);
2936     }
2937 }
2938 
2939 void
2940 SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2941                                  SymbolContextList& sc_list)
2942 {
2943     const size_t num_matches = die_offsets.size();
2944     if (num_matches)
2945     {
2946         SymbolContext sc;
2947 
2948         DWARFCompileUnit* dwarf_cu = NULL;
2949         for (size_t i=0; i<num_matches; ++i)
2950         {
2951             const dw_offset_t die_offset = die_offsets[i];
2952             ResolveFunction (die_offset, dwarf_cu, sc_list);
2953         }
2954     }
2955 }
2956 
2957 bool
2958 SymbolFileDWARF::FunctionDieMatchesPartialName (const DWARFDebugInfoEntry* die,
2959                                                 const DWARFCompileUnit *dwarf_cu,
2960                                                 uint32_t name_type_mask,
2961                                                 const char *partial_name,
2962                                                 const char *base_name_start,
2963                                                 const char *base_name_end)
2964 {
2965     // If we are looking only for methods, throw away all the ones that aren't in C++ classes:
2966     if (name_type_mask == eFunctionNameTypeMethod
2967         || name_type_mask == eFunctionNameTypeBase)
2968     {
2969         clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIEOffset(die->GetOffset());
2970         if (!containing_decl_ctx)
2971             return false;
2972 
2973         bool is_cxx_method = DeclKindIsCXXClass(containing_decl_ctx->getDeclKind());
2974 
2975         if (!is_cxx_method && name_type_mask == eFunctionNameTypeMethod)
2976             return false;
2977         if (is_cxx_method && name_type_mask == eFunctionNameTypeBase)
2978             return false;
2979     }
2980 
2981     // Now we need to check whether the name we got back for this type matches the extra specifications
2982     // that were in the name we're looking up:
2983     if (base_name_start != partial_name || *base_name_end != '\0')
2984     {
2985         // First see if the stuff to the left matches the full name.  To do that let's see if
2986         // we can pull out the mips linkage name attribute:
2987 
2988         Mangled best_name;
2989 
2990         DWARFDebugInfoEntry::Attributes attributes;
2991         die->GetAttributes(this, dwarf_cu, NULL, attributes);
2992         uint32_t idx = attributes.FindAttributeIndex(DW_AT_MIPS_linkage_name);
2993         if (idx != UINT32_MAX)
2994         {
2995             DWARFFormValue form_value;
2996             if (attributes.ExtractFormValueAtIndex(this, idx, form_value))
2997             {
2998                 const char *name = form_value.AsCString(&get_debug_str_data());
2999                 best_name.SetValue (name, true);
3000             }
3001         }
3002         if (best_name)
3003         {
3004             const char *demangled = best_name.GetDemangledName().GetCString();
3005             if (demangled)
3006             {
3007                 std::string name_no_parens(partial_name, base_name_end - partial_name);
3008                 const char *partial_in_demangled = strstr (demangled, name_no_parens.c_str());
3009                 if (partial_in_demangled == NULL)
3010                     return false;
3011                 else
3012                 {
3013                     // Sort out the case where our name is something like "Process::Destroy" and the match is
3014                     // "SBProcess::Destroy" - that shouldn't be a match.  We should really always match on
3015                     // namespace boundaries...
3016 
3017                     if (partial_name[0] == ':'  && partial_name[1] == ':')
3018                     {
3019                         // The partial name was already on a namespace boundary so all matches are good.
3020                         return true;
3021                     }
3022                     else if (partial_in_demangled == demangled)
3023                     {
3024                         // They both start the same, so this is an good match.
3025                         return true;
3026                     }
3027                     else
3028                     {
3029                         if (partial_in_demangled - demangled == 1)
3030                         {
3031                             // Only one character difference, can't be a namespace boundary...
3032                             return false;
3033                         }
3034                         else if (*(partial_in_demangled - 1) == ':' && *(partial_in_demangled - 2) == ':')
3035                         {
3036                             // We are on a namespace boundary, so this is also good.
3037                             return true;
3038                         }
3039                         else
3040                             return false;
3041                     }
3042                 }
3043             }
3044         }
3045     }
3046 
3047     return true;
3048 }
3049 
3050 uint32_t
3051 SymbolFileDWARF::FindFunctions (const ConstString &name,
3052                                 const lldb_private::ClangNamespaceDecl *namespace_decl,
3053                                 uint32_t name_type_mask,
3054                                 bool include_inlines,
3055                                 bool append,
3056                                 SymbolContextList& sc_list)
3057 {
3058     Timer scoped_timer (__PRETTY_FUNCTION__,
3059                         "SymbolFileDWARF::FindFunctions (name = '%s')",
3060                         name.AsCString());
3061 
3062     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3063 
3064     if (log)
3065     {
3066         GetObjectFile()->GetModule()->LogMessage (log.get(),
3067                                                   "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
3068                                                   name.GetCString(),
3069                                                   name_type_mask,
3070                                                   append);
3071     }
3072 
3073     // If we aren't appending the results to this list, then clear the list
3074     if (!append)
3075         sc_list.Clear();
3076 
3077     if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3078 		return 0;
3079 
3080     // If name is empty then we won't find anything.
3081     if (name.IsEmpty())
3082         return 0;
3083 
3084     // Remember how many sc_list are in the list before we search in case
3085     // we are appending the results to a variable list.
3086 
3087     const uint32_t original_size = sc_list.GetSize();
3088 
3089     const char *name_cstr = name.GetCString();
3090     uint32_t effective_name_type_mask = eFunctionNameTypeNone;
3091     const char *base_name_start = name_cstr;
3092     const char *base_name_end = name_cstr + strlen(name_cstr);
3093 
3094     if (name_type_mask & eFunctionNameTypeAuto)
3095     {
3096         if (CPPLanguageRuntime::IsCPPMangledName (name_cstr))
3097             effective_name_type_mask = eFunctionNameTypeFull;
3098         else if (ObjCLanguageRuntime::IsPossibleObjCMethodName (name_cstr))
3099             effective_name_type_mask = eFunctionNameTypeFull;
3100         else
3101         {
3102             if (ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3103                 effective_name_type_mask |= eFunctionNameTypeSelector;
3104 
3105             if (CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3106                 effective_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
3107         }
3108     }
3109     else
3110     {
3111         effective_name_type_mask = name_type_mask;
3112         if (effective_name_type_mask & eFunctionNameTypeMethod || name_type_mask & eFunctionNameTypeBase)
3113         {
3114             // If they've asked for a CPP method or function name and it can't be that, we don't
3115             // even need to search for CPP methods or names.
3116             if (!CPPLanguageRuntime::IsPossibleCPPCall(name_cstr, base_name_start, base_name_end))
3117             {
3118                 effective_name_type_mask &= ~(eFunctionNameTypeMethod | eFunctionNameTypeBase);
3119                 if (effective_name_type_mask == eFunctionNameTypeNone)
3120                     return 0;
3121             }
3122         }
3123 
3124         if (effective_name_type_mask & eFunctionNameTypeSelector)
3125         {
3126             if (!ObjCLanguageRuntime::IsPossibleObjCSelector(name_cstr))
3127             {
3128                 effective_name_type_mask &= ~(eFunctionNameTypeSelector);
3129                 if (effective_name_type_mask == eFunctionNameTypeNone)
3130                     return 0;
3131             }
3132         }
3133     }
3134 
3135     DWARFDebugInfo* info = DebugInfo();
3136     if (info == NULL)
3137         return 0;
3138 
3139     DWARFCompileUnit *dwarf_cu = NULL;
3140     if (m_using_apple_tables)
3141     {
3142         if (m_apple_names_ap.get())
3143         {
3144 
3145             DIEArray die_offsets;
3146 
3147             uint32_t num_matches = 0;
3148 
3149             if (effective_name_type_mask & eFunctionNameTypeFull)
3150             {
3151                 // If they asked for the full name, match what they typed.  At some point we may
3152                 // want to canonicalize this (strip double spaces, etc.  For now, we just add all the
3153                 // dies that we find by exact match.
3154                 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3155                 for (uint32_t i = 0; i < num_matches; i++)
3156                 {
3157                     const dw_offset_t die_offset = die_offsets[i];
3158                     const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3159                     if (die)
3160                     {
3161                         if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3162                             continue;
3163 
3164                         if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3165                             continue;
3166 
3167                         ResolveFunction (dwarf_cu, die, sc_list);
3168                     }
3169                     else
3170                     {
3171                         GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3172                                                                                    die_offset, name_cstr);
3173                     }
3174                 }
3175             }
3176             else
3177             {
3178                 if (effective_name_type_mask & eFunctionNameTypeSelector)
3179                 {
3180                     if (namespace_decl && *namespace_decl)
3181                         return 0; // no selectors in namespaces
3182 
3183                     num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
3184                     // Now make sure these are actually ObjC methods.  In this case we can simply look up the name,
3185                     // and if it is an ObjC method name, we're good.
3186 
3187                     for (uint32_t i = 0; i < num_matches; i++)
3188                     {
3189                         const dw_offset_t die_offset = die_offsets[i];
3190                         const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3191                         if (die)
3192                         {
3193                             const char *die_name = die->GetName(this, dwarf_cu);
3194                             if (ObjCLanguageRuntime::IsPossibleObjCMethodName(die_name))
3195                             {
3196                                 if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3197                                     continue;
3198 
3199                                 ResolveFunction (dwarf_cu, die, sc_list);
3200                             }
3201                         }
3202                         else
3203                         {
3204                             GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3205                                                                        die_offset, name_cstr);
3206                         }
3207                     }
3208                     die_offsets.clear();
3209                 }
3210 
3211                 if (effective_name_type_mask & eFunctionNameTypeMethod
3212                     || effective_name_type_mask & eFunctionNameTypeBase)
3213                 {
3214                     if ((effective_name_type_mask & eFunctionNameTypeMethod) &&
3215                         (namespace_decl && *namespace_decl))
3216                         return 0; // no methods in namespaces
3217 
3218                     // The apple_names table stores just the "base name" of C++ methods in the table.  So we have to
3219                     // extract the base name, look that up, and if there is any other information in the name we were
3220                     // passed in we have to post-filter based on that.
3221 
3222                     // FIXME: Arrange the logic above so that we don't calculate the base name twice:
3223                     std::string base_name(base_name_start, base_name_end - base_name_start);
3224                     num_matches = m_apple_names_ap->FindByName (base_name.c_str(), die_offsets);
3225 
3226                     for (uint32_t i = 0; i < num_matches; i++)
3227                     {
3228                         const dw_offset_t die_offset = die_offsets[i];
3229                         const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3230                         if (die)
3231                         {
3232                             if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3233                                 continue;
3234 
3235                             if (!FunctionDieMatchesPartialName(die,
3236                                                                dwarf_cu,
3237                                                                effective_name_type_mask,
3238                                                                name_cstr,
3239                                                                base_name_start,
3240                                                                base_name_end))
3241                                 continue;
3242 
3243                             if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3244                                 continue;
3245 
3246                             // If we get to here, the die is good, and we should add it:
3247                             ResolveFunction (dwarf_cu, die, sc_list);
3248                         }
3249                         else
3250                         {
3251                             GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
3252                                                                                        die_offset, name_cstr);
3253                         }
3254                     }
3255                     die_offsets.clear();
3256                 }
3257             }
3258         }
3259     }
3260     else
3261     {
3262 
3263         // Index the DWARF if we haven't already
3264         if (!m_indexed)
3265             Index ();
3266 
3267         if (name_type_mask & eFunctionNameTypeFull)
3268             FindFunctions (name, m_function_fullname_index, sc_list);
3269 
3270         std::string base_name(base_name_start, base_name_end - base_name_start);
3271         ConstString base_name_const(base_name.c_str());
3272         DIEArray die_offsets;
3273         DWARFCompileUnit *dwarf_cu = NULL;
3274 
3275         if (effective_name_type_mask & eFunctionNameTypeBase)
3276         {
3277             uint32_t num_base = m_function_basename_index.Find(base_name_const, die_offsets);
3278             for (uint32_t i = 0; i < num_base; i++)
3279             {
3280                 const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3281                 if (die)
3282                 {
3283                     if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3284                         continue;
3285 
3286                     if (!FunctionDieMatchesPartialName(die,
3287                                                        dwarf_cu,
3288                                                        effective_name_type_mask,
3289                                                        name_cstr,
3290                                                        base_name_start,
3291                                                        base_name_end))
3292                         continue;
3293 
3294                     if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3295                         continue;
3296 
3297                     // If we get to here, the die is good, and we should add it:
3298                     ResolveFunction (dwarf_cu, die, sc_list);
3299                 }
3300             }
3301             die_offsets.clear();
3302         }
3303 
3304         if (effective_name_type_mask & eFunctionNameTypeMethod)
3305         {
3306             if (namespace_decl && *namespace_decl)
3307                 return 0; // no methods in namespaces
3308 
3309             uint32_t num_base = m_function_method_index.Find(base_name_const, die_offsets);
3310             {
3311                 for (uint32_t i = 0; i < num_base; i++)
3312                 {
3313                     const DWARFDebugInfoEntry* die = info->GetDIEPtrWithCompileUnitHint (die_offsets[i], &dwarf_cu);
3314                     if (die)
3315                     {
3316                         if (!FunctionDieMatchesPartialName(die,
3317                                                            dwarf_cu,
3318                                                            effective_name_type_mask,
3319                                                            name_cstr,
3320                                                            base_name_start,
3321                                                            base_name_end))
3322                             continue;
3323 
3324                         if (!include_inlines && die->Tag() == DW_TAG_inlined_subroutine)
3325                             continue;
3326 
3327                         // If we get to here, the die is good, and we should add it:
3328                         ResolveFunction (dwarf_cu, die, sc_list);
3329                     }
3330                 }
3331             }
3332             die_offsets.clear();
3333         }
3334 
3335         if ((effective_name_type_mask & eFunctionNameTypeSelector) && (!namespace_decl || !*namespace_decl))
3336         {
3337             FindFunctions (name, m_function_selector_index, sc_list);
3338         }
3339 
3340     }
3341 
3342     // Return the number of variable that were appended to the list
3343     return sc_list.GetSize() - original_size;
3344 }
3345 
3346 uint32_t
3347 SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
3348 {
3349     Timer scoped_timer (__PRETTY_FUNCTION__,
3350                         "SymbolFileDWARF::FindFunctions (regex = '%s')",
3351                         regex.GetText());
3352 
3353     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3354 
3355     if (log)
3356     {
3357         GetObjectFile()->GetModule()->LogMessage (log.get(),
3358                                                   "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
3359                                                   regex.GetText(),
3360                                                   append);
3361     }
3362 
3363 
3364     // If we aren't appending the results to this list, then clear the list
3365     if (!append)
3366         sc_list.Clear();
3367 
3368     // Remember how many sc_list are in the list before we search in case
3369     // we are appending the results to a variable list.
3370     uint32_t original_size = sc_list.GetSize();
3371 
3372     if (m_using_apple_tables)
3373     {
3374         if (m_apple_names_ap.get())
3375             FindFunctions (regex, *m_apple_names_ap, sc_list);
3376     }
3377     else
3378     {
3379         // Index the DWARF if we haven't already
3380         if (!m_indexed)
3381             Index ();
3382 
3383         FindFunctions (regex, m_function_basename_index, sc_list);
3384 
3385         FindFunctions (regex, m_function_fullname_index, sc_list);
3386     }
3387 
3388     // Return the number of variable that were appended to the list
3389     return sc_list.GetSize() - original_size;
3390 }
3391 
3392 uint32_t
3393 SymbolFileDWARF::FindTypes (const SymbolContext& sc,
3394                             const ConstString &name,
3395                             const lldb_private::ClangNamespaceDecl *namespace_decl,
3396                             bool append,
3397                             uint32_t max_matches,
3398                             TypeList& types)
3399 {
3400     DWARFDebugInfo* info = DebugInfo();
3401     if (info == NULL)
3402         return 0;
3403 
3404     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3405 
3406     if (log)
3407     {
3408         GetObjectFile()->GetModule()->LogMessage (log.get(),
3409                                                   "SymbolFileDWARF::FindTypes (sc, name=\"%s\", append=%u, max_matches=%u, type_list)",
3410                                                   name.GetCString(),
3411                                                   append,
3412                                                   max_matches);
3413     }
3414 
3415     // If we aren't appending the results to this list, then clear the list
3416     if (!append)
3417         types.Clear();
3418 
3419     if (!NamespaceDeclMatchesThisSymbolFile(namespace_decl))
3420 		return 0;
3421 
3422     DIEArray die_offsets;
3423 
3424     if (m_using_apple_tables)
3425     {
3426         if (m_apple_types_ap.get())
3427         {
3428             const char *name_cstr = name.GetCString();
3429             m_apple_types_ap->FindByName (name_cstr, die_offsets);
3430         }
3431     }
3432     else
3433     {
3434         if (!m_indexed)
3435             Index ();
3436 
3437         m_type_index.Find (name, die_offsets);
3438     }
3439 
3440     const size_t num_matches = die_offsets.size();
3441 
3442     if (num_matches)
3443     {
3444         const uint32_t initial_types_size = types.GetSize();
3445         DWARFCompileUnit* dwarf_cu = NULL;
3446         const DWARFDebugInfoEntry* die = NULL;
3447         DWARFDebugInfo* debug_info = DebugInfo();
3448         for (size_t i=0; i<num_matches; ++i)
3449         {
3450             const dw_offset_t die_offset = die_offsets[i];
3451             die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3452 
3453             if (die)
3454             {
3455                 if (namespace_decl && !DIEIsInNamespace (namespace_decl, dwarf_cu, die))
3456                     continue;
3457 
3458                 Type *matching_type = ResolveType (dwarf_cu, die);
3459                 if (matching_type)
3460                 {
3461                     // We found a type pointer, now find the shared pointer form our type list
3462                     types.InsertUnique (matching_type->shared_from_this());
3463                     if (types.GetSize() >= max_matches)
3464                         break;
3465                 }
3466             }
3467             else
3468             {
3469                 if (m_using_apple_tables)
3470                 {
3471                     GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3472                                                                                die_offset, name.GetCString());
3473                 }
3474             }
3475 
3476         }
3477         return types.GetSize() - initial_types_size;
3478     }
3479     return 0;
3480 }
3481 
3482 
3483 ClangNamespaceDecl
3484 SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
3485                                 const ConstString &name,
3486                                 const lldb_private::ClangNamespaceDecl *parent_namespace_decl)
3487 {
3488     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3489 
3490     if (log)
3491     {
3492         GetObjectFile()->GetModule()->LogMessage (log.get(),
3493                                                   "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3494                                                   name.GetCString());
3495     }
3496 
3497     if (!NamespaceDeclMatchesThisSymbolFile(parent_namespace_decl))
3498 		return ClangNamespaceDecl();
3499 
3500     ClangNamespaceDecl namespace_decl;
3501     DWARFDebugInfo* info = DebugInfo();
3502     if (info)
3503     {
3504         DIEArray die_offsets;
3505 
3506         // Index if we already haven't to make sure the compile units
3507         // get indexed and make their global DIE index list
3508         if (m_using_apple_tables)
3509         {
3510             if (m_apple_namespaces_ap.get())
3511             {
3512                 const char *name_cstr = name.GetCString();
3513                 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3514             }
3515         }
3516         else
3517         {
3518             if (!m_indexed)
3519                 Index ();
3520 
3521             m_namespace_index.Find (name, die_offsets);
3522         }
3523 
3524         DWARFCompileUnit* dwarf_cu = NULL;
3525         const DWARFDebugInfoEntry* die = NULL;
3526         const size_t num_matches = die_offsets.size();
3527         if (num_matches)
3528         {
3529             DWARFDebugInfo* debug_info = DebugInfo();
3530             for (size_t i=0; i<num_matches; ++i)
3531             {
3532                 const dw_offset_t die_offset = die_offsets[i];
3533                 die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
3534 
3535                 if (die)
3536                 {
3537                     if (parent_namespace_decl && !DIEIsInNamespace (parent_namespace_decl, dwarf_cu, die))
3538                         continue;
3539 
3540                     clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (dwarf_cu, die);
3541                     if (clang_namespace_decl)
3542                     {
3543                         namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
3544                         namespace_decl.SetNamespaceDecl (clang_namespace_decl);
3545                         break;
3546                     }
3547                 }
3548                 else
3549                 {
3550                     if (m_using_apple_tables)
3551                     {
3552                         GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3553                                                                    die_offset, name.GetCString());
3554                     }
3555                 }
3556 
3557             }
3558         }
3559     }
3560     return namespace_decl;
3561 }
3562 
3563 uint32_t
3564 SymbolFileDWARF::FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, TypeList& types)
3565 {
3566     // Remember how many sc_list are in the list before we search in case
3567     // we are appending the results to a variable list.
3568     uint32_t original_size = types.GetSize();
3569 
3570     const uint32_t num_die_offsets = die_offsets.size();
3571     // Parse all of the types we found from the pubtypes matches
3572     uint32_t i;
3573     uint32_t num_matches = 0;
3574     for (i = 0; i < num_die_offsets; ++i)
3575     {
3576         Type *matching_type = ResolveTypeUID (die_offsets[i]);
3577         if (matching_type)
3578         {
3579             // We found a type pointer, now find the shared pointer form our type list
3580             types.InsertUnique (matching_type->shared_from_this());
3581             ++num_matches;
3582             if (num_matches >= max_matches)
3583                 break;
3584         }
3585     }
3586 
3587     // Return the number of variable that were appended to the list
3588     return types.GetSize() - original_size;
3589 }
3590 
3591 
3592 size_t
3593 SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
3594                                        clang::DeclContext *containing_decl_ctx,
3595                                        DWARFCompileUnit* dwarf_cu,
3596                                        const DWARFDebugInfoEntry *parent_die,
3597                                        bool skip_artificial,
3598                                        bool &is_static,
3599                                        TypeList* type_list,
3600                                        std::vector<clang_type_t>& function_param_types,
3601                                        std::vector<clang::ParmVarDecl*>& function_param_decls,
3602                                        unsigned &type_quals,
3603                                        ClangASTContext::TemplateParameterInfos &template_param_infos)
3604 {
3605     if (parent_die == NULL)
3606         return 0;
3607 
3608     const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3609 
3610     size_t arg_idx = 0;
3611     const DWARFDebugInfoEntry *die;
3612     for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3613     {
3614         dw_tag_t tag = die->Tag();
3615         switch (tag)
3616         {
3617         case DW_TAG_formal_parameter:
3618             {
3619                 DWARFDebugInfoEntry::Attributes attributes;
3620                 const size_t num_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
3621                 if (num_attributes > 0)
3622                 {
3623                     const char *name = NULL;
3624                     Declaration decl;
3625                     dw_offset_t param_type_die_offset = DW_INVALID_OFFSET;
3626                     bool is_artificial = false;
3627                     // one of None, Auto, Register, Extern, Static, PrivateExtern
3628 
3629                     clang::StorageClass storage = clang::SC_None;
3630                     uint32_t i;
3631                     for (i=0; i<num_attributes; ++i)
3632                     {
3633                         const dw_attr_t attr = attributes.AttributeAtIndex(i);
3634                         DWARFFormValue form_value;
3635                         if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3636                         {
3637                             switch (attr)
3638                             {
3639                             case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3640                             case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
3641                             case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3642                             case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break;
3643                             case DW_AT_type:        param_type_die_offset = form_value.Reference(dwarf_cu); break;
3644                             case DW_AT_artificial:  is_artificial = form_value.Unsigned() != 0; break;
3645                             case DW_AT_location:
3646     //                          if (form_value.BlockData())
3647     //                          {
3648     //                              const DataExtractor& debug_info_data = debug_info();
3649     //                              uint32_t block_length = form_value.Unsigned();
3650     //                              DataExtractor location(debug_info_data, form_value.BlockData() - debug_info_data.GetDataStart(), block_length);
3651     //                          }
3652     //                          else
3653     //                          {
3654     //                          }
3655     //                          break;
3656                             case DW_AT_const_value:
3657                             case DW_AT_default_value:
3658                             case DW_AT_description:
3659                             case DW_AT_endianity:
3660                             case DW_AT_is_optional:
3661                             case DW_AT_segment:
3662                             case DW_AT_variable_parameter:
3663                             default:
3664                             case DW_AT_abstract_origin:
3665                             case DW_AT_sibling:
3666                                 break;
3667                             }
3668                         }
3669                     }
3670 
3671                     bool skip = false;
3672                     if (skip_artificial)
3673                     {
3674                         if (is_artificial)
3675                         {
3676                             // In order to determine if a C++ member function is
3677                             // "const" we have to look at the const-ness of "this"...
3678                             // Ugly, but that
3679                             if (arg_idx == 0)
3680                             {
3681                                 if (DeclKindIsCXXClass(containing_decl_ctx->getDeclKind()))
3682                                 {
3683                                     // Often times compilers omit the "this" name for the
3684                                     // specification DIEs, so we can't rely upon the name
3685                                     // being in the formal parameter DIE...
3686                                     if (name == NULL || ::strcmp(name, "this")==0)
3687                                     {
3688                                         Type *this_type = ResolveTypeUID (param_type_die_offset);
3689                                         if (this_type)
3690                                         {
3691                                             uint32_t encoding_mask = this_type->GetEncodingMask();
3692                                             if (encoding_mask & Type::eEncodingIsPointerUID)
3693                                             {
3694                                                 is_static = false;
3695 
3696                                                 if (encoding_mask & (1u << Type::eEncodingIsConstUID))
3697                                                     type_quals |= clang::Qualifiers::Const;
3698                                                 if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
3699                                                     type_quals |= clang::Qualifiers::Volatile;
3700                                             }
3701                                         }
3702                                     }
3703                                 }
3704                             }
3705                             skip = true;
3706                         }
3707                         else
3708                         {
3709 
3710                             // HACK: Objective C formal parameters "self" and "_cmd"
3711                             // are not marked as artificial in the DWARF...
3712                             CompileUnit *comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, UINT32_MAX);
3713                             if (comp_unit)
3714                             {
3715                                 switch (comp_unit->GetLanguage())
3716                                 {
3717                                     case eLanguageTypeObjC:
3718                                     case eLanguageTypeObjC_plus_plus:
3719                                         if (name && name[0] && (strcmp (name, "self") == 0 || strcmp (name, "_cmd") == 0))
3720                                             skip = true;
3721                                         break;
3722                                     default:
3723                                         break;
3724                                 }
3725                             }
3726                         }
3727                     }
3728 
3729                     if (!skip)
3730                     {
3731                         Type *type = ResolveTypeUID(param_type_die_offset);
3732                         if (type)
3733                         {
3734                             function_param_types.push_back (type->GetClangForwardType());
3735 
3736                             clang::ParmVarDecl *param_var_decl = GetClangASTContext().CreateParameterDeclaration (name,
3737                                                                                                                   type->GetClangForwardType(),
3738                                                                                                                   storage);
3739                             assert(param_var_decl);
3740                             function_param_decls.push_back(param_var_decl);
3741                         }
3742                     }
3743                 }
3744                 arg_idx++;
3745             }
3746             break;
3747 
3748         case DW_TAG_template_type_parameter:
3749         case DW_TAG_template_value_parameter:
3750             ParseTemplateDIE (dwarf_cu, die,template_param_infos);
3751             break;
3752 
3753         default:
3754             break;
3755         }
3756     }
3757     return arg_idx;
3758 }
3759 
3760 size_t
3761 SymbolFileDWARF::ParseChildEnumerators
3762 (
3763     const SymbolContext& sc,
3764     clang_type_t  enumerator_clang_type,
3765     uint32_t enumerator_byte_size,
3766     DWARFCompileUnit* dwarf_cu,
3767     const DWARFDebugInfoEntry *parent_die
3768 )
3769 {
3770     if (parent_die == NULL)
3771         return 0;
3772 
3773     size_t enumerators_added = 0;
3774     const DWARFDebugInfoEntry *die;
3775     const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3776 
3777     for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3778     {
3779         const dw_tag_t tag = die->Tag();
3780         if (tag == DW_TAG_enumerator)
3781         {
3782             DWARFDebugInfoEntry::Attributes attributes;
3783             const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
3784             if (num_child_attributes > 0)
3785             {
3786                 const char *name = NULL;
3787                 bool got_value = false;
3788                 int64_t enum_value = 0;
3789                 Declaration decl;
3790 
3791                 uint32_t i;
3792                 for (i=0; i<num_child_attributes; ++i)
3793                 {
3794                     const dw_attr_t attr = attributes.AttributeAtIndex(i);
3795                     DWARFFormValue form_value;
3796                     if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3797                     {
3798                         switch (attr)
3799                         {
3800                         case DW_AT_const_value:
3801                             got_value = true;
3802                             enum_value = form_value.Unsigned();
3803                             break;
3804 
3805                         case DW_AT_name:
3806                             name = form_value.AsCString(&get_debug_str_data());
3807                             break;
3808 
3809                         case DW_AT_description:
3810                         default:
3811                         case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
3812                         case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
3813                         case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
3814                         case DW_AT_sibling:
3815                             break;
3816                         }
3817                     }
3818                 }
3819 
3820                 if (name && name[0] && got_value)
3821                 {
3822                     GetClangASTContext().AddEnumerationValueToEnumerationType (enumerator_clang_type,
3823                                                                                enumerator_clang_type,
3824                                                                                decl,
3825                                                                                name,
3826                                                                                enum_value,
3827                                                                                enumerator_byte_size * 8);
3828                     ++enumerators_added;
3829                 }
3830             }
3831         }
3832     }
3833     return enumerators_added;
3834 }
3835 
3836 void
3837 SymbolFileDWARF::ParseChildArrayInfo
3838 (
3839     const SymbolContext& sc,
3840     DWARFCompileUnit* dwarf_cu,
3841     const DWARFDebugInfoEntry *parent_die,
3842     int64_t& first_index,
3843     std::vector<uint64_t>& element_orders,
3844     uint32_t& byte_stride,
3845     uint32_t& bit_stride
3846 )
3847 {
3848     if (parent_die == NULL)
3849         return;
3850 
3851     const DWARFDebugInfoEntry *die;
3852     const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (dwarf_cu->GetAddressByteSize());
3853     for (die = parent_die->GetFirstChild(); die != NULL; die = die->GetSibling())
3854     {
3855         const dw_tag_t tag = die->Tag();
3856         switch (tag)
3857         {
3858         case DW_TAG_enumerator:
3859             {
3860                 DWARFDebugInfoEntry::Attributes attributes;
3861                 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
3862                 if (num_child_attributes > 0)
3863                 {
3864                     const char *name = NULL;
3865                     bool got_value = false;
3866                     int64_t enum_value = 0;
3867 
3868                     uint32_t i;
3869                     for (i=0; i<num_child_attributes; ++i)
3870                     {
3871                         const dw_attr_t attr = attributes.AttributeAtIndex(i);
3872                         DWARFFormValue form_value;
3873                         if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3874                         {
3875                             switch (attr)
3876                             {
3877                             case DW_AT_const_value:
3878                                 got_value = true;
3879                                 enum_value = form_value.Unsigned();
3880                                 break;
3881 
3882                             case DW_AT_name:
3883                                 name = form_value.AsCString(&get_debug_str_data());
3884                                 break;
3885 
3886                             case DW_AT_description:
3887                             default:
3888                             case DW_AT_decl_file:
3889                             case DW_AT_decl_line:
3890                             case DW_AT_decl_column:
3891                             case DW_AT_sibling:
3892                                 break;
3893                             }
3894                         }
3895                     }
3896                 }
3897             }
3898             break;
3899 
3900         case DW_TAG_subrange_type:
3901             {
3902                 DWARFDebugInfoEntry::Attributes attributes;
3903                 const size_t num_child_attributes = die->GetAttributes(this, dwarf_cu, fixed_form_sizes, attributes);
3904                 if (num_child_attributes > 0)
3905                 {
3906                     const char *name = NULL;
3907                     bool got_value = false;
3908                     uint64_t byte_size = 0;
3909                     int64_t enum_value = 0;
3910                     uint64_t num_elements = 0;
3911                     uint64_t lower_bound = 0;
3912                     uint64_t upper_bound = 0;
3913                     uint32_t i;
3914                     for (i=0; i<num_child_attributes; ++i)
3915                     {
3916                         const dw_attr_t attr = attributes.AttributeAtIndex(i);
3917                         DWARFFormValue form_value;
3918                         if (attributes.ExtractFormValueAtIndex(this, i, form_value))
3919                         {
3920                             switch (attr)
3921                             {
3922                             case DW_AT_const_value:
3923                                 got_value = true;
3924                                 enum_value = form_value.Unsigned();
3925                                 break;
3926 
3927                             case DW_AT_name:
3928                                 name = form_value.AsCString(&get_debug_str_data());
3929                                 break;
3930 
3931                             case DW_AT_count:
3932                                 num_elements = form_value.Unsigned();
3933                                 break;
3934 
3935                             case DW_AT_bit_stride:
3936                                 bit_stride = form_value.Unsigned();
3937                                 break;
3938 
3939                             case DW_AT_byte_stride:
3940                                 byte_stride = form_value.Unsigned();
3941                                 break;
3942 
3943                             case DW_AT_byte_size:
3944                                 byte_size = form_value.Unsigned();
3945                                 break;
3946 
3947                             case DW_AT_lower_bound:
3948                                 lower_bound = form_value.Unsigned();
3949                                 break;
3950 
3951                             case DW_AT_upper_bound:
3952                                 upper_bound = form_value.Unsigned();
3953                                 break;
3954 
3955                             default:
3956                             case DW_AT_abstract_origin:
3957                             case DW_AT_accessibility:
3958                             case DW_AT_allocated:
3959                             case DW_AT_associated:
3960                             case DW_AT_data_location:
3961                             case DW_AT_declaration:
3962                             case DW_AT_description:
3963                             case DW_AT_sibling:
3964                             case DW_AT_threads_scaled:
3965                             case DW_AT_type:
3966                             case DW_AT_visibility:
3967                                 break;
3968                             }
3969                         }
3970                     }
3971 
3972                     if (upper_bound > lower_bound)
3973                         num_elements = upper_bound - lower_bound + 1;
3974 
3975                     if (num_elements > 0)
3976                         element_orders.push_back (num_elements);
3977                 }
3978             }
3979             break;
3980         }
3981     }
3982 }
3983 
3984 TypeSP
3985 SymbolFileDWARF::GetTypeForDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry* die)
3986 {
3987     TypeSP type_sp;
3988     if (die != NULL)
3989     {
3990         assert(dwarf_cu != NULL);
3991         Type *type_ptr = m_die_to_type.lookup (die);
3992         if (type_ptr == NULL)
3993         {
3994             CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(dwarf_cu);
3995             assert (lldb_cu);
3996             SymbolContext sc(lldb_cu);
3997             type_sp = ParseType(sc, dwarf_cu, die, NULL);
3998         }
3999         else if (type_ptr != DIE_IS_BEING_PARSED)
4000         {
4001             // Grab the existing type from the master types lists
4002             type_sp = type_ptr->shared_from_this();
4003         }
4004 
4005     }
4006     return type_sp;
4007 }
4008 
4009 clang::DeclContext *
4010 SymbolFileDWARF::GetClangDeclContextContainingDIEOffset (dw_offset_t die_offset)
4011 {
4012     if (die_offset != DW_INVALID_OFFSET)
4013     {
4014         DWARFCompileUnitSP cu_sp;
4015         const DWARFDebugInfoEntry* die = DebugInfo()->GetDIEPtr(die_offset, &cu_sp);
4016         return GetClangDeclContextContainingDIE (cu_sp.get(), die, NULL);
4017     }
4018     return NULL;
4019 }
4020 
4021 clang::DeclContext *
4022 SymbolFileDWARF::GetClangDeclContextForDIEOffset (const SymbolContext &sc, dw_offset_t die_offset)
4023 {
4024     if (die_offset != DW_INVALID_OFFSET)
4025     {
4026         DWARFDebugInfo* debug_info = DebugInfo();
4027         if (debug_info)
4028         {
4029             DWARFCompileUnitSP cu_sp;
4030             const DWARFDebugInfoEntry* die = debug_info->GetDIEPtr(die_offset, &cu_sp);
4031             if (die)
4032                 return GetClangDeclContextForDIE (sc, cu_sp.get(), die);
4033         }
4034     }
4035     return NULL;
4036 }
4037 
4038 clang::NamespaceDecl *
4039 SymbolFileDWARF::ResolveNamespaceDIE (DWARFCompileUnit *dwarf_cu, const DWARFDebugInfoEntry *die)
4040 {
4041     if (die && die->Tag() == DW_TAG_namespace)
4042     {
4043         // See if we already parsed this namespace DIE and associated it with a
4044         // uniqued namespace declaration
4045         clang::NamespaceDecl *namespace_decl = static_cast<clang::NamespaceDecl *>(m_die_to_decl_ctx[die]);
4046         if (namespace_decl)
4047             return namespace_decl;
4048         else
4049         {
4050             const char *namespace_name = die->GetAttributeValueAsString(this, dwarf_cu, DW_AT_name, NULL);
4051             clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, NULL);
4052             namespace_decl = GetClangASTContext().GetUniqueNamespaceDeclaration (namespace_name, containing_decl_ctx);
4053             LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4054             if (log)
4055             {
4056                 if (namespace_name)
4057                 {
4058                     GetObjectFile()->GetModule()->LogMessage (log.get(),
4059                                                               "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace with DW_AT_name(\"%s\") => clang::NamespaceDecl *%p (original = %p)",
4060                                                               GetClangASTContext().getASTContext(),
4061                                                               MakeUserID(die->GetOffset()),
4062                                                               namespace_name,
4063                                                               namespace_decl,
4064                                                               namespace_decl->getOriginalNamespace());
4065                 }
4066                 else
4067                 {
4068                     GetObjectFile()->GetModule()->LogMessage (log.get(),
4069                                                               "ASTContext => %p: 0x%8.8llx: DW_TAG_namespace (anonymous) => clang::NamespaceDecl *%p (original = %p)",
4070                                                               GetClangASTContext().getASTContext(),
4071                                                               MakeUserID(die->GetOffset()),
4072                                                               namespace_decl,
4073                                                               namespace_decl->getOriginalNamespace());
4074                 }
4075             }
4076 
4077             if (namespace_decl)
4078                 LinkDeclContextToDIE((clang::DeclContext*)namespace_decl, die);
4079             return namespace_decl;
4080         }
4081     }
4082     return NULL;
4083 }
4084 
4085 clang::DeclContext *
4086 SymbolFileDWARF::GetClangDeclContextForDIE (const SymbolContext &sc, DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4087 {
4088     clang::DeclContext *clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4089     if (clang_decl_ctx)
4090         return clang_decl_ctx;
4091     // If this DIE has a specification, or an abstract origin, then trace to those.
4092 
4093     dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4094     if (die_offset != DW_INVALID_OFFSET)
4095         return GetClangDeclContextForDIEOffset (sc, die_offset);
4096 
4097     die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4098     if (die_offset != DW_INVALID_OFFSET)
4099         return GetClangDeclContextForDIEOffset (sc, die_offset);
4100 
4101     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4102     if (log)
4103         GetObjectFile()->GetModule()->LogMessage(log.get(), "SymbolFileDWARF::GetClangDeclContextForDIE (die = 0x%8.8x) %s '%s'", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), die->GetName(this, cu));
4104     // This is the DIE we want.  Parse it, then query our map.
4105     bool assert_not_being_parsed = true;
4106     ResolveTypeUID (cu, die, assert_not_being_parsed);
4107 
4108     clang_decl_ctx = GetCachedClangDeclContextForDIE (die);
4109 
4110     return clang_decl_ctx;
4111 }
4112 
4113 clang::DeclContext *
4114 SymbolFileDWARF::GetClangDeclContextContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die, const DWARFDebugInfoEntry **decl_ctx_die_copy)
4115 {
4116     if (m_clang_tu_decl == NULL)
4117         m_clang_tu_decl = GetClangASTContext().getASTContext()->getTranslationUnitDecl();
4118 
4119     const DWARFDebugInfoEntry *decl_ctx_die = GetDeclContextDIEContainingDIE (cu, die);
4120 
4121     if (decl_ctx_die_copy)
4122         *decl_ctx_die_copy = decl_ctx_die;
4123 
4124     if (decl_ctx_die)
4125     {
4126 
4127         DIEToDeclContextMap::iterator pos = m_die_to_decl_ctx.find (decl_ctx_die);
4128         if (pos != m_die_to_decl_ctx.end())
4129             return pos->second;
4130 
4131         switch (decl_ctx_die->Tag())
4132         {
4133         case DW_TAG_compile_unit:
4134             return m_clang_tu_decl;
4135 
4136         case DW_TAG_namespace:
4137             return ResolveNamespaceDIE (cu, decl_ctx_die);
4138             break;
4139 
4140         case DW_TAG_structure_type:
4141         case DW_TAG_union_type:
4142         case DW_TAG_class_type:
4143             {
4144                 Type* type = ResolveType (cu, decl_ctx_die);
4145                 if (type)
4146                 {
4147                     clang::DeclContext *decl_ctx = ClangASTContext::GetDeclContextForType (type->GetClangForwardType ());
4148                     if (decl_ctx)
4149                     {
4150                         LinkDeclContextToDIE (decl_ctx, decl_ctx_die);
4151                         if (decl_ctx)
4152                             return decl_ctx;
4153                     }
4154                 }
4155             }
4156             break;
4157 
4158         default:
4159             break;
4160         }
4161     }
4162     return m_clang_tu_decl;
4163 }
4164 
4165 
4166 const DWARFDebugInfoEntry *
4167 SymbolFileDWARF::GetDeclContextDIEContainingDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die)
4168 {
4169     if (cu && die)
4170     {
4171         const DWARFDebugInfoEntry * const decl_die = die;
4172 
4173         while (die != NULL)
4174         {
4175             // If this is the original DIE that we are searching for a declaration
4176             // for, then don't look in the cache as we don't want our own decl
4177             // context to be our decl context...
4178             if (decl_die != die)
4179             {
4180                 switch (die->Tag())
4181                 {
4182                     case DW_TAG_compile_unit:
4183                     case DW_TAG_namespace:
4184                     case DW_TAG_structure_type:
4185                     case DW_TAG_union_type:
4186                     case DW_TAG_class_type:
4187                         return die;
4188 
4189                     default:
4190                         break;
4191                 }
4192             }
4193 
4194             dw_offset_t die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_specification, DW_INVALID_OFFSET);
4195             if (die_offset != DW_INVALID_OFFSET)
4196             {
4197                 DWARFCompileUnit *spec_cu = cu;
4198                 const DWARFDebugInfoEntry *spec_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &spec_cu);
4199                 const DWARFDebugInfoEntry *spec_die_decl_ctx_die = GetDeclContextDIEContainingDIE (spec_cu, spec_die);
4200                 if (spec_die_decl_ctx_die)
4201                     return spec_die_decl_ctx_die;
4202             }
4203 
4204             die_offset = die->GetAttributeValueAsReference(this, cu, DW_AT_abstract_origin, DW_INVALID_OFFSET);
4205             if (die_offset != DW_INVALID_OFFSET)
4206             {
4207                 DWARFCompileUnit *abs_cu = cu;
4208                 const DWARFDebugInfoEntry *abs_die = DebugInfo()->GetDIEPtrWithCompileUnitHint (die_offset, &abs_cu);
4209                 const DWARFDebugInfoEntry *abs_die_decl_ctx_die = GetDeclContextDIEContainingDIE (abs_cu, abs_die);
4210                 if (abs_die_decl_ctx_die)
4211                     return abs_die_decl_ctx_die;
4212             }
4213 
4214             die = die->GetParent();
4215         }
4216     }
4217     return NULL;
4218 }
4219 
4220 
4221 Symbol *
4222 SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
4223 {
4224     Symbol *objc_class_symbol = NULL;
4225     if (m_obj_file)
4226     {
4227         Symtab *symtab = m_obj_file->GetSymtab();
4228         if (symtab)
4229         {
4230             objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
4231                                                                         eSymbolTypeObjCClass,
4232                                                                         Symtab::eDebugNo,
4233                                                                         Symtab::eVisibilityAny);
4234         }
4235     }
4236     return objc_class_symbol;
4237 }
4238 
4239 // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
4240 // then we can end up looking through all class types for a complete type and never find
4241 // the full definition. We need to know if this attribute is supported, so we determine
4242 // this here and cache th result. We also need to worry about the debug map DWARF file
4243 // if we are doing darwin DWARF in .o file debugging.
4244 bool
4245 SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
4246 {
4247     if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
4248     {
4249         m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
4250         if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
4251             m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4252         else
4253         {
4254             DWARFDebugInfo* debug_info = DebugInfo();
4255             const uint32_t num_compile_units = GetNumCompileUnits();
4256             for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
4257             {
4258                 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
4259                 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
4260                 {
4261                     m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
4262                     break;
4263                 }
4264             }
4265         }
4266         if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && m_debug_map_symfile)
4267             return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
4268     }
4269     return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
4270 }
4271 
4272 // This function can be used when a DIE is found that is a forward declaration
4273 // DIE and we want to try and find a type that has the complete definition.
4274 TypeSP
4275 SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die,
4276                                                        const ConstString &type_name,
4277                                                        bool must_be_implementation)
4278 {
4279 
4280     TypeSP type_sp;
4281 
4282     if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
4283         return type_sp;
4284 
4285     DIEArray die_offsets;
4286 
4287     if (m_using_apple_tables)
4288     {
4289         if (m_apple_types_ap.get())
4290         {
4291             const char *name_cstr = type_name.GetCString();
4292             m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
4293         }
4294     }
4295     else
4296     {
4297         if (!m_indexed)
4298             Index ();
4299 
4300         m_type_index.Find (type_name, die_offsets);
4301     }
4302 
4303     const size_t num_matches = die_offsets.size();
4304 
4305     DWARFCompileUnit* type_cu = NULL;
4306     const DWARFDebugInfoEntry* type_die = NULL;
4307     if (num_matches)
4308     {
4309         DWARFDebugInfo* debug_info = DebugInfo();
4310         for (size_t i=0; i<num_matches; ++i)
4311         {
4312             const dw_offset_t die_offset = die_offsets[i];
4313             type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4314 
4315             if (type_die)
4316             {
4317                 bool try_resolving_type = false;
4318 
4319                 // Don't try and resolve the DIE we are looking for with the DIE itself!
4320                 if (type_die != die)
4321                 {
4322                     switch (type_die->Tag())
4323                     {
4324                         case DW_TAG_class_type:
4325                         case DW_TAG_structure_type:
4326                             try_resolving_type = true;
4327                             break;
4328                         default:
4329                             break;
4330                     }
4331                 }
4332 
4333                 if (try_resolving_type)
4334                 {
4335 					if (must_be_implementation && type_cu->Supports_DW_AT_APPLE_objc_complete_type())
4336 	                    try_resolving_type = type_die->GetAttributeValueAsUnsigned (this, type_cu, DW_AT_APPLE_objc_complete_type, 0);
4337 
4338                     if (try_resolving_type)
4339                     {
4340                         Type *resolved_type = ResolveType (type_cu, type_die, false);
4341                         if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4342                         {
4343                             DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4344                                           MakeUserID(die->GetOffset()),
4345                                           MakeUserID(dwarf_cu->GetOffset()),
4346                                           m_obj_file->GetFileSpec().GetFilename().AsCString(),
4347                                           MakeUserID(type_die->GetOffset()),
4348                                           MakeUserID(type_cu->GetOffset()));
4349 
4350                             if (die)
4351                                 m_die_to_type[die] = resolved_type;
4352                             type_sp = resolved_type->shared_from_this();
4353                             break;
4354                         }
4355                     }
4356                 }
4357             }
4358             else
4359             {
4360                 if (m_using_apple_tables)
4361                 {
4362                     GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4363                                                                die_offset, type_name.GetCString());
4364                 }
4365             }
4366 
4367         }
4368     }
4369     return type_sp;
4370 }
4371 
4372 //----------------------------------------------------------------------
4373 // This function helps to ensure that the declaration contexts match for
4374 // two different DIEs. Often times debug information will refer to a
4375 // forward declaration of a type (the equivalent of "struct my_struct;".
4376 // There will often be a declaration of that type elsewhere that has the
4377 // full definition. When we go looking for the full type "my_struct", we
4378 // will find one or more matches in the accelerator tables and we will
4379 // then need to make sure the type was in the same declaration context
4380 // as the original DIE. This function can efficiently compare two DIEs
4381 // and will return true when the declaration context matches, and false
4382 // when they don't.
4383 //----------------------------------------------------------------------
4384 bool
4385 SymbolFileDWARF::DIEDeclContextsMatch (DWARFCompileUnit* cu1, const DWARFDebugInfoEntry *die1,
4386                                        DWARFCompileUnit* cu2, const DWARFDebugInfoEntry *die2)
4387 {
4388     assert (die1 != die2);
4389     DWARFDIECollection decl_ctx_1;
4390     DWARFDIECollection decl_ctx_2;
4391     //The declaration DIE stack is a stack of the declaration context
4392     // DIEs all the way back to the compile unit. If a type "T" is
4393     // declared inside a class "B", and class "B" is declared inside
4394     // a class "A" and class "A" is in a namespace "lldb", and the
4395     // namespace is in a compile unit, there will be a stack of DIEs:
4396     //
4397     //   [0] DW_TAG_class_type for "B"
4398     //   [1] DW_TAG_class_type for "A"
4399     //   [2] DW_TAG_namespace  for "lldb"
4400     //   [3] DW_TAG_compile_unit for the source file.
4401     //
4402     // We grab both contexts and make sure that everything matches
4403     // all the way back to the compiler unit.
4404 
4405     // First lets grab the decl contexts for both DIEs
4406     die1->GetDeclContextDIEs (this, cu1, decl_ctx_1);
4407     die2->GetDeclContextDIEs (this, cu2, decl_ctx_2);
4408     // Make sure the context arrays have the same size, otherwise
4409     // we are done
4410     const size_t count1 = decl_ctx_1.Size();
4411     const size_t count2 = decl_ctx_2.Size();
4412     if (count1 != count2)
4413         return false;
4414 
4415     // Make sure the DW_TAG values match all the way back up the the
4416     // compile unit. If they don't, then we are done.
4417     const DWARFDebugInfoEntry *decl_ctx_die1;
4418     const DWARFDebugInfoEntry *decl_ctx_die2;
4419     size_t i;
4420     for (i=0; i<count1; i++)
4421     {
4422         decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4423         decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4424         if (decl_ctx_die1->Tag() != decl_ctx_die2->Tag())
4425             return false;
4426     }
4427 #if defined LLDB_CONFIGURATION_DEBUG
4428 
4429     // Make sure the top item in the decl context die array is always
4430     // DW_TAG_compile_unit. If it isn't then something went wrong in
4431     // the DWARFDebugInfoEntry::GetDeclContextDIEs() function...
4432     assert (decl_ctx_1.GetDIEPtrAtIndex (count1 - 1)->Tag() == DW_TAG_compile_unit);
4433 
4434 #endif
4435     // Always skip the compile unit when comparing by only iterating up to
4436     // "count - 1". Here we compare the names as we go.
4437     for (i=0; i<count1 - 1; i++)
4438     {
4439         decl_ctx_die1 = decl_ctx_1.GetDIEPtrAtIndex (i);
4440         decl_ctx_die2 = decl_ctx_2.GetDIEPtrAtIndex (i);
4441         const char *name1 = decl_ctx_die1->GetName(this, cu1);
4442         const char *name2 = decl_ctx_die2->GetName(this, cu2);
4443         // If the string was from a DW_FORM_strp, then the pointer will often
4444         // be the same!
4445         if (name1 == name2)
4446             continue;
4447 
4448         // Name pointers are not equal, so only compare the strings
4449         // if both are not NULL.
4450         if (name1 && name2)
4451         {
4452             // If the strings don't compare, we are done...
4453             if (strcmp(name1, name2) != 0)
4454                 return false;
4455         }
4456         else
4457         {
4458             // One name was NULL while the other wasn't
4459             return false;
4460         }
4461     }
4462     // We made it through all of the checks and the declaration contexts
4463     // are equal.
4464     return true;
4465 }
4466 
4467 // This function can be used when a DIE is found that is a forward declaration
4468 // DIE and we want to try and find a type that has the complete definition.
4469 TypeSP
4470 SymbolFileDWARF::FindDefinitionTypeForDIE (DWARFCompileUnit* cu,
4471                                            const DWARFDebugInfoEntry *die,
4472                                            const ConstString &type_name)
4473 {
4474     TypeSP type_sp;
4475 
4476     if (cu == NULL || die == NULL || !type_name)
4477         return type_sp;
4478 
4479     DIEArray die_offsets;
4480 
4481     if (m_using_apple_tables)
4482     {
4483         if (m_apple_types_ap.get())
4484         {
4485             if (m_apple_types_ap->GetHeader().header_data.atoms.size() > 1)
4486             {
4487                 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), die->Tag(), die_offsets);
4488             }
4489             else
4490             {
4491                 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
4492             }
4493         }
4494     }
4495     else
4496     {
4497         if (!m_indexed)
4498             Index ();
4499 
4500         m_type_index.Find (type_name, die_offsets);
4501     }
4502 
4503     const size_t num_matches = die_offsets.size();
4504 
4505     const dw_tag_t die_tag = die->Tag();
4506 
4507     DWARFCompileUnit* type_cu = NULL;
4508     const DWARFDebugInfoEntry* type_die = NULL;
4509     if (num_matches)
4510     {
4511         DWARFDebugInfo* debug_info = DebugInfo();
4512         for (size_t i=0; i<num_matches; ++i)
4513         {
4514             const dw_offset_t die_offset = die_offsets[i];
4515             type_die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &type_cu);
4516 
4517             if (type_die)
4518             {
4519                 bool try_resolving_type = false;
4520 
4521                 // Don't try and resolve the DIE we are looking for with the DIE itself!
4522                 if (type_die != die)
4523                 {
4524                     const dw_tag_t type_die_tag = type_die->Tag();
4525                     // Make sure the tags match
4526                     if (type_die_tag == die_tag)
4527                     {
4528                         // The tags match, lets try resolving this type
4529                         try_resolving_type = true;
4530                     }
4531                     else
4532                     {
4533                         // The tags don't match, but we need to watch our for a
4534                         // forward declaration for a struct and ("struct foo")
4535                         // ends up being a class ("class foo { ... };") or
4536                         // vice versa.
4537                         switch (type_die_tag)
4538                         {
4539                         case DW_TAG_class_type:
4540                             // We had a "class foo", see if we ended up with a "struct foo { ... };"
4541                             try_resolving_type = (die_tag == DW_TAG_structure_type);
4542                             break;
4543                         case DW_TAG_structure_type:
4544                             // We had a "struct foo", see if we ended up with a "class foo { ... };"
4545                             try_resolving_type = (die_tag == DW_TAG_class_type);
4546                             break;
4547                         default:
4548                             // Tags don't match, don't event try to resolve
4549                             // using this type whose name matches....
4550                             break;
4551                         }
4552                     }
4553                 }
4554 
4555                 if (try_resolving_type)
4556                 {
4557                     // Make sure the decl contexts match all the way up
4558                     if (DIEDeclContextsMatch(cu, die, type_cu, type_die))
4559                     {
4560                         Type *resolved_type = ResolveType (type_cu, type_die, false);
4561                         if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
4562                         {
4563                             DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
4564                                           MakeUserID(die->GetOffset()),
4565                                           MakeUserID(dwarf_cu->GetOffset()),
4566                                           m_obj_file->GetFileSpec().GetFilename().AsCString(),
4567                                           MakeUserID(type_die->GetOffset()),
4568                                           MakeUserID(type_cu->GetOffset()));
4569 
4570                             m_die_to_type[die] = resolved_type;
4571                             type_sp = resolved_type->shared_from_this();
4572                             break;
4573                         }
4574                     }
4575                 }
4576             }
4577             else
4578             {
4579                 if (m_using_apple_tables)
4580                 {
4581                     GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
4582                                                                                die_offset, type_name.GetCString());
4583                 }
4584             }
4585 
4586         }
4587     }
4588     return type_sp;
4589 }
4590 
4591 TypeSP
4592 SymbolFileDWARF::ParseType (const SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new_ptr)
4593 {
4594     TypeSP type_sp;
4595 
4596     if (type_is_new_ptr)
4597         *type_is_new_ptr = false;
4598 
4599 #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
4600     static DIEStack g_die_stack;
4601     DIEStack::ScopedPopper scoped_die_logger(g_die_stack);
4602 #endif
4603 
4604     AccessType accessibility = eAccessNone;
4605     if (die != NULL)
4606     {
4607         LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4608         if (log)
4609         {
4610             const DWARFDebugInfoEntry *context_die;
4611             clang::DeclContext *context = GetClangDeclContextContainingDIE (dwarf_cu, die, &context_die);
4612 
4613             GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x, decl_ctx = %p (die 0x%8.8x)) %s name = '%s')",
4614                         die->GetOffset(),
4615                         context,
4616                         context_die->GetOffset(),
4617                         DW_TAG_value_to_name(die->Tag()),
4618                         die->GetName(this, dwarf_cu));
4619 
4620 #if defined(LLDB_CONFIGURATION_DEBUG) or defined(LLDB_CONFIGURATION_RELEASE)
4621             scoped_die_logger.Push (dwarf_cu, die);
4622             g_die_stack.LogDIEs(log.get(), this);
4623 #endif
4624         }
4625 //
4626 //        LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
4627 //        if (log && dwarf_cu)
4628 //        {
4629 //            StreamString s;
4630 //            die->DumpLocation (this, dwarf_cu, s);
4631 //            GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDwarf::%s %s", __FUNCTION__, s.GetData());
4632 //
4633 //        }
4634 
4635         Type *type_ptr = m_die_to_type.lookup (die);
4636         TypeList* type_list = GetTypeList();
4637         if (type_ptr == NULL)
4638         {
4639             ClangASTContext &ast = GetClangASTContext();
4640             if (type_is_new_ptr)
4641                 *type_is_new_ptr = true;
4642 
4643             const dw_tag_t tag = die->Tag();
4644 
4645             bool is_forward_declaration = false;
4646             DWARFDebugInfoEntry::Attributes attributes;
4647             const char *type_name_cstr = NULL;
4648             ConstString type_name_const_str;
4649             Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
4650             size_t byte_size = 0;
4651             bool byte_size_valid = false;
4652             Declaration decl;
4653 
4654             Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
4655             clang_type_t clang_type = NULL;
4656 
4657             dw_attr_t attr;
4658 
4659             switch (tag)
4660             {
4661             case DW_TAG_base_type:
4662             case DW_TAG_pointer_type:
4663             case DW_TAG_reference_type:
4664             case DW_TAG_typedef:
4665             case DW_TAG_const_type:
4666             case DW_TAG_restrict_type:
4667             case DW_TAG_volatile_type:
4668             case DW_TAG_unspecified_type:
4669                 {
4670                     // Set a bit that lets us know that we are currently parsing this
4671                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
4672 
4673                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
4674                     uint32_t encoding = 0;
4675                     lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
4676 
4677                     if (num_attributes > 0)
4678                     {
4679                         uint32_t i;
4680                         for (i=0; i<num_attributes; ++i)
4681                         {
4682                             attr = attributes.AttributeAtIndex(i);
4683                             DWARFFormValue form_value;
4684                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4685                             {
4686                                 switch (attr)
4687                                 {
4688                                 case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4689                                 case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
4690                                 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4691                                 case DW_AT_name:
4692 
4693                                     type_name_cstr = form_value.AsCString(&get_debug_str_data());
4694                                     // Work around a bug in llvm-gcc where they give a name to a reference type which doesn't
4695                                     // include the "&"...
4696                                     if (tag == DW_TAG_reference_type)
4697                                     {
4698                                         if (strchr (type_name_cstr, '&') == NULL)
4699                                             type_name_cstr = NULL;
4700                                     }
4701                                     if (type_name_cstr)
4702                                         type_name_const_str.SetCString(type_name_cstr);
4703                                     break;
4704                                 case DW_AT_byte_size:   byte_size = form_value.Unsigned();  byte_size_valid = true; break;
4705                                 case DW_AT_encoding:    encoding = form_value.Unsigned(); break;
4706                                 case DW_AT_type:        encoding_uid = form_value.Reference(dwarf_cu); break;
4707                                 default:
4708                                 case DW_AT_sibling:
4709                                     break;
4710                                 }
4711                             }
4712                         }
4713                     }
4714 
4715                     DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\") type => 0x%8.8x\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr, encoding_uid);
4716 
4717                     switch (tag)
4718                     {
4719                     default:
4720                         break;
4721 
4722                     case DW_TAG_unspecified_type:
4723                         if (strcmp(type_name_cstr, "nullptr_t") == 0)
4724                         {
4725                             resolve_state = Type::eResolveStateFull;
4726                             clang_type = ast.getASTContext()->NullPtrTy.getAsOpaquePtr();
4727                             break;
4728                         }
4729                         // Fall through to base type below in case we can handle the type there...
4730 
4731                     case DW_TAG_base_type:
4732                         resolve_state = Type::eResolveStateFull;
4733                         clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr,
4734                                                                                    encoding,
4735                                                                                    byte_size * 8);
4736                         break;
4737 
4738                     case DW_TAG_pointer_type:   encoding_data_type = Type::eEncodingIsPointerUID;           break;
4739                     case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID;   break;
4740                     case DW_TAG_typedef:        encoding_data_type = Type::eEncodingIsTypedefUID;           break;
4741                     case DW_TAG_const_type:     encoding_data_type = Type::eEncodingIsConstUID;             break;
4742                     case DW_TAG_restrict_type:  encoding_data_type = Type::eEncodingIsRestrictUID;          break;
4743                     case DW_TAG_volatile_type:  encoding_data_type = Type::eEncodingIsVolatileUID;          break;
4744                     }
4745 
4746                     if (clang_type == NULL && (encoding_data_type == Type::eEncodingIsPointerUID || encoding_data_type == Type::eEncodingIsTypedefUID))
4747                     {
4748                         if (type_name_cstr != NULL && sc.comp_unit != NULL &&
4749                             (sc.comp_unit->GetLanguage() == eLanguageTypeObjC || sc.comp_unit->GetLanguage() == eLanguageTypeObjC_plus_plus))
4750                         {
4751                             static ConstString g_objc_type_name_id("id");
4752                             static ConstString g_objc_type_name_Class("Class");
4753                             static ConstString g_objc_type_name_selector("SEL");
4754 
4755                             if (type_name_const_str == g_objc_type_name_id)
4756                             {
4757                                 if (log)
4758                                     GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'id' built-in type.",
4759                                                                               die->GetOffset(),
4760                                                                               DW_TAG_value_to_name(die->Tag()),
4761                                                                               die->GetName(this, dwarf_cu));
4762                                 clang_type = ast.GetBuiltInType_objc_id();
4763                                 encoding_data_type = Type::eEncodingIsUID;
4764                                 encoding_uid = LLDB_INVALID_UID;
4765                                 resolve_state = Type::eResolveStateFull;
4766 
4767                             }
4768                             else if (type_name_const_str == g_objc_type_name_Class)
4769                             {
4770                                 if (log)
4771                                     GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'Class' built-in type.",
4772                                                                               die->GetOffset(),
4773                                                                               DW_TAG_value_to_name(die->Tag()),
4774                                                                               die->GetName(this, dwarf_cu));
4775                                 clang_type = ast.GetBuiltInType_objc_Class();
4776                                 encoding_data_type = Type::eEncodingIsUID;
4777                                 encoding_uid = LLDB_INVALID_UID;
4778                                 resolve_state = Type::eResolveStateFull;
4779                             }
4780                             else if (type_name_const_str == g_objc_type_name_selector)
4781                             {
4782                                 if (log)
4783                                     GetObjectFile()->GetModule()->LogMessage (log.get(), "SymbolFileDWARF::ParseType (die = 0x%8.8x) %s '%s' is Objective C 'selector' built-in type.",
4784                                                                               die->GetOffset(),
4785                                                                               DW_TAG_value_to_name(die->Tag()),
4786                                                                               die->GetName(this, dwarf_cu));
4787                                 clang_type = ast.GetBuiltInType_objc_selector();
4788                                 encoding_data_type = Type::eEncodingIsUID;
4789                                 encoding_uid = LLDB_INVALID_UID;
4790                                 resolve_state = Type::eResolveStateFull;
4791                             }
4792                         }
4793                     }
4794 
4795                     type_sp.reset( new Type (MakeUserID(die->GetOffset()),
4796                                              this,
4797                                              type_name_const_str,
4798                                              byte_size,
4799                                              NULL,
4800                                              encoding_uid,
4801                                              encoding_data_type,
4802                                              &decl,
4803                                              clang_type,
4804                                              resolve_state));
4805 
4806                     m_die_to_type[die] = type_sp.get();
4807 
4808 //                  Type* encoding_type = GetUniquedTypeForDIEOffset(encoding_uid, type_sp, NULL, 0, 0, false);
4809 //                  if (encoding_type != NULL)
4810 //                  {
4811 //                      if (encoding_type != DIE_IS_BEING_PARSED)
4812 //                          type_sp->SetEncodingType(encoding_type);
4813 //                      else
4814 //                          m_indirect_fixups.push_back(type_sp.get());
4815 //                  }
4816                 }
4817                 break;
4818 
4819             case DW_TAG_structure_type:
4820             case DW_TAG_union_type:
4821             case DW_TAG_class_type:
4822                 {
4823                     // Set a bit that lets us know that we are currently parsing this
4824                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
4825 
4826                     LanguageType class_language = eLanguageTypeUnknown;
4827                     bool is_complete_objc_class = false;
4828                     //bool struct_is_class = false;
4829                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
4830                     if (num_attributes > 0)
4831                     {
4832                         uint32_t i;
4833                         for (i=0; i<num_attributes; ++i)
4834                         {
4835                             attr = attributes.AttributeAtIndex(i);
4836                             DWARFFormValue form_value;
4837                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
4838                             {
4839                                 switch (attr)
4840                                 {
4841                                 case DW_AT_decl_file:
4842                                     if (dwarf_cu->DW_AT_decl_file_attributes_are_invalid())
4843 									{
4844 										// llvm-gcc outputs invalid DW_AT_decl_file attributes that always
4845 										// point to the compile unit file, so we clear this invalid value
4846 										// so that we can still unique types efficiently.
4847                                         decl.SetFile(FileSpec ("<invalid>", false));
4848 									}
4849                                     else
4850                                         decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned()));
4851                                     break;
4852 
4853                                 case DW_AT_decl_line:
4854                                     decl.SetLine(form_value.Unsigned());
4855                                     break;
4856 
4857                                 case DW_AT_decl_column:
4858                                     decl.SetColumn(form_value.Unsigned());
4859                                     break;
4860 
4861                                 case DW_AT_name:
4862                                     type_name_cstr = form_value.AsCString(&get_debug_str_data());
4863                                     type_name_const_str.SetCString(type_name_cstr);
4864                                     break;
4865 
4866                                 case DW_AT_byte_size:
4867                                     byte_size = form_value.Unsigned();
4868                                     byte_size_valid = true;
4869                                     break;
4870 
4871                                 case DW_AT_accessibility:
4872                                     accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned());
4873                                     break;
4874 
4875                                 case DW_AT_declaration:
4876                                     is_forward_declaration = form_value.Unsigned() != 0;
4877                                     break;
4878 
4879                                 case DW_AT_APPLE_runtime_class:
4880                                     class_language = (LanguageType)form_value.Signed();
4881                                     break;
4882 
4883                                 case DW_AT_APPLE_objc_complete_type:
4884                                     is_complete_objc_class = form_value.Signed();
4885                                     break;
4886 
4887                                 case DW_AT_allocated:
4888                                 case DW_AT_associated:
4889                                 case DW_AT_data_location:
4890                                 case DW_AT_description:
4891                                 case DW_AT_start_scope:
4892                                 case DW_AT_visibility:
4893                                 default:
4894                                 case DW_AT_sibling:
4895                                     break;
4896                                 }
4897                             }
4898                         }
4899                     }
4900 
4901                     UniqueDWARFASTType unique_ast_entry;
4902 
4903                     // Only try and unique the type if it has a name.
4904                     if (type_name_const_str &&
4905                         GetUniqueDWARFASTTypeMap().Find (type_name_const_str,
4906                                                          this,
4907                                                          dwarf_cu,
4908                                                          die,
4909                                                          decl,
4910                                                          byte_size_valid ? byte_size : -1,
4911                                                          unique_ast_entry))
4912                     {
4913                         // We have already parsed this type or from another
4914                         // compile unit. GCC loves to use the "one definition
4915                         // rule" which can result in multiple definitions
4916                         // of the same class over and over in each compile
4917                         // unit.
4918                         type_sp = unique_ast_entry.m_type_sp;
4919                         if (type_sp)
4920                         {
4921                             m_die_to_type[die] = type_sp.get();
4922                             return type_sp;
4923                         }
4924                     }
4925 
4926                     DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
4927 
4928                     int tag_decl_kind = -1;
4929                     AccessType default_accessibility = eAccessNone;
4930                     if (tag == DW_TAG_structure_type)
4931                     {
4932                         tag_decl_kind = clang::TTK_Struct;
4933                         default_accessibility = eAccessPublic;
4934                     }
4935                     else if (tag == DW_TAG_union_type)
4936                     {
4937                         tag_decl_kind = clang::TTK_Union;
4938                         default_accessibility = eAccessPublic;
4939                     }
4940                     else if (tag == DW_TAG_class_type)
4941                     {
4942                         tag_decl_kind = clang::TTK_Class;
4943                         default_accessibility = eAccessPrivate;
4944                     }
4945 
4946                     if (byte_size_valid && byte_size == 0 && type_name_cstr &&
4947                         die->HasChildren() == false &&
4948                         sc.comp_unit->GetLanguage() == eLanguageTypeObjC)
4949                     {
4950                         // Work around an issue with clang at the moment where
4951                         // forward declarations for objective C classes are emitted
4952                         // as:
4953                         //  DW_TAG_structure_type [2]
4954                         //  DW_AT_name( "ForwardObjcClass" )
4955                         //  DW_AT_byte_size( 0x00 )
4956                         //  DW_AT_decl_file( "..." )
4957                         //  DW_AT_decl_line( 1 )
4958                         //
4959                         // Note that there is no DW_AT_declaration and there are
4960                         // no children, and the byte size is zero.
4961                         is_forward_declaration = true;
4962                     }
4963 
4964                     if (class_language == eLanguageTypeObjC)
4965                     {
4966                         if (!is_complete_objc_class && Supports_DW_AT_APPLE_objc_complete_type(dwarf_cu))
4967                         {
4968                             // We have a valid eSymbolTypeObjCClass class symbol whose
4969                             // name matches the current objective C class that we
4970                             // are trying to find and this DIE isn't the complete
4971                             // definition (we checked is_complete_objc_class above and
4972                             // know it is false), so the real definition is in here somewhere
4973                             type_sp = FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
4974 
4975                             if (!type_sp && m_debug_map_symfile)
4976                             {
4977                                 // We weren't able to find a full declaration in
4978                                 // this DWARF, see if we have a declaration anywhere
4979                                 // else...
4980                                 type_sp = m_debug_map_symfile->FindCompleteObjCDefinitionTypeForDIE (die, type_name_const_str, true);
4981                             }
4982 
4983                             if (type_sp)
4984                             {
4985                                 if (log)
4986                                 {
4987                                     GetObjectFile()->GetModule()->LogMessage (log.get(),
4988                                                                               "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is an incomplete objc type, complete type is 0x%8.8llx",
4989                                                                               this,
4990                                                                               die->GetOffset(),
4991                                                                               DW_TAG_value_to_name(tag),
4992                                                                               type_name_cstr,
4993                                                                               type_sp->GetID());
4994                                 }
4995 
4996                                 // We found a real definition for this type elsewhere
4997                                 // so lets use it and cache the fact that we found
4998                                 // a complete type for this die
4999                                 m_die_to_type[die] = type_sp.get();
5000                                 return type_sp;
5001                             }
5002                         }
5003                     }
5004 
5005 
5006                     if (is_forward_declaration)
5007                     {
5008                         // We have a forward declaration to a type and we need
5009                         // to try and find a full declaration. We look in the
5010                         // current type index just in case we have a forward
5011                         // declaration followed by an actual declarations in the
5012                         // DWARF. If this fails, we need to look elsewhere...
5013                         if (log)
5014                         {
5015                             GetObjectFile()->GetModule()->LogMessage (log.get(),
5016                                                                       "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, trying to find complete type",
5017                                                                       this,
5018                                                                       die->GetOffset(),
5019                                                                       DW_TAG_value_to_name(tag),
5020                                                                       type_name_cstr);
5021                         }
5022 
5023                         type_sp = FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5024 
5025                         if (!type_sp && m_debug_map_symfile)
5026                         {
5027                             // We weren't able to find a full declaration in
5028                             // this DWARF, see if we have a declaration anywhere
5029                             // else...
5030                             type_sp = m_debug_map_symfile->FindDefinitionTypeForDIE (dwarf_cu, die, type_name_const_str);
5031                         }
5032 
5033                         if (type_sp)
5034                         {
5035                             if (log)
5036                             {
5037                                 GetObjectFile()->GetModule()->LogMessage (log.get(),
5038                                                                           "SymbolFileDWARF(%p) - 0x%8.8x: %s type \"%s\" is a forward declaration, complete type is 0x%8.8llx",
5039                                                                           this,
5040                                                                           die->GetOffset(),
5041                                                                           DW_TAG_value_to_name(tag),
5042                                                                           type_name_cstr,
5043                                                                           type_sp->GetID());
5044                             }
5045 
5046                             // We found a real definition for this type elsewhere
5047                             // so lets use it and cache the fact that we found
5048                             // a complete type for this die
5049                             m_die_to_type[die] = type_sp.get();
5050                             return type_sp;
5051                         }
5052                     }
5053                     assert (tag_decl_kind != -1);
5054                     bool clang_type_was_created = false;
5055                     clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5056                     if (clang_type == NULL)
5057                     {
5058                         const DWARFDebugInfoEntry *decl_ctx_die;
5059 
5060                         clang::DeclContext *decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
5061                         if (accessibility == eAccessNone && decl_ctx)
5062                         {
5063                             // Check the decl context that contains this class/struct/union.
5064                             // If it is a class we must give it an accessability.
5065                             const clang::Decl::Kind containing_decl_kind = decl_ctx->getDeclKind();
5066                             if (DeclKindIsCXXClass (containing_decl_kind))
5067                                 accessibility = default_accessibility;
5068                         }
5069 
5070                         if (type_name_cstr && strchr (type_name_cstr, '<'))
5071                         {
5072                             ClangASTContext::TemplateParameterInfos template_param_infos;
5073                             if (ParseTemplateParameterInfos (dwarf_cu, die, template_param_infos))
5074                             {
5075                                 clang::ClassTemplateDecl *class_template_decl = ParseClassTemplateDecl (decl_ctx,
5076                                                                                                         accessibility,
5077                                                                                                         type_name_cstr,
5078                                                                                                         tag_decl_kind,
5079                                                                                                         template_param_infos);
5080 
5081                                 clang::ClassTemplateSpecializationDecl *class_specialization_decl = ast.CreateClassTemplateSpecializationDecl (decl_ctx,
5082                                                                                                                                                class_template_decl,
5083                                                                                                                                                tag_decl_kind,
5084                                                                                                                                                template_param_infos);
5085                                 clang_type = ast.CreateClassTemplateSpecializationType (class_specialization_decl);
5086                                 clang_type_was_created = true;
5087                             }
5088                         }
5089 
5090                         if (!clang_type_was_created)
5091                         {
5092                             clang_type_was_created = true;
5093                             clang_type = ast.CreateRecordType (decl_ctx,
5094                                                                accessibility,
5095                                                                type_name_cstr,
5096                                                                tag_decl_kind,
5097                                                                class_language);
5098                         }
5099                     }
5100 
5101                     // Store a forward declaration to this class type in case any
5102                     // parameters in any class methods need it for the clang
5103                     // types for function prototypes.
5104                     LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5105                     type_sp.reset (new Type (MakeUserID(die->GetOffset()),
5106                                              this,
5107                                              type_name_const_str,
5108                                              byte_size,
5109                                              NULL,
5110                                              LLDB_INVALID_UID,
5111                                              Type::eEncodingIsUID,
5112                                              &decl,
5113                                              clang_type,
5114                                              Type::eResolveStateForward));
5115 
5116                     type_sp->SetIsCompleteObjCClass(is_complete_objc_class);
5117 
5118 
5119                     // Add our type to the unique type map so we don't
5120                     // end up creating many copies of the same type over
5121                     // and over in the ASTContext for our module
5122                     unique_ast_entry.m_type_sp = type_sp;
5123                     unique_ast_entry.m_symfile = this;
5124                     unique_ast_entry.m_cu = dwarf_cu;
5125                     unique_ast_entry.m_die = die;
5126                     unique_ast_entry.m_declaration = decl;
5127                     unique_ast_entry.m_byte_size = byte_size;
5128                     GetUniqueDWARFASTTypeMap().Insert (type_name_const_str,
5129                                                        unique_ast_entry);
5130 
5131                     if (!is_forward_declaration)
5132                     {
5133                         // Always start the definition for a class type so that
5134                         // if the class has child classes or types that require
5135                         // the class to be created for use as their decl contexts
5136                         // the class will be ready to accept these child definitions.
5137                         if (die->HasChildren() == false)
5138                         {
5139                             // No children for this struct/union/class, lets finish it
5140                             ast.StartTagDeclarationDefinition (clang_type);
5141                             ast.CompleteTagDeclarationDefinition (clang_type);
5142                         }
5143                         else if (clang_type_was_created)
5144                         {
5145                             // Start the definition if the class is not objective C since
5146                             // the underlying decls respond to isCompleteDefinition(). Objective
5147                             // C decls dont' respond to isCompleteDefinition() so we can't
5148                             // start the declaration definition right away. For C++ classs/union/structs
5149                             // we want to start the definition in case the class is needed as the
5150                             // declaration context for a contained class or type without the need
5151                             // to complete that type..
5152 
5153                             if (class_language != eLanguageTypeObjC)
5154                                 ast.StartTagDeclarationDefinition (clang_type);
5155 
5156                             // Leave this as a forward declaration until we need
5157                             // to know the details of the type. lldb_private::Type
5158                             // will automatically call the SymbolFile virtual function
5159                             // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
5160                             // When the definition needs to be defined.
5161                             m_forward_decl_die_to_clang_type[die] = clang_type;
5162                             m_forward_decl_clang_type_to_die[ClangASTType::RemoveFastQualifiers (clang_type)] = die;
5163                             ClangASTContext::SetHasExternalStorage (clang_type, true);
5164                         }
5165                     }
5166 
5167                 }
5168                 break;
5169 
5170             case DW_TAG_enumeration_type:
5171                 {
5172                     // Set a bit that lets us know that we are currently parsing this
5173                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
5174 
5175                     lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
5176 
5177                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5178                     if (num_attributes > 0)
5179                     {
5180                         uint32_t i;
5181 
5182                         for (i=0; i<num_attributes; ++i)
5183                         {
5184                             attr = attributes.AttributeAtIndex(i);
5185                             DWARFFormValue form_value;
5186                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5187                             {
5188                                 switch (attr)
5189                                 {
5190                                 case DW_AT_decl_file:       decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5191                                 case DW_AT_decl_line:       decl.SetLine(form_value.Unsigned()); break;
5192                                 case DW_AT_decl_column:     decl.SetColumn(form_value.Unsigned()); break;
5193                                 case DW_AT_name:
5194                                     type_name_cstr = form_value.AsCString(&get_debug_str_data());
5195                                     type_name_const_str.SetCString(type_name_cstr);
5196                                     break;
5197                                 case DW_AT_type:            encoding_uid = form_value.Reference(dwarf_cu); break;
5198                                 case DW_AT_byte_size:       byte_size = form_value.Unsigned(); byte_size_valid = true; break;
5199                                 case DW_AT_accessibility:   accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5200                                 case DW_AT_declaration:     is_forward_declaration = form_value.Unsigned() != 0; break;
5201                                 case DW_AT_allocated:
5202                                 case DW_AT_associated:
5203                                 case DW_AT_bit_stride:
5204                                 case DW_AT_byte_stride:
5205                                 case DW_AT_data_location:
5206                                 case DW_AT_description:
5207                                 case DW_AT_start_scope:
5208                                 case DW_AT_visibility:
5209                                 case DW_AT_specification:
5210                                 case DW_AT_abstract_origin:
5211                                 case DW_AT_sibling:
5212                                     break;
5213                                 }
5214                             }
5215                         }
5216 
5217                         DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
5218 
5219                         clang_type_t enumerator_clang_type = NULL;
5220                         clang_type = m_forward_decl_die_to_clang_type.lookup (die);
5221                         if (clang_type == NULL)
5222                         {
5223                             enumerator_clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (NULL,
5224                                                                                                   DW_ATE_signed,
5225                                                                                                   byte_size * 8);
5226                             clang_type = ast.CreateEnumerationType (type_name_cstr,
5227                                                                     GetClangDeclContextContainingDIE (dwarf_cu, die, NULL),
5228                                                                     decl,
5229                                                                     enumerator_clang_type);
5230                         }
5231                         else
5232                         {
5233                             enumerator_clang_type = ClangASTContext::GetEnumerationIntegerType (clang_type);
5234                             assert (enumerator_clang_type != NULL);
5235                         }
5236 
5237                         LinkDeclContextToDIE(ClangASTContext::GetDeclContextForType(clang_type), die);
5238 
5239                         type_sp.reset( new Type (MakeUserID(die->GetOffset()),
5240                                                  this,
5241                                                  type_name_const_str,
5242                                                  byte_size,
5243                                                  NULL,
5244                                                  encoding_uid,
5245                                                  Type::eEncodingIsUID,
5246                                                  &decl,
5247                                                  clang_type,
5248                                                  Type::eResolveStateForward));
5249 
5250                         ast.StartTagDeclarationDefinition (clang_type);
5251                         if (die->HasChildren())
5252                         {
5253                             SymbolContext cu_sc(GetCompUnitForDWARFCompUnit(dwarf_cu));
5254                             ParseChildEnumerators(cu_sc, clang_type, type_sp->GetByteSize(), dwarf_cu, die);
5255                         }
5256                         ast.CompleteTagDeclarationDefinition (clang_type);
5257                     }
5258                 }
5259                 break;
5260 
5261             case DW_TAG_inlined_subroutine:
5262             case DW_TAG_subprogram:
5263             case DW_TAG_subroutine_type:
5264                 {
5265                     // Set a bit that lets us know that we are currently parsing this
5266                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
5267 
5268                     const char *mangled = NULL;
5269                     dw_offset_t type_die_offset = DW_INVALID_OFFSET;
5270                     bool is_variadic = false;
5271                     bool is_inline = false;
5272                     bool is_static = false;
5273                     bool is_virtual = false;
5274                     bool is_explicit = false;
5275                     bool is_artificial = false;
5276                     dw_offset_t specification_die_offset = DW_INVALID_OFFSET;
5277                     dw_offset_t abstract_origin_die_offset = DW_INVALID_OFFSET;
5278 
5279                     unsigned type_quals = 0;
5280                     clang::StorageClass storage = clang::SC_None;//, Extern, Static, PrivateExtern
5281 
5282 
5283                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5284                     if (num_attributes > 0)
5285                     {
5286                         uint32_t i;
5287                         for (i=0; i<num_attributes; ++i)
5288                         {
5289                             attr = attributes.AttributeAtIndex(i);
5290                             DWARFFormValue form_value;
5291                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5292                             {
5293                                 switch (attr)
5294                                 {
5295                                 case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5296                                 case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
5297                                 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5298                                 case DW_AT_name:
5299                                     type_name_cstr = form_value.AsCString(&get_debug_str_data());
5300                                     type_name_const_str.SetCString(type_name_cstr);
5301                                     break;
5302 
5303                                 case DW_AT_MIPS_linkage_name:   mangled = form_value.AsCString(&get_debug_str_data()); break;
5304                                 case DW_AT_type:                type_die_offset = form_value.Reference(dwarf_cu); break;
5305                                 case DW_AT_accessibility:       accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5306                                 case DW_AT_declaration:         is_forward_declaration = form_value.Unsigned() != 0; break;
5307                                 case DW_AT_inline:              is_inline = form_value.Unsigned() != 0; break;
5308                                 case DW_AT_virtuality:          is_virtual = form_value.Unsigned() != 0;  break;
5309                                 case DW_AT_explicit:            is_explicit = form_value.Unsigned() != 0;  break;
5310                                 case DW_AT_artificial:          is_artificial = form_value.Unsigned() != 0;  break;
5311 
5312 
5313                                 case DW_AT_external:
5314                                     if (form_value.Unsigned())
5315                                     {
5316                                         if (storage == clang::SC_None)
5317                                             storage = clang::SC_Extern;
5318                                         else
5319                                             storage = clang::SC_PrivateExtern;
5320                                     }
5321                                     break;
5322 
5323                                 case DW_AT_specification:
5324                                     specification_die_offset = form_value.Reference(dwarf_cu);
5325                                     break;
5326 
5327                                 case DW_AT_abstract_origin:
5328                                     abstract_origin_die_offset = form_value.Reference(dwarf_cu);
5329                                     break;
5330 
5331                                 case DW_AT_allocated:
5332                                 case DW_AT_associated:
5333                                 case DW_AT_address_class:
5334                                 case DW_AT_calling_convention:
5335                                 case DW_AT_data_location:
5336                                 case DW_AT_elemental:
5337                                 case DW_AT_entry_pc:
5338                                 case DW_AT_frame_base:
5339                                 case DW_AT_high_pc:
5340                                 case DW_AT_low_pc:
5341                                 case DW_AT_object_pointer:
5342                                 case DW_AT_prototyped:
5343                                 case DW_AT_pure:
5344                                 case DW_AT_ranges:
5345                                 case DW_AT_recursive:
5346                                 case DW_AT_return_addr:
5347                                 case DW_AT_segment:
5348                                 case DW_AT_start_scope:
5349                                 case DW_AT_static_link:
5350                                 case DW_AT_trampoline:
5351                                 case DW_AT_visibility:
5352                                 case DW_AT_vtable_elem_location:
5353                                 case DW_AT_description:
5354                                 case DW_AT_sibling:
5355                                     break;
5356                                 }
5357                             }
5358                         }
5359                     }
5360 
5361                     DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
5362 
5363                     clang_type_t return_clang_type = NULL;
5364                     Type *func_type = NULL;
5365 
5366                     if (type_die_offset != DW_INVALID_OFFSET)
5367                         func_type = ResolveTypeUID(type_die_offset);
5368 
5369                     if (func_type)
5370                         return_clang_type = func_type->GetClangForwardType();
5371                     else
5372                         return_clang_type = ast.GetBuiltInType_void();
5373 
5374 
5375                     std::vector<clang_type_t> function_param_types;
5376                     std::vector<clang::ParmVarDecl*> function_param_decls;
5377 
5378                     // Parse the function children for the parameters
5379 
5380                     const DWARFDebugInfoEntry *decl_ctx_die = NULL;
5381                     clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die, &decl_ctx_die);
5382                     const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
5383 
5384                     const bool is_cxx_method = DeclKindIsCXXClass (containing_decl_kind);
5385                     // Start off static. This will be set to false in ParseChildParameters(...)
5386                     // if we find a "this" paramters as the first parameter
5387                     if (is_cxx_method)
5388                         is_static = true;
5389                     ClangASTContext::TemplateParameterInfos template_param_infos;
5390 
5391                     if (die->HasChildren())
5392                     {
5393                         bool skip_artificial = true;
5394                         ParseChildParameters (sc,
5395                                               containing_decl_ctx,
5396                                               dwarf_cu,
5397                                               die,
5398                                               skip_artificial,
5399                                               is_static,
5400                                               type_list,
5401                                               function_param_types,
5402                                               function_param_decls,
5403                                               type_quals,
5404                                               template_param_infos);
5405                     }
5406 
5407                     // clang_type will get the function prototype clang type after this call
5408                     clang_type = ast.CreateFunctionType (return_clang_type,
5409                                                          &function_param_types[0],
5410                                                          function_param_types.size(),
5411                                                          is_variadic,
5412                                                          type_quals);
5413 
5414                     if (type_name_cstr)
5415                     {
5416                         bool type_handled = false;
5417                         if (tag == DW_TAG_subprogram)
5418                         {
5419                             ConstString class_name;
5420                             ConstString class_name_no_category;
5421                             if (ObjCLanguageRuntime::ParseMethodName (type_name_cstr, &class_name, NULL, NULL, &class_name_no_category))
5422                             {
5423                                 // Use the class name with no category if there is one
5424                                 if (class_name_no_category)
5425                                     class_name = class_name_no_category;
5426 
5427                                 SymbolContext empty_sc;
5428                                 clang_type_t class_opaque_type = NULL;
5429                                 if (class_name)
5430                                 {
5431                                     TypeList types;
5432                                     TypeSP complete_objc_class_type_sp (FindCompleteObjCDefinitionTypeForDIE (NULL, class_name, false));
5433 
5434                                     if (complete_objc_class_type_sp)
5435                                     {
5436                                         clang_type_t type_clang_forward_type = complete_objc_class_type_sp->GetClangForwardType();
5437                                         if (ClangASTContext::IsObjCClassType (type_clang_forward_type))
5438                                             class_opaque_type = type_clang_forward_type;
5439                                     }
5440                                 }
5441 
5442                                 if (class_opaque_type)
5443                                 {
5444                                     // If accessibility isn't set to anything valid, assume public for
5445                                     // now...
5446                                     if (accessibility == eAccessNone)
5447                                         accessibility = eAccessPublic;
5448 
5449                                     clang::ObjCMethodDecl *objc_method_decl;
5450                                     objc_method_decl = ast.AddMethodToObjCObjectType (class_opaque_type,
5451                                                                                       type_name_cstr,
5452                                                                                       clang_type,
5453                                                                                       accessibility);
5454                                     LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(objc_method_decl), die);
5455                                     type_handled = objc_method_decl != NULL;
5456                                 }
5457                             }
5458                             else if (is_cxx_method)
5459                             {
5460                                 // Look at the parent of this DIE and see if is is
5461                                 // a class or struct and see if this is actually a
5462                                 // C++ method
5463                                 Type *class_type = ResolveType (dwarf_cu, decl_ctx_die);
5464                                 if (class_type)
5465                                 {
5466                                     if (specification_die_offset != DW_INVALID_OFFSET)
5467                                     {
5468                                         // We have a specification which we are going to base our function
5469                                         // prototype off of, so we need this type to be completed so that the
5470                                         // m_die_to_decl_ctx for the method in the specification has a valid
5471                                         // clang decl context.
5472                                         class_type->GetClangForwardType();
5473                                         // If we have a specification, then the function type should have been
5474                                         // made with the specification and not with this die.
5475                                         DWARFCompileUnitSP spec_cu_sp;
5476                                         const DWARFDebugInfoEntry* spec_die = DebugInfo()->GetDIEPtr(specification_die_offset, &spec_cu_sp);
5477                                         clang::DeclContext *spec_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, spec_die);
5478                                         if (spec_clang_decl_ctx)
5479                                         {
5480                                             LinkDeclContextToDIE(spec_clang_decl_ctx, die);
5481                                         }
5482                                         else
5483                                         {
5484                                             GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_specification(0x%8.8x) has no decl\n",
5485                                                                                          MakeUserID(die->GetOffset()),
5486                                                                                          specification_die_offset);
5487                                         }
5488                                         type_handled = true;
5489                                     }
5490                                     else if (abstract_origin_die_offset != DW_INVALID_OFFSET)
5491                                     {
5492                                         // We have a specification which we are going to base our function
5493                                         // prototype off of, so we need this type to be completed so that the
5494                                         // m_die_to_decl_ctx for the method in the abstract origin has a valid
5495                                         // clang decl context.
5496                                         class_type->GetClangForwardType();
5497 
5498                                         DWARFCompileUnitSP abs_cu_sp;
5499                                         const DWARFDebugInfoEntry* abs_die = DebugInfo()->GetDIEPtr(abstract_origin_die_offset, &abs_cu_sp);
5500                                         clang::DeclContext *abs_clang_decl_ctx = GetClangDeclContextForDIE (sc, dwarf_cu, abs_die);
5501                                         if (abs_clang_decl_ctx)
5502                                         {
5503                                             LinkDeclContextToDIE (abs_clang_decl_ctx, die);
5504                                         }
5505                                         else
5506                                         {
5507                                             GetObjectFile()->GetModule()->ReportWarning ("0x%8.8llx: DW_AT_abstract_origin(0x%8.8x) has no decl\n",
5508                                                                                          MakeUserID(die->GetOffset()),
5509                                                                                          abstract_origin_die_offset);
5510                                         }
5511                                         type_handled = true;
5512                                     }
5513                                     else
5514                                     {
5515                                         clang_type_t class_opaque_type = class_type->GetClangForwardType();
5516                                         if (ClangASTContext::IsCXXClassType (class_opaque_type))
5517                                         {
5518                                             if (ClangASTContext::IsBeingDefined (class_opaque_type))
5519                                             {
5520                                                 // Neither GCC 4.2 nor clang++ currently set a valid accessibility
5521                                                 // in the DWARF for C++ methods... Default to public for now...
5522                                                 if (accessibility == eAccessNone)
5523                                                     accessibility = eAccessPublic;
5524 
5525                                                 if (!is_static && !die->HasChildren())
5526                                                 {
5527                                                     // We have a C++ member function with no children (this pointer!)
5528                                                     // and clang will get mad if we try and make a function that isn't
5529                                                     // well formed in the DWARF, so we will just skip it...
5530                                                     type_handled = true;
5531                                                 }
5532                                                 else
5533                                                 {
5534                                                     clang::CXXMethodDecl *cxx_method_decl;
5535                                                     // REMOVE THE CRASH DESCRIPTION BELOW
5536                                                     Host::SetCrashDescriptionWithFormat ("SymbolFileDWARF::ParseType() is adding a method %s to class %s in DIE 0x%8.8llx from %s/%s",
5537                                                                                          type_name_cstr,
5538                                                                                          class_type->GetName().GetCString(),
5539                                                                                          MakeUserID(die->GetOffset()),
5540                                                                                          m_obj_file->GetFileSpec().GetDirectory().GetCString(),
5541                                                                                          m_obj_file->GetFileSpec().GetFilename().GetCString());
5542 
5543                                                     const bool is_attr_used = false;
5544 
5545                                                     cxx_method_decl = ast.AddMethodToCXXRecordType (class_opaque_type,
5546                                                                                                     type_name_cstr,
5547                                                                                                     clang_type,
5548                                                                                                     accessibility,
5549                                                                                                     is_virtual,
5550                                                                                                     is_static,
5551                                                                                                     is_inline,
5552                                                                                                     is_explicit,
5553                                                                                                     is_attr_used,
5554                                                                                                     is_artificial);
5555                                                     LinkDeclContextToDIE(ClangASTContext::GetAsDeclContext(cxx_method_decl), die);
5556 
5557                                                     Host::SetCrashDescription (NULL);
5558 
5559                                                     type_handled = cxx_method_decl != NULL;
5560                                                 }
5561                                             }
5562                                             else
5563                                             {
5564                                                 // We were asked to parse the type for a method in a class, yet the
5565                                                 // class hasn't been asked to complete itself through the
5566                                                 // clang::ExternalASTSource protocol, so we need to just have the
5567                                                 // class complete itself and do things the right way, then our
5568                                                 // DIE should then have an entry in the m_die_to_type map. First
5569                                                 // we need to modify the m_die_to_type so it doesn't think we are
5570                                                 // trying to parse this DIE anymore...
5571                                                 m_die_to_type[die] = NULL;
5572 
5573                                                 // Now we get the full type to force our class type to complete itself
5574                                                 // using the clang::ExternalASTSource protocol which will parse all
5575                                                 // base classes and all methods (including the method for this DIE).
5576                                                 class_type->GetClangFullType();
5577 
5578                                                 // The type for this DIE should have been filled in the function call above
5579                                                 type_ptr = m_die_to_type[die];
5580                                                 if (type_ptr)
5581                                                 {
5582                                                     type_sp = type_ptr->shared_from_this();
5583                                                     break;
5584                                                 }
5585                                             }
5586                                         }
5587                                     }
5588                                 }
5589                             }
5590                         }
5591 
5592                         if (!type_handled)
5593                         {
5594                             // We just have a function that isn't part of a class
5595                             clang::FunctionDecl *function_decl = ast.CreateFunctionDeclaration (containing_decl_ctx,
5596                                                                                                 type_name_cstr,
5597                                                                                                 clang_type,
5598                                                                                                 storage,
5599                                                                                                 is_inline);
5600 
5601 //                            if (template_param_infos.GetSize() > 0)
5602 //                            {
5603 //                                clang::FunctionTemplateDecl *func_template_decl = ast.CreateFunctionTemplateDecl (containing_decl_ctx,
5604 //                                                                                                                  function_decl,
5605 //                                                                                                                  type_name_cstr,
5606 //                                                                                                                  template_param_infos);
5607 //
5608 //                                ast.CreateFunctionTemplateSpecializationInfo (function_decl,
5609 //                                                                              func_template_decl,
5610 //                                                                              template_param_infos);
5611 //                            }
5612                             // Add the decl to our DIE to decl context map
5613                             assert (function_decl);
5614                             LinkDeclContextToDIE(function_decl, die);
5615                             if (!function_param_decls.empty())
5616                                 ast.SetFunctionParameters (function_decl,
5617                                                            &function_param_decls.front(),
5618                                                            function_param_decls.size());
5619                         }
5620                     }
5621                     type_sp.reset( new Type (MakeUserID(die->GetOffset()),
5622                                              this,
5623                                              type_name_const_str,
5624                                              0,
5625                                              NULL,
5626                                              LLDB_INVALID_UID,
5627                                              Type::eEncodingIsUID,
5628                                              &decl,
5629                                              clang_type,
5630                                              Type::eResolveStateFull));
5631                     assert(type_sp.get());
5632                 }
5633                 break;
5634 
5635             case DW_TAG_array_type:
5636                 {
5637                     // Set a bit that lets us know that we are currently parsing this
5638                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
5639 
5640                     lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
5641                     int64_t first_index = 0;
5642                     uint32_t byte_stride = 0;
5643                     uint32_t bit_stride = 0;
5644                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5645 
5646                     if (num_attributes > 0)
5647                     {
5648                         uint32_t i;
5649                         for (i=0; i<num_attributes; ++i)
5650                         {
5651                             attr = attributes.AttributeAtIndex(i);
5652                             DWARFFormValue form_value;
5653                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5654                             {
5655                                 switch (attr)
5656                                 {
5657                                 case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
5658                                 case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
5659                                 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
5660                                 case DW_AT_name:
5661                                     type_name_cstr = form_value.AsCString(&get_debug_str_data());
5662                                     type_name_const_str.SetCString(type_name_cstr);
5663                                     break;
5664 
5665                                 case DW_AT_type:            type_die_offset = form_value.Reference(dwarf_cu); break;
5666                                 case DW_AT_byte_size:       byte_size = form_value.Unsigned(); byte_size_valid = true; break;
5667                                 case DW_AT_byte_stride:     byte_stride = form_value.Unsigned(); break;
5668                                 case DW_AT_bit_stride:      bit_stride = form_value.Unsigned(); break;
5669                                 case DW_AT_accessibility:   accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
5670                                 case DW_AT_declaration:     is_forward_declaration = form_value.Unsigned() != 0; break;
5671                                 case DW_AT_allocated:
5672                                 case DW_AT_associated:
5673                                 case DW_AT_data_location:
5674                                 case DW_AT_description:
5675                                 case DW_AT_ordering:
5676                                 case DW_AT_start_scope:
5677                                 case DW_AT_visibility:
5678                                 case DW_AT_specification:
5679                                 case DW_AT_abstract_origin:
5680                                 case DW_AT_sibling:
5681                                     break;
5682                                 }
5683                             }
5684                         }
5685 
5686                         DEBUG_PRINTF ("0x%8.8llx: %s (\"%s\")\n", MakeUserID(die->GetOffset()), DW_TAG_value_to_name(tag), type_name_cstr);
5687 
5688                         Type *element_type = ResolveTypeUID(type_die_offset);
5689 
5690                         if (element_type)
5691                         {
5692                             std::vector<uint64_t> element_orders;
5693                             ParseChildArrayInfo(sc, dwarf_cu, die, first_index, element_orders, byte_stride, bit_stride);
5694                             // We have an array that claims to have no members, lets give it at least one member...
5695                             if (element_orders.empty())
5696                                 element_orders.push_back (1);
5697                             if (byte_stride == 0 && bit_stride == 0)
5698                                 byte_stride = element_type->GetByteSize();
5699                             clang_type_t array_element_type = element_type->GetClangForwardType();
5700                             uint64_t array_element_bit_stride = byte_stride * 8 + bit_stride;
5701                             uint64_t num_elements = 0;
5702                             std::vector<uint64_t>::const_reverse_iterator pos;
5703                             std::vector<uint64_t>::const_reverse_iterator end = element_orders.rend();
5704                             for (pos = element_orders.rbegin(); pos != end; ++pos)
5705                             {
5706                                 num_elements = *pos;
5707                                 clang_type = ast.CreateArrayType (array_element_type,
5708                                                                   num_elements,
5709                                                                   num_elements * array_element_bit_stride);
5710                                 array_element_type = clang_type;
5711                                 array_element_bit_stride = array_element_bit_stride * num_elements;
5712                             }
5713                             ConstString empty_name;
5714                             type_sp.reset( new Type (MakeUserID(die->GetOffset()),
5715                                                      this,
5716                                                      empty_name,
5717                                                      array_element_bit_stride / 8,
5718                                                      NULL,
5719                                                      type_die_offset,
5720                                                      Type::eEncodingIsUID,
5721                                                      &decl,
5722                                                      clang_type,
5723                                                      Type::eResolveStateFull));
5724                             type_sp->SetEncodingType (element_type);
5725                         }
5726                     }
5727                 }
5728                 break;
5729 
5730             case DW_TAG_ptr_to_member_type:
5731                 {
5732                     dw_offset_t type_die_offset = DW_INVALID_OFFSET;
5733                     dw_offset_t containing_type_die_offset = DW_INVALID_OFFSET;
5734 
5735                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
5736 
5737                     if (num_attributes > 0) {
5738                         uint32_t i;
5739                         for (i=0; i<num_attributes; ++i)
5740                         {
5741                             attr = attributes.AttributeAtIndex(i);
5742                             DWARFFormValue form_value;
5743                             if (attributes.ExtractFormValueAtIndex(this, i, form_value))
5744                             {
5745                                 switch (attr)
5746                                 {
5747                                     case DW_AT_type:
5748                                         type_die_offset = form_value.Reference(dwarf_cu); break;
5749                                     case DW_AT_containing_type:
5750                                         containing_type_die_offset = form_value.Reference(dwarf_cu); break;
5751                                 }
5752                             }
5753                         }
5754 
5755                         Type *pointee_type = ResolveTypeUID(type_die_offset);
5756                         Type *class_type = ResolveTypeUID(containing_type_die_offset);
5757 
5758                         clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
5759                         clang_type_t class_clang_type = class_type->GetClangLayoutType();
5760 
5761                         clang_type = ast.CreateMemberPointerType(pointee_clang_type,
5762                                                                  class_clang_type);
5763 
5764                         byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(),
5765                                                                        clang_type) / 8;
5766 
5767                         type_sp.reset( new Type (MakeUserID(die->GetOffset()),
5768                                                  this,
5769                                                  type_name_const_str,
5770                                                  byte_size,
5771                                                  NULL,
5772                                                  LLDB_INVALID_UID,
5773                                                  Type::eEncodingIsUID,
5774                                                  NULL,
5775                                                  clang_type,
5776                                                  Type::eResolveStateForward));
5777                     }
5778 
5779                     break;
5780                 }
5781             default:
5782                 assert(false && "Unhandled type tag!");
5783                 break;
5784             }
5785 
5786             if (type_sp.get())
5787             {
5788                 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
5789                 dw_tag_t sc_parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
5790 
5791                 SymbolContextScope * symbol_context_scope = NULL;
5792                 if (sc_parent_tag == DW_TAG_compile_unit)
5793                 {
5794                     symbol_context_scope = sc.comp_unit;
5795                 }
5796                 else if (sc.function != NULL)
5797                 {
5798                     symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
5799                     if (symbol_context_scope == NULL)
5800                         symbol_context_scope = sc.function;
5801                 }
5802 
5803                 if (symbol_context_scope != NULL)
5804                 {
5805                     type_sp->SetSymbolContextScope(symbol_context_scope);
5806                 }
5807 
5808                 // We are ready to put this type into the uniqued list up at the module level
5809                 type_list->Insert (type_sp);
5810 
5811                 m_die_to_type[die] = type_sp.get();
5812             }
5813         }
5814         else if (type_ptr != DIE_IS_BEING_PARSED)
5815         {
5816             type_sp = type_ptr->shared_from_this();
5817         }
5818     }
5819     return type_sp;
5820 }
5821 
5822 size_t
5823 SymbolFileDWARF::ParseTypes
5824 (
5825     const SymbolContext& sc,
5826     DWARFCompileUnit* dwarf_cu,
5827     const DWARFDebugInfoEntry *die,
5828     bool parse_siblings,
5829     bool parse_children
5830 )
5831 {
5832     size_t types_added = 0;
5833     while (die != NULL)
5834     {
5835         bool type_is_new = false;
5836         if (ParseType(sc, dwarf_cu, die, &type_is_new).get())
5837         {
5838             if (type_is_new)
5839                 ++types_added;
5840         }
5841 
5842         if (parse_children && die->HasChildren())
5843         {
5844             if (die->Tag() == DW_TAG_subprogram)
5845             {
5846                 SymbolContext child_sc(sc);
5847                 child_sc.function = sc.comp_unit->FindFunctionByUID(MakeUserID(die->GetOffset())).get();
5848                 types_added += ParseTypes(child_sc, dwarf_cu, die->GetFirstChild(), true, true);
5849             }
5850             else
5851                 types_added += ParseTypes(sc, dwarf_cu, die->GetFirstChild(), true, true);
5852         }
5853 
5854         if (parse_siblings)
5855             die = die->GetSibling();
5856         else
5857             die = NULL;
5858     }
5859     return types_added;
5860 }
5861 
5862 
5863 size_t
5864 SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
5865 {
5866     assert(sc.comp_unit && sc.function);
5867     size_t functions_added = 0;
5868     DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5869     if (dwarf_cu)
5870     {
5871         dw_offset_t function_die_offset = sc.function->GetID();
5872         const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(function_die_offset);
5873         if (function_die)
5874         {
5875             ParseFunctionBlocks(sc, &sc.function->GetBlock (false), dwarf_cu, function_die, LLDB_INVALID_ADDRESS, 0);
5876         }
5877     }
5878 
5879     return functions_added;
5880 }
5881 
5882 
5883 size_t
5884 SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
5885 {
5886     // At least a compile unit must be valid
5887     assert(sc.comp_unit);
5888     size_t types_added = 0;
5889     DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnitForUID(sc.comp_unit->GetID());
5890     if (dwarf_cu)
5891     {
5892         if (sc.function)
5893         {
5894             dw_offset_t function_die_offset = sc.function->GetID();
5895             const DWARFDebugInfoEntry *func_die = dwarf_cu->GetDIEPtr(function_die_offset);
5896             if (func_die && func_die->HasChildren())
5897             {
5898                 types_added = ParseTypes(sc, dwarf_cu, func_die->GetFirstChild(), true, true);
5899             }
5900         }
5901         else
5902         {
5903             const DWARFDebugInfoEntry *dwarf_cu_die = dwarf_cu->DIE();
5904             if (dwarf_cu_die && dwarf_cu_die->HasChildren())
5905             {
5906                 types_added = ParseTypes(sc, dwarf_cu, dwarf_cu_die->GetFirstChild(), true, true);
5907             }
5908         }
5909     }
5910 
5911     return types_added;
5912 }
5913 
5914 size_t
5915 SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
5916 {
5917     if (sc.comp_unit != NULL)
5918     {
5919         DWARFDebugInfo* info = DebugInfo();
5920         if (info == NULL)
5921             return 0;
5922 
5923         uint32_t cu_idx = UINT32_MAX;
5924         DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID(), &cu_idx).get();
5925 
5926         if (dwarf_cu == NULL)
5927             return 0;
5928 
5929         if (sc.function)
5930         {
5931             const DWARFDebugInfoEntry *function_die = dwarf_cu->GetDIEPtr(sc.function->GetID());
5932 
5933             dw_addr_t func_lo_pc = function_die->GetAttributeValueAsUnsigned (this, dwarf_cu, DW_AT_low_pc, DW_INVALID_ADDRESS);
5934             if (func_lo_pc != DW_INVALID_ADDRESS)
5935             {
5936                 const size_t num_variables = ParseVariables(sc, dwarf_cu, func_lo_pc, function_die->GetFirstChild(), true, true);
5937 
5938                 // Let all blocks know they have parse all their variables
5939                 sc.function->GetBlock (false).SetDidParseVariables (true, true);
5940                 return num_variables;
5941             }
5942         }
5943         else if (sc.comp_unit)
5944         {
5945             uint32_t vars_added = 0;
5946             VariableListSP variables (sc.comp_unit->GetVariableList(false));
5947 
5948             if (variables.get() == NULL)
5949             {
5950                 variables.reset(new VariableList());
5951                 sc.comp_unit->SetVariableList(variables);
5952 
5953                 DWARFCompileUnit* match_dwarf_cu = NULL;
5954                 const DWARFDebugInfoEntry* die = NULL;
5955                 DIEArray die_offsets;
5956                 if (m_using_apple_tables)
5957                 {
5958                     if (m_apple_names_ap.get())
5959                     {
5960                         DWARFMappedHash::DIEInfoArray hash_data_array;
5961                         if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
5962                                                                     dwarf_cu->GetNextCompileUnitOffset(),
5963                                                                     hash_data_array))
5964                         {
5965                             DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
5966                         }
5967                     }
5968                 }
5969                 else
5970                 {
5971                     // Index if we already haven't to make sure the compile units
5972                     // get indexed and make their global DIE index list
5973                     if (!m_indexed)
5974                         Index ();
5975 
5976                     m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
5977                                                                  dwarf_cu->GetNextCompileUnitOffset(),
5978                                                                  die_offsets);
5979                 }
5980 
5981                 const size_t num_matches = die_offsets.size();
5982                 if (num_matches)
5983                 {
5984                     DWARFDebugInfo* debug_info = DebugInfo();
5985                     for (size_t i=0; i<num_matches; ++i)
5986                     {
5987                         const dw_offset_t die_offset = die_offsets[i];
5988                         die = debug_info->GetDIEPtrWithCompileUnitHint (die_offset, &match_dwarf_cu);
5989                         if (die)
5990                         {
5991                             VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, LLDB_INVALID_ADDRESS));
5992                             if (var_sp)
5993                             {
5994                                 variables->AddVariableIfUnique (var_sp);
5995                                 ++vars_added;
5996                             }
5997                         }
5998                         else
5999                         {
6000                             if (m_using_apple_tables)
6001                             {
6002                                 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_offset);
6003                             }
6004                         }
6005 
6006                     }
6007                 }
6008             }
6009             return vars_added;
6010         }
6011     }
6012     return 0;
6013 }
6014 
6015 
6016 VariableSP
6017 SymbolFileDWARF::ParseVariableDIE
6018 (
6019     const SymbolContext& sc,
6020     DWARFCompileUnit* dwarf_cu,
6021     const DWARFDebugInfoEntry *die,
6022     const lldb::addr_t func_low_pc
6023 )
6024 {
6025 
6026     VariableSP var_sp (m_die_to_variable_sp[die]);
6027     if (var_sp)
6028         return var_sp;  // Already been parsed!
6029 
6030     const dw_tag_t tag = die->Tag();
6031 
6032     if ((tag == DW_TAG_variable) ||
6033         (tag == DW_TAG_constant) ||
6034         (tag == DW_TAG_formal_parameter && sc.function))
6035     {
6036         DWARFDebugInfoEntry::Attributes attributes;
6037         const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
6038         if (num_attributes > 0)
6039         {
6040             const char *name = NULL;
6041             const char *mangled = NULL;
6042             Declaration decl;
6043             uint32_t i;
6044             lldb::user_id_t type_uid = LLDB_INVALID_UID;
6045             DWARFExpression location;
6046             bool is_external = false;
6047             bool is_artificial = false;
6048             bool location_is_const_value_data = false;
6049             AccessType accessibility = eAccessNone;
6050 
6051             for (i=0; i<num_attributes; ++i)
6052             {
6053                 dw_attr_t attr = attributes.AttributeAtIndex(i);
6054                 DWARFFormValue form_value;
6055                 if (attributes.ExtractFormValueAtIndex(this, i, form_value))
6056                 {
6057                     switch (attr)
6058                     {
6059                     case DW_AT_decl_file:   decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
6060                     case DW_AT_decl_line:   decl.SetLine(form_value.Unsigned()); break;
6061                     case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
6062                     case DW_AT_name:        name = form_value.AsCString(&get_debug_str_data()); break;
6063                     case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break;
6064                     case DW_AT_type:        type_uid = form_value.Reference(dwarf_cu); break;
6065                     case DW_AT_external:    is_external = form_value.Unsigned() != 0; break;
6066                     case DW_AT_const_value:
6067                         location_is_const_value_data = true;
6068                         // Fall through...
6069                     case DW_AT_location:
6070                         {
6071                             if (form_value.BlockData())
6072                             {
6073                                 const DataExtractor& debug_info_data = get_debug_info_data();
6074 
6075                                 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
6076                                 uint32_t block_length = form_value.Unsigned();
6077                                 location.SetOpcodeData(get_debug_info_data(), block_offset, block_length);
6078                             }
6079                             else
6080                             {
6081                                 const DataExtractor&    debug_loc_data = get_debug_loc_data();
6082                                 const dw_offset_t debug_loc_offset = form_value.Unsigned();
6083 
6084                                 size_t loc_list_length = DWARFLocationList::Size(debug_loc_data, debug_loc_offset);
6085                                 if (loc_list_length > 0)
6086                                 {
6087                                     location.SetOpcodeData(debug_loc_data, debug_loc_offset, loc_list_length);
6088                                     assert (func_low_pc != LLDB_INVALID_ADDRESS);
6089                                     location.SetLocationListSlide (func_low_pc - dwarf_cu->GetBaseAddress());
6090                                 }
6091                             }
6092                         }
6093                         break;
6094 
6095                     case DW_AT_artificial:      is_artificial = form_value.Unsigned() != 0; break;
6096                     case DW_AT_accessibility:   accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
6097                     case DW_AT_declaration:
6098                     case DW_AT_description:
6099                     case DW_AT_endianity:
6100                     case DW_AT_segment:
6101                     case DW_AT_start_scope:
6102                     case DW_AT_visibility:
6103                     default:
6104                     case DW_AT_abstract_origin:
6105                     case DW_AT_sibling:
6106                     case DW_AT_specification:
6107                         break;
6108                     }
6109                 }
6110             }
6111 
6112             if (location.IsValid())
6113             {
6114                 ValueType scope = eValueTypeInvalid;
6115 
6116                 const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(die);
6117                 dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6118                 SymbolContextScope * symbol_context_scope = NULL;
6119 
6120                 // DWARF doesn't specify if a DW_TAG_variable is a local, global
6121                 // or static variable, so we have to do a little digging by
6122                 // looking at the location of a varaible to see if it contains
6123                 // a DW_OP_addr opcode _somewhere_ in the definition. I say
6124                 // somewhere because clang likes to combine small global variables
6125                 // into the same symbol and have locations like:
6126                 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
6127                 // So if we don't have a DW_TAG_formal_parameter, we can look at
6128                 // the location to see if it contains a DW_OP_addr opcode, and
6129                 // then we can correctly classify  our variables.
6130                 if (tag == DW_TAG_formal_parameter)
6131                     scope = eValueTypeVariableArgument;
6132                 else
6133                 {
6134                     bool op_error = false;
6135                     // Check if the location has a DW_OP_addr with any address value...
6136                     addr_t location_has_op_addr = false;
6137                     if (!location_is_const_value_data)
6138                     {
6139                         location_has_op_addr = location.LocationContains_DW_OP_addr (LLDB_INVALID_ADDRESS, op_error);
6140                         if (op_error)
6141                         {
6142                             StreamString strm;
6143                             location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
6144                             GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die->GetOffset(), DW_TAG_value_to_name(die->Tag()), strm.GetString().c_str());
6145                         }
6146                     }
6147 
6148                     if (location_has_op_addr)
6149                     {
6150                         if (is_external)
6151                         {
6152                             scope = eValueTypeVariableGlobal;
6153 
6154                             if (m_debug_map_symfile)
6155                             {
6156                                 // When leaving the DWARF in the .o files on darwin,
6157                                 // when we have a global variable that wasn't initialized,
6158                                 // the .o file might not have allocated a virtual
6159                                 // address for the global variable. In this case it will
6160                                 // have created a symbol for the global variable
6161                                 // that is undefined and external and the value will
6162                                 // be the byte size of the variable. When we do the
6163                                 // address map in SymbolFileDWARFDebugMap we rely on
6164                                 // having an address, we need to do some magic here
6165                                 // so we can get the correct address for our global
6166                                 // variable. The address for all of these entries
6167                                 // will be zero, and there will be an undefined symbol
6168                                 // in this object file, and the executable will have
6169                                 // a matching symbol with a good address. So here we
6170                                 // dig up the correct address and replace it in the
6171                                 // location for the variable, and set the variable's
6172                                 // symbol context scope to be that of the main executable
6173                                 // so the file address will resolve correctly.
6174                                 if (location.LocationContains_DW_OP_addr (0, op_error))
6175                                 {
6176 
6177                                     // we have a possible uninitialized extern global
6178                                     Symtab *symtab = m_obj_file->GetSymtab();
6179                                     if (symtab)
6180                                     {
6181                                         ConstString const_name(name);
6182                                         Symbol *undefined_symbol = symtab->FindFirstSymbolWithNameAndType (const_name,
6183                                                                                                            eSymbolTypeUndefined,
6184                                                                                                            Symtab::eDebugNo,
6185                                                                                                            Symtab::eVisibilityExtern);
6186 
6187                                         if (undefined_symbol)
6188                                         {
6189                                             ObjectFile *debug_map_objfile = m_debug_map_symfile->GetObjectFile();
6190                                             if (debug_map_objfile)
6191                                             {
6192                                                 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
6193                                                 Symbol *defined_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
6194                                                                                                                            eSymbolTypeData,
6195                                                                                                                            Symtab::eDebugYes,
6196                                                                                                                            Symtab::eVisibilityExtern);
6197                                                 if (defined_symbol)
6198                                                 {
6199                                                     if (defined_symbol->ValueIsAddress())
6200                                                     {
6201                                                         const addr_t defined_addr = defined_symbol->GetAddress().GetFileAddress();
6202                                                         if (defined_addr != LLDB_INVALID_ADDRESS)
6203                                                         {
6204                                                             if (location.Update_DW_OP_addr (defined_addr))
6205                                                             {
6206                                                                 symbol_context_scope = defined_symbol;
6207                                                             }
6208                                                         }
6209                                                     }
6210                                                 }
6211                                             }
6212                                         }
6213                                     }
6214                                 }
6215                             }
6216                         }
6217                         else
6218                         {
6219                             scope = eValueTypeVariableStatic;
6220                         }
6221                     }
6222                     else
6223                     {
6224                         scope = eValueTypeVariableLocal;
6225                     }
6226                 }
6227 
6228                 if (symbol_context_scope == NULL)
6229                 {
6230                     switch (parent_tag)
6231                     {
6232                     case DW_TAG_subprogram:
6233                     case DW_TAG_inlined_subroutine:
6234                     case DW_TAG_lexical_block:
6235                         if (sc.function)
6236                         {
6237                             symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6238                             if (symbol_context_scope == NULL)
6239                                 symbol_context_scope = sc.function;
6240                         }
6241                         break;
6242 
6243                     default:
6244                         symbol_context_scope = sc.comp_unit;
6245                         break;
6246                     }
6247                 }
6248 
6249                 if (symbol_context_scope)
6250                 {
6251                     var_sp.reset (new Variable (MakeUserID(die->GetOffset()),
6252                                                 name,
6253                                                 mangled,
6254                                                 SymbolFileTypeSP (new SymbolFileType(*this, type_uid)),
6255                                                 scope,
6256                                                 symbol_context_scope,
6257                                                 &decl,
6258                                                 location,
6259                                                 is_external,
6260                                                 is_artificial));
6261 
6262                     var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
6263                 }
6264                 else
6265                 {
6266                     // Not ready to parse this variable yet. It might be a global
6267                     // or static variable that is in a function scope and the function
6268                     // in the symbol context wasn't filled in yet
6269                     return var_sp;
6270                 }
6271             }
6272         }
6273         // Cache var_sp even if NULL (the variable was just a specification or
6274         // was missing vital information to be able to be displayed in the debugger
6275         // (missing location due to optimization, etc)) so we don't re-parse
6276         // this DIE over and over later...
6277         m_die_to_variable_sp[die] = var_sp;
6278     }
6279     return var_sp;
6280 }
6281 
6282 
6283 const DWARFDebugInfoEntry *
6284 SymbolFileDWARF::FindBlockContainingSpecification (dw_offset_t func_die_offset,
6285                                                    dw_offset_t spec_block_die_offset,
6286                                                    DWARFCompileUnit **result_die_cu_handle)
6287 {
6288     // Give the concrete function die specified by "func_die_offset", find the
6289     // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6290     // to "spec_block_die_offset"
6291     DWARFDebugInfo* info = DebugInfo();
6292 
6293     const DWARFDebugInfoEntry *die = info->GetDIEPtrWithCompileUnitHint(func_die_offset, result_die_cu_handle);
6294     if (die)
6295     {
6296         assert (*result_die_cu_handle);
6297         return FindBlockContainingSpecification (*result_die_cu_handle, die, spec_block_die_offset, result_die_cu_handle);
6298     }
6299     return NULL;
6300 }
6301 
6302 
6303 const DWARFDebugInfoEntry *
6304 SymbolFileDWARF::FindBlockContainingSpecification(DWARFCompileUnit* dwarf_cu,
6305                                                   const DWARFDebugInfoEntry *die,
6306                                                   dw_offset_t spec_block_die_offset,
6307                                                   DWARFCompileUnit **result_die_cu_handle)
6308 {
6309     if (die)
6310     {
6311         switch (die->Tag())
6312         {
6313         case DW_TAG_subprogram:
6314         case DW_TAG_inlined_subroutine:
6315         case DW_TAG_lexical_block:
6316             {
6317                 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
6318                 {
6319                     *result_die_cu_handle = dwarf_cu;
6320                     return die;
6321                 }
6322 
6323                 if (die->GetAttributeValueAsReference (this, dwarf_cu, DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
6324                 {
6325                     *result_die_cu_handle = dwarf_cu;
6326                     return die;
6327                 }
6328             }
6329             break;
6330         }
6331 
6332         // Give the concrete function die specified by "func_die_offset", find the
6333         // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
6334         // to "spec_block_die_offset"
6335         for (const DWARFDebugInfoEntry *child_die = die->GetFirstChild(); child_die != NULL; child_die = child_die->GetSibling())
6336         {
6337             const DWARFDebugInfoEntry *result_die = FindBlockContainingSpecification (dwarf_cu,
6338                                                                                       child_die,
6339                                                                                       spec_block_die_offset,
6340                                                                                       result_die_cu_handle);
6341             if (result_die)
6342                 return result_die;
6343         }
6344     }
6345 
6346     *result_die_cu_handle = NULL;
6347     return NULL;
6348 }
6349 
6350 size_t
6351 SymbolFileDWARF::ParseVariables
6352 (
6353     const SymbolContext& sc,
6354     DWARFCompileUnit* dwarf_cu,
6355     const lldb::addr_t func_low_pc,
6356     const DWARFDebugInfoEntry *orig_die,
6357     bool parse_siblings,
6358     bool parse_children,
6359     VariableList* cc_variable_list
6360 )
6361 {
6362     if (orig_die == NULL)
6363         return 0;
6364 
6365     VariableListSP variable_list_sp;
6366 
6367     size_t vars_added = 0;
6368     const DWARFDebugInfoEntry *die = orig_die;
6369     while (die != NULL)
6370     {
6371         dw_tag_t tag = die->Tag();
6372 
6373         // Check to see if we have already parsed this variable or constant?
6374         if (m_die_to_variable_sp[die])
6375         {
6376             if (cc_variable_list)
6377                 cc_variable_list->AddVariableIfUnique (m_die_to_variable_sp[die]);
6378         }
6379         else
6380         {
6381             // We haven't already parsed it, lets do that now.
6382             if ((tag == DW_TAG_variable) ||
6383                 (tag == DW_TAG_constant) ||
6384                 (tag == DW_TAG_formal_parameter && sc.function))
6385             {
6386                 if (variable_list_sp.get() == NULL)
6387                 {
6388                     const DWARFDebugInfoEntry *sc_parent_die = GetParentSymbolContextDIE(orig_die);
6389                     dw_tag_t parent_tag = sc_parent_die ? sc_parent_die->Tag() : 0;
6390                     switch (parent_tag)
6391                     {
6392                         case DW_TAG_compile_unit:
6393                             if (sc.comp_unit != NULL)
6394                             {
6395                                 variable_list_sp = sc.comp_unit->GetVariableList(false);
6396                                 if (variable_list_sp.get() == NULL)
6397                                 {
6398                                     variable_list_sp.reset(new VariableList());
6399                                     sc.comp_unit->SetVariableList(variable_list_sp);
6400                                 }
6401                             }
6402                             else
6403                             {
6404                                 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8llx %s with no valid compile unit in symbol context for 0x%8.8llx %s.\n",
6405                                                                            MakeUserID(sc_parent_die->GetOffset()),
6406                                                                            DW_TAG_value_to_name (parent_tag),
6407                                                                            MakeUserID(orig_die->GetOffset()),
6408                                                                            DW_TAG_value_to_name (orig_die->Tag()));
6409                             }
6410                             break;
6411 
6412                         case DW_TAG_subprogram:
6413                         case DW_TAG_inlined_subroutine:
6414                         case DW_TAG_lexical_block:
6415                             if (sc.function != NULL)
6416                             {
6417                                 // Check to see if we already have parsed the variables for the given scope
6418 
6419                                 Block *block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(sc_parent_die->GetOffset()));
6420                                 if (block == NULL)
6421                                 {
6422                                     // This must be a specification or abstract origin with
6423                                     // a concrete block couterpart in the current function. We need
6424                                     // to find the concrete block so we can correctly add the
6425                                     // variable to it
6426                                     DWARFCompileUnit *concrete_block_die_cu = dwarf_cu;
6427                                     const DWARFDebugInfoEntry *concrete_block_die = FindBlockContainingSpecification (sc.function->GetID(),
6428                                                                                                                       sc_parent_die->GetOffset(),
6429                                                                                                                       &concrete_block_die_cu);
6430                                     if (concrete_block_die)
6431                                         block = sc.function->GetBlock(true).FindBlockByID(MakeUserID(concrete_block_die->GetOffset()));
6432                                 }
6433 
6434                                 if (block != NULL)
6435                                 {
6436                                     const bool can_create = false;
6437                                     variable_list_sp = block->GetBlockVariableList (can_create);
6438                                     if (variable_list_sp.get() == NULL)
6439                                     {
6440                                         variable_list_sp.reset(new VariableList());
6441                                         block->SetVariableList(variable_list_sp);
6442                                     }
6443                                 }
6444                             }
6445                             break;
6446 
6447                         default:
6448                              GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8llx %s.\n",
6449                                                                         MakeUserID(orig_die->GetOffset()),
6450                                                                         DW_TAG_value_to_name (orig_die->Tag()));
6451                             break;
6452                     }
6453                 }
6454 
6455                 if (variable_list_sp)
6456                 {
6457                     VariableSP var_sp (ParseVariableDIE(sc, dwarf_cu, die, func_low_pc));
6458                     if (var_sp)
6459                     {
6460                         variable_list_sp->AddVariableIfUnique (var_sp);
6461                         if (cc_variable_list)
6462                             cc_variable_list->AddVariableIfUnique (var_sp);
6463                         ++vars_added;
6464                     }
6465                 }
6466             }
6467         }
6468 
6469         bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
6470 
6471         if (!skip_children && parse_children && die->HasChildren())
6472         {
6473             vars_added += ParseVariables(sc, dwarf_cu, func_low_pc, die->GetFirstChild(), true, true, cc_variable_list);
6474         }
6475 
6476         if (parse_siblings)
6477             die = die->GetSibling();
6478         else
6479             die = NULL;
6480     }
6481     return vars_added;
6482 }
6483 
6484 //------------------------------------------------------------------
6485 // PluginInterface protocol
6486 //------------------------------------------------------------------
6487 const char *
6488 SymbolFileDWARF::GetPluginName()
6489 {
6490     return "SymbolFileDWARF";
6491 }
6492 
6493 const char *
6494 SymbolFileDWARF::GetShortPluginName()
6495 {
6496     return GetPluginNameStatic();
6497 }
6498 
6499 uint32_t
6500 SymbolFileDWARF::GetPluginVersion()
6501 {
6502     return 1;
6503 }
6504 
6505 void
6506 SymbolFileDWARF::CompleteTagDecl (void *baton, clang::TagDecl *decl)
6507 {
6508     SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6509     clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6510     if (clang_type)
6511         symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6512 }
6513 
6514 void
6515 SymbolFileDWARF::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *decl)
6516 {
6517     SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6518     clang_type_t clang_type = symbol_file_dwarf->GetClangASTContext().GetTypeForDecl (decl);
6519     if (clang_type)
6520         symbol_file_dwarf->ResolveClangOpaqueTypeDefinition (clang_type);
6521 }
6522 
6523 void
6524 SymbolFileDWARF::DumpIndexes ()
6525 {
6526     StreamFile s(stdout, false);
6527 
6528     s.Printf ("DWARF index for (%s) '%s/%s':",
6529               GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
6530               GetObjectFile()->GetFileSpec().GetDirectory().AsCString(),
6531               GetObjectFile()->GetFileSpec().GetFilename().AsCString());
6532     s.Printf("\nFunction basenames:\n");    m_function_basename_index.Dump (&s);
6533     s.Printf("\nFunction fullnames:\n");    m_function_fullname_index.Dump (&s);
6534     s.Printf("\nFunction methods:\n");      m_function_method_index.Dump (&s);
6535     s.Printf("\nFunction selectors:\n");    m_function_selector_index.Dump (&s);
6536     s.Printf("\nObjective C class selectors:\n");    m_objc_class_selectors_index.Dump (&s);
6537     s.Printf("\nGlobals and statics:\n");   m_global_index.Dump (&s);
6538     s.Printf("\nTypes:\n");                 m_type_index.Dump (&s);
6539     s.Printf("\nNamepaces:\n");             m_namespace_index.Dump (&s);
6540 }
6541 
6542 void
6543 SymbolFileDWARF::SearchDeclContext (const clang::DeclContext *decl_context,
6544                                     const char *name,
6545                                     llvm::SmallVectorImpl <clang::NamedDecl *> *results)
6546 {
6547     DeclContextToDIEMap::iterator iter = m_decl_ctx_to_die.find(decl_context);
6548 
6549     if (iter == m_decl_ctx_to_die.end())
6550         return;
6551 
6552     for (DIEPointerSet::iterator pos = iter->second.begin(), end = iter->second.end(); pos != end; ++pos)
6553     {
6554         const DWARFDebugInfoEntry *context_die = *pos;
6555 
6556         if (!results)
6557             return;
6558 
6559         DWARFDebugInfo* info = DebugInfo();
6560 
6561         DIEArray die_offsets;
6562 
6563         DWARFCompileUnit* dwarf_cu = NULL;
6564         const DWARFDebugInfoEntry* die = NULL;
6565 
6566         if (m_using_apple_tables)
6567         {
6568             if (m_apple_types_ap.get())
6569                 m_apple_types_ap->FindByName (name, die_offsets);
6570         }
6571         else
6572         {
6573             if (!m_indexed)
6574                 Index ();
6575 
6576             m_type_index.Find (ConstString(name), die_offsets);
6577         }
6578 
6579         const size_t num_matches = die_offsets.size();
6580 
6581         if (num_matches)
6582         {
6583             for (size_t i = 0; i < num_matches; ++i)
6584             {
6585                 const dw_offset_t die_offset = die_offsets[i];
6586                 die = info->GetDIEPtrWithCompileUnitHint (die_offset, &dwarf_cu);
6587 
6588                 if (die->GetParent() != context_die)
6589                     continue;
6590 
6591                 Type *matching_type = ResolveType (dwarf_cu, die);
6592 
6593                 lldb::clang_type_t type = matching_type->GetClangForwardType();
6594                 clang::QualType qual_type = clang::QualType::getFromOpaquePtr(type);
6595 
6596                 if (const clang::TagType *tag_type = llvm::dyn_cast<clang::TagType>(qual_type.getTypePtr()))
6597                 {
6598                     clang::TagDecl *tag_decl = tag_type->getDecl();
6599                     results->push_back(tag_decl);
6600                 }
6601                 else if (const clang::TypedefType *typedef_type = llvm::dyn_cast<clang::TypedefType>(qual_type.getTypePtr()))
6602                 {
6603                     clang::TypedefNameDecl *typedef_decl = typedef_type->getDecl();
6604                     results->push_back(typedef_decl);
6605                 }
6606             }
6607         }
6608     }
6609 }
6610 
6611 void
6612 SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton,
6613                                                  const clang::DeclContext *decl_context,
6614                                                  clang::DeclarationName decl_name,
6615                                                  llvm::SmallVectorImpl <clang::NamedDecl *> *results)
6616 {
6617 
6618     switch (decl_context->getDeclKind())
6619     {
6620     case clang::Decl::Namespace:
6621     case clang::Decl::TranslationUnit:
6622         {
6623             SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6624             symbol_file_dwarf->SearchDeclContext (decl_context, decl_name.getAsString().c_str(), results);
6625         }
6626         break;
6627     default:
6628         break;
6629     }
6630 }
6631 
6632 bool
6633 SymbolFileDWARF::LayoutRecordType (void *baton,
6634                                    const clang::RecordDecl *record_decl,
6635                                    uint64_t &size,
6636                                    uint64_t &alignment,
6637                                    llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6638                                    llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6639                                    llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6640 {
6641     SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton;
6642     return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets);
6643 }
6644 
6645 
6646 bool
6647 SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl,
6648                                    uint64_t &bit_size,
6649                                    uint64_t &alignment,
6650                                    llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets,
6651                                    llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
6652                                    llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
6653 {
6654     LogSP log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
6655     RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
6656     bool success = false;
6657     base_offsets.clear();
6658     vbase_offsets.clear();
6659     if (pos != m_record_decl_to_layout_map.end())
6660     {
6661         bit_size = pos->second.bit_size;
6662         alignment = pos->second.alignment;
6663         field_offsets.swap(pos->second.field_offsets);
6664         m_record_decl_to_layout_map.erase(pos);
6665         success = true;
6666     }
6667     else
6668     {
6669         bit_size = 0;
6670         alignment = 0;
6671         field_offsets.clear();
6672     }
6673 
6674     if (log)
6675         GetObjectFile()->GetModule()->LogMessage (log.get(),
6676                                                   "SymbolFileDWARF::LayoutRecordType (record_decl = %p, bit_size = %llu, alignment = %llu, field_offsets[%u],base_offsets[%u], vbase_offsets[%u]) success = %i",
6677                                                   record_decl,
6678                                                   bit_size,
6679                                                   alignment,
6680                                                   (uint32_t)field_offsets.size(),
6681                                                   (uint32_t)base_offsets.size(),
6682                                                   (uint32_t)vbase_offsets.size(),
6683                                                   success);
6684     return success;
6685 }
6686 
6687 
6688 
6689