Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1875)

Unified Diff: Tools/lldb/lldb_webkit.py

Issue 24178002: Fix lldb string formatter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add comments. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Tools/lldb/lldb_webkit.py
diff --git a/Tools/lldb/lldb_webkit.py b/Tools/lldb/lldb_webkit.py
index 4adc4388350a6eb99aa4673a925519c020fc3831..1420a7a13780031e93223ec3dd651f53368ed6d4 100644
--- a/Tools/lldb/lldb_webkit.py
+++ b/Tools/lldb/lldb_webkit.py
@@ -30,6 +30,7 @@
"""
import lldb
+import struct
def __lldb_init_module(debugger, dict):
@@ -74,45 +75,6 @@ def WTFHashTable_SummaryProvider(valobj, dict):
# def JSCJSString_SummaryProvider(valobj, dict):
-def guess_string_length(valobj, error):
- if not valobj.GetValue():
- return 0
-
- for i in xrange(0, 2048):
- if valobj.GetPointeeData(i, 1).GetUnsignedInt16(error, 0) == 0:
- return i
-
- return 256
-
-
-def ustring_to_string(valobj, error, length=None):
- if length is None:
- length = guess_string_length(valobj, 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)
-
- return out_string.encode('utf-8')
-
-
-def lstring_to_string(valobj, error, length=None):
- if length is None:
- length = guess_string_length(valobj, 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)
-
- return out_string.encode('utf-8')
-
-
class WTFStringImplProvider:
def __init__(self, valobj, dict):
self.valobj = valobj
@@ -120,22 +82,37 @@ class WTFStringImplProvider:
def get_length(self):
return self.valobj.GetChildMemberWithName('m_length').GetValueAsUnsigned(0)
+ def get_data(self, length):
+ offset = 12
+ # Try to get the address of the object.
+ addr = self.valobj.GetAddress()
+ # If address == 0 then the object is a pointer so we can use it's
+ # value instead. We need to offset the pointer so it points to
+ # raw string data.
+ ptr = (int(str(addr), 16) if addr else self.valobj.GetValueAsUnsigned(0)) + offset
+ error = lldb.SBError()
+ # Read the raw data from memory.
+ return self.valobj.GetTarget().GetProcess().ReadMemory(ptr, length, error)
+
def get_data8(self):
- return self.valobj.GetChildAtIndex(2).GetChildMemberWithName('m_data8')
+ return self.get_data(self.get_length())
def get_data16(self):
- return self.valobj.GetChildAtIndex(2).GetChildMemberWithName('m_data16')
+ length = self.get_length()
+ # Read raw string data.
+ data = self.get_data(2 * length)
+ # Create a list of length 2-byte unsigned integers from byte array.
+ ushort_list = struct.unpack(length * 'H', data)
+ # Return the string.
+ return u"".join(map(unichr, ushort_list))
def to_string(self):
error = lldb.SBError()
- if self.is_8bit():
- return lstring_to_string(self.get_data8(), error, self.get_length())
- return ustring_to_string(self.get_data16(), error, self.get_length())
+ data = self.get_data8() if self.is_8bit() else self.get_data16()
+ return data.encode('utf-8')
def is_8bit(self):
- # FIXME: find a way to access WTF::StringImpl::s_hashFlag8BitBuffer
- return bool(self.valobj.GetChildMemberWithName('m_hashAndFlags').GetValueAsUnsigned(0) \
- & 1 << 6)
+ return bool(self.valobj.GetChildMemberWithName('m_is8Bit').GetValueAsUnsigned(0))
class WTFStringProvider:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698