Dumper: replace xrange with range

Change-Id: I09b3dd4da548643e927dbc5bb3130c28a746396b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2020-02-24 10:37:40 +01:00
committed by Christian Stenger
parent 72d5708388
commit 4422805cec
7 changed files with 32 additions and 33 deletions

View File

@@ -353,7 +353,7 @@ class Dumper(DumperBase):
def putVTableChildren(self, item, itemCount): def putVTableChildren(self, item, itemCount):
p = item.address() p = item.address()
for i in xrange(itemCount): for i in range(itemCount):
deref = self.extractPointer(p) deref = self.extractPointer(p)
if deref == 0: if deref == 0:
n = i n = i

View File

@@ -48,7 +48,6 @@ except ModuleNotFoundError:
if sys.version_info[0] >= 3: if sys.version_info[0] >= 3:
xrange = range
toInteger = int toInteger = int
else: else:
toInteger = long toInteger = long
@@ -306,8 +305,8 @@ class DumperBase:
def childRange(self): def childRange(self):
if self.currentMaxNumChild is None: if self.currentMaxNumChild is None:
return xrange(0, self.currentNumChild) return range(0, self.currentNumChild)
return xrange(min(self.currentMaxNumChild, self.currentNumChild)) return range(min(self.currentMaxNumChild, self.currentNumChild))
def enterSubItem(self, item): def enterSubItem(self, item):
if self.useTimeStamps: if self.useTimeStamps:
@@ -820,7 +819,7 @@ class DumperBase:
def putVTableChildren(self, item, itemCount): def putVTableChildren(self, item, itemCount):
p = item.pointer() p = item.pointer()
for i in xrange(itemCount): for i in range(itemCount):
deref = self.extractPointer(p) deref = self.extractPointer(p)
if deref == 0: if deref == 0:
itemCount = i itemCount = i
@@ -901,7 +900,7 @@ class DumperBase:
self.warn('REDUCING READING MAXIMUM TO %s' % maximum) self.warn('REDUCING READING MAXIMUM TO %s' % maximum)
#DumperBase.warn('BASE: 0x%x TSIZE: %s MAX: %s' % (base, tsize, maximum)) #DumperBase.warn('BASE: 0x%x TSIZE: %s MAX: %s' % (base, tsize, maximum))
for i in xrange(0, maximum, tsize): for i in range(0, maximum, tsize):
t = struct.unpack_from(code, blob, i)[0] t = struct.unpack_from(code, blob, i)[0]
if t == 0: if t == 0:
return 0, i, self.hexencode(blob[:i]) return 0, i, self.hexencode(blob[:i])
@@ -2090,7 +2089,7 @@ class DumperBase:
base = self.extractPointer(connections) base = self.extractPointer(connections)
data, size, alloc = self.vectorDataHelper(base) data, size, alloc = self.vectorDataHelper(base)
connectionType = self.createType('@QObjectPrivate::Connection') connectionType = self.createType('@QObjectPrivate::Connection')
for i in xrange(size): for i in range(size):
first = self.extractPointer(data + i * 2 * ptrSize) first = self.extractPointer(data + i * 2 * ptrSize)
while first: while first:
self.putSubItem('%s' % pp, self.putSubItem('%s' % pp,
@@ -2193,7 +2192,7 @@ class DumperBase:
if self.currentIName in self.expandedINames: if self.currentIName in self.expandedINames:
p = value p = value
with Children(self, n): with Children(self, n):
for i in xrange(n): for i in range(n):
self.putSubItem(i, p.dereference()) self.putSubItem(i, p.dereference())
p += 1 p += 1
@@ -2340,7 +2339,7 @@ class DumperBase:
self.putField('exp', exp) self.putField('exp', exp)
self.putItemCount(n) self.putItemCount(n)
self.putNoType() self.putNoType()
for i in xrange(n): for i in range(n):
self.handleWatch(exps[i], exps[i], '%s.%d' % (iname, i)) self.handleWatch(exps[i], exps[i], '%s.%d' % (iname, i))
return return

View File

@@ -101,7 +101,7 @@ PPPCommand()
def scanStack(p, n): def scanStack(p, n):
p = int(p) p = int(p)
r = [] r = []
for i in xrange(n): for i in range(n):
f = gdb.parse_and_eval('{void*}%s' % p) f = gdb.parse_and_eval('{void*}%s' % p)
m = gdb.execute('info symbol %s' % f, to_string=True) m = gdb.execute('info symbol %s' % f, to_string=True)
if not m.startswith('No symbol matches'): if not m.startswith('No symbol matches'):

View File

@@ -810,7 +810,7 @@ class Dumper(DumperBase):
needle = self.canonicalTypeName(name) needle = self.canonicalTypeName(name)
#DumperBase.warn('NEEDLE: %s ' % needle) #DumperBase.warn('NEEDLE: %s ' % needle)
self.warn('Searching for type %s across all target modules, this could be very slow' % name) self.warn('Searching for type %s across all target modules, this could be very slow' % name)
for i in xrange(self.target.GetNumModules()): for i in range(self.target.GetNumModules()):
module = self.target.GetModuleAtIndex(i) module = self.target.GetModuleAtIndex(i)
# SBModule.GetType is new somewhere after early 300.x # SBModule.GetType is new somewhere after early 300.x
# So this may fail. # So this may fail.
@@ -1000,7 +1000,7 @@ class Dumper(DumperBase):
return None if thread is None else thread.GetSelectedFrame() return None if thread is None else thread.GetSelectedFrame()
def firstStoppedThread(self): def firstStoppedThread(self):
for i in xrange(0, self.process.GetNumThreads()): for i in range(0, self.process.GetNumThreads()):
thread = self.process.GetThreadAtIndex(i) thread = self.process.GetThreadAtIndex(i)
reason = thread.GetStopReason() reason = thread.GetStopReason()
if (reason == lldb.eStopReasonBreakpoint or if (reason == lldb.eStopReasonBreakpoint or
@@ -1013,7 +1013,7 @@ class Dumper(DumperBase):
def fetchThreads(self, args): def fetchThreads(self, args):
result = 'threads=[' result = 'threads=['
for i in xrange(0, self.process.GetNumThreads()): for i in range(0, self.process.GetNumThreads()):
thread = self.process.GetThreadAtIndex(i) thread = self.process.GetThreadAtIndex(i)
if thread.is_stopped: if thread.is_stopped:
state = 'stopped' state = 'stopped'
@@ -1043,7 +1043,7 @@ class Dumper(DumperBase):
self.reportResult(result, args) self.reportResult(result, args)
def firstUsableFrame(self, thread): def firstUsableFrame(self, thread):
for i in xrange(10): for i in range(10):
frame = thread.GetFrameAtIndex(i) frame = thread.GetFrameAtIndex(i)
lineEntry = frame.GetLineEntry() lineEntry = frame.GetLineEntry()
line = lineEntry.GetLine() line = lineEntry.GetLine()
@@ -1067,7 +1067,7 @@ class Dumper(DumperBase):
self.currentCallContext = None self.currentCallContext = None
result = 'stack={current-thread="%s"' % thread.GetThreadID() result = 'stack={current-thread="%s"' % thread.GetThreadID()
result += ',frames=[' result += ',frames=['
for i in xrange(n): for i in range(n):
frame = thread.GetFrameAtIndex(i) frame = thread.GetFrameAtIndex(i)
if not frame.IsValid(): if not frame.IsValid():
isLimited = False isLimited = False
@@ -1183,7 +1183,7 @@ class Dumper(DumperBase):
with Children(self): with Children(self):
statics = frame.GetVariables(False, False, True, False) statics = frame.GetVariables(False, False, True, False)
if len(statics): if len(statics):
for i in xrange(len(statics)): for i in range(len(statics)):
staticVar = statics[i] staticVar = statics[i]
staticVar.SetPreferSyntheticValue(False) staticVar.SetPreferSyntheticValue(False)
typename = staticVar.GetType().GetName() typename = staticVar.GetType().GetName()
@@ -1408,7 +1408,7 @@ class Dumper(DumperBase):
if bp.IsValid() and isinstance(bp, lldb.SBBreakpoint): if bp.IsValid() and isinstance(bp, lldb.SBBreakpoint):
result += ',locations=[' result += ',locations=['
lineEntry = None lineEntry = None
for i in xrange(bp.GetNumLocations()): for i in range(bp.GetNumLocations()):
loc = bp.GetLocationAtIndex(i) loc = bp.GetLocationAtIndex(i)
addr = loc.GetAddress() addr = loc.GetAddress()
lineEntry = addr.GetLineEntry() lineEntry = addr.GetLineEntry()
@@ -1539,7 +1539,7 @@ class Dumper(DumperBase):
def fetchModules(self, args): def fetchModules(self, args):
result = 'modules=[' result = 'modules=['
for i in xrange(self.target.GetNumModules()): for i in range(self.target.GetNumModules()):
module = self.target.GetModuleAtIndex(i) module = self.target.GetModuleAtIndex(i)
result += '{file="%s"' % module.file.fullpath result += '{file="%s"' % module.file.fullpath
result += ',name="%s"' % module.file.basename result += ',name="%s"' % module.file.basename
@@ -1559,7 +1559,7 @@ class Dumper(DumperBase):
moduleName = args['module'] moduleName = args['module']
#file = lldb.SBFileSpec(moduleName) #file = lldb.SBFileSpec(moduleName)
#module = self.target.FindModule(file) #module = self.target.FindModule(file)
for i in xrange(self.target.GetNumModules()): for i in range(self.target.GetNumModules()):
module = self.target.GetModuleAtIndex(i) module = self.target.GetModuleAtIndex(i)
if module.file.fullpath == moduleName: if module.file.fullpath == moduleName:
break break
@@ -1872,7 +1872,7 @@ class Tester(Dumper):
break break
if state == lldb.eStateStopped: # 5 if state == lldb.eStateStopped: # 5
stoppedThread = None stoppedThread = None
for i in xrange(0, self.process.GetNumThreads()): for i in range(0, self.process.GetNumThreads()):
thread = self.process.GetThreadAtIndex(i) thread = self.process.GetThreadAtIndex(i)
reason = thread.GetStopReason() reason = thread.GetStopReason()
#DumperBase.warn('THREAD: %s REASON: %s' % (thread, reason)) #DumperBase.warn('THREAD: %s REASON: %s' % (thread, reason))

View File

@@ -65,7 +65,7 @@ def qdump____m512d(d, value):
def qdump____m128i(d, value): def qdump____m128i(d, value):
data = d.hexencode(value.data(16)) data = d.hexencode(value.data(16))
d.putValue(':'.join('%04x' % int(data[i:i+4], 16) for i in xrange(0, 32, 4))) d.putValue(':'.join('%04x' % int(data[i:i+4], 16) for i in range(0, 32, 4)))
if d.isExpanded(): if d.isExpanded():
with Children(d): with Children(d):
addr = value.address() addr = value.address()
@@ -76,7 +76,7 @@ def qdump____m128i(d, value):
def qdump____m256i(d, value): def qdump____m256i(d, value):
data = d.hexencode(value.data(32)) data = d.hexencode(value.data(32))
d.putValue(':'.join('%04x' % int(data[i:i+4], 16) for i in xrange(0, 64, 4))) d.putValue(':'.join('%04x' % int(data[i:i+4], 16) for i in range(0, 64, 4)))
if d.isExpanded(): if d.isExpanded():
with Children(d): with Children(d):
addr = value.address() addr = value.address()
@@ -87,8 +87,8 @@ def qdump____m256i(d, value):
def qdump____m512i(d, value): def qdump____m512i(d, value):
data = d.hexencode(value.data(64)) data = d.hexencode(value.data(64))
d.putValue(':'.join('%04x' % int(data[i:i+4], 16) for i in xrange(0, 64, 4)) d.putValue(':'.join('%04x' % int(data[i:i+4], 16) for i in range(0, 64, 4))
+ ', ' + ':'.join('%04x' % int(data[i:i+4], 16) for i in xrange(64, 128, 4))) + ', ' + ':'.join('%04x' % int(data[i:i+4], 16) for i in range(64, 128, 4)))
if d.isExpanded(): if d.isExpanded():
with Children(d): with Children(d):
d.putArrayItem('uint32x16', value.address(), 16, 'unsigned int') d.putArrayItem('uint32x16', value.address(), 16, 'unsigned int')
@@ -279,14 +279,14 @@ if False:
d.putNoType() d.putNoType()
if d.isExpanded(): if d.isExpanded():
with Children(d): with Children(d):
for i in xrange(count): for i in range(count):
d.putSubItem(Item(entries[i], iname)) d.putSubItem(Item(entries[i], iname))
with SubItem(d, 'data'): with SubItem(d, 'data'):
d.putEmptyValue() d.putEmptyValue()
d.putNoType() d.putNoType()
if d.isExpanded(): if d.isExpanded():
with Children(d): with Children(d):
for i in xrange(count): for i in range(count):
with SubItem(d, i): with SubItem(d, i):
entry = entries[i] entry = entries[i]
mpitype = str(entry['type']) mpitype = str(entry['type'])

View File

@@ -126,8 +126,8 @@ def qdump_X_QAbstractItemModel(d, value):
if d.isExpanded(): if d.isExpanded():
with Children(d, numChild=rowCount * columnCount, childType=ri.type): with Children(d, numChild=rowCount * columnCount, childType=ri.type):
i = 0 i = 0
for row in xrange(rowCount): for row in range(rowCount):
for column in xrange(columnCount): for column in range(columnCount):
with SubItem(d, i): with SubItem(d, i):
d.putName('[%s, %s]' % (row, column)) d.putName('[%s, %s]' % (row, column))
mi = d.parseAndEvaluate('%s.index(%d,%d,%s)' mi = d.parseAndEvaluate('%s.index(%d,%d,%s)'
@@ -182,8 +182,8 @@ def qdump_X_QModelIndex(d, value):
with Children(d): with Children(d):
d.putFields(value, False) d.putFields(value, False)
i = 0 i = 0
for row in xrange(rowCount): for row in range(rowCount):
for column in xrange(columnCount): for column in range(columnCount):
with UnnamedSubItem(d, i): with UnnamedSubItem(d, i):
d.putName('[%s, %s]' % (row, column)) d.putName('[%s, %s]' % (row, column))
mi2 = d.parseAndEvaluate('%s.index(%d,%d,%s)' mi2 = d.parseAndEvaluate('%s.index(%d,%d,%s)'
@@ -912,7 +912,7 @@ def qdump__QHostAddress(d, value):
if protocol == 1: if protocol == 1:
# value.d.d->a6 # value.d.d->a6
data = d.hexencode(a6) data = d.hexencode(a6)
address = ':'.join('%x' % int(data[i:i+4], 16) for i in xrange(0, 32, 4)) address = ':'.join('%x' % int(data[i:i+4], 16) for i in range(0, 32, 4))
d.putValue(address) d.putValue(address)
elif protocol == 0: elif protocol == 0:
# value.d.d->a # value.d.d->a
@@ -938,7 +938,7 @@ def qdump__QHostAddress(d, value):
def qdump__QIPv6Address(d, value): def qdump__QIPv6Address(d, value):
raw = d.split('16s', value)[0] raw = d.split('16s', value)[0]
data = d.hexencode(raw) data = d.hexencode(raw)
d.putValue(':'.join('%x' % int(data[i:i+4], 16) for i in xrange(0, 32, 4))) d.putValue(':'.join('%x' % int(data[i:i+4], 16) for i in range(0, 32, 4)))
d.putArrayData(value.address(), 16, d.lookupType('unsigned char')) d.putArrayData(value.address(), 16, d.lookupType('unsigned char'))
def qform__QList(): def qform__QList():

View File

@@ -1160,7 +1160,7 @@ def qdump____gnu_cxx__hash_set(d, value):
bucketFinish = buckets["_M_finish"] bucketFinish = buckets["_M_finish"]
p = bucketStart p = bucketStart
itemCount = 0 itemCount = 0
for i in xrange((bucketFinish.pointer() - bucketStart.pointer()) // d.ptrSize()): for i in range((bucketFinish.pointer() - bucketStart.pointer()) // d.ptrSize()):
if p.dereference().pointer(): if p.dereference().pointer():
cur = p.dereference() cur = p.dereference()
while cur.pointer(): while cur.pointer():