[Lldb-commits] [lldb] r186104 - Fix "source list -n printf" on Linux (printf is symbol alias for __printf)

Michael Sartain mikesart at valvesoftware.com
Thu Jul 11 09:40:56 PDT 2013


Author: mikesart
Date: Thu Jul 11 11:40:56 2013
New Revision: 186104

URL: http://llvm.org/viewvc/llvm-project?rev=186104&view=rev
Log:
Fix "source list -n printf" on Linux (printf is symbol alias for __printf)

Differential Revision: http://llvm-reviews.chandlerc.com/D1109

Modified:
    lldb/trunk/include/lldb/Core/ModuleList.h
    lldb/trunk/source/Commands/CommandObjectSource.cpp
    lldb/trunk/source/Core/ModuleList.cpp
    lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp

Modified: lldb/trunk/include/lldb/Core/ModuleList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ModuleList.h?rev=186104&r1=186103&r2=186104&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/ModuleList.h (original)
+++ lldb/trunk/include/lldb/Core/ModuleList.h Thu Jul 11 11:40:56 2013
@@ -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

Modified: lldb/trunk/source/Commands/CommandObjectSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectSource.cpp?rev=186104&r1=186103&r2=186104&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectSource.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectSource.cpp Thu Jul 11 11:40:56 2013
@@ -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)
-            {
-                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)
+            // Displaying the source for a symbol. Search for function named name.
+            size_t num_matches = FindMatchingFunctions (target, name, sc_list);
+            if (!num_matches)
+            {
+                // 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++)
+                {
+                    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)
                     {

Modified: lldb/trunk/source/Core/ModuleList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ModuleList.cpp?rev=186104&r1=186103&r2=186104&view=diff
==============================================================================
--- lldb/trunk/source/Core/ModuleList.cpp (original)
+++ lldb/trunk/source/Core/ModuleList.cpp Thu Jul 11 11:40:56 2013
@@ -386,7 +386,6 @@ ModuleList::FindFunctions (const ConstSt
     }
     else
     {
-    
         Mutex::Locker locker(m_modules_mutex);
         collection::const_iterator pos, end = m_modules.end();
         for (pos = m_modules.begin(); pos != end; ++pos)
@@ -397,6 +396,67 @@ ModuleList::FindFunctions (const ConstSt
     return sc_list.GetSize() - old_size;
 }
 
+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, 

Modified: lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp?rev=186104&r1=186103&r2=186104&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp (original)
+++ lldb/trunk/source/Plugins/Disassembler/llvm/DisassemblerLLVMC.cpp Thu Jul 11 11:40:56 2013
@@ -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();





More information about the lldb-commits mailing list