[Lldb-commits] [lldb] r183272 - <rdar://problem/12582328>

Enrico Granata egranata at apple.com
Tue Jun 4 15:25:36 PDT 2013


Author: enrico
Date: Tue Jun  4 17:25:36 2013
New Revision: 183272

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

If you want to define a formatter for "array of Foo of any size", ordinarily you would say

-x "Foo \[[0-9]+\]"

this checkin allows you to instead say "Foo[]" (or "Foo []") and LLDB will automatically create the regular expression and add the -x flag on your behalf


Modified:
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=183272&r1=183271&r2=183272&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Tue Jun  4 17:25:36 2013
@@ -179,7 +179,7 @@ public:
     }
     
     static bool
-    AddSummary(const ConstString& type_name,
+    AddSummary(ConstString type_name,
                lldb::TypeSummaryImplSP entry,
                SummaryFormatType type,
                std::string category,
@@ -324,7 +324,7 @@ public:
     }
     
     static bool
-    AddSynth(const ConstString& type_name,
+    AddSynth(ConstString type_name,
              lldb::SyntheticChildrenSP entry,
              SynthFormatType type,
              std::string category_name,
@@ -1340,7 +1340,7 @@ CommandObjectTypeSummaryAdd::DoExecute (
 }
 
 bool
-CommandObjectTypeSummaryAdd::AddSummary(const ConstString& type_name,
+CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
                                         TypeSummaryImplSP entry,
                                         SummaryFormatType type,
                                         std::string category_name,
@@ -1349,6 +1349,21 @@ CommandObjectTypeSummaryAdd::AddSummary(
     lldb::TypeCategoryImplSP category;
     DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
     
+    if (type == eRegularSummary)
+    {
+        std::string type_name_str(type_name.GetCString());
+        if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
+        {
+            type_name_str.resize(type_name_str.length()-2);
+            if (type_name_str.back() != ' ')
+                type_name_str.append(" \\[[0-9]+\\]");
+            else
+                type_name_str.append("\\[[0-9]+\\]");
+            type_name.SetCString(type_name_str.c_str());
+            type = eRegexSummary;
+        }
+    }
+    
     if (type == eRegexSummary)
     {
         RegularExpressionSP typeRX(new RegularExpression());
@@ -3575,15 +3590,30 @@ CommandObjectTypeSynthAdd::CommandObject
 }
 
 bool
-CommandObjectTypeSynthAdd::AddSynth(const ConstString& type_name,
-         SyntheticChildrenSP entry,
-         SynthFormatType type,
-         std::string category_name,
-         Error* error)
+CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
+                                    SyntheticChildrenSP entry,
+                                    SynthFormatType type,
+                                    std::string category_name,
+                                    Error* error)
 {
     lldb::TypeCategoryImplSP category;
     DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
     
+    if (type == eRegularSynth)
+    {
+        std::string type_name_str(type_name.GetCString());
+        if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
+        {
+            type_name_str.resize(type_name_str.length()-2);
+            if (type_name_str.back() != ' ')
+                type_name_str.append(" \\[[0-9]+\\]");
+            else
+                type_name_str.append("\\[[0-9]+\\]");
+            type_name.SetCString(type_name_str.c_str());
+            type = eRegularSynth;
+        }
+    }
+    
     if (category->AnyMatches(type_name,
                              eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
                              false))
@@ -3754,7 +3784,7 @@ private:
     };
     
     bool
-    AddFilter(const ConstString& type_name,
+    AddFilter(ConstString type_name,
               SyntheticChildrenSP entry,
               FilterFormatType type,
               std::string category_name,
@@ -3763,6 +3793,21 @@ private:
         lldb::TypeCategoryImplSP category;
         DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
         
+        if (type == eRegularFilter)
+        {
+            std::string type_name_str(type_name.GetCString());
+            if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
+            {
+                type_name_str.resize(type_name_str.length()-2);
+                if (type_name_str.back() != ' ')
+                    type_name_str.append(" \\[[0-9]+\\]");
+                else
+                    type_name_str.append("\\[[0-9]+\\]");
+                type_name.SetCString(type_name_str.c_str());
+                type = eRegexFilter;
+            }
+        }
+        
         if (category->AnyMatches(type_name,
                                  eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
                                  false))

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py?rev=183272&r1=183271&r2=183272&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-advanced/TestDataFormatterAdv.py Tue Jun  4 17:25:36 2013
@@ -77,7 +77,8 @@ class AdvDataFormatterTestCase(TestBase)
         self.expect("frame variable int_array",
             substrs = ['1,2,3,4,5'])
 
-        self.runCmd("type summary add --summary-string \"${var[].integer}\" -x \"i_am_cool \\[[0-9]\\]")
+        # this will fail if we don't do [] as regex correctly
+        self.runCmd('type summary add --summary-string "${var[].integer}" "i_am_cool[]')
         
         self.expect("frame variable cool_array",
             substrs = ['1,1,1,1,6'])
@@ -122,7 +123,12 @@ class AdvDataFormatterTestCase(TestBase)
 
         self.runCmd("type summary clear")
             
-        self.runCmd("type summary add --summary-string \"${var[0-1]}\" -x \"int \[[0-9]\]\"")
+        self.runCmd('type summary add --summary-string \"${var[0-1]}\" -x \"int \[[0-9]\]\"')
+
+        self.expect("frame variable int_array",
+            substrs = ['1,2'])
+
+        self.runCmd('type summary add --summary-string \"${var[0-1]}\" "int []"')
 
         self.expect("frame variable int_array",
             substrs = ['1,2'])





More information about the lldb-commits mailing list