Commit 2f009a30 authored by hjk's avatar hjk

debugger: remove custom 'select' function from dumpers

parent 185aaa7e
......@@ -10,7 +10,9 @@ import os
try:
import curses.ascii
def printableChar(ucs):
return select(curses.ascii.isprint(ucs), ucs, '?')
if curses.ascii.isprint(ucs):
return ucs
return '?'
except:
def printableChar(ucs):
if ucs >= 32 and ucs <= 126:
......@@ -78,11 +80,6 @@ DisplayProcess \
= range(5)
def select(condition, if_expr, else_expr):
if condition:
return if_expr
return else_expr
def isGoodGdb():
#return gdb.VERSION.startswith("6.8.50.2009") \
# and gdb.VERSION != "6.8.50.20090630-cvs"
......@@ -836,23 +833,22 @@ def qtNamespace():
except:
return ""
def findFirstZero(p, max):
for i in xrange(max):
def findFirstZero(p, maximum):
for i in xrange(maximum):
if p.dereference() == 0:
return i
p = p + 1
return -1
return maximum + 1
def extractCharArray(p, maxsize):
t = lookupType("unsigned char").pointer()
p = p.cast(t)
i = findFirstZero(p, maxsize)
limit = select(i < 0, maxsize, i)
limit = findFirstZero(p, maxsize)
s = ""
for i in xrange(limit):
s += "%c" % int(p.dereference())
p += 1
if i == maxsize:
if i > maxsize:
s += "..."
return s
......@@ -866,18 +862,13 @@ def extractByteArray(value):
if size > 0:
checkAccess(data, 4)
checkAccess(data + size) == 0
return extractCharArray(data, 1000, size)
return extractCharArray(data, min(100, size))
def encodeCharArray(p, maxsize, size = -1):
def encodeCharArray(p, maxsize, limit = -1):
t = lookupType("unsigned char").pointer()
p = p.cast(t)
if size == -1:
size = findFirstZero(p, maxsize)
if size == -1:
size = maxsize
limit = size
if size > maxsize:
limit = maxsize
if limit == -1:
limit = findFirstZero(p, maxsize)
s = ""
try:
# gdb.Inferior is new in gdb 7.2
......@@ -887,15 +878,14 @@ def encodeCharArray(p, maxsize, size = -1):
for i in xrange(limit):
s += "%02x" % int(p.dereference())
p += 1
if maxsize < size:
if limit > maxsize:
s += "2e2e2e"
return s
def encodeChar2Array(p, maxsize):
t = lookupType("unsigned short").pointer()
p = p.cast(t)
i = findFirstZero(p, maxsize)
limit = select(i < 0, maxsize, i)
limit = findFirstZero(p, maxsize)
s = ""
for i in xrange(limit):
s += "%04x" % int(p.dereference())
......@@ -907,13 +897,12 @@ def encodeChar2Array(p, maxsize):
def encodeChar4Array(p, maxsize):
t = lookupType("unsigned int").pointer()
p = p.cast(t)
i = findFirstZero(p, maxsize)
limit = select(i < 0, maxsize, i)
limit = findFirstZero(p, maxsize)
s = ""
for i in xrange(limit):
s += "%08x" % int(p.dereference())
p += 1
if i == maxsize:
if i > maxsize:
s += "2e0000002e0000002e000000"
return s
......@@ -927,7 +916,7 @@ def encodeByteArray(value):
if size > 0:
checkAccess(data, 4)
checkAccess(data + size) == 0
return encodeCharArray(data, 1000, size)
return encodeCharArray(data, 100, size)
def encodeString(value):
d_ptr = value['d'].dereference()
......@@ -941,16 +930,19 @@ def encodeString(value):
checkRef(d_ptr["ref"])
p = gdb.Value(d_ptr["data"])
s = ""
limit = min(size, 1000)
try:
# gdb.Inferior is new in gdb 7.2
inferior = gdb.inferiors()[0]
s = binascii.hexlify(inferior.read_memory(p, 2 * int(size)))
s = binascii.hexlify(inferior.read_memory(p, 2 * limit))
except:
for i in xrange(size):
for i in xrange(limit):
val = int(p.dereference())
s += "%02x" % (val % 256)
s += "%02x" % (val / 256)
p += 1
if limit < size:
s += "2e002e002e00"
return s
def stripTypedefs(type):
......@@ -1569,7 +1561,6 @@ class Dumper:
with SubItem(self):
self.putName(name)
self.putValue(value)
self.putAddress(value.address)
self.putType("bool")
self.putNumChild(0)
......@@ -1693,7 +1684,10 @@ class Dumper:
baseptr = value.cast(realtype.pointer())
if format == 0 or format == 1:
# Explicityly requested Latin1 or UTF-8 formatting.
f = select(format == 0, Hex2EncodedLatin1, Hex2EncodedUtf8)
if format == 0:
f = Hex2EncodedLatin1
else:
f = Hex2EncodedUtf8
self.putAddress(value.address)
self.putType(realtype)
self.putValue(encodeCharArray(value, 100), f)
......@@ -1791,12 +1785,19 @@ class Dumper:
#self.putAddress(item.value)
return
if format == 1 or format == 2:
# Explicityly requested Latin1 or UTF-8 formatting.
f = select(format == 1, Hex2EncodedLatin1, Hex2EncodedUtf8)
if format == 1:
# Explicityly requested Latin1 formatting.
self.putAddress(value.address)
self.putType(realtype)
self.putValue(encodeCharArray(value, 100), f)
self.putValue(encodeCharArray(value, 100), Hex2EncodedLatin1)
self.putNumChild(0)
return
if format == 2:
# Explicityly requested UTF-8 formatting.
self.putAddress(value.address)
self.putType(realtype)
self.putValue(encodeCharArray(value, 100), Hex2EncodedUtf8)
self.putNumChild(0)
return
......
......@@ -386,10 +386,11 @@ def qdump__QHash(d, item):
isSimpleKey = isSimpleType(keyType)
isSimpleValue = isSimpleType(valueType)
node = hashDataFirstNode(item.value)
innerType = e_ptr.dereference().type
inner = select(isSimpleKey and isSimpleValue, valueType, innerType)
with Children(d, [size, 1000], inner):
childType = innerType
if isSimpleKey and isSimpleValue:
childType = isSimpleValue
with Children(d, [size, 1000], childType):
for i in d.childRange():
it = node.dereference().cast(innerType)
with SubItem(d):
......@@ -620,7 +621,10 @@ def qdumpHelper__QMap(d, item, forceLong):
payloadSize = nodeType.sizeof - 2 * lookupType("void").pointer().sizeof
charPtr = lookupType("char").pointer()
innerType = select(isSimpleKey and isSimpleValue, valueType, nodeType)
if isSimpleKey and isSimpleValue:
innerType = valueType
else:
innerType = nodeType
with Children(d, n, innerType):
for i in xrange(n):
......@@ -1162,7 +1166,9 @@ def qdump__QPointF(d, item):
def qdump__QRect(d, item):
def pp(l): return select(l >= 0, "+%s" % l, l)
def pp(l):
if l >= 0: return "+%s" % l
return l
x1 = item.value["x1"]
y1 = item.value["y1"]
x2 = item.value["x2"]
......@@ -1180,7 +1186,9 @@ def qdump__QRect(d, item):
def qdump__QRectF(d, item):
def pp(l): return select(l >= 0, "+%s" % l, l)
def pp(l):
if l >= 0: return "+%s" % l
return l
x = item.value["xp"]
y = item.value["yp"]
w = item.value["w"]
......@@ -1473,7 +1481,10 @@ def qdumpHelper__QVariant(d, value):
d.putValue("(invalid)")
d.putNumChild(0)
elif variantType == 1: # QVariant::Bool
d.putValue(select(data["b"], "true", "false"))
if int(data["b"]):
d.putValue("true")
else:
d.putValue("false")
d.putNumChild(0)
inner = "bool"
elif variantType == 2: # QVariant::Int
......@@ -1730,7 +1741,9 @@ def qdump__std__deque(d, item):
if d.isExpanded(item):
innerType = templateArgument(item.value.type, 0)
innerSize = innerType.sizeof
bufsize = select(innerSize < 512, 512 / innerSize, 1)
bufsize = 1
if innerSize < 512:
bufsize = 512 / innerSize
with Children(d, [size, 2000], innerType):
pcur = start["_M_cur"]
pfirst = start["_M_first"]
......@@ -1784,11 +1797,18 @@ def qdump__std__map(d, item):
pairType = templateArgument(templateArgument(item.value.type, 3), 0)
isSimpleKey = isSimpleType(keyType)
isSimpleValue = isSimpleType(valueType)
innerType = select(isSimpleKey and isSimpleValue, valueType, pairType)
innerType = pairType
if isSimpleKey and isSimpleValue:
innerType = valueType
pairPointer = pairType.pointer()
node = impl["_M_header"]["_M_left"]
with Children(d, [size, 1000], select(size > 0, innerType, pairType),
select(isSimpleKey and isSimpleValue, None, 2)):
childType = innerType
if size == 0:
childType = pairType
childNumChild = 2
if isSimpleKey and isSimpleValue:
childNumChild = None
with Children(d, [size, 1000], childType, childNumChild):
for i in d.childRange():
pair = (node + 1).cast(pairPointer).dereference()
......@@ -1950,8 +1970,7 @@ def qdump__std__vector(d, item):
with Children(d, [size, 10000], type):
for i in d.childRange():
q = start + i / storagesize
data = (q.dereference() >> (i % storagesize)) & 1
d.putBoolItem(str(i), select(data, "true", "false"))
d.putBoolItem(str(i), (q.dereference() >> (i % storagesize)) & 1)
else:
with Children(d, [size, 10000], type):
p = start
......
......@@ -539,6 +539,8 @@ int testQByteArray2()
QByteArray ba;
for (int i = 256; --i >= 0; )
ba.append(char(i));
QString s(10000, 'x');
std::string ss(10000, 'c');
return ba.size();
}
......@@ -1339,7 +1341,7 @@ std::list<int> testStdList()
void testStdMap()
{
// This is not supposed to work with the compiled dumpers.
#if 0
#if 1
std::map<QString, Foo> gg3;
gg3["22.0"] = Foo(22);
gg3["33.0"] = Foo(33);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment