Title: [152366] trunk/Tools
Revision
152366
Author
[email protected]
Date
2013-07-03 10:28:43 -0700 (Wed, 03 Jul 2013)

Log Message

Xcode often gets in a state where the debugger is completely unresponsive
https://bugs.webkit.org/show_bug.cgi?id=118157

The GetPointeeData() operations we use to retrieve strings is extremely expensive.
Rather than pull the character data out of the debugger one byte at a time
through the GetPointeeData() API, retrieve the memory contents of the string through
the ReadMemory() API, and convert the retrieved memory into a python string.

Reviewed by Anders Carlsson.

* lldb/lldb_webkit.py:
(__lldb_init_module.lldb_webkit):
(guess_string_length):
(ustring_to_string):
(lstring_to_string):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (152365 => 152366)


--- trunk/Tools/ChangeLog	2013-07-03 17:28:10 UTC (rev 152365)
+++ trunk/Tools/ChangeLog	2013-07-03 17:28:43 UTC (rev 152366)
@@ -1,3 +1,21 @@
+2013-07-03  Jer Noble  <[email protected]>
+
+        Xcode often gets in a state where the debugger is completely unresponsive
+        https://bugs.webkit.org/show_bug.cgi?id=118157
+
+        The GetPointeeData() operations we use to retrieve strings is extremely expensive.
+        Rather than pull the character data out of the debugger one byte at a time
+        through the GetPointeeData() API, retrieve the memory contents of the string through
+        the ReadMemory() API, and convert the retrieved memory into a python string.
+
+        Reviewed by Anders Carlsson.
+
+        * lldb/lldb_webkit.py:
+        (__lldb_init_module.lldb_webkit):
+        (guess_string_length):
+        (ustring_to_string):
+        (lstring_to_string):
+
 2013-07-03  Morten Stenshorne  <[email protected]>
 
         [GTK] Let F5 refresh the page in MiniBrowser

Modified: trunk/Tools/lldb/lldb_webkit.py (152365 => 152366)


--- trunk/Tools/lldb/lldb_webkit.py	2013-07-03 17:28:10 UTC (rev 152365)
+++ trunk/Tools/lldb/lldb_webkit.py	2013-07-03 17:28:43 UTC (rev 152366)
@@ -30,8 +30,8 @@
 """
 
 import lldb
+import struct
 
-
 def __lldb_init_module(debugger, dict):
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFString_SummaryProvider WTF::String')
     debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFStringImpl_SummaryProvider WTF::StringImpl')
@@ -41,7 +41,6 @@
     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)
     return "{ length = %d, contents = '%s' }" % (provider.get_length(), provider.to_string())
@@ -74,45 +73,56 @@
 # def JSCJSString_SummaryProvider(valobj, dict):
 
 
-def guess_string_length(valobj, error):
+def guess_string_length(valobj, charSize, error):
     if not valobj.GetValue():
         return 0
 
-    for i in xrange(0, 2048):
-        if valobj.GetPointeeData(i, 1).GetUnsignedInt16(error, 0) == 0:
+    maxLength = 256
+
+    pointer = valobj.GetValueAsUnsigned()
+    contents = valobj.GetProcess().ReadMemory(pointer, maxLength * charSize, lldb.SBError())
+    format = 'B' if charSize == 1 else 'H'
+
+    for i in xrange(0, maxLength):
+        if not struct.unpack_from(format, contents, i * charSize)[0]:
             return i
 
-    return 256
+    return maxLength
 
-
 def ustring_to_string(valobj, error, length=None):
     if length is None:
-        length = guess_string_length(valobj, error)
+        length = guess_string_length(valobj, 2, error)
     else:
         length = int(length)
 
-    out_string = u""
-    for i in xrange(0, length):
-        char_value = valobj.GetPointeeData(i, 1).GetUnsignedInt16(error, 0)
-        out_string = out_string + unichr(char_value)
+    pointer = valobj.GetValueAsUnsigned()
+    contents = valobj.GetProcess().ReadMemory(pointer, length * 2, lldb.SBError())
 
-    return out_string.encode('utf-8')
+    # lldb does not (currently) support returning unicode from python summary providers,
+    # so potentially convert this to ascii by escaping
+    string = contents.decode('utf16')
+    try:
+        return str(string)
+    except:
+        return string.encode('unicode_escape')
 
-
 def lstring_to_string(valobj, error, length=None):
     if length is None:
-        length = guess_string_length(valobj, error)
+        length = guess_string_length(valobj, 1, error)
     else:
         length = int(length)
 
-    out_string = u""
-    for i in xrange(0, length):
-        char_value = valobj.GetPointeeData(i, 1).GetUnsignedInt8(error, 0)
-        out_string = out_string + unichr(char_value)
+    pointer = valobj.GetValueAsUnsigned()
+    contents = valobj.GetProcess().ReadMemory(pointer, length, lldb.SBError())
 
-    return out_string.encode('utf-8')
+    # lldb does not (currently) support returning unicode from python summary providers,
+    # so potentially convert this to ascii by escaping
+    string = contents.decode('utf8')
+    try:
+        return str(string)
+    except:
+        return string.encode('unicode_escape')
 
-
 class WTFStringImplProvider:
     def __init__(self, valobj, dict):
         self.valobj = valobj
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to