Title: [251813] trunk
Revision
251813
Author
[email protected]
Date
2019-10-30 15:21:06 -0700 (Wed, 30 Oct 2019)

Log Message

Add pretty printer for CompactPointerTuple
https://bugs.webkit.org/show_bug.cgi?id=203495

Reviewed by Jer Noble.

Source/WTF:

#include <wtf/FastMalloc.h> for the definition of WTF_MAKE_FAST_ALLOCATED.

* wtf/CompactPointerTuple.h:

Tools:

Make it easy to see the state of a CompactPointerTuple. Now we will print something like:

        (WTF::CompactPointerTuple<WTF::String *, unsigned char>) $0 = { type = 7 } {
          [0] = 0x00007ffeefbff220 { length = 8, contents = 'résumé' }
          [1] = 7
        }

for aCompactPointerTuple defined like this:

        String aString { "résumé" };
        CompactPointerTuple<String*, uint8_t> aCompactPointerTuple { &aString, 7 };

* lldb/lldbWebKitTester/main.cpp:
(testSummaryProviders):
* lldb/lldb_webkit.py:
(__lldb_init_module):
(__lldb_init_module.lldb_webkit):
(WTFCompactPointerTuple_SummaryProvider):
(WTFCompactPointerTupleProvider):
(WTFCompactPointerTupleProvider.__init__):

(WTFCompactPointerTupleProvider.type_as_string):
(WTFCompactPointerTupleProvider.is_human_readable_type):
The majority of the time CompactPointerTuple will be used with non-character type data. So,
I optimize for this use case and consider the integral value as more readable than than LLDB's
default summary provider that emits the character or equivalent C escape sequence.

(WTFCompactPointerTupleProvider.has_children):
(WTFCompactPointerTupleProvider.num_children):
(WTFCompactPointerTupleProvider.get_child_index):
(WTFCompactPointerTupleProvider.get_child_at_index):
(WTFCompactPointerTupleProvider.update):
* lldb/lldb_webkit_unittest.py:
(TestSummaryProviders.serial_test_WTFOptionSetProvider_aliased_flag):
(TestSummaryProviders):
(TestSummaryProviders.serial_test_WTFCompactPointerTuple_SummaryProvider_empty):
(TestSummaryProviders.serial_test_WTFCompactPointerTuple_SummaryProvider_simple):
(TestSummaryProviders.serial_test_WTFCompactPointerTuple_SummaryProvider_max_type_value):
(TestSummaryProviders.serial_test_WTFCompactPointerTuple_SummaryProvider_bool):
(TestSummaryProviders.serial_test_WTFCompactPointerTupleProvider_empty):
(TestSummaryProviders.serial_test_WTFCompactPointerTupleProvider_simple):
(TestSummaryProviders.serial_test_WTFCompactPointerTupleProvider_max_type_value):
(TestSummaryProviders.serial_test_WTFCompactPointerTupleProvider_simple_bool):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (251812 => 251813)


--- trunk/Source/WTF/ChangeLog	2019-10-30 22:19:33 UTC (rev 251812)
+++ trunk/Source/WTF/ChangeLog	2019-10-30 22:21:06 UTC (rev 251813)
@@ -1,3 +1,14 @@
+2019-10-30  Daniel Bates  <[email protected]>
+
+        Add pretty printer for CompactPointerTuple
+        https://bugs.webkit.org/show_bug.cgi?id=203495
+
+        Reviewed by Jer Noble.
+
+        #include <wtf/FastMalloc.h> for the definition of WTF_MAKE_FAST_ALLOCATED.
+
+        * wtf/CompactPointerTuple.h:
+
 2019-10-29  Yusuke Suzuki  <[email protected]>
 
         [JSC] Add fast path for String#localeCompare

Modified: trunk/Source/WTF/wtf/CompactPointerTuple.h (251812 => 251813)


--- trunk/Source/WTF/wtf/CompactPointerTuple.h	2019-10-30 22:19:33 UTC (rev 251812)
+++ trunk/Source/WTF/wtf/CompactPointerTuple.h	2019-10-30 22:21:06 UTC (rev 251813)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include <type_traits>
+#include <wtf/FastMalloc.h>
 #include <wtf/StdLibExtras.h>
 
 namespace WTF {

Modified: trunk/Tools/ChangeLog (251812 => 251813)


--- trunk/Tools/ChangeLog	2019-10-30 22:19:33 UTC (rev 251812)
+++ trunk/Tools/ChangeLog	2019-10-30 22:21:06 UTC (rev 251813)
@@ -1,3 +1,54 @@
+2019-10-30  Daniel Bates  <[email protected]>
+
+        Add pretty printer for CompactPointerTuple
+        https://bugs.webkit.org/show_bug.cgi?id=203495
+
+        Reviewed by Jer Noble.
+
+        Make it easy to see the state of a CompactPointerTuple. Now we will print something like:
+
+                (WTF::CompactPointerTuple<WTF::String *, unsigned char>) $0 = { type = 7 } {
+                  [0] = 0x00007ffeefbff220 { length = 8, contents = 'résumé' }
+                  [1] = 7
+                }
+
+        for aCompactPointerTuple defined like this:
+
+                String aString { "résumé" };
+                CompactPointerTuple<String*, uint8_t> aCompactPointerTuple { &aString, 7 };
+
+        * lldb/lldbWebKitTester/main.cpp:
+        (testSummaryProviders):
+        * lldb/lldb_webkit.py:
+        (__lldb_init_module):
+        (__lldb_init_module.lldb_webkit):
+        (WTFCompactPointerTuple_SummaryProvider):
+        (WTFCompactPointerTupleProvider):
+        (WTFCompactPointerTupleProvider.__init__):
+
+        (WTFCompactPointerTupleProvider.type_as_string):
+        (WTFCompactPointerTupleProvider.is_human_readable_type):
+        The majority of the time CompactPointerTuple will be used with non-character type data. So,
+        I optimize for this use case and consider the integral value as more readable than than LLDB's
+        default summary provider that emits the character or equivalent C escape sequence.
+
+        (WTFCompactPointerTupleProvider.has_children):
+        (WTFCompactPointerTupleProvider.num_children):
+        (WTFCompactPointerTupleProvider.get_child_index):
+        (WTFCompactPointerTupleProvider.get_child_at_index):
+        (WTFCompactPointerTupleProvider.update):
+        * lldb/lldb_webkit_unittest.py:
+        (TestSummaryProviders.serial_test_WTFOptionSetProvider_aliased_flag):
+        (TestSummaryProviders):
+        (TestSummaryProviders.serial_test_WTFCompactPointerTuple_SummaryProvider_empty):
+        (TestSummaryProviders.serial_test_WTFCompactPointerTuple_SummaryProvider_simple):
+        (TestSummaryProviders.serial_test_WTFCompactPointerTuple_SummaryProvider_max_type_value):
+        (TestSummaryProviders.serial_test_WTFCompactPointerTuple_SummaryProvider_bool):
+        (TestSummaryProviders.serial_test_WTFCompactPointerTupleProvider_empty):
+        (TestSummaryProviders.serial_test_WTFCompactPointerTupleProvider_simple):
+        (TestSummaryProviders.serial_test_WTFCompactPointerTupleProvider_max_type_value):
+        (TestSummaryProviders.serial_test_WTFCompactPointerTupleProvider_simple_bool):
+
 2019-10-30  Jonathan Bedard  <[email protected]>
 
         Python 3: Add support in webkitpy.port

Modified: trunk/Tools/lldb/lldbWebKitTester/main.cpp (251812 => 251813)


--- trunk/Tools/lldb/lldbWebKitTester/main.cpp	2019-10-30 22:19:33 UTC (rev 251812)
+++ trunk/Tools/lldb/lldbWebKitTester/main.cpp	2019-10-30 22:21:06 UTC (rev 251813)
@@ -25,6 +25,7 @@
 
 #include "DumpClassLayoutTesting.h"
 #include <stdio.h>
+#include <wtf/CompactPointerTuple.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/OptionSet.h>
@@ -86,6 +87,11 @@
     OptionSet<ExampleFlags> exampleFlagsSimple { ExampleFlags::A, ExampleFlags::D, ExampleFlags::C };
     OptionSet<ExampleFlags> exampleFlagsAliasedFlag { ExampleFlags::AAlias, ExampleFlags::D };
 
+    CompactPointerTuple<String*, uint8_t> exampleCompactPointerTupleEmpty;
+    CompactPointerTuple<String*, uint8_t> exampleCompactPointerTupleSimple { &an8BitString, 7 };
+    CompactPointerTuple<String*, uint8_t> exampleCompactPointerTupleMaxTypeValue { &an8BitString, 255 };
+    CompactPointerTuple<String*, bool> exampleCompactPointerTupleSimpleBool { &an8BitString, true };
+
     breakForTestingSummaryProviders();
 }
 

Modified: trunk/Tools/lldb/lldb_webkit.py (251812 => 251813)


--- trunk/Tools/lldb/lldb_webkit.py	2019-10-30 22:19:33 UTC (rev 251812)
+++ trunk/Tools/lldb/lldb_webkit.py	2019-10-30 22:21:06 UTC (rev 251813)
@@ -66,6 +66,7 @@
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFHashSet_SummaryProvider -x "^WTF::HashSet<.+>$"')
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFMediaTime_SummaryProvider WTF::MediaTime')
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFOptionSet_SummaryProvider -x "^WTF::OptionSet<.+>$"')
+    debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFCompactPointerTuple_SummaryProvider -x "^WTF::CompactPointerTuple<.+,.+>$"')
 
     debugger.HandleCommand('type summary add -F lldb_webkit.WTFURL_SummaryProvider WTF::URL')
     debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreColor_SummaryProvider WebCore::Color')
@@ -93,6 +94,7 @@
     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 synthetic add -x "^WTF::OptionSet<.+>$" --python-class lldb_webkit.WTFOptionSetProvider')
+    debugger.HandleCommand('type synthetic add -x "^WTF::CompactPointerTuple<.+,.+>$" --python-class lldb_webkit.WTFCompactPointerTupleProvider')
 
     addSummaryAndSyntheticFormattersForRawBitmaskType(debugger, "WebEventFlags", {
         0x00010000: "WebEventFlagMaskLeftCommandKey",
@@ -168,6 +170,11 @@
     return "{ %d/%d, %f }" % (provider.timeValue(), provider.timeScale(), float(provider.timeValue()) / provider.timeScale())
 
 
+def WTFCompactPointerTuple_SummaryProvider(valobj, dict):
+    provider = WTFCompactPointerTupleProvider(valobj, dict)
+    return "{ type = %s }" % provider.type_as_string()
+
+
 def WebCoreColor_SummaryProvider(valobj, dict):
     provider = WebCoreColorProvider(valobj, dict)
     return "{ %s }" % provider.to_string()
@@ -844,6 +851,89 @@
         return self.valobj.GetValueAsUnsigned(0)
 
 
+class WTFCompactPointerTupleProvider(object):
+
+    TYPE_MASK = 0xF800000000000007
+    POINTER_MASK = ~TYPE_MASK
+
+    def __init__(self, valobj, internal_dict):
+        self.valobj = valobj
+        self._is32Bit = valobj.GetTarget().GetAddressByteSize() == 4
+        self._pointer = None
+        self._type = None
+        self.update()
+
+    def type_as_string(self):
+        if not self.is_human_readable_type():
+            return "%s" % self._type.GetValueAsUnsigned(0)
+        return "%s" % self._type.GetValue()
+
+    def is_human_readable_type(self):
+        # The default summary provider for uint8_t, unsigned char emits the ASCII printable character or equivalent
+        # C escape sequence (e.g. \a = 0x07). Typically the CompactPointerTuple is used to encode non-character integral
+        # data. In this context it is less readable to use the default summary provider. So, we don't.
+        return self.valobj.GetType().GetTemplateArgumentType(1).GetBasicType() != lldb.eBasicTypeUnsignedChar
+
+    # LLDB overrides
+    def has_children(self):
+        return self._type is not None and self._pointer is not None
+
+    def num_children(self):
+        if not self.has_children:
+            return 0
+        return 2
+
+    def get_child_index(self, name):
+        if name == '[0]':
+            return 0
+        if name == '[1]':
+            return 1
+        if self._is32Bit:
+            if name == 'm_pointer':
+                return 2
+            if name == 'm_type':
+                return 3
+        else:
+            if name == 'm_data':
+                return 2
+        return None
+
+    def get_child_at_index(self, index):
+        if index < 0 or not self.valobj.IsValid():
+            return None
+        if index == 0:
+            return self._pointer
+        if index == 1:
+            return self._type
+        if self._is32Bit:
+            if index == 2:
+                return self._pointer
+            if index == 3:
+                return self._type
+        else:
+            if index == 2:
+                return self.valobj.GetChildMemberWithName('m_data')
+        return None
+
+    def update(self):
+        if self._is32Bit:
+            self._pointer = self.valobj.GetChildMemberWithName('m_pointer')
+            self._type = self.valobj.GetChildMemberWithName('m_type')
+        else:
+            data = ""
+            byte_order = self.valobj.GetTarget().GetByteOrder()
+            address_byte_size = self.valobj.GetTarget().GetAddressByteSize()
+
+            pointer_data = lldb.SBData.CreateDataFromUInt64Array(byte_order, address_byte_size, [data & self.POINTER_MASK])
+            self._pointer = self.valobj.CreateValueFromData('[0]', pointer_data, self.valobj.GetType().GetTemplateArgumentType(0))
+
+            type_data = lldb.SBData.CreateDataFromUInt64Array(byte_order, address_byte_size, [(data >> 59 | data << 5) & 0xFF])
+            type_to_use = self.valobj.GetType().GetTemplateArgumentType(1)
+            if not self.is_human_readable_type():
+                type_to_use = self.valobj.GetTarget().GetBasicType(lldb.eBasicTypeUnsignedInt)
+            self._type = self.valobj.CreateValueFromData('[1]', type_data, type_to_use)
+
+
 class WTFVectorProvider:
     def __init__(self, valobj, internal_dict):
         self.valobj = valobj

Modified: trunk/Tools/lldb/lldb_webkit_unittest.py (251812 => 251813)


--- trunk/Tools/lldb/lldb_webkit_unittest.py	2019-10-30 22:19:33 UTC (rev 251812)
+++ trunk/Tools/lldb/lldb_webkit_unittest.py	2019-10-30 22:21:06 UTC (rev 251813)
@@ -204,3 +204,57 @@
         self.assertEqual(provider.get_child_at_index(0).GetValue(), '1')
         self.assertEqual(provider.get_child_at_index(1).GetName(), 'D')
         self.assertEqual(provider.get_child_at_index(1).GetValue(), '8')
+
+    # MARK: WTFCompactPointerTuple test cases
+
+    def serial_test_WTFCompactPointerTuple_SummaryProvider_empty(self):
+        variable = self._sbFrame.FindVariable('exampleCompactPointerTupleEmpty')
+        summary = lldb_webkit.WTFCompactPointerTuple_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ type = 0 }")
+
+    def serial_test_WTFCompactPointerTuple_SummaryProvider_simple(self):
+        variable = self._sbFrame.FindVariable('exampleCompactPointerTupleSimple')
+        summary = lldb_webkit.WTFCompactPointerTuple_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ type = 7 }")
+
+    def serial_test_WTFCompactPointerTuple_SummaryProvider_max_type_value(self):
+        variable = self._sbFrame.FindVariable('exampleCompactPointerTupleMaxTypeValue')
+        summary = lldb_webkit.WTFCompactPointerTuple_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ type = 255 }")
+
+    def serial_test_WTFCompactPointerTuple_SummaryProvider_bool(self):
+        variable = self._sbFrame.FindVariable('exampleCompactPointerTupleSimpleBool')
+        summary = lldb_webkit.WTFCompactPointerTuple_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ type = true }")
+
+    def serial_test_WTFCompactPointerTupleProvider_empty(self):
+        variable = self._sbFrame.FindVariable('exampleCompactPointerTupleEmpty')
+        provider = lldb_webkit.WTFCompactPointerTupleProvider(variable, {})
+        self.assertEqual(provider.get_child_at_index(0).GetName(), '[0]')
+        self.assertEqual(provider.get_child_at_index(0).GetValueAsUnsigned(), 0)
+        self.assertEqual(provider.get_child_at_index(1).GetName(), '[1]')
+        self.assertEqual(provider.get_child_at_index(1).GetValueAsUnsigned(), 0)
+
+    def serial_test_WTFCompactPointerTupleProvider_simple(self):
+        variable = self._sbFrame.FindVariable('exampleCompactPointerTupleSimple')
+        provider = lldb_webkit.WTFCompactPointerTupleProvider(variable, {})
+        self.assertEqual(provider.get_child_at_index(0).GetName(), '[0]')
+        self.assertNotEqual(provider.get_child_at_index(0).GetValueAsUnsigned(), 0)
+        self.assertEqual(provider.get_child_at_index(1).GetName(), '[1]')
+        self.assertEqual(provider.get_child_at_index(1).GetValueAsUnsigned(), 7)
+
+    def serial_test_WTFCompactPointerTupleProvider_max_type_value(self):
+        variable = self._sbFrame.FindVariable('exampleCompactPointerTupleMaxTypeValue')
+        provider = lldb_webkit.WTFCompactPointerTupleProvider(variable, {})
+        self.assertEqual(provider.get_child_at_index(0).GetName(), '[0]')
+        self.assertNotEqual(provider.get_child_at_index(0).GetValueAsUnsigned(), 0)
+        self.assertEqual(provider.get_child_at_index(1).GetName(), '[1]')
+        self.assertEqual(provider.get_child_at_index(1).GetValueAsUnsigned(), 255)
+
+    def serial_test_WTFCompactPointerTupleProvider_simple_bool(self):
+        variable = self._sbFrame.FindVariable('exampleCompactPointerTupleSimpleBool')
+        provider = lldb_webkit.WTFCompactPointerTupleProvider(variable, {})
+        self.assertEqual(provider.get_child_at_index(0).GetName(), '[0]')
+        self.assertNotEqual(provider.get_child_at_index(0).GetValueAsUnsigned(), 0)
+        self.assertEqual(provider.get_child_at_index(1).GetName(), '[1]')
+        self.assertEqual(provider.get_child_at_index(1).GetValue(), 'true')
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to