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/ClangUtil.h"
39 #include "lldb/Symbol/CompileUnit.h"
40 #include "lldb/Symbol/CompilerDecl.h"
41 #include "lldb/Symbol/CompilerDeclContext.h"
42 #include "lldb/Symbol/DebugMacros.h"
43 #include "lldb/Symbol/LineTable.h"
44 #include "lldb/Symbol/ObjectFile.h"
45 #include "lldb/Symbol/SymbolVendor.h"
46 #include "lldb/Symbol/TypeMap.h"
47 #include "lldb/Symbol/TypeSystem.h"
48 #include "lldb/Symbol/VariableList.h"
50 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
51 #include "Plugins/Language/ObjC/ObjCLanguage.h"
53 #include "lldb/Target/Language.h"
55 #include "lldb/Utility/TaskPool.h"
57 #include "DWARFASTParser.h"
58 #include "DWARFASTParserClang.h"
59 #include "DWARFCompileUnit.h"
60 #include "DWARFDIECollection.h"
61 #include "DWARFDebugAbbrev.h"
62 #include "DWARFDebugAranges.h"
63 #include "DWARFDebugInfo.h"
64 #include "DWARFDebugLine.h"
65 #include "DWARFDebugMacro.h"
66 #include "DWARFDebugPubnames.h"
67 #include "DWARFDebugRanges.h"
68 #include "DWARFDeclContext.h"
69 #include "DWARFFormValue.h"
70 #include "LogChannelDWARF.h"
71 #include "SymbolFileDWARFDebugMap.h"
72 #include "SymbolFileDWARFDwo.h"
79 //#define ENABLE_DEBUG_PRINTF // COMMENT OUT THIS LINE PRIOR TO CHECKIN
81 #ifdef ENABLE_DEBUG_PRINTF
83 #define DEBUG_PRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
85 #define DEBUG_PRINTF(fmt, ...)
89 using namespace lldb_private;
92 // child_requires_parent_class_union_or_struct_to_be_completed (dw_tag_t tag)
98 // case DW_TAG_subprogram:
99 // case DW_TAG_inlined_subroutine:
100 // case DW_TAG_class_type:
101 // case DW_TAG_structure_type:
102 // case DW_TAG_union_type:
111 PropertyDefinition g_properties[] = {
112 {"comp-dir-symlink-paths", OptionValue::eTypeFileSpecList, true, 0, nullptr,
113 nullptr, "If the DW_AT_comp_dir matches any of these paths the symbolic "
114 "links will be resolved at DWARF parse time."},
115 {nullptr, OptionValue::eTypeInvalid, false, 0, nullptr, nullptr, nullptr}};
117 enum { ePropertySymLinkPaths };
119 class PluginProperties : public Properties {
121 static ConstString GetSettingName() {
122 return SymbolFileDWARF::GetPluginNameStatic();
126 m_collection_sp.reset(new OptionValueProperties(GetSettingName()));
127 m_collection_sp->Initialize(g_properties);
130 FileSpecList &GetSymLinkPaths() {
131 OptionValueFileSpecList *option_value =
132 m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(
133 nullptr, true, ePropertySymLinkPaths);
134 assert(option_value);
135 return option_value->GetCurrentValue();
139 typedef std::shared_ptr<PluginProperties> SymbolFileDWARFPropertiesSP;
141 static const SymbolFileDWARFPropertiesSP &GetGlobalPluginProperties() {
142 static const auto g_settings_sp(std::make_shared<PluginProperties>());
143 return g_settings_sp;
146 } // anonymous namespace end
148 static const char *removeHostnameFromPathname(const char *path_from_dwarf) {
149 if (!path_from_dwarf || !path_from_dwarf[0]) {
150 return path_from_dwarf;
153 const char *colon_pos = strchr(path_from_dwarf, ':');
154 if (nullptr == colon_pos) {
155 return path_from_dwarf;
158 const char *slash_pos = strchr(path_from_dwarf, '/');
159 if (slash_pos && (slash_pos < colon_pos)) {
160 return path_from_dwarf;
163 // check whether we have a windows path, and so the first character
164 // is a drive-letter not a hostname.
165 if (colon_pos == path_from_dwarf + 1 && isalpha(*path_from_dwarf) &&
166 strlen(path_from_dwarf) > 2 && '\\' == path_from_dwarf[2]) {
167 return path_from_dwarf;
170 return colon_pos + 1;
173 static const char *resolveCompDir(const char *path_from_dwarf) {
174 if (!path_from_dwarf)
177 // DWARF2/3 suggests the form hostname:pathname for compilation directory.
178 // Remove the host part if present.
179 const char *local_path = removeHostnameFromPathname(path_from_dwarf);
183 bool is_symlink = false;
184 FileSpec local_path_spec(local_path, false);
185 const auto &file_specs = GetGlobalPluginProperties()->GetSymLinkPaths();
186 for (size_t i = 0; i < file_specs.GetSize() && !is_symlink; ++i)
187 is_symlink = FileSpec::Equal(file_specs.GetFileSpecAtIndex(i),
188 local_path_spec, true);
193 if (!local_path_spec.IsSymbolicLink())
196 FileSpec resolved_local_path_spec;
198 FileSystem::Readlink(local_path_spec, resolved_local_path_spec);
200 return resolved_local_path_spec.GetCString();
205 void SymbolFileDWARF::Initialize() {
206 LogChannelDWARF::Initialize();
207 PluginManager::RegisterPlugin(GetPluginNameStatic(),
208 GetPluginDescriptionStatic(), CreateInstance,
212 void SymbolFileDWARF::DebuggerInitialize(Debugger &debugger) {
213 if (!PluginManager::GetSettingForSymbolFilePlugin(
214 debugger, PluginProperties::GetSettingName())) {
215 const bool is_global_setting = true;
216 PluginManager::CreateSettingForSymbolFilePlugin(
217 debugger, GetGlobalPluginProperties()->GetValueProperties(),
218 ConstString("Properties for the dwarf symbol-file plug-in."),
223 void SymbolFileDWARF::Terminate() {
224 PluginManager::UnregisterPlugin(CreateInstance);
225 LogChannelDWARF::Initialize();
228 lldb_private::ConstString SymbolFileDWARF::GetPluginNameStatic() {
229 static ConstString g_name("dwarf");
233 const char *SymbolFileDWARF::GetPluginDescriptionStatic() {
234 return "DWARF and DWARF3 debug symbol file reader.";
237 SymbolFile *SymbolFileDWARF::CreateInstance(ObjectFile *obj_file) {
238 return new SymbolFileDWARF(obj_file);
241 TypeList *SymbolFileDWARF::GetTypeList() {
242 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
243 if (debug_map_symfile)
244 return debug_map_symfile->GetTypeList();
246 return m_obj_file->GetModule()->GetTypeList();
248 void SymbolFileDWARF::GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset,
249 dw_offset_t max_die_offset, uint32_t type_mask,
252 const dw_offset_t die_offset = die.GetOffset();
254 if (die_offset >= max_die_offset)
257 if (die_offset >= min_die_offset) {
258 const dw_tag_t tag = die.Tag();
260 bool add_type = false;
263 case DW_TAG_array_type:
264 add_type = (type_mask & eTypeClassArray) != 0;
266 case DW_TAG_unspecified_type:
267 case DW_TAG_base_type:
268 add_type = (type_mask & eTypeClassBuiltin) != 0;
270 case DW_TAG_class_type:
271 add_type = (type_mask & eTypeClassClass) != 0;
273 case DW_TAG_structure_type:
274 add_type = (type_mask & eTypeClassStruct) != 0;
276 case DW_TAG_union_type:
277 add_type = (type_mask & eTypeClassUnion) != 0;
279 case DW_TAG_enumeration_type:
280 add_type = (type_mask & eTypeClassEnumeration) != 0;
282 case DW_TAG_subroutine_type:
283 case DW_TAG_subprogram:
284 case DW_TAG_inlined_subroutine:
285 add_type = (type_mask & eTypeClassFunction) != 0;
287 case DW_TAG_pointer_type:
288 add_type = (type_mask & eTypeClassPointer) != 0;
290 case DW_TAG_rvalue_reference_type:
291 case DW_TAG_reference_type:
292 add_type = (type_mask & eTypeClassReference) != 0;
295 add_type = (type_mask & eTypeClassTypedef) != 0;
297 case DW_TAG_ptr_to_member_type:
298 add_type = (type_mask & eTypeClassMemberPointer) != 0;
303 const bool assert_not_being_parsed = true;
304 Type *type = ResolveTypeUID(die, assert_not_being_parsed);
306 if (type_set.find(type) == type_set.end())
307 type_set.insert(type);
312 for (DWARFDIE child_die = die.GetFirstChild(); child_die.IsValid();
313 child_die = child_die.GetSibling()) {
314 GetTypes(child_die, min_die_offset, max_die_offset, type_mask, type_set);
319 size_t SymbolFileDWARF::GetTypes(SymbolContextScope *sc_scope,
320 uint32_t type_mask, TypeList &type_list)
325 CompileUnit *comp_unit = NULL;
326 DWARFCompileUnit *dwarf_cu = NULL;
328 comp_unit = sc_scope->CalculateSymbolContextCompileUnit();
331 dwarf_cu = GetDWARFCompileUnit(comp_unit);
334 GetTypes(dwarf_cu->DIE(), dwarf_cu->GetOffset(),
335 dwarf_cu->GetNextCompileUnitOffset(), type_mask, type_set);
337 DWARFDebugInfo *info = DebugInfo();
339 const size_t num_cus = info->GetNumCompileUnits();
340 for (size_t cu_idx = 0; cu_idx < num_cus; ++cu_idx) {
341 dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
343 GetTypes(dwarf_cu->DIE(), 0, UINT32_MAX, type_mask, type_set);
349 std::set<CompilerType> compiler_type_set;
350 size_t num_types_added = 0;
351 for (Type *type : type_set) {
352 CompilerType compiler_type = type->GetForwardCompilerType();
353 if (compiler_type_set.find(compiler_type) == compiler_type_set.end()) {
354 compiler_type_set.insert(compiler_type);
355 type_list.Insert(type->shared_from_this());
359 return num_types_added;
362 //----------------------------------------------------------------------
363 // Gets the first parent that is a lexical block, function or inlined
364 // subroutine, or compile unit.
365 //----------------------------------------------------------------------
367 SymbolFileDWARF::GetParentSymbolContextDIE(const DWARFDIE &child_die) {
369 for (die = child_die.GetParent(); die; die = die.GetParent()) {
370 dw_tag_t tag = die.Tag();
373 case DW_TAG_compile_unit:
374 case DW_TAG_subprogram:
375 case DW_TAG_inlined_subroutine:
376 case DW_TAG_lexical_block:
383 SymbolFileDWARF::SymbolFileDWARF(ObjectFile *objfile)
384 : SymbolFile(objfile), UserID(0), // Used by SymbolFileDWARFDebugMap to when
385 // this class parses .o files to contain
386 // the .o file index/ID
387 m_debug_map_module_wp(), m_debug_map_symfile(NULL), m_data_debug_abbrev(),
388 m_data_debug_aranges(), m_data_debug_frame(), m_data_debug_info(),
389 m_data_debug_line(), m_data_debug_macro(), m_data_debug_loc(),
390 m_data_debug_ranges(), m_data_debug_str(), m_data_apple_names(),
391 m_data_apple_types(), m_data_apple_namespaces(), m_abbr(), m_info(),
392 m_line(), m_apple_names_ap(), m_apple_types_ap(), m_apple_namespaces_ap(),
393 m_apple_objc_ap(), m_function_basename_index(),
394 m_function_fullname_index(), m_function_method_index(),
395 m_function_selector_index(), m_objc_class_selectors_index(),
396 m_global_index(), m_type_index(), m_namespace_index(), m_indexed(false),
397 m_using_apple_tables(false), m_fetched_external_modules(false),
398 m_supports_DW_AT_APPLE_objc_complete_type(eLazyBoolCalculate), m_ranges(),
399 m_unique_ast_type_map() {}
401 SymbolFileDWARF::~SymbolFileDWARF() {}
403 static const ConstString &GetDWARFMachOSegmentName() {
404 static ConstString g_dwarf_section_name("__DWARF");
405 return g_dwarf_section_name;
408 UniqueDWARFASTTypeMap &SymbolFileDWARF::GetUniqueDWARFASTTypeMap() {
409 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
410 if (debug_map_symfile)
411 return debug_map_symfile->GetUniqueDWARFASTTypeMap();
413 return m_unique_ast_type_map;
416 TypeSystem *SymbolFileDWARF::GetTypeSystemForLanguage(LanguageType language) {
417 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
418 TypeSystem *type_system;
419 if (debug_map_symfile) {
420 type_system = debug_map_symfile->GetTypeSystemForLanguage(language);
422 type_system = m_obj_file->GetModule()->GetTypeSystemForLanguage(language);
424 type_system->SetSymbolFile(this);
429 void SymbolFileDWARF::InitializeObject() {
430 ModuleSP module_sp(m_obj_file->GetModule());
432 const SectionList *section_list = module_sp->GetSectionList();
433 const Section *section =
434 section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
436 // Memory map the DWARF mach-o segment so we have everything mmap'ed
437 // to keep our heap memory usage down.
439 m_obj_file->MemoryMapSectionData(section, m_dwarf_data);
442 get_apple_names_data();
443 if (m_data_apple_names.m_data.GetByteSize() > 0) {
444 m_apple_names_ap.reset(new DWARFMappedHash::MemoryTable(
445 m_data_apple_names.m_data, get_debug_str_data(), ".apple_names"));
446 if (m_apple_names_ap->IsValid())
447 m_using_apple_tables = true;
449 m_apple_names_ap.reset();
451 get_apple_types_data();
452 if (m_data_apple_types.m_data.GetByteSize() > 0) {
453 m_apple_types_ap.reset(new DWARFMappedHash::MemoryTable(
454 m_data_apple_types.m_data, get_debug_str_data(), ".apple_types"));
455 if (m_apple_types_ap->IsValid())
456 m_using_apple_tables = true;
458 m_apple_types_ap.reset();
461 get_apple_namespaces_data();
462 if (m_data_apple_namespaces.m_data.GetByteSize() > 0) {
463 m_apple_namespaces_ap.reset(new DWARFMappedHash::MemoryTable(
464 m_data_apple_namespaces.m_data, get_debug_str_data(),
465 ".apple_namespaces"));
466 if (m_apple_namespaces_ap->IsValid())
467 m_using_apple_tables = true;
469 m_apple_namespaces_ap.reset();
472 get_apple_objc_data();
473 if (m_data_apple_objc.m_data.GetByteSize() > 0) {
474 m_apple_objc_ap.reset(new DWARFMappedHash::MemoryTable(
475 m_data_apple_objc.m_data, get_debug_str_data(), ".apple_objc"));
476 if (m_apple_objc_ap->IsValid())
477 m_using_apple_tables = true;
479 m_apple_objc_ap.reset();
483 bool SymbolFileDWARF::SupportedVersion(uint16_t version) {
484 return version == 2 || version == 3 || version == 4;
487 uint32_t SymbolFileDWARF::CalculateAbilities() {
488 uint32_t abilities = 0;
489 if (m_obj_file != NULL) {
490 const Section *section = NULL;
491 const SectionList *section_list = m_obj_file->GetSectionList();
492 if (section_list == NULL)
495 uint64_t debug_abbrev_file_size = 0;
496 uint64_t debug_info_file_size = 0;
497 uint64_t debug_line_file_size = 0;
499 section = section_list->FindSectionByName(GetDWARFMachOSegmentName()).get();
502 section_list = §ion->GetChildren();
505 section_list->FindSectionByType(eSectionTypeDWARFDebugInfo, true).get();
506 if (section != NULL) {
507 debug_info_file_size = section->GetFileSize();
510 section_list->FindSectionByType(eSectionTypeDWARFDebugAbbrev, true)
513 debug_abbrev_file_size = section->GetFileSize();
516 section_list->FindSectionByType(eSectionTypeDWARFDebugLine, true)
519 debug_line_file_size = section->GetFileSize();
521 const char *symfile_dir_cstr =
522 m_obj_file->GetFileSpec().GetDirectory().GetCString();
523 if (symfile_dir_cstr) {
524 if (strcasestr(symfile_dir_cstr, ".dsym")) {
525 if (m_obj_file->GetType() == ObjectFile::eTypeDebugInfo) {
526 // We have a dSYM file that didn't have a any debug info.
527 // If the string table has a size of 1, then it was made from
528 // an executable with no debug info, or from an executable that
531 section_list->FindSectionByType(eSectionTypeDWARFDebugStr, true)
533 if (section && section->GetFileSize() == 1) {
534 m_obj_file->GetModule()->ReportWarning(
535 "empty dSYM file detected, dSYM was created with an "
536 "executable with no debug info.");
543 if (debug_abbrev_file_size > 0 && debug_info_file_size > 0)
544 abilities |= CompileUnits | Functions | Blocks | GlobalVariables |
545 LocalVariables | VariableTypes;
547 if (debug_line_file_size > 0)
548 abilities |= LineTables;
553 const DWARFDataExtractor &
554 SymbolFileDWARF::GetCachedSectionData(lldb::SectionType sect_type,
555 DWARFDataSegment &data_segment) {
556 std::call_once(data_segment.m_flag, &SymbolFileDWARF::LoadSectionData, this,
557 sect_type, std::ref(data_segment.m_data));
558 return data_segment.m_data;
561 void SymbolFileDWARF::LoadSectionData(lldb::SectionType sect_type,
562 DWARFDataExtractor &data) {
563 ModuleSP module_sp(m_obj_file->GetModule());
564 const SectionList *section_list = module_sp->GetSectionList();
566 SectionSP section_sp(section_list->FindSectionByType(sect_type, true));
568 // See if we memory mapped the DWARF segment?
569 if (m_dwarf_data.GetByteSize()) {
570 data.SetData(m_dwarf_data, section_sp->GetOffset(),
571 section_sp->GetFileSize());
573 if (m_obj_file->ReadSectionData(section_sp.get(), data) == 0)
580 const DWARFDataExtractor &SymbolFileDWARF::get_debug_abbrev_data() {
581 return GetCachedSectionData(eSectionTypeDWARFDebugAbbrev,
582 m_data_debug_abbrev);
585 const DWARFDataExtractor &SymbolFileDWARF::get_debug_addr_data() {
586 return GetCachedSectionData(eSectionTypeDWARFDebugAddr, m_data_debug_addr);
589 const DWARFDataExtractor &SymbolFileDWARF::get_debug_aranges_data() {
590 return GetCachedSectionData(eSectionTypeDWARFDebugAranges,
591 m_data_debug_aranges);
594 const DWARFDataExtractor &SymbolFileDWARF::get_debug_frame_data() {
595 return GetCachedSectionData(eSectionTypeDWARFDebugFrame, m_data_debug_frame);
598 const DWARFDataExtractor &SymbolFileDWARF::get_debug_info_data() {
599 return GetCachedSectionData(eSectionTypeDWARFDebugInfo, m_data_debug_info);
602 const DWARFDataExtractor &SymbolFileDWARF::get_debug_line_data() {
603 return GetCachedSectionData(eSectionTypeDWARFDebugLine, m_data_debug_line);
606 const DWARFDataExtractor &SymbolFileDWARF::get_debug_macro_data() {
607 return GetCachedSectionData(eSectionTypeDWARFDebugMacro, m_data_debug_macro);
610 const DWARFDataExtractor &SymbolFileDWARF::get_debug_loc_data() {
611 return GetCachedSectionData(eSectionTypeDWARFDebugLoc, m_data_debug_loc);
614 const DWARFDataExtractor &SymbolFileDWARF::get_debug_ranges_data() {
615 return GetCachedSectionData(eSectionTypeDWARFDebugRanges,
616 m_data_debug_ranges);
619 const DWARFDataExtractor &SymbolFileDWARF::get_debug_str_data() {
620 return GetCachedSectionData(eSectionTypeDWARFDebugStr, m_data_debug_str);
623 const DWARFDataExtractor &SymbolFileDWARF::get_debug_str_offsets_data() {
624 return GetCachedSectionData(eSectionTypeDWARFDebugStrOffsets,
625 m_data_debug_str_offsets);
628 const DWARFDataExtractor &SymbolFileDWARF::get_apple_names_data() {
629 return GetCachedSectionData(eSectionTypeDWARFAppleNames, m_data_apple_names);
632 const DWARFDataExtractor &SymbolFileDWARF::get_apple_types_data() {
633 return GetCachedSectionData(eSectionTypeDWARFAppleTypes, m_data_apple_types);
636 const DWARFDataExtractor &SymbolFileDWARF::get_apple_namespaces_data() {
637 return GetCachedSectionData(eSectionTypeDWARFAppleNamespaces,
638 m_data_apple_namespaces);
641 const DWARFDataExtractor &SymbolFileDWARF::get_apple_objc_data() {
642 return GetCachedSectionData(eSectionTypeDWARFAppleObjC, m_data_apple_objc);
645 DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() {
646 if (m_abbr.get() == NULL) {
647 const DWARFDataExtractor &debug_abbrev_data = get_debug_abbrev_data();
648 if (debug_abbrev_data.GetByteSize() > 0) {
649 m_abbr.reset(new DWARFDebugAbbrev());
651 m_abbr->Parse(debug_abbrev_data);
657 const DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() const {
661 DWARFDebugInfo *SymbolFileDWARF::DebugInfo() {
662 if (m_info.get() == NULL) {
663 Timer scoped_timer(LLVM_PRETTY_FUNCTION, "%s this = %p",
664 LLVM_PRETTY_FUNCTION, static_cast<void *>(this));
665 if (get_debug_info_data().GetByteSize() > 0) {
666 m_info.reset(new DWARFDebugInfo());
668 m_info->SetDwarfData(this);
675 const DWARFDebugInfo *SymbolFileDWARF::DebugInfo() const {
680 SymbolFileDWARF::GetDWARFCompileUnit(lldb_private::CompileUnit *comp_unit) {
684 DWARFDebugInfo *info = DebugInfo();
686 // Just a normal DWARF file whose user ID for the compile unit is
687 // the DWARF offset itself
689 DWARFCompileUnit *dwarf_cu =
690 info->GetCompileUnit((dw_offset_t)comp_unit->GetID());
691 if (dwarf_cu && dwarf_cu->GetUserData() == NULL)
692 dwarf_cu->SetUserData(comp_unit);
698 DWARFDebugRanges *SymbolFileDWARF::DebugRanges() {
699 if (m_ranges.get() == NULL) {
700 Timer scoped_timer(LLVM_PRETTY_FUNCTION, "%s this = %p",
701 LLVM_PRETTY_FUNCTION, static_cast<void *>(this));
702 if (get_debug_ranges_data().GetByteSize() > 0) {
703 m_ranges.reset(new DWARFDebugRanges());
705 m_ranges->Extract(this);
708 return m_ranges.get();
711 const DWARFDebugRanges *SymbolFileDWARF::DebugRanges() const {
712 return m_ranges.get();
715 lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFCompileUnit *dwarf_cu,
719 CompileUnit *comp_unit = (CompileUnit *)dwarf_cu->GetUserData();
721 // We already parsed this compile unit, had out a shared pointer to it
722 cu_sp = comp_unit->shared_from_this();
724 if (dwarf_cu->GetSymbolFileDWARF() != this) {
725 return dwarf_cu->GetSymbolFileDWARF()->ParseCompileUnit(dwarf_cu,
727 } else if (dwarf_cu->GetOffset() == 0 && GetDebugMapSymfile()) {
728 // Let the debug map create the compile unit
729 cu_sp = m_debug_map_symfile->GetCompileUnit(this);
730 dwarf_cu->SetUserData(cu_sp.get());
732 ModuleSP module_sp(m_obj_file->GetModule());
734 const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly();
736 FileSpec cu_file_spec{cu_die.GetName(), false};
738 // If we have a full path to the compile unit, we don't need to
740 // the file. This can be expensive e.g. when the source files are
742 if (cu_file_spec.IsRelative()) {
743 const char *cu_comp_dir{
744 cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr)};
745 cu_file_spec.PrependPathComponent(resolveCompDir(cu_comp_dir));
748 std::string remapped_file;
749 if (module_sp->RemapSourceFile(cu_file_spec.GetPath(),
751 cu_file_spec.SetFile(remapped_file, false);
754 LanguageType cu_language = DWARFCompileUnit::LanguageTypeFromDWARF(
755 cu_die.GetAttributeValueAsUnsigned(DW_AT_language, 0));
757 bool is_optimized = dwarf_cu->GetIsOptimized();
758 cu_sp.reset(new CompileUnit(
759 module_sp, dwarf_cu, cu_file_spec, dwarf_cu->GetID(),
760 cu_language, is_optimized ? eLazyBoolYes : eLazyBoolNo));
762 // If we just created a compile unit with an invalid file spec,
764 // first entry in the supports files from the line table as that
768 cu_file_spec = cu_sp->GetSupportFiles().GetFileSpecAtIndex(1);
770 (FileSpec &)(*cu_sp) = cu_file_spec;
771 // Also fix the invalid file spec which was copied from the
773 cu_sp->GetSupportFiles().Replace(0, cu_file_spec);
777 dwarf_cu->SetUserData(cu_sp.get());
779 // Figure out the compile unit index if we weren't given one
780 if (cu_idx == UINT32_MAX)
781 DebugInfo()->GetCompileUnit(dwarf_cu->GetOffset(), &cu_idx);
783 m_obj_file->GetModule()->GetSymbolVendor()->SetCompileUnitAtIndex(
794 uint32_t SymbolFileDWARF::GetNumCompileUnits() {
795 DWARFDebugInfo *info = DebugInfo();
797 return info->GetNumCompileUnits();
801 CompUnitSP SymbolFileDWARF::ParseCompileUnitAtIndex(uint32_t cu_idx) {
803 DWARFDebugInfo *info = DebugInfo();
805 DWARFCompileUnit *dwarf_cu = info->GetCompileUnitAtIndex(cu_idx);
807 cu_sp = ParseCompileUnit(dwarf_cu, cu_idx);
812 Function *SymbolFileDWARF::ParseCompileUnitFunction(const SymbolContext &sc,
813 const DWARFDIE &die) {
815 TypeSystem *type_system =
816 GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
819 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
821 return dwarf_ast->ParseFunctionFromDWARF(sc, die);
827 bool SymbolFileDWARF::FixupAddress(Address &addr) {
828 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
829 if (debug_map_symfile) {
830 return debug_map_symfile->LinkOSOAddress(addr);
832 // This is a normal DWARF file, no address fixups need to happen
836 SymbolFileDWARF::ParseCompileUnitLanguage(const SymbolContext &sc) {
837 assert(sc.comp_unit);
838 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
840 return dwarf_cu->GetLanguageType();
842 return eLanguageTypeUnknown;
845 size_t SymbolFileDWARF::ParseCompileUnitFunctions(const SymbolContext &sc) {
846 assert(sc.comp_unit);
847 size_t functions_added = 0;
848 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
850 DWARFDIECollection function_dies;
851 const size_t num_functions =
852 dwarf_cu->AppendDIEsWithTag(DW_TAG_subprogram, function_dies);
854 for (func_idx = 0; func_idx < num_functions; ++func_idx) {
855 DWARFDIE die = function_dies.GetDIEAtIndex(func_idx);
856 if (sc.comp_unit->FindFunctionByUID(die.GetID()).get() == NULL) {
857 if (ParseCompileUnitFunction(sc, die))
863 return functions_added;
866 bool SymbolFileDWARF::ParseCompileUnitSupportFiles(
867 const SymbolContext &sc, FileSpecList &support_files) {
868 assert(sc.comp_unit);
869 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
871 const DWARFDIE cu_die = dwarf_cu->GetCompileUnitDIEOnly();
874 const char *cu_comp_dir = resolveCompDir(
875 cu_die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr));
876 const dw_offset_t stmt_list = cu_die.GetAttributeValueAsUnsigned(
877 DW_AT_stmt_list, DW_INVALID_OFFSET);
878 if (stmt_list != DW_INVALID_OFFSET) {
879 // All file indexes in DWARF are one based and a file of index zero is
880 // supposed to be the compile unit itself.
881 support_files.Append(*sc.comp_unit);
882 return DWARFDebugLine::ParseSupportFiles(
883 sc.comp_unit->GetModule(), get_debug_line_data(), cu_comp_dir,
884 stmt_list, support_files);
891 bool SymbolFileDWARF::ParseCompileUnitIsOptimized(
892 const lldb_private::SymbolContext &sc) {
893 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
895 return dwarf_cu->GetIsOptimized();
899 bool SymbolFileDWARF::ParseImportedModules(
900 const lldb_private::SymbolContext &sc,
901 std::vector<lldb_private::ConstString> &imported_modules) {
902 assert(sc.comp_unit);
903 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
905 if (ClangModulesDeclVendor::LanguageSupportsClangModules(
906 sc.comp_unit->GetLanguage())) {
907 UpdateExternalModuleListIfNeeded();
910 const DWARFDIE die = dwarf_cu->GetCompileUnitDIEOnly();
913 for (DWARFDIE child_die = die.GetFirstChild(); child_die;
914 child_die = child_die.GetSibling()) {
915 if (child_die.Tag() == DW_TAG_imported_declaration) {
916 if (DWARFDIE module_die =
917 child_die.GetReferencedDIE(DW_AT_import)) {
918 if (module_die.Tag() == DW_TAG_module) {
919 if (const char *name = module_die.GetAttributeValueAsString(
920 DW_AT_name, nullptr)) {
921 ConstString const_name(name);
922 imported_modules.push_back(const_name);
930 for (const auto &pair : m_external_type_modules) {
931 imported_modules.push_back(pair.first);
939 struct ParseDWARFLineTableCallbackInfo {
940 LineTable *line_table;
941 std::unique_ptr<LineSequence> sequence_ap;
942 lldb::addr_t addr_mask;
945 //----------------------------------------------------------------------
946 // ParseStatementTableCallback
947 //----------------------------------------------------------------------
948 static void ParseDWARFLineTableCallback(dw_offset_t offset,
949 const DWARFDebugLine::State &state,
951 if (state.row == DWARFDebugLine::State::StartParsingLineTable) {
952 // Just started parsing the line table
953 } else if (state.row == DWARFDebugLine::State::DoneParsingLineTable) {
954 // Done parsing line table, nothing to do for the cleanup
956 ParseDWARFLineTableCallbackInfo *info =
957 (ParseDWARFLineTableCallbackInfo *)userData;
958 LineTable *line_table = info->line_table;
960 // If this is our first time here, we need to create a
961 // sequence container.
962 if (!info->sequence_ap.get()) {
963 info->sequence_ap.reset(line_table->CreateLineSequenceContainer());
964 assert(info->sequence_ap.get());
966 line_table->AppendLineEntryToSequence(
967 info->sequence_ap.get(), state.address & info->addr_mask, state.line,
968 state.column, state.file, state.is_stmt, state.basic_block,
969 state.prologue_end, state.epilogue_begin, state.end_sequence);
970 if (state.end_sequence) {
971 // First, put the current sequence into the line table.
972 line_table->InsertSequence(info->sequence_ap.get());
973 // Then, empty it to prepare for the next sequence.
974 info->sequence_ap->Clear();
979 bool SymbolFileDWARF::ParseCompileUnitLineTable(const SymbolContext &sc) {
980 assert(sc.comp_unit);
981 if (sc.comp_unit->GetLineTable() != NULL)
984 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
986 const DWARFDIE dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
988 const dw_offset_t cu_line_offset =
989 dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list,
991 if (cu_line_offset != DW_INVALID_OFFSET) {
992 std::unique_ptr<LineTable> line_table_ap(new LineTable(sc.comp_unit));
993 if (line_table_ap.get()) {
994 ParseDWARFLineTableCallbackInfo info;
995 info.line_table = line_table_ap.get();
999 * The SymbolContext may not have a valid target, thus we may not be
1001 * to call Address::GetOpcodeLoadAddress() which would clear the bit
1003 * for MIPS. Use ArchSpec to clear the bit #0.
1006 GetObjectFile()->GetArchitecture(arch);
1007 switch (arch.GetMachine()) {
1008 case llvm::Triple::mips:
1009 case llvm::Triple::mipsel:
1010 case llvm::Triple::mips64:
1011 case llvm::Triple::mips64el:
1012 info.addr_mask = ~((lldb::addr_t)1);
1015 info.addr_mask = ~((lldb::addr_t)0);
1019 lldb::offset_t offset = cu_line_offset;
1020 DWARFDebugLine::ParseStatementTable(get_debug_line_data(), &offset,
1021 ParseDWARFLineTableCallback,
1023 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
1024 if (debug_map_symfile) {
1025 // We have an object file that has a line table with addresses
1026 // that are not linked. We need to link the line table and convert
1027 // the addresses that are relative to the .o file into addresses
1028 // for the main executable.
1029 sc.comp_unit->SetLineTable(
1030 debug_map_symfile->LinkOSOLineTable(this, line_table_ap.get()));
1032 sc.comp_unit->SetLineTable(line_table_ap.release());
1042 lldb_private::DebugMacrosSP
1043 SymbolFileDWARF::ParseDebugMacros(lldb::offset_t *offset) {
1044 auto iter = m_debug_macros_map.find(*offset);
1045 if (iter != m_debug_macros_map.end())
1046 return iter->second;
1048 const DWARFDataExtractor &debug_macro_data = get_debug_macro_data();
1049 if (debug_macro_data.GetByteSize() == 0)
1050 return DebugMacrosSP();
1052 lldb_private::DebugMacrosSP debug_macros_sp(new lldb_private::DebugMacros());
1053 m_debug_macros_map[*offset] = debug_macros_sp;
1055 const DWARFDebugMacroHeader &header =
1056 DWARFDebugMacroHeader::ParseHeader(debug_macro_data, offset);
1057 DWARFDebugMacroEntry::ReadMacroEntries(debug_macro_data, get_debug_str_data(),
1058 header.OffsetIs64Bit(), offset, this,
1061 return debug_macros_sp;
1064 bool SymbolFileDWARF::ParseCompileUnitDebugMacros(const SymbolContext &sc) {
1065 assert(sc.comp_unit);
1067 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
1068 if (dwarf_cu == nullptr)
1071 const DWARFDIE dwarf_cu_die = dwarf_cu->GetCompileUnitDIEOnly();
1075 lldb::offset_t sect_offset =
1076 dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_macros, DW_INVALID_OFFSET);
1077 if (sect_offset == DW_INVALID_OFFSET)
1078 sect_offset = dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_GNU_macros,
1080 if (sect_offset == DW_INVALID_OFFSET)
1083 sc.comp_unit->SetDebugMacros(ParseDebugMacros(§_offset));
1088 size_t SymbolFileDWARF::ParseFunctionBlocks(const SymbolContext &sc,
1089 Block *parent_block,
1090 const DWARFDIE &orig_die,
1091 addr_t subprogram_low_pc,
1093 size_t blocks_added = 0;
1094 DWARFDIE die = orig_die;
1096 dw_tag_t tag = die.Tag();
1099 case DW_TAG_inlined_subroutine:
1100 case DW_TAG_subprogram:
1101 case DW_TAG_lexical_block: {
1102 Block *block = NULL;
1103 if (tag == DW_TAG_subprogram) {
1104 // Skip any DW_TAG_subprogram DIEs that are inside
1105 // of a normal or inlined functions. These will be
1106 // parsed on their own as separate entities.
1111 block = parent_block;
1113 BlockSP block_sp(new Block(die.GetID()));
1114 parent_block->AddChild(block_sp);
1115 block = block_sp.get();
1117 DWARFRangeList ranges;
1118 const char *name = NULL;
1119 const char *mangled_name = NULL;
1123 int decl_column = 0;
1126 int call_column = 0;
1127 if (die.GetDIENamesAndRanges(name, mangled_name, ranges, decl_file,
1128 decl_line, decl_column, call_file, call_line,
1129 call_column, nullptr)) {
1130 if (tag == DW_TAG_subprogram) {
1131 assert(subprogram_low_pc == LLDB_INVALID_ADDRESS);
1132 subprogram_low_pc = ranges.GetMinRangeBase(0);
1133 } else if (tag == DW_TAG_inlined_subroutine) {
1134 // We get called here for inlined subroutines in two ways.
1135 // The first time is when we are making the Function object
1136 // for this inlined concrete instance. Since we're creating a top
1138 // here, the subprogram_low_pc will be LLDB_INVALID_ADDRESS. So we
1140 // adjust the containing address.
1141 // The second time is when we are parsing the blocks inside the
1142 // function that contains
1143 // the inlined concrete instance. Since these will be blocks inside
1144 // the containing "real"
1145 // function the offset will be for that function.
1146 if (subprogram_low_pc == LLDB_INVALID_ADDRESS) {
1147 subprogram_low_pc = ranges.GetMinRangeBase(0);
1151 const size_t num_ranges = ranges.GetSize();
1152 for (size_t i = 0; i < num_ranges; ++i) {
1153 const DWARFRangeList::Entry &range = ranges.GetEntryRef(i);
1154 const addr_t range_base = range.GetRangeBase();
1155 if (range_base >= subprogram_low_pc)
1156 block->AddRange(Block::Range(range_base - subprogram_low_pc,
1157 range.GetByteSize()));
1159 GetObjectFile()->GetModule()->ReportError(
1160 "0x%8.8" PRIx64 ": adding range [0x%" PRIx64 "-0x%" PRIx64
1161 ") which has a base that is less than the function's low PC "
1162 "0x%" PRIx64 ". Please file a bug and attach the file at the "
1163 "start of this error message",
1164 block->GetID(), range_base, range.GetRangeEnd(),
1168 block->FinalizeRanges();
1170 if (tag != DW_TAG_subprogram &&
1171 (name != NULL || mangled_name != NULL)) {
1172 std::unique_ptr<Declaration> decl_ap;
1173 if (decl_file != 0 || decl_line != 0 || decl_column != 0)
1174 decl_ap.reset(new Declaration(
1175 sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(decl_file),
1176 decl_line, decl_column));
1178 std::unique_ptr<Declaration> call_ap;
1179 if (call_file != 0 || call_line != 0 || call_column != 0)
1180 call_ap.reset(new Declaration(
1181 sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(call_file),
1182 call_line, call_column));
1184 block->SetInlinedFunctionInfo(name, mangled_name, decl_ap.get(),
1190 if (die.HasChildren()) {
1191 blocks_added += ParseFunctionBlocks(sc, block, die.GetFirstChild(),
1192 subprogram_low_pc, depth + 1);
1200 // Only parse siblings of the block if we are not at depth zero. A depth
1201 // of zero indicates we are currently parsing the top level
1202 // DW_TAG_subprogram DIE
1207 die = die.GetSibling();
1209 return blocks_added;
1212 bool SymbolFileDWARF::ClassOrStructIsVirtual(const DWARFDIE &parent_die) {
1214 for (DWARFDIE die = parent_die.GetFirstChild(); die;
1215 die = die.GetSibling()) {
1216 dw_tag_t tag = die.Tag();
1217 bool check_virtuality = false;
1219 case DW_TAG_inheritance:
1220 case DW_TAG_subprogram:
1221 check_virtuality = true;
1226 if (check_virtuality) {
1227 if (die.GetAttributeValueAsUnsigned(DW_AT_virtuality, 0) != 0)
1235 void SymbolFileDWARF::ParseDeclsForContext(CompilerDeclContext decl_ctx) {
1236 TypeSystem *type_system = decl_ctx.GetTypeSystem();
1237 DWARFASTParser *ast_parser = type_system->GetDWARFParser();
1238 std::vector<DWARFDIE> decl_ctx_die_list =
1239 ast_parser->GetDIEForDeclContext(decl_ctx);
1241 for (DWARFDIE decl_ctx_die : decl_ctx_die_list)
1242 for (DWARFDIE decl = decl_ctx_die.GetFirstChild(); decl;
1243 decl = decl.GetSibling())
1244 ast_parser->GetDeclForUIDFromDWARF(decl);
1247 SymbolFileDWARF *SymbolFileDWARF::GetDWARFForUID(lldb::user_id_t uid) {
1248 // Anytime we get a "lldb::user_id_t" from an lldb_private::SymbolFile API
1249 // we must make sure we use the correct DWARF file when resolving things.
1250 // On MacOSX, when using SymbolFileDWARFDebugMap, we will use multiple
1251 // SymbolFileDWARF classes, one for each .o file. We can often end up
1252 // with references to other DWARF objects and we must be ready to receive
1253 // a "lldb::user_id_t" that specifies a DIE from another SymbolFileDWARF
1255 SymbolFileDWARFDebugMap *debug_map = GetDebugMapSymfile();
1257 return debug_map->GetSymbolFileByOSOIndex(
1258 debug_map->GetOSOIndexFromUserID(uid));
1263 SymbolFileDWARF::GetDIEFromUID(lldb::user_id_t uid) {
1264 // Anytime we get a "lldb::user_id_t" from an lldb_private::SymbolFile API
1265 // we must make sure we use the correct DWARF file when resolving things.
1266 // On MacOSX, when using SymbolFileDWARFDebugMap, we will use multiple
1267 // SymbolFileDWARF classes, one for each .o file. We can often end up
1268 // with references to other DWARF objects and we must be ready to receive
1269 // a "lldb::user_id_t" that specifies a DIE from another SymbolFileDWARF
1271 SymbolFileDWARF *dwarf = GetDWARFForUID(uid);
1273 return dwarf->GetDIE(DIERef(uid, dwarf));
1277 CompilerDecl SymbolFileDWARF::GetDeclForUID(lldb::user_id_t type_uid) {
1278 // Anytime we have a lldb::user_id_t, we must get the DIE by
1279 // calling SymbolFileDWARF::GetDIEFromUID(). See comments inside
1280 // the SymbolFileDWARF::GetDIEFromUID() for details.
1281 DWARFDIE die = GetDIEFromUID(type_uid);
1283 return die.GetDecl();
1284 return CompilerDecl();
1288 SymbolFileDWARF::GetDeclContextForUID(lldb::user_id_t type_uid) {
1289 // Anytime we have a lldb::user_id_t, we must get the DIE by
1290 // calling SymbolFileDWARF::GetDIEFromUID(). See comments inside
1291 // the SymbolFileDWARF::GetDIEFromUID() for details.
1292 DWARFDIE die = GetDIEFromUID(type_uid);
1294 return die.GetDeclContext();
1295 return CompilerDeclContext();
1299 SymbolFileDWARF::GetDeclContextContainingUID(lldb::user_id_t type_uid) {
1300 // Anytime we have a lldb::user_id_t, we must get the DIE by
1301 // calling SymbolFileDWARF::GetDIEFromUID(). See comments inside
1302 // the SymbolFileDWARF::GetDIEFromUID() for details.
1303 DWARFDIE die = GetDIEFromUID(type_uid);
1305 return die.GetContainingDeclContext();
1306 return CompilerDeclContext();
1309 Type *SymbolFileDWARF::ResolveTypeUID(lldb::user_id_t type_uid) {
1310 // Anytime we have a lldb::user_id_t, we must get the DIE by
1311 // calling SymbolFileDWARF::GetDIEFromUID(). See comments inside
1312 // the SymbolFileDWARF::GetDIEFromUID() for details.
1313 DWARFDIE type_die = GetDIEFromUID(type_uid);
1315 return type_die.ResolveType();
1320 Type *SymbolFileDWARF::ResolveTypeUID(const DIERef &die_ref) {
1321 return ResolveType(GetDIE(die_ref), true);
1324 Type *SymbolFileDWARF::ResolveTypeUID(const DWARFDIE &die,
1325 bool assert_not_being_parsed) {
1327 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO));
1329 GetObjectFile()->GetModule()->LogMessage(
1330 log, "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s'",
1331 die.GetOffset(), die.GetTagAsCString(), die.GetName());
1333 // We might be coming in in the middle of a type tree (a class
1334 // within a class, an enum within a class), so parse any needed
1335 // parent DIEs before we get to this one...
1336 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(die);
1339 switch (decl_ctx_die.Tag()) {
1340 case DW_TAG_structure_type:
1341 case DW_TAG_union_type:
1342 case DW_TAG_class_type: {
1343 // Get the type, which could be a forward declaration
1345 GetObjectFile()->GetModule()->LogMessage(
1346 log, "SymbolFileDWARF::ResolveTypeUID (die = 0x%8.8x) %s '%s' "
1347 "resolve parent forward type for 0x%8.8x",
1348 die.GetOffset(), die.GetTagAsCString(), die.GetName(),
1349 decl_ctx_die.GetOffset());
1357 return ResolveType(die);
1362 // This function is used when SymbolFileDWARFDebugMap owns a bunch of
1363 // SymbolFileDWARF objects to detect if this DWARF file is the one that
1364 // can resolve a compiler_type.
1365 bool SymbolFileDWARF::HasForwardDeclForClangType(
1366 const CompilerType &compiler_type) {
1367 CompilerType compiler_type_no_qualifiers =
1368 ClangUtil::RemoveFastQualifiers(compiler_type);
1369 if (GetForwardDeclClangTypeToDie().count(
1370 compiler_type_no_qualifiers.GetOpaqueQualType())) {
1373 TypeSystem *type_system = compiler_type.GetTypeSystem();
1375 ClangASTContext *clang_type_system =
1376 llvm::dyn_cast_or_null<ClangASTContext>(type_system);
1377 if (!clang_type_system)
1379 DWARFASTParserClang *ast_parser =
1380 static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser());
1381 return ast_parser->GetClangASTImporter().CanImport(compiler_type);
1384 bool SymbolFileDWARF::CompleteType(CompilerType &compiler_type) {
1385 std::lock_guard<std::recursive_mutex> guard(
1386 GetObjectFile()->GetModule()->GetMutex());
1388 ClangASTContext *clang_type_system =
1389 llvm::dyn_cast_or_null<ClangASTContext>(compiler_type.GetTypeSystem());
1390 if (clang_type_system) {
1391 DWARFASTParserClang *ast_parser =
1392 static_cast<DWARFASTParserClang *>(clang_type_system->GetDWARFParser());
1394 ast_parser->GetClangASTImporter().CanImport(compiler_type))
1395 return ast_parser->GetClangASTImporter().CompleteType(compiler_type);
1398 // We have a struct/union/class/enum that needs to be fully resolved.
1399 CompilerType compiler_type_no_qualifiers =
1400 ClangUtil::RemoveFastQualifiers(compiler_type);
1401 auto die_it = GetForwardDeclClangTypeToDie().find(
1402 compiler_type_no_qualifiers.GetOpaqueQualType());
1403 if (die_it == GetForwardDeclClangTypeToDie().end()) {
1404 // We have already resolved this type...
1408 DWARFDIE dwarf_die = GetDIE(die_it->getSecond());
1410 // Once we start resolving this type, remove it from the forward declaration
1411 // map in case anyone child members or other types require this type to get
1413 // The type will get resolved when all of the calls to
1414 // SymbolFileDWARF::ResolveClangOpaqueTypeDefinition
1416 GetForwardDeclClangTypeToDie().erase(die_it);
1418 Type *type = GetDIEToType().lookup(dwarf_die.GetDIE());
1420 Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_DEBUG_INFO |
1421 DWARF_LOG_TYPE_COMPLETION));
1423 GetObjectFile()->GetModule()->LogMessageVerboseBacktrace(
1424 log, "0x%8.8" PRIx64 ": %s '%s' resolving forward declaration...",
1425 dwarf_die.GetID(), dwarf_die.GetTagAsCString(),
1426 type->GetName().AsCString());
1427 assert(compiler_type);
1428 DWARFASTParser *dwarf_ast = dwarf_die.GetDWARFParser();
1430 return dwarf_ast->CompleteTypeFromDWARF(dwarf_die, type, compiler_type);
1435 Type *SymbolFileDWARF::ResolveType(const DWARFDIE &die,
1436 bool assert_not_being_parsed,
1437 bool resolve_function_context) {
1439 Type *type = GetTypeForDIE(die, resolve_function_context).get();
1441 if (assert_not_being_parsed) {
1442 if (type != DIE_IS_BEING_PARSED)
1445 GetObjectFile()->GetModule()->ReportError(
1446 "Parsing a die that is being parsed die: 0x%8.8x: %s %s",
1447 die.GetOffset(), die.GetTagAsCString(), die.GetName());
1456 SymbolFileDWARF::GetCompUnitForDWARFCompUnit(DWARFCompileUnit *dwarf_cu,
1458 // Check if the symbol vendor already knows about this compile unit?
1459 if (dwarf_cu->GetUserData() == NULL) {
1460 // The symbol vendor doesn't know about this compile unit, we
1461 // need to parse and add it to the symbol vendor object.
1462 return ParseCompileUnit(dwarf_cu, cu_idx).get();
1464 return (CompileUnit *)dwarf_cu->GetUserData();
1467 size_t SymbolFileDWARF::GetObjCMethodDIEOffsets(ConstString class_name,
1468 DIEArray &method_die_offsets) {
1469 method_die_offsets.clear();
1470 if (m_using_apple_tables) {
1471 if (m_apple_objc_ap.get())
1472 m_apple_objc_ap->FindByName(class_name.GetCString(), method_die_offsets);
1477 m_objc_class_selectors_index.Find(class_name, method_die_offsets);
1479 return method_die_offsets.size();
1482 bool SymbolFileDWARF::GetFunction(const DWARFDIE &die, SymbolContext &sc) {
1486 // Check if the symbol vendor already knows about this compile unit?
1487 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
1489 sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
1490 if (sc.function == NULL)
1491 sc.function = ParseCompileUnitFunction(sc, die);
1494 sc.module_sp = sc.function->CalculateSymbolContextModule();
1502 lldb::ModuleSP SymbolFileDWARF::GetDWOModule(ConstString name) {
1503 UpdateExternalModuleListIfNeeded();
1504 const auto &pos = m_external_type_modules.find(name);
1505 if (pos != m_external_type_modules.end())
1508 return lldb::ModuleSP();
1512 SymbolFileDWARF::GetDIE(const DIERef &die_ref) {
1513 DWARFDebugInfo *debug_info = DebugInfo();
1515 return debug_info->GetDIE(die_ref);
1520 std::unique_ptr<SymbolFileDWARFDwo>
1521 SymbolFileDWARF::GetDwoSymbolFileForCompileUnit(
1522 DWARFCompileUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die) {
1523 // If we are using a dSYM file, we never want the standard DWO files since
1524 // the -gmodule support uses the same DWO machanism to specify full debug
1525 // info files for modules.
1526 if (GetDebugMapSymfile())
1529 const char *dwo_name = cu_die.GetAttributeValueAsString(
1530 this, &dwarf_cu, DW_AT_GNU_dwo_name, nullptr);
1534 FileSpec dwo_file(dwo_name, true);
1535 if (dwo_file.IsRelative()) {
1536 const char *comp_dir = cu_die.GetAttributeValueAsString(
1537 this, &dwarf_cu, DW_AT_comp_dir, nullptr);
1541 dwo_file.SetFile(comp_dir, true);
1542 dwo_file.AppendPathComponent(dwo_name);
1545 if (!dwo_file.Exists())
1548 const lldb::offset_t file_offset = 0;
1549 DataBufferSP dwo_file_data_sp;
1550 lldb::offset_t dwo_file_data_offset = 0;
1551 ObjectFileSP dwo_obj_file = ObjectFile::FindPlugin(
1552 GetObjectFile()->GetModule(), &dwo_file, file_offset,
1553 dwo_file.GetByteSize(), dwo_file_data_sp, dwo_file_data_offset);
1554 if (dwo_obj_file == nullptr)
1557 return llvm::make_unique<SymbolFileDWARFDwo>(dwo_obj_file, &dwarf_cu);
1560 void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() {
1561 if (m_fetched_external_modules)
1563 m_fetched_external_modules = true;
1565 DWARFDebugInfo *debug_info = DebugInfo();
1567 const uint32_t num_compile_units = GetNumCompileUnits();
1568 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
1569 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1571 const DWARFDIE die = dwarf_cu->GetCompileUnitDIEOnly();
1572 if (die && die.HasChildren() == false) {
1573 const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr);
1576 ConstString const_name(name);
1577 if (m_external_type_modules.find(const_name) ==
1578 m_external_type_modules.end()) {
1580 const char *dwo_path =
1581 die.GetAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr);
1583 ModuleSpec dwo_module_spec;
1584 dwo_module_spec.GetFileSpec().SetFile(dwo_path, false);
1585 if (dwo_module_spec.GetFileSpec().IsRelative()) {
1586 const char *comp_dir =
1587 die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr);
1589 dwo_module_spec.GetFileSpec().SetFile(comp_dir, true);
1590 dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path);
1593 dwo_module_spec.GetArchitecture() =
1594 m_obj_file->GetModule()->GetArchitecture();
1595 // printf ("Loading dwo = '%s'\n", dwo_path);
1596 Error error = ModuleList::GetSharedModule(
1597 dwo_module_spec, module_sp, NULL, NULL, NULL);
1599 GetObjectFile()->GetModule()->ReportWarning(
1600 "0x%8.8x: unable to locate module needed for external types: "
1601 "%s\nerror: %s\nDebugging will be degraded due to missing "
1602 "types. Rebuilding your project will regenerate the needed "
1605 dwo_module_spec.GetFileSpec().GetPath().c_str(),
1606 error.AsCString("unknown error"));
1609 m_external_type_modules[const_name] = module_sp;
1616 SymbolFileDWARF::GlobalVariableMap &SymbolFileDWARF::GetGlobalAranges() {
1617 if (!m_global_aranges_ap) {
1618 m_global_aranges_ap.reset(new GlobalVariableMap());
1620 ModuleSP module_sp = GetObjectFile()->GetModule();
1622 const size_t num_cus = module_sp->GetNumCompileUnits();
1623 for (size_t i = 0; i < num_cus; ++i) {
1624 CompUnitSP cu_sp = module_sp->GetCompileUnitAtIndex(i);
1626 VariableListSP globals_sp = cu_sp->GetVariableList(true);
1628 const size_t num_globals = globals_sp->GetSize();
1629 for (size_t g = 0; g < num_globals; ++g) {
1630 VariableSP var_sp = globals_sp->GetVariableAtIndex(g);
1631 if (var_sp && !var_sp->GetLocationIsConstantValueData()) {
1632 const DWARFExpression &location = var_sp->LocationExpression();
1633 Value location_result;
1635 if (location.Evaluate(nullptr, nullptr, nullptr,
1636 LLDB_INVALID_ADDRESS, nullptr, nullptr,
1637 location_result, &error)) {
1638 if (location_result.GetValueType() ==
1639 Value::eValueTypeFileAddress) {
1640 lldb::addr_t file_addr =
1641 location_result.GetScalar().ULongLong();
1642 lldb::addr_t byte_size = 1;
1643 if (var_sp->GetType())
1644 byte_size = var_sp->GetType()->GetByteSize();
1645 m_global_aranges_ap->Append(GlobalVariableMap::Entry(
1646 file_addr, byte_size, var_sp.get()));
1655 m_global_aranges_ap->Sort();
1657 return *m_global_aranges_ap;
1660 uint32_t SymbolFileDWARF::ResolveSymbolContext(const Address &so_addr,
1661 uint32_t resolve_scope,
1662 SymbolContext &sc) {
1663 Timer scoped_timer(LLVM_PRETTY_FUNCTION, "SymbolFileDWARF::"
1664 "ResolveSymbolContext (so_addr = { "
1665 "section = %p, offset = 0x%" PRIx64
1666 " }, resolve_scope = 0x%8.8x)",
1667 static_cast<void *>(so_addr.GetSection().get()),
1668 so_addr.GetOffset(), resolve_scope);
1669 uint32_t resolved = 0;
1671 (eSymbolContextCompUnit | eSymbolContextFunction | eSymbolContextBlock |
1672 eSymbolContextLineEntry | eSymbolContextVariable)) {
1673 lldb::addr_t file_vm_addr = so_addr.GetFileAddress();
1675 DWARFDebugInfo *debug_info = DebugInfo();
1677 const dw_offset_t cu_offset =
1678 debug_info->GetCompileUnitAranges().FindAddress(file_vm_addr);
1679 if (cu_offset == DW_INVALID_OFFSET) {
1680 // Global variables are not in the compile unit address ranges. The only
1682 // currently find global variables is to iterate over the
1683 // .debug_pubnames or the
1684 // __apple_names table and find all items in there that point to
1686 // DIEs and then find the address that matches.
1687 if (resolve_scope & eSymbolContextVariable) {
1688 GlobalVariableMap &map = GetGlobalAranges();
1689 const GlobalVariableMap::Entry *entry =
1690 map.FindEntryThatContains(file_vm_addr);
1691 if (entry && entry->data) {
1692 Variable *variable = entry->data;
1693 SymbolContextScope *scc = variable->GetSymbolContextScope();
1695 scc->CalculateSymbolContext(&sc);
1696 sc.variable = variable;
1698 return sc.GetResolvedMask();
1702 uint32_t cu_idx = DW_INVALID_INDEX;
1703 DWARFCompileUnit *dwarf_cu =
1704 debug_info->GetCompileUnit(cu_offset, &cu_idx);
1706 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
1708 resolved |= eSymbolContextCompUnit;
1710 bool force_check_line_table = false;
1712 (eSymbolContextFunction | eSymbolContextBlock)) {
1713 DWARFDIE function_die = dwarf_cu->LookupAddress(file_vm_addr);
1717 sc.comp_unit->FindFunctionByUID(function_die.GetID()).get();
1718 if (sc.function == NULL)
1719 sc.function = ParseCompileUnitFunction(sc, function_die);
1721 if (sc.function && (resolve_scope & eSymbolContextBlock))
1722 block_die = function_die.LookupDeepestBlock(file_vm_addr);
1724 // We might have had a compile unit that had discontiguous
1725 // address ranges where the gaps are symbols that don't have
1726 // any debug info. Discontiguous compile unit address ranges
1727 // should only happen when there aren't other functions from
1728 // other compile units in these gaps. This helps keep the size
1729 // of the aranges down.
1730 force_check_line_table = true;
1733 if (sc.function != NULL) {
1734 resolved |= eSymbolContextFunction;
1736 if (resolve_scope & eSymbolContextBlock) {
1737 Block &block = sc.function->GetBlock(true);
1740 sc.block = block.FindBlockByID(block_die.GetID());
1742 sc.block = block.FindBlockByID(function_die.GetID());
1744 resolved |= eSymbolContextBlock;
1749 if ((resolve_scope & eSymbolContextLineEntry) ||
1750 force_check_line_table) {
1751 LineTable *line_table = sc.comp_unit->GetLineTable();
1752 if (line_table != NULL) {
1753 // And address that makes it into this function should be in
1755 // of this debug file if there is no debug map, or it will be an
1756 // address in the .o file which needs to be fixed up to be in
1758 // of the debug map executable. Either way, calling
1760 // will work for us.
1761 Address exe_so_addr(so_addr);
1762 if (FixupAddress(exe_so_addr)) {
1763 if (line_table->FindLineEntryByAddress(exe_so_addr,
1765 resolved |= eSymbolContextLineEntry;
1771 if (force_check_line_table &&
1772 !(resolved & eSymbolContextLineEntry)) {
1773 // We might have had a compile unit that had discontiguous
1774 // address ranges where the gaps are symbols that don't have
1775 // any debug info. Discontiguous compile unit address ranges
1776 // should only happen when there aren't other functions from
1777 // other compile units in these gaps. This helps keep the size
1778 // of the aranges down.
1779 sc.comp_unit = NULL;
1780 resolved &= ~eSymbolContextCompUnit;
1783 GetObjectFile()->GetModule()->ReportWarning(
1784 "0x%8.8x: compile unit %u failed to create a valid "
1785 "lldb_private::CompileUnit class.",
1795 uint32_t SymbolFileDWARF::ResolveSymbolContext(const FileSpec &file_spec,
1798 uint32_t resolve_scope,
1799 SymbolContextList &sc_list) {
1800 const uint32_t prev_size = sc_list.GetSize();
1801 if (resolve_scope & eSymbolContextCompUnit) {
1802 DWARFDebugInfo *debug_info = DebugInfo();
1805 DWARFCompileUnit *dwarf_cu = NULL;
1808 (dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx)) != NULL;
1810 CompileUnit *dc_cu = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
1811 const bool full_match = (bool)file_spec.GetDirectory();
1812 bool file_spec_matches_cu_file_spec =
1813 dc_cu != NULL && FileSpec::Equal(file_spec, *dc_cu, full_match);
1814 if (check_inlines || file_spec_matches_cu_file_spec) {
1815 SymbolContext sc(m_obj_file->GetModule());
1816 sc.comp_unit = GetCompUnitForDWARFCompUnit(dwarf_cu, cu_idx);
1818 uint32_t file_idx = UINT32_MAX;
1820 // If we are looking for inline functions only and we don't
1821 // find it in the support files, we are done.
1822 if (check_inlines) {
1823 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex(
1824 1, file_spec, true);
1825 if (file_idx == UINT32_MAX)
1830 LineTable *line_table = sc.comp_unit->GetLineTable();
1832 if (line_table != NULL && line != 0) {
1833 // We will have already looked up the file index if
1834 // we are searching for inline entries.
1836 file_idx = sc.comp_unit->GetSupportFiles().FindFileIndex(
1837 1, file_spec, true);
1839 if (file_idx != UINT32_MAX) {
1840 uint32_t found_line;
1841 uint32_t line_idx = line_table->FindLineEntryIndexByFileIndex(
1842 0, file_idx, line, false, &sc.line_entry);
1843 found_line = sc.line_entry.line;
1845 while (line_idx != UINT32_MAX) {
1849 (eSymbolContextFunction | eSymbolContextBlock)) {
1850 const lldb::addr_t file_vm_addr =
1851 sc.line_entry.range.GetBaseAddress().GetFileAddress();
1852 if (file_vm_addr != LLDB_INVALID_ADDRESS) {
1853 DWARFDIE function_die =
1854 dwarf_cu->LookupAddress(file_vm_addr);
1859 ->FindFunctionByUID(function_die.GetID())
1861 if (sc.function == NULL)
1863 ParseCompileUnitFunction(sc, function_die);
1866 (resolve_scope & eSymbolContextBlock))
1868 function_die.LookupDeepestBlock(file_vm_addr);
1871 if (sc.function != NULL) {
1872 Block &block = sc.function->GetBlock(true);
1875 sc.block = block.FindBlockByID(block_die.GetID());
1876 else if (function_die)
1878 block.FindBlockByID(function_die.GetID());
1884 line_idx = line_table->FindLineEntryIndexByFileIndex(
1885 line_idx + 1, file_idx, found_line, true,
1889 } else if (file_spec_matches_cu_file_spec && !check_inlines) {
1890 // only append the context if we aren't looking for inline call
1892 // by file and line and if the file spec matches that of the
1896 } else if (file_spec_matches_cu_file_spec && !check_inlines) {
1897 // only append the context if we aren't looking for inline call
1899 // by file and line and if the file spec matches that of the
1911 return sc_list.GetSize() - prev_size;
1914 void SymbolFileDWARF::Index() {
1919 LLVM_PRETTY_FUNCTION, "SymbolFileDWARF::Index (%s)",
1920 GetObjectFile()->GetFileSpec().GetFilename().AsCString("<Unknown>"));
1922 DWARFDebugInfo *debug_info = DebugInfo();
1924 const uint32_t num_compile_units = GetNumCompileUnits();
1925 if (num_compile_units == 0)
1928 std::vector<NameToDIE> function_basename_index(num_compile_units);
1929 std::vector<NameToDIE> function_fullname_index(num_compile_units);
1930 std::vector<NameToDIE> function_method_index(num_compile_units);
1931 std::vector<NameToDIE> function_selector_index(num_compile_units);
1932 std::vector<NameToDIE> objc_class_selectors_index(num_compile_units);
1933 std::vector<NameToDIE> global_index(num_compile_units);
1934 std::vector<NameToDIE> type_index(num_compile_units);
1935 std::vector<NameToDIE> namespace_index(num_compile_units);
1937 std::vector<bool> clear_cu_dies(num_compile_units, false);
1938 auto parser_fn = [this, debug_info, &function_basename_index,
1939 &function_fullname_index, &function_method_index,
1940 &function_selector_index, &objc_class_selectors_index,
1941 &global_index, &type_index,
1942 &namespace_index](uint32_t cu_idx) {
1943 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1946 function_basename_index[cu_idx], function_fullname_index[cu_idx],
1947 function_method_index[cu_idx], function_selector_index[cu_idx],
1948 objc_class_selectors_index[cu_idx], global_index[cu_idx],
1949 type_index[cu_idx], namespace_index[cu_idx]);
1954 auto extract_fn = [this, debug_info, num_compile_units](uint32_t cu_idx) {
1955 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
1957 // dwarf_cu->ExtractDIEsIfNeeded(false) will return zero if the
1958 // DIEs for a compile unit have already been parsed.
1959 return std::make_pair(cu_idx, dwarf_cu->ExtractDIEsIfNeeded(false) > 1);
1961 return std::make_pair(cu_idx, false);
1964 // Create a task runner that extracts dies for each DWARF compile unit in a
1966 TaskRunner<std::pair<uint32_t, bool>> task_runner_extract;
1967 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1968 task_runner_extract.AddTask(extract_fn, cu_idx);
1970 //----------------------------------------------------------------------
1971 // First figure out which compile units didn't have their DIEs already
1972 // parsed and remember this. If no DIEs were parsed prior to this index
1973 // function call, we are going to want to clear the CU dies after we
1974 // are done indexing to make sure we don't pull in all DWARF dies, but
1975 // we need to wait until all compile units have been indexed in case
1976 // a DIE in one compile unit refers to another and the indexes accesses
1978 //----------------------------------------------------------------------
1980 auto f = task_runner_extract.WaitForNextCompletedTask();
1985 std::tie(cu_idx, clear) = f.get();
1986 clear_cu_dies[cu_idx] = clear;
1989 // Now create a task runner that can index each DWARF compile unit in a
1991 // thread so we can index quickly.
1993 TaskRunner<uint32_t> task_runner;
1994 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx)
1995 task_runner.AddTask(parser_fn, cu_idx);
1998 std::future<uint32_t> f = task_runner.WaitForNextCompletedTask();
2001 uint32_t cu_idx = f.get();
2003 m_function_basename_index.Append(function_basename_index[cu_idx]);
2004 m_function_fullname_index.Append(function_fullname_index[cu_idx]);
2005 m_function_method_index.Append(function_method_index[cu_idx]);
2006 m_function_selector_index.Append(function_selector_index[cu_idx]);
2007 m_objc_class_selectors_index.Append(objc_class_selectors_index[cu_idx]);
2008 m_global_index.Append(global_index[cu_idx]);
2009 m_type_index.Append(type_index[cu_idx]);
2010 m_namespace_index.Append(namespace_index[cu_idx]);
2013 TaskPool::RunTasks([&]() { m_function_basename_index.Finalize(); },
2014 [&]() { m_function_fullname_index.Finalize(); },
2015 [&]() { m_function_method_index.Finalize(); },
2016 [&]() { m_function_selector_index.Finalize(); },
2017 [&]() { m_objc_class_selectors_index.Finalize(); },
2018 [&]() { m_global_index.Finalize(); },
2019 [&]() { m_type_index.Finalize(); },
2020 [&]() { m_namespace_index.Finalize(); });
2022 //----------------------------------------------------------------------
2023 // Keep memory down by clearing DIEs for any compile units if indexing
2024 // caused us to load the compile unit's DIEs.
2025 //----------------------------------------------------------------------
2026 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
2027 if (clear_cu_dies[cu_idx])
2028 debug_info->GetCompileUnitAtIndex(cu_idx)->ClearDIEs(true);
2031 #if defined(ENABLE_DEBUG_PRINTF)
2032 StreamFile s(stdout, false);
2033 s.Printf("DWARF index for '%s':",
2034 GetObjectFile()->GetFileSpec().GetPath().c_str());
2035 s.Printf("\nFunction basenames:\n");
2036 m_function_basename_index.Dump(&s);
2037 s.Printf("\nFunction fullnames:\n");
2038 m_function_fullname_index.Dump(&s);
2039 s.Printf("\nFunction methods:\n");
2040 m_function_method_index.Dump(&s);
2041 s.Printf("\nFunction selectors:\n");
2042 m_function_selector_index.Dump(&s);
2043 s.Printf("\nObjective C class selectors:\n");
2044 m_objc_class_selectors_index.Dump(&s);
2045 s.Printf("\nGlobals and statics:\n");
2046 m_global_index.Dump(&s);
2047 s.Printf("\nTypes:\n");
2048 m_type_index.Dump(&s);
2049 s.Printf("\nNamespaces:\n");
2050 m_namespace_index.Dump(&s);
2055 bool SymbolFileDWARF::DeclContextMatchesThisSymbolFile(
2056 const lldb_private::CompilerDeclContext *decl_ctx) {
2057 if (decl_ctx == nullptr || !decl_ctx->IsValid()) {
2058 // Invalid namespace decl which means we aren't matching only things
2059 // in this symbol file, so return true to indicate it matches this
2064 TypeSystem *decl_ctx_type_system = decl_ctx->GetTypeSystem();
2065 TypeSystem *type_system = GetTypeSystemForLanguage(
2066 decl_ctx_type_system->GetMinimumLanguage(nullptr));
2067 if (decl_ctx_type_system == type_system)
2068 return true; // The type systems match, return true
2070 // The namespace AST was valid, and it does not match...
2071 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2074 GetObjectFile()->GetModule()->LogMessage(
2075 log, "Valid namespace does not match symbol file");
2080 uint32_t SymbolFileDWARF::FindGlobalVariables(
2081 const ConstString &name, const CompilerDeclContext *parent_decl_ctx,
2082 bool append, uint32_t max_matches, VariableList &variables) {
2083 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2086 GetObjectFile()->GetModule()->LogMessage(
2087 log, "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", "
2088 "parent_decl_ctx=%p, append=%u, max_matches=%u, variables)",
2089 name.GetCString(), static_cast<const void *>(parent_decl_ctx), append,
2092 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2095 DWARFDebugInfo *info = DebugInfo();
2099 // If we aren't appending the results to this list, then clear the list
2103 // Remember how many variables are in the list before we search in case
2104 // we are appending the results to a variable list.
2105 const uint32_t original_size = variables.GetSize();
2107 DIEArray die_offsets;
2109 if (m_using_apple_tables) {
2110 if (m_apple_names_ap.get()) {
2111 const char *name_cstr = name.GetCString();
2112 llvm::StringRef basename;
2113 llvm::StringRef context;
2115 if (!CPlusPlusLanguage::ExtractContextAndIdentifier(name_cstr, context,
2117 basename = name_cstr;
2119 m_apple_names_ap->FindByName(basename.data(), die_offsets);
2122 // Index the DWARF if we haven't already
2126 m_global_index.Find(name, die_offsets);
2129 const size_t num_die_matches = die_offsets.size();
2130 if (num_die_matches) {
2132 sc.module_sp = m_obj_file->GetModule();
2133 assert(sc.module_sp);
2136 for (size_t i = 0; i < num_die_matches && !done; ++i) {
2137 const DIERef &die_ref = die_offsets[i];
2138 DWARFDIE die = GetDIE(die_ref);
2141 switch (die.Tag()) {
2143 case DW_TAG_subprogram:
2144 case DW_TAG_inlined_subroutine:
2145 case DW_TAG_try_block:
2146 case DW_TAG_catch_block:
2149 case DW_TAG_variable: {
2150 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
2152 if (parent_decl_ctx) {
2153 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2155 CompilerDeclContext actual_parent_decl_ctx =
2156 dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
2157 if (!actual_parent_decl_ctx ||
2158 actual_parent_decl_ctx != *parent_decl_ctx)
2163 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false,
2166 if (variables.GetSize() - original_size >= max_matches)
2171 if (m_using_apple_tables) {
2172 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
2173 "the DWARF debug information has been modified (.apple_names "
2174 "accelerator table had bad die 0x%8.8x for '%s')\n",
2175 die_ref.die_offset, name.GetCString());
2181 // Return the number of variable that were appended to the list
2182 const uint32_t num_matches = variables.GetSize() - original_size;
2183 if (log && num_matches > 0) {
2184 GetObjectFile()->GetModule()->LogMessage(
2185 log, "SymbolFileDWARF::FindGlobalVariables (name=\"%s\", "
2186 "parent_decl_ctx=%p, append=%u, max_matches=%u, variables) => %u",
2187 name.GetCString(), static_cast<const void *>(parent_decl_ctx), append,
2188 max_matches, num_matches);
2193 uint32_t SymbolFileDWARF::FindGlobalVariables(const RegularExpression ®ex,
2194 bool append, uint32_t max_matches,
2195 VariableList &variables) {
2196 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2199 GetObjectFile()->GetModule()->LogMessage(
2200 log, "SymbolFileDWARF::FindGlobalVariables (regex=\"%s\", append=%u, "
2201 "max_matches=%u, variables)",
2202 regex.GetText().str().c_str(), append, max_matches);
2205 DWARFDebugInfo *info = DebugInfo();
2209 // If we aren't appending the results to this list, then clear the list
2213 // Remember how many variables are in the list before we search in case
2214 // we are appending the results to a variable list.
2215 const uint32_t original_size = variables.GetSize();
2217 DIEArray die_offsets;
2219 if (m_using_apple_tables) {
2220 if (m_apple_names_ap.get()) {
2221 DWARFMappedHash::DIEInfoArray hash_data_array;
2222 if (m_apple_names_ap->AppendAllDIEsThatMatchingRegex(regex,
2224 DWARFMappedHash::ExtractDIEArray(hash_data_array, die_offsets);
2227 // Index the DWARF if we haven't already
2231 m_global_index.Find(regex, die_offsets);
2235 sc.module_sp = m_obj_file->GetModule();
2236 assert(sc.module_sp);
2238 const size_t num_matches = die_offsets.size();
2240 for (size_t i = 0; i < num_matches; ++i) {
2241 const DIERef &die_ref = die_offsets[i];
2242 DWARFDIE die = GetDIE(die_ref);
2245 sc.comp_unit = GetCompUnitForDWARFCompUnit(die.GetCU(), UINT32_MAX);
2247 ParseVariables(sc, die, LLDB_INVALID_ADDRESS, false, false, &variables);
2249 if (variables.GetSize() - original_size >= max_matches)
2252 if (m_using_apple_tables) {
2253 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
2254 "the DWARF debug information has been modified (.apple_names "
2255 "accelerator table had bad die 0x%8.8x for regex '%s')\n",
2256 die_ref.die_offset, regex.GetText().str().c_str());
2262 // Return the number of variable that were appended to the list
2263 return variables.GetSize() - original_size;
2266 bool SymbolFileDWARF::ResolveFunction(const DIERef &die_ref,
2267 bool include_inlines,
2268 SymbolContextList &sc_list) {
2269 DWARFDIE die = DebugInfo()->GetDIE(die_ref);
2270 return ResolveFunction(die, include_inlines, sc_list);
2273 bool SymbolFileDWARF::ResolveFunction(const DWARFDIE &orig_die,
2274 bool include_inlines,
2275 SymbolContextList &sc_list) {
2281 // If we were passed a die that is not a function, just return false...
2282 if (!(orig_die.Tag() == DW_TAG_subprogram ||
2283 (include_inlines && orig_die.Tag() == DW_TAG_inlined_subroutine)))
2286 DWARFDIE die = orig_die;
2287 DWARFDIE inlined_die;
2288 if (die.Tag() == DW_TAG_inlined_subroutine) {
2292 die = die.GetParent();
2295 if (die.Tag() == DW_TAG_subprogram)
2301 assert(die && die.Tag() == DW_TAG_subprogram);
2302 if (GetFunction(die, sc)) {
2304 // Parse all blocks if needed
2306 Block &function_block = sc.function->GetBlock(true);
2307 sc.block = function_block.FindBlockByID(inlined_die.GetID());
2308 if (sc.block == NULL)
2309 sc.block = function_block.FindBlockByID(inlined_die.GetOffset());
2310 if (sc.block == NULL || sc.block->GetStartAddress(addr) == false)
2314 addr = sc.function->GetAddressRange().GetBaseAddress();
2317 if (addr.IsValid()) {
2326 void SymbolFileDWARF::FindFunctions(const ConstString &name,
2327 const NameToDIE &name_to_die,
2328 bool include_inlines,
2329 SymbolContextList &sc_list) {
2330 DIEArray die_offsets;
2331 if (name_to_die.Find(name, die_offsets)) {
2332 ParseFunctions(die_offsets, include_inlines, sc_list);
2336 void SymbolFileDWARF::FindFunctions(const RegularExpression ®ex,
2337 const NameToDIE &name_to_die,
2338 bool include_inlines,
2339 SymbolContextList &sc_list) {
2340 DIEArray die_offsets;
2341 if (name_to_die.Find(regex, die_offsets)) {
2342 ParseFunctions(die_offsets, include_inlines, sc_list);
2346 void SymbolFileDWARF::FindFunctions(
2347 const RegularExpression ®ex,
2348 const DWARFMappedHash::MemoryTable &memory_table, bool include_inlines,
2349 SymbolContextList &sc_list) {
2350 DIEArray die_offsets;
2351 DWARFMappedHash::DIEInfoArray hash_data_array;
2352 if (memory_table.AppendAllDIEsThatMatchingRegex(regex, hash_data_array)) {
2353 DWARFMappedHash::ExtractDIEArray(hash_data_array, die_offsets);
2354 ParseFunctions(die_offsets, include_inlines, sc_list);
2358 void SymbolFileDWARF::ParseFunctions(const DIEArray &die_offsets,
2359 bool include_inlines,
2360 SymbolContextList &sc_list) {
2361 const size_t num_matches = die_offsets.size();
2363 for (size_t i = 0; i < num_matches; ++i)
2364 ResolveFunction(die_offsets[i], include_inlines, sc_list);
2368 bool SymbolFileDWARF::DIEInDeclContext(const CompilerDeclContext *decl_ctx,
2369 const DWARFDIE &die) {
2370 // If we have no parent decl context to match this DIE matches, and if the
2372 // decl context isn't valid, we aren't trying to look for any particular decl
2373 // context so any die matches.
2374 if (decl_ctx == nullptr || !decl_ctx->IsValid())
2378 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2380 CompilerDeclContext actual_decl_ctx =
2381 dwarf_ast->GetDeclContextContainingUIDFromDWARF(die);
2382 if (actual_decl_ctx)
2383 return actual_decl_ctx == *decl_ctx;
2390 SymbolFileDWARF::FindFunctions(const ConstString &name,
2391 const CompilerDeclContext *parent_decl_ctx,
2392 uint32_t name_type_mask, bool include_inlines,
2393 bool append, SymbolContextList &sc_list) {
2394 Timer scoped_timer(LLVM_PRETTY_FUNCTION,
2395 "SymbolFileDWARF::FindFunctions (name = '%s')",
2398 // eFunctionNameTypeAuto should be pre-resolved by a call to
2399 // Module::LookupInfo::LookupInfo()
2400 assert((name_type_mask & eFunctionNameTypeAuto) == 0);
2402 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2405 GetObjectFile()->GetModule()->LogMessage(
2406 log, "SymbolFileDWARF::FindFunctions (name=\"%s\", "
2407 "name_type_mask=0x%x, append=%u, sc_list)",
2408 name.GetCString(), name_type_mask, append);
2411 // If we aren't appending the results to this list, then clear the list
2415 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2418 // If name is empty then we won't find anything.
2422 // Remember how many sc_list are in the list before we search in case
2423 // we are appending the results to a variable list.
2425 const char *name_cstr = name.GetCString();
2427 const uint32_t original_size = sc_list.GetSize();
2429 DWARFDebugInfo *info = DebugInfo();
2433 std::set<const DWARFDebugInfoEntry *> resolved_dies;
2434 if (m_using_apple_tables) {
2435 if (m_apple_names_ap.get()) {
2437 DIEArray die_offsets;
2439 uint32_t num_matches = 0;
2441 if (name_type_mask & eFunctionNameTypeFull) {
2442 // If they asked for the full name, match what they typed. At some
2444 // want to canonicalize this (strip double spaces, etc. For now, we
2446 // dies that we find by exact match.
2447 num_matches = m_apple_names_ap->FindByName(name_cstr, die_offsets);
2448 for (uint32_t i = 0; i < num_matches; i++) {
2449 const DIERef &die_ref = die_offsets[i];
2450 DWARFDIE die = info->GetDIE(die_ref);
2452 if (!DIEInDeclContext(parent_decl_ctx, die))
2453 continue; // The containing decl contexts don't match
2455 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) {
2456 if (ResolveFunction(die, include_inlines, sc_list))
2457 resolved_dies.insert(die.GetDIE());
2460 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
2461 "the DWARF debug information has been modified (.apple_names "
2462 "accelerator table had bad die 0x%8.8x for '%s')",
2463 die_ref.die_offset, name_cstr);
2468 if (name_type_mask & eFunctionNameTypeSelector) {
2469 if (parent_decl_ctx && parent_decl_ctx->IsValid())
2470 return 0; // no selectors in namespaces
2472 num_matches = m_apple_names_ap->FindByName(name_cstr, die_offsets);
2473 // Now make sure these are actually ObjC methods. In this case we can
2474 // simply look up the name,
2475 // and if it is an ObjC method name, we're good.
2477 for (uint32_t i = 0; i < num_matches; i++) {
2478 const DIERef &die_ref = die_offsets[i];
2479 DWARFDIE die = info->GetDIE(die_ref);
2481 const char *die_name = die.GetName();
2482 if (ObjCLanguage::IsPossibleObjCMethodName(die_name)) {
2483 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) {
2484 if (ResolveFunction(die, include_inlines, sc_list))
2485 resolved_dies.insert(die.GetDIE());
2489 GetObjectFile()->GetModule()->ReportError(
2490 "the DWARF debug information has been modified (.apple_names "
2491 "accelerator table had bad die 0x%8.8x for '%s')",
2492 die_ref.die_offset, name_cstr);
2495 die_offsets.clear();
2498 if (((name_type_mask & eFunctionNameTypeMethod) && !parent_decl_ctx) ||
2499 name_type_mask & eFunctionNameTypeBase) {
2500 // The apple_names table stores just the "base name" of C++ methods in
2501 // the table. So we have to
2502 // extract the base name, look that up, and if there is any other
2503 // information in the name we were
2504 // passed in we have to post-filter based on that.
2506 // FIXME: Arrange the logic above so that we don't calculate the base
2508 num_matches = m_apple_names_ap->FindByName(name_cstr, die_offsets);
2510 for (uint32_t i = 0; i < num_matches; i++) {
2511 const DIERef &die_ref = die_offsets[i];
2512 DWARFDIE die = info->GetDIE(die_ref);
2514 if (!DIEInDeclContext(parent_decl_ctx, die))
2515 continue; // The containing decl contexts don't match
2517 // If we get to here, the die is good, and we should add it:
2518 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end() &&
2519 ResolveFunction(die, include_inlines, sc_list)) {
2520 bool keep_die = true;
2521 if ((name_type_mask &
2522 (eFunctionNameTypeBase | eFunctionNameTypeMethod)) !=
2523 (eFunctionNameTypeBase | eFunctionNameTypeMethod)) {
2524 // We are looking for either basenames or methods, so we need to
2525 // trim out the ones we won't want by looking at the type
2527 if (sc_list.GetLastContext(sc)) {
2529 // We have an inlined function
2530 } else if (sc.function) {
2531 Type *type = sc.function->GetType();
2534 CompilerDeclContext decl_ctx =
2535 GetDeclContextContainingUID(type->GetID());
2536 if (decl_ctx.IsStructUnionOrClass()) {
2537 if (name_type_mask & eFunctionNameTypeBase) {
2538 sc_list.RemoveContextAtIndex(sc_list.GetSize() - 1);
2542 if (name_type_mask & eFunctionNameTypeMethod) {
2543 sc_list.RemoveContextAtIndex(sc_list.GetSize() - 1);
2548 GetObjectFile()->GetModule()->ReportWarning(
2549 "function at die offset 0x%8.8x had no function type",
2550 die_ref.die_offset);
2556 resolved_dies.insert(die.GetDIE());
2559 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
2560 "the DWARF debug information has been modified (.apple_names "
2561 "accelerator table had bad die 0x%8.8x for '%s')",
2562 die_ref.die_offset, name_cstr);
2565 die_offsets.clear();
2570 // Index the DWARF if we haven't already
2574 if (name_type_mask & eFunctionNameTypeFull) {
2575 FindFunctions(name, m_function_fullname_index, include_inlines, sc_list);
2577 // FIXME Temporary workaround for global/anonymous namespace
2578 // functions debugging FreeBSD and Linux binaries.
2579 // If we didn't find any functions in the global namespace try
2580 // looking in the basename index but ignore any returned
2581 // functions that have a namespace but keep functions which
2582 // have an anonymous namespace
2583 // TODO: The arch in the object file isn't correct for MSVC
2584 // binaries on windows, we should find a way to make it
2585 // correct and handle those symbols as well.
2586 if (sc_list.GetSize() == original_size) {
2588 if (!parent_decl_ctx && GetObjectFile()->GetArchitecture(arch) &&
2589 arch.GetTriple().isOSBinFormatELF()) {
2590 SymbolContextList temp_sc_list;
2591 FindFunctions(name, m_function_basename_index, include_inlines,
2594 for (uint32_t i = 0; i < temp_sc_list.GetSize(); i++) {
2595 if (temp_sc_list.GetContextAtIndex(i, sc)) {
2596 ConstString mangled_name =
2597 sc.GetFunctionName(Mangled::ePreferMangled);
2598 ConstString demangled_name =
2599 sc.GetFunctionName(Mangled::ePreferDemangled);
2600 // Mangled names on Linux and FreeBSD are of the form:
2601 // _ZN18function_namespace13function_nameEv.
2602 if (strncmp(mangled_name.GetCString(), "_ZN", 3) ||
2603 !strncmp(demangled_name.GetCString(), "(anonymous namespace)",
2612 DIEArray die_offsets;
2613 if (name_type_mask & eFunctionNameTypeBase) {
2614 uint32_t num_base = m_function_basename_index.Find(name, die_offsets);
2615 for (uint32_t i = 0; i < num_base; i++) {
2616 DWARFDIE die = info->GetDIE(die_offsets[i]);
2618 if (!DIEInDeclContext(parent_decl_ctx, die))
2619 continue; // The containing decl contexts don't match
2621 // If we get to here, the die is good, and we should add it:
2622 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) {
2623 if (ResolveFunction(die, include_inlines, sc_list))
2624 resolved_dies.insert(die.GetDIE());
2628 die_offsets.clear();
2631 if (name_type_mask & eFunctionNameTypeMethod) {
2632 if (parent_decl_ctx && parent_decl_ctx->IsValid())
2633 return 0; // no methods in namespaces
2635 uint32_t num_base = m_function_method_index.Find(name, die_offsets);
2637 for (uint32_t i = 0; i < num_base; i++) {
2638 DWARFDIE die = info->GetDIE(die_offsets[i]);
2640 // If we get to here, the die is good, and we should add it:
2641 if (resolved_dies.find(die.GetDIE()) == resolved_dies.end()) {
2642 if (ResolveFunction(die, include_inlines, sc_list))
2643 resolved_dies.insert(die.GetDIE());
2648 die_offsets.clear();
2651 if ((name_type_mask & eFunctionNameTypeSelector) &&
2652 (!parent_decl_ctx || !parent_decl_ctx->IsValid())) {
2653 FindFunctions(name, m_function_selector_index, include_inlines, sc_list);
2657 // Return the number of variable that were appended to the list
2658 const uint32_t num_matches = sc_list.GetSize() - original_size;
2660 if (log && num_matches > 0) {
2661 GetObjectFile()->GetModule()->LogMessage(
2662 log, "SymbolFileDWARF::FindFunctions (name=\"%s\", "
2663 "name_type_mask=0x%x, include_inlines=%d, append=%u, sc_list) => "
2665 name.GetCString(), name_type_mask, include_inlines, append,
2671 uint32_t SymbolFileDWARF::FindFunctions(const RegularExpression ®ex,
2672 bool include_inlines, bool append,
2673 SymbolContextList &sc_list) {
2674 Timer scoped_timer(LLVM_PRETTY_FUNCTION,
2675 "SymbolFileDWARF::FindFunctions (regex = '%s')",
2676 regex.GetText().str().c_str());
2678 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2681 GetObjectFile()->GetModule()->LogMessage(
2683 "SymbolFileDWARF::FindFunctions (regex=\"%s\", append=%u, sc_list)",
2684 regex.GetText().str().c_str(), append);
2687 // If we aren't appending the results to this list, then clear the list
2691 // Remember how many sc_list are in the list before we search in case
2692 // we are appending the results to a variable list.
2693 uint32_t original_size = sc_list.GetSize();
2695 if (m_using_apple_tables) {
2696 if (m_apple_names_ap.get())
2697 FindFunctions(regex, *m_apple_names_ap, include_inlines, sc_list);
2699 // Index the DWARF if we haven't already
2703 FindFunctions(regex, m_function_basename_index, include_inlines, sc_list);
2705 FindFunctions(regex, m_function_fullname_index, include_inlines, sc_list);
2708 // Return the number of variable that were appended to the list
2709 return sc_list.GetSize() - original_size;
2712 void SymbolFileDWARF::GetMangledNamesForFunction(
2713 const std::string &scope_qualified_name,
2714 std::vector<ConstString> &mangled_names) {
2715 DWARFDebugInfo *info = DebugInfo();
2716 uint32_t num_comp_units = 0;
2718 num_comp_units = info->GetNumCompileUnits();
2720 for (uint32_t i = 0; i < num_comp_units; i++) {
2721 DWARFCompileUnit *cu = info->GetCompileUnitAtIndex(i);
2725 SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile();
2727 dwo->GetMangledNamesForFunction(scope_qualified_name, mangled_names);
2730 NameToOffsetMap::iterator iter =
2731 m_function_scope_qualified_name_map.find(scope_qualified_name);
2732 if (iter == m_function_scope_qualified_name_map.end())
2735 DIERefSetSP set_sp = (*iter).second;
2736 std::set<DIERef>::iterator set_iter;
2737 for (set_iter = set_sp->begin(); set_iter != set_sp->end(); set_iter++) {
2738 DWARFDIE die = DebugInfo()->GetDIE(*set_iter);
2739 mangled_names.push_back(ConstString(die.GetMangledName()));
2743 uint32_t SymbolFileDWARF::FindTypes(
2744 const SymbolContext &sc, const ConstString &name,
2745 const CompilerDeclContext *parent_decl_ctx, bool append,
2746 uint32_t max_matches,
2747 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
2749 // If we aren't appending the results to this list, then clear the list
2753 // Make sure we haven't already searched this SymbolFile before...
2754 if (searched_symbol_files.count(this))
2757 searched_symbol_files.insert(this);
2759 DWARFDebugInfo *info = DebugInfo();
2763 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2766 if (parent_decl_ctx)
2767 GetObjectFile()->GetModule()->LogMessage(
2768 log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = "
2769 "%p (\"%s\"), append=%u, max_matches=%u, type_list)",
2770 name.GetCString(), static_cast<const void *>(parent_decl_ctx),
2771 parent_decl_ctx->GetName().AsCString("<NULL>"), append, max_matches);
2773 GetObjectFile()->GetModule()->LogMessage(
2774 log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx = "
2775 "NULL, append=%u, max_matches=%u, type_list)",
2776 name.GetCString(), append, max_matches);
2779 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2782 DIEArray die_offsets;
2784 if (m_using_apple_tables) {
2785 if (m_apple_types_ap.get()) {
2786 const char *name_cstr = name.GetCString();
2787 m_apple_types_ap->FindByName(name_cstr, die_offsets);
2793 m_type_index.Find(name, die_offsets);
2796 const size_t num_die_matches = die_offsets.size();
2798 if (num_die_matches) {
2799 const uint32_t initial_types_size = types.GetSize();
2800 for (size_t i = 0; i < num_die_matches; ++i) {
2801 const DIERef &die_ref = die_offsets[i];
2802 DWARFDIE die = GetDIE(die_ref);
2805 if (!DIEInDeclContext(parent_decl_ctx, die))
2806 continue; // The containing decl contexts don't match
2808 Type *matching_type = ResolveType(die, true, true);
2809 if (matching_type) {
2810 // We found a type pointer, now find the shared pointer form our type
2812 types.InsertUnique(matching_type->shared_from_this());
2813 if (types.GetSize() >= max_matches)
2817 if (m_using_apple_tables) {
2818 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
2819 "the DWARF debug information has been modified (.apple_types "
2820 "accelerator table had bad die 0x%8.8x for '%s')\n",
2821 die_ref.die_offset, name.GetCString());
2825 const uint32_t num_matches = types.GetSize() - initial_types_size;
2826 if (log && num_matches) {
2827 if (parent_decl_ctx) {
2828 GetObjectFile()->GetModule()->LogMessage(
2829 log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
2830 "= %p (\"%s\"), append=%u, max_matches=%u, type_list) => %u",
2831 name.GetCString(), static_cast<const void *>(parent_decl_ctx),
2832 parent_decl_ctx->GetName().AsCString("<NULL>"), append, max_matches,
2835 GetObjectFile()->GetModule()->LogMessage(
2836 log, "SymbolFileDWARF::FindTypes (sc, name=\"%s\", parent_decl_ctx "
2837 "= NULL, append=%u, max_matches=%u, type_list) => %u",
2838 name.GetCString(), append, max_matches, num_matches);
2843 UpdateExternalModuleListIfNeeded();
2845 for (const auto &pair : m_external_type_modules) {
2846 ModuleSP external_module_sp = pair.second;
2847 if (external_module_sp) {
2848 SymbolVendor *sym_vendor = external_module_sp->GetSymbolVendor();
2850 const uint32_t num_external_matches =
2851 sym_vendor->FindTypes(sc, name, parent_decl_ctx, append,
2852 max_matches, searched_symbol_files, types);
2853 if (num_external_matches)
2854 return num_external_matches;
2863 size_t SymbolFileDWARF::FindTypes(const std::vector<CompilerContext> &context,
2864 bool append, TypeMap &types) {
2868 if (context.empty())
2871 DIEArray die_offsets;
2873 ConstString name = context.back().name;
2878 if (m_using_apple_tables) {
2879 if (m_apple_types_ap.get()) {
2880 const char *name_cstr = name.GetCString();
2881 m_apple_types_ap->FindByName(name_cstr, die_offsets);
2887 m_type_index.Find(name, die_offsets);
2890 const size_t num_die_matches = die_offsets.size();
2892 if (num_die_matches) {
2893 size_t num_matches = 0;
2894 for (size_t i = 0; i < num_die_matches; ++i) {
2895 const DIERef &die_ref = die_offsets[i];
2896 DWARFDIE die = GetDIE(die_ref);
2899 std::vector<CompilerContext> die_context;
2900 die.GetDWOContext(die_context);
2901 if (die_context != context)
2904 Type *matching_type = ResolveType(die, true, true);
2905 if (matching_type) {
2906 // We found a type pointer, now find the shared pointer form our type
2908 types.InsertUnique(matching_type->shared_from_this());
2912 if (m_using_apple_tables) {
2913 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
2914 "the DWARF debug information has been modified (.apple_types "
2915 "accelerator table had bad die 0x%8.8x for '%s')\n",
2916 die_ref.die_offset, name.GetCString());
2926 SymbolFileDWARF::FindNamespace(const SymbolContext &sc, const ConstString &name,
2927 const CompilerDeclContext *parent_decl_ctx) {
2928 Log *log(LogChannelDWARF::GetLogIfAll(DWARF_LOG_LOOKUPS));
2931 GetObjectFile()->GetModule()->LogMessage(
2932 log, "SymbolFileDWARF::FindNamespace (sc, name=\"%s\")",
2936 CompilerDeclContext namespace_decl_ctx;
2938 if (!DeclContextMatchesThisSymbolFile(parent_decl_ctx))
2939 return namespace_decl_ctx;
2941 DWARFDebugInfo *info = DebugInfo();
2943 DIEArray die_offsets;
2945 // Index if we already haven't to make sure the compile units
2946 // get indexed and make their global DIE index list
2947 if (m_using_apple_tables) {
2948 if (m_apple_namespaces_ap.get()) {
2949 const char *name_cstr = name.GetCString();
2950 m_apple_namespaces_ap->FindByName(name_cstr, die_offsets);
2956 m_namespace_index.Find(name, die_offsets);
2959 const size_t num_matches = die_offsets.size();
2961 for (size_t i = 0; i < num_matches; ++i) {
2962 const DIERef &die_ref = die_offsets[i];
2963 DWARFDIE die = GetDIE(die_ref);
2966 if (!DIEInDeclContext(parent_decl_ctx, die))
2967 continue; // The containing decl contexts don't match
2969 DWARFASTParser *dwarf_ast = die.GetDWARFParser();
2971 namespace_decl_ctx = dwarf_ast->GetDeclContextForUIDFromDWARF(die);
2972 if (namespace_decl_ctx)
2976 if (m_using_apple_tables) {
2977 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
2978 "the DWARF debug information has been modified "
2979 "(.apple_namespaces accelerator table had bad die 0x%8.8x for "
2981 die_ref.die_offset, name.GetCString());
2987 if (log && namespace_decl_ctx) {
2988 GetObjectFile()->GetModule()->LogMessage(
2989 log, "SymbolFileDWARF::FindNamespace (sc, name=\"%s\") => "
2990 "CompilerDeclContext(%p/%p) \"%s\"",
2992 static_cast<const void *>(namespace_decl_ctx.GetTypeSystem()),
2993 static_cast<const void *>(namespace_decl_ctx.GetOpaqueDeclContext()),
2994 namespace_decl_ctx.GetName().AsCString("<NULL>"));
2997 return namespace_decl_ctx;
3000 TypeSP SymbolFileDWARF::GetTypeForDIE(const DWARFDIE &die,
3001 bool resolve_function_context) {
3004 Type *type_ptr = GetDIEToType().lookup(die.GetDIE());
3005 if (type_ptr == NULL) {
3006 CompileUnit *lldb_cu = GetCompUnitForDWARFCompUnit(die.GetCU());
3008 SymbolContext sc(lldb_cu);
3009 const DWARFDebugInfoEntry *parent_die = die.GetParent().GetDIE();
3010 while (parent_die != nullptr) {
3011 if (parent_die->Tag() == DW_TAG_subprogram)
3013 parent_die = parent_die->GetParent();
3015 SymbolContext sc_backup = sc;
3016 if (resolve_function_context && parent_die != nullptr &&
3017 !GetFunction(DWARFDIE(die.GetCU(), parent_die), sc))
3020 type_sp = ParseType(sc, die, NULL);
3021 } else if (type_ptr != DIE_IS_BEING_PARSED) {
3022 // Grab the existing type from the master types lists
3023 type_sp = type_ptr->shared_from_this();
3030 SymbolFileDWARF::GetDeclContextDIEContainingDIE(const DWARFDIE &orig_die) {
3032 DWARFDIE die = orig_die;
3035 // If this is the original DIE that we are searching for a declaration
3036 // for, then don't look in the cache as we don't want our own decl
3037 // context to be our decl context...
3038 if (orig_die != die) {
3039 switch (die.Tag()) {
3040 case DW_TAG_compile_unit:
3041 case DW_TAG_namespace:
3042 case DW_TAG_structure_type:
3043 case DW_TAG_union_type:
3044 case DW_TAG_class_type:
3045 case DW_TAG_lexical_block:
3046 case DW_TAG_subprogram:
3054 DWARFDIE spec_die = die.GetReferencedDIE(DW_AT_specification);
3056 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(spec_die);
3058 return decl_ctx_die;
3061 DWARFDIE abs_die = die.GetReferencedDIE(DW_AT_abstract_origin);
3063 DWARFDIE decl_ctx_die = GetDeclContextDIEContainingDIE(abs_die);
3065 return decl_ctx_die;
3068 die = die.GetParent();
3075 SymbolFileDWARF::GetObjCClassSymbol(const ConstString &objc_class_name) {
3076 Symbol *objc_class_symbol = NULL;
3078 Symtab *symtab = m_obj_file->GetSymtab();
3080 objc_class_symbol = symtab->FindFirstSymbolWithNameAndType(
3081 objc_class_name, eSymbolTypeObjCClass, Symtab::eDebugNo,
3082 Symtab::eVisibilityAny);
3085 return objc_class_symbol;
3088 // Some compilers don't emit the DW_AT_APPLE_objc_complete_type attribute. If
3090 // then we can end up looking through all class types for a complete type and
3092 // the full definition. We need to know if this attribute is supported, so we
3094 // this here and cache th result. We also need to worry about the debug map
3096 // if we are doing darwin DWARF in .o file debugging.
3097 bool SymbolFileDWARF::Supports_DW_AT_APPLE_objc_complete_type(
3098 DWARFCompileUnit *cu) {
3099 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolCalculate) {
3100 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolNo;
3101 if (cu && cu->Supports_DW_AT_APPLE_objc_complete_type())
3102 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3104 DWARFDebugInfo *debug_info = DebugInfo();
3105 const uint32_t num_compile_units = GetNumCompileUnits();
3106 for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
3107 DWARFCompileUnit *dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);
3108 if (dwarf_cu != cu &&
3109 dwarf_cu->Supports_DW_AT_APPLE_objc_complete_type()) {
3110 m_supports_DW_AT_APPLE_objc_complete_type = eLazyBoolYes;
3115 if (m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolNo &&
3116 GetDebugMapSymfile())
3117 return m_debug_map_symfile->Supports_DW_AT_APPLE_objc_complete_type(this);
3119 return m_supports_DW_AT_APPLE_objc_complete_type == eLazyBoolYes;
3122 // This function can be used when a DIE is found that is a forward declaration
3123 // DIE and we want to try and find a type that has the complete definition.
3124 TypeSP SymbolFileDWARF::FindCompleteObjCDefinitionTypeForDIE(
3125 const DWARFDIE &die, const ConstString &type_name,
3126 bool must_be_implementation) {
3130 if (!type_name || (must_be_implementation && !GetObjCClassSymbol(type_name)))
3133 DIEArray die_offsets;
3135 if (m_using_apple_tables) {
3136 if (m_apple_types_ap.get()) {
3137 const char *name_cstr = type_name.GetCString();
3138 m_apple_types_ap->FindCompleteObjCClassByName(name_cstr, die_offsets,
3139 must_be_implementation);
3145 m_type_index.Find(type_name, die_offsets);
3148 const size_t num_matches = die_offsets.size();
3151 for (size_t i = 0; i < num_matches; ++i) {
3152 const DIERef &die_ref = die_offsets[i];
3153 DWARFDIE type_die = GetDIE(die_ref);
3156 bool try_resolving_type = false;
3158 // Don't try and resolve the DIE we are looking for with the DIE itself!
3159 if (type_die != die) {
3160 switch (type_die.Tag()) {
3161 case DW_TAG_class_type:
3162 case DW_TAG_structure_type:
3163 try_resolving_type = true;
3170 if (try_resolving_type) {
3171 if (must_be_implementation &&
3172 type_die.Supports_DW_AT_APPLE_objc_complete_type())
3173 try_resolving_type = type_die.GetAttributeValueAsUnsigned(
3174 DW_AT_APPLE_objc_complete_type, 0);
3176 if (try_resolving_type) {
3177 Type *resolved_type = ResolveType(type_die, false, true);
3178 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) {
3179 DEBUG_PRINTF("resolved 0x%8.8" PRIx64 " from %s to 0x%8.8" PRIx64
3180 " (cu 0x%8.8" PRIx64 ")\n",
3182 m_obj_file->GetFileSpec().GetFilename().AsCString(
3184 type_die.GetID(), type_cu->GetID());
3187 GetDIEToType()[die.GetDIE()] = resolved_type;
3188 type_sp = resolved_type->shared_from_this();
3194 if (m_using_apple_tables) {
3195 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
3196 "the DWARF debug information has been modified (.apple_types "
3197 "accelerator table had bad die 0x%8.8x for '%s')\n",
3198 die_ref.die_offset, type_name.GetCString());
3206 //----------------------------------------------------------------------
3207 // This function helps to ensure that the declaration contexts match for
3208 // two different DIEs. Often times debug information will refer to a
3209 // forward declaration of a type (the equivalent of "struct my_struct;".
3210 // There will often be a declaration of that type elsewhere that has the
3211 // full definition. When we go looking for the full type "my_struct", we
3212 // will find one or more matches in the accelerator tables and we will
3213 // then need to make sure the type was in the same declaration context
3214 // as the original DIE. This function can efficiently compare two DIEs
3215 // and will return true when the declaration context matches, and false
3217 //----------------------------------------------------------------------
3218 bool SymbolFileDWARF::DIEDeclContextsMatch(const DWARFDIE &die1,
3219 const DWARFDIE &die2) {
3223 DWARFDIECollection decl_ctx_1;
3224 DWARFDIECollection decl_ctx_2;
3225 // The declaration DIE stack is a stack of the declaration context
3226 // DIEs all the way back to the compile unit. If a type "T" is
3227 // declared inside a class "B", and class "B" is declared inside
3228 // a class "A" and class "A" is in a namespace "lldb", and the
3229 // namespace is in a compile unit, there will be a stack of DIEs:
3231 // [0] DW_TAG_class_type for "B"
3232 // [1] DW_TAG_class_type for "A"
3233 // [2] DW_TAG_namespace for "lldb"
3234 // [3] DW_TAG_compile_unit for the source file.
3236 // We grab both contexts and make sure that everything matches
3237 // all the way back to the compiler unit.
3239 // First lets grab the decl contexts for both DIEs
3240 die1.GetDeclContextDIEs(decl_ctx_1);
3241 die2.GetDeclContextDIEs(decl_ctx_2);
3242 // Make sure the context arrays have the same size, otherwise
3244 const size_t count1 = decl_ctx_1.Size();
3245 const size_t count2 = decl_ctx_2.Size();
3246 if (count1 != count2)
3249 // Make sure the DW_TAG values match all the way back up the
3250 // compile unit. If they don't, then we are done.
3251 DWARFDIE decl_ctx_die1;
3252 DWARFDIE decl_ctx_die2;
3254 for (i = 0; i < count1; i++) {
3255 decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex(i);
3256 decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex(i);
3257 if (decl_ctx_die1.Tag() != decl_ctx_die2.Tag())
3260 #if defined LLDB_CONFIGURATION_DEBUG
3262 // Make sure the top item in the decl context die array is always
3263 // DW_TAG_compile_unit. If it isn't then something went wrong in
3264 // the DWARFDIE::GetDeclContextDIEs() function...
3265 assert(decl_ctx_1.GetDIEAtIndex(count1 - 1).Tag() == DW_TAG_compile_unit);
3268 // Always skip the compile unit when comparing by only iterating up to
3269 // "count - 1". Here we compare the names as we go.
3270 for (i = 0; i < count1 - 1; i++) {
3271 decl_ctx_die1 = decl_ctx_1.GetDIEAtIndex(i);
3272 decl_ctx_die2 = decl_ctx_2.GetDIEAtIndex(i);
3273 const char *name1 = decl_ctx_die1.GetName();
3274 const char *name2 = decl_ctx_die2.GetName();
3275 // If the string was from a DW_FORM_strp, then the pointer will often
3280 // Name pointers are not equal, so only compare the strings
3281 // if both are not NULL.
3282 if (name1 && name2) {
3283 // If the strings don't compare, we are done...
3284 if (strcmp(name1, name2) != 0)
3287 // One name was NULL while the other wasn't
3291 // We made it through all of the checks and the declaration contexts
3296 TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(
3297 const DWARFDeclContext &dwarf_decl_ctx) {
3300 const uint32_t dwarf_decl_ctx_count = dwarf_decl_ctx.GetSize();
3301 if (dwarf_decl_ctx_count > 0) {
3302 const ConstString type_name(dwarf_decl_ctx[0].name);
3303 const dw_tag_t tag = dwarf_decl_ctx[0].tag;
3306 Log *log(LogChannelDWARF::GetLogIfAny(DWARF_LOG_TYPE_COMPLETION |
3307 DWARF_LOG_LOOKUPS));
3309 GetObjectFile()->GetModule()->LogMessage(
3310 log, "SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(tag=%"
3311 "s, qualified-name='%s')",
3312 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3313 dwarf_decl_ctx.GetQualifiedName());
3316 DIEArray die_offsets;
3318 if (m_using_apple_tables) {
3319 if (m_apple_types_ap.get()) {
3320 const bool has_tag =
3321 m_apple_types_ap->GetHeader().header_data.ContainsAtom(
3322 DWARFMappedHash::eAtomTypeTag);
3323 const bool has_qualified_name_hash =
3324 m_apple_types_ap->GetHeader().header_data.ContainsAtom(
3325 DWARFMappedHash::eAtomTypeQualNameHash);
3326 if (has_tag && has_qualified_name_hash) {
3327 const char *qualified_name = dwarf_decl_ctx.GetQualifiedName();
3328 const uint32_t qualified_name_hash =
3329 MappedHash::HashStringUsingDJB(qualified_name);
3331 GetObjectFile()->GetModule()->LogMessage(
3332 log, "FindByNameAndTagAndQualifiedNameHash()");
3333 m_apple_types_ap->FindByNameAndTagAndQualifiedNameHash(
3334 type_name.GetCString(), tag, qualified_name_hash, die_offsets);
3335 } else if (has_tag) {
3337 GetObjectFile()->GetModule()->LogMessage(log,
3338 "FindByNameAndTag()");
3339 m_apple_types_ap->FindByNameAndTag(type_name.GetCString(), tag,
3342 m_apple_types_ap->FindByName(type_name.GetCString(), die_offsets);
3349 m_type_index.Find(type_name, die_offsets);
3352 const size_t num_matches = die_offsets.size();
3354 // Get the type system that we are looking to find a type for. We will use
3356 // to ensure any matches we find are in a language that this type system
3358 const LanguageType language = dwarf_decl_ctx.GetLanguage();
3359 TypeSystem *type_system = (language == eLanguageTypeUnknown)
3361 : GetTypeSystemForLanguage(language);
3364 for (size_t i = 0; i < num_matches; ++i) {
3365 const DIERef &die_ref = die_offsets[i];
3366 DWARFDIE type_die = GetDIE(die_ref);
3369 // Make sure type_die's langauge matches the type system we are
3371 // We don't want to find a "Foo" type from Java if we are looking
3373 // type for C, C++, ObjC, or ObjC++.
3375 !type_system->SupportsLanguage(type_die.GetLanguage()))
3377 bool try_resolving_type = false;
3379 // Don't try and resolve the DIE we are looking for with the DIE
3381 const dw_tag_t type_tag = type_die.Tag();
3382 // Make sure the tags match
3383 if (type_tag == tag) {
3384 // The tags match, lets try resolving this type
3385 try_resolving_type = true;
3387 // The tags don't match, but we need to watch our for a
3388 // forward declaration for a struct and ("struct foo")
3389 // ends up being a class ("class foo { ... };") or
3392 case DW_TAG_class_type:
3393 // We had a "class foo", see if we ended up with a "struct foo {
3395 try_resolving_type = (tag == DW_TAG_structure_type);
3397 case DW_TAG_structure_type:
3398 // We had a "struct foo", see if we ended up with a "class foo {
3400 try_resolving_type = (tag == DW_TAG_class_type);
3403 // Tags don't match, don't event try to resolve
3404 // using this type whose name matches....
3409 if (try_resolving_type) {
3410 DWARFDeclContext type_dwarf_decl_ctx;
3411 type_die.GetDWARFDeclContext(type_dwarf_decl_ctx);
3414 GetObjectFile()->GetModule()->LogMessage(
3415 log, "SymbolFileDWARF::"
3416 "FindDefinitionTypeForDWARFDeclContext(tag=%s, "
3417 "qualified-name='%s') trying die=0x%8.8x (%s)",
3418 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3419 dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(),
3420 type_dwarf_decl_ctx.GetQualifiedName());
3423 // Make sure the decl contexts match all the way up
3424 if (dwarf_decl_ctx == type_dwarf_decl_ctx) {
3425 Type *resolved_type = ResolveType(type_die, false);
3426 if (resolved_type && resolved_type != DIE_IS_BEING_PARSED) {
3427 type_sp = resolved_type->shared_from_this();
3433 std::string qualified_name;
3434 type_die.GetQualifiedName(qualified_name);
3435 GetObjectFile()->GetModule()->LogMessage(
3436 log, "SymbolFileDWARF::"
3437 "FindDefinitionTypeForDWARFDeclContext(tag=%s, "
3438 "qualified-name='%s') ignoring die=0x%8.8x (%s)",
3439 DW_TAG_value_to_name(dwarf_decl_ctx[0].tag),
3440 dwarf_decl_ctx.GetQualifiedName(), type_die.GetOffset(),
3441 qualified_name.c_str());
3445 if (m_using_apple_tables) {
3446 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
3447 "the DWARF debug information has been modified (.apple_types "
3448 "accelerator table had bad die 0x%8.8x for '%s')\n",
3449 die_ref.die_offset, type_name.GetCString());
3459 TypeSP SymbolFileDWARF::ParseType(const SymbolContext &sc, const DWARFDIE &die,
3460 bool *type_is_new_ptr) {
3464 TypeSystem *type_system =
3465 GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
3468 DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
3470 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
3471 type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr);
3473 TypeList *type_list = GetTypeList();
3475 type_list->Insert(type_sp);
3477 if (die.Tag() == DW_TAG_subprogram) {
3478 DIERef die_ref = die.GetDIERef();
3479 std::string scope_qualified_name(GetDeclContextForUID(die.GetID())
3480 .GetScopeQualifiedName()
3482 if (scope_qualified_name.size()) {
3483 NameToOffsetMap::iterator iter =
3484 m_function_scope_qualified_name_map.find(
3485 scope_qualified_name);
3486 if (iter != m_function_scope_qualified_name_map.end())
3487 (*iter).second->insert(die_ref);
3489 DIERefSetSP new_set(new std::set<DIERef>);
3490 new_set->insert(die_ref);
3491 m_function_scope_qualified_name_map.emplace(
3492 std::make_pair(scope_qualified_name, new_set));
3504 size_t SymbolFileDWARF::ParseTypes(const SymbolContext &sc,
3505 const DWARFDIE &orig_die,
3506 bool parse_siblings, bool parse_children) {
3507 size_t types_added = 0;
3508 DWARFDIE die = orig_die;
3510 bool type_is_new = false;
3511 if (ParseType(sc, die, &type_is_new).get()) {
3516 if (parse_children && die.HasChildren()) {
3517 if (die.Tag() == DW_TAG_subprogram) {
3518 SymbolContext child_sc(sc);
3519 child_sc.function = sc.comp_unit->FindFunctionByUID(die.GetID()).get();
3520 types_added += ParseTypes(child_sc, die.GetFirstChild(), true, true);
3522 types_added += ParseTypes(sc, die.GetFirstChild(), true, true);
3526 die = die.GetSibling();
3533 size_t SymbolFileDWARF::ParseFunctionBlocks(const SymbolContext &sc) {
3534 assert(sc.comp_unit && sc.function);
3535 size_t functions_added = 0;
3536 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
3538 const dw_offset_t function_die_offset = sc.function->GetID();
3539 DWARFDIE function_die = dwarf_cu->GetDIE(function_die_offset);
3541 ParseFunctionBlocks(sc, &sc.function->GetBlock(false), function_die,
3542 LLDB_INVALID_ADDRESS, 0);
3546 return functions_added;
3549 size_t SymbolFileDWARF::ParseTypes(const SymbolContext &sc) {
3550 // At least a compile unit must be valid
3551 assert(sc.comp_unit);
3552 size_t types_added = 0;
3553 DWARFCompileUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
3556 dw_offset_t function_die_offset = sc.function->GetID();
3557 DWARFDIE func_die = dwarf_cu->GetDIE(function_die_offset);
3558 if (func_die && func_die.HasChildren()) {
3559 types_added = ParseTypes(sc, func_die.GetFirstChild(), true, true);
3562 DWARFDIE dwarf_cu_die = dwarf_cu->DIE();
3563 if (dwarf_cu_die && dwarf_cu_die.HasChildren()) {
3564 types_added = ParseTypes(sc, dwarf_cu_die.GetFirstChild(), true, true);
3572 size_t SymbolFileDWARF::ParseVariablesForContext(const SymbolContext &sc) {
3573 if (sc.comp_unit != NULL) {
3574 DWARFDebugInfo *info = DebugInfo();
3579 DWARFDIE function_die = info->GetDIE(DIERef(sc.function->GetID(), this));
3581 const dw_addr_t func_lo_pc = function_die.GetAttributeValueAsAddress(
3582 DW_AT_low_pc, LLDB_INVALID_ADDRESS);
3583 if (func_lo_pc != LLDB_INVALID_ADDRESS) {
3584 const size_t num_variables = ParseVariables(
3585 sc, function_die.GetFirstChild(), func_lo_pc, true, true);
3587 // Let all blocks know they have parse all their variables
3588 sc.function->GetBlock(false).SetDidParseVariables(true, true);
3589 return num_variables;
3591 } else if (sc.comp_unit) {
3592 DWARFCompileUnit *dwarf_cu = info->GetCompileUnit(sc.comp_unit->GetID());
3594 if (dwarf_cu == NULL)
3597 uint32_t vars_added = 0;
3598 VariableListSP variables(sc.comp_unit->GetVariableList(false));
3600 if (variables.get() == NULL) {
3601 variables.reset(new VariableList());
3602 sc.comp_unit->SetVariableList(variables);
3604 DIEArray die_offsets;
3605 if (m_using_apple_tables) {
3606 if (m_apple_names_ap.get()) {
3607 DWARFMappedHash::DIEInfoArray hash_data_array;
3608 if (m_apple_names_ap->AppendAllDIEsInRange(
3609 dwarf_cu->GetOffset(), dwarf_cu->GetNextCompileUnitOffset(),
3611 DWARFMappedHash::ExtractDIEArray(hash_data_array, die_offsets);
3615 // Index if we already haven't to make sure the compile units
3616 // get indexed and make their global DIE index list
3620 m_global_index.FindAllEntriesForCompileUnit(dwarf_cu->GetOffset(),
3624 const size_t num_matches = die_offsets.size();
3626 for (size_t i = 0; i < num_matches; ++i) {
3627 const DIERef &die_ref = die_offsets[i];
3628 DWARFDIE die = GetDIE(die_ref);
3631 ParseVariableDIE(sc, die, LLDB_INVALID_ADDRESS));
3633 variables->AddVariableIfUnique(var_sp);
3637 if (m_using_apple_tables) {
3638 GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
3639 "the DWARF debug information has been modified "
3640 "(.apple_names accelerator table had bad die 0x%8.8x)\n",
3641 die_ref.die_offset);
3653 VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
3654 const DWARFDIE &die,
3655 const lldb::addr_t func_low_pc) {
3656 if (die.GetDWARF() != this)
3657 return die.GetDWARF()->ParseVariableDIE(sc, die, func_low_pc);
3663 var_sp = GetDIEToVariable()[die.GetDIE()];
3665 return var_sp; // Already been parsed!
3667 const dw_tag_t tag = die.Tag();
3668 ModuleSP module = GetObjectFile()->GetModule();
3670 if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) ||
3671 (tag == DW_TAG_formal_parameter && sc.function)) {
3672 DWARFAttributes attributes;
3673 const size_t num_attributes = die.GetAttributes(attributes);
3675 if (num_attributes > 0) {
3676 const char *name = NULL;
3677 const char *mangled = NULL;
3680 DWARFFormValue type_die_form;
3681 DWARFExpression location(die.GetCU());
3682 bool is_external = false;
3683 bool is_artificial = false;
3684 bool location_is_const_value_data = false;
3685 bool has_explicit_location = false;
3686 DWARFFormValue const_value;
3687 Variable::RangeList scope_ranges;
3688 // AccessType accessibility = eAccessNone;
3690 for (i = 0; i < num_attributes; ++i) {
3691 dw_attr_t attr = attributes.AttributeAtIndex(i);
3692 DWARFFormValue form_value;
3694 if (attributes.ExtractFormValueAtIndex(i, form_value)) {
3696 case DW_AT_decl_file:
3697 decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(
3698 form_value.Unsigned()));
3700 case DW_AT_decl_line:
3701 decl.SetLine(form_value.Unsigned());
3703 case DW_AT_decl_column:
3704 decl.SetColumn(form_value.Unsigned());
3707 name = form_value.AsCString();
3709 case DW_AT_linkage_name:
3710 case DW_AT_MIPS_linkage_name:
3711 mangled = form_value.AsCString();
3714 type_die_form = form_value;
3716 case DW_AT_external:
3717 is_external = form_value.Boolean();
3719 case DW_AT_const_value:
3720 // If we have already found a DW_AT_location attribute, ignore this
3722 if (!has_explicit_location) {
3723 location_is_const_value_data = true;
3724 // The constant value will be either a block, a data value or a
3726 const DWARFDataExtractor &debug_info_data = get_debug_info_data();
3727 if (DWARFFormValue::IsBlockForm(form_value.Form())) {
3728 // Retrieve the value as a block expression.
3729 uint32_t block_offset =
3730 form_value.BlockData() - debug_info_data.GetDataStart();
3731 uint32_t block_length = form_value.Unsigned();
3732 location.CopyOpcodeData(module, debug_info_data, block_offset,
3734 } else if (DWARFFormValue::IsDataForm(form_value.Form())) {
3735 // Retrieve the value as a data expression.
3736 DWARFFormValue::FixedFormSizes fixed_form_sizes =
3737 DWARFFormValue::GetFixedFormSizesForAddressSize(
3738 attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
3739 attributes.CompileUnitAtIndex(i)->IsDWARF64());
3740 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
3741 uint32_t data_length =
3742 fixed_form_sizes.GetSize(form_value.Form());
3743 if (data_length == 0) {
3744 const uint8_t *data_pointer = form_value.BlockData();
3746 form_value.Unsigned();
3747 } else if (DWARFFormValue::IsDataForm(form_value.Form())) {
3748 // we need to get the byte size of the type later after we
3749 // create the variable
3750 const_value = form_value;
3753 location.CopyOpcodeData(module, debug_info_data, data_offset,
3756 // Retrieve the value as a string expression.
3757 if (form_value.Form() == DW_FORM_strp) {
3758 DWARFFormValue::FixedFormSizes fixed_form_sizes =
3759 DWARFFormValue::GetFixedFormSizesForAddressSize(
3760 attributes.CompileUnitAtIndex(i)
3761 ->GetAddressByteSize(),
3762 attributes.CompileUnitAtIndex(i)->IsDWARF64());
3763 uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
3764 uint32_t data_length =
3765 fixed_form_sizes.GetSize(form_value.Form());
3766 location.CopyOpcodeData(module, debug_info_data, data_offset,
3769 const char *str = form_value.AsCString();
3770 uint32_t string_offset =
3771 str - (const char *)debug_info_data.GetDataStart();
3772 uint32_t string_length = strlen(str) + 1;
3773 location.CopyOpcodeData(module, debug_info_data,
3774 string_offset, string_length);
3779 case DW_AT_location: {
3780 location_is_const_value_data = false;
3781 has_explicit_location = true;
3782 if (DWARFFormValue::IsBlockForm(form_value.Form())) {
3783 const DWARFDataExtractor &debug_info_data = get_debug_info_data();
3785 uint32_t block_offset =
3786 form_value.BlockData() - debug_info_data.GetDataStart();
3787 uint32_t block_length = form_value.Unsigned();
3788 location.CopyOpcodeData(module, get_debug_info_data(),
3789 block_offset, block_length);
3791 const DWARFDataExtractor &debug_loc_data = get_debug_loc_data();
3792 const dw_offset_t debug_loc_offset = form_value.Unsigned();
3794 size_t loc_list_length = DWARFExpression::LocationListSize(
3795 die.GetCU(), debug_loc_data, debug_loc_offset);
3796 if (loc_list_length > 0) {
3797 location.CopyOpcodeData(module, debug_loc_data,
3798 debug_loc_offset, loc_list_length);
3799 assert(func_low_pc != LLDB_INVALID_ADDRESS);
3800 location.SetLocationListSlide(
3802 attributes.CompileUnitAtIndex(i)->GetBaseAddress());
3806 case DW_AT_specification:
3807 spec_die = GetDIE(DIERef(form_value));
3809 case DW_AT_start_scope: {
3810 if (form_value.Form() == DW_FORM_sec_offset) {
3811 DWARFRangeList dwarf_scope_ranges;
3812 const DWARFDebugRanges *debug_ranges = DebugRanges();
3813 debug_ranges->FindRanges(die.GetCU()->GetRangesBase(),
3814 form_value.Unsigned(),
3815 dwarf_scope_ranges);
3817 // All DW_AT_start_scope are relative to the base address of the
3818 // compile unit. We add the compile unit base address to make
3819 // sure all the addresses are properly fixed up.
3820 for (size_t i = 0, count = dwarf_scope_ranges.GetSize();
3822 const DWARFRangeList::Entry &range =
3823 dwarf_scope_ranges.GetEntryRef(i);
3824 scope_ranges.Append(range.GetRangeBase() +
3825 die.GetCU()->GetBaseAddress(),
3826 range.GetByteSize());
3829 // TODO: Handle the case when DW_AT_start_scope have form
3831 // dwarf spec is a bit ambiguous about what is the expected
3833 // case the enclosing block have a non coninious address range and
3835 // DW_AT_start_scope entry have a form constant.
3836 GetObjectFile()->GetModule()->ReportWarning(
3838 ": DW_AT_start_scope has unsupported form type (0x%x)\n",
3839 die.GetID(), form_value.Form());
3842 scope_ranges.Sort();
3843 scope_ranges.CombineConsecutiveRanges();
3845 case DW_AT_artificial:
3846 is_artificial = form_value.Boolean();
3848 case DW_AT_accessibility:
3849 break; // accessibility =
3850 // DW_ACCESS_to_AccessType(form_value.Unsigned()); break;
3851 case DW_AT_declaration:
3852 case DW_AT_description:
3853 case DW_AT_endianity:
3855 case DW_AT_visibility:
3857 case DW_AT_abstract_origin:
3864 const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE(die);
3865 const dw_tag_t parent_tag = die.GetParent().Tag();
3866 bool is_static_member =
3867 parent_tag == DW_TAG_compile_unit &&
3868 (parent_context_die.Tag() == DW_TAG_class_type ||
3869 parent_context_die.Tag() == DW_TAG_structure_type);
3871 ValueType scope = eValueTypeInvalid;
3873 const DWARFDIE sc_parent_die = GetParentSymbolContextDIE(die);
3874 SymbolContextScope *symbol_context_scope = NULL;
3876 bool has_explicit_mangled = mangled != nullptr;
3878 // LLDB relies on the mangled name (DW_TAG_linkage_name or
3879 // DW_AT_MIPS_linkage_name) to
3880 // generate fully qualified names of global variables with commands like
3882 // For example, if j were an int variable holding a value 4 and declared
3884 // B which in turn is contained in a namespace A, the command "frame var
3886 // "(int) A::B::j = 4". If the compiler does not emit a linkage name, we
3888 // to generate a fully qualified name from the declaration context.
3889 if (parent_tag == DW_TAG_compile_unit &&
3890 Language::LanguageIsCPlusPlus(die.GetLanguage())) {
3891 DWARFDeclContext decl_ctx;
3893 die.GetDWARFDeclContext(decl_ctx);
3894 mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
3898 if (tag == DW_TAG_formal_parameter)
3899 scope = eValueTypeVariableArgument;
3901 // DWARF doesn't specify if a DW_TAG_variable is a local, global
3902 // or static variable, so we have to do a little digging:
3903 // 1) DW_AT_linkage_name implies static lifetime (but may be missing)
3904 // 2) An empty DW_AT_location is an (optimized-out) static lifetime var.
3905 // 3) DW_AT_location containing a DW_OP_addr implies static lifetime.
3906 // Clang likes to combine small global variables into the same symbol
3907 // with locations like: DW_OP_addr(0x1000), DW_OP_constu(2), DW_OP_plus
3908 // so we need to look through the whole expression.
3909 bool is_static_lifetime =
3910 has_explicit_mangled ||
3911 (has_explicit_location && !location.IsValid());
3912 // Check if the location has a DW_OP_addr with any address value...
3913 lldb::addr_t location_DW_OP_addr = LLDB_INVALID_ADDRESS;
3914 if (!location_is_const_value_data) {
3915 bool op_error = false;
3916 location_DW_OP_addr = location.GetLocation_DW_OP_addr(0, op_error);
3919 location.DumpLocationForAddress(&strm, eDescriptionLevelFull, 0, 0,
3921 GetObjectFile()->GetModule()->ReportError(
3922 "0x%8.8x: %s has an invalid location: %s", die.GetOffset(),
3923 die.GetTagAsCString(), strm.GetData());
3925 if (location_DW_OP_addr != LLDB_INVALID_ADDRESS)
3926 is_static_lifetime = true;
3928 SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
3930 if (is_static_lifetime) {
3932 scope = eValueTypeVariableGlobal;
3934 scope = eValueTypeVariableStatic;
3936 if (debug_map_symfile) {
3937 // When leaving the DWARF in the .o files on darwin,
3938 // when we have a global variable that wasn't initialized,
3939 // the .o file might not have allocated a virtual
3940 // address for the global variable. In this case it will
3941 // have created a symbol for the global variable
3942 // that is undefined/data and external and the value will
3943 // be the byte size of the variable. When we do the
3944 // address map in SymbolFileDWARFDebugMap we rely on
3945 // having an address, we need to do some magic here
3946 // so we can get the correct address for our global
3947 // variable. The address for all of these entries
3948 // will be zero, and there will be an undefined symbol
3949 // in this object file, and the executable will have
3950 // a matching symbol with a good address. So here we
3951 // dig up the correct address and replace it in the
3952 // location for the variable, and set the variable's
3953 // symbol context scope to be that of the main executable
3954 // so the file address will resolve correctly.
3955 bool linked_oso_file_addr = false;
3956 if (is_external && location_DW_OP_addr == 0) {
3957 // we have a possible uninitialized extern global
3958 ConstString const_name(mangled ? mangled : name);
3959 ObjectFile *debug_map_objfile =
3960 debug_map_symfile->GetObjectFile();
3961 if (debug_map_objfile) {
3962 Symtab *debug_map_symtab = debug_map_objfile->GetSymtab();
3963 if (debug_map_symtab) {
3964 Symbol *exe_symbol =
3965 debug_map_symtab->FindFirstSymbolWithNameAndType(
3966 const_name, eSymbolTypeData, Symtab::eDebugYes,
3967 Symtab::eVisibilityExtern);
3969 if (exe_symbol->ValueIsAddress()) {
3970 const addr_t exe_file_addr =
3971 exe_symbol->GetAddressRef().GetFileAddress();
3972 if (exe_file_addr != LLDB_INVALID_ADDRESS) {
3973 if (location.Update_DW_OP_addr(exe_file_addr)) {
3974 linked_oso_file_addr = true;
3975 symbol_context_scope = exe_symbol;
3984 if (!linked_oso_file_addr) {
3985 // The DW_OP_addr is not zero, but it contains a .o file address
3987 // needs to be linked up correctly.
3988 const lldb::addr_t exe_file_addr =
3989 debug_map_symfile->LinkOSOFileAddress(this,
3990 location_DW_OP_addr);
3991 if (exe_file_addr != LLDB_INVALID_ADDRESS) {
3992 // Update the file address for this variable
3993 location.Update_DW_OP_addr(exe_file_addr);
3995 // Variable didn't make it into the final executable
4001 if (location_is_const_value_data)
4002 scope = eValueTypeVariableStatic;
4004 scope = eValueTypeVariableLocal;
4005 if (debug_map_symfile) {
4006 // We need to check for TLS addresses that we need to fixup
4007 if (location.ContainsThreadLocalStorage()) {
4008 location.LinkThreadLocalStorage(
4009 debug_map_symfile->GetObjectFile()->GetModule(),
4010 [this, debug_map_symfile](
4011 lldb::addr_t unlinked_file_addr) -> lldb::addr_t {
4012 return debug_map_symfile->LinkOSOFileAddress(
4013 this, unlinked_file_addr);
4015 scope = eValueTypeVariableThreadLocal;
4022 if (symbol_context_scope == NULL) {
4023 switch (parent_tag) {
4024 case DW_TAG_subprogram:
4025 case DW_TAG_inlined_subroutine:
4026 case DW_TAG_lexical_block:
4028 symbol_context_scope = sc.function->GetBlock(true).FindBlockByID(
4029 sc_parent_die.GetID());
4030 if (symbol_context_scope == NULL)
4031 symbol_context_scope = sc.function;
4036 symbol_context_scope = sc.comp_unit;
4041 if (symbol_context_scope) {
4042 SymbolFileTypeSP type_sp(
4043 new SymbolFileType(*this, DIERef(type_die_form).GetUID(this)));
4045 if (const_value.Form() && type_sp && type_sp->GetType())
4046 location.CopyOpcodeData(const_value.Unsigned(),
4047 type_sp->GetType()->GetByteSize(),
4048 die.GetCU()->GetAddressByteSize());
4050 var_sp.reset(new Variable(die.GetID(), name, mangled, type_sp, scope,
4051 symbol_context_scope, scope_ranges, &decl,
4052 location, is_external, is_artificial,
4055 var_sp->SetLocationIsConstantValueData(location_is_const_value_data);
4057 // Not ready to parse this variable yet. It might be a global
4058 // or static variable that is in a function scope and the function
4059 // in the symbol context wasn't filled in yet
4063 // Cache var_sp even if NULL (the variable was just a specification or
4064 // was missing vital information to be able to be displayed in the debugger
4065 // (missing location due to optimization, etc)) so we don't re-parse
4066 // this DIE over and over later...
4067 GetDIEToVariable()[die.GetDIE()] = var_sp;
4069 GetDIEToVariable()[spec_die.GetDIE()] = var_sp;
4075 SymbolFileDWARF::FindBlockContainingSpecification(
4076 const DIERef &func_die_ref, dw_offset_t spec_block_die_offset) {
4077 // Give the concrete function die specified by "func_die_offset", find the
4078 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4079 // to "spec_block_die_offset"
4080 return FindBlockContainingSpecification(DebugInfo()->GetDIE(func_die_ref),
4081 spec_block_die_offset);
4085 SymbolFileDWARF::FindBlockContainingSpecification(
4086 const DWARFDIE &die, dw_offset_t spec_block_die_offset) {
4088 switch (die.Tag()) {
4089 case DW_TAG_subprogram:
4090 case DW_TAG_inlined_subroutine:
4091 case DW_TAG_lexical_block: {
4092 if (die.GetAttributeValueAsReference(
4093 DW_AT_specification, DW_INVALID_OFFSET) == spec_block_die_offset)
4096 if (die.GetAttributeValueAsReference(DW_AT_abstract_origin,
4097 DW_INVALID_OFFSET) ==
4098 spec_block_die_offset)
4103 // Give the concrete function die specified by "func_die_offset", find the
4104 // concrete block whose DW_AT_specification or DW_AT_abstract_origin points
4105 // to "spec_block_die_offset"
4106 for (DWARFDIE child_die = die.GetFirstChild(); child_die;
4107 child_die = child_die.GetSibling()) {
4108 DWARFDIE result_die =
4109 FindBlockContainingSpecification(child_die, spec_block_die_offset);
4118 size_t SymbolFileDWARF::ParseVariables(const SymbolContext &sc,
4119 const DWARFDIE &orig_die,
4120 const lldb::addr_t func_low_pc,
4121 bool parse_siblings, bool parse_children,
4122 VariableList *cc_variable_list) {
4126 VariableListSP variable_list_sp;
4128 size_t vars_added = 0;
4129 DWARFDIE die = orig_die;
4131 dw_tag_t tag = die.Tag();
4133 // Check to see if we have already parsed this variable or constant?
4134 VariableSP var_sp = GetDIEToVariable()[die.GetDIE()];
4136 if (cc_variable_list)
4137 cc_variable_list->AddVariableIfUnique(var_sp);
4139 // We haven't already parsed it, lets do that now.
4140 if ((tag == DW_TAG_variable) || (tag == DW_TAG_constant) ||
4141 (tag == DW_TAG_formal_parameter && sc.function)) {
4142 if (variable_list_sp.get() == NULL) {
4143 DWARFDIE sc_parent_die = GetParentSymbolContextDIE(orig_die);
4144 dw_tag_t parent_tag = sc_parent_die.Tag();
4145 switch (parent_tag) {
4146 case DW_TAG_compile_unit:
4147 if (sc.comp_unit != NULL) {
4148 variable_list_sp = sc.comp_unit->GetVariableList(false);
4149 if (variable_list_sp.get() == NULL) {
4150 variable_list_sp.reset(new VariableList());
4151 sc.comp_unit->SetVariableList(variable_list_sp);
4154 GetObjectFile()->GetModule()->ReportError(
4155 "parent 0x%8.8" PRIx64 " %s with no valid compile unit in "
4156 "symbol context for 0x%8.8" PRIx64
4158 sc_parent_die.GetID(), sc_parent_die.GetTagAsCString(),
4159 orig_die.GetID(), orig_die.GetTagAsCString());
4163 case DW_TAG_subprogram:
4164 case DW_TAG_inlined_subroutine:
4165 case DW_TAG_lexical_block:
4166 if (sc.function != NULL) {
4167 // Check to see if we already have parsed the variables for the
4170 Block *block = sc.function->GetBlock(true).FindBlockByID(
4171 sc_parent_die.GetID());
4172 if (block == NULL) {
4173 // This must be a specification or abstract origin with
4174 // a concrete block counterpart in the current function. We need
4175 // to find the concrete block so we can correctly add the
4177 const DWARFDIE concrete_block_die =
4178 FindBlockContainingSpecification(
4179 DIERef(sc.function->GetID(), this),
4180 sc_parent_die.GetOffset());
4181 if (concrete_block_die)
4182 block = sc.function->GetBlock(true).FindBlockByID(
4183 concrete_block_die.GetID());
4186 if (block != NULL) {
4187 const bool can_create = false;
4188 variable_list_sp = block->GetBlockVariableList(can_create);
4189 if (variable_list_sp.get() == NULL) {
4190 variable_list_sp.reset(new VariableList());
4191 block->SetVariableList(variable_list_sp);
4198 GetObjectFile()->GetModule()->ReportError(
4199 "didn't find appropriate parent DIE for variable list for "
4200 "0x%8.8" PRIx64 " %s.\n",
4201 orig_die.GetID(), orig_die.GetTagAsCString());
4206 if (variable_list_sp) {
4207 VariableSP var_sp(ParseVariableDIE(sc, die, func_low_pc));
4209 variable_list_sp->AddVariableIfUnique(var_sp);
4210 if (cc_variable_list)
4211 cc_variable_list->AddVariableIfUnique(var_sp);
4218 bool skip_children = (sc.function == NULL && tag == DW_TAG_subprogram);
4220 if (!skip_children && parse_children && die.HasChildren()) {
4221 vars_added += ParseVariables(sc, die.GetFirstChild(), func_low_pc, true,
4222 true, cc_variable_list);
4226 die = die.GetSibling();
4233 //------------------------------------------------------------------
4234 // PluginInterface protocol
4235 //------------------------------------------------------------------
4236 ConstString SymbolFileDWARF::GetPluginName() { return GetPluginNameStatic(); }
4238 uint32_t SymbolFileDWARF::GetPluginVersion() { return 1; }
4240 void SymbolFileDWARF::DumpIndexes() {
4241 StreamFile s(stdout, false);
4244 "DWARF index for (%s) '%s':",
4245 GetObjectFile()->GetModule()->GetArchitecture().GetArchitectureName(),
4246 GetObjectFile()->GetFileSpec().GetPath().c_str());
4247 s.Printf("\nFunction basenames:\n");
4248 m_function_basename_index.Dump(&s);
4249 s.Printf("\nFunction fullnames:\n");
4250 m_function_fullname_index.Dump(&s);
4251 s.Printf("\nFunction methods:\n");
4252 m_function_method_index.Dump(&s);
4253 s.Printf("\nFunction selectors:\n");
4254 m_function_selector_index.Dump(&s);
4255 s.Printf("\nObjective C class selectors:\n");
4256 m_objc_class_selectors_index.Dump(&s);
4257 s.Printf("\nGlobals and statics:\n");
4258 m_global_index.Dump(&s);
4259 s.Printf("\nTypes:\n");
4260 m_type_index.Dump(&s);
4261 s.Printf("\nNamespaces:\n");
4262 m_namespace_index.Dump(&s);
4265 SymbolFileDWARFDebugMap *SymbolFileDWARF::GetDebugMapSymfile() {
4266 if (m_debug_map_symfile == NULL && !m_debug_map_module_wp.expired()) {
4267 lldb::ModuleSP module_sp(m_debug_map_module_wp.lock());
4269 SymbolVendor *sym_vendor = module_sp->GetSymbolVendor();
4271 m_debug_map_symfile =
4272 (SymbolFileDWARFDebugMap *)sym_vendor->GetSymbolFile();
4275 return m_debug_map_symfile;
4278 DWARFExpression::LocationListFormat
4279 SymbolFileDWARF::GetLocationListFormat() const {
4280 return DWARFExpression::RegularLocationList;