[Lldb-commits] [lldb] r156835 - in /lldb/trunk/source: Commands/CommandObjectTarget.cpp Core/Address.cpp Symbol/Symbol.cpp

Greg Clayton gclayton at apple.com
Tue May 15 11:43:44 PDT 2012


Author: gclayton
Date: Tue May 15 13:43:44 2012
New Revision: 156835

URL: http://llvm.org/viewvc/llvm-project?rev=156835&view=rev
Log:
<rdar://problem/11455398>

Add "--name" option to "image lookup" that will search both functions and symbols.

Also made all of the output from any of the "image lookup" commands be the same regardless of the lookup type (function name, symbol name, func or symbol, file and line, address, etc). The --verbose or -v option also will expand the results as needed and display things so they look the same.


Modified:
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Core/Address.cpp
    lldb/trunk/source/Symbol/Symbol.cpp

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=156835&r1=156834&r2=156835&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Tue May 15 13:43:44 2012
@@ -1361,6 +1361,29 @@
     return false;
 }
 
+static void
+DumpAddress (ExecutionContextScope *exe_scope, const Address &so_addr, bool verbose, Stream &strm)
+{
+    strm.IndentMore();
+    strm.Indent ("    Address: ");
+    so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
+    strm.PutCString (" (");
+    so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
+    strm.PutCString (")\n");
+    strm.Indent ("    Summary: ");
+    const uint32_t save_indent = strm.GetIndentLevel ();
+    strm.SetIndentLevel (save_indent + 13);
+    so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
+    strm.SetIndentLevel (save_indent);
+    // Print out detailed address information when verbose is enabled
+    if (verbose)
+    {
+        strm.EOL();
+        so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
+    }
+    strm.IndentLess();
+}
+
 static bool
 LookupAddressInModule (CommandInterpreter &interpreter, 
                        Stream &strm, 
@@ -1390,24 +1413,25 @@
         }
         
         ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
-        strm.IndentMore();
-        strm.Indent ("    Address: ");
-        so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
-        strm.PutCString (" (");
-        so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
-        strm.PutCString (")\n");
-        strm.Indent ("    Summary: ");
-        const uint32_t save_indent = strm.GetIndentLevel ();
-        strm.SetIndentLevel (save_indent + 13);
-        so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
-        strm.SetIndentLevel (save_indent);
-        // Print out detailed address information when verbose is enabled
-        if (verbose)
-        {
-            strm.EOL();
-            so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
-        }
-        strm.IndentLess();
+        DumpAddress (exe_scope, so_addr, verbose, strm);
+//        strm.IndentMore();
+//        strm.Indent ("    Address: ");
+//        so_addr.Dump (&strm, exe_scope, Address::DumpStyleModuleWithFileAddress);
+//        strm.PutCString (" (");
+//        so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
+//        strm.PutCString (")\n");
+//        strm.Indent ("    Summary: ");
+//        const uint32_t save_indent = strm.GetIndentLevel ();
+//        strm.SetIndentLevel (save_indent + 13);
+//        so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
+//        strm.SetIndentLevel (save_indent);
+//        // Print out detailed address information when verbose is enabled
+//        if (verbose)
+//        {
+//            strm.EOL();
+//            so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext);
+//        }
+//        strm.IndentLess();
         return true;
     }
     
@@ -1415,7 +1439,7 @@
 }
 
 static uint32_t
-LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex)
+LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool verbose)
 {
     if (module)
     {
@@ -1452,12 +1476,17 @@
                     DumpFullpath (strm, &module->GetFileSpec(), 0);
                     strm.PutCString(":\n");
                     strm.IndentMore ();
-                    Symtab::DumpSymbolHeader (&strm);
+                    //Symtab::DumpSymbolHeader (&strm);
                     for (i=0; i < num_matches; ++i)
                     {
                         Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]);
-                        strm.Indent ();
-                        symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i);
+                        DumpAddress (interpreter.GetExecutionContext().GetBestExecutionContextScope(),
+                                     symbol->GetAddress(),
+                                     verbose,
+                                     strm);
+
+//                        strm.Indent ();
+//                        symbol->Dump (&strm, interpreter.GetExecutionContext().GetTargetPtr(), i);
                     }
                     strm.IndentLess ();
                     return num_matches;
@@ -1470,7 +1499,7 @@
 
 
 static void
-DumpSymbolContextList (CommandInterpreter &interpreter, Stream &strm, SymbolContextList &sc_list, bool prepend_addr, bool verbose)
+DumpSymbolContextList (ExecutionContextScope *exe_scope, Stream &strm, SymbolContextList &sc_list, bool verbose)
 {
     strm.IndentMore ();
     uint32_t i;
@@ -1481,21 +1510,6 @@
         SymbolContext sc;
         if (sc_list.GetContextAtIndex(i, sc))
         {
-            strm.Indent();
-            ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope ();
-            
-            if (prepend_addr)
-            {
-                if (sc.line_entry.range.GetBaseAddress().IsValid())
-                {
-                    sc.line_entry.range.GetBaseAddress().Dump (&strm, 
-                                                               exe_scope,
-                                                               Address::DumpStyleLoadAddress, 
-                                                               Address::DumpStyleModuleWithFileAddress);
-                    strm.PutCString(" in ");
-                }
-            }
-            
             AddressRange range;
             
             sc.GetAddressRange(eSymbolContextEverything, 
@@ -1503,43 +1517,25 @@
                                true, 
                                range);
             
-            sc.DumpStopContext(&strm, 
-                               exe_scope, 
-                               range.GetBaseAddress(), 
-                               true, 
-                               true, 
-                               false);
-
-            strm.EOL();
-            if (verbose)
-            {
-                if (sc.line_entry.range.GetBaseAddress().IsValid())
-                {
-                    if (sc.line_entry.range.GetBaseAddress().Dump (&strm, 
-                                                                   exe_scope, 
-                                                                   Address::DumpStyleDetailedSymbolContext))
-                        strm.PutCString("\n\n");
-                }
-                else if (sc.function->GetAddressRange().GetBaseAddress().IsValid())
-                {
-                    if (sc.function->GetAddressRange().GetBaseAddress().Dump (&strm, 
-                                                                              exe_scope, 
-                                                                              Address::DumpStyleDetailedSymbolContext))
-                        strm.PutCString("\n\n");
-                }
-            }
+            DumpAddress (exe_scope, range.GetBaseAddress(), verbose, strm);
         }
     }
     strm.IndentLess ();
 }
 
 static uint32_t
-LookupFunctionInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex, bool include_inlines, bool verbose)
+LookupFunctionInModule (CommandInterpreter &interpreter,
+                        Stream &strm,
+                        Module *module,
+                        const char *name,
+                        bool name_is_regex,
+                        bool include_inlines,
+                        bool include_symbols,
+                        bool verbose)
 {
     if (module && name && name[0])
     {
         SymbolContextList sc_list;
-        const bool include_symbols = false;
         const bool append = true;
         uint32_t num_matches = 0;
         if (name_is_regex)
@@ -1569,7 +1565,7 @@
             strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : "");
             DumpFullpath (strm, &module->GetFileSpec(), 0);
             strm.PutCString(":\n");
-            DumpSymbolContextList (interpreter, strm, sc_list, true, verbose);
+            DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
         }
         return num_matches;
     }
@@ -1643,7 +1639,7 @@
             strm << " in ";
             DumpFullpath (strm, &module->GetFileSpec(), 0);
             strm.PutCString(":\n");
-            DumpSymbolContextList (interpreter, strm, sc_list, true, verbose);
+            DumpSymbolContextList (interpreter.GetExecutionContext().GetBestExecutionContextScope(), strm, sc_list, verbose);
             return num_matches;
         }
     }
@@ -2837,13 +2833,43 @@
                 return result.Succeeded();
             }
             
-            if (use_global_module_list)
+            ModuleList module_list;
+            ModuleList *module_list_ptr = NULL;
+            const size_t argc = command.GetArgumentCount();
+            if (argc == 0)
             {
-                locker.Lock (Module::GetAllocationModuleCollectionMutex());
-                num_modules = Module::GetNumberAllocatedModules();
+                if (use_global_module_list)
+                {
+                    locker.Lock (Module::GetAllocationModuleCollectionMutex());
+                    num_modules = Module::GetNumberAllocatedModules();
+                }
+                else
+                {
+                    module_list_ptr = &target->GetImages();
+                    num_modules = target->GetImages().GetSize();
+                }
             }
             else
-                num_modules = target->GetImages().GetSize();
+            {
+                for (size_t i=0; i<argc; ++i)
+                {
+                    // Dump specified images (by basename or fullpath)
+                    const char *arg_cstr = command.GetArgumentAtIndex(i);
+                    const size_t num_matches = FindModulesByName (target, arg_cstr, module_list, use_global_module_list);
+                    if (num_matches == 0)
+                    {
+                        if (argc == 1)
+                        {
+                            result.AppendErrorWithFormat ("no modules found that match '%s'", arg_cstr);
+                            result.SetStatus (eReturnStatusFailed);
+                            return false;
+                        }
+                    }
+                }
+                
+                num_modules = module_list.GetSize();
+                module_list_ptr = &module_list;
+            }
 
             if (num_modules > 0)
             {                
@@ -2851,15 +2877,15 @@
                 {
                     ModuleSP module_sp;
                     Module *module;
-                    if (use_global_module_list)
+                    if (module_list_ptr)
                     {
-                        module = Module::GetAllocatedModuleAtIndex(image_idx);
-                        module_sp = module->shared_from_this();
+                        module_sp = module_list_ptr->GetModuleAtIndex(image_idx);
+                        module = module_sp.get();
                     }
                     else
                     {
-                        module_sp = target->GetImages().GetModuleAtIndex(image_idx);
-                        module = module_sp.get();
+                        module = Module::GetAllocatedModuleAtIndex(image_idx);
+                        module_sp = module->shared_from_this();
                     }
                     
                     int indent = strm.Printf("[%3u] ", image_idx);
@@ -2870,10 +2896,20 @@
             }
             else
             {
-                if (use_global_module_list)
-                    result.AppendError ("the global module list is empty");
+                if (argc)
+                {
+                    if (use_global_module_list)
+                        result.AppendError ("the global module list has no matching modules");
+                    else
+                        result.AppendError ("the target has no matching modules");
+                }
                 else
-                    result.AppendError ("the target has no associated executable images");
+                {
+                    if (use_global_module_list)
+                        result.AppendError ("the global module list is empty");
+                    else
+                        result.AppendError ("the target has no associated executable images");
+                }
                 result.SetStatus (eReturnStatusFailed);
                 return false;
             }
@@ -3081,6 +3117,7 @@
         eLookupTypeSymbol,
         eLookupTypeFileLine,    // Line is optional
         eLookupTypeFunction,
+        eLookupTypeFunctionOrSymbol,
         eLookupTypeType,
         kNumLookupTypes
     };
@@ -3145,11 +3182,16 @@
                     m_type = eLookupTypeFileLine;
                     break;
                     
-                case 'n':
+                case 'F':
                     m_str = option_arg;
                     m_type = eLookupTypeFunction;
                     break;
-                    
+                
+                case 'n':
+                    m_str = option_arg;
+                    m_type = eLookupTypeFunctionOrSymbol;
+                    break;
+
                 case 't':
                     m_str = option_arg;
                     m_type = eLookupTypeType;
@@ -3260,7 +3302,12 @@
             case eLookupTypeSymbol:
                 if (!m_options.m_str.empty())
                 {
-                    if (LookupSymbolInModule (m_interpreter, result.GetOutputStream(), module, m_options.m_str.c_str(), m_options.m_use_regex))
+                    if (LookupSymbolInModule (m_interpreter,
+                                              result.GetOutputStream(),
+                                              module,
+                                              m_options.m_str.c_str(),
+                                              m_options.m_use_regex,
+                                              m_options.m_verbose))
                     {
                         result.SetStatus(eReturnStatusSuccessFinishResult);
                         return true;
@@ -3285,7 +3332,8 @@
                     }
                 }
                 break;
-                
+
+            case eLookupTypeFunctionOrSymbol:
             case eLookupTypeFunction:
                 if (!m_options.m_str.empty())
                 {
@@ -3295,6 +3343,7 @@
                                                 m_options.m_str.c_str(),
                                                 m_options.m_use_regex,
                                                 m_options.m_include_inlines,
+                                                m_options.m_type == eLookupTypeFunctionOrSymbol, // include symbols
                                                 m_options.m_verbose))
                     {
                         result.SetStatus(eReturnStatusSuccessFinishResult);
@@ -3303,6 +3352,7 @@
                 }
                 break;
                 
+                
             case eLookupTypeType:
                 if (!m_options.m_str.empty())
                 {
@@ -3416,18 +3466,19 @@
 {
     { LLDB_OPT_SET_1,   true,  "address",    'a', required_argument, NULL, 0, eArgTypeAddress,      "Lookup an address in one or more target modules."},
     { LLDB_OPT_SET_1,   false, "offset",     'o', required_argument, NULL, 0, eArgTypeOffset,       "When looking up an address subtract <offset> from any addresses before doing the lookup."},
-    { LLDB_OPT_SET_2| LLDB_OPT_SET_4  
-      /* FIXME: re-enable this for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_5 */ ,
+    { LLDB_OPT_SET_2| LLDB_OPT_SET_4 | LLDB_OPT_SET_5
+      /* FIXME: re-enable this for types when the LookupTypeInModule actually uses the regex option: | LLDB_OPT_SET_6 */ ,
                         false, "regex",      'r', no_argument,       NULL, 0, eArgTypeNone,         "The <name> argument for name lookups are regular expressions."},
     { LLDB_OPT_SET_2,   true,  "symbol",     's', required_argument, NULL, 0, eArgTypeSymbol,       "Lookup a symbol by name in the symbol tables in one or more target modules."},
     { LLDB_OPT_SET_3,   true,  "file",       'f', required_argument, NULL, 0, eArgTypeFilename,     "Lookup a file by fullpath or basename in one or more target modules."},
     { LLDB_OPT_SET_3,   false, "line",       'l', required_argument, NULL, 0, eArgTypeLineNum,      "Lookup a line number in a file (must be used in conjunction with --file)."},
     { LLDB_OPT_SET_3|
       LLDB_OPT_SET_4,   false, "no-inlines", 'i', no_argument,       NULL, 0, eArgTypeNone,         "Ignore inline entries (must be used in conjunction with --file or --function)."},
-    { LLDB_OPT_SET_4,   true,  "function",   'n', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules."},
-    { LLDB_OPT_SET_5,   true,  "type",       't', required_argument, NULL, 0, eArgTypeName,         "Lookup a type by name in the debug symbols in one or more target modules."},
+    { LLDB_OPT_SET_4,   true,  "function",   'F', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more target modules."},
+    { LLDB_OPT_SET_5,   true,  "name",       'n', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function or symbol by name in one or more target modules."},
+    { LLDB_OPT_SET_6,   true,  "type",       't', required_argument, NULL, 0, eArgTypeName,         "Lookup a type by name in the debug symbols in one or more target modules."},
     { LLDB_OPT_SET_ALL, false, "verbose",    'v', no_argument,       NULL, 0, eArgTypeNone,         "Enable verbose lookup information."},
-    { 0, false, NULL,           0, 0,                 NULL, 0, eArgTypeNone, NULL }
+    { 0,                false, NULL,           0, 0,                 NULL, 0, eArgTypeNone, NULL }
 };
 
 

Modified: lldb/trunk/source/Core/Address.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Address.cpp?rev=156835&r1=156834&r2=156835&view=diff
==============================================================================
--- lldb/trunk/source/Core/Address.cpp (original)
+++ lldb/trunk/source/Core/Address.cpp Tue May 15 13:43:44 2012
@@ -707,7 +707,8 @@
                         Variable *var = variable_list.GetVariableAtIndex (var_idx).get();
                         if (var && var->LocationIsValidForAddress (*this))
                         {
-                            s->Printf ("     Variable: id = {0x%8.8llx}, name = \"%s\", type= \"%s\", location =",
+                            s->Indent();
+                            s->Printf ("   Variable: id = {0x%8.8llx}, name = \"%s\", type= \"%s\", location =",
                                        var->GetID(),
                                        var->GetName().GetCString(),
                                        var->GetType()->GetName().GetCString());

Modified: lldb/trunk/source/Symbol/Symbol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Symbol.cpp?rev=156835&r1=156834&r2=156835&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Symbol.cpp (original)
+++ lldb/trunk/source/Symbol/Symbol.cpp Tue May 15 13:43:44 2012
@@ -179,7 +179,7 @@
 void
 Symbol::GetDescription (Stream *s, lldb::DescriptionLevel level, Target *target) const
 {
-    s->Printf("uid={%6u}", m_uid);
+    s->Printf("id = {0x%8.8x}", m_uid);
     
     if (m_addr_range.GetBaseAddress().GetSection())
     {





More information about the lldb-commits mailing list