<div dir="ltr">"source list -n printf" wasn't working on Linux because printf is a symbol and the code was only searching for functions.<div><br></div><div>The patch now searches for symbols if function searching fails and tries to find a symbol that lines up exactly with a function.</div>
<div><br></div><div>The Linux test suite passes with this patch. Please let me know if it's ok to submit.</div><div> -Mike</div><div><br></div><div><a href="http://llvm-reviews.chandlerc.com/D1107" target="_blank">http://llvm-reviews.chandlerc.com/D1107</a><br>
<div class="gmail_quote">
<br>
Files:<br>
source/Commands/CommandObjectSource.cpp<br>
<br>
Index: source/Commands/CommandObjectSource.cpp<br>
===================================================================<br>
--- source/Commands/CommandObjectSource.cpp<br>
+++ source/Commands/CommandObjectSource.cpp<br>
@@ -26,11 +26,13 @@<br>
#include "lldb/Host/FileSpec.h"<br>
#include "lldb/Symbol/CompileUnit.h"<br>
#include "lldb/Symbol/Function.h"<br>
+#include "lldb/Symbol/Symbol.h"<br>
#include "lldb/Target/Process.h"<br>
#include "lldb/Target/TargetList.h"<br>
#include "lldb/Interpreter/CommandCompletions.h"<br>
#include "lldb/Interpreter/Options.h"<br>
<br>
+<br>
using namespace lldb;<br>
using namespace lldb_private;<br>
<br>
@@ -439,6 +441,39 @@<br>
return 0;<br>
}<br>
<br>
+ size_t FindMatchingFunctions (Target *target, const ConstString &name, Options &options, bool include_symbols, SymbolContextList& sc_list)<br>
+ {<br>
+ // Displaying the source for a symbol:<br>
+ bool include_inlines = true;<br>
+ bool append = false;<br>
+ size_t num_matches = 0;<br>
+<br>
+ if (m_options.num_lines == 0)<br>
+ m_options.num_lines = 10;<br>
+<br>
+ const size_t num_modules = m_options.modules.size();<br>
+ if (num_modules > 0)<br>
+ {<br>
+ ModuleList matching_modules;<br>
+ for (size_t i = 0; i < num_modules; ++i)<br>
+ {<br>
+ FileSpec module_file_spec(m_options.modules[i].c_str(), false);<br>
+ if (module_file_spec)<br>
+ {<br>
+ ModuleSpec module_spec (module_file_spec);<br>
+ matching_modules.Clear();<br>
+ target->GetImages().FindModules (module_spec, matching_modules);<br>
+ num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list);<br>
+ }<br>
+ }<br>
+ }<br>
+ else<br>
+ {<br>
+ num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list);<br>
+ }<br>
+ return num_matches;<br>
+ }<br>
+<br>
bool<br>
DoExecute (Args& command, CommandReturnObject &result)<br>
{<br>
@@ -456,38 +491,36 @@<br>
SymbolContextList sc_list;<br>
if (!m_options.symbol_name.empty())<br>
{<br>
- // Displaying the source for a symbol:<br>
+ SymbolContext sc;<br>
ConstString name(m_options.symbol_name.c_str());<br>
- bool include_symbols = false;<br>
- bool include_inlines = true;<br>
- bool append = true;<br>
- size_t num_matches = 0;<br>
-<br>
- if (m_options.num_lines == 0)<br>
- m_options.num_lines = 10;<br>
<br>
- const size_t num_modules = m_options.modules.size();<br>
- if (num_modules > 0)<br>
- {<br>
- ModuleList matching_modules;<br>
- for (size_t i = 0; i < num_modules; ++i)<br>
+ // Displaying the source for a symbol. Search for function named name.<br>
+ size_t num_matches = FindMatchingFunctions (target, name, m_options, false, sc_list);<br>
+ if (!num_matches)<br>
+ {<br>
+ // If we didn't find any functions with that name, try searching for symbols.<br>
+ size_t num_sym_matches = FindMatchingFunctions (target, name, m_options, true, sc_list);<br>
+ if (num_sym_matches)<br>
{<br>
- FileSpec module_file_spec(m_options.modules[i].c_str(), false);<br>
- if (module_file_spec)<br>
+ // Go through all matching symbols and see if any line up exactly with a function address.<br>
+ for (size_t i = 0; i < num_sym_matches; i++)<br>
{<br>
- ModuleSpec module_spec (module_file_spec);<br>
- matching_modules.Clear();<br>
- target->GetImages().FindModules (module_spec, matching_modules);<br>
- num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list);<br>
+ sc_list.GetContextAtIndex (i, sc);<br>
+ if (sc.symbol)<br>
+ {<br>
+ const Address &base_address = sc.symbol->GetAddress();<br>
+ Function *function = base_address.CalculateSymbolContextFunction();<br>
+ if (function)<br>
+ {<br>
+ sc_list.Clear();<br>
+ sc_list.Append (SymbolContext(function));<br>
+ num_matches = 1;<br>
+ break;<br>
+ }<br>
+ }<br>
}<br>
}<br>
}<br>
- else<br>
- {<br>
- num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list);<br>
- }<br>
-<br>
- SymbolContext sc;<br>
<br>
if (num_matches == 0)<br>
{<br>
</div><br></div></div>