diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h --- a/lldb/include/lldb/Symbol/ObjectFile.h +++ b/lldb/include/lldb/Symbol/ObjectFile.h @@ -682,6 +682,10 @@ return symbol_name; } + /// Can we trust the address ranges accelerator associated with this object + /// file to be complete. + virtual bool CanTrustAddressRanges() { return false; } + static lldb::SymbolType GetSymbolTypeFromName( llvm::StringRef name, lldb::SymbolType symbol_type_hint = lldb::eSymbolTypeUndefined); diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h @@ -143,6 +143,8 @@ bool GetIsDynamicLinkEditor() override; + bool CanTrustAddressRanges() override; + static bool ParseHeader(lldb_private::DataExtractor &data, lldb::offset_t *data_offset_ptr, llvm::MachO::mach_header &header); diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -6094,6 +6094,12 @@ return m_header.filetype == llvm::MachO::MH_DYLINKER; } +bool ObjectFileMachO::CanTrustAddressRanges() { + // Dsymutil guarantees that the .debug_aranges accelerator is complete and can + // be trusted by LLDB. + return m_header.filetype == llvm::MachO::MH_DSYM; +} + bool ObjectFileMachO::AllowAssemblyEmulationUnwindPlans() { return m_allow_assembly_emulation_unwind_plans; } diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp @@ -53,12 +53,13 @@ } // Manually build arange data for everything that wasn't in .debug_aranges. - // Skip this step for dSYMs as we can trust dsymutil to have emitted complete - // aranges. - const bool is_dsym = - m_dwarf.GetObjectFile() && - m_dwarf.GetObjectFile()->GetType() == ObjectFile::eTypeDebugInfo; - if (!is_dsym) { + // The .debug_aranges accelerator is not guaranteed to be complete. + // Tools such as dsymutil can provide stronger guarantees than required by the + // standard. Without that guarantee, we have to iterate over every CU in the + // .debug_info and make sure there's a corresponding entry in the table and if + // not, add one for every subprogram. + ObjectFile *OF = m_dwarf.GetObjectFile(); + if (!OF || !OF->CanTrustAddressRanges()) { const size_t num_units = GetNumUnits(); for (size_t idx = 0; idx < num_units; ++idx) { DWARFUnit *cu = GetUnitAtIndex(idx);