[Lldb-commits] [lldb] r135529 - in /lldb/trunk: include/lldb/Core/FormatManager.h source/Commands/CommandObjectType.cpp

Enrico Granata granata.enrico at gmail.com
Tue Jul 19 15:35:10 PDT 2011


Author: enrico
Date: Tue Jul 19 17:35:10 2011
New Revision: 135529

URL: http://llvm.org/viewvc/llvm-project?rev=135529&view=rev
Log:
type category list now supports a regular expression argument that filters categories to only include the ones matching the regex
type summary list now supports a -w flag with a regular expression argument that filters categories to only include the ones matching the regex
in category and summary listings, categories are printed in a meaningful order:
 - enabled ones first, in the order in which they are searched for summaries
 - disabled ones, in an unspecified order
type summary list by default only expands non-empty enabled categories. to obtain a full listing, you must use the -w flag giving a "match-all" regex

Modified:
    lldb/trunk/include/lldb/Core/FormatManager.h
    lldb/trunk/source/Commands/CommandObjectType.cpp

Modified: lldb/trunk/include/lldb/Core/FormatManager.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatManager.h?rev=135529&r1=135528&r2=135529&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatManager.h (original)
+++ lldb/trunk/include/lldb/Core/FormatManager.h Tue Jul 19 17:35:10 2011
@@ -507,6 +507,12 @@
         return (del_sum || del_rex);
     }
     
+    uint32_t
+    GetCount()
+    {
+        return Summary()->GetCount() + RegexSummary()->GetCount();
+    }
+    
     typedef lldb::SharedPtr<FormatCategory>::Type SharedPointer;
 };
 
@@ -642,18 +648,59 @@
         return true;
     }
     
+    class match_category_to_name
+    {
+    private:
+        FormatCategory* addr;
+    public:
+        
+        match_category_to_name(FormatCategory* ptr) : addr(ptr)
+        {}
+        
+        bool operator()(std::pair<const char*,FormatCategory::SharedPointer> map_entry)
+        {
+            if (addr == map_entry.second.get())
+                return true;
+            return false;
+        }
+    };
+    
     void
     LoopThrough(CallbackType callback, void* param)
     {
         if (callback)
         {
             Mutex::Locker(m_map_mutex);
-            MapIterator pos, end = m_map.end();
-            for (pos = m_map.begin(); pos != end; pos++)
+            
+            // loop through enabled categories in respective order
+            {
+                ActiveCategoriesIterator begin, end = m_active_categories.end();
+                for (begin = m_active_categories.begin(); begin != end; begin++)
+                {
+                    FormatCategory::SharedPointer category = *begin;
+                    const char* type;
+                    MapIterator type_position = 
+                    std::find_if(m_map.begin(),m_map.end(),match_category_to_name(category.get()));
+                    if (type_position != m_map.end())
+                        type = type_position->first;
+                    else
+                        continue;
+                    if (!callback(param, type, category))
+                        break;
+                }
+            }
+            
+            // loop through disabled categories in just any order
             {
-                KeyType type = pos->first;
-                if (!callback(param, type, pos->second))
-                    break;
+                MapIterator pos, end = m_map.end();
+                for (pos = m_map.begin(); pos != end; pos++)
+                {
+                    if (pos->second->IsEnabled())
+                        continue;
+                    KeyType type = pos->first;
+                    if (!callback(param, type, pos->second))
+                        break;
+                }
             }
         }
     }

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=135529&r1=135528&r2=135529&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Tue Jul 19 17:35:10 2011
@@ -1390,18 +1390,82 @@
     CommandObjectTypeSummaryList* self;
     CommandReturnObject* result;
     RegularExpression* regex;
+    RegularExpression* cate_regex;
     CommandObjectTypeSummaryList_LoopCallbackParam(CommandObjectTypeSummaryList* S, CommandReturnObject* R,
-                                                  RegularExpression* X = NULL) : self(S), result(R), regex(X) {}
+                                                  RegularExpression* X = NULL,
+                                                  RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
 };
 
 class CommandObjectTypeSummaryList : public CommandObject
 {
+    
+    class CommandOptions : public Options
+    {
+    public:
+        
+        CommandOptions (CommandInterpreter &interpreter) :
+        Options (interpreter)
+        {
+        }
+        
+        virtual
+        ~CommandOptions (){}
+        
+        virtual Error
+        SetOptionValue (uint32_t option_idx, const char *option_arg)
+        {
+            Error error;
+            char short_option = (char) m_getopt_table[option_idx].val;
+            
+            switch (short_option)
+            {
+                case 'w':
+                    m_category_regex = std::string(option_arg);
+                    break;
+                default:
+                    error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
+                    break;
+            }
+            
+            return error;
+        }
+        
+        void
+        OptionParsingStarting ()
+        {
+            m_category_regex = "";
+        }
+        
+        const OptionDefinition*
+        GetDefinitions ()
+        {
+            return g_option_table;
+        }
+        
+        // Options table: Required for subclasses of Options.
+        
+        static OptionDefinition g_option_table[];
+        
+        // Instance variables to hold the values for command options.
+        
+        std::string m_category_regex;
+        
+    };
+    
+    CommandOptions m_options;
+    
+    virtual Options *
+    GetOptions ()
+    {
+        return &m_options;
+    }
+    
 public:
     CommandObjectTypeSummaryList (CommandInterpreter &interpreter) :
     CommandObject (interpreter,
                    "type summary list",
                    "Show a list of current summary styles.",
-                   NULL)
+                   NULL), m_options(interpreter)
     {
         CommandArgumentEntry type_arg;
         CommandArgumentData type_style_arg;
@@ -1424,14 +1488,17 @@
         const size_t argc = command.GetArgumentCount();
         
         CommandObjectTypeSummaryList_LoopCallbackParam *param;
+        RegularExpression* cate_regex = 
+        m_options.m_category_regex.empty() ? NULL :
+        new RegularExpression(m_options.m_category_regex.c_str());
         
         if (argc == 1) {
             RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
             regex->Compile(command.GetArgumentAtIndex(0));
-            param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex);
+            param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex,cate_regex);
         }
         else
-            param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result);
+            param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,NULL,cate_regex);
         
         Debugger::Formatting::Categories::LoopThrough(PerCategoryCallback,param);
                 
@@ -1449,6 +1516,9 @@
             delete param;
         }
         
+        if (cate_regex)
+            delete cate_regex;
+        
         result.SetStatus(eReturnStatusSuccessFinishResult);
         return result.Succeeded();
     }
@@ -1456,23 +1526,33 @@
 private:
     
     static bool
-    PerCategoryCallback(void* param,
+    PerCategoryCallback(void* param_vp,
                         const char* cate_name,
                         const FormatCategory::SharedPointer& cate)
     {
         
-        CommandReturnObject* result = ((CommandObjectTypeSummaryList_LoopCallbackParam*)param)->result;
-
+        CommandObjectTypeSummaryList_LoopCallbackParam* param = 
+            (CommandObjectTypeSummaryList_LoopCallbackParam*)param_vp;
+        CommandReturnObject* result = param->result;
+        
+        // if the category is disabled or empty and there is no regex, just skip it
+        if ((cate->IsEnabled() == false || cate->GetCount() == 0) && param->cate_regex == NULL)
+            return true;
+        
+        // if we have a regex and this category does not match it, just skip it
+        if(param->cate_regex != NULL && param->cate_regex->Execute(cate_name) == false)
+            return true;
+        
         result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
                                          cate_name,
                                          (cate->IsEnabled() ? "enabled" : "disabled"));
-        
-        cate->Summary()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param);
+                
+        cate->Summary()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
         
         if (cate->RegexSummary()->GetCount() > 0)
         {
             result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
-            cate->RegexSummary()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param);
+            cate->RegexSummary()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param_vp);
         }
         return true;
     }
@@ -1512,6 +1592,13 @@
     return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
 }
 
+OptionDefinition
+CommandObjectTypeSummaryList::CommandOptions::g_option_table[] =
+{
+    { LLDB_OPT_SET_ALL, false, "category-regex", 'w', required_argument, NULL, 0, eArgTypeName,  "Only show categories matching this filter."},
+    { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
+};
+
 //-------------------------------------------------------------------------
 // CommandObjectTypeCategoryEnable
 //-------------------------------------------------------------------------
@@ -1714,13 +1801,33 @@
 class CommandObjectTypeCategoryList : public CommandObject
 {
 private:
+    
+    struct CommandObjectTypeCategoryList_CallbackParam
+    {
+        CommandReturnObject* result;
+        RegularExpression* regex;
+        
+        CommandObjectTypeCategoryList_CallbackParam(CommandReturnObject* res,
+                                                    RegularExpression* rex = NULL) :
+        result(res),
+        regex(rex)
+        {
+        }
+        
+    };
+    
     static bool
-    PerCategoryCallback(void* param,
+    PerCategoryCallback(void* param_vp,
                         const char* cate_name,
                         const FormatCategory::SharedPointer& cate)
     {
-        CommandReturnObject* result = (CommandReturnObject*)param;
-        result->GetOutputStream().Printf("Category %s is%s enabled\n",
+        CommandObjectTypeCategoryList_CallbackParam* param =
+            (CommandObjectTypeCategoryList_CallbackParam*)param_vp;
+        CommandReturnObject* result = param->result;
+        RegularExpression* regex = param->regex;
+        
+        if (regex == NULL || regex->Execute(cate_name))
+            result->GetOutputStream().Printf("Category %s is%s enabled\n",
                                        cate_name,
                                        (cate->IsEnabled() ? "" : " not"));
         return true;
@@ -1732,6 +1839,15 @@
                    "Provide a list of all existing categories.",
                    NULL)
     {
+        CommandArgumentEntry type_arg;
+        CommandArgumentData type_style_arg;
+        
+        type_style_arg.arg_type = eArgTypeName;
+        type_style_arg.arg_repetition = eArgRepeatOptional;
+        
+        type_arg.push_back (type_style_arg);
+        
+        m_arguments.push_back (type_arg);
     }
     
     ~CommandObjectTypeCategoryList ()
@@ -1741,7 +1857,28 @@
     bool
     Execute (Args& command, CommandReturnObject &result)
     {
-        Debugger::Formatting::Categories::LoopThrough(PerCategoryCallback, (void*)&result);
+        const size_t argc = command.GetArgumentCount();
+        RegularExpression* regex = NULL;
+        
+        if (argc == 0)
+            ;
+        else if (argc == 1)
+            regex = new RegularExpression(command.GetArgumentAtIndex(0));
+        else
+        {
+            result.AppendErrorWithFormat ("%s takes 0 or one arg.\n", m_cmd_name.c_str());
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+        }
+        
+        CommandObjectTypeCategoryList_CallbackParam param(&result,
+                                                          regex);
+        
+        Debugger::Formatting::Categories::LoopThrough(PerCategoryCallback, &param);
+        
+        if (regex)
+            delete regex;
+        
         result.SetStatus(eReturnStatusSuccessFinishResult);
         return result.Succeeded();
     }





More information about the lldb-commits mailing list