forked from qt-creator/qt-creator
debugger: cache results of gdb.lookup_type
This commit is contained in:
@@ -90,12 +90,50 @@ def isGoodGdb():
|
||||
# and gdb.VERSION != "6.8.50.20090630-cvs"
|
||||
return 'parse_and_eval' in __builtin__.dir(gdb)
|
||||
|
||||
typeCache = {}
|
||||
|
||||
def lookupType(typestring):
|
||||
type = typeCache.get(typestring)
|
||||
#warn("LOOKUP 1: %s -> %s" % (typestring, type))
|
||||
if type is None:
|
||||
ts = typestring
|
||||
while True:
|
||||
#WARN("ts: '%s'" % ts)
|
||||
if ts.startswith("class "):
|
||||
ts = ts[6:]
|
||||
elif ts.startswith("struct "):
|
||||
ts = ts[7:]
|
||||
elif ts.startswith("const "):
|
||||
ts = ts[6:]
|
||||
elif ts.startswith("volatile "):
|
||||
ts = ts[9:]
|
||||
elif ts.startswith("enum "):
|
||||
ts = ts[5:]
|
||||
elif ts.endswith("const"):
|
||||
ts = ts[-5:]
|
||||
elif ts.endswith("volatile"):
|
||||
ts = ts[-8:]
|
||||
else:
|
||||
break
|
||||
try:
|
||||
#warn("LOOKING UP '%s'" % ts)
|
||||
type = gdb.lookup_type(ts)
|
||||
except:
|
||||
# Can throw "RuntimeError: No type named class Foo."
|
||||
#warn("LOOKING UP '%s' FAILED" % ts)
|
||||
pass
|
||||
#warn(" RESULT: '%s'" % type)
|
||||
#if not type is None:
|
||||
# warn(" FIELDS: '%s'" % type.fields())
|
||||
typeCache[typestring] = type
|
||||
return type
|
||||
|
||||
def cleanAddress(addr):
|
||||
if addr is None:
|
||||
return "<no address>"
|
||||
# We cannot use str(addr) as it yields rubbish for char pointers
|
||||
# that might trigger Unicode encoding errors.
|
||||
return addr.cast(gdb.lookup_type("void").pointer())
|
||||
return addr.cast(lookupType("void").pointer())
|
||||
|
||||
# Workaround for gdb < 7.1
|
||||
def numericTemplateArgument(type, position):
|
||||
@@ -535,7 +573,7 @@ def checkRef(ref):
|
||||
check(count < 1000000) # assume there aren't a million references to any object
|
||||
|
||||
#def couldBePointer(p, align):
|
||||
# type = gdb.lookup_type("unsigned int")
|
||||
# type = lookupType("unsigned int")
|
||||
# ptr = gdb.Value(p).cast(type)
|
||||
# d = int(str(ptr))
|
||||
# warn("CHECKING : %s %d " % (p, ((d & 3) == 0 and (d > 1000 or d == 0))))
|
||||
@@ -559,7 +597,7 @@ def isNull(p):
|
||||
# for invalid char *, as their "contents" is being examined
|
||||
#s = str(p)
|
||||
#return s == "0x0" or s.startswith("0x0 ")
|
||||
return p.cast(gdb.lookup_type("void").pointer()) == 0
|
||||
return p.cast(lookupType("void").pointer()) == 0
|
||||
|
||||
movableTypes = set([
|
||||
"QBrush", "QBitArray", "QByteArray",
|
||||
@@ -648,7 +686,7 @@ def findFirstZero(p, max):
|
||||
|
||||
|
||||
def extractCharArray(p, maxsize):
|
||||
t = gdb.lookup_type("unsigned char").pointer()
|
||||
t = lookupType("unsigned char").pointer()
|
||||
p = p.cast(t)
|
||||
i = findFirstZero(p, maxsize)
|
||||
limit = select(i < 0, maxsize, i)
|
||||
@@ -673,7 +711,7 @@ def extractByteArray(value):
|
||||
return extractCharArray(data, 100)
|
||||
|
||||
def encodeCharArray(p, maxsize, size = -1):
|
||||
t = gdb.lookup_type("unsigned char").pointer()
|
||||
t = lookupType("unsigned char").pointer()
|
||||
p = p.cast(t)
|
||||
if size == -1:
|
||||
i = findFirstZero(p, maxsize)
|
||||
@@ -689,7 +727,7 @@ def encodeCharArray(p, maxsize, size = -1):
|
||||
return s
|
||||
|
||||
def encodeChar2Array(p, maxsize):
|
||||
t = gdb.lookup_type("unsigned short").pointer()
|
||||
t = lookupType("unsigned short").pointer()
|
||||
p = p.cast(t)
|
||||
i = findFirstZero(p, maxsize)
|
||||
limit = select(i < 0, maxsize, i)
|
||||
@@ -702,7 +740,7 @@ def encodeChar2Array(p, maxsize):
|
||||
return s
|
||||
|
||||
def encodeChar4Array(p, maxsize):
|
||||
t = gdb.lookup_type("unsigned int").pointer()
|
||||
t = lookupType("unsigned int").pointer()
|
||||
p = p.cast(t)
|
||||
i = findFirstZero(p, maxsize)
|
||||
limit = select(i < 0, maxsize, i)
|
||||
@@ -1087,7 +1125,7 @@ class Dumper:
|
||||
def putPointerValue(self, value):
|
||||
# Use a lower priority
|
||||
self.putValue("0x%x" % value.dereference().cast(
|
||||
gdb.lookup_type("unsigned long")), None, -1)
|
||||
lookupType("unsigned long")), None, -1)
|
||||
|
||||
def putStringValue(self, value):
|
||||
if value is None:
|
||||
@@ -1370,7 +1408,7 @@ class Dumper:
|
||||
if self.isExpanded(item):
|
||||
if value.type.code == gdb.TYPE_CODE_ARRAY:
|
||||
baseptr = value.cast(value.type.target().pointer())
|
||||
charptr = gdb.lookup_type("unsigned char").pointer()
|
||||
charptr = lookupType("unsigned char").pointer()
|
||||
addr1 = (baseptr+1).cast(charptr)
|
||||
addr0 = baseptr.cast(charptr)
|
||||
self.putField("addrbase" % cleanAddress(addr0))
|
||||
|
||||
Reference in New Issue
Block a user