diff options
author | Michael Sartain <mikesart@valvesoftware.com> | 2013-07-11 16:40:56 +0000 |
---|---|---|
committer | Michael Sartain <mikesart@valvesoftware.com> | 2013-07-11 16:40:56 +0000 |
commit | cc791bbfab548d302e8e9584c8e532e8f596dd31 (patch) | |
tree | f228620c2b21b63afd309614b28c960915594023 | |
parent | 29e787d45651294f3658e6e02bda15504bdffe6c (diff) | |
download | bcm5719-llvm-cc791bbfab548d302e8e9584c8e532e8f596dd31.tar.gz bcm5719-llvm-cc791bbfab548d302e8e9584c8e532e8f596dd31.zip |
Fix "source list -n printf" on Linux (printf is symbol alias for __printf)
Differential Revision: http://llvm-reviews.chandlerc.com/D1109
llvm-svn: 186104
-rw-r--r-- | lldb/include/lldb/Core/ModuleList.h | 8 | ||||
-rw-r--r-- | lldb/source/Commands/CommandObjectSource.cpp | 124 | ||||
-rw-r--r-- | lldb/source/Core/ModuleList.cpp | 62 | ||||
-rw-r--r-- | lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp | 2 |
4 files changed, 166 insertions, 30 deletions
diff --git a/lldb/include/lldb/Core/ModuleList.h b/lldb/include/lldb/Core/ModuleList.h index 8da07cba9ca..1198e419648 100644 --- a/lldb/include/lldb/Core/ModuleList.h +++ b/lldb/include/lldb/Core/ModuleList.h @@ -270,6 +270,14 @@ public: SymbolContextList &sc_list) const; //------------------------------------------------------------------ + /// @see Module::FindFunctionSymbols () + //------------------------------------------------------------------ + size_t + FindFunctionSymbols (const ConstString &name, + uint32_t name_type_mask, + SymbolContextList& sc_list); + + //------------------------------------------------------------------ /// Find global and static variables by name. /// /// @param[in] name diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp index df20ea10a48..a08e39352b3 100644 --- a/lldb/source/Commands/CommandObjectSource.cpp +++ b/lldb/source/Commands/CommandObjectSource.cpp @@ -26,6 +26,7 @@ #include "lldb/Host/FileSpec.h" #include "lldb/Symbol/CompileUnit.h" #include "lldb/Symbol/Function.h" +#include "lldb/Symbol/Symbol.h" #include "lldb/Target/Process.h" #include "lldb/Target/TargetList.h" #include "lldb/Interpreter/CommandCompletions.h" @@ -439,6 +440,73 @@ protected: return 0; } + // From Jim: The FindMatchingFunctions / FindMatchingFunctionSymbols functions + // "take a possibly empty vector of strings which are names of modules, and + // run the two search functions on the subset of the full module list that + // matches the strings in the input vector". If we wanted to put these somewhere, + // there should probably be a module-filter-list that can be passed to the + // various ModuleList::Find* calls, which would either be a vector of string + // names or a ModuleSpecList. + size_t FindMatchingFunctions (Target *target, const ConstString &name, SymbolContextList& sc_list) + { + // Displaying the source for a symbol: + bool include_inlines = true; + bool append = true; + bool include_symbols = false; + size_t num_matches = 0; + + if (m_options.num_lines == 0) + m_options.num_lines = 10; + + const size_t num_modules = m_options.modules.size(); + if (num_modules > 0) + { + ModuleList matching_modules; + for (size_t i = 0; i < num_modules; ++i) + { + FileSpec module_file_spec(m_options.modules[i].c_str(), false); + if (module_file_spec) + { + ModuleSpec module_spec (module_file_spec); + matching_modules.Clear(); + target->GetImages().FindModules (module_spec, matching_modules); + num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); + } + } + } + else + { + num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); + } + return num_matches; + } + + size_t FindMatchingFunctionSymbols (Target *target, const ConstString &name, SymbolContextList& sc_list) + { + size_t num_matches = 0; + const size_t num_modules = m_options.modules.size(); + if (num_modules > 0) + { + ModuleList matching_modules; + for (size_t i = 0; i < num_modules; ++i) + { + FileSpec module_file_spec(m_options.modules[i].c_str(), false); + if (module_file_spec) + { + ModuleSpec module_spec (module_file_spec); + matching_modules.Clear(); + target->GetImages().FindModules (module_spec, matching_modules); + num_matches += matching_modules.FindFunctionSymbols (name, eFunctionNameTypeAuto, sc_list); + } + } + } + else + { + num_matches = target->GetImages().FindFunctionSymbols (name, eFunctionNameTypeAuto, sc_list); + } + return num_matches; + } + bool DoExecute (Args& command, CommandReturnObject &result) { @@ -453,41 +521,36 @@ protected: Target *target = m_exe_ctx.GetTargetPtr(); - SymbolContextList sc_list; if (!m_options.symbol_name.empty()) { - // Displaying the source for a symbol: + SymbolContextList sc_list; ConstString name(m_options.symbol_name.c_str()); - bool include_symbols = false; - bool include_inlines = true; - bool append = true; - size_t num_matches = 0; - - if (m_options.num_lines == 0) - m_options.num_lines = 10; - const size_t num_modules = m_options.modules.size(); - if (num_modules > 0) + // Displaying the source for a symbol. Search for function named name. + size_t num_matches = FindMatchingFunctions (target, name, sc_list); + if (!num_matches) { - ModuleList matching_modules; - for (size_t i = 0; i < num_modules; ++i) + // If we didn't find any functions with that name, try searching for symbols + // that line up exactly with function addresses. + SymbolContextList sc_list_symbols; + size_t num_symbol_matches = FindMatchingFunctionSymbols (target, name, sc_list_symbols); + for (size_t i = 0; i < num_symbol_matches; i++) { - FileSpec module_file_spec(m_options.modules[i].c_str(), false); - if (module_file_spec) + SymbolContext sc; + sc_list_symbols.GetContextAtIndex (i, sc); + if (sc.symbol) { - ModuleSpec module_spec (module_file_spec); - matching_modules.Clear(); - target->GetImages().FindModules (module_spec, matching_modules); - num_matches += matching_modules.FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); + const Address &base_address = sc.symbol->GetAddress(); + Function *function = base_address.CalculateSymbolContextFunction(); + if (function) + { + sc_list.Append (SymbolContext(function)); + num_matches++; + break; + } } } } - else - { - num_matches = target->GetImages().FindFunctions (name, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); - } - - SymbolContext sc; if (num_matches == 0) { @@ -495,7 +558,7 @@ protected: result.SetStatus (eReturnStatusFailed); return false; } - + if (num_matches > 1) { std::set<SourceInfo> source_match_set; @@ -503,6 +566,7 @@ protected: bool displayed_something = false; for (size_t i = 0; i < num_matches; i++) { + SymbolContext sc; sc_list.GetContextAtIndex (i, sc); SourceInfo source_info (sc.GetFunctionName(), sc.GetFunctionStartLineEntry()); @@ -525,6 +589,7 @@ protected: } else { + SymbolContext sc; sc_list.GetContextAtIndex (0, sc); SourceInfo source_info; @@ -541,9 +606,9 @@ protected: } else if (m_options.address != LLDB_INVALID_ADDRESS) { - SymbolContext sc; Address so_addr; StreamString error_strm; + SymbolContextList sc_list; if (target->GetSectionLoadList().IsEmpty()) { @@ -556,6 +621,7 @@ protected: ModuleSP module_sp (module_list.GetModuleAtIndex(i)); if (module_sp && module_sp->ResolveFileAddress(m_options.address, so_addr)) { + SymbolContext sc; sc.Clear(true); if (module_sp->ResolveSymbolContextForAddress (so_addr, eSymbolContextEverything, sc) & eSymbolContextLineEntry) sc_list.Append(sc); @@ -579,6 +645,7 @@ protected: ModuleSP module_sp (so_addr.GetModule()); if (module_sp) { + SymbolContext sc; sc.Clear(true); if (module_sp->ResolveSymbolContextForAddress (so_addr, eSymbolContextEverything, sc) & eSymbolContextLineEntry) { @@ -605,6 +672,7 @@ protected: uint32_t num_matches = sc_list.GetSize(); for (uint32_t i=0; i<num_matches; ++i) { + SymbolContext sc; sc_list.GetContextAtIndex(i, sc); if (sc.comp_unit) { @@ -738,12 +806,12 @@ protected: if (num_matches > 1) { - SymbolContext sc; bool got_multiple = false; FileSpec *test_cu_spec = NULL; for (unsigned i = 0; i < num_matches; i++) { + SymbolContext sc; sc_list.GetContextAtIndex(i, sc); if (sc.comp_unit) { diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp index 07b20b8d91e..6c94a501da9 100644 --- a/lldb/source/Core/ModuleList.cpp +++ b/lldb/source/Core/ModuleList.cpp @@ -386,7 +386,6 @@ ModuleList::FindFunctions (const ConstString &name, } else { - Mutex::Locker locker(m_modules_mutex); collection::const_iterator pos, end = m_modules.end(); for (pos = m_modules.begin(); pos != end; ++pos) @@ -398,6 +397,67 @@ ModuleList::FindFunctions (const ConstString &name, } size_t +ModuleList::FindFunctionSymbols (const ConstString &name, + uint32_t name_type_mask, + SymbolContextList& sc_list) +{ + const size_t old_size = sc_list.GetSize(); + + if (name_type_mask & eFunctionNameTypeAuto) + { + ConstString lookup_name; + uint32_t lookup_name_type_mask = 0; + bool match_name_after_lookup = false; + Module::PrepareForFunctionNameLookup (name, name_type_mask, + lookup_name, + lookup_name_type_mask, + match_name_after_lookup); + + Mutex::Locker locker(m_modules_mutex); + collection::const_iterator pos, end = m_modules.end(); + for (pos = m_modules.begin(); pos != end; ++pos) + { + (*pos)->FindFunctionSymbols (lookup_name, + lookup_name_type_mask, + sc_list); + } + + if (match_name_after_lookup) + { + SymbolContext sc; + size_t i = old_size; + while (i<sc_list.GetSize()) + { + if (sc_list.GetContextAtIndex(i, sc)) + { + const char *func_name = sc.GetFunctionName().GetCString(); + if (func_name && strstr (func_name, name.GetCString()) == NULL) + { + // Remove the current context + sc_list.RemoveContextAtIndex(i); + // Don't increment i and continue in the loop + continue; + } + } + ++i; + } + } + + } + else + { + Mutex::Locker locker(m_modules_mutex); + collection::const_iterator pos, end = m_modules.end(); + for (pos = m_modules.begin(); pos != end; ++pos) + { + (*pos)->FindFunctionSymbols (name, name_type_mask, sc_list); + } + } + + return sc_list.GetSize() - old_size; +} + +size_t ModuleList::FindCompileUnits (const FileSpec &path, bool append, SymbolContextList &sc_list) const diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp index 3fe7cd0198b..437860101e0 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp @@ -123,7 +123,7 @@ public: lldb::offset_t data_offset) { // All we have to do is read the opcode which can be easy for some - // architetures + // architectures bool got_op = false; DisassemblerLLVMC &llvm_disasm = GetDisassemblerLLVMC(); const ArchSpec &arch = llvm_disasm.GetArchitecture(); |