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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2012 Apple. All rights reserved. 1 # Copyright (C) 2012 Apple. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions 4 # modification, are permitted provided that the following conditions
5 # are met: 5 # are met:
6 # 1. Redistributions of source code must retain the above copyright 6 # 1. Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright 8 # 2. Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the 9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution. 10 # documentation and/or other materials provided with the distribution.
(...skipping 12 matching lines...) Expand all
23 """ 23 """
24 LLDB Support for WebKit Types 24 LLDB Support for WebKit Types
25 25
26 Add the following to your .lldbinit file to add WebKit Type summaries in LLD B and Xcode: 26 Add the following to your .lldbinit file to add WebKit Type summaries in LLD B and Xcode:
27 27
28 command script import {Path to WebKit Root}/Tools/lldb/lldb_webkit.py 28 command script import {Path to WebKit Root}/Tools/lldb/lldb_webkit.py
29 29
30 """ 30 """
31 31
32 import lldb 32 import lldb
33 import struct
33 34
34 35
35 def __lldb_init_module(debugger, dict): 36 def __lldb_init_module(debugger, dict):
36 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFString_S ummaryProvider WTF::String') 37 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFString_S ummaryProvider WTF::String')
37 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFStringIm pl_SummaryProvider WTF::StringImpl') 38 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFStringIm pl_SummaryProvider WTF::StringImpl')
38 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFAtomicSt ring_SummaryProvider WTF::AtomicString') 39 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFAtomicSt ring_SummaryProvider WTF::AtomicString')
39 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFVector_S ummaryProvider -x "WTF::Vector<.+>$"') 40 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFVector_S ummaryProvider -x "WTF::Vector<.+>$"')
40 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFHashTabl e_SummaryProvider -x "WTF::HashTable<.+>$"') 41 debugger.HandleCommand('type summary add --expand -F lldb_webkit.WTFHashTabl e_SummaryProvider -x "WTF::HashTable<.+>$"')
41 debugger.HandleCommand('type synthetic add -x "WTF::Vector<.+>$" --python-cl ass lldb_webkit.WTFVectorProvider') 42 debugger.HandleCommand('type synthetic add -x "WTF::Vector<.+>$" --python-cl ass lldb_webkit.WTFVectorProvider')
42 debugger.HandleCommand('type synthetic add -x "WTF::HashTable<.+>$" --python -class lldb_webkit.WTFHashTableProvider') 43 debugger.HandleCommand('type synthetic add -x "WTF::HashTable<.+>$" --python -class lldb_webkit.WTFHashTableProvider')
(...skipping 24 matching lines...) Expand all
67 68
68 # FIXME: Provide support for the following types: 69 # FIXME: Provide support for the following types:
69 # def WTFVector_SummaryProvider(valobj, dict): 70 # def WTFVector_SummaryProvider(valobj, dict):
70 # def WTFCString_SummaryProvider(valobj, dict): 71 # def WTFCString_SummaryProvider(valobj, dict):
71 # def WebCoreKURLGooglePrivate_SummaryProvider(valobj, dict): 72 # def WebCoreKURLGooglePrivate_SummaryProvider(valobj, dict):
72 # def WebCoreQualifiedName_SummaryProvider(valobj, dict): 73 # def WebCoreQualifiedName_SummaryProvider(valobj, dict):
73 # def JSCIdentifier_SummaryProvider(valobj, dict): 74 # def JSCIdentifier_SummaryProvider(valobj, dict):
74 # def JSCJSString_SummaryProvider(valobj, dict): 75 # def JSCJSString_SummaryProvider(valobj, dict):
75 76
76 77
77 def guess_string_length(valobj, error):
78 if not valobj.GetValue():
79 return 0
80
81 for i in xrange(0, 2048):
82 if valobj.GetPointeeData(i, 1).GetUnsignedInt16(error, 0) == 0:
83 return i
84
85 return 256
86
87
88 def ustring_to_string(valobj, error, length=None):
89 if length is None:
90 length = guess_string_length(valobj, error)
91 else:
92 length = int(length)
93
94 out_string = u""
95 for i in xrange(0, length):
96 char_value = valobj.GetPointeeData(i, 1).GetUnsignedInt16(error, 0)
97 out_string = out_string + unichr(char_value)
98
99 return out_string.encode('utf-8')
100
101
102 def lstring_to_string(valobj, error, length=None):
103 if length is None:
104 length = guess_string_length(valobj, error)
105 else:
106 length = int(length)
107
108 out_string = u""
109 for i in xrange(0, length):
110 char_value = valobj.GetPointeeData(i, 1).GetUnsignedInt8(error, 0)
111 out_string = out_string + unichr(char_value)
112
113 return out_string.encode('utf-8')
114
115
116 class WTFStringImplProvider: 78 class WTFStringImplProvider:
117 def __init__(self, valobj, dict): 79 def __init__(self, valobj, dict):
118 self.valobj = valobj 80 self.valobj = valobj
119 81
120 def get_length(self): 82 def get_length(self):
121 return self.valobj.GetChildMemberWithName('m_length').GetValueAsUnsigned (0) 83 return self.valobj.GetChildMemberWithName('m_length').GetValueAsUnsigned (0)
122 84
85 def get_data(self, length):
86 offset = 12
87 # Try to get the address of the object.
88 addr = self.valobj.GetAddress()
89 # If address == 0 then the object is a pointer so we can use it's
90 # value instead. We need to offset the pointer so it points to
91 # raw string data.
92 ptr = (int(str(addr), 16) if addr else self.valobj.GetValueAsUnsigned(0) ) + offset
93 error = lldb.SBError()
94 # Read the raw data from memory.
95 return self.valobj.GetTarget().GetProcess().ReadMemory(ptr, length, erro r)
96
123 def get_data8(self): 97 def get_data8(self):
124 return self.valobj.GetChildAtIndex(2).GetChildMemberWithName('m_data8') 98 return self.get_data(self.get_length())
125 99
126 def get_data16(self): 100 def get_data16(self):
127 return self.valobj.GetChildAtIndex(2).GetChildMemberWithName('m_data16') 101 length = self.get_length()
102 # Read raw string data.
103 data = self.get_data(2 * length)
104 # Create a list of length 2-byte unsigned integers from byte array.
105 ushort_list = struct.unpack(length * 'H', data)
106 # Return the string.
107 return u"".join(map(unichr, ushort_list))
128 108
129 def to_string(self): 109 def to_string(self):
130 error = lldb.SBError() 110 error = lldb.SBError()
131 if self.is_8bit(): 111 data = self.get_data8() if self.is_8bit() else self.get_data16()
132 return lstring_to_string(self.get_data8(), error, self.get_length()) 112 return data.encode('utf-8')
133 return ustring_to_string(self.get_data16(), error, self.get_length())
134 113
135 def is_8bit(self): 114 def is_8bit(self):
136 # FIXME: find a way to access WTF::StringImpl::s_hashFlag8BitBuffer 115 return bool(self.valobj.GetChildMemberWithName('m_is8Bit').GetValueAsUns igned(0))
137 return bool(self.valobj.GetChildMemberWithName('m_hashAndFlags').GetValu eAsUnsigned(0) \
138 & 1 << 6)
139 116
140 117
141 class WTFStringProvider: 118 class WTFStringProvider:
142 def __init__(self, valobj, dict): 119 def __init__(self, valobj, dict):
143 self.valobj = valobj 120 self.valobj = valobj
144 121
145 def stringimpl(self): 122 def stringimpl(self):
146 impl_ptr = self.valobj.GetChildMemberWithName('m_impl').GetChildMemberWi thName('m_ptr') 123 impl_ptr = self.valobj.GetChildMemberWithName('m_impl').GetChildMemberWi thName('m_ptr')
147 return WTFStringImplProvider(impl_ptr, dict) 124 return WTFStringImplProvider(impl_ptr, dict)
148 125
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 220
244 def keyCount(self): 221 def keyCount(self):
245 return self.valobj.GetChildMemberWithName('m_keyCount').GetValueAsUnsign ed(0) 222 return self.valobj.GetChildMemberWithName('m_keyCount').GetValueAsUnsign ed(0)
246 223
247 def update(self): 224 def update(self):
248 self.data_type = self.valobj.GetType().GetTemplateArgumentType(0) 225 self.data_type = self.valobj.GetType().GetTemplateArgumentType(0)
249 self.data_size = self.data_type.GetByteSize() 226 self.data_size = self.data_type.GetByteSize()
250 227
251 def has_children(self): 228 def has_children(self):
252 return True 229 return True
OLDNEW
« 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