Commit a7a3941c authored by hjk's avatar hjk Committed by hjk
Browse files

debugger: Fix QString, QVector, QByteArray dumper for Qt 5 container changes.



Change-Id: Ib966adda453cbc8e44c36ae629f62ac3a5bf5bf7
Reviewed-by: default avatarChristian Stenger <christian.stenger@nokia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 492b1ccc
......@@ -501,15 +501,16 @@ def checkSimpleRef(ref):
check(count < 1000000)
def checkRef(ref):
# assume there aren't a million references to any object
if qtMajorVersion() >= 5:
count = ref["atomic"]["_q_value"]
check(count >= -1)
check(count < 1000000)
else:
count = ref["_q_value"]
check(count > 0)
check(count < 1000000)
try:
count = ref["atomic"]["_q_value"] # Qt 5.
minimum = -1
except:
count = ref["_q_value"] # Qt 4.
minimum = 0
# Assume there aren't a million references to any object.
check(count >= minimum)
check(count < 1000000)
#def couldBePointer(p, align):
# type = lookupType("unsigned int")
......@@ -667,24 +668,6 @@ def qtNamespace():
except:
return ""
# -- Determine major Qt version by calling qVersion (cached)
qqMajorVersion = None
def qtMajorVersion():
global qqMajorVersion
if not qqMajorVersion is None:
return qqMajorVersion
try:
# -- Result is returned as character, need to subtract '0'
v = int(parseAndEvaluate("*(char*)qVersion()"))
if v >= 51:
qqMajorVersion = v - 48
return qqMajorVersion
return 0
except:
return 0
def findFirstZero(p, maximum):
for i in xrange(maximum):
if p.dereference() == 0:
......@@ -762,21 +745,17 @@ def encodeChar4Array(p, maxsize):
return s
def qByteArrayData(value):
if qtMajorVersion() < 5:
d_ptr = value['d'].dereference()
checkRef(d_ptr["ref"])
data = d_ptr['data']
size = d_ptr['size']
alloc = d_ptr['alloc']
return data, size, alloc
else: # Qt5: Implement the QByteArrayData::data() accessor.
qByteArrayData = value['d'].dereference()
size = qByteArrayData['size']
alloc = qByteArrayData['alloc']
private = value['d']
checkRef(private['ref'])
try:
# Qt 5. Will fail on Qt 4 due to the missing 'offset' member.
offset = private['offset']
charPointerType = lookupType('char *')
data = qByteArrayData['d'].cast(charPointerType) \
+ qByteArrayData['offset'] + charPointerType.sizeof
return data, size, alloc
data = private.cast(charPointerType) + private['offset']
return data, int(private['size']), int(private['alloc'])
except:
# Qt 4:
return private['data'], int(private['size']), int(private['alloc'])
def encodeByteArray(value):
data, size, alloc = qByteArrayData(value)
......@@ -787,21 +766,23 @@ def encodeByteArray(value):
return encodeCharArray(data, 100, size)
def qQStringData(value):
if qtMajorVersion() < 5:
d_ptr = value['d'].dereference()
checkRef(d_ptr['ref'])
return d_ptr['data'], int(d_ptr['size']), int(d_ptr['alloc'])
else: # Qt5: Implement the QStringArrayData::data() accessor.
qStringData = value['d'].dereference()
private = value['d']
checkRef(private['ref'])
try:
# Qt 5. Will fail on Qt 4 due to the missing 'offset' member.
offset = private['offset']
ushortPointerType = lookupType('ushort *')
data = qStringData['d'].cast(ushortPointerType) \
+ ushortPointerType.sizeof / 2 + qStringData['offset']
return data, int(qStringData['size']), int(qStringData['alloc'])
data = private.cast(ushortPointerType) + offset / 2
return data, int(private['size']), int(private['alloc'])
except:
# Qt 4.
return private['data'], int(private['size']), int(private['alloc'])
def encodeString(value):
data, size, alloc = qQStringData(value)
check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
if alloc != 0:
check(0 <= size and size <= alloc and alloc <= 100*1000*1000)
if size > 0:
checkAccess(data, 4)
checkAccess(data + size) == 0
......
......@@ -1644,23 +1644,29 @@ def qedit__QVector(expr, value):
def qdump__QVector(d, value):
d_ptr = value["d"]
p_ptr = value["p"]
alloc = d_ptr["alloc"]
size = d_ptr["size"]
private = value["d"]
checkRef(private["ref"])
alloc = private["alloc"]
size = private["size"]
innerType = templateArgument(value.type, 0)
charPointerType = lookupType("char *")
try:
# Qt 5. Will fail on Qt 4 due to the missing 'offset' member.
offset = private["offset"]
data = private.cast(charPointerType) + offset
except:
# Qt 4.
data = value["p"]["array"]
check(0 <= size and size <= alloc and alloc <= 1000 * 1000 * 1000)
checkRef(d_ptr["ref"])
p = data.cast(innerType.pointer())
innerType = templateArgument(value.type, 0)
check(0 <= size and size <= alloc and alloc <= 1000 * 1000 * 1000)
d.putItemCount(size)
d.putNumChild(size)
if d.isExpanded():
p = gdb.Value(p_ptr["array"]).cast(innerType.pointer())
charPtr = lookupType("char").pointer()
d.putField("size", size)
with Children(d, size, maxNumChild=2000, childType=innerType, addrBase=p,
addrStep=(p+1).cast(charPtr) - p.cast(charPtr)):
addrStep=(p+1).cast(charPointerType) - p.cast(charPointerType)):
for i in d.childRange():
d.putSubItem(i, p.dereference())
p += 1
......
......@@ -582,11 +582,24 @@ namespace qbytearray {
dummyStatement(&buf1, &buf2, &buf3);
}
void testQByteArray4()
{
char data[] = { 'H', 'e', 'l', 'l', 'o' };
QByteArray ba1 = QByteArray::fromRawData(data, 4);
QByteArray ba2 = QByteArray::fromRawData(data + 1, 4);
BREAK_HERE;
// Check ba1 "Hell" QByteArray.
// Check ba2 "ello" QByteArray.
// Continue.
dummyStatement(&ba1, &ba2, &data);
}
void testQByteArray()
{
testQByteArray1();
testQByteArray2();
testQByteArray3();
testQByteArray4();
}
} // namespace qbytearray
......@@ -3370,14 +3383,26 @@ namespace qstring {
str += QLatin1Char(0);
str += QLatin1Char(1);
str += " fat ";
str += " World ";
str += " World ";
str += " World";
str.prepend("Prefix: ");
BREAK_HERE;
// Check str "Hello big, \t\r\n\000\001 fat World World " QString.
// Check str "Prefix: Hello big, \t\r\n\000\001 fat World" QString.
// Continue.
dummyStatement(&str);
}
void testQString2()
{
QChar data[] = { 'H', 'e', 'l', 'l', 'o' };
QString str1 = QString::fromRawData(data, 4);
QString str2 = QString::fromRawData(data + 1, 4);
BREAK_HERE;
// Check str1 "Hell" QString.
// Check str2 "ello" QString.
// Continue.
dummyStatement(&str1, &str2, &data);
}
void stringRefTest(const QString &refstring)
{
dummyStatement(&refstring);
......@@ -3408,6 +3433,7 @@ namespace qstring {
void testQString()
{
testQString1();
testQString2();
testQString3();
testQStringQuotes();
}
......
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