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