[Lldb-commits] [lldb] r241531 - Add a summary for vector types

Enrico Granata egranata at apple.com
Mon Jul 6 17:20:57 PDT 2015


Author: enrico
Date: Mon Jul  6 19:20:57 2015
New Revision: 241531

URL: http://llvm.org/viewvc/llvm-project?rev=241531&view=rev
Log:
Add a summary for vector types

The summary is - quite simply - a one-line printout of the vector elements

We still need synthetic children:
a) as a source of the elements to print in the summary
b) for graphical IDEs that display structure regardless of the summary settings

rdar://5429347


Modified:
    lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h
    lldb/trunk/include/lldb/DataFormatters/VectorType.h
    lldb/trunk/source/DataFormatters/FormatManager.cpp
    lldb/trunk/source/DataFormatters/VectorType.cpp
    lldb/trunk/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py

Modified: lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h?rev=241531&r1=241530&r2=241531&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/CXXFormatterFunctions.h Mon Jul  6 19:20:57 2015
@@ -18,6 +18,7 @@
 #include "lldb/Core/ConstString.h"
 #include "lldb/DataFormatters/FormatClasses.h"
 #include "lldb/DataFormatters/TypeSynthetic.h"
+#include "lldb/DataFormatters/VectorType.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/ObjCLanguageRuntime.h"
 #include "lldb/Target/Target.h"

Modified: lldb/trunk/include/lldb/DataFormatters/VectorType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/VectorType.h?rev=241531&r1=241530&r2=241531&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/VectorType.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/VectorType.h Mon Jul  6 19:20:57 2015
@@ -0,0 +1,28 @@
+//===-- VectorType.h ------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_VectorType_h_
+#define liblldb_VectorType_h_
+
+#include "lldb/lldb-forward.h"
+
+namespace lldb_private {
+    namespace formatters
+    {
+        bool
+        VectorTypeSummaryProvider (ValueObject&,
+                                   Stream&,
+                                   const TypeSummaryOptions&);
+
+        SyntheticChildrenFrontEnd*
+        VectorTypeSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP);
+    } // namespace formatters
+} // namespace lldb_private
+
+#endif // liblldb_VectorType_h_

Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=241531&r1=241530&r2=241531&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Mon Jul  6 19:20:57 2015
@@ -1608,6 +1608,26 @@ FormatManager::LoadHardcodedFormatters()
                                             }
                                             return nullptr;
                                         });
+        m_hardcoded_summaries.push_back(
+                                         [](lldb_private::ValueObject& valobj,
+                                            lldb::DynamicValueType,
+                                            FormatManager& fmt_mgr) -> TypeSummaryImpl::SharedPointer {
+                                             static CXXFunctionSummaryFormat::SharedPointer formatter_sp(new CXXFunctionSummaryFormat(TypeSummaryImpl::Flags()
+                                                                                                                                      .SetCascades(true)
+                                                                                                                                      .SetDontShowChildren(true)
+                                                                                                                                      .SetHideItemNames(true)
+                                                                                                                                      .SetShowMembersOneLiner(true)
+                                                                                                                                      .SetSkipPointers(true)
+                                                                                                                                      .SetSkipReferences(false),
+                                                                                                                                      lldb_private::formatters::VectorTypeSummaryProvider,
+                                                                                                                                      "vector_type pointer summary provider"));
+                                             if (valobj.GetClangType().IsVectorType(nullptr, nullptr))
+                                             {
+                                                 if (fmt_mgr.GetCategory(fmt_mgr.m_vectortypes_category_name)->IsEnabled())
+                                                     return formatter_sp;
+                                             }
+                                             return nullptr;
+                                         });
     }
     {
         // insert code to load synthetics here

Modified: lldb/trunk/source/DataFormatters/VectorType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/VectorType.cpp?rev=241531&r1=241530&r2=241531&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/VectorType.cpp (original)
+++ lldb/trunk/source/DataFormatters/VectorType.cpp Mon Jul  6 19:20:57 2015
@@ -7,9 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/DataFormatters/CXXFormatterFunctions.h"
+#include "lldb/DataFormatters/VectorType.h"
 
 #include "lldb/Core/ValueObject.h"
+#include "lldb/DataFormatters/CXXFormatterFunctions.h"
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/ClangASTType.h"
 
@@ -267,6 +268,51 @@ namespace lldb_private {
     }
 }
 
+bool
+lldb_private::formatters::VectorTypeSummaryProvider (ValueObject& valobj,
+                                                     Stream& s,
+                                                     const TypeSummaryOptions&)
+{
+    auto synthetic_children = VectorTypeSyntheticFrontEndCreator(nullptr, valobj.GetSP());
+    if (!synthetic_children)
+        return false;
+    
+    synthetic_children->Update();
+    
+    s.PutChar('(');
+    bool first = true;
+    
+    size_t idx = 0, len = synthetic_children->CalculateNumChildren();
+    
+    for (;
+         idx < len;
+         idx++)
+    {
+        auto child_sp = synthetic_children->GetChildAtIndex(idx);
+        if (!child_sp)
+            continue;
+        child_sp = child_sp->GetQualifiedRepresentationIfAvailable(lldb::eDynamicDontRunTarget, true);
+        
+        const char* child_value = child_sp->GetValueAsCString();
+        if (child_value && *child_value)
+        {
+            if (first)
+            {
+                s.Printf("%s", child_value);
+                first = false;
+            }
+            else
+            {
+                s.Printf(", %s", child_value);
+            }
+        }
+    }
+    
+    s.PutChar(')');
+    
+    return true;
+}
+
 lldb_private::SyntheticChildrenFrontEnd*
 lldb_private::formatters::VectorTypeSyntheticFrontEndCreator (CXXSyntheticChildren*, lldb::ValueObjectSP valobj_sp)
 {

Modified: lldb/trunk/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py?rev=241531&r1=241530&r2=241531&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py (original)
+++ lldb/trunk/test/functionalities/data-formatter/vector-types/TestVectorTypesFormatting.py Mon Jul  6 19:20:57 2015
@@ -69,8 +69,9 @@ class VectorTypesFormattingTestCase(Test
         self.assertTrue(v.GetChildAtIndex(2).GetData().float[0] == 2.50, "child 2 == 2.50")
         self.assertTrue(v.GetChildAtIndex(3).GetData().float[0] == 2.50, "child 3 == 2.50")
         
-        self.expect("expr -f int16_t[] -- v", substrs=['[0] = 0', '[1] = 16288', '[2] = 0', '[3] = 16288', '[4] = 0', '[5] = 16416', '[6] = 0', '[7] = 16416'])
-        self.expect("expr -f uint128_t[] -- v", substrs=['[0] = 85236745249553456609335044694184296448'])
+        self.expect("expr -f int16_t[] -- v", substrs=['(0, 16288, 0, 16288, 0, 16416, 0, 16416)'])
+        self.expect("expr -f uint128_t[] -- v", substrs=['(85236745249553456609335044694184296448)'])
+        self.expect("expr -f float32[] -- v", substrs=['(1.25, 1.25, 2.5, 2.5)'])
         
         oldValue = v.GetChildAtIndex(0).GetValue()
         v.SetFormat(lldb.eFormatHex)





More information about the lldb-commits mailing list