<div dir="ltr">Hi Sean,<div><br></div><div>On Linux with i386 inferiors,</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>range.GetBaseAddress().GetCallableLoadAddress(target);</div></blockquote><div>returns the wrong load address for strlen, while</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>candidate_sc.symbol->ResolveCallableAddress(*target);</div></blockquote><div>returns the correct load address.</div><div><br></div><div>This is causing TestCStrings to fail on our bot: <a href="http://lab.llvm.org:8011/builders/lldb-x86_64-ubuntu-14.04-cmake/builds/11726" target="_blank">http://lab.llvm.org:8011/builders/lldb-x86_64-ubuntu-14.04-cmake/builds/11726</a></div><div><br></div><div>Do you know why this might be happening?</div><div><br></div><div>May I revert back to using</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>candidate_sc.symbol->ResolveCallableAddress(*target);</div></blockquote>and<div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>candidate_sc.symbol->GetAddress().GetLoadAddress(target);<br></div></blockquote>while you look into it?<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Feb 23, 2016 at 3:13 PM Sean Callanan via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: spyffe<br>
Date: Tue Feb 23 17:09:06 2016<br>
New Revision: 261704<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=261704&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=261704&view=rev</a><br>
Log:<br>
When looking for symbols, find load addresses in a more robust way.<br>
<br>
IRExecutionUnit previously replicated a bunch of logic that already<br>
existed elsewhere for the purpose of getting a load address for a<br>
symbol. This approach failed to resolve certain types of symbols.<br>
Instead, we now use functions on SymbolContext to do the address<br>
resolution.<br>
<br>
This is a cleanup of IRExecutionUnit::FindInSymbols, and also fixes a<br>
latent bug where we looked at the wrong SymbolContext to determine<br>
whether or not it is external.<br>
<br>
<rdar://problem/24770829><br>
<br>
Modified:<br>
lldb/trunk/source/Expression/IRExecutionUnit.cpp<br>
<br>
Modified: lldb/trunk/source/Expression/IRExecutionUnit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRExecutionUnit.cpp?rev=261704&r1=261703&r2=261704&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRExecutionUnit.cpp?rev=261704&r1=261703&r2=261704&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Expression/IRExecutionUnit.cpp (original)<br>
+++ lldb/trunk/source/Expression/IRExecutionUnit.cpp Tue Feb 23 17:09:06 2016<br>
@@ -769,9 +769,62 @@ IRExecutionUnit::CollectCandidateCPlusPl<br>
lldb::addr_t<br>
IRExecutionUnit::FindInSymbols(const std::vector<IRExecutionUnit::SearchSpec> &specs, const lldb_private::SymbolContext &sc)<br>
{<br>
+ Target *target = sc.target_sp.get();<br>
+<br>
+ if (!target)<br>
+ {<br>
+ // we shouldn't be doing any symbol lookup at all without a target<br>
+ return LLDB_INVALID_ADDRESS;<br>
+ }<br>
+<br>
for (const SearchSpec &spec : specs)<br>
{<br>
SymbolContextList sc_list;<br>
+<br>
+ lldb::addr_t best_internal_load_address = LLDB_INVALID_ADDRESS;<br>
+<br>
+ std::function<bool (lldb::addr_t &, SymbolContextList &, const lldb_private::SymbolContext &)> get_external_load_address =<br>
+ [&best_internal_load_address, target](lldb::addr_t &load_address,<br>
+ SymbolContextList &sc_list,<br>
+ const lldb_private::SymbolContext &sc) -> lldb::addr_t<br>
+ {<br>
+ load_address = LLDB_INVALID_ADDRESS;<br>
+<br>
+ for (size_t si = 0, se = sc_list.GetSize(); si < se; ++si)<br>
+ {<br>
+ SymbolContext candidate_sc;<br>
+<br>
+ sc_list.GetContextAtIndex(si, candidate_sc);<br>
+<br>
+ const bool is_external = (candidate_sc.function) ||<br>
+ (candidate_sc.symbol && candidate_sc.symbol->IsExternal());<br>
+<br>
+ AddressRange range;<br>
+<br>
+ if (candidate_sc.GetAddressRange(lldb::eSymbolContextFunction | lldb::eSymbolContextSymbol,<br>
+ 0,<br>
+ false,<br>
+ range))<br>
+ {<br>
+ load_address = range.GetBaseAddress().GetCallableLoadAddress(target);<br>
+<br>
+ if (load_address != LLDB_INVALID_ADDRESS)<br>
+ {<br>
+ if (is_external)<br>
+ {<br>
+ return true;<br>
+ }<br>
+ else if (best_internal_load_address == LLDB_INVALID_ADDRESS)<br>
+ {<br>
+ best_internal_load_address = load_address;<br>
+ load_address = LLDB_INVALID_ADDRESS;<br>
+ }<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ return false;<br>
+ };<br>
<br>
if (sc.module_sp)<br>
{<br>
@@ -783,6 +836,17 @@ IRExecutionUnit::FindInSymbols(const std<br>
true, // append<br>
sc_list);<br>
}<br>
+<br>
+ lldb::addr_t load_address = LLDB_INVALID_ADDRESS;<br>
+<br>
+ if (get_external_load_address(load_address, sc_list, sc))<br>
+ {<br>
+ return load_address;<br>
+ }<br>
+ else<br>
+ {<br>
+ sc_list.Clear();<br>
+ }<br>
<br>
if (sc_list.GetSize() == 0 && sc.target_sp)<br>
{<br>
@@ -794,49 +858,26 @@ IRExecutionUnit::FindInSymbols(const std<br>
sc_list);<br>
}<br>
<br>
+ if (get_external_load_address(load_address, sc_list, sc))<br>
+ {<br>
+ return load_address;<br>
+ }<br>
+ else<br>
+ {<br>
+ sc_list.Clear();<br>
+ }<br>
+<br>
if (sc_list.GetSize() == 0 && sc.target_sp)<br>
{<br>
sc.target_sp->GetImages().FindSymbolsWithNameAndType(<a href="http://spec.name" rel="noreferrer" target="_blank">spec.name</a>, lldb::eSymbolTypeAny, sc_list);<br>
}<br>
<br>
- lldb::addr_t best_internal_load_address = LLDB_INVALID_ADDRESS;<br>
-<br>
- for (size_t si = 0, se = sc_list.GetSize(); si < se; ++si)<br>
+ if (get_external_load_address(load_address, sc_list, sc))<br>
{<br>
- bool is_external = false;<br>
-<br>
- SymbolContext candidate_sc;<br>
-<br>
- sc_list.GetContextAtIndex(si, candidate_sc);<br>
- if (candidate_sc.function)<br>
- {<br>
- is_external = true;<br>
- }<br>
- else if (sc.symbol)<br>
- {<br>
- if (sc.symbol->IsExternal())<br>
- {<br>
- is_external = true;<br>
- }<br>
- }<br>
-<br>
- lldb::addr_t load_address = candidate_sc.symbol->ResolveCallableAddress(*sc.target_sp);<br>
-<br>
- if (load_address == LLDB_INVALID_ADDRESS)<br>
- load_address = candidate_sc.symbol->GetAddress().GetLoadAddress(sc.target_sp.get());<br>
-<br>
- if (load_address != LLDB_INVALID_ADDRESS)<br>
- {<br>
- if (is_external)<br>
- {<br>
- return load_address;<br>
- }<br>
- else<br>
- {<br>
- best_internal_load_address = load_address;<br>
- }<br>
- }<br>
+ return load_address;<br>
}<br>
+ // if there are any searches we try after this, add an sc_list.Clear() in an "else" clause here<br>
+<br>
if (best_internal_load_address != LLDB_INVALID_ADDRESS)<br>
{<br>
return best_internal_load_address;<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></div></div>