Commit 40052046 authored by hjk's avatar hjk
Browse files

Debugger: Rework display length limitation systems



There are two values now, one to limit an entry in the L&E view
(default 100) and a hard upper limit (at 1 mio).

If displayed values are elided, the true length is shown in addition.

Change-Id: I180b70446c18e258c164e5af75b88d4c8b6c53f2
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 382730b1
......@@ -71,6 +71,19 @@ except:
return "Normal"
class ReportItem:
"""
Helper structure to keep temporary "best" information about a value
or a type scheduled to be reported. This might get overridden be
subsequent better guesses during a putItem() run.
"""
def __init__(self):
self.value = None
self.priority = -100
self.encoding = None
self.elided = 0
class Blob(object):
"""
Helper structure to keep a blob of bytes, possibly
......@@ -310,6 +323,7 @@ class DumperBase:
# Later set, or not set:
# cachedQtVersion
self.stringCutOff = 10000
self.displayStringLimit = 100
# This is a cache mapping from 'type name' to 'display alternatives'.
self.qqFormats = {}
......@@ -375,12 +389,11 @@ class DumperBase:
# assume no Qt 3 support by default
return False
# Clamps size to limit.
def computeLimit(self, size, limit):
if limit is None:
return size
if limit == 0:
return min(size, self.stringCutOff)
return min(size, limit)
if limit is None or size <= limit:
return 0, size
return size, limit
def vectorDataHelper(self, addr):
if self.qtVersion() >= 0x050000:
......@@ -419,53 +432,50 @@ class DumperBase:
return data, size, alloc
# addr is the begin of a QByteArrayData structure
def encodeStringHelper(self, addr, limit = 0):
def encodeStringHelper(self, addr, limit):
# Should not happen, but we get it with LLDB as result
# of inferior calls
if addr == 0:
return ""
return 0, ""
data, size, alloc = self.byteArrayDataHelper(addr)
if alloc != 0:
self.check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
limit = self.computeLimit(size, limit)
s = self.readMemory(data, 2 * limit)
if limit < size:
s += "2e002e002e00"
return s
elided, shown = self.computeLimit(size, limit)
return elided, self.readMemory(data, 2 * shown)
def encodeByteArrayHelper(self, addr, limit = None):
def encodeByteArrayHelper(self, addr, limit):
data, size, alloc = self.byteArrayDataHelper(addr)
if alloc != 0:
self.check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
limit = self.computeLimit(size, limit)
s = self.readMemory(data, limit)
if limit < size:
s += "2e2e2e"
return s
elided, shown = self.computeLimit(size, limit)
return elided, self.readMemory(data, shown)
def readMemory(self, addr, size):
data = self.extractBlob(addr, size).toBytes()
return self.hexencode(data)
def encodeByteArray(self, value, limit = 0):
return self.encodeByteArrayHelper(self.extractPointer(value), limit)
elided, data = self.encodeByteArrayHelper(self.extractPointer(value), limit)
return data
def byteArrayData(self, value):
return self.byteArrayDataHelper(self.extractPointer(value))
def putByteArrayValue(self, value):
return self.putValue(self.encodeByteArray(value, self.stringCutOff), Hex2EncodedLatin1)
elided, data = self.encodeByteArrayHelper(self.extractPointer(value), self.displayStringLimit)
self.putValue(data, Hex2EncodedLatin1, elided=elided)
def putByteArrayValueByAddress(self, addr):
self.putValue(self.encodeByteArrayHelper(self.extractPointer(addr)),
Hex2EncodedLatin1)
elided, data = self.encodeByteArrayHelper(addr, self.displayStringLimit)
self.putValue(data, Hex2EncodedLatin1, elided=elided)
def putStringValueByAddress(self, addr):
self.putValue(self.encodeStringHelper(self.extractPointer(addr)),
Hex4EncodedLittleEndian)
elided, data = self.encodeStringHelper(self.extractPointer(addr), self.displayStringLimit)
self.putValue(data, Hex4EncodedLittleEndian, elided=elided)
def encodeString(self, value, limit = 0):
return self.encodeStringHelper(self.extractPointer(value), limit)
elided, data = self.encodeStringHelper(self.extractPointer(value), limit)
return data
def stringData(self, value):
return self.byteArrayDataHelper(self.extractPointer(value))
......@@ -499,7 +509,8 @@ class DumperBase:
return inner.strip()
def putStringValue(self, value):
return self.putValue(self.encodeString(value, self.stringCutOff), Hex4EncodedLittleEndian)
elided, data = self.encodeStringHelper(self.extractPointer(value), self.displayStringLimit)
self.putValue(data, Hex4EncodedLittleEndian, elided=elided)
def putAddressItem(self, name, value, type = ""):
with SubItem(self, name):
......@@ -619,27 +630,16 @@ class DumperBase:
def findFirstZero(self, p, maximum):
for i in xrange(maximum):
if int(p.dereference()) == 0:
return i
return 0, i
p = p + 1
return maximum + 1
# Real end is unknown.
return -1, maximum
def encodeCArray(self, p, innerType, suffix):
def encodeCArray(self, p, innerType, limit):
t = self.lookupType(innerType)
p = p.cast(t.pointer())
limit = self.findFirstZero(p, self.stringCutOff)
s = self.readMemory(p, limit * t.sizeof)
if limit > self.stringCutOff:
s += suffix
return s
def encodeCharArray(self, p):
return self.encodeCArray(p, "unsigned char", "2e2e2e")
def encodeChar2Array(self, p):
return self.encodeCArray(p, "unsigned short", "2e002e002e00")
def encodeChar4Array(self, p):
return self.encodeCArray(p, "unsigned int", "2e0000002e0000002e000000")
elided, shown = self.findFirstZero(p, limit)
return elided, self.readMemory(p, shown * t.sizeof)
def putItemCount(self, count, maximum = 1000000000):
# This needs to override the default value, so don't use 'put' directly.
......@@ -654,26 +654,34 @@ class DumperBase:
def putType(self, type, priority = 0):
# Higher priority values override lower ones.
if priority >= self.currentTypePriority:
self.currentType = str(type)
self.currentTypePriority = priority
if priority >= self.currentType.priority:
self.currentType.value = str(type)
self.currentType.priority = priority
def putValue(self, value, encoding = None, priority = 0):
def putValue(self, value, encoding = None, priority = 0, elided = None):
# Higher priority values override lower ones.
if priority >= self.currentValuePriority:
self.currentValue = value
self.currentValuePriority = priority
self.currentValueEncoding = encoding
# elided = 0 indicates all data is available in value,
# otherwise it's the true length.
if priority >= self.currentValue.priority:
self.currentValue.value = value
self.currentValue.priority = priority
self.currentValue.encoding = encoding
self.currentValue.elided = elided
def putEmptyValue(self, priority = -10):
if priority >= self.currentValuePriority:
self.currentValue = ""
self.currentValuePriority = priority
self.currentValueEncoding = None
if priority >= self.currentValue.priority:
self.currentValue.value = ""
self.currentValue.priority = priority
self.currentValue.encoding = None
self.currentValue.elided = None
def putName(self, name):
self.put('name="%s",' % name)
def putBetterType(self, type):
self.currentType.value = str(type)
self.currentType.priority += 1
def putNoType(self):
# FIXME: replace with something that does not need special handling
# in SubItem.__exit__().
......@@ -682,7 +690,7 @@ class DumperBase:
def putInaccessible(self):
#self.putBetterType(" ")
self.putNumChild(0)
self.currentValue = None
self.currentValue.value = None
def putNamedSubItem(self, component, value, name):
with SubItem(self, component):
......@@ -805,7 +813,8 @@ class DumperBase:
if format == None and innerTypeName == "char":
# Use Latin1 as default for char *.
self.putType(typeName)
self.putValue(self.encodeCharArray(value), Hex2EncodedLatin1)
(elided, data) = self.encodeCArray(value, "unsigned char", self.displayStringLimit)
self.putValue(data, Hex2EncodedLatin1, elided=elided)
self.putNumChild(0)
return
......@@ -823,35 +832,40 @@ class DumperBase:
if format == Latin1StringFormat:
# Explicitly requested Latin1 formatting.
self.putType(typeName)
self.putValue(self.encodeCharArray(value), Hex2EncodedLatin1)
(elided, data) = self.encodeCArray(value, "unsigned char", self.displayStringLimit)
self.putValue(data, Hex2EncodedLatin1, elided=elided)
self.putNumChild(0)
return
if format == Utf8StringFormat:
# Explicitly requested UTF-8 formatting.
self.putType(typeName)
self.putValue(self.encodeCharArray(value), Hex2EncodedUtf8)
(elided, data) = self.encodeCArray(value, "unsigned char", self.displayStringLimit)
self.putValue(data, Hex2EncodedUtf8, elided=elided)
self.putNumChild(0)
return
if format == Local8BitStringFormat:
# Explicitly requested local 8 bit formatting.
self.putType(typeName)
self.putValue(self.encodeCharArray(value), Hex2EncodedLocal8Bit)
(elided, data) = self.encodeCArray(value, "unsigned char", self.displayStringLimit)
self.putValue(data, Hex2EncodedLocal8Bit, elided=elided)
self.putNumChild(0)
return
if format == Utf16StringFormat:
# Explicitly requested UTF-16 formatting.
self.putType(typeName)
self.putValue(self.encodeChar2Array(value), Hex4EncodedLittleEndian)
(elided, data) = self.encodeCArray(value, "unsigned short", self.displayStringLimit)
self.putValue(data, Hex4EncodedLittleEndian, elided=elided)
self.putNumChild(0)
return
if format == Ucs4StringFormat:
# Explicitly requested UCS-4 formatting.
self.putType(typeName)
self.putValue(self.encodeChar4Array(value), Hex8EncodedLittleEndian)
(elided, data) = self.encodeCArray(value, "unsigned int", self.displayStringLimit)
self.putValue(data, Hex8EncodedLittleEndian, elided=elided)
self.putNumChild(0)
return
......@@ -1226,7 +1240,7 @@ class DumperBase:
format = self.formats.get(self.currentIName)
if format is None:
if type is None:
type = self.currentType
type = self.currentType.value
needle = self.stripForFormat(str(type))
format = self.typeformats.get(needle)
return format
......@@ -1256,8 +1270,8 @@ class DumperBase:
if not hasPlot():
return
if not self.isSimpleType(typeobj):
#self.putValue(self.currentValue + " (not plottable)")
self.putValue(self.currentValue)
#self.putValue(self.currentValue.value + " (not plottable)")
self.putValue(self.currentValue.value)
self.putField("plottable", "0")
return
global gnuplotPipe
......@@ -1435,8 +1449,8 @@ class DumperBase:
value = self.parseAndEvaluate(exp)
self.putItem(value)
except RuntimeError:
self.currentType = " "
self.currentValue = "<no such value>"
self.currentType.value = " "
self.currentValue.value = "<no such value>"
self.currentChildNumChild = -1
self.currentNumChild = 0
self.putNumChild(0)
......
......@@ -367,11 +367,8 @@ class Dumper(DumperBase):
self.currentChildNumChild = -1
self.currentMaxNumChild = -1
self.currentNumChild = -1
self.currentValue = None
self.currentValuePriority = -100
self.currentValueEncoding = None
self.currentType = None
self.currentTypePriority = -100
self.currentValue = ReportItem()
self.currentType = ReportItem()
self.currentAddress = None
self.typeformats = {}
self.formats = {}
......@@ -402,6 +399,8 @@ class Dumper(DumperBase):
self.expandedINames = set(arg[pos:].split(","))
elif arg.startswith("stringcutoff:"):
self.stringCutOff = int(arg[pos:])
elif arg.startswith("displaystringlimit:"):
self.displayStringLimit = int(arg[pos:])
elif arg.startswith("typeformats:"):
for f in arg[pos:].split(","):
pos = f.find("=")
......@@ -525,39 +524,39 @@ class Dumper(DumperBase):
self.put('name="%s",' % item.name)
item.savedIName = self.currentIName
item.savedValue = self.currentValue
item.savedValuePriority = self.currentValuePriority
item.savedValueEncoding = self.currentValueEncoding
item.savedType = self.currentType
item.savedTypePriority = self.currentTypePriority
item.savedCurrentAddress = self.currentAddress
self.currentIName = item.iname
self.currentValuePriority = -100
self.currentValueEncoding = None
self.currentType = ""
self.currentTypePriority = -100
self.currentValue = ReportItem();
self.currentType = ReportItem();
self.currentAddress = None
def exitSubItem(self, item, exType, exValue, exTraceBack):
#warn(" CURRENT VALUE: %s %s %s" % (self.currentValue,
# self.currentValueEncoding, self.currentValuePriority))
#warn("CURRENT VALUE: %s: %s %s %s %s" % (
# self.currentIName,
# self.currentValue.value,
# self.currentValue.elided,
# self.currentValue.encoding,
# self.currentValue.priority))
if not exType is None:
if self.passExceptions:
showException("SUBITEM", exType, exValue, exTraceBack)
self.putNumChild(0)
self.putValue("<not accessible>")
try:
#warn("TYPE VALUE: %s" % self.currentValue)
typeName = stripClassTag(self.currentType)
#warn("TYPE: '%s' DEFAULT: '%s' % (typeName, self.currentChildType))
#warn("CURRENT TYPE: %s" % self.currentType.value)
typeName = stripClassTag(self.currentType.value)
if len(typeName) > 0 and typeName != self.currentChildType:
self.put('type="%s",' % typeName) # str(type.unqualified()) ?
if self.currentValue is None:
if self.currentValue.value is None:
self.put('value="<not accessible>",numchild="0",')
else:
if not self.currentValueEncoding is None:
self.put('valueencoded="%d",' % self.currentValueEncoding)
self.put('value="%s",' % self.currentValue)
if not self.currentValue.encoding is None:
self.put('valueencoded="%d",' % self.currentValue.encoding)
if self.currentValue.elided:
self.put('valueelided="%d",' % self.currentValue.elided)
self.put('value="%s",' % self.currentValue.value)
except:
pass
if not self.currentAddress is None:
......@@ -565,10 +564,7 @@ class Dumper(DumperBase):
self.put('},')
self.currentIName = item.savedIName
self.currentValue = item.savedValue
self.currentValuePriority = item.savedValuePriority
self.currentValueEncoding = item.savedValueEncoding
self.currentType = item.savedType
self.currentTypePriority = item.savedTypePriority
self.currentAddress = item.savedCurrentAddress
return True
......@@ -888,10 +884,6 @@ class Dumper(DumperBase):
self.isQt3Support = lambda: self.cachedIsQt3Suport
return self.cachedIsQt3Suport
def putBetterType(self, type):
self.currentType = str(type)
self.currentTypePriority = self.currentTypePriority + 1
def putAddress(self, addr):
if self.currentPrintsAddress:
try:
......
......@@ -261,11 +261,8 @@ class Dumper(DumperBase):
self.typeformats = {}
self.currentIName = None
self.currentValuePriority = -100
self.currentValueEncoding = None
self.currentType = ""
self.currentTypePriority = -100
self.currentValue = None
self.currentValue = ReportItem()
self.currentType = ReportItem()
self.currentNumChild = None
self.currentMaxNumChild = None
self.currentPrintsAddress = None
......@@ -310,15 +307,10 @@ class Dumper(DumperBase):
self.put('name="%s",' % item.name)
item.savedIName = self.currentIName
item.savedValue = self.currentValue
item.savedValuePriority = self.currentValuePriority
item.savedValueEncoding = self.currentValueEncoding
item.savedType = self.currentType
item.savedTypePriority = self.currentTypePriority
self.currentIName = item.iname
self.currentValuePriority = -100
self.currentValueEncoding = None
self.currentType = ""
self.currentTypePriority = -100
self.currentValue = ReportItem()
self.currentType = ReportItem()
def exitSubItem(self, item, exType, exValue, exTraceBack):
if not exType is None:
......@@ -327,24 +319,23 @@ class Dumper(DumperBase):
self.putNumChild(0)
self.putValue("<not accessible>")
try:
typeName = self.currentType
typeName = self.currentType.value
if len(typeName) > 0 and typeName != self.currentChildType:
self.put('type="%s",' % typeName) # str(type.unqualified()) ?
if self.currentValue is None:
if self.currentValue.value is None:
self.put('value="<not accessible>",numchild="0",')
else:
if not self.currentValueEncoding is None:
self.put('valueencoded="%s",' % self.currentValueEncoding)
self.put('value="%s",' % self.currentValue)
if not self.currentValue.encoding is None:
self.put('valueencoded="%s",' % self.currentValue.encoding)
if self.currentValue.elided:
self.put('valueelided="%s",' % self.currentValue.elided)
self.put('value="%s",' % self.currentValue.value)
except:
pass
self.put('},')
self.currentIName = item.savedIName
self.currentValue = item.savedValue
self.currentValuePriority = item.savedValuePriority
self.currentValueEncoding = item.savedValueEncoding
self.currentType = item.savedType
self.currentTypePriority = item.savedTypePriority
return True
def isSimpleType(self, typeobj):
......@@ -856,14 +847,6 @@ class Dumper(DumperBase):
def reportStackTop(self):
self.report('stack-top={}')
def putBetterType(self, type):
try:
self.currentType = type.GetName()
except:
self.currentType = str(type)
self.currentTypePriority = self.currentTypePriority + 1
#warn("BETTER TYPE: %s PRIORITY: %s" % (type, self.currentTypePriority))
def extractBlob(self, base, size):
if size == 0:
return Blob("")
......
......@@ -274,7 +274,7 @@ def qdump__QDateTime(d, value):
tz = ""
else:
idBase = tzp + 2 * d.ptrSize() # [QSharedData] + [vptr]
tz = d.encodeByteArrayHelper(d.extractPointer(idBase))
tz = d.encodeByteArrayHelper(d.extractPointer(idBase), limit=100)
d.putValue("%s/%s/%s/%s/%s" % (msecs, spec, offset, tz, status),
DateTimeInternal)
else:
......@@ -705,7 +705,7 @@ def qdump__QHostAddress(d, value):
ipStringAddress = privAddress + (0 if isQt5 else 24)
isParsedAddress = privAddress + 24 + 2 * sizeofQString
# value.d.d->ipString
ipString = d.encodeStringHelper(d.extractPointer(ipStringAddress))
ipString = d.encodeStringHelper(d.extractPointer(ipStringAddress), limit=100)
if d.extractByte(isParsedAddress) and len(ipString) > 0:
d.putValue(ipString, Hex4EncodedLittleEndian)
else:
......@@ -720,7 +720,7 @@ def qdump__QHostAddress(d, value):
data = d.readMemory(privAddress + a6Offset, 16)
address = ':'.join("%x" % int(data[i:i+4], 16) for i in xrange(0, 32, 4))
scopeId = privAddress + sizeofQString + (0 if isQt5 else 24)
scopeId = d.encodeStringHelper(d.extractPointer(scopeId))
scopeId = d.encodeStringHelper(d.extractPointer(scopeId), limit=100)
d.putValue("%s%%%s" % (address, scopeId), IPv6AddressAndHexScopeId)
elif proto == 0:
# value.d.d->a
......@@ -1730,7 +1730,7 @@ def qdump__QString(d, value):
d.putDisplay(StopDisplay)
elif format == 2:
d.putField("editformat", DisplayUtf16String)
d.putField("editvalue", d.encodeString(value))
d.putField("editvalue", d.encodeString(value, limit=None))
def qdump__QStringRef(d, value):
......@@ -1759,7 +1759,7 @@ def qdump__QTemporaryFile(d, value):
def qdump__QTextCodec(d, value):
name = d.call(value, "name")
d.putValue(d.encodeByteArray(d, name), 6)
d.putValue(d.encodeByteArray(name, limit=100), 6)
d.putNumChild(2)
if d.isExpanded():
with Children(d):
......@@ -1843,13 +1843,13 @@ def qdump__QUrl(d, value):
d.putValue("<invalid>")
return
schemeAddr = privAddress + 2 * d.intSize()
scheme = d.encodeStringHelper(d.extractPointer(schemeAddr))
userName = d.encodeStringHelper(d.extractPointer(schemeAddr + 1 * d.ptrSize()))
password = d.encodeStringHelper(d.extractPointer(schemeAddr + 2 * d.ptrSize()))
host = d.encodeStringHelper(d.extractPointer(schemeAddr + 3 * d.ptrSize()))
path = d.encodeStringHelper(d.extractPointer(schemeAddr + 4 * d.ptrSize()))
query = d.encodeStringHelper(d.extractPointer(schemeAddr + 5 * d.ptrSize()))
fragment = d.encodeStringHelper(d.extractPointer(schemeAddr + 6 * d.ptrSize()))
scheme = d.encodeStringHelper(d.extractPointer(schemeAddr), limit=1000)
userName = d.encodeStringHelper(d.extractPointer(schemeAddr + 1 * d.ptrSize()), limit=100)
password = d.encodeStringHelper(d.extractPointer(schemeAddr + 2 * d.ptrSize()), limit=100)
host = d.encodeStringHelper(d.extractPointer(schemeAddr + 3 * d.ptrSize()), limit=100)
path = d.encodeStringHelper(d.extractPointer(schemeAddr + 4 * d.ptrSize()), limit=1000)
query = d.encodeStringHelper(d.extractPointer(schemeAddr + 5 * d.ptrSize()), limit=10000)
fragment = d.encodeStringHelper(d.extractPointer(schemeAddr + 6 * d.ptrSize()), limit=10000)
port = d.extractInt(d.extractPointer(value) + d.intSize())
url = scheme
......
......@@ -418,10 +418,8 @@ def qdump__std__stringHelper1__QNX(d, value, charSize):
qdump_stringHelper(d, sizePtr, size * charSize, charSize)
def qdump_stringHelper(d, data, size, charSize):
cutoff = min(size, d.stringCutOff)
mem = d.readMemory(data, cutoff)
if size > d.stringCutOff:
mem += "2e2e2e"
elided, shown = d.computeLimit(size, d.displayStringLimit)
mem = d.readMemory(data, shown)
if charSize == 1:
encodingType = Hex2EncodedLatin1
displayType = DisplayLatin1String
......@@ -433,7 +431,7 @@ def qdump_stringHelper(d, data, size, charSize):
displayType = DisplayUtf16String
d.putNumChild(0)
d.putValue(mem, encodingType)
d.putValue(mem, encodingType, elided=elided)
format = d.currentItemFormat()
if format == 1:
......
......@@ -121,6 +121,14 @@ CommonOptionsPageWidget::CommonOptionsPageWidget
spinBoxMaximalStringLength->setSingleStep(1000);
spinBoxMaximalStringLength->setValue(10000);
labelDisplayStringLimit = new QLabel(tr("Display string limit:"), behaviorBox);
spinBoxDisplayStringLimit = new QSpinBox(behaviorBox);
spinBoxDisplayStringLimit->setSpecialValueText(tr("<unlimited>"));
spinBoxDisplayStringLimit->setMaximum(10000);
spinBoxDisplayStringLimit->setSingleStep(10);
spinBoxDisplayStringLimit->setValue(100);
sourcesMappingWidget = new DebuggerSourcePathMappingWidget(this);
QHBoxLayout *horizontalLayout = new QHBoxLayout();
......@@ -128,6 +136,11 @@ CommonOptionsPageWidget::CommonOptionsPageWidget
horizontalLayout->addWidget(spinBoxMaximalStackDepth);
horizontalLayout->addStretch();
QHBoxLayout *horizontalLayout1 = new QHBoxLayout();
horizontalLayout1->addWidget(labelDisplayStringLimit);
horizontalLayout1->addWidget(spinBoxDisplayStringLimit);
horizontalLayout1->addStretch();