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

Side by Side Diff: Tools/gdb/webkit.py

Issue 313833003: Tools gdb script renamed class xrange to range for python3.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 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) 2010, Google Inc. All rights reserved. 1 # Copyright (C) 2010, Google Inc. 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 are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 22 matching lines...) Expand all
33 import sys 33 import sys
34 sys.path.insert(0, "/path/to/tools/gdb/") 34 sys.path.insert(0, "/path/to/tools/gdb/")
35 import webkit 35 import webkit
36 """ 36 """
37 37
38 from __future__ import print_function 38 from __future__ import print_function
39 39
40 import gdb 40 import gdb
41 import re 41 import re
42 import struct 42 import struct
43 import sys
44
45
46 def rangeHandler(start, end=0):
hayato 2014/06/05 03:28:39 Th default value, end=0, looks strange to me. If
Habib Virji 2014/06/05 08:59:57 Done.
47 if sys.version < '3':
hayato 2014/06/05 03:28:39 You should use sys.version_info.
Habib Virji 2014/06/05 08:59:57 Done.
48 return xrange(start, end)
49 else:
50 return list(range(start, end))
hayato 2014/06/05 03:28:39 This should be range(start, end)
Habib Virji 2014/06/05 08:59:57 Done.
43 51
44 52
45 def guess_string_length(ptr): 53 def guess_string_length(ptr):
46 """Guess length of string pointed by ptr. 54 """Guess length of string pointed by ptr.
47 55
48 Returns a tuple of (length, an error message). 56 Returns a tuple of (length, an error message).
49 """ 57 """
50 # Try to guess at the length. 58 # Try to guess at the length.
51 for i in xrange(0, 2048): 59 for i in rangeHandler(0, 2048):
52 try: 60 try:
53 if int((ptr + i).dereference()) == 0: 61 if int((ptr + i).dereference()) == 0:
54 return i, '' 62 return i, ''
55 except RuntimeError: 63 except RuntimeError:
56 # We indexed into inaccessible memory; give up. 64 # We indexed into inaccessible memory; give up.
57 return i, ' (gdb hit inaccessible memory)' 65 return i, ' (gdb hit inaccessible memory)'
58 return 256, ' (gdb found no trailing NUL)' 66 return 256, ' (gdb found no trailing NUL)'
59 67
60 68
61 def ustring_to_string(ptr, length=None): 69 def ustring_to_string(ptr, length=None):
62 """Convert a pointer to UTF-16 data into a Python string encoded with utf-8. 70 """Convert a pointer to UTF-16 data into a Python string encoded with utf-8.
63 71
64 ptr and length are both gdb.Value objects. 72 ptr and length are both gdb.Value objects.
65 If length is unspecified, will guess at the length.""" 73 If length is unspecified, will guess at the length."""
66 error_message = '' 74 error_message = ''
67 if length is None: 75 if length is None:
68 length, error_message = guess_string_length(ptr) 76 length, error_message = guess_string_length(ptr)
69 else: 77 else:
70 length = int(length) 78 length = int(length)
71 char_vals = [int((ptr + i).dereference()) for i in xrange(length)] 79 char_vals = [int((ptr + i).dereference()) for i in rangeHandler(length)]
72 string = struct.pack('H' * length, *char_vals).decode('utf-16', 'replace').e ncode('utf-8') 80 string = struct.pack('H' * length, *char_vals).decode('utf-16', 'replace').e ncode('utf-8')
73 return string + error_message 81 return string + error_message
74 82
75 83
76 def lstring_to_string(ptr, length=None): 84 def lstring_to_string(ptr, length=None):
77 """Convert a pointer to LChar* data into a Python (non-Unicode) string. 85 """Convert a pointer to LChar* data into a Python (non-Unicode) string.
78 86
79 ptr and length are both gdb.Value objects. 87 ptr and length are both gdb.Value objects.
80 If length is unspecified, will guess at the length.""" 88 If length is unspecified, will guess at the length."""
81 error_message = '' 89 error_message = ''
82 if length is None: 90 if length is None:
83 length, error_message = guess_string_length(ptr) 91 length, error_message = guess_string_length(ptr)
84 else: 92 else:
85 length = int(length) 93 length = int(length)
86 string = ''.join([chr((ptr + i).dereference()) for i in xrange(length)]) 94 string = ''.join([chr((ptr + i).dereference()) for i in rangeHandler(length) ])
87 return string + error_message 95 return string + error_message
88 96
89 97
90 class StringPrinter(object): 98 class StringPrinter(object):
91 "Shared code between different string-printing classes" 99 "Shared code between different string-printing classes"
92 def __init__(self, val): 100 def __init__(self, val):
93 self.val = val 101 self.val = val
94 102
95 def display_hint(self): 103 def display_hint(self):
96 return 'string' 104 return 'string'
(...skipping 16 matching lines...) Expand all
113 def to_string(self): 121 def to_string(self):
114 return self.val['m_string'] 122 return self.val['m_string']
115 123
116 124
117 class WTFCStringPrinter(StringPrinter): 125 class WTFCStringPrinter(StringPrinter):
118 "Print a WTF::CString" 126 "Print a WTF::CString"
119 def to_string(self): 127 def to_string(self):
120 # The CString holds a buffer, which is a refptr to a WTF::CStringBuffer. 128 # The CString holds a buffer, which is a refptr to a WTF::CStringBuffer.
121 data = self.val['m_buffer']['m_ptr']['m_data'].cast(gdb.lookup_type('cha r').pointer()) 129 data = self.val['m_buffer']['m_ptr']['m_data'].cast(gdb.lookup_type('cha r').pointer())
122 length = self.val['m_buffer']['m_ptr']['m_length'] 130 length = self.val['m_buffer']['m_ptr']['m_length']
123 return ''.join([chr((data + i).dereference()) for i in xrange(length)]) 131 return ''.join([chr((data + i).dereference()) for i in rangeHandler(leng th)])
124 132
125 133
126 class WTFStringImplPrinter(StringPrinter): 134 class WTFStringImplPrinter(StringPrinter):
127 "Print a WTF::StringImpl" 135 "Print a WTF::StringImpl"
128 def get_length(self): 136 def get_length(self):
129 return self.val['m_length'] 137 return self.val['m_length']
130 138
131 def to_string(self): 139 def to_string(self):
132 chars_start = self.val.address + 1 140 chars_start = self.val.address + 1
133 if self.is_8bit(): 141 if self.is_8bit():
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 padding = '' 384 padding = ''
377 while len(stack) > 0: 385 while len(stack) > 0:
378 pair = stack.pop() 386 pair = stack.pop()
379 print(padding, pair[1], pair[0]) 387 print(padding, pair[1], pair[0])
380 padding = padding + ' ' 388 padding = padding + ' '
381 else: 389 else:
382 print('Sorry: I don\'t know how to deal with %s yet.' % target_type) 390 print('Sorry: I don\'t know how to deal with %s yet.' % target_type)
383 391
384 392
385 PrintPathToRootCommand() 393 PrintPathToRootCommand()
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