Provide an lldb type summary for WebCore::Color
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jul 2018 22:19:46 +0000 (22:19 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jul 2018 22:19:46 +0000 (22:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187776

Reviewed by Dan Bates.

* lldb/lldbWebKitTester/lldbWebKitTester.xcodeproj/project.pbxproj: Link against WebKit
    to get to WebCore.
* lldb/lldbWebKitTester/main.cpp:
(testSummaryProviders): Create some Color objects for testing.

* lldb/lldb_webkit.py: Add a Color summary provider.
(__lldb_init_module):
(WebCoreColor_SummaryProvider):
(WebCoreColorProvider):
(WebCoreColorProvider.__init__):
(WebCoreColorProvider._is_extended):
(WebCoreColorProvider._is_valid):
(WebCoreColorProvider._is_semantic):
(WebCoreColorProvider._to_string_extended):
(WebCoreColorProvider.to_string):

* lldb/lldb_webkit_unittest.py: Tests.
(TestSummaryProviders.serial_test_WTFVectorProvider_vector_size_and_capacity):
(TestSummaryProviders):
(TestSummaryProviders.serial_test_WebCoreColorProvider_invalid_color):
(TestSummaryProviders.serial_test_WebCoreColorProvider_extended_color):
(TestSummaryProviders.serial_test_WebCoreColorProvider_rgb_color):
(TestSummaryProviders.serial_test_WebCoreColorProvider_rgba_color):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233934 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/lldb/lldbWebKitTester/lldbWebKitTester.xcodeproj/project.pbxproj
Tools/lldb/lldbWebKitTester/main.cpp
Tools/lldb/lldb_webkit.py
Tools/lldb/lldb_webkit_unittest.py

index 6fe09f2..27a7e9d 100644 (file)
@@ -1,3 +1,34 @@
+2018-07-18  Dean Jackson  <dino@apple.com>
+
+        Provide an lldb type summary for WebCore::Color
+        https://bugs.webkit.org/show_bug.cgi?id=187776
+
+        Reviewed by Dan Bates.
+
+        * lldb/lldbWebKitTester/lldbWebKitTester.xcodeproj/project.pbxproj: Link against WebKit
+            to get to WebCore.
+        * lldb/lldbWebKitTester/main.cpp:
+        (testSummaryProviders): Create some Color objects for testing.
+
+        * lldb/lldb_webkit.py: Add a Color summary provider.
+        (__lldb_init_module):
+        (WebCoreColor_SummaryProvider):
+        (WebCoreColorProvider):
+        (WebCoreColorProvider.__init__):
+        (WebCoreColorProvider._is_extended):
+        (WebCoreColorProvider._is_valid):
+        (WebCoreColorProvider._is_semantic):
+        (WebCoreColorProvider._to_string_extended):
+        (WebCoreColorProvider.to_string):
+
+        * lldb/lldb_webkit_unittest.py: Tests.
+        (TestSummaryProviders.serial_test_WTFVectorProvider_vector_size_and_capacity):
+        (TestSummaryProviders):
+        (TestSummaryProviders.serial_test_WebCoreColorProvider_invalid_color):
+        (TestSummaryProviders.serial_test_WebCoreColorProvider_extended_color):
+        (TestSummaryProviders.serial_test_WebCoreColorProvider_rgb_color):
+        (TestSummaryProviders.serial_test_WebCoreColorProvider_rgba_color):
+
 2018-07-18  Stephan Szabo  <stephan.szabo@sony.com>
 
         Adding myself to contributors.json
index 283299a..ae8ef16 100644 (file)
@@ -8,6 +8,7 @@
 
 /* Begin PBXBuildFile section */
                0FC1C35420E5391E001E9FB0 /* DumpClassLayoutTesting.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC1C35320E5391E001E9FB0 /* DumpClassLayoutTesting.cpp */; };
+               3156A19320FEEE3200CA3BA3 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3156A19220FEEE3200CA3BA3 /* WebKit.framework */; };
                7CB6844B1AFA7978002B305C /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CB6844A1AFA7978002B305C /* main.cpp */; };
                CE6C3AFF20C0B17B003E33D8 /* libWTF.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE6C3AFE20C0B17B003E33D8 /* libWTF.a */; };
                CE6C3B0120C0C444003E33D8 /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CE6C3B0020C0C443003E33D8 /* libicucore.dylib */; };
@@ -28,6 +29,7 @@
 /* Begin PBXFileReference section */
                0FC1C35320E5391E001E9FB0 /* DumpClassLayoutTesting.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DumpClassLayoutTesting.cpp; sourceTree = "<group>"; };
                0FC1C35520E53932001E9FB0 /* DumpClassLayoutTesting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DumpClassLayoutTesting.h; sourceTree = "<group>"; };
+               3156A19220FEEE3200CA3BA3 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = WebKit.framework; sourceTree = "<group>"; };
                7C2227511AFC4D9C008C3338 /* Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
                7C2227521AFC4D9C008C3338 /* lldbWebKitTester.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = lldbWebKitTester.xcconfig; sourceTree = "<group>"; };
                7C2227531AFC4D9C008C3338 /* DebugRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = DebugRelease.xcconfig; sourceTree = "<group>"; };
@@ -44,6 +46,7 @@
                        files = (
                                CE6C3B0120C0C444003E33D8 /* libicucore.dylib in Frameworks */,
                                CE6C3AFF20C0B17B003E33D8 /* libWTF.a in Frameworks */,
+                               3156A19320FEEE3200CA3BA3 /* WebKit.framework in Frameworks */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
@@ -93,6 +96,7 @@
                        children = (
                                CE6C3B0020C0C443003E33D8 /* libicucore.dylib */,
                                CE6C3AFE20C0B17B003E33D8 /* libWTF.a */,
+                               3156A19220FEEE3200CA3BA3 /* WebKit.framework */,
                        );
                        name = Frameworks;
                        sourceTree = "<group>";
index 9c72441..874961a 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#define WEBCORE_EXPORT
+
 #include "DumpClassLayoutTesting.h"
+#include <WebCore/Color.h>
 #include <stdio.h>
 #include <wtf/text/StringBuilder.h>
 #include <wtf/text/WTFString.h>
@@ -61,6 +64,12 @@ static void testSummaryProviders()
     aVectorWithOneItem.reserveCapacity(16);
     aVectorWithOneItem.append(1);
 
+    auto invalidColor = WebCore::Color { };
+    auto rgbColor = WebCore::Color { 255, 128, 64 };
+    auto rgbaColor = WebCore::Color { 255, 128, 64, 128 };
+    auto extendedColor = WebCore::Color { 0.1, 0.2, 0.3, 0.4, WebCore::ColorSpaceDisplayP3 };
+    auto semanticColor = WebCore::Color { WebCore::makeRGBA(255, 255, 255, 255), WebCore::Color::Semantic };
+
     breakForTestingSummaryProviders();
 }
 
index 52fb7a4..bfc014e 100644 (file)
@@ -44,6 +44,7 @@ def __lldb_init_module(debugger, dict):
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFMediaTime_SummaryProvider WTF::MediaTime')
     debugger.HandleCommand('type synthetic add -x "WTF::Vector<.+>$" --python-class lldb_webkit.WTFVectorProvider')
     debugger.HandleCommand('type synthetic add -x "WTF::HashTable<.+>$" --python-class lldb_webkit.WTFHashTableProvider')
+    debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreColor_SummaryProvider WebCore::Color')
     debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreLayoutUnit_SummaryProvider WebCore::LayoutUnit')
     debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreLayoutSize_SummaryProvider WebCore::LayoutSize')
     debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreLayoutPoint_SummaryProvider WebCore::LayoutPoint')
@@ -96,6 +97,11 @@ def WTFMediaTime_SummaryProvider(valobj, dict):
     return "{ %d/%d, %f }" % (provider.timeValue(), provider.timeScale(), float(provider.timeValue()) / provider.timeScale())
 
 
+def WebCoreColor_SummaryProvider(valobj, dict):
+    provider = WebCoreColorProvider(valobj, dict)
+    return "{ %s }" % provider.to_string()
+
+
 def WebCoreURL_SummaryProvider(valobj, dict):
     provider = WebCoreURLProvider(valobj, dict)
     return "{ %s }" % provider.to_string()
@@ -309,6 +315,58 @@ class WTFStringProvider:
         return impl.to_string()
 
 
+class WebCoreColorProvider:
+    "Print a WebCore::Color"
+    def __init__(self, valobj, dict):
+        self.valobj = valobj
+
+    def _is_extended(self, rgba_and_flags):
+        return not bool(rgba_and_flags & 0x1)
+
+    def _is_valid(self, rgba_and_flags):
+        # Assumes not extended.
+        return bool(rgba_and_flags & 0x2)
+
+    def _is_semantic(self, rgba_and_flags):
+        # Assumes not extended.
+        return bool(rgba_and_flags & 0x4)
+
+    def _to_string_extended(self):
+        extended_color = self.valobj.GetChildMemberWithName('m_colorData').GetChildMemberWithName('extendedColor').Dereference()
+        profile = extended_color.GetChildMemberWithName('m_colorSpace').GetValue()
+        if profile == 'ColorSpaceSRGB':
+            profile = 'srgb'
+        elif profile == 'ColorSpaceDisplayP3':
+            profile = 'display-p3'
+        else:
+            profile = 'unknown'
+        red = float(extended_color.GetChildMemberWithName('m_red').GetValue())
+        green = float(extended_color.GetChildMemberWithName('m_green').GetValue())
+        blue = float(extended_color.GetChildMemberWithName('m_blue').GetValue())
+        alpha = float(extended_color.GetChildMemberWithName('m_alpha').GetValue())
+        return "color(%s %1.2f %1.2f %1.2f / %1.2f)" % (profile, red, green, blue, alpha)
+
+    def to_string(self):
+        rgba_and_flags = self.valobj.GetChildMemberWithName('m_colorData').GetChildMemberWithName('rgbaAndFlags').GetValueAsUnsigned(0)
+
+        if self._is_extended(rgba_and_flags):
+            return self._to_string_extended()
+
+        if not self._is_valid(rgba_and_flags):
+            return 'invalid'
+
+        color = rgba_and_flags >> 32
+        red = (color >> 16) & 0xFF
+        green = (color >> 8) & 0xFF
+        blue = color & 0xFF
+        alpha = ((color >> 24) & 0xFF) / 255.0
+
+        semantic = ' semantic' if self._is_semantic(rgba_and_flags) else ""
+
+        result = 'rgba(%d, %d, %d, %1.2f)%s' % (red, green, blue, alpha, semantic)
+        return result
+
+
 class WebCoreLayoutUnitProvider:
     "Print a WebCore::LayoutUnit"
     def __init__(self, valobj, dict):
index 953020f..e28fdf0 100755 (executable)
@@ -152,3 +152,30 @@ class TestSummaryProviders(unittest.TestCase):
         self.assertIsNotNone(variable)
         summary = lldb_webkit.WTFVector_SummaryProvider(variable, {})
         self.assertEqual(summary, "{ size = 1, capacity = 16 }")
+
+    # MARK: WebCoreColor_SummaryProvider test cases
+
+    def serial_test_WebCoreColorProvider_invalid_color(self):
+        variable = self._sbFrame.FindVariable('invalidColor')
+        summary = lldb_webkit.WebCoreColorProvider_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ invalid }")
+
+    def serial_test_WebCoreColorProvider_extended_color(self):
+        variable = self._sbFrame.FindVariable('extendedColor')
+        summary = lldb_webkit.WebCoreColorProvider_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ color(display-p3 0.10 0.20 0.30 / 0.40) }")
+
+    def serial_test_WebCoreColorProvider_rgb_color(self):
+        variable = self._sbFrame.FindVariable('rgbColor')
+        summary = lldb_webkit.WebCoreColorProvider_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ rgba(255, 128, 64, 1.00) }")
+
+    def serial_test_WebCoreColorProvider_rgba_color(self):
+        variable = self._sbFrame.FindVariable('rgbaColor')
+        summary = lldb_webkit.WebCoreColorProvider_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ rgba(255, 128, 64, 0.50) }")
+
+    def serial_test_WebCoreColorProvider_semantic_color(self):
+        variable = self._sbFrame.FindVariable('semanticColor')
+        summary = lldb_webkit.WebCoreColorProvider_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ rgba(255, 255, 255, 1.00) semantic }")