diff --git a/lldb/include/lldb/Core/RangeMap.h b/lldb/include/lldb/Core/RangeMap.h index b2e3f06f08a9..538d562968bb 100644 --- a/lldb/include/lldb/Core/RangeMap.h +++ b/lldb/include/lldb/Core/RangeMap.h @@ -1216,6 +1216,25 @@ namespace lldb_private { } return UINT32_MAX; } + + uint32_t + FindEntryIndexesThatContains (B addr, std::vector &indexes) const + { +#ifdef ASSERT_RANGEMAP_ARE_SORTED + assert (IsSorted()); +#endif + + if (!m_entries.empty()) + { + typename Collection::const_iterator pos; + for(pos = m_entries.begin(); pos != m_entries.end(); pos++) + { + if (pos->Contains(addr)) + indexes.push_back (pos->data); + } + } + return indexes.size() ; + } Entry * FindEntryThatContains (B addr) diff --git a/lldb/include/lldb/Symbol/Symtab.h b/lldb/include/lldb/Symbol/Symtab.h index cf28c7e87ac5..31d0d8a51ad2 100644 --- a/lldb/include/lldb/Symbol/Symtab.h +++ b/lldb/include/lldb/Symbol/Symtab.h @@ -81,6 +81,7 @@ public: Symbol * FindFirstSymbolWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility); Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr, const uint32_t* indexes, uint32_t num_indexes); Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr); + void ForEachSymbolContainingFileAddresss (lldb::addr_t file_addr, std::function const &callback); size_t FindFunctionSymbols (const ConstString &name, uint32_t name_type_mask, SymbolContextList& sc_list); void CalculateSymbolSizes (); diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp index 833540e1a309..c4d90f53db04 100644 --- a/lldb/source/Core/Module.cpp +++ b/lldb/source/Core/Module.cpp @@ -559,7 +559,16 @@ Module::ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve Symtab *symtab = sym_vendor->GetSymtab(); if (symtab && so_addr.IsSectionOffset()) { - sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress()); + Symbol *matching_symbol = nullptr; + symtab->ForEachSymbolContainingFileAddresss (so_addr.GetFileAddress(), [&matching_symbol](Symbol *symbol) -> bool { + if (symbol->GetType() != eSymbolTypeInvalid) + { + matching_symbol = symbol; + return false; // Stop iterating + } + return true; // Keep iterating + }); + sc.symbol = matching_symbol; if (!sc.symbol && resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction)) { diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp index 31db57289fdc..61b8317fde13 100644 --- a/lldb/source/Symbol/Symtab.cpp +++ b/lldb/source/Symbol/Symtab.cpp @@ -1073,6 +1073,26 @@ Symtab::FindSymbolContainingFileAddress (addr_t file_addr) return nullptr; } +void +Symtab::ForEachSymbolContainingFileAddresss (addr_t file_addr, std::function const &callback) +{ + Mutex::Locker locker (m_mutex); + + if (!m_file_addr_to_index_computed) + InitAddressIndexes(); + + std::vector all_addr_indexes; + + // Get all symbols with file_addr + const size_t addr_match_count = m_file_addr_to_index.FindEntryIndexesThatContains(file_addr, all_addr_indexes); + + for (size_t i=0; i &symbol_indexes, SymbolContextList &sc_list) {