<div dir="ltr">What is this fixing and how can we write a test for it?</div><br><div class="gmail_quote"><div dir="ltr">On Sat, Jan 23, 2016 at 2:40 AM Mohit K. Bhakkad via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mohit.bhakkad<br>
Date: Sat Jan 23 04:36:06 2016<br>
New Revision: 258621<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=258621&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=258621&view=rev</a><br>
Log:<br>
[LLDB] Consider only valid symbols while resolving by address<br>
<br>
Reviewers: clayborg.<br>
Subscribers: jaydeep, bhushan, sagar, nitesh.jain, lldb-commits.<br>
Differential Revision: <a href="http://reviews.llvm.org/D16397" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16397</a><br>
<br>
Modified:<br>
lldb/trunk/include/lldb/Core/RangeMap.h<br>
lldb/trunk/include/lldb/Symbol/Symtab.h<br>
lldb/trunk/source/Core/Module.cpp<br>
lldb/trunk/source/Symbol/Symtab.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/Core/RangeMap.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RangeMap.h?rev=258621&r1=258620&r2=258621&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RangeMap.h?rev=258621&r1=258620&r2=258621&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Core/RangeMap.h (original)<br>
+++ lldb/trunk/include/lldb/Core/RangeMap.h Sat Jan 23 04:36:06 2016<br>
@@ -1216,6 +1216,25 @@ namespace lldb_private {<br>
}<br>
return UINT32_MAX;<br>
}<br>
+<br>
+ uint32_t<br>
+ FindEntryIndexesThatContains (B addr, std::vector<uint32_t> &indexes) const<br>
+ {<br>
+#ifdef ASSERT_RANGEMAP_ARE_SORTED<br>
+ assert (IsSorted());<br>
+#endif<br>
+<br>
+ if (!m_entries.empty())<br>
+ {<br>
+ typename Collection::const_iterator pos;<br>
+ for(pos = m_entries.begin(); pos != m_entries.end(); pos++)<br>
+ {<br>
+ if (pos->Contains(addr))<br>
+ indexes.push_back (pos->data);<br>
+ }<br>
+ }<br>
+ return indexes.size() ;<br>
+ }<br>
<br>
Entry *<br>
FindEntryThatContains (B addr)<br>
<br>
Modified: lldb/trunk/include/lldb/Symbol/Symtab.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symtab.h?rev=258621&r1=258620&r2=258621&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/Symtab.h?rev=258621&r1=258620&r2=258621&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/Symtab.h (original)<br>
+++ lldb/trunk/include/lldb/Symbol/Symtab.h Sat Jan 23 04:36:06 2016<br>
@@ -81,6 +81,7 @@ public:<br>
Symbol * FindFirstSymbolWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility);<br>
Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr, const uint32_t* indexes, uint32_t num_indexes);<br>
Symbol * FindSymbolContainingFileAddress (lldb::addr_t file_addr);<br>
+ void ForEachSymbolContainingFileAddresss (lldb::addr_t file_addr, std::function <bool(Symbol *)> const &callback);<br>
size_t FindFunctionSymbols (const ConstString &name, uint32_t name_type_mask, SymbolContextList& sc_list);<br>
void CalculateSymbolSizes ();<br>
<br>
<br>
Modified: lldb/trunk/source/Core/Module.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=258621&r1=258620&r2=258621&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=258621&r1=258620&r2=258621&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Core/Module.cpp (original)<br>
+++ lldb/trunk/source/Core/Module.cpp Sat Jan 23 04:36:06 2016<br>
@@ -559,7 +559,16 @@ Module::ResolveSymbolContextForAddress (<br>
Symtab *symtab = sym_vendor->GetSymtab();<br>
if (symtab && so_addr.IsSectionOffset())<br>
{<br>
- sc.symbol = symtab->FindSymbolContainingFileAddress(so_addr.GetFileAddress());<br>
+ Symbol *matching_symbol = nullptr;<br>
+ symtab->ForEachSymbolContainingFileAddresss (so_addr.GetFileAddress(), [&matching_symbol](Symbol *symbol) -> bool {<br>
+ if (symbol->GetType() != eSymbolTypeInvalid)<br>
+ {<br>
+ matching_symbol = symbol;<br>
+ return false; // Stop iterating<br>
+ }<br>
+ return true; // Keep iterating<br>
+ });<br>
+ sc.symbol = matching_symbol;<br>
if (!sc.symbol &&<br>
resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction))<br>
{<br>
<br>
Modified: lldb/trunk/source/Symbol/Symtab.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=258621&r1=258620&r2=258621&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symtab.cpp?rev=258621&r1=258620&r2=258621&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/Symtab.cpp (original)<br>
+++ lldb/trunk/source/Symbol/Symtab.cpp Sat Jan 23 04:36:06 2016<br>
@@ -1074,6 +1074,26 @@ Symtab::FindSymbolContainingFileAddress<br>
}<br>
<br>
void<br>
+Symtab::ForEachSymbolContainingFileAddresss (addr_t file_addr, std::function <bool(Symbol *)> const &callback)<br>
+{<br>
+ Mutex::Locker locker (m_mutex);<br>
+<br>
+ if (!m_file_addr_to_index_computed)<br>
+ InitAddressIndexes();<br>
+<br>
+ std::vector<uint32_t> all_addr_indexes;<br>
+<br>
+ // Get all symbols with file_addr<br>
+ const size_t addr_match_count = m_file_addr_to_index.FindEntryIndexesThatContains(file_addr, all_addr_indexes);<br>
+<br>
+ for (size_t i=0; i<addr_match_count; ++i)<br>
+ {<br>
+ if (!callback(SymbolAtIndex(all_addr_indexes[i])))<br>
+ break;<br>
+ }<br>
+}<br>
+<br>
+void<br>
Symtab::SymbolIndicesToSymbolContextList (std::vector<uint32_t> &symbol_indexes, SymbolContextList &sc_list)<br>
{<br>
// No need to protect this call using m_mutex all other method calls are<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>