LLDB: add synthetic provider for WTF::HashTable
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2013 00:51:38 +0000 (00:51 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Feb 2013 00:51:38 +0000 (00:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108718

Reviewed by Darin Adler.

Add a synthetic provider which will emit the contents of a given
WTF::HashTable. This allows clients using Xcode/lldb to enumerate
the hash contents.

* lldb/lldb_webkit.py:
(__lldb_init_module):
(__lldb_init_module.lldb_webkit):
(WTFHashTable_SummaryProvider):
(WTFVectorProvider.has_children):
(WTFHashTableProvider):
(WTFHashTableProvider.__init__):
(WTFHashTableProvider.num_children):
(WTFHashTableProvider.get_child_index):
(WTFHashTableProvider.get_child_at_index):
(WTFHashTableProvider.tableSize):
(WTFHashTableProvider.keyCount):
(WTFHashTableProvider.update):
(WTFHashTableProvider.has_children):

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

Tools/ChangeLog
Tools/lldb/lldb_webkit.py

index 4cc097f..2092d86 100644 (file)
@@ -1,3 +1,29 @@
+2013-02-01  Jer Noble  <jer.noble@apple.com>
+
+        LLDB: add synthetic provider for WTF::HashTable
+        https://bugs.webkit.org/show_bug.cgi?id=108718
+
+        Reviewed by Darin Adler.
+
+        Add a synthetic provider which will emit the contents of a given
+        WTF::HashTable. This allows clients using Xcode/lldb to enumerate
+        the hash contents.
+
+        * lldb/lldb_webkit.py:
+        (__lldb_init_module):
+        (__lldb_init_module.lldb_webkit):
+        (WTFHashTable_SummaryProvider):
+        (WTFVectorProvider.has_children):
+        (WTFHashTableProvider):
+        (WTFHashTableProvider.__init__):
+        (WTFHashTableProvider.num_children):
+        (WTFHashTableProvider.get_child_index):
+        (WTFHashTableProvider.get_child_at_index):
+        (WTFHashTableProvider.tableSize):
+        (WTFHashTableProvider.keyCount):
+        (WTFHashTableProvider.update):
+        (WTFHashTableProvider.has_children):
+
 2013-02-01  Roger Fong  <roger_fong@apple.com>
 
         Unreviewed. Fix webkitpy tests since a build_style is not specified in some cases.
index 37844f8..4adc438 100644 (file)
@@ -37,7 +37,9 @@ 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.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 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):
@@ -58,6 +60,11 @@ def WTFVector_SummaryProvider(valobj, dict):
     provider = WTFVectorProvider(valobj, dict)
     return "{ size = %d, capacity = %d }" % (provider.size, provider.capacity)
 
+
+def WTFHashTable_SummaryProvider(valobj, dict):
+    provider = WTFHashTableProvider(valobj, dict)
+    return "{ tableSize = %d, keyCount = %d }" % (provider.tableSize(), provider.keyCount())
+
 # FIXME: Provide support for the following types:
 # def WTFVector_SummaryProvider(valobj, dict):
 # def WTFCString_SummaryProvider(valobj, dict):
@@ -190,3 +197,56 @@ class WTFVectorProvider:
 
     def has_children(self):
         return True
+
+
+class WTFHashTableProvider:
+    def __init__(self, valobj, internal_dict):
+        self.valobj = valobj
+        self.update()
+
+    def num_children(self):
+        return self.tableSize() + 5
+
+    def get_child_index(self, name):
+        if name == "m_table":
+            return self.tableSize()
+        elif name == "m_tableSize":
+            return self.tableSize() + 1
+        elif name == "m_tableSizeMask":
+            return self.tableSize() + 2
+        elif name == "m_keyCount":
+            return self.tableSize() + 3
+        elif name == "m_deletedCount":
+            return self.tableSize() + 4
+        else:
+            return int(name.lstrip('[').rstrip(']'))
+
+    def get_child_at_index(self, index):
+        if index == self.tableSize():
+            return self.valobj.GetChildMemberWithName('m_table')
+        elif index == self.tableSize() + 1:
+            return self.valobj.GetChildMemberWithName('m_tableSize')
+        elif index == self.tableSize() + 2:
+            return self.valobj.GetChildMemberWithName('m_tableSizeMask')
+        elif index == self.tableSize() + 3:
+            return self.valobj.GetChildMemberWithName('m_keyCount')
+        elif index == self.tableSize() + 4:
+            return self.valobj.GetChildMemberWithName('m_deletedCount')
+        elif index < self.tableSize():
+            table = self.valobj.GetChildMemberWithName('m_table')
+            return table.CreateChildAtOffset('[' + str(index) + ']', index * self.data_size, self.data_type)
+        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_size = self.data_type.GetByteSize()
+
+    def has_children(self):
+        return True