1 //===-- SymbolFileDWARF.cpp ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "SymbolFileDWARF.h"
12 // Other libraries and framework includes
13 #include "llvm/Support/Casting.h"
15 #include "lldb/Core/ArchSpec.h"
16 #include "lldb/Core/Module.h"
17 #include "lldb/Core/ModuleList.h"
18 #include "lldb/Core/ModuleSpec.h"
19 #include "lldb/Core/PluginManager.h"
20 #include "lldb/Core/RegularExpression.h"
21 #include "lldb/Core/Scalar.h"
22 #include "lldb/Core/Section.h"
23 #include "lldb/Core/StreamFile.h"
24 #include "lldb/Core/StreamString.h"
25 #include "lldb/Core/Timer.h"
26 #include "lldb/Core/Value.h"
28 #include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
30 #include "lldb/Host/FileSystem.h"
31 #include "lldb/Host/Host.h"
33 #include "lldb/Interpreter/OptionValueFileSpecList.h"
34 #include "lldb/Interpreter/OptionValueProperties.h"
36 #include "lldb/Symbol/Block.h"
37 #include "lldb/Symbol/ClangASTContext.h"
38 #include "lldb/Symbol/CompilerDecl.h"
39 #include "lldb/Symbol/CompilerDeclContext.h"
40 #include "lldb/Symbol/CompileUnit.h"
41 #include "lldb/Symbol/LineTable.h"
42 #include "lldb/Symbol/DebugMacros.h"
43 #include "lldb/Symbol/ObjectFile.h"
44 #include "lldb/Symbol/SymbolVendor.h"
45 #include "lldb/Symbol/TypeSystem.h"
46 #include "lldb/Symbol/VariableList.h"
47 #include "lldb/Symbol/TypeMap.h"
49 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
50 #include "Plugins/Language/ObjC/ObjCLanguage.h"
52 #include "lldb/Target/Language.h"
54 #include "lldb/Utility/TaskPool.h"
56 #include "DWARFASTParser.h"
57 #include "DWARFCompileUnit.h"
58 #include "DWARFDebugAbbrev.h"
59 #include "DWARFDebugAranges.h"
60 #include "DWARFDebugInfo.h"
61 #include "DWARFDebugLine.h"
62 #include "DWARFDebugMacro.h"
63 #include "DWARFDebugPubnames.h"
64 #include "DWARFDebugRanges.h"
65 #include "DWARFDeclContext.h"
66 #include "DWARFDIECollection.h"
67 #include "DWARFFormValue.h"
68 #include "LogChannelDWARF.h"
69 #include "SymbolFileDWARFDwo.h"
70 #include "SymbolFileDWARFDebugMap.h"
77 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
79 #ifdef ENABLE_DEBUG_PRINTF
81 #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
83 #define DEBUG_PRINTF(fmt, ...)
87 using namespace lldb_private;
90 //child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
96 // case DW_TAG_subprogram:
97 // case DW_TAG_inlined_subroutine:
98 // case DW_TAG_class_type:
99 // case DW_TAG_structure_type:
100 // case DW_TAG_union_type:
112 { "comp-dir-symlink-paths" , OptionValue::eTypeFileSpecList, true, 0 , nullptr, nullptr, "If the DW_AT_comp_dir matches any of these paths the symbolic links will be resolved at DWARF parse time." },
113 { nullptr , OptionValue::eTypeInvalid , false, 0, nullptr, nullptr, nullptr }
118 ePropertySymLinkPaths
122 class PluginProperties : public Properties
128 return SymbolFileDWARF::GetPluginNameStatic();
133 m_collection_sp.reset (new OptionValueProperties(GetSettingName()));
134 m_collection_sp->Initialize(g_properties);
140 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, true, ePropertySymLinkPaths);
141 assert(option_value);
142 return option_value->GetCurrentValue();
147 typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
149 static const SymbolFileDWARFPropertiesSP&
150 GetGlobalPluginProperties()
152 static const auto g_settings_sp(std::make_shared<PluginProperties>());
153 return g_settings_sp;
156 } // anonymous namespace end
160 removeHostnameFromPathname(const char* path_from_dwarf)
162 if (!path_from_dwarf || !path_from_dwarf[0])
164 return path_from_dwarf;
167 const char *colon_pos = strchr(path_from_dwarf, ':');
168 if (nullptr == colon_pos)
170 return path_from_dwarf;
173 const char *slash_pos = strchr(path_from_dwarf, '/');
174 if (slash_pos && (slash_pos < colon_pos))
176 return path_from_dwarf;
179 // check whether we have a windows path, and so the first character
180 // is a drive-letter not a hostname.
182 colon_pos == path_from_dwarf + 1 &&
183 isalpha(*path_from_dwarf) &&
184 strlen(path_from_dwarf) > 2 &&
185 '\\' == path_from_dwarf[2])
187 return path_from_dwarf;
190 return colon_pos + 1;
194 resolveCompDir(const char* path_from_dwarf)
196 if (!path_from_dwarf)
199 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
200 // Remove the host part if present.
201 const char* local_path = removeHostnameFromPathname(path_from_dwarf);
205 bool is_symlink = false;
206 FileSpec local_path_spec(local_path, false);
207 const auto& file_specs = GetGlobalPluginProperties()->GetSymLinkPaths();
208 for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i)
209 is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i), local_path_spec, true);
214 if (!local_path_spec.IsSymbolicLink())
217 FileSpec resolved_local_path_spec;
218 const auto error = FileSystem::Readlink(local_path_spec, resolved_local_path_spec);
220 return resolved_local_path_spec.GetCString();
227 SymbolFileDWARF::Initialize()
229 LogChannelDWARF::Initialize();
230 PluginManager::RegisterPlugin (GetPluginNameStatic(),
231 GetPluginDescriptionStatic(),
237 SymbolFileDWARF::DebuggerInitialize(Debugger &debugger)
239 if (!PluginManager::GetSettingForSymbolFilePlugin(debugger, PluginProperties::GetSettingName()))
241 const bool is_global_setting = true;
242 PluginManager::CreateSettingForSymbolFilePlugin(debugger,
243 GetGlobalPluginProperties()->GetValueProperties(),
244 ConstString ("Properties for the dwarf symbol-file plug-in."),
250 SymbolFileDWARF::Terminate()
252 PluginManager::UnregisterPlugin (CreateInstance);
253 LogChannelDWARF::Initialize();
257 lldb_private::ConstString
258 SymbolFileDWARF::GetPluginNameStatic()
260 static ConstString g_name("dwarf");
265 SymbolFileDWARF::GetPluginDescriptionStatic()
267 return "DWARF and DWARF3 debug symbol file reader.";
272 SymbolFileDWARF::CreateInstance (ObjectFile* obj_file)
274 return new SymbolFileDWARF(obj_file);
278 SymbolFileDWARF::GetTypeList ()
280 if (GetDebugMapSymfile ())
281 return m_debug_map_symfile->GetTypeList();
282 return m_obj_file->GetModule()->GetTypeList();
286 SymbolFileDWARF::GetTypes (const DWARFDIE &die,
287 dw_offset_t min_die_offset,
288 dw_offset_t max_die_offset,
294 const dw_offset_t die_offset = die.GetOffset();
296 if (die_offset >= max_die_offset)
299 if (die_offset >= min_die_offset)
301 const dw_tag_t tag = die.Tag();
303 bool add_type = false;
307 case DW_TAG_array_type: add_type = (type_mask & eTypeClassArray ) != 0; break;
308 case DW_TAG_unspecified_type:
309 case DW_TAG_base_type: add_type = (type_mask & eTypeClassBuiltin ) != 0; break;
310 case DW_TAG_class_type: add_type = (type_mask & eTypeClassClass ) != 0; break;
311 case DW_TAG_structure_type: add_type = (type_mask & eTypeClassStruct ) != 0; break;
312 case DW_TAG_union_type: add_type = (type_mask & eTypeClassUnion ) != 0; break;
313 case DW_TAG_enumeration_type: add_type = (type_mask & eTypeClassEnumeration ) != 0; break;
314 case DW_TAG_subroutine_type:
315 case DW_TAG_subprogram:
316 case DW_TAG_inlined_subroutine: add_type = (type_mask & eTypeClassFunction ) != 0; break;
317 case DW_TAG_pointer_type: add_type = (type_mask & eTypeClassPointer ) != 0; break;
318 case DW_TAG_rvalue_reference_type:
319 case DW_TAG_reference_type: add_type = (type_mask & eTypeClassReference ) != 0; break;
320 case DW_TAG_typedef: add_type = (type_mask & eTypeClassTypedef ) != 0; break;
321 case DW_TAG_ptr_to_member_type: add_type = (type_mask & eTypeClassMemberPointer ) != 0; break;
326 const bool assert_not_being_parsed = true;
327 Type *type = ResolveTypeUID (die, assert_not_being_parsed);
330 if (type_set.find(type) == type_set.end())
331 type_set.insert(type);
336 for (DWARFDIE child_die = die.GetFirstChild();
338 child_die = child_die.GetSibling())
340 GetTypes (child_die, min_die_offset, max_die_offset, type_mask, type_set);
346 SymbolFileDWARF::GetTypes (SymbolContextScope *sc_scope,
353 CompileUnit *comp_unit = NULL;
354 DWARFCompileUnit* dwarf_cu = NULL;
356 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
360 dwarf_cu = GetDWARFCompileUnit(comp_unit);
363 GetTypes (dwarf_cu->DIE(),
364 dwarf_cu->GetOffset(),
365 dwarf_cu->GetNextCompileUnitOffset(),
371 DWARFDebugInfo* info = DebugInfo();
374 const size_t num_cus = info->GetNumCompileUnits();
375 for (size_t cu_idx=0; cu_idx<num_cus; ++cu_idx)
377 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
380 GetTypes (dwarf_cu->DIE(),
390 std::set<CompilerType> compiler_type_set;
391 size_t num_types_added = 0;
392 for (Type *type : type_set)
394 CompilerType compiler_type = type->GetForwardCompilerType ();
395 if (compiler_type_set.find(compiler_type) == compiler_type_set.end())
397 compiler_type_set.insert(compiler_type);
398 type_list.Insert (type->shared_from_this());
402 return num_types_added;
406 //----------------------------------------------------------------------
407 // Gets the first parent that is a lexical block, function or inlined
408 // subroutine, or compile unit.
409 //----------------------------------------------------------------------
411 SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die)
414 for (die = child_die.GetParent(); die; die = die.GetParent())
416 dw_tag_t tag = die.Tag();
420 case DW_TAG_compile_unit:
421 case DW_TAG_subprogram:
422 case DW_TAG_inlined_subroutine:
423 case DW_TAG_lexical_block:
431 SymbolFileDWARF::SymbolFileDWARF(ObjectFile* objfile) :
432 SymbolFile (objfile),
433 UserID (0), // Used by SymbolFileDWARFDebugMap to when this class parses .o files to contain the .o file index/ID
434 m_debug_map_module_wp (),
435 m_debug_map_symfile (NULL),
436 m_data_debug_abbrev (),
437 m_data_debug_aranges (),
438 m_data_debug_frame (),
439 m_data_debug_info (),
440 m_data_debug_line (),
441 m_data_debug_macro (),
443 m_data_debug_ranges (),
445 m_data_apple_names (),
446 m_data_apple_types (),
447 m_data_apple_namespaces (),
453 m_apple_namespaces_ap (),
455 m_function_basename_index(),
456 m_function_fullname_index(),
457 m_function_method_index(),
458 m_function_selector_index(),
459 m_objc_class_selectors_index(),
464 m_using_apple_tables (false),
465 m_fetched_external_modules (false),
466 m_supports_DW_AT_APPLE_objc_complete_type (eLazyBoolCalculate),
468 m_unique_ast_type_map ()
472 SymbolFileDWARF::~SymbolFileDWARF()
476 static const ConstString &
477 GetDWARFMachOSegmentName ()
479 static ConstString g_dwarf_section_name ("__DWARF");
480 return g_dwarf_section_name;
483 UniqueDWARFASTTypeMap &
484 SymbolFileDWARF::GetUniqueDWARFASTTypeMap ()
486 if (GetDebugMapSymfile ())
487 return m_debug_map_symfile->GetUniqueDWARFASTTypeMap ();
488 return m_unique_ast_type_map;
492 SymbolFileDWARF::GetTypeSystemForLanguage (LanguageType language)
494 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
495 TypeSystem *type_system;
496 if (debug_map_symfile)
498 type_system = debug_map_symfile->GetTypeSystemForLanguage(language);
502 type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
504 type_system->SetSymbolFile(this);
510 SymbolFileDWARF::InitializeObject()
512 ModuleSP module_sp (m_obj_file->GetModule());
515 const SectionList *section_list = module_sp->GetSectionList();
516 const Section* section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
518 // Memory map the DWARF mach-o segment so we have everything mmap'ed
519 // to keep our heap memory usage down.
521 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
524 get_apple_names_data();
525 if (m_data_apple_names.m_data.GetByteSize() > 0)
527 m_apple_names_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_names.m_data,
528 get_debug_str_data(),
530 if (m_apple_names_ap->IsValid())
531 m_using_apple_tables = true;
533 m_apple_names_ap.reset();
535 get_apple_types_data();
536 if (m_data_apple_types.m_data.GetByteSize() > 0)
538 m_apple_types_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_types.m_data,
539 get_debug_str_data(),
541 if (m_apple_types_ap->IsValid())
542 m_using_apple_tables = true;
544 m_apple_types_ap.reset();
547 get_apple_namespaces_data();
548 if (m_data_apple_namespaces.m_data.GetByteSize() > 0)
550 m_apple_namespaces_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_namespaces.m_data,
551 get_debug_str_data(),
552 ".apple_namespaces"));
553 if (m_apple_namespaces_ap->IsValid())
554 m_using_apple_tables = true;
556 m_apple_namespaces_ap.reset();
559 get_apple_objc_data();
560 if (m_data_apple_objc.m_data.GetByteSize() > 0)
562 m_apple_objc_ap.reset (new DWARFMappedHash::MemoryTable (m_data_apple_objc.m_data,
563 get_debug_str_data(),
565 if (m_apple_objc_ap->IsValid())
566 m_using_apple_tables = true;
568 m_apple_objc_ap.reset();
573 SymbolFileDWARF::SupportedVersion(uint16_t version)
575 return version == 2 || version == 3 || version == 4;
579 SymbolFileDWARF::CalculateAbilities ()
581 uint32_t abilities = 0;
582 if (m_obj_file != NULL)
584 const Section* section = NULL;
585 const SectionList *section_list = m_obj_file->GetSectionList();
586 if (section_list == NULL)
589 uint64_t debug_abbrev_file_size = 0;
590 uint64_t debug_info_file_size = 0;
591 uint64_t debug_line_file_size = 0;
593 section = section_list->FindSectionByName(GetDWARFMachOSegmentName ()).get();
596 section_list = §ion->GetChildren ();
598 section = section_list->FindSectionByType (eSectionTypeDWARFDebugInfo, true).get();
601 debug_info_file_size = section->GetFileSize();
603 section = section_list->FindSectionByType (eSectionTypeDWARFDebugAbbrev, true).get();
605 debug_abbrev_file_size = section->GetFileSize();
607 section = section_list->FindSectionByType (eSectionTypeDWARFDebugLine, true).get();
609 debug_line_file_size = section->GetFileSize();
613 const char *symfile_dir_cstr = m_obj_file->GetFileSpec().GetDirectory().GetCString();
614 if (symfile_dir_cstr)
616 if (strcasestr(symfile_dir_cstr, ".dsym"))
618 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo)
620 // We have a dSYM file that didn't have a any debug info.
621 // If the string table has a size of 1, then it was made from
622 // an executable with no debug info, or from an executable that
624 section = section_list->FindSectionByType (eSectionTypeDWARFDebugStr, true).get();
625 if (section && section->GetFileSize() == 1)
627 m_obj_file->GetModule()->ReportWarning ("empty dSYM file detected, dSYM was created with an executable with no debug info.");
634 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
635 abilities |= CompileUnits | Functions | Blocks | GlobalVariables | LocalVariables | VariableTypes;
637 if (debug_line_file_size > 0)
638 abilities |= LineTables;
643 const DWARFDataExtractor&
644 SymbolFileDWARF::GetCachedSectionData (lldb::SectionType sect_type, DWARFDataSegment& data_segment)
646 std::call_once(data_segment.m_flag,
647 &SymbolFileDWARF::LoadSectionData,
650 std::ref(data_segment.m_data));
651 return data_segment.m_data;
655 SymbolFileDWARF::LoadSectionData (lldb::SectionType sect_type, DWARFDataExtractor& data)
657 ModuleSP module_sp (m_obj_file->GetModule());
658 const SectionList *section_list = module_sp->GetSectionList();
661 SectionSP section_sp (section_list->FindSectionByType(sect_type, true));
664 // See if we memory mapped the DWARF segment?
665 if (m_dwarf_data.GetByteSize())
667 data.SetData(m_dwarf_data, section_sp->GetOffset(), section_sp->GetFileSize());
671 if (m_obj_file->ReadSectionData(section_sp.get(), data) == 0)
678 const DWARFDataExtractor&
679 SymbolFileDWARF::get_debug_abbrev_data()
681 return GetCachedSectionData (eSectionTypeDWARFDebugAbbrev, m_data_debug_abbrev);
684 const DWARFDataExtractor&
685 SymbolFileDWARF::get_debug_addr_data()
687 return GetCachedSectionData (eSectionTypeDWARFDebugAddr, m_data_debug_addr);
690 const DWARFDataExtractor&
691 SymbolFileDWARF::get_debug_aranges_data()
693 return GetCachedSectionData (eSectionTypeDWARFDebugAranges, m_data_debug_aranges);
696 const DWARFDataExtractor&
697 SymbolFileDWARF::get_debug_frame_data()
699 return GetCachedSectionData (eSectionTypeDWARFDebugFrame, m_data_debug_frame);
702 const DWARFDataExtractor&
703 SymbolFileDWARF::get_debug_info_data()
705 return GetCachedSectionData (eSectionTypeDWARFDebugInfo, m_data_debug_info);
708 const DWARFDataExtractor&
709 SymbolFileDWARF::get_debug_line_data()
711 return GetCachedSectionData (eSectionTypeDWARFDebugLine, m_data_debug_line);
714 const DWARFDataExtractor&
715 SymbolFileDWARF::get_debug_macro_data()
717 return GetCachedSectionData (eSectionTypeDWARFDebugMacro, m_data_debug_macro);
720 const DWARFDataExtractor&
721 SymbolFileDWARF::get_debug_loc_data()
723 return GetCachedSectionData (eSectionTypeDWARFDebugLoc, m_data_debug_loc);
726 const DWARFDataExtractor&
727 SymbolFileDWARF::get_debug_ranges_data()
729 return GetCachedSectionData (eSectionTypeDWARFDebugRanges, m_data_debug_ranges);
732 const DWARFDataExtractor&
733 SymbolFileDWARF::get_debug_str_data()
735 return GetCachedSectionData (eSectionTypeDWARFDebugStr, m_data_debug_str);
738 const DWARFDataExtractor&
739 SymbolFileDWARF::get_debug_str_offsets_data()
741 return GetCachedSectionData (eSectionTypeDWARFDebugStrOffsets, m_data_debug_str_offsets);
744 const DWARFDataExtractor&
745 SymbolFileDWARF::get_apple_names_data()
747 return GetCachedSectionData (eSectionTypeDWARFAppleNames, m_data_apple_names);
750 const DWARFDataExtractor&
751 SymbolFileDWARF::get_apple_types_data()
753 return GetCachedSectionData (eSectionTypeDWARFAppleTypes, m_data_apple_types);
756 const DWARFDataExtractor&
757 SymbolFileDWARF::get_apple_namespaces_data()
759 return GetCachedSectionData (eSectionTypeDWARFAppleNamespaces, m_data_apple_namespaces);
762 const DWARFDataExtractor&
763 SymbolFileDWARF::get_apple_objc_data()
765 return GetCachedSectionData (eSectionTypeDWARFAppleObjC, m_data_apple_objc);
770 SymbolFileDWARF::DebugAbbrev()
772 if (m_abbr.get() == NULL)
774 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
775 if (debug_abbrev_data.GetByteSize() > 0)
777 m_abbr.reset(new DWARFDebugAbbrev());
779 m_abbr->Parse(debug_abbrev_data);
785 const DWARFDebugAbbrev*
786 SymbolFileDWARF::DebugAbbrev() const
793 SymbolFileDWARF::DebugInfo()
795 if (m_info.get() == NULL)
797 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
798 __PRETTY_FUNCTION__, static_cast<void*>(this));
799 if (get_debug_info_data().GetByteSize() > 0)
801 m_info.reset(new DWARFDebugInfo());
804 m_info->SetDwarfData(this);
811 const DWARFDebugInfo*
812 SymbolFileDWARF::DebugInfo() const
818 SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit)
823 DWARFDebugInfo* info = DebugInfo();
826 if (GetDebugMapSymfile ())
828 // The debug map symbol file made the compile units for this DWARF
829 // file which is .o file with DWARF in it, and we should have
830 // only 1 compile unit which is at offset zero in the DWARF.
831 // TODO: modify to support LTO .o files where each .o file might
832 // have multiple DW_TAG_compile_unit tags.
834 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(0);
835 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
836 dwarf_cu->SetUserData(comp_unit);
841 // Just a normal DWARF file whose user ID for the compile unit is
842 // the DWARF offset itself
844 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit((dw_offset_t)comp_unit->GetID());
845 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
846 dwarf_cu->SetUserData(comp_unit);
856 SymbolFileDWARF::DebugRanges()
858 if (m_ranges.get() == NULL)
860 Timer scoped_timer(__PRETTY_FUNCTION__, "%s this = %p",
861 __PRETTY_FUNCTION__, static_cast<void*>(this));
862 if (get_debug_ranges_data().GetByteSize() > 0)
864 m_ranges.reset(new DWARFDebugRanges());
866 m_ranges->Extract(this);
869 return m_ranges.get();
872 const DWARFDebugRanges*
873 SymbolFileDWARF::DebugRanges() const
875 return m_ranges.get();
879 SymbolFileDWARF::ParseCompileUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
884 CompileUnit *comp_unit = (CompileUnit*)dwarf_cu->GetUserData();
887 // We already parsed this compile unit, had out a shared pointer to it
888 cu_sp = comp_unit->shared_from_this();
892 if (dwarf_cu->GetSymbolFileDWARF() != this)
894 return dwarf_cu->GetSymbolFileDWARF()->ParseCompileUnit(dwarf_cu, cu_idx);
896 else if (GetDebugMapSymfile ())
898 // Let the debug map create the compile unit
899 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
900 dwarf_cu->SetUserData(cu_sp.get());
904 ModuleSP module_sp (m_obj_file->GetModule());
907 const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly ();
910 FileSpec cu_file_spec{cu_die.GetName(), false};
913 // If we have a full path to the compile unit, we don't need to resolve
914 // the file. This can be expensive e.g. when the source files are NFS mounted.
915 if (cu_file_spec.IsRelative())
917 const char *cu_comp_dir{cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr)};
918 cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir));
921 std::string remapped_file;
922 if (module_sp->RemapSourceFile(cu_file_spec.GetCString(), remapped_file))
923 cu_file_spec.SetFile(remapped_file, false);
926 LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0));
928 bool is_optimized = dwarf_cu->GetIsOptimized ();
929 cu_sp.reset(new CompileUnit (module_sp,
937 // If we just created a compile unit with an invalid file spec, try and get the
938 // first entry in the supports files from the line table as that should be the
942 cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1);
945 (FileSpec &)(*cu_sp) = cu_file_spec;
946 // Also fix the invalid file spec which was copied from the compile unit.
947 cu_sp->GetSupportFiles().Replace(0, cu_file_spec);
951 dwarf_cu->SetUserData(cu_sp.get());
953 // Figure out the compile unit index if we weren't given one
954 if (cu_idx == UINT32_MAX)
955 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
957 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(cu_idx, cu_sp);
968 SymbolFileDWARF::GetNumCompileUnits()
970 DWARFDebugInfo* info = DebugInfo();
972 return info->GetNumCompileUnits();
977 SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx)
980 DWARFDebugInfo* info = DebugInfo();
983 DWARFCompileUnit* dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
985 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
991 SymbolFileDWARF::ParseCompileUnitFunction (const SymbolContext& sc, const DWARFDIE &die)
995 TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
999 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
1001 return dwarf_ast->ParseFunctionFromDWARF(sc, die);
1008 SymbolFileDWARF::FixupAddress (Address &addr)
1010 SymbolFileDWARFDebugMap * debug_map_symfile = GetDebugMapSymfile ();
1011 if (debug_map_symfile)
1013 return debug_map_symfile->LinkOSOAddress(addr);
1015 // This is a normal DWARF file, no address fixups need to happen
1019 SymbolFileDWARF::ParseCompileUnitLanguage (const SymbolContext& sc)
1021 assert (sc.comp_unit);
1022 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1024 return dwarf_cu->GetLanguageType();
1026 return eLanguageTypeUnknown;
1030 SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc)
1032 assert (sc.comp_unit);
1033 size_t functions_added = 0;
1034 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1037 DWARFDIECollection function_dies;
1038 const size_t num_functions = dwarf_cu->AppendDIEsWithTag (DW_TAG_subprogram, function_dies);
1040 for (func_idx = 0; func_idx < num_functions; ++func_idx)
1042 DWARFDIE die = function_dies.GetDIEAtIndex(func_idx);
1043 if (sc.comp_unit->FindFunctionByUID (die.GetID()).get() == NULL)
1045 if (ParseCompileUnitFunction(sc, die))
1051 return functions_added;
1055 SymbolFileDWARF::ParseCompileUnitSupportFiles (const SymbolContext& sc, FileSpecList& support_files)
1057 assert (sc.comp_unit);
1058 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1061 const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1065 const char * cu_comp_dir = resolveCompDir(cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr));
1067 const dw_offset_t stmt_list = cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, DW_INVALID_OFFSET);
1068 if (stmt_list != DW_INVALID_OFFSET)
1070 // All file indexes in DWARF are one based and a file of index zero is
1071 // supposed to be the compile unit itself.
1072 support_files.Append (*sc.comp_unit);
1073 return DWARFDebugLine::ParseSupportFiles(sc.comp_unit->GetModule(),
1074 get_debug_line_data(),
1085 SymbolFileDWARF::ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules)
1087 assert (sc.comp_unit);
1088 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1091 if (ClangModulesDeclVendor::LanguageSupportsClangModules(sc.comp_unit->GetLanguage()))
1093 UpdateExternalModuleListIfNeeded();
1094 for (const auto &pair : m_external_type_modules)
1096 imported_modules.push_back(pair.first);
1103 struct ParseDWARFLineTableCallbackInfo
1105 LineTable* line_table;
1106 std::unique_ptr<LineSequence> sequence_ap;
1107 lldb::addr_t addr_mask;
1110 //----------------------------------------------------------------------
1111 // ParseStatementTableCallback
1112 //----------------------------------------------------------------------
1114 ParseDWARFLineTableCallback(dw_offset_t offset, const DWARFDebugLine::State& state, void* userData)
1116 if (state.row == DWARFDebugLine::State::StartParsingLineTable)
1118 // Just started parsing the line table
1120 else if (state.row == DWARFDebugLine::State::DoneParsingLineTable)
1122 // Done parsing line table, nothing to do for the cleanup
1126 ParseDWARFLineTableCallbackInfo* info = (ParseDWARFLineTableCallbackInfo*)userData;
1127 LineTable* line_table = info->line_table;
1129 // If this is our first time here, we need to create a
1130 // sequence container.
1131 if (!info->sequence_ap.get())
1133 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
1134 assert(info->sequence_ap.get());
1136 line_table->AppendLineEntryToSequence (info->sequence_ap.get(),
1137 state.address & info->addr_mask,
1144 state.epilogue_begin,
1145 state.end_sequence);
1146 if (state.end_sequence)
1148 // First, put the current sequence into the line table.
1149 line_table->InsertSequence(info->sequence_ap.get());
1150 // Then, empty it to prepare for the next sequence.
1151 info->sequence_ap->Clear();
1157 SymbolFileDWARF::ParseCompileUnitLineTable (const SymbolContext &sc)
1159 assert (sc.comp_unit);
1160 if (sc.comp_unit->GetLineTable() != NULL)
1163 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1166 const DWARFDIE dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1169 const dw_offset_t cu_line_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list, DW_INVALID_OFFSET);
1170 if (cu_line_offset != DW_INVALID_OFFSET)
1172 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
1173 if (line_table_ap.get())
1175 ParseDWARFLineTableCallbackInfo info;
1176 info.line_table = line_table_ap.get();
1180 * The SymbolContext may not have a valid target, thus we may not be able
1181 * to call Address::GetOpcodeLoadAddress() which would clear the bit #0
1182 * for MIPS. Use ArchSpec to clear the bit #0.
1185 GetObjectFile()->GetArchitecture(arch);
1186 switch (arch.GetMachine())
1188 case llvm::Triple::mips:
1189 case llvm::Triple::mipsel:
1190 case llvm::Triple::mips64:
1191 case llvm::Triple::mips64el:
1192 info.addr_mask = ~((lldb::addr_t)1);
1195 info.addr_mask = ~((lldb::addr_t)0);
1199 lldb::offset_t offset = cu_line_offset;
1200 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset, ParseDWARFLineTableCallback, &info);
1201 if (m_debug_map_symfile)
1203 // We have an object file that has a line table with addresses
1204 // that are not linked. We need to link the line table and convert
1205 // the addresses that are relative to the .o file into addresses
1206 // for the main executable.
1207 sc.comp_unit->SetLineTable (m_debug_map_symfile->LinkOSOLineTable (this, line_table_ap.get()));
1211 sc.comp_unit->SetLineTable(line_table_ap.release());
1221 lldb_private::DebugMacrosSP
1222 SymbolFileDWARF::ParseDebugMacros(lldb::offset_t *offset)
1224 auto iter = m_debug_macros_map.find(*offset);
1225 if (iter != m_debug_macros_map.end())
1226 return iter->second;
1228 const DWARFDataExtractor &debug_macro_data = get_debug_macro_data();
1229 if (debug_macro_data.GetByteSize() == 0)
1230 return DebugMacrosSP();
1232 lldb_private::DebugMacrosSP debug_macros_sp(new lldb_private::DebugMacros());
1233 m_debug_macros_map[*offset] = debug_macros_sp;
1235 const DWARFDebugMacroHeader &header = DWARFDebugMacroHeader::ParseHeader(debug_macro_data, offset);
1236 DWARFDebugMacroEntry::ReadMacroEntries(
1237 debug_macro_data, get_debug_str_data(), header.OffsetIs64Bit(), offset, this, debug_macros_sp);
1239 return debug_macros_sp;
1243 SymbolFileDWARF::ParseCompileUnitDebugMacros(const SymbolContext& sc)
1245 assert (sc.comp_unit);
1247 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1248 if (dwarf_cu == nullptr)
1251 const DWARFDIE dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1255 lldb::offset_t sect_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_macros, DW_INVALID_OFFSET);
1256 if (sect_offset == DW_INVALID_OFFSET)
1257 sect_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_GNU_macros, DW_INVALID_OFFSET);
1258 if (sect_offset == DW_INVALID_OFFSET)
1261 sc.comp_unit->SetDebugMacros(ParseDebugMacros(§_offset));
1267 SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext& sc,
1268 Block *parent_block,
1269 const DWARFDIE &orig_die,
1270 addr_t subprogram_low_pc,
1273 size_t blocks_added = 0;
1274 DWARFDIE die = orig_die;
1277 dw_tag_t tag = die.Tag();
1281 case DW_TAG_inlined_subroutine:
1282 case DW_TAG_subprogram:
1283 case DW_TAG_lexical_block:
1285 Block *block = NULL;
1286 if (tag == DW_TAG_subprogram)
1288 // Skip any DW_TAG_subprogram DIEs that are inside
1289 // of a normal or inlined functions. These will be
1290 // parsed on their own as separate entities.
1295 block = parent_block;
1299 BlockSP block_sp(new Block (die.GetID()));
1300 parent_block->AddChild(block_sp);
1301 block = block_sp.get();
1303 DWARFRangeList ranges;
1304 const char *name = NULL;
1305 const char *mangled_name = NULL;
1309 int decl_column = 0;
1312 int call_column = 0;
1313 if (die.GetDIENamesAndRanges (name,
1316 decl_file, decl_line, decl_column,
1317 call_file, call_line, call_column, nullptr))
1319 if (tag == DW_TAG_subprogram)
1321 assert (subprogram_low_pc == LLDB_INVALID_ADDRESS);
1322 subprogram_low_pc = ranges.GetMinRangeBase(0);
1324 else if (tag == DW_TAG_inlined_subroutine)
1326 // We get called here for inlined subroutines in two ways.
1327 // The first time is when we are making the Function object
1328 // for this inlined concrete instance. Since we're creating a top level block at
1329 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we need to
1330 // adjust the containing address.
1331 // The second time is when we are parsing the blocks inside the function that contains
1332 // the inlined concrete instance. Since these will be blocks inside the containing "real"
1333 // function the offset will be for that function.
1334 if (subprogram_low_pc == LLDB_INVALID_ADDRESS)
1336 subprogram_low_pc = ranges.GetMinRangeBase(0);
1340 const size_t num_ranges = ranges.GetSize();
1341 for (size_t i = 0; i<num_ranges; ++i)
1343 const DWARFRangeList::Entry &range = ranges.GetEntryRef (i);
1344 const addr_t range_base = range.GetRangeBase();
1345 if (range_base >= subprogram_low_pc)
1346 block->AddRange(Block::Range (range_base - subprogram_low_pc, range.GetByteSize()));
1349 GetObjectFile()->GetModule()->ReportError ("0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64 ") which has a base that is less than the function's low PC 0x%" PRIx64 ". Please file a bug and attach the file at the start of this error message",
1352 range.GetRangeEnd(),
1356 block->FinalizeRanges ();
1358 if (tag != DW_TAG_subprogram && (name != NULL || mangled_name != NULL))
1360 std::unique_ptr<Declaration> decl_ap;
1361 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1362 decl_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1363 decl_line, decl_column));
1365 std::unique_ptr<Declaration> call_ap;
1366 if (call_file != 0 || call_line != 0 || call_column != 0)
1367 call_ap.reset(new Declaration(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1368 call_line, call_column));
1370 block->SetInlinedFunctionInfo (name, mangled_name, decl_ap.get(), call_ap.get());
1375 if (die.HasChildren())
1377 blocks_added += ParseFunctionBlocks (sc,
1379 die.GetFirstChild(),
1390 // Only parse siblings of the block if we are not at depth zero. A depth
1391 // of zero indicates we are currently parsing the top level
1392 // DW_TAG_subprogram DIE
1397 die = die.GetSibling();
1399 return blocks_added;
1403 SymbolFileDWARF::ClassOrStructIsVirtual (const DWARFDIE &parent_die)
1407 for (DWARFDIE die = parent_die.GetFirstChild(); die; die = die.GetSibling())
1409 dw_tag_t tag = die.Tag();
1410 bool check_virtuality = false;
1413 case DW_TAG_inheritance:
1414 case DW_TAG_subprogram:
1415 check_virtuality = true;
1420 if (check_virtuality)
1422 if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0)
1431 SymbolFileDWARF::ParseDeclsForContext (CompilerDeclContext decl_ctx)
1433 TypeSystem *type_system = decl_ctx.GetTypeSystem();
1434 DWARFASTParser *ast_parser = type_system->GetDWARFParser();
1435 std::vector<DWARFDIE> decl_ctx_die_list = ast_parser->GetDIEForDeclContext(decl_ctx);
1437 for (DWARFDIE decl_ctx_die : decl_ctx_die_list)
1438 for (DWARFDIE decl = decl_ctx_die.GetFirstChild(); decl; decl = decl.GetSibling())
1439 ast_parser->GetDeclForUIDFromDWARF(decl);
1443 SymbolFileDWARF::GetDeclForUID (lldb::user_id_t type_uid)
1445 if (UserIDMatches(type_uid))
1447 DWARFDebugInfo* debug_info = DebugInfo();
1450 DWARFDIE die = debug_info->GetDIE(DIERef(type_uid));
1453 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
1455 return dwarf_ast->GetDeclForUIDFromDWARF(die);
1459 return CompilerDecl();
1463 SymbolFileDWARF::GetDeclContextForUID (lldb::user_id_t type_uid)
1465 if (UserIDMatches(type_uid))
1467 DWARFDebugInfo* debug_info = DebugInfo();
1470 DWARFDIE die = debug_info->GetDIE(DIERef(type_uid));
1473 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
1475 return dwarf_ast->GetDeclContextForUIDFromDWARF(die);
1479 return CompilerDeclContext();
1483 SymbolFileDWARF::GetDeclContextContainingUID (lldb::user_id_t type_uid)
1485 if (UserIDMatches(type_uid))
1487 DWARFDebugInfo* debug_info = DebugInfo();
1490 DWARFDIE die = debug_info->GetDIE(DIERef(type_uid));
1493 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
1495 return dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
1499 return CompilerDeclContext();
1504 SymbolFileDWARF::ResolveTypeUID (lldb::user_id_t type_uid)
1506 if (UserIDMatches(type_uid))
1508 DWARFDebugInfo* debug_info = DebugInfo();
1511 DWARFDIE type_die = debug_info->GetDIE (DIERef(type_uid));
1514 const bool assert_not_being_parsed = true;
1515 return ResolveTypeUID (type_die, assert_not_being_parsed);
1523 SymbolFileDWARF::ResolveTypeUID (const DWARFDIE &die, bool assert_not_being_parsed)
1527 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1529 GetObjectFile()->GetModule()->LogMessage (log,
1530 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1532 die.GetTagAsCString(),
1535 // We might be coming in in the middle of a type tree (a class
1536 // withing a class, an enum within a class), so parse any needed
1537 // parent DIEs before we get to this one...
1538 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE (die);
1543 switch (decl_ctx_die.Tag())
1545 case DW_TAG_structure_type:
1546 case DW_TAG_union_type:
1547 case DW_TAG_class_type:
1549 // Get the type, which could be a forward declaration
1551 GetObjectFile()->GetModule()->LogMessage (log,
1552 "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' resolve parent forward type for 0x%8.8x",
1554 die.GetTagAsCString(),
1556 decl_ctx_die.GetOffset());
1565 return ResolveType (die);
1570 // This function is used when SymbolFileDWARFDebugMap owns a bunch of
1571 // SymbolFileDWARF objects to detect if this DWARF file is the one that
1572 // can resolve a compiler_type.
1574 SymbolFileDWARF::HasForwardDeclForClangType (const CompilerType &compiler_type)
1576 CompilerType compiler_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(compiler_type);
1577 if (GetForwardDeclClangTypeToDie().count (compiler_type_no_qualifiers.GetOpaqueQualType()))
1581 TypeSystem *type_system = compiler_type.GetTypeSystem();
1584 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
1586 return dwarf_ast->CanCompleteType(compiler_type);
1593 SymbolFileDWARF::CompleteType (CompilerType &compiler_type)
1595 TypeSystem *type_system = compiler_type.GetTypeSystem();
1598 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
1599 if (dwarf_ast && dwarf_ast->CanCompleteType(compiler_type))
1600 return dwarf_ast->CompleteType(compiler_type);
1603 // We have a struct/union/class/enum that needs to be fully resolved.
1604 CompilerType compiler_type_no_qualifiers = ClangASTContext::RemoveFastQualifiers(compiler_type);
1605 auto die_it = GetForwardDeclClangTypeToDie().find (compiler_type_no_qualifiers.GetOpaqueQualType());
1606 if (die_it == GetForwardDeclClangTypeToDie().end())
1608 // We have already resolved this type...
1612 DWARFDebugInfo* debug_info = DebugInfo();
1613 DWARFDIE dwarf_die = debug_info->GetDIE(die_it->getSecond());
1615 assert(UserIDMatches(die_it->getSecond().GetUID()) && "CompleteType called on the wrong SymbolFile");
1617 // Once we start resolving this type, remove it from the forward declaration
1618 // map in case anyone child members or other types require this type to get resolved.
1619 // The type will get resolved when all of the calls to SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1621 GetForwardDeclClangTypeToDie().erase (die_it);
1623 Type *type = GetDIEToType().lookup (dwarf_die.GetDIE());
1625 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO|DWARF_LOG_TYPE_COMPLETION));
1627 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace (log,
1628 "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
1630 dwarf_die.GetTagAsCString(),
1631 type->GetName().AsCString());
1632 assert (compiler_type);
1633 DWARFASTParser *dwarf_ast = dwarf_die.GetDWARFParser();
1635 return dwarf_ast->CompleteTypeFromDWARF (dwarf_die, type, compiler_type);
1640 SymbolFileDWARF::ResolveType (const DWARFDIE &die, bool assert_not_being_parsed, bool resolve_function_context)
1644 Type *type = GetDIEToType().lookup (die.GetDIE());
1647 type = GetTypeForDIE (die, resolve_function_context).get();
1649 if (assert_not_being_parsed)
1651 if (type != DIE_IS_BEING_PARSED)
1654 GetObjectFile()->GetModule()->ReportError ("Parsing a die that is being parsed die: 0x%8.8x: %s %s",
1656 die.GetTagAsCString(),
1667 SymbolFileDWARF::GetCompUnitForDWARFCompUnit (DWARFCompileUnit* dwarf_cu, uint32_t cu_idx)
1669 // Check if the symbol vendor already knows about this compile unit?
1670 if (dwarf_cu->GetUserData() == NULL)
1672 // The symbol vendor doesn't know about this compile unit, we
1673 // need to parse and add it to the symbol vendor object.
1674 return ParseCompileUnit(dwarf_cu, cu_idx).get();
1676 return (CompileUnit*)dwarf_cu->GetUserData();
1680 SymbolFileDWARF::GetObjCMethodDIEOffsets (ConstString class_name, DIEArray &method_die_offsets)
1682 method_die_offsets.clear();
1683 if (m_using_apple_tables)
1685 if (m_apple_objc_ap.get())
1686 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
1693 m_objc_class_selectors_index.Find (class_name, method_die_offsets);
1695 return method_die_offsets.size();
1699 SymbolFileDWARF::GetFunction (const DWARFDIE &die, SymbolContext& sc)
1705 // Check if the symbol vendor already knows about this compile unit?
1706 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
1708 sc.function = sc.comp_unit->FindFunctionByUID (die.GetID()).get();
1709 if (sc.function == NULL)
1710 sc.function = ParseCompileUnitFunction(sc, die);
1714 sc.module_sp = sc.function->CalculateSymbolContextModule();
1723 SymbolFileDWARF::GetDWOModule (ConstString name)
1725 UpdateExternalModuleListIfNeeded();
1726 const auto &pos = m_external_type_modules.find(name);
1727 if (pos != m_external_type_modules.end())
1730 return lldb::ModuleSP();
1734 SymbolFileDWARF::UpdateExternalModuleListIfNeeded()
1736 if (m_fetched_external_modules)
1738 m_fetched_external_modules = true;
1740 DWARFDebugInfo * debug_info = DebugInfo();
1742 const uint32_t num_compile_units = GetNumCompileUnits();
1743 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1745 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1747 const DWARFDIE die = dwarf_cu->GetCompileUnitDIEOnly();
1748 if (die && die.HasChildren() == false)
1750 const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr);
1754 ConstString const_name(name);
1755 if (m_external_type_modules.find(const_name) == m_external_type_modules.end())
1758 const char *dwo_path = die.GetAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr);
1761 ModuleSpec dwo_module_spec;
1762 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
1763 dwo_module_spec.GetArchitecture() = m_obj_file->GetModule()->GetArchitecture();
1764 //printf ("Loading dwo = '%s'\n", dwo_path);
1765 Error error = ModuleList::GetSharedModule (dwo_module_spec, module_sp, NULL, NULL, NULL);
1767 m_external_type_modules[const_name] = module_sp;
1774 SymbolFileDWARF::GlobalVariableMap &
1775 SymbolFileDWARF::GetGlobalAranges()
1777 if (!m_global_aranges_ap)
1779 m_global_aranges_ap.reset (new GlobalVariableMap());
1781 ModuleSP module_sp = GetObjectFile()->GetModule();
1784 const size_t num_cus = module_sp->GetNumCompileUnits();
1785 for (size_t i = 0; i < num_cus; ++i)
1787 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
1790 VariableListSP globals_sp = cu_sp->GetVariableList(true);
1793 const size_t num_globals = globals_sp->GetSize();
1794 for (size_t g = 0; g < num_globals; ++g)
1796 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
1797 if (var_sp && !var_sp->GetLocationIsConstantValueData())
1799 const DWARFExpression &location = var_sp->LocationExpression();
1800 Value location_result;
1802 if (location.Evaluate(NULL, NULL, NULL, LLDB_INVALID_ADDRESS, NULL, location_result, &error))
1804 if (location_result.GetValueType() == Value::eValueTypeFileAddress)
1806 lldb::addr_t file_addr = location_result.GetScalar().ULongLong();
1807 lldb::addr_t byte_size = 1;
1808 if (var_sp->GetType())
1809 byte_size = var_sp->GetType()->GetByteSize();
1810 m_global_aranges_ap->Append(GlobalVariableMap::Entry(file_addr, byte_size, var_sp.get()));
1819 m_global_aranges_ap->Sort();
1821 return *m_global_aranges_ap;
1826 SymbolFileDWARF::ResolveSymbolContext (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc)
1828 Timer scoped_timer(__PRETTY_FUNCTION__,
1829 "SymbolFileDWARF::ResolveSymbolContext (so_addr = { section = %p, offset = 0x%" PRIx64 " }, resolve_scope = 0x%8.8x)",
1830 static_cast<void*>(so_addr.GetSection().get()),
1831 so_addr.GetOffset(), resolve_scope);
1832 uint32_t resolved = 0;
1833 if (resolve_scope & ( eSymbolContextCompUnit |
1834 eSymbolContextFunction |
1835 eSymbolContextBlock |
1836 eSymbolContextLineEntry |
1837 eSymbolContextVariable ))
1839 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1841 DWARFDebugInfo* debug_info = DebugInfo();
1844 const dw_offset_t cu_offset = debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
1845 if (cu_offset == DW_INVALID_OFFSET)
1847 // Global variables are not in the compile unit address ranges. The only way to
1848 // currently find global variables is to iterate over the .debug_pubnames or the
1849 // __apple_names table and find all items in there that point to DW_TAG_variable
1850 // DIEs and then find the address that matches.
1851 if (resolve_scope & eSymbolContextVariable)
1853 GlobalVariableMap &map = GetGlobalAranges();
1854 const GlobalVariableMap::Entry *entry = map.FindEntryThatContains(file_vm_addr);
1855 if (entry && entry->data)
1857 Variable *variable = entry->data;
1858 SymbolContextScope *scc = variable->GetSymbolContextScope();
1861 scc->CalculateSymbolContext(&sc);
1862 sc.variable = variable;
1864 return sc.GetResolvedMask();
1870 uint32_t cu_idx = DW_INVALID_INDEX;
1871 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnit(cu_offset, &cu_idx);
1874 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
1877 resolved |= eSymbolContextCompUnit;
1879 bool force_check_line_table = false;
1880 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
1882 DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr);
1886 sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get();
1887 if (sc.function == NULL)
1888 sc.function = ParseCompileUnitFunction(sc, function_die);
1890 if (sc.function && (resolve_scope & eSymbolContextBlock))
1891 block_die = function_die.LookupDeepestBlock(file_vm_addr);
1895 // We might have had a compile unit that had discontiguous
1896 // address ranges where the gaps are symbols that don't have
1897 // any debug info. Discontiguous compile unit address ranges
1898 // should only happen when there aren't other functions from
1899 // other compile units in these gaps. This helps keep the size
1900 // of the aranges down.
1901 force_check_line_table = true;
1904 if (sc.function != NULL)
1906 resolved |= eSymbolContextFunction;
1908 if (resolve_scope & eSymbolContextBlock)
1910 Block& block = sc.function->GetBlock (true);
1913 sc.block = block.FindBlockByID (block_die.GetID());
1915 sc.block = block.FindBlockByID (function_die.GetID());
1917 resolved |= eSymbolContextBlock;
1922 if ((resolve_scope & eSymbolContextLineEntry) || force_check_line_table)
1924 LineTable *line_table = sc.comp_unit->GetLineTable();
1925 if (line_table != NULL)
1927 // And address that makes it into this function should be in terms
1928 // of this debug file if there is no debug map, or it will be an
1929 // address in the .o file which needs to be fixed up to be in terms
1930 // of the debug map executable. Either way, calling FixupAddress()
1931 // will work for us.
1932 Address exe_so_addr (so_addr);
1933 if (FixupAddress(exe_so_addr))
1935 if (line_table->FindLineEntryByAddress (exe_so_addr, sc.line_entry))
1937 resolved |= eSymbolContextLineEntry;
1943 if (force_check_line_table && !(resolved & eSymbolContextLineEntry))
1945 // We might have had a compile unit that had discontiguous
1946 // address ranges where the gaps are symbols that don't have
1947 // any debug info. Discontiguous compile unit address ranges
1948 // should only happen when there aren't other functions from
1949 // other compile units in these gaps. This helps keep the size
1950 // of the aranges down.
1951 sc.comp_unit = NULL;
1952 resolved &= ~eSymbolContextCompUnit;
1957 GetObjectFile()->GetModule()->ReportWarning ("0x%8.8x: compile unit %u failed to create a valid lldb_private::CompileUnit class.",
1971 SymbolFileDWARF::ResolveSymbolContext(const FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list)
1973 const uint32_t prev_size = sc_list.GetSize();
1974 if (resolve_scope & eSymbolContextCompUnit)
1976 DWARFDebugInfo* debug_info = DebugInfo();
1980 DWARFCompileUnit* dwarf_cu = NULL;
1982 for (cu_idx = 0; (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL; ++cu_idx)
1984 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
1985 const bool full_match = (bool)file_spec.GetDirectory();
1986 bool file_spec_matches_cu_file_spec = dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match);
1987 if (check_inlines || file_spec_matches_cu_file_spec)
1989 SymbolContext sc (m_obj_file->GetModule());
1990 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
1993 uint32_t file_idx = UINT32_MAX;
1995 // If we are looking for inline functions only and we don't
1996 // find it in the support files, we are done.
1999 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2000 if (file_idx == UINT32_MAX)
2006 LineTable *line_table = sc.comp_unit->GetLineTable();
2008 if (line_table != NULL && line != 0)
2010 // We will have already looked up the file index if
2011 // we are searching for inline entries.
2013 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex (1, file_spec, true);
2015 if (file_idx != UINT32_MAX)
2017 uint32_t found_line;
2018 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex (0, file_idx, line, false, &sc.line_entry);
2019 found_line = sc.line_entry.line;
2021 while (line_idx != UINT32_MAX)
2025 if (resolve_scope & (eSymbolContextFunction | eSymbolContextBlock))
2027 const lldb::addr_t file_vm_addr = sc.line_entry.range.GetBaseAddress().GetFileAddress();
2028 if (file_vm_addr != LLDB_INVALID_ADDRESS)
2030 DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr);
2034 sc.function = sc.comp_unit->FindFunctionByUID (function_die.GetID()).get();
2035 if (sc.function == NULL)
2036 sc.function = ParseCompileUnitFunction(sc, function_die);
2038 if (sc.function && (resolve_scope & eSymbolContextBlock))
2039 block_die = function_die.LookupDeepestBlock(file_vm_addr);
2042 if (sc.function != NULL)
2044 Block& block = sc.function->GetBlock (true);
2047 sc.block = block.FindBlockByID (block_die.GetID());
2048 else if (function_die)
2049 sc.block = block.FindBlockByID (function_die.GetID());
2055 line_idx = line_table->FindLineEntryIndexByFileIndex (line_idx + 1, file_idx, found_line, true, &sc.line_entry);
2059 else if (file_spec_matches_cu_file_spec && !check_inlines)
2061 // only append the context if we aren't looking for inline call sites
2062 // by file and line and if the file spec matches that of the compile unit
2066 else if (file_spec_matches_cu_file_spec && !check_inlines)
2068 // only append the context if we aren't looking for inline call sites
2069 // by file and line and if the file spec matches that of the compile unit
2080 return sc_list.GetSize() - prev_size;
2084 SymbolFileDWARF::Index ()
2089 Timer scoped_timer (__PRETTY_FUNCTION__,
2090 "SymbolFileDWARF::Index (%s)",
2091 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
2093 DWARFDebugInfo* debug_info = DebugInfo();
2096 const uint32_t num_compile_units = GetNumCompileUnits();
2097 std::vector<NameToDIE> function_basename_index(num_compile_units);
2098 std::vector<NameToDIE> function_fullname_index(num_compile_units);
2099 std::vector<NameToDIE> function_method_index(num_compile_units);
2100 std::vector<NameToDIE> function_selector_index(num_compile_units);
2101 std::vector<NameToDIE> objc_class_selectors_index(num_compile_units);
2102 std::vector<NameToDIE> global_index(num_compile_units);
2103 std::vector<NameToDIE> type_index(num_compile_units);
2104 std::vector<NameToDIE> namespace_index(num_compile_units);
2106 auto parser_fn = [this,
2108 &function_basename_index,
2109 &function_fullname_index,
2110 &function_method_index,
2111 &function_selector_index,
2112 &objc_class_selectors_index,
2115 &namespace_index](uint32_t cu_idx)
2117 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
2118 bool clear_dies = dwarf_cu->ExtractDIEsIfNeeded(false) > 1;
2120 dwarf_cu->Index(function_basename_index[cu_idx],
2121 function_fullname_index[cu_idx],
2122 function_method_index[cu_idx],
2123 function_selector_index[cu_idx],
2124 objc_class_selectors_index[cu_idx],
2125 global_index[cu_idx],
2127 namespace_index[cu_idx]);
2129 // Keep memory down by clearing DIEs if this generate function
2130 // caused them to be parsed
2132 dwarf_cu->ClearDIEs(true);
2137 TaskRunner<uint32_t> task_runner;
2138 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
2139 task_runner.AddTask(parser_fn, cu_idx);
2143 std::future<uint32_t> f = task_runner.WaitForNextCompletedTask();
2146 uint32_t cu_idx = f.get();
2148 m_function_basename_index.Append(function_basename_index[cu_idx]);
2149 m_function_fullname_index.Append(function_fullname_index[cu_idx]);
2150 m_function_method_index.Append(function_method_index[cu_idx]);
2151 m_function_selector_index.Append(function_selector_index[cu_idx]);
2152 m_objc_class_selectors_index.Append(objc_class_selectors_index[cu_idx]);
2153 m_global_index.Append(global_index[cu_idx]);
2154 m_type_index.Append(type_index[cu_idx]);
2155 m_namespace_index.Append(namespace_index[cu_idx]);
2159 [&]() { m_function_basename_index.Finalize(); },
2160 [&]() { m_function_fullname_index.Finalize(); },
2161 [&]() { m_function_method_index.Finalize(); },
2162 [&]() { m_function_selector_index.Finalize(); },
2163 [&]() { m_objc_class_selectors_index.Finalize(); },
2164 [&]() { m_global_index.Finalize(); },
2165 [&]() { m_type_index.Finalize(); },
2166 [&]() { m_namespace_index.Finalize(); });
2168 #if defined (ENABLE_DEBUG_PRINTF)
2169 StreamFile s(stdout, false);
2170 s.Printf ("DWARF index for '%s':",
2171 GetObjectFile()->GetFileSpec().GetPath().c_str());
2172 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
2173 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
2174 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
2175 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
2176 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
2177 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
2178 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
2179 s.Printf("\nNamespaces:\n") m_namespace_index.Dump (&s);
2185 SymbolFileDWARF::DeclContextMatchesThisSymbolFile (const lldb_private::CompilerDeclContext *decl_ctx)
2187 if (decl_ctx == nullptr || !decl_ctx->IsValid())
2189 // Invalid namespace decl which means we aren't matching only things
2190 // in this symbol file, so return true to indicate it matches this
2195 TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem();
2196 TypeSystem *type_system = GetTypeSystemForLanguage(decl_ctx_type_system->GetMinimumLanguage(nullptr));
2197 if (decl_ctx_type_system == type_system)
2198 return true; // The type systems match, return true
2200 // The namespace AST was valid, and it does not match...
2201 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2204 GetObjectFile()->GetModule()->LogMessage(log, "Valid namespace does not match symbol file");
2210 SymbolFileDWARF::FindGlobalVariables (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, VariableList& variables)
2212 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2215 GetObjectFile()->GetModule()->LogMessage (log,
2216 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables)",
2218 static_cast<const void*>(parent_decl_ctx),
2219 append, max_matches);
2221 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2224 DWARFDebugInfo* info = DebugInfo();
2228 // If we aren't appending the results to this list, then clear the list
2232 // Remember how many variables are in the list before we search in case
2233 // we are appending the results to a variable list.
2234 const uint32_t original_size = variables.GetSize();
2236 DIEArray die_offsets;
2238 if (m_using_apple_tables)
2240 if (m_apple_names_ap.get())
2242 const char *name_cstr = name.GetCString();
2243 llvm::StringRef basename;
2244 llvm::StringRef context;
2246 if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context, basename))
2247 basename = name_cstr;
2249 m_apple_names_ap->FindByName (basename.data(), die_offsets);
2254 // Index the DWARF if we haven't already
2258 m_global_index.Find (name, die_offsets);
2261 const size_t num_die_matches = die_offsets.size();
2262 if (num_die_matches)
2265 sc.module_sp = m_obj_file->GetModule();
2266 assert (sc.module_sp);
2268 DWARFDebugInfo* debug_info = DebugInfo();
2270 for (size_t i=0; i<num_die_matches && !done; ++i)
2272 const DIERef& die_ref = die_offsets[i];
2273 DWARFDIE die = debug_info->GetDIE (die_ref);
2280 case DW_TAG_subprogram:
2281 case DW_TAG_inlined_subroutine:
2282 case DW_TAG_try_block:
2283 case DW_TAG_catch_block:
2286 case DW_TAG_variable:
2288 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
2290 if (parent_decl_ctx)
2292 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2295 CompilerDeclContext actual_parent_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF (die);
2296 if (!actual_parent_decl_ctx || actual_parent_decl_ctx != *parent_decl_ctx)
2301 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
2303 if (variables.GetSize() - original_size >= max_matches)
2311 if (m_using_apple_tables)
2313 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')\n",
2314 die_ref.die_offset, name.GetCString());
2320 // Return the number of variable that were appended to the list
2321 const uint32_t num_matches = variables.GetSize() - original_size;
2322 if (log && num_matches > 0)
2324 GetObjectFile()->GetModule()->LogMessage (log,
2325 "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", parent_decl_ctx=%p, append=%u, max_matches=%u, variables) => %u",
2327 static_cast<const void*>(parent_decl_ctx),
2328 append, max_matches,
2335 SymbolFileDWARF::FindGlobalVariables(const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables)
2337 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2341 GetObjectFile()->GetModule()->LogMessage (log,
2342 "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, max_matches=%u, variables)",
2343 regex.GetText(), append,
2347 DWARFDebugInfo* info = DebugInfo();
2351 // If we aren't appending the results to this list, then clear the list
2355 // Remember how many variables are in the list before we search in case
2356 // we are appending the results to a variable list.
2357 const uint32_t original_size = variables.GetSize();
2359 DIEArray die_offsets;
2361 if (m_using_apple_tables)
2363 if (m_apple_names_ap.get())
2365 DWARFMappedHash::DIEInfoArray hash_data_array;
2366 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2367 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2372 // Index the DWARF if we haven't already
2376 m_global_index.Find (regex, die_offsets);
2380 sc.module_sp = m_obj_file->GetModule();
2381 assert (sc.module_sp);
2383 const size_t num_matches = die_offsets.size();
2386 DWARFDebugInfo* debug_info = DebugInfo();
2387 for (size_t i=0; i<num_matches; ++i)
2389 const DIERef& die_ref = die_offsets[i];
2390 DWARFDIE die = debug_info->GetDIE (die_ref);
2394 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
2396 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
2398 if (variables.GetSize() - original_size >= max_matches)
2403 if (m_using_apple_tables)
2405 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for regex '%s')\n",
2406 die_ref.die_offset, regex.GetText());
2412 // Return the number of variable that were appended to the list
2413 return variables.GetSize() - original_size;
2418 SymbolFileDWARF::ResolveFunction (const DIERef& die_ref,
2419 bool include_inlines,
2420 SymbolContextList& sc_list)
2422 DWARFDIE die = DebugInfo()->GetDIE (die_ref);
2423 return ResolveFunction (die, include_inlines, sc_list);
2428 SymbolFileDWARF::ResolveFunction (const DWARFDIE &orig_die,
2429 bool include_inlines,
2430 SymbolContextList& sc_list)
2437 // If we were passed a die that is not a function, just return false...
2438 if (!(orig_die.Tag() == DW_TAG_subprogram || (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine)))
2441 DWARFDIE die = orig_die;
2442 DWARFDIE inlined_die;
2443 if (die.Tag() == DW_TAG_inlined_subroutine)
2449 die = die.GetParent();
2453 if (die.Tag() == DW_TAG_subprogram)
2460 assert (die && die.Tag() == DW_TAG_subprogram);
2461 if (GetFunction (die, sc))
2464 // Parse all blocks if needed
2467 Block &function_block = sc.function->GetBlock (true);
2468 sc.block = function_block.FindBlockByID (inlined_die.GetID());
2469 if (sc.block == NULL)
2470 sc.block = function_block.FindBlockByID (inlined_die.GetOffset());
2471 if (sc.block == NULL || sc.block->GetStartAddress (addr) == false)
2477 addr = sc.function->GetAddressRange().GetBaseAddress();
2491 SymbolFileDWARF::FindFunctions (const ConstString &name,
2492 const NameToDIE &name_to_die,
2493 bool include_inlines,
2494 SymbolContextList& sc_list)
2496 DIEArray die_offsets;
2497 if (name_to_die.Find (name, die_offsets))
2499 ParseFunctions (die_offsets, include_inlines, sc_list);
2505 SymbolFileDWARF::FindFunctions (const RegularExpression ®ex,
2506 const NameToDIE &name_to_die,
2507 bool include_inlines,
2508 SymbolContextList& sc_list)
2510 DIEArray die_offsets;
2511 if (name_to_die.Find (regex, die_offsets))
2513 ParseFunctions (die_offsets, include_inlines, sc_list);
2519 SymbolFileDWARF::FindFunctions (const RegularExpression ®ex,
2520 const DWARFMappedHash::MemoryTable &memory_table,
2521 bool include_inlines,
2522 SymbolContextList& sc_list)
2524 DIEArray die_offsets;
2525 DWARFMappedHash::DIEInfoArray hash_data_array;
2526 if (memory_table.AppendAllDIEsThatMatchingRegex (regex, hash_data_array))
2528 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
2529 ParseFunctions (die_offsets, include_inlines, sc_list);
2534 SymbolFileDWARF::ParseFunctions (const DIEArray &die_offsets,
2535 bool include_inlines,
2536 SymbolContextList& sc_list)
2538 const size_t num_matches = die_offsets.size();
2541 for (size_t i=0; i<num_matches; ++i)
2542 ResolveFunction (die_offsets[i], include_inlines, sc_list);
2547 SymbolFileDWARF::DIEInDeclContext (const CompilerDeclContext *decl_ctx,
2548 const DWARFDIE &die)
2550 // If we have no parent decl context to match this DIE matches, and if the parent
2551 // decl context isn't valid, we aren't trying to look for any particular decl
2552 // context so any die matches.
2553 if (decl_ctx == nullptr || !decl_ctx->IsValid())
2558 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2561 CompilerDeclContext actual_decl_ctx = dwarf_ast->GetDeclContextContainingUIDFromDWARF (die);
2562 if (actual_decl_ctx)
2563 return actual_decl_ctx == *decl_ctx;
2570 SymbolFileDWARF::FindFunctions (const ConstString &name,
2571 const CompilerDeclContext *parent_decl_ctx,
2572 uint32_t name_type_mask,
2573 bool include_inlines,
2575 SymbolContextList& sc_list)
2577 Timer scoped_timer (__PRETTY_FUNCTION__,
2578 "SymbolFileDWARF::FindFunctions (name = '%s')",
2581 // eFunctionNameTypeAuto should be pre-resolved by a call to Module::PrepareForFunctionNameLookup()
2582 assert ((name_type_mask & eFunctionNameTypeAuto) == 0);
2584 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2588 GetObjectFile()->GetModule()->LogMessage (log,
2589 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, append=%u, sc_list)",
2595 // If we aren't appending the results to this list, then clear the list
2599 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2602 // If name is empty then we won't find anything.
2606 // Remember how many sc_list are in the list before we search in case
2607 // we are appending the results to a variable list.
2609 const char *name_cstr = name.GetCString();
2611 const uint32_t original_size = sc_list.GetSize();
2613 DWARFDebugInfo* info = DebugInfo();
2617 std::set<const DWARFDebugInfoEntry *> resolved_dies;
2618 if (m_using_apple_tables)
2620 if (m_apple_names_ap.get())
2623 DIEArray die_offsets;
2625 uint32_t num_matches = 0;
2627 if (name_type_mask & eFunctionNameTypeFull)
2629 // If they asked for the full name, match what they typed. At some point we may
2630 // want to canonicalize this (strip double spaces, etc. For now, we just add all the
2631 // dies that we find by exact match.
2632 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2633 for (uint32_t i = 0; i < num_matches; i++)
2635 const DIERef& die_ref = die_offsets[i];
2636 DWARFDIE die = info->GetDIE (die_ref);
2639 if (!DIEInDeclContext(parent_decl_ctx, die))
2640 continue; // The containing decl contexts don't match
2642 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
2644 if (ResolveFunction (die, include_inlines, sc_list))
2645 resolved_dies.insert(die.GetDIE());
2650 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2651 die_ref.die_offset, name_cstr);
2656 if (name_type_mask & eFunctionNameTypeSelector)
2658 if (parent_decl_ctx && parent_decl_ctx->IsValid())
2659 return 0; // no selectors in namespaces
2661 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2662 // Now make sure these are actually ObjC methods. In this case we can simply look up the name,
2663 // and if it is an ObjC method name, we're good.
2665 for (uint32_t i = 0; i < num_matches; i++)
2667 const DIERef& die_ref = die_offsets[i];
2668 DWARFDIE die = info->GetDIE (die_ref);
2671 const char *die_name = die.GetName();
2672 if (ObjCLanguage::IsPossibleObjCMethodName(die_name))
2674 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
2676 if (ResolveFunction (die, include_inlines, sc_list))
2677 resolved_dies.insert(die.GetDIE());
2683 GetObjectFile()->GetModule()->ReportError ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2684 die_ref.die_offset, name_cstr);
2687 die_offsets.clear();
2690 if (((name_type_mask & eFunctionNameTypeMethod) && !parent_decl_ctx) || name_type_mask & eFunctionNameTypeBase)
2692 // The apple_names table stores just the "base name" of C++ methods in the table. So we have to
2693 // extract the base name, look that up, and if there is any other information in the name we were
2694 // passed in we have to post-filter based on that.
2696 // FIXME: Arrange the logic above so that we don't calculate the base name twice:
2697 num_matches = m_apple_names_ap->FindByName (name_cstr, die_offsets);
2699 for (uint32_t i = 0; i < num_matches; i++)
2701 const DIERef& die_ref = die_offsets[i];
2702 DWARFDIE die = info->GetDIE (die_ref);
2705 if (!DIEInDeclContext(parent_decl_ctx, die))
2706 continue; // The containing decl contexts don't match
2709 // If we get to here, the die is good, and we should add it:
2710 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end() && ResolveFunction (die, include_inlines, sc_list))
2712 bool keep_die = true;
2713 if ((name_type_mask & (eFunctionNameTypeBase|eFunctionNameTypeMethod)) != (eFunctionNameTypeBase|eFunctionNameTypeMethod))
2715 // We are looking for either basenames or methods, so we need to
2716 // trim out the ones we won't want by looking at the type
2718 if (sc_list.GetLastContext(sc))
2722 // We have an inlined function
2724 else if (sc.function)
2726 Type *type = sc.function->GetType();
2730 CompilerDeclContext decl_ctx = GetDeclContextContainingUID (type->GetID());
2731 if (decl_ctx.IsStructUnionOrClass())
2733 if (name_type_mask & eFunctionNameTypeBase)
2735 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
2741 if (name_type_mask & eFunctionNameTypeMethod)
2743 sc_list.RemoveContextAtIndex(sc_list.GetSize()-1);
2750 GetObjectFile()->GetModule()->ReportWarning ("function at die offset 0x%8.8x had no function type",
2751 die_ref.die_offset);
2757 resolved_dies.insert(die.GetDIE());
2762 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x for '%s')",
2763 die_ref.die_offset, name_cstr);
2766 die_offsets.clear();
2773 // Index the DWARF if we haven't already
2777 if (name_type_mask & eFunctionNameTypeFull)
2779 FindFunctions (name, m_function_fullname_index, include_inlines, sc_list);
2781 // FIXME Temporary workaround for global/anonymous namespace
2782 // functions debugging FreeBSD and Linux binaries.
2783 // If we didn't find any functions in the global namespace try
2784 // looking in the basename index but ignore any returned
2785 // functions that have a namespace but keep functions which
2786 // have an anonymous namespace
2787 // TODO: The arch in the object file isn't correct for MSVC
2788 // binaries on windows, we should find a way to make it
2789 // correct and handle those symbols as well.
2790 if (sc_list.GetSize() == original_size)
2793 if (!parent_decl_ctx &&
2794 GetObjectFile()->GetArchitecture(arch) &&
2795 (arch.GetTriple().isOSFreeBSD() || arch.GetTriple().isOSLinux() ||
2796 arch.GetMachine() == llvm::Triple::hexagon))
2798 SymbolContextList temp_sc_list;
2799 FindFunctions (name, m_function_basename_index, include_inlines, temp_sc_list);
2801 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++)
2803 if (temp_sc_list.GetContextAtIndex(i, sc))
2805 ConstString mangled_name = sc.GetFunctionName(Mangled::ePreferMangled);
2806 ConstString demangled_name = sc.GetFunctionName(Mangled::ePreferDemangled);
2807 // Mangled names on Linux and FreeBSD are of the form:
2808 // _ZN18function_namespace13function_nameEv.
2809 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
2810 !strncmp(demangled_name.GetCString(), "(anonymous namespace)", 21))
2819 DIEArray die_offsets;
2820 if (name_type_mask & eFunctionNameTypeBase)
2822 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
2823 for (uint32_t i = 0; i < num_base; i++)
2825 DWARFDIE die = info->GetDIE (die_offsets[i]);
2828 if (!DIEInDeclContext(parent_decl_ctx, die))
2829 continue; // The containing decl contexts don't match
2831 // If we get to here, the die is good, and we should add it:
2832 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
2834 if (ResolveFunction (die, include_inlines, sc_list))
2835 resolved_dies.insert(die.GetDIE());
2839 die_offsets.clear();
2842 if (name_type_mask & eFunctionNameTypeMethod)
2844 if (parent_decl_ctx && parent_decl_ctx->IsValid())
2845 return 0; // no methods in namespaces
2847 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
2849 for (uint32_t i = 0; i < num_base; i++)
2851 DWARFDIE die = info->GetDIE (die_offsets[i]);
2854 // If we get to here, the die is good, and we should add it:
2855 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end())
2857 if (ResolveFunction (die, include_inlines, sc_list))
2858 resolved_dies.insert(die.GetDIE());
2863 die_offsets.clear();
2866 if ((name_type_mask & eFunctionNameTypeSelector) && (!parent_decl_ctx || !parent_decl_ctx->IsValid()))
2868 FindFunctions (name, m_function_selector_index, include_inlines, sc_list);
2873 // Return the number of variable that were appended to the list
2874 const uint32_t num_matches = sc_list.GetSize() - original_size;
2876 if (log && num_matches > 0)
2878 GetObjectFile()->GetModule()->LogMessage (log,
2879 "SymbolFileDWARF::FindFunctions (name=\"%s\", name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => %u",
2890 SymbolFileDWARF::FindFunctions(const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list)
2892 Timer scoped_timer (__PRETTY_FUNCTION__,
2893 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2896 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2900 GetObjectFile()->GetModule()->LogMessage (log,
2901 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
2907 // If we aren't appending the results to this list, then clear the list
2911 // Remember how many sc_list are in the list before we search in case
2912 // we are appending the results to a variable list.
2913 uint32_t original_size = sc_list.GetSize();
2915 if (m_using_apple_tables)
2917 if (m_apple_names_ap.get())
2918 FindFunctions (regex, *m_apple_names_ap, include_inlines, sc_list);
2922 // Index the DWARF if we haven't already
2926 FindFunctions (regex, m_function_basename_index, include_inlines, sc_list);
2928 FindFunctions (regex, m_function_fullname_index, include_inlines, sc_list);
2931 // Return the number of variable that were appended to the list
2932 return sc_list.GetSize() - original_size;
2936 SymbolFileDWARF::GetMangledNamesForFunction (const std::string &scope_qualified_name,
2937 std::vector<ConstString> &mangled_names)
2939 DWARFDebugInfo* info = DebugInfo();
2940 uint32_t num_comp_units = 0;
2942 num_comp_units = info->GetNumCompileUnits();
2944 for (uint32_t i = 0; i < num_comp_units; i++)
2946 DWARFCompileUnit *cu = info->GetCompileUnitAtIndex(i);
2950 SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile();
2952 dwo->GetMangledNamesForFunction(scope_qualified_name, mangled_names);
2955 NameToOffsetMap::iterator iter = m_function_scope_qualified_name_map.find(scope_qualified_name);
2956 if (iter == m_function_scope_qualified_name_map.end())
2959 DIERefSetSP set_sp = (*iter).second;
2960 std::set<DIERef>::iterator set_iter;
2961 for (set_iter = set_sp->begin(); set_iter != set_sp->end(); set_iter++)
2963 DWARFDIE die = DebugInfo()->GetDIE (*set_iter);
2964 mangled_names.push_back(ConstString(die.GetMangledName()));
2970 SymbolFileDWARF::FindTypes (const SymbolContext& sc,
2971 const ConstString &name,
2972 const CompilerDeclContext *parent_decl_ctx,
2974 uint32_t max_matches,
2977 DWARFDebugInfo* info = DebugInfo();
2981 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2985 if (parent_decl_ctx)
2986 GetObjectFile()->GetModule()->LogMessage (log,
2987 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list)",
2989 static_cast<const void*>(parent_decl_ctx),
2990 parent_decl_ctx->GetName().AsCString("<NULL>"),
2991 append, max_matches);
2993 GetObjectFile()->GetModule()->LogMessage (log,
2994 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list)",
2995 name.GetCString(), append,
2999 // If we aren't appending the results to this list, then clear the list
3003 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
3006 DIEArray die_offsets;
3008 if (m_using_apple_tables)
3010 if (m_apple_types_ap.get())
3012 const char *name_cstr = name.GetCString();
3013 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3021 m_type_index.Find (name, die_offsets);
3024 const size_t num_die_matches = die_offsets.size();
3026 if (num_die_matches)
3028 const uint32_t initial_types_size = types.GetSize();
3029 DWARFDebugInfo* debug_info = DebugInfo();
3030 for (size_t i=0; i<num_die_matches; ++i)
3032 const DIERef& die_ref = die_offsets[i];
3033 DWARFDIE die = debug_info->GetDIE (die_ref);
3037 if (!DIEInDeclContext(parent_decl_ctx, die))
3038 continue; // The containing decl contexts don't match
3040 Type *matching_type = ResolveType (die, true, true);
3043 // We found a type pointer, now find the shared pointer form our type list
3044 types.InsertUnique (matching_type->shared_from_this());
3045 if (types.GetSize() >= max_matches)
3051 if (m_using_apple_tables)
3053 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3054 die_ref.die_offset, name.GetCString());
3059 const uint32_t num_matches = types.GetSize() - initial_types_size;
3060 if (log && num_matches)
3062 if (parent_decl_ctx)
3064 GetObjectFile()->GetModule()->LogMessage (log,
3065 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u",
3067 static_cast<const void*>(parent_decl_ctx),
3068 parent_decl_ctx->GetName().AsCString("<NULL>"),
3069 append, max_matches,
3074 GetObjectFile()->GetModule()->LogMessage (log,
3075 "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = NULL, append=%u, max_matches=%u, type_list) => %u",
3077 append, max_matches,
3085 UpdateExternalModuleListIfNeeded();
3087 for (const auto &pair : m_external_type_modules)
3089 ModuleSP external_module_sp = pair.second;
3090 if (external_module_sp)
3092 SymbolVendor *sym_vendor = external_module_sp->GetSymbolVendor();
3095 const uint32_t num_external_matches = sym_vendor->FindTypes (sc,
3101 if (num_external_matches)
3102 return num_external_matches;
3113 SymbolFileDWARF::FindTypes (const std::vector<CompilerContext> &context,
3120 if (context.empty())
3123 DIEArray die_offsets;
3125 ConstString name = context.back().name;
3127 if (m_using_apple_tables)
3129 if (m_apple_types_ap.get())
3131 const char *name_cstr = name.GetCString();
3132 m_apple_types_ap->FindByName (name_cstr, die_offsets);
3140 m_type_index.Find (name, die_offsets);
3143 const size_t num_die_matches = die_offsets.size();
3145 if (num_die_matches)
3147 size_t num_matches = 0;
3148 DWARFDebugInfo* debug_info = DebugInfo();
3149 for (size_t i=0; i<num_die_matches; ++i)
3151 const DIERef& die_ref = die_offsets[i];
3152 DWARFDIE die = debug_info->GetDIE (die_ref);
3156 std::vector<CompilerContext> die_context;
3157 die.GetDWOContext(die_context);
3158 if (die_context != context)
3161 Type *matching_type = ResolveType (die, true, true);
3164 // We found a type pointer, now find the shared pointer form our type list
3165 types.InsertUnique (matching_type->shared_from_this());
3171 if (m_using_apple_tables)
3173 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3174 die_ref.die_offset, name.GetCString());
3186 SymbolFileDWARF::FindNamespace (const SymbolContext& sc,
3187 const ConstString &name,
3188 const CompilerDeclContext *parent_decl_ctx)
3190 Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
3194 GetObjectFile()->GetModule()->LogMessage (log,
3195 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
3199 CompilerDeclContext namespace_decl_ctx;
3201 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
3202 return namespace_decl_ctx;
3205 DWARFDebugInfo* info = DebugInfo();
3208 DIEArray die_offsets;
3210 // Index if we already haven't to make sure the compile units
3211 // get indexed and make their global DIE index list
3212 if (m_using_apple_tables)
3214 if (m_apple_namespaces_ap.get())
3216 const char *name_cstr = name.GetCString();
3217 m_apple_namespaces_ap->FindByName (name_cstr, die_offsets);
3225 m_namespace_index.Find (name, die_offsets);
3228 const size_t num_matches = die_offsets.size();
3231 DWARFDebugInfo* debug_info = DebugInfo();
3232 for (size_t i=0; i<num_matches; ++i)
3234 const DIERef& die_ref = die_offsets[i];
3235 DWARFDIE die = debug_info->GetDIE (die_ref);
3239 if (!DIEInDeclContext (parent_decl_ctx, die))
3240 continue; // The containing decl contexts don't match
3242 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
3245 namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF (die);
3246 if (namespace_decl_ctx)
3252 if (m_using_apple_tables)
3254 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_namespaces accelerator table had bad die 0x%8.8x for '%s')\n",
3255 die_ref.die_offset, name.GetCString());
3262 if (log && namespace_decl_ctx)
3264 GetObjectFile()->GetModule()->LogMessage (log,
3265 "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => CompilerDeclContext(%p/%p) \"%s\"",
3267 static_cast<const void*>(namespace_decl_ctx.GetTypeSystem()),
3268 static_cast<const void*>(namespace_decl_ctx.GetOpaqueDeclContext()),
3269 namespace_decl_ctx.GetName().AsCString("<NULL>"));
3272 return namespace_decl_ctx;
3276 SymbolFileDWARF::GetTypeForDIE (const DWARFDIE &die, bool resolve_function_context)
3281 Type *type_ptr = GetDIEToType().lookup (die.GetDIE());
3282 if (type_ptr == NULL)
3284 CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(die.GetCU());
3286 SymbolContext sc(lldb_cu);
3287 const DWARFDebugInfoEntry* parent_die = die.GetParent().GetDIE();
3288 while (parent_die != nullptr)
3290 if (parent_die->Tag() == DW_TAG_subprogram)
3292 parent_die = parent_die->GetParent();
3294 SymbolContext sc_backup = sc;
3295 if (resolve_function_context && parent_die != nullptr && !GetFunction(DWARFDIE(die.GetCU(),parent_die), sc))
3298 type_sp = ParseType(sc, die, NULL);
3300 else if (type_ptr != DIE_IS_BEING_PARSED)
3302 // Grab the existing type from the master types lists
3303 type_sp = type_ptr->shared_from_this();
3312 SymbolFileDWARF::GetDeclContextDIEContainingDIE (const DWARFDIE &orig_die)
3316 DWARFDIE die = orig_die;
3320 // If this is the original DIE that we are searching for a declaration
3321 // for, then don't look in the cache as we don't want our own decl
3322 // context to be our decl context...
3323 if (orig_die != die)
3327 case DW_TAG_compile_unit:
3328 case DW_TAG_namespace:
3329 case DW_TAG_structure_type:
3330 case DW_TAG_union_type:
3331 case DW_TAG_class_type:
3332 case DW_TAG_lexical_block:
3333 case DW_TAG_subprogram:
3341 DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification);
3344 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die);
3346 return decl_ctx_die;
3349 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
3352 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die);
3354 return decl_ctx_die;
3357 die = die.GetParent();
3365 SymbolFileDWARF::GetObjCClassSymbol (const ConstString &objc_class_name)
3367 Symbol *objc_class_symbol = NULL;
3370 Symtab *symtab = m_obj_file->GetSymtab ();
3373 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType (objc_class_name,
3374 eSymbolTypeObjCClass,
3376 Symtab::eVisibilityAny);
3379 return objc_class_symbol;
3382 // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If they don't
3383 // then we can end up looking through all class types for a complete type and never find
3384 // the full definition. We need to know if this attribute is supported, so we determine
3385 // this here and cache th result. We also need to worry about the debug map DWARF file
3386 // if we are doing darwin DWARF in .o file debugging.
3388 SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type (DWARFCompileUnit *cu)
3390 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate)
3392 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
3393 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
3394 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3397 DWARFDebugInfo* debug_info = DebugInfo();
3398 const uint32_t num_compile_units = GetNumCompileUnits();
3399 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
3401 DWARFCompileUnit* dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
3402 if (dwarf_cu != cu && dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type())
3404 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3409 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo && GetDebugMapSymfile ())
3410 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type (this);
3412 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
3415 // This function can be used when a DIE is found that is a forward declaration
3416 // DIE and we want to try and find a type that has the complete definition.
3418 SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die,
3419 const ConstString &type_name,
3420 bool must_be_implementation)
3425 if (!type_name || (must_be_implementation && !GetObjCClassSymbol (type_name)))
3428 DIEArray die_offsets;
3430 if (m_using_apple_tables)
3432 if (m_apple_types_ap.get())
3434 const char *name_cstr = type_name.GetCString();
3435 m_apple_types_ap->FindCompleteObjCClassByName (name_cstr, die_offsets, must_be_implementation);
3443 m_type_index.Find (type_name, die_offsets);
3446 const size_t num_matches = die_offsets.size();
3450 DWARFDebugInfo* debug_info = DebugInfo();
3451 for (size_t i=0; i<num_matches; ++i)
3453 const DIERef& die_ref = die_offsets[i];
3454 DWARFDIE type_die = debug_info->GetDIE (die_ref);
3458 bool try_resolving_type = false;
3460 // Don't try and resolve the DIE we are looking for with the DIE itself!
3461 if (type_die != die)
3463 switch (type_die.Tag())
3465 case DW_TAG_class_type:
3466 case DW_TAG_structure_type:
3467 try_resolving_type = true;
3474 if (try_resolving_type)
3476 if (must_be_implementation && type_die.Supports_DW_AT_APPLE_objc_complete_type())
3477 try_resolving_type = type_die.GetAttributeValueAsUnsigned (DW_AT_APPLE_objc_complete_type, 0);
3479 if (try_resolving_type)
3481 Type *resolved_type = ResolveType (type_die, false, true);
3482 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3484 DEBUG_PRINTF ("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64 " (cu 0x%8.8" PRIx64 ")\n",
3486 m_obj_file->GetFileSpec().GetFilename().AsCString("<Unknown>"),
3491 GetDIEToType()[die.GetDIE()] = resolved_type;
3492 type_sp = resolved_type->shared_from_this();
3500 if (m_using_apple_tables)
3502 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3503 die_ref.die_offset, type_name.GetCString());
3513 //----------------------------------------------------------------------
3514 // This function helps to ensure that the declaration contexts match for
3515 // two different DIEs. Often times debug information will refer to a
3516 // forward declaration of a type (the equivalent of "struct my_struct;".
3517 // There will often be a declaration of that type elsewhere that has the
3518 // full definition. When we go looking for the full type "my_struct", we
3519 // will find one or more matches in the accelerator tables and we will
3520 // then need to make sure the type was in the same declaration context
3521 // as the original DIE. This function can efficiently compare two DIEs
3522 // and will return true when the declaration context matches, and false
3524 //----------------------------------------------------------------------
3526 SymbolFileDWARF::DIEDeclContextsMatch (const DWARFDIE &die1,
3527 const DWARFDIE &die2)
3532 DWARFDIECollection decl_ctx_1;
3533 DWARFDIECollection decl_ctx_2;
3534 //The declaration DIE stack is a stack of the declaration context
3535 // DIEs all the way back to the compile unit. If a type "T" is
3536 // declared inside a class "B", and class "B" is declared inside
3537 // a class "A" and class "A" is in a namespace "lldb", and the
3538 // namespace is in a compile unit, there will be a stack of DIEs:
3540 // [0] DW_TAG_class_type for "B"
3541 // [1] DW_TAG_class_type for "A"
3542 // [2] DW_TAG_namespace for "lldb"
3543 // [3] DW_TAG_compile_unit for the source file.
3545 // We grab both contexts and make sure that everything matches
3546 // all the way back to the compiler unit.
3548 // First lets grab the decl contexts for both DIEs
3549 die1.GetDeclContextDIEs (decl_ctx_1);
3550 die2.GetDeclContextDIEs (decl_ctx_2);
3551 // Make sure the context arrays have the same size, otherwise
3553 const size_t count1 = decl_ctx_1.Size();
3554 const size_t count2 = decl_ctx_2.Size();
3555 if (count1 != count2)
3558 // Make sure the DW_TAG values match all the way back up the
3559 // compile unit. If they don't, then we are done.
3560 DWARFDIE decl_ctx_die1;
3561 DWARFDIE decl_ctx_die2;
3563 for (i=0; i<count1; i++)
3565 decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i);
3566 decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i);
3567 if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag())
3570 #if defined LLDB_CONFIGURATION_DEBUG
3572 // Make sure the top item in the decl context die array is always
3573 // DW_TAG_compile_unit. If it isn't then something went wrong in
3574 // the DWARFDIE::GetDeclContextDIEs() function...
3575 assert (decl_ctx_1.GetDIEAtIndex (count1 - 1).Tag() == DW_TAG_compile_unit);
3578 // Always skip the compile unit when comparing by only iterating up to
3579 // "count - 1". Here we compare the names as we go.
3580 for (i=0; i<count1 - 1; i++)
3582 decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex (i);
3583 decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex (i);
3584 const char *name1 = decl_ctx_die1.GetName();
3585 const char *name2 = decl_ctx_die2.GetName();
3586 // If the string was from a DW_FORM_strp, then the pointer will often
3591 // Name pointers are not equal, so only compare the strings
3592 // if both are not NULL.
3595 // If the strings don't compare, we are done...
3596 if (strcmp(name1, name2) != 0)
3601 // One name was NULL while the other wasn't
3605 // We made it through all of the checks and the declaration contexts
3612 SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &dwarf_decl_ctx)
3616 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
3617 if (dwarf_decl_ctx_count > 0)
3619 const ConstString type_name(dwarf_decl_ctx[0].name);
3620 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
3624 Log *log (LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION|DWARF_LOG_LOOKUPS));
3627 GetObjectFile()->GetModule()->LogMessage (log,
3628 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s')",
3629 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3630 dwarf_decl_ctx.GetQualifiedName());
3633 DIEArray die_offsets;
3635 if (m_using_apple_tables)
3637 if (m_apple_types_ap.get())
3639 const bool has_tag = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeTag);
3640 const bool has_qualified_name_hash = m_apple_types_ap->GetHeader().header_data.ContainsAtom (DWARFMappedHash::eAtomTypeQualNameHash);
3641 if (has_tag && has_qualified_name_hash)
3643 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
3644 const uint32_t qualified_name_hash = MappedHash::HashStringUsingDJB (qualified_name);
3646 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTagAndQualifiedNameHash()");
3647 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash (type_name.GetCString(), tag, qualified_name_hash, die_offsets);
3652 GetObjectFile()->GetModule()->LogMessage (log,"FindByNameAndTag()");
3653 m_apple_types_ap->FindByNameAndTag (type_name.GetCString(), tag, die_offsets);
3657 m_apple_types_ap->FindByName (type_name.GetCString(), die_offsets);
3666 m_type_index.Find (type_name, die_offsets);
3669 const size_t num_matches = die_offsets.size();
3674 DWARFDebugInfo* debug_info = DebugInfo();
3675 for (size_t i=0; i<num_matches; ++i)
3677 const DIERef& die_ref = die_offsets[i];
3678 DWARFDIE type_die = debug_info->GetDIE (die_ref);
3682 bool try_resolving_type = false;
3684 // Don't try and resolve the DIE we are looking for with the DIE itself!
3685 const dw_tag_t type_tag = type_die.Tag();
3686 // Make sure the tags match
3687 if (type_tag == tag)
3689 // The tags match, lets try resolving this type
3690 try_resolving_type = true;
3694 // The tags don't match, but we need to watch our for a
3695 // forward declaration for a struct and ("struct foo")
3696 // ends up being a class ("class foo { ... };") or
3700 case DW_TAG_class_type:
3701 // We had a "class foo", see if we ended up with a "struct foo { ... };"
3702 try_resolving_type = (tag == DW_TAG_structure_type);
3704 case DW_TAG_structure_type:
3705 // We had a "struct foo", see if we ended up with a "class foo { ... };"
3706 try_resolving_type = (tag == DW_TAG_class_type);
3709 // Tags don't match, don't event try to resolve
3710 // using this type whose name matches....
3715 if (try_resolving_type)
3717 DWARFDeclContext type_dwarf_decl_ctx;
3718 type_die.GetDWARFDeclContext (type_dwarf_decl_ctx);
3722 GetObjectFile()->GetModule()->LogMessage (log,
3723 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') trying die=0x%8.8x (%s)",
3724 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3725 dwarf_decl_ctx.GetQualifiedName(),
3726 type_die.GetOffset(),
3727 type_dwarf_decl_ctx.GetQualifiedName());
3730 // Make sure the decl contexts match all the way up
3731 if (dwarf_decl_ctx == type_dwarf_decl_ctx)
3733 Type *resolved_type = ResolveType (type_die, false);
3734 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
3736 type_sp = resolved_type->shared_from_this();
3745 std::string qualified_name;
3746 type_die.GetQualifiedName(qualified_name);
3747 GetObjectFile()->GetModule()->LogMessage (log,
3748 "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%s, qualified-name='%s') ignoring die=0x%8.8x (%s)",
3749 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3750 dwarf_decl_ctx.GetQualifiedName(),
3751 type_die.GetOffset(),
3752 qualified_name.c_str());
3758 if (m_using_apple_tables)
3760 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_types accelerator table had bad die 0x%8.8x for '%s')\n",
3761 die_ref.die_offset, type_name.GetCString());
3773 SymbolFileDWARF::ParseType (const SymbolContext& sc, const DWARFDIE &die, bool *type_is_new_ptr)
3779 TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
3783 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
3786 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
3787 type_sp = dwarf_ast->ParseTypeFromDWARF (sc, die, log, type_is_new_ptr);
3790 TypeList* type_list = GetTypeList();
3792 type_list->Insert(type_sp);
3794 if (die.Tag() == DW_TAG_subprogram)
3796 DIERef die_ref = die.GetDIERef();
3797 std::string scope_qualified_name(GetDeclContextForUID(die.GetID()).GetScopeQualifiedName().AsCString(""));
3798 if (scope_qualified_name.size())
3800 NameToOffsetMap::iterator iter = m_function_scope_qualified_name_map.find(scope_qualified_name);
3801 if (iter != m_function_scope_qualified_name_map.end())
3802 (*iter).second->insert(die_ref);
3805 DIERefSetSP new_set(new std::set<DIERef>);
3806 new_set->insert(die_ref);
3807 m_function_scope_qualified_name_map.emplace(std::make_pair(scope_qualified_name, new_set));
3820 SymbolFileDWARF::ParseTypes
3822 const SymbolContext& sc,
3823 const DWARFDIE &orig_die,
3824 bool parse_siblings,
3828 size_t types_added = 0;
3829 DWARFDIE die = orig_die;
3832 bool type_is_new = false;
3833 if (ParseType(sc, die, &type_is_new).get())
3839 if (parse_children && die.HasChildren())
3841 if (die.Tag() == DW_TAG_subprogram)
3843 SymbolContext child_sc(sc);
3844 child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
3845 types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true);
3848 types_added += ParseTypes(sc, die.GetFirstChild(), true, true);
3852 die = die.GetSibling();
3861 SymbolFileDWARF::ParseFunctionBlocks (const SymbolContext &sc)
3863 assert(sc.comp_unit && sc.function);
3864 size_t functions_added = 0;
3865 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
3868 const dw_offset_t function_die_offset = sc.function->GetID();
3869 DWARFDIE function_die = dwarf_cu->GetDIE (function_die_offset);
3872 ParseFunctionBlocks(sc, &sc.function->GetBlock (false), function_die, LLDB_INVALID_ADDRESS, 0);
3876 return functions_added;
3881 SymbolFileDWARF::ParseTypes (const SymbolContext &sc)
3883 // At least a compile unit must be valid
3884 assert(sc.comp_unit);
3885 size_t types_added = 0;
3886 DWARFCompileUnit* dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
3891 dw_offset_t function_die_offset = sc.function->GetID();
3892 DWARFDIE func_die = dwarf_cu->GetDIE(function_die_offset);
3893 if (func_die && func_die.HasChildren())
3895 types_added = ParseTypes(sc, func_die.GetFirstChild(), true, true);
3900 DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
3901 if (dwarf_cu_die && dwarf_cu_die.HasChildren())
3903 types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
3912 SymbolFileDWARF::ParseVariablesForContext (const SymbolContext& sc)
3914 if (sc.comp_unit != NULL)
3916 DWARFDebugInfo* info = DebugInfo();
3922 DWARFDIE function_die = info->GetDIE(DIERef(sc.function->GetID()));
3924 const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsAddress (DW_AT_low_pc, LLDB_INVALID_ADDRESS);
3925 if (func_lo_pc != LLDB_INVALID_ADDRESS)
3927 const size_t num_variables = ParseVariables(sc, function_die.GetFirstChild(), func_lo_pc, true, true);
3929 // Let all blocks know they have parse all their variables
3930 sc.function->GetBlock (false).SetDidParseVariables (true, true);
3931 return num_variables;
3934 else if (sc.comp_unit)
3936 DWARFCompileUnit* dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID());
3938 if (dwarf_cu == NULL)
3941 uint32_t vars_added = 0;
3942 VariableListSP variables (sc.comp_unit->GetVariableList(false));
3944 if (variables.get() == NULL)
3946 variables.reset(new VariableList());
3947 sc.comp_unit->SetVariableList(variables);
3949 DIEArray die_offsets;
3950 if (m_using_apple_tables)
3952 if (m_apple_names_ap.get())
3954 DWARFMappedHash::DIEInfoArray hash_data_array;
3955 if (m_apple_names_ap->AppendAllDIEsInRange (dwarf_cu->GetOffset(),
3956 dwarf_cu->GetNextCompileUnitOffset(),
3959 DWARFMappedHash::ExtractDIEArray (hash_data_array, die_offsets);
3965 // Index if we already haven't to make sure the compile units
3966 // get indexed and make their global DIE index list
3970 m_global_index.FindAllEntriesForCompileUnit (dwarf_cu->GetOffset(),
3974 const size_t num_matches = die_offsets.size();
3977 DWARFDebugInfo* debug_info = DebugInfo();
3978 for (size_t i=0; i<num_matches; ++i)
3980 const DIERef& die_ref = die_offsets[i];
3981 DWARFDIE die = debug_info->GetDIE (die_ref);
3984 VariableSP var_sp (ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS));
3987 variables->AddVariableIfUnique (var_sp);
3993 if (m_using_apple_tables)
3995 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected ("the DWARF debug information has been modified (.apple_names accelerator table had bad die 0x%8.8x)\n", die_ref.die_offset);
4009 SymbolFileDWARF::ParseVariableDIE
4011 const SymbolContext& sc,
4012 const DWARFDIE &die,
4013 const lldb::addr_t func_low_pc
4016 if (die.GetDWARF() != this)
4017 return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc);
4023 var_sp = GetDIEToVariable()[die.GetDIE()];
4025 return var_sp; // Already been parsed!
4027 const dw_tag_t tag = die.Tag();
4028 ModuleSP module = GetObjectFile()->GetModule();
4030 if ((tag == DW_TAG_variable) ||
4031 (tag == DW_TAG_constant) ||
4032 (tag == DW_TAG_formal_parameter && sc.function))
4034 DWARFAttributes attributes;
4035 const size_t num_attributes = die.GetAttributes(attributes);
4037 if (num_attributes > 0)
4039 const char *name = NULL;
4040 const char *mangled = NULL;
4043 DWARFFormValue type_die_form;
4044 DWARFExpression location(die.GetCU());
4045 bool is_external = false;
4046 bool is_artificial = false;
4047 bool location_is_const_value_data = false;
4048 bool has_explicit_location = false;
4049 DWARFFormValue const_value;
4050 //AccessType accessibility = eAccessNone;
4052 for (i=0; i<num_attributes; ++i)
4054 dw_attr_t attr = attributes.AttributeAtIndex(i);
4055 DWARFFormValue form_value;
4057 if (attributes.ExtractFormValueAtIndex(i, form_value))
4061 case DW_AT_decl_file: decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break;
4062 case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break;
4063 case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break;
4064 case DW_AT_name: name = form_value.AsCString(); break;
4065 case DW_AT_linkage_name:
4066 case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(); break;
4067 case DW_AT_type: type_die_form = form_value; break;
4068 case DW_AT_external: is_external = form_value.Boolean(); break;
4069 case DW_AT_const_value:
4070 // If we have already found a DW_AT_location attribute, ignore this attribute.
4071 if (!has_explicit_location)
4073 location_is_const_value_data = true;
4074 // The constant value will be either a block, a data value or a string.
4075 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
4076 if (DWARFFormValue::IsBlockForm(form_value.Form()))
4078 // Retrieve the value as a block expression.
4079 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4080 uint32_t block_length = form_value.Unsigned();
4081 location.CopyOpcodeData(module, debug_info_data, block_offset, block_length);
4083 else if (DWARFFormValue::IsDataForm(form_value.Form()))
4085 // Retrieve the value as a data expression.
4086 DWARFFormValue::FixedFormSizes fixed_form_sizes =
4087 DWARFFormValue::GetFixedFormSizesForAddressSize (
4088 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
4089 attributes.CompileUnitAtIndex(i)->IsDWARF64());
4090 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
4091 uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form());
4092 if (data_length == 0)
4094 const uint8_t *data_pointer = form_value.BlockData();
4097 form_value.Unsigned();
4099 else if (DWARFFormValue::IsDataForm(form_value.Form()))
4101 // we need to get the byte size of the type later after we create the variable
4102 const_value = form_value;
4106 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
4110 // Retrieve the value as a string expression.
4111 if (form_value.Form() == DW_FORM_strp)
4113 DWARFFormValue::FixedFormSizes fixed_form_sizes =
4114 DWARFFormValue::GetFixedFormSizesForAddressSize (
4115 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
4116 attributes.CompileUnitAtIndex(i)->IsDWARF64());
4117 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
4118 uint32_t data_length = fixed_form_sizes.GetSize(form_value.Form());
4119 location.CopyOpcodeData(module, debug_info_data, data_offset, data_length);
4123 const char *str = form_value.AsCString();
4124 uint32_t string_offset = str - (const char *)debug_info_data.GetDataStart();
4125 uint32_t string_length = strlen(str) + 1;
4126 location.CopyOpcodeData(module, debug_info_data, string_offset, string_length);
4131 case DW_AT_location:
4133 location_is_const_value_data = false;
4134 has_explicit_location = true;
4135 if (form_value.BlockData())
4137 const DWARFDataExtractor& debug_info_data = get_debug_info_data();
4139 uint32_t block_offset = form_value.BlockData() - debug_info_data.GetDataStart();
4140 uint32_t block_length = form_value.Unsigned();
4141 location.CopyOpcodeData(module, get_debug_info_data(), block_offset, block_length);
4145 const DWARFDataExtractor& debug_loc_data = get_debug_loc_data();
4146 const dw_offset_t debug_loc_offset = form_value.Unsigned();
4148 size_t loc_list_length = DWARFExpression::LocationListSize(die.GetCU(), debug_loc_data, debug_loc_offset);
4149 if (loc_list_length > 0)
4151 location.CopyOpcodeData(module, debug_loc_data, debug_loc_offset, loc_list_length);
4152 assert (func_low_pc != LLDB_INVALID_ADDRESS);
4153 location.SetLocationListSlide (func_low_pc - attributes.CompileUnitAtIndex(i)->GetBaseAddress());
4158 case DW_AT_specification:
4160 DWARFDebugInfo* debug_info = DebugInfo();
4162 spec_die = debug_info->GetDIE(DIERef(form_value));
4165 case DW_AT_artificial: is_artificial = form_value.Boolean(); break;
4166 case DW_AT_accessibility: break; //accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
4167 case DW_AT_declaration:
4168 case DW_AT_description:
4169 case DW_AT_endianity:
4171 case DW_AT_start_scope:
4172 case DW_AT_visibility:
4174 case DW_AT_abstract_origin:
4181 const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
4182 const dw_tag_t parent_tag = die.GetParent().Tag();
4183 bool is_static_member = parent_tag == DW_TAG_compile_unit && (parent_context_die.Tag() == DW_TAG_class_type || parent_context_die.Tag() == DW_TAG_structure_type);
4185 ValueType scope = eValueTypeInvalid;
4187 const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
4188 SymbolContextScope * symbol_context_scope = NULL;
4192 // LLDB relies on the mangled name (DW_TAG_linkage_name or DW_AT_MIPS_linkage_name) to
4193 // generate fully qualified names of global variables with commands like "frame var j".
4194 // For example, if j were an int variable holding a value 4 and declared in a namespace
4195 // B which in turn is contained in a namespace A, the command "frame var j" returns
4196 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we should be able
4197 // to generate a fully qualified name from the declaration context.
4198 if (parent_tag == DW_TAG_compile_unit &&
4199 Language::LanguageIsCPlusPlus(die.GetLanguage()))
4201 DWARFDeclContext decl_ctx;
4203 die.GetDWARFDeclContext(decl_ctx);
4204 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
4208 // DWARF doesn't specify if a DW_TAG_variable is a local, global
4209 // or static variable, so we have to do a little digging by
4210 // looking at the location of a variable to see if it contains
4211 // a DW_OP_addr opcode _somewhere_ in the definition. I say
4212 // somewhere because clang likes to combine small global variables
4213 // into the same symbol and have locations like:
4214 // DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
4215 // So if we don't have a DW_TAG_formal_parameter, we can look at
4216 // the location to see if it contains a DW_OP_addr opcode, and
4217 // then we can correctly classify our variables.
4218 if (tag == DW_TAG_formal_parameter)
4219 scope = eValueTypeVariableArgument;
4222 bool op_error = false;
4223 // Check if the location has a DW_OP_addr with any address value...
4224 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
4225 if (!location_is_const_value_data)
4227 location_DW_OP_addr = location.GetLocation_DW_OP_addr (0, op_error);
4231 location.DumpLocationForAddress (&strm, eDescriptionLevelFull, 0, 0, NULL);
4232 GetObjectFile()->GetModule()->ReportError ("0x%8.8x: %s has an invalid location: %s", die.GetOffset(), die.GetTagAsCString(), strm.GetString().c_str());
4236 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
4239 scope = eValueTypeVariableGlobal;
4241 scope = eValueTypeVariableStatic;
4244 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile ();
4246 if (debug_map_symfile)
4248 // When leaving the DWARF in the .o files on darwin,
4249 // when we have a global variable that wasn't initialized,
4250 // the .o file might not have allocated a virtual
4251 // address for the global variable. In this case it will
4252 // have created a symbol for the global variable
4253 // that is undefined/data and external and the value will
4254 // be the byte size of the variable. When we do the
4255 // address map in SymbolFileDWARFDebugMap we rely on
4256 // having an address, we need to do some magic here
4257 // so we can get the correct address for our global
4258 // variable. The address for all of these entries
4259 // will be zero, and there will be an undefined symbol
4260 // in this object file, and the executable will have
4261 // a matching symbol with a good address. So here we
4262 // dig up the correct address and replace it in the
4263 // location for the variable, and set the variable's
4264 // symbol context scope to be that of the main executable
4265 // so the file address will resolve correctly.
4266 bool linked_oso_file_addr = false;
4267 if (is_external && location_DW_OP_addr == 0)
4269 // we have a possible uninitialized extern global
4270 ConstString const_name(mangled ? mangled : name);
4271 ObjectFile *debug_map_objfile = debug_map_symfile->GetObjectFile();
4272 if (debug_map_objfile)
4274 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
4275 if (debug_map_symtab)
4277 Symbol *exe_symbol = debug_map_symtab->FindFirstSymbolWithNameAndType (const_name,
4280 Symtab::eVisibilityExtern);
4283 if (exe_symbol->ValueIsAddress())
4285 const addr_t exe_file_addr = exe_symbol->GetAddressRef().GetFileAddress();
4286 if (exe_file_addr != LLDB_INVALID_ADDRESS)
4288 if (location.Update_DW_OP_addr (exe_file_addr))
4290 linked_oso_file_addr = true;
4291 symbol_context_scope = exe_symbol;
4300 if (!linked_oso_file_addr)
4302 // The DW_OP_addr is not zero, but it contains a .o file address which
4303 // needs to be linked up correctly.
4304 const lldb::addr_t exe_file_addr = debug_map_symfile->LinkOSOFileAddress(this, location_DW_OP_addr);
4305 if (exe_file_addr != LLDB_INVALID_ADDRESS)
4307 // Update the file address for this variable
4308 location.Update_DW_OP_addr (exe_file_addr);
4312 // Variable didn't make it into the final executable
4320 if (location_is_const_value_data)
4321 scope = eValueTypeVariableStatic;
4323 scope = eValueTypeVariableLocal;
4327 if (symbol_context_scope == NULL)
4331 case DW_TAG_subprogram:
4332 case DW_TAG_inlined_subroutine:
4333 case DW_TAG_lexical_block:
4336 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
4337 if (symbol_context_scope == NULL)
4338 symbol_context_scope = sc.function;
4343 symbol_context_scope = sc.comp_unit;
4348 if (symbol_context_scope)
4350 SymbolFileTypeSP type_sp(new SymbolFileType(*this, DIERef(type_die_form).GetUID()));
4352 if (const_value.Form() && type_sp && type_sp->GetType())
4353 location.CopyOpcodeData(const_value.Unsigned(), type_sp->GetType()->GetByteSize(), die.GetCU()->GetAddressByteSize());
4355 var_sp.reset (new Variable (die.GetID(),
4360 symbol_context_scope,
4367 var_sp->SetLocationIsConstantValueData (location_is_const_value_data);
4371 // Not ready to parse this variable yet. It might be a global
4372 // or static variable that is in a function scope and the function
4373 // in the symbol context wasn't filled in yet
4377 // Cache var_sp even if NULL (the variable was just a specification or
4378 // was missing vital information to be able to be displayed in the debugger
4379 // (missing location due to optimization, etc)) so we don't re-parse
4380 // this DIE over and over later...
4381 GetDIEToVariable()[die.GetDIE()] = var_sp;
4383 GetDIEToVariable()[spec_die.GetDIE()] = var_sp;
4390 SymbolFileDWARF::FindBlockContainingSpecification (const DIERef& func_die_ref,
4391 dw_offset_t spec_block_die_offset)
4393 // Give the concrete function die specified by "func_die_offset", find the
4394 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4395 // to "spec_block_die_offset"
4396 return FindBlockContainingSpecification (DebugInfo()->GetDIE (func_die_ref), spec_block_die_offset);
4401 SymbolFileDWARF::FindBlockContainingSpecification(const DWARFDIE &die,
4402 dw_offset_t spec_block_die_offset)
4408 case DW_TAG_subprogram:
4409 case DW_TAG_inlined_subroutine:
4410 case DW_TAG_lexical_block:
4412 if (die.GetAttributeValueAsReference (DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
4415 if (die.GetAttributeValueAsReference (DW_AT_abstract_origin, DW_INVALID_OFFSET) == spec_block_die_offset)
4421 // Give the concrete function die specified by "func_die_offset", find the
4422 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4423 // to "spec_block_die_offset"
4424 for (DWARFDIE child_die = die.GetFirstChild(); child_die; child_die = child_die.GetSibling())
4426 DWARFDIE result_die = FindBlockContainingSpecification (child_die, spec_block_die_offset);
4436 SymbolFileDWARF::ParseVariables (const SymbolContext& sc,
4437 const DWARFDIE &orig_die,
4438 const lldb::addr_t func_low_pc,
4439 bool parse_siblings,
4440 bool parse_children,
4441 VariableList* cc_variable_list)
4446 VariableListSP variable_list_sp;
4448 size_t vars_added = 0;
4449 DWARFDIE die = orig_die;
4452 dw_tag_t tag = die.Tag();
4454 // Check to see if we have already parsed this variable or constant?
4455 VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
4458 if (cc_variable_list)
4459 cc_variable_list->AddVariableIfUnique (var_sp);
4463 // We haven't already parsed it, lets do that now.
4464 if ((tag == DW_TAG_variable) ||
4465 (tag == DW_TAG_constant) ||
4466 (tag == DW_TAG_formal_parameter && sc.function))
4468 if (variable_list_sp.get() == NULL)
4470 DWARFDIE sc_parent_die = GetParentSymbolContextDIE(orig_die);
4471 dw_tag_t parent_tag = sc_parent_die.Tag();
4474 case DW_TAG_compile_unit:
4475 if (sc.comp_unit != NULL)
4477 variable_list_sp = sc.comp_unit->GetVariableList(false);
4478 if (variable_list_sp.get() == NULL)
4480 variable_list_sp.reset(new VariableList());
4481 sc.comp_unit->SetVariableList(variable_list_sp);
4486 GetObjectFile()->GetModule()->ReportError ("parent 0x%8.8" PRIx64 " %s with no valid compile unit in symbol context for 0x%8.8" PRIx64 " %s.\n",
4487 sc_parent_die.GetID(),
4488 sc_parent_die.GetTagAsCString(),
4490 orig_die.GetTagAsCString());
4494 case DW_TAG_subprogram:
4495 case DW_TAG_inlined_subroutine:
4496 case DW_TAG_lexical_block:
4497 if (sc.function != NULL)
4499 // Check to see if we already have parsed the variables for the given scope
4501 Block *block = sc.function->GetBlock(true).FindBlockByID(sc_parent_die.GetID());
4504 // This must be a specification or abstract origin with
4505 // a concrete block counterpart in the current function. We need
4506 // to find the concrete block so we can correctly add the
4508 const DWARFDIE concrete_block_die = FindBlockContainingSpecification (DIERef(sc.function->GetID()),
4509 sc_parent_die.GetOffset());
4510 if (concrete_block_die)
4511 block = sc.function->GetBlock(true).FindBlockByID(concrete_block_die.GetID());
4516 const bool can_create = false;
4517 variable_list_sp = block->GetBlockVariableList (can_create);
4518 if (variable_list_sp.get() == NULL)
4520 variable_list_sp.reset(new VariableList());
4521 block->SetVariableList(variable_list_sp);
4528 GetObjectFile()->GetModule()->ReportError ("didn't find appropriate parent DIE for variable list for 0x%8.8" PRIx64 " %s.\n",
4530 orig_die.GetTagAsCString());
4535 if (variable_list_sp)
4537 VariableSP var_sp (ParseVariableDIE(sc, die, func_low_pc));
4540 variable_list_sp->AddVariableIfUnique (var_sp);
4541 if (cc_variable_list)
4542 cc_variable_list->AddVariableIfUnique (var_sp);
4549 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4551 if (!skip_children && parse_children && die.HasChildren())
4553 vars_added += ParseVariables(sc, die.GetFirstChild(), func_low_pc, true, true, cc_variable_list);
4557 die = die.GetSibling();
4564 //------------------------------------------------------------------
4565 // PluginInterface protocol
4566 //------------------------------------------------------------------
4568 SymbolFileDWARF::GetPluginName()
4570 return GetPluginNameStatic();
4574 SymbolFileDWARF::GetPluginVersion()
4580 SymbolFileDWARF::DumpIndexes ()
4582 StreamFile s(stdout, false);
4584 s.Printf ("DWARF index for (%s) '%s':",
4585 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
4586 GetObjectFile()->GetFileSpec().GetPath().c_str());
4587 s.Printf("\nFunction basenames:\n"); m_function_basename_index.Dump (&s);
4588 s.Printf("\nFunction fullnames:\n"); m_function_fullname_index.Dump (&s);
4589 s.Printf("\nFunction methods:\n"); m_function_method_index.Dump (&s);
4590 s.Printf("\nFunction selectors:\n"); m_function_selector_index.Dump (&s);
4591 s.Printf("\nObjective C class selectors:\n"); m_objc_class_selectors_index.Dump (&s);
4592 s.Printf("\nGlobals and statics:\n"); m_global_index.Dump (&s);
4593 s.Printf("\nTypes:\n"); m_type_index.Dump (&s);
4594 s.Printf("\nNamespaces:\n"); m_namespace_index.Dump (&s);
4598 SymbolFileDWARFDebugMap *
4599 SymbolFileDWARF::GetDebugMapSymfile ()
4601 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired())
4603 lldb::ModuleSP module_sp (m_debug_map_module_wp.lock());
4606 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
4608 m_debug_map_symfile = (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
4611 return m_debug_map_symfile;
4614 DWARFExpression::LocationListFormat
4615 SymbolFileDWARF::GetLocationListFormat() const
4617 return DWARFExpression::RegularLocationList;