[Lldb-commits] [lldb] r243166 - Add option eTypeOptionHideEmptyAggregates.

Siva Chandra sivachandra at google.com
Fri Jul 24 14:30:58 PDT 2015


Author: sivachandra
Date: Fri Jul 24 16:30:58 2015
New Revision: 243166

URL: http://llvm.org/viewvc/llvm-project?rev=243166&view=rev
Log:
Add option eTypeOptionHideEmptyAggregates.

Summary:
For certain data structures, when the synthetic child provider returns
zero children, a summary like "Empty instance of <typename>" could be
more appropriate than something like "size=0 {}". This new option helps
hide the trailing "{}".

This is also exposed with a -h option for the command "type summary add".

Reviewers: granata.enrico

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D11473

Modified:
    lldb/trunk/include/lldb/DataFormatters/TypeSummary.h
    lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/source/Commands/CommandObjectType.cpp
    lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp
    lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py
    lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/main.cpp
    lldb/trunk/test/python_api/formatters/TestFormattersSBAPI.py
    lldb/trunk/test/python_api/formatters/main.cpp
    lldb/trunk/test/python_api/formatters/synth.py

Modified: lldb/trunk/include/lldb/DataFormatters/TypeSummary.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/TypeSummary.h?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/TypeSummary.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/TypeSummary.h Fri Jul 24 16:30:58 2015
@@ -162,6 +162,22 @@ namespace lldb_private {
                     m_flags &= ~lldb::eTypeOptionHideChildren;
                 return *this;
             }
+
+            bool
+            GetHideEmptyAggregates () const
+            {
+                return (m_flags & lldb::eTypeOptionHideEmptyAggregates) == lldb::eTypeOptionHideEmptyAggregates;
+            }
+
+            Flags&
+            SetHideEmptyAggregates (bool value = true)
+            {
+                if (value)
+                    m_flags |= lldb::eTypeOptionHideEmptyAggregates;
+                else
+                    m_flags &= ~lldb::eTypeOptionHideEmptyAggregates;
+                return *this;
+            }
             
             bool
             GetDontShowValue () const
@@ -279,6 +295,12 @@ namespace lldb_private {
         {
             return !m_flags.GetDontShowChildren();
         }
+
+        virtual bool
+        DoesPrintEmptyAggregates () const
+        {
+            return !m_flags.GetHideEmptyAggregates();
+        }
         
         virtual bool
         DoesPrintValue (ValueObject* valobj) const

Modified: lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/ValueObjectPrinter.h Fri Jul 24 16:30:58 2015
@@ -344,6 +344,9 @@ protected:
     bool
     ShouldPrintChildren (bool is_failed_description,
                          uint32_t& curr_ptr_depth);
+
+    bool
+    ShouldExpandEmptyAggregates ();
     
     ValueObject*
     GetValueObjectForChildrenGeneration ();

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Fri Jul 24 16:30:58 2015
@@ -729,15 +729,16 @@ namespace lldb {
     //----------------------------------------------------------------------
     FLAGS_ENUM(TypeOptions)
     {
-        eTypeOptionNone            = (0u),
-        eTypeOptionCascade         = (1u << 0),
-        eTypeOptionSkipPointers    = (1u << 1),
-        eTypeOptionSkipReferences  = (1u << 2),
-        eTypeOptionHideChildren    = (1u << 3),
-        eTypeOptionHideValue       = (1u << 4),
-        eTypeOptionShowOneLiner    = (1u << 5),
-        eTypeOptionHideNames       = (1u << 6),
-        eTypeOptionNonCacheable    = (1u << 7)
+        eTypeOptionNone                = (0u),
+        eTypeOptionCascade             = (1u << 0),
+        eTypeOptionSkipPointers        = (1u << 1),
+        eTypeOptionSkipReferences      = (1u << 2),
+        eTypeOptionHideChildren        = (1u << 3),
+        eTypeOptionHideValue           = (1u << 4),
+        eTypeOptionShowOneLiner        = (1u << 5),
+        eTypeOptionHideNames           = (1u << 6),
+        eTypeOptionNonCacheable        = (1u << 7),
+        eTypeOptionHideEmptyAggregates = (1u << 8)
     };
 
    //----------------------------------------------------------------------

Modified: lldb/trunk/source/Commands/CommandObjectType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectType.cpp?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectType.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectType.cpp Fri Jul 24 16:30:58 2015
@@ -1438,6 +1438,9 @@ CommandObjectTypeSummaryAdd::CommandOpti
         case 'e':
             m_flags.SetDontShowChildren(false);
             break;
+        case 'h':
+            m_flags.SetHideEmptyAggregates(true);
+            break;
         case 'v':
             m_flags.SetDontShowValue(true);
             break;
@@ -1924,6 +1927,7 @@ CommandObjectTypeSummaryAdd::CommandOpti
     { LLDB_OPT_SET_3, false, "python-function", 'F', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonFunction, "Give the name of a Python function to use for this type."},
     { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Input Python code to use for this type manually."},
     { LLDB_OPT_SET_2 | LLDB_OPT_SET_3,   false, "expand", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,    "Expand aggregate data types to show children on separate lines."},
+    { LLDB_OPT_SET_2 | LLDB_OPT_SET_3,   false, "hide-empty", 'h', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,    "Do not expand aggregate data types with no children."},
     { LLDB_OPT_SET_2 | LLDB_OPT_SET_3,   false, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName,    "A name for this summary string."},
     { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
 };

Modified: lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp (original)
+++ lldb/trunk/source/DataFormatters/ValueObjectPrinter.cpp Fri Jul 24 16:30:58 2015
@@ -480,6 +480,17 @@ ValueObjectPrinter::ShouldPrintChildren
     return false;
 }
 
+bool
+ValueObjectPrinter::ShouldExpandEmptyAggregates ()
+{
+    TypeSummaryImpl* entry = GetSummaryFormatter();
+
+    if (!entry)
+        return true;
+
+    return entry->DoesPrintEmptyAggregates();
+}
+
 ValueObject*
 ValueObjectPrinter::GetValueObjectForChildrenGeneration ()
 {
@@ -582,7 +593,7 @@ ValueObjectPrinter::PrintChildren (uint3
         if (ShouldPrintValueObject())
         {
             // if it has a synthetic value, then don't print {}, the synthetic children are probably only being used to vend a value
-            if (m_valobj->DoesProvideSyntheticValue())
+            if (m_valobj->DoesProvideSyntheticValue() || !ShouldExpandEmptyAggregates())
                 m_stream->PutCString( "\n");
             else
                 m_stream->PutCString(" {}\n");

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/TestDataFormatterSynth.py Fri Jul 24 16:30:58 2015
@@ -208,6 +208,12 @@ class SynthDataFormatterTestCase(TestBas
         self.expect('frame variable bag_bag',
                     substrs = ['x.z = 12'])
 
+        self.runCmd('type summary add -e -s "I am always empty but have" EmptyStruct')
+        self.expect('frame variable es', substrs = ["I am always empty but have {}"])
+        self.runCmd('type summary add -e -h -s "I am really empty" EmptyStruct')
+        self.expect('frame variable es', substrs = ["I am really empty"])
+        self.expect('frame variable es', substrs = ["I am really empty {}"], matching=False)
+
 
 if __name__ == '__main__':
     import atexit

Modified: lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/main.cpp?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/main.cpp (original)
+++ lldb/trunk/test/functionalities/data-formatter/data-formatter-synth/main.cpp Fri Jul 24 16:30:58 2015
@@ -46,6 +46,8 @@ struct BagOfBags
     q(20.11) {}
 };
 
+struct EmptyStruct {};
+
 struct Plenty
 {
     BagOfInts *some_values;
@@ -70,6 +72,7 @@ int main (int argc, const char * argv[])
     BagOfFloats float_bag(2.71);
     
     BagOfBags bag_bag;
+    EmptyStruct es;
     
     Plenty plenty_of_stuff(5,true,false);
     

Modified: lldb/trunk/test/python_api/formatters/TestFormattersSBAPI.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/formatters/TestFormattersSBAPI.py?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/test/python_api/formatters/TestFormattersSBAPI.py (original)
+++ lldb/trunk/test/python_api/formatters/TestFormattersSBAPI.py Fri Jul 24 16:30:58 2015
@@ -302,6 +302,10 @@ class SBFormattersAPITestCase(TestBase):
         self.assertTrue(summary.IsValid(), "no summary found for foo* when one was in place")
         self.assertTrue(summary.GetData() == "hello static world", "wrong summary found for foo*")
 
+        self.expect("frame variable e1", substrs=["I am an empty Empty1 {}"])
+        self.expect("frame variable e2", substrs=["I am an empty Empty2"])
+        self.expect("frame variable e2", substrs=["I am an empty Empty2 {}"], matching=False)
+
     def force_synth_off(self):
         """Test that one can have the public API return non-synthetic SBValues if desired"""
         self.runCmd("file no_synth", CURRENT_EXECUTABLE_SET)

Modified: lldb/trunk/test/python_api/formatters/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/formatters/main.cpp?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/test/python_api/formatters/main.cpp (original)
+++ lldb/trunk/test/python_api/formatters/main.cpp Fri Jul 24 16:30:58 2015
@@ -26,6 +26,9 @@ struct CCC
 	int a, b, c;
 };
 
+struct Empty1 { void *data; };
+struct Empty2 { void *data; };
+
 
 int main(int argc, char const *argv[]) {
 	JustAStruct foo;
@@ -49,5 +52,8 @@ int main(int argc, char const *argv[]) {
 
 	CCC ccc = {111, 222, 333};
 
+        Empty1 e1;
+        Empty2 e2;
+
 	return 0; // Set break point at this line.
 }

Modified: lldb/trunk/test/python_api/formatters/synth.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/formatters/synth.py?rev=243166&r1=243165&r2=243166&view=diff
==============================================================================
--- lldb/trunk/test/python_api/formatters/synth.py (original)
+++ lldb/trunk/test/python_api/formatters/synth.py Fri Jul 24 16:30:58 2015
@@ -48,6 +48,36 @@ class CCCSynthProvider(object):
             return self._sbvalue.GetChildMemberWithName("c")
 
 
+def empty1_summary(sbvalue, internal_dict):
+    return "I am an empty Empty1"
+
+
+class Empty1SynthProvider(object):
+    def __init__(self, sbvalue, internal_dict):
+        self._sbvalue = sbvalue
+
+    def num_children(self):
+        return 0
+
+    def get_child_at_index(self, index):
+        return None
+
+
+def empty2_summary(sbvalue, internal_dict):
+    return "I am an empty Empty2"
+
+
+class Empty2SynthProvider(object):
+    def __init__(self, sbvalue, internal_dict):
+        self._sbvalue = sbvalue
+
+    def num_children(self):
+        return 0
+
+    def get_child_at_index(self, index):
+        return None
+
+
 def __lldb_init_module(debugger,dict):
      debugger.CreateCategory("JASSynth").AddTypeSynthetic(lldb.SBTypeNameSpecifier("JustAStruct"),
         lldb.SBTypeSynthetic.CreateWithClassName("synth.jasSynthProvider"))
@@ -60,5 +90,16 @@ def __lldb_init_module(debugger,dict):
          lldb.SBTypeNameSpecifier("CCC"),
          lldb.SBTypeSummary.CreateWithFunctionName("synth.ccc_summary",
                                                    lldb.eTypeOptionCascade))
-
-
+     cat.AddTypeSynthetic(
+         lldb.SBTypeNameSpecifier("Empty1"),
+         lldb.SBTypeSynthetic.CreateWithClassName("synth.Empty1SynthProvider"))
+     cat.AddTypeSummary(
+         lldb.SBTypeNameSpecifier("Empty1"),
+         lldb.SBTypeSummary.CreateWithFunctionName("synth.empty1_summary"))
+     cat.AddTypeSynthetic(
+         lldb.SBTypeNameSpecifier("Empty2"),
+         lldb.SBTypeSynthetic.CreateWithClassName("synth.Empty2SynthProvider"))
+     cat.AddTypeSummary(
+         lldb.SBTypeNameSpecifier("Empty2"),
+         lldb.SBTypeSummary.CreateWithFunctionName("synth.empty2_summary",
+                                                   lldb.eTypeOptionHideEmptyAggregates))





More information about the lldb-commits mailing list