Fix lldb summarizers for HashMaps and HashSets
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 22 Jul 2018 04:56:33 +0000 (04:56 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 22 Jul 2018 04:56:33 +0000 (04:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187883

Reviewed by Dan Bates.

HashMap and HashSet summarizers were broken in various ways.

The 'type summary add -x' regexp needs to match at the start and end of the string
to avoid finding types nested inside other templates.

The HashTable synthetic child code incorrectly used the type of the key, rather than
the value when synthesizing children.

Add HashMap and HashSet summarizers.

I tried to get synthetic children working directly for HashMap and HashSet, but was unable.

* lldb/lldbWebKitTester/main.cpp:
(testSummaryProviders):
* lldb/lldb_webkit.py:
(__lldb_init_module):
(__lldb_init_module.lldb_webkit):
(WTFHashMap_SummaryProvider):
(WTFHashSet_SummaryProvider):
(WebCoreColorProvider._to_string_extended):
(WebCoreURLProvider.to_string):
(WTFHashMapProvider):
(WTFHashMapProvider.__init__):
(WTFHashMapProvider.tableSize):
(WTFHashMapProvider.keyCount):
(WTFHashSetProvider):
(WTFHashSetProvider.__init__):
(WTFHashSetProvider.tableSize):
(WTFHashSetProvider.keyCount):
(WTFHashTableProvider.tableSize):
(WTFHashTableProvider):
(WTFHashTableProvider.keyCount):
(WTFHashTableProvider.get_child_at_index):
(WTFHashTableProvider.update):
* lldb/lldb_webkit_unittest.py:
(TestSummaryProviders.serial_test_WTFVectorProvider_empty_vector):
(TestSummaryProviders.serial_test_WTFVectorProvider_vector_size_and_capacity):
(TestSummaryProviders):
(TestSummaryProviders.serial_test_WTFHashMap_tablesize_and_size):
(TestSummaryProviders.serial_test_WTFHashMap_of_vectors_tablesize_and_size):
(TestSummaryProviders.serial_test_WTFHashSet_tablesize_and_size):

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

Tools/ChangeLog
Tools/lldb/lldbWebKitTester/main.cpp
Tools/lldb/lldb_webkit.py
Tools/lldb/lldb_webkit_unittest.py

index 898c1d5..565ac83 100644 (file)
@@ -1,5 +1,54 @@
 2018-07-21  Simon Fraser  <simon.fraser@apple.com>
 
+        Fix lldb summarizers for HashMaps and HashSets
+        https://bugs.webkit.org/show_bug.cgi?id=187883
+
+        Reviewed by Dan Bates.
+        
+        HashMap and HashSet summarizers were broken in various ways.
+        
+        The 'type summary add -x' regexp needs to match at the start and end of the string
+        to avoid finding types nested inside other templates.
+        
+        The HashTable synthetic child code incorrectly used the type of the key, rather than
+        the value when synthesizing children.
+        
+        Add HashMap and HashSet summarizers.
+
+        I tried to get synthetic children working directly for HashMap and HashSet, but was unable.
+
+        * lldb/lldbWebKitTester/main.cpp:
+        (testSummaryProviders):
+        * lldb/lldb_webkit.py:
+        (__lldb_init_module):
+        (__lldb_init_module.lldb_webkit):
+        (WTFHashMap_SummaryProvider):
+        (WTFHashSet_SummaryProvider):
+        (WebCoreColorProvider._to_string_extended):
+        (WebCoreURLProvider.to_string):
+        (WTFHashMapProvider):
+        (WTFHashMapProvider.__init__):
+        (WTFHashMapProvider.tableSize):
+        (WTFHashMapProvider.keyCount):
+        (WTFHashSetProvider):
+        (WTFHashSetProvider.__init__):
+        (WTFHashSetProvider.tableSize):
+        (WTFHashSetProvider.keyCount):
+        (WTFHashTableProvider.tableSize):
+        (WTFHashTableProvider):
+        (WTFHashTableProvider.keyCount):
+        (WTFHashTableProvider.get_child_at_index):
+        (WTFHashTableProvider.update):
+        * lldb/lldb_webkit_unittest.py:
+        (TestSummaryProviders.serial_test_WTFVectorProvider_empty_vector):
+        (TestSummaryProviders.serial_test_WTFVectorProvider_vector_size_and_capacity):
+        (TestSummaryProviders):
+        (TestSummaryProviders.serial_test_WTFHashMap_tablesize_and_size):
+        (TestSummaryProviders.serial_test_WTFHashMap_of_vectors_tablesize_and_size):
+        (TestSummaryProviders.serial_test_WTFHashSet_tablesize_and_size):
+
+2018-07-21  Simon Fraser  <simon.fraser@apple.com>
+
         Add lldb formatters for WebCore geometry types
         https://bugs.webkit.org/show_bug.cgi?id=187884
 
index 9c72441..2ce8d61 100644 (file)
@@ -25,6 +25,9 @@
 
 #include "DumpClassLayoutTesting.h"
 #include <stdio.h>
+#include <wtf/HashMap.h>
+#include <wtf/HashSet.h>
+#include <wtf/Vector.h>
 #include <wtf/text/StringBuilder.h>
 #include <wtf/text/WTFString.h>
 
@@ -55,12 +58,21 @@ static void testSummaryProviders()
     String a16BitString = utf16String(u"\u1680Cappuccino\u1680");
     StringImpl* a16BitStringImpl = a16BitString.impl();
 
-
     Vector<int> anEmptyVector;
     Vector<int> aVectorWithOneItem;
     aVectorWithOneItem.reserveCapacity(16);
     aVectorWithOneItem.append(1);
 
+    HashMap<unsigned, int> hashMapOfInts;
+    hashMapOfInts.add(12, 23);
+    hashMapOfInts.add(34, 45);
+
+    HashSet<unsigned> hashSetOfInts;
+    hashSetOfInts.add(42);
+
+    HashMap<unsigned, Vector<int>> hashMapOfVectors;
+    hashMapOfVectors.add(1, Vector<int>({2, 3}));
+
     breakForTestingSummaryProviders();
 }
 
index 5f29cc4..aabae4d 100644 (file)
@@ -39,14 +39,13 @@ def __lldb_init_module(debugger, dict):
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFStringImpl_SummaryProvider WTF::StringImpl')
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFStringView_SummaryProvider WTF::StringView')
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFAtomicString_SummaryProvider WTF::AtomicString')
-    debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFVector_SummaryProvider -x "WTF::Vector<.+>$"')
-    debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFHashTable_SummaryProvider -x "WTF::HashTable<.+>$"')
+    debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFVector_SummaryProvider -x "^WTF::Vector<.+>$"')
+    debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFHashTable_SummaryProvider -x "^WTF::HashTable<.+>$"')
+    debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFHashMap_SummaryProvider -x "^WTF::HashMap<.+>$"')
+    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 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.WebCoreURL_SummaryProvider WebCore::URL')
-
     debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreColor_SummaryProvider WebCore::Color')
 
     debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreLayoutUnit_SummaryProvider WebCore::LayoutUnit')
@@ -62,6 +61,10 @@ def __lldb_init_module(debugger, dict):
     debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreFloatPoint_SummaryProvider WebCore::FloatPoint')
     debugger.HandleCommand('type summary add -F lldb_webkit.WebCoreFloatRect_SummaryProvider WebCore::FloatRect')
 
+    # synthetic types (see <https://lldb.llvm.org/varformats.html>)
+    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')
+
 
 def WTFString_SummaryProvider(valobj, dict):
     provider = WTFStringProvider(valobj, dict)
@@ -94,6 +97,16 @@ def WTFHashTable_SummaryProvider(valobj, dict):
     return "{ tableSize = %d, keyCount = %d }" % (provider.tableSize(), provider.keyCount())
 
 
+def WTFHashMap_SummaryProvider(valobj, dict):
+    provider = WTFHashMapProvider(valobj, dict)
+    return "{ tableSize = %d, keyCount = %d }" % (provider.tableSize(), provider.keyCount())
+
+
+def WTFHashSet_SummaryProvider(valobj, dict):
+    provider = WTFHashSetProvider(valobj, dict)
+    return "{ tableSize = %d, keyCount = %d }" % (provider.tableSize(), provider.keyCount())
+
+
 def WTFMediaTime_SummaryProvider(valobj, dict):
     provider = WTFMediaTimeProvider(valobj, dict)
     if provider.isInvalid():
@@ -560,6 +573,7 @@ class WebCoreURLProvider:
     def to_string(self):
         return WTFStringProvider(self.valobj.GetChildMemberWithName('m_string'), dict).to_string()
 
+
 class WTFVectorProvider:
     def __init__(self, valobj, internal_dict):
         self.valobj = valobj
@@ -603,11 +617,44 @@ class WTFVectorProvider:
         return True
 
 
+class WTFHashMapProvider:
+    def __init__(self, valobj, internal_dict):
+        self.valobj = valobj
+        impl_ptr = self.valobj.GetChildMemberWithName('m_impl')
+        self._hash_table_provider = WTFHashTableProvider(impl_ptr, dict)
+
+    def tableSize(self):
+        return self._hash_table_provider.tableSize()
+
+    def keyCount(self):
+        return self._hash_table_provider.keyCount()
+
+
+class WTFHashSetProvider:
+    def __init__(self, valobj, internal_dict):
+        self.valobj = valobj
+        impl_ptr = self.valobj.GetChildMemberWithName('m_impl')
+        self._hash_table_provider = WTFHashTableProvider(impl_ptr, dict)
+
+    def tableSize(self):
+        return self._hash_table_provider.tableSize()
+
+    def keyCount(self):
+        return self._hash_table_provider.keyCount()
+
+
 class WTFHashTableProvider:
     def __init__(self, valobj, internal_dict):
         self.valobj = valobj
         self.update()
 
+    def tableSize(self):
+        return self.valobj.GetChildMemberWithName('m_tableSize').GetValueAsUnsigned(0)
+
+    def keyCount(self):
+        return self.valobj.GetChildMemberWithName('m_keyCount').GetValueAsUnsigned(0)
+
+    # Synthetic children provider methods.
     def num_children(self):
         return self.tableSize() + 5
 
@@ -642,14 +689,8 @@ class WTFHashTableProvider:
         else:
             return None
 
-    def tableSize(self):
-        return self.valobj.GetChildMemberWithName('m_tableSize').GetValueAsUnsigned(0)
-
-    def keyCount(self):
-        return self.valobj.GetChildMemberWithName('m_keyCount').GetValueAsUnsigned(0)
-
     def update(self):
-        self.data_type = self.valobj.GetType().GetTemplateArgumentType(0)
+        self.data_type = self.valobj.GetType().GetTemplateArgumentType(1)
         self.data_size = self.data_type.GetByteSize()
 
     def has_children(self):
index 953020f..865c97a 100755 (executable)
@@ -143,12 +143,27 @@ class TestSummaryProviders(unittest.TestCase):
 
     def serial_test_WTFVectorProvider_empty_vector(self):
         variable = self._sbFrame.FindVariable('anEmptyVector');
-        self.assertIsNotNone(variable)
         summary = lldb_webkit.WTFVector_SummaryProvider(variable, {})
         self.assertEqual(summary, "{ size = 0, capacity = 0 }")
 
     def serial_test_WTFVectorProvider_vector_size_and_capacity(self):
         variable = self._sbFrame.FindVariable('aVectorWithOneItem');
-        self.assertIsNotNone(variable)
         summary = lldb_webkit.WTFVector_SummaryProvider(variable, {})
         self.assertEqual(summary, "{ size = 1, capacity = 16 }")
+
+    # MARK: WTFHashMap_SummaryProvider and WTFHashSet_SummaryProvider test cases
+
+    def serial_test_WTFHashMap_tablesize_and_size(self):
+        variable = self._sbFrame.FindVariable('hashMapOfInts')
+        summary = lldb_webkit.WTFHashMap_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ tableSize = 8, keyCount = 2 }")
+
+    def serial_test_WTFHashMap_of_vectors_tablesize_and_size(self):
+        variable = self._sbFrame.FindVariable('hashMapOfVectors')
+        summary = lldb_webkit.WTFHashMap_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ tableSize = 8, keyCount = 1 }")
+
+    def serial_test_WTFHashSet_tablesize_and_size(self):
+        variable = self._sbFrame.FindVariable('hashSetOfInts')
+        summary = lldb_webkit.WTFHashSet_SummaryProvider(variable, {})
+        self.assertEqual(summary, "{ tableSize = 8, keyCount = 1 }")