From 0352007fdb3f6ae1eaedbff53e018ad1e364720e Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Thu, 14 Nov 2019 09:35:06 -0800 Subject: [PATCH] Convert UpdateExternalModuleListIfNeeded to use early exits. --- .../Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp | 118 ++++++++++----------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 0a2ce5a..4d4a0d8 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1618,72 +1618,72 @@ void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() { DWARFDebugInfo *debug_info = DebugInfo(); + // Follow DWO skeleton unit breadcrumbs. const uint32_t num_compile_units = GetNumCompileUnits(); for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) { DWARFUnit *dwarf_cu = debug_info->GetUnitAtIndex(cu_idx); - const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly(); - if (die && !die.HasChildren()) { - const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr); - - if (name) { - ConstString const_name(name); - if (m_external_type_modules.find(const_name) == - m_external_type_modules.end()) { - ModuleSP module_sp; - const char *dwo_path = - die.GetAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr); - if (dwo_path) { - ModuleSpec dwo_module_spec; - dwo_module_spec.GetFileSpec().SetFile(dwo_path, - FileSpec::Style::native); - if (dwo_module_spec.GetFileSpec().IsRelative()) { - const char *comp_dir = - die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr); - if (comp_dir) { - dwo_module_spec.GetFileSpec().SetFile(comp_dir, - FileSpec::Style::native); - FileSystem::Instance().Resolve(dwo_module_spec.GetFileSpec()); - dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path); - } - } - dwo_module_spec.GetArchitecture() = - m_objfile_sp->GetModule()->GetArchitecture(); - - // When LLDB loads "external" modules it looks at the presence of - // DW_AT_GNU_dwo_name. However, when the already created module - // (corresponding to .dwo itself) is being processed, it will see - // the presence of DW_AT_GNU_dwo_name (which contains the name of - // dwo file) and will try to call ModuleList::GetSharedModule - // again. In some cases (i.e. for empty files) Clang 4.0 generates - // a *.dwo file which has DW_AT_GNU_dwo_name, but no - // DW_AT_comp_dir. In this case the method - // ModuleList::GetSharedModule will fail and the warning will be - // printed. However, as one can notice in this case we don't - // actually need to try to load the already loaded module - // (corresponding to .dwo) so we simply skip it. - if (m_objfile_sp->GetFileSpec().GetFileNameExtension() == ".dwo" && - llvm::StringRef(m_objfile_sp->GetFileSpec().GetPath()) - .endswith(dwo_module_spec.GetFileSpec().GetPath())) { - continue; - } + if (!die || die.HasChildren()) + continue; - Status error = ModuleList::GetSharedModule( - dwo_module_spec, module_sp, nullptr, nullptr, nullptr); - if (!module_sp) { - GetObjectFile()->GetModule()->ReportWarning( - "0x%8.8x: unable to locate module needed for external types: " - "%s\nerror: %s\nDebugging will be degraded due to missing " - "types. Rebuilding your project will regenerate the needed " - "module files.", - die.GetOffset(), - dwo_module_spec.GetFileSpec().GetPath().c_str(), - error.AsCString("unknown error")); - } - } - m_external_type_modules[const_name] = module_sp; + const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr); + if (!name) + continue; + + ConstString const_name(name); + ModuleSP &module_sp = m_external_type_modules[const_name]; + if (module_sp) + continue; + + const char *dwo_path = + die.GetAttributeValueAsString(DW_AT_GNU_dwo_name, nullptr); + if (!dwo_path) + dwo_path = die.GetAttributeValueAsString(DW_AT_dwo_name, nullptr); + if (dwo_path) { + ModuleSpec dwo_module_spec; + dwo_module_spec.GetFileSpec().SetFile(dwo_path, FileSpec::Style::native); + if (dwo_module_spec.GetFileSpec().IsRelative()) { + const char *comp_dir = + die.GetAttributeValueAsString(DW_AT_comp_dir, nullptr); + if (comp_dir) { + dwo_module_spec.GetFileSpec().SetFile(comp_dir, + FileSpec::Style::native); + FileSystem::Instance().Resolve(dwo_module_spec.GetFileSpec()); + dwo_module_spec.GetFileSpec().AppendPathComponent(dwo_path); } } + dwo_module_spec.GetArchitecture() = + m_objfile_sp->GetModule()->GetArchitecture(); + + // When LLDB loads "external" modules it looks at the presence + // of DW_AT_dwo_name. However, when the already created module + // (corresponding to .dwo itself) is being processed, it will + // see the presence of DW_AT_dwo_name (which contains the name + // of dwo file) and will try to call ModuleList::GetSharedModule + // again. In some cases (i.e., for empty files) Clang 4.0 + // generates a *.dwo file which has DW_AT_dwo_name, but no + // DW_AT_comp_dir. In this case the method + // ModuleList::GetSharedModule will fail and the warning will be + // printed. However, as one can notice in this case we don't + // actually need to try to load the already loaded module + // (corresponding to .dwo) so we simply skip it. + if (m_objfile_sp->GetFileSpec().GetFileNameExtension() == ".dwo" && + llvm::StringRef(m_objfile_sp->GetFileSpec().GetPath()) + .endswith(dwo_module_spec.GetFileSpec().GetPath())) { + continue; + } + + Status error = ModuleList::GetSharedModule(dwo_module_spec, module_sp, + nullptr, nullptr, nullptr); + if (!module_sp) { + GetObjectFile()->GetModule()->ReportWarning( + "0x%8.8x: unable to locate module needed for external types: " + "%s\nerror: %s\nDebugging will be degraded due to missing " + "types. Rebuilding your project will regenerate the needed " + "module files.", + die.GetOffset(), dwo_module_spec.GetFileSpec().GetPath().c_str(), + error.AsCString("unknown error")); + } } } } -- 2.7.4