Fixes: debugger: work on hash dumper for string-ish keys

This commit is contained in:
hjk
2009-01-28 16:55:09 +01:00
parent 2dac5e6447
commit b58fe0f4d3
3 changed files with 76 additions and 37 deletions

View File

@@ -216,7 +216,7 @@ QT_END_NAMESPACE
// comma-separated integer list // comma-separated integer list
static char qDumpInBuffer[10000]; static char qDumpInBuffer[10000];
static char qDumpOutBuffer[100000]; static char qDumpOutBuffer[100000];
static char qDumpSize[20]; //static char qDumpSize[20];
namespace { namespace {
@@ -314,6 +314,15 @@ static bool isShortKey(const char *type)
return isSimpleType(type) || isEqual(type, NS"QString"); return isSimpleType(type) || isEqual(type, NS"QString");
} }
static bool isStringType(const char *type)
{
return isEqual(type, NS"QString")
|| isEqual(type, NS"QByteArray")
|| isEqual(type, "std::string")
|| isEqual(type, "std::wstring")
|| isEqual(type, "wstring");
}
static bool isMovableType(const char *type) static bool isMovableType(const char *type)
{ {
if (isPointerType(type)) if (isPointerType(type))
@@ -555,7 +564,7 @@ void QDumper::addCommaIfNeeded()
put(','); put(',');
} }
void QDumper::putBase64Encoded(const char *buf, int n, char delim) void QDumper::putBase64Encoded(const char *buf, int n)
{ {
const char alphabet[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef" const char alphabet[] = "ABCDEFGH" "IJKLMNOP" "QRSTUVWX" "YZabcdef"
"ghijklmn" "opqrstuv" "wxyz0123" "456789+/"; "ghijklmn" "opqrstuv" "wxyz0123" "456789+/";
@@ -740,6 +749,7 @@ static void qDumpInnerValueHelper(QDumper &d, const char *type, const void *addr
return; return;
case 'B': case 'B':
if (isEqual(type, "QByteArray")) { if (isEqual(type, "QByteArray")) {
d.addCommaIfNeeded();
d << field << "encoded=\"1\","; d << field << "encoded=\"1\",";
P(d, field, *(QByteArray*)addr); P(d, field, *(QByteArray*)addr);
} }
@@ -769,6 +779,7 @@ static void qDumpInnerValueHelper(QDumper &d, const char *type, const void *addr
return; return;
case 'S': case 'S':
if (isEqual(type, "QString")) { if (isEqual(type, "QString")) {
d.addCommaIfNeeded();
d << field << "encoded=\"1\","; d << field << "encoded=\"1\",";
P(d, field, *(QString*)addr); P(d, field, *(QString*)addr);
} }
@@ -1086,13 +1097,17 @@ static void qDumpQHash(QDumper &d)
if (d.dumpChildren) { if (d.dumpChildren) {
if (n > 1000) if (n > 1000)
n = 1000; n = 1000;
bool simpleKey = isShortKey(keyType); bool isSimpleKey = isSimpleType(keyType);
bool simpleValue = isShortKey(valueType); bool isStringKey = isStringType(keyType);
bool isSimpleValue = isSimpleType(valueType);
bool opt = isOptimizedIntKey(keyType); bool opt = isOptimizedIntKey(keyType);
int keyOffset = hashOffset(opt, true, keySize, valueSize); int keyOffset = hashOffset(opt, true, keySize, valueSize);
int valueOffset = hashOffset(opt, false, keySize, valueSize); int valueOffset = hashOffset(opt, false, keySize, valueSize);
P(d, "extra", "simplekey: " << simpleKey << " simpleValue: " << simpleValue P(d, "extra", "isSimpleKey: " << isSimpleKey
<< " isStringKey: " << isStringKey
<< " isSimpleValue: " << isSimpleValue
<< " valueType: '" << valueType << "'"
<< " keySize: " << keyOffset << " valueOffset: " << valueOffset << " keySize: " << keyOffset << " valueOffset: " << valueOffset
<< " opt: " << opt); << " opt: " << opt);
@@ -1103,18 +1118,17 @@ static void qDumpQHash(QDumper &d)
d << ",children=["; d << ",children=[";
while (node != end) { while (node != end) {
d.beginHash(); d.beginHash();
if (simpleKey) { P(d, "name", i);
P(d, "name", i); qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key");
qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key"); qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
if (simpleValue) if (isSimpleKey && isSimpleValue) {
qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
P(d, "type", valueType); P(d, "type", valueType);
P(d, "addr", addOffset(node, valueOffset)); P(d, "addr", addOffset(node, valueOffset));
} else { } else {
P(d, "name", i); P(d, "exp", "*('"NS"QHashNode<" << keyType << ","
//P(d, "exp", "*(char*)" << node); << valueType << " >'*)" << node);
P(d, "exp", "*('"NS"QHashNode<" << keyType << "," << valueType << " >'*)" << node); P(d, "type", "'"NS"QHashNode<" << keyType << ","
P(d, "type", "'"NS"QHashNode<" << keyType << "," << valueType << " >'"); << valueType << " >'");
} }
d.endHash(); d.endHash();
++i; ++i;
@@ -1262,8 +1276,8 @@ static void qDumpQLinkedList(QDumper &d)
P(d, "numchild", n); P(d, "numchild", n);
P(d, "childtype", d.innertype); P(d, "childtype", d.innertype);
if (d.dumpChildren) { if (d.dumpChildren) {
unsigned innerSize = d.extraInt[0]; //unsigned innerSize = d.extraInt[0];
bool innerTypeIsPointer = isPointerType(d.innertype); //bool innerTypeIsPointer = isPointerType(d.innertype);
QByteArray strippedInnerType = stripPointerType(d.innertype); QByteArray strippedInnerType = stripPointerType(d.innertype);
const char *stripped = const char *stripped =
isPointerType(d.innertype) ? strippedInnerType.data() : 0; isPointerType(d.innertype) ? strippedInnerType.data() : 0;
@@ -1397,13 +1411,13 @@ static void qDumpQMap(QDumper &d)
unsigned mapnodesize = d.extraInt[2]; unsigned mapnodesize = d.extraInt[2];
unsigned valueOff = d.extraInt[3]; unsigned valueOff = d.extraInt[3];
bool simpleKey = isShortKey(keyType); bool isSimpleKey = isShortKey(keyType);
bool simpleValue = isShortKey(valueType); bool isSimpleValue = isShortKey(valueType);
// both negative: // both negative:
int keyOffset = 2 * sizeof(void*) - int(mapnodesize); int keyOffset = 2 * sizeof(void*) - int(mapnodesize);
int valueOffset = 2 * sizeof(void*) - int(mapnodesize) + valueOff; int valueOffset = 2 * sizeof(void*) - int(mapnodesize) + valueOff;
P(d, "extra", "simplekey: " << simpleKey << " simpleValue: " << simpleValue P(d, "extra", "simplekey: " << isSimpleKey << " isSimpleValue: " << isSimpleValue
<< " keyOffset: " << keyOffset << " valueOffset: " << valueOffset << " keyOffset: " << keyOffset << " valueOffset: " << valueOffset
<< " mapnodesize: " << mapnodesize); << " mapnodesize: " << mapnodesize);
d << ",children=["; d << ",children=[";
@@ -1415,10 +1429,10 @@ static void qDumpQMap(QDumper &d)
while (node != end) { while (node != end) {
d.beginHash(); d.beginHash();
P(d, "name", i); P(d, "name", i);
if (simpleKey) { if (isSimpleKey) {
P(d, "type", valueType); P(d, "type", valueType);
qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key"); qDumpInnerValueHelper(d, keyType, addOffset(node, keyOffset), "key");
if (simpleValue) if (isSimpleValue)
qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset)); qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
P(d, "type", valueType); P(d, "type", valueType);
@@ -2199,26 +2213,30 @@ static void qDumpStdMap(QDumper &d)
P(d, "pairtype", pairType); P(d, "pairtype", pairType);
if (d.dumpChildren) { if (d.dumpChildren) {
bool simpleKey = isSimpleType(keyType); bool isSimpleKey = isSimpleType(keyType);
bool simpleValue = isShortKey(valueType); bool isStringKey = isStringType(keyType);
bool isSimpleValue = isShortKey(valueType);
int valueOffset = d.extraInt[2]; int valueOffset = d.extraInt[2];
d << ",children=["; d << ",children=[";
it = map.begin(); it = map.begin();
for (int i = 0; i < 1000 && it != map.end(); ++i, ++it) { for (int i = 0; i < 1000 && it != map.end(); ++i, ++it) {
const void *node = it.operator->(); const void *node = it.operator->();
if (simpleKey) { if (isSimpleKey) {
d.beginHash(); d.beginHash();
P(d, "type", valueType); P(d, "type", valueType);
qDumpInnerValueHelper(d, keyType, node, "name"); P(d, "name", i);
qDumpInnerValueHelper(d, keyType, node, "key");
P(d, "nameisindex", "1"); P(d, "nameisindex", "1");
if (simpleValue) if (isSimpleValue)
qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset)); qDumpInnerValueHelper(d, valueType, addOffset(node, valueOffset));
P(d, "addr", addOffset(node, valueOffset)); P(d, "addr", addOffset(node, valueOffset));
d.endHash(); d.endHash();
} else { } else {
d.beginHash(); d.beginHash();
P(d, "name", i); P(d, "name", i);
if (isStringKey)
qDumpInnerValueHelper(d, keyType, node, "key");
P(d, "addr", it.operator->()); P(d, "addr", it.operator->());
P(d, "type", pairType); P(d, "type", pairType);
d.endHash(); d.endHash();

View File

@@ -2833,9 +2833,12 @@ static bool extractTemplate(const QString &type, QString *tmplate, QString *inne
// 'tmplate' and "Inner1@Inner2@..." etc in 'inner'. Result indicates // 'tmplate' and "Inner1@Inner2@..." etc in 'inner'. Result indicates
// whether parsing was successful // whether parsing was successful
int level = 0; int level = 0;
bool skipSpace = false;
for (int i = 0; i != type.size(); ++i) { for (int i = 0; i != type.size(); ++i) {
QChar c = type[i]; QChar c = type[i];
if (c == '<') { if (c == ' ' && skipSpace) {
skipSpace = false;
} else if (c == '<') {
*(level == 0 ? tmplate : inner) += c; *(level == 0 ? tmplate : inner) += c;
++level; ++level;
} else if (c == '>') { } else if (c == '>') {
@@ -2843,6 +2846,7 @@ static bool extractTemplate(const QString &type, QString *tmplate, QString *inne
*(level == 0 ? tmplate : inner) += c; *(level == 0 ? tmplate : inner) += c;
} else if (c == ',') { } else if (c == ',') {
*inner += (level == 1) ? '@' : ','; *inner += (level == 1) ? '@' : ',';
skipSpace = true;
} else { } else {
*(level == 0 ? tmplate : inner) += c; *(level == 0 ? tmplate : inner) += c;
} }
@@ -3555,9 +3559,15 @@ void GdbEngine::handleDumpCustomValue2(const GdbResultRecord &record,
data1.name = '[' + data1.name + ']'; data1.name = '[' + data1.name + ']';
QString key = item.findChild("key").data(); QString key = item.findChild("key").data();
if (!key.isEmpty()) { if (!key.isEmpty()) {
if (item.findChild("keyencoded").data()[0] == '1') if (item.findChild("keyencoded").data()[0] == '1') {
key = '"' + QByteArray::fromBase64(key.toUtf8()) + '"'; key = '"' + QByteArray::fromBase64(key.toUtf8()) + '"';
data1.name += " (" + key + ")"; if (key.size() > 13) {
key = key.left(12);
key += "...";
}
}
//data1.name += " (" + key + ")";
data1.name = key;
} }
setWatchDataType(data1, item.findChild("type")); setWatchDataType(data1, item.findChild("type"));
setWatchDataExpression(data1, item.findChild("exp")); setWatchDataExpression(data1, item.findChild("exp"));

View File

@@ -159,16 +159,27 @@ void testQHash()
#if 1 #if 1
QHash<QString, float> hgg1; QHash<QString, int> hgg1;
hgg1["22.0"] = 22.0; hgg1["22.0"] = 22.0;
hgg1["23.0"] = 22.0; hgg1["123.0"] = 22.0;
hgg1["24.0"] = 22.0; hgg1["111111ss111128.0"] = 28.0;
hgg1["25.0"] = 22.0; hgg1["11124.0"] = 22.0;
hgg1["26.0"] = 22.0; hgg1["1111125.0"] = 22.0;
hgg1["27.0"] = 27.0; hgg1["11111126.0"] = 22.0;
hgg1["28.0"] = 28.0; hgg1["111111127.0"] = 27.0;
hgg1["29.0"] = 29.0; hgg1["111111111128.0"] = 28.0;
hgg1["111111111111111111129.0"] = 29.0;
QHash<QByteArray, float> hgx1;
hgx1["22.0"] = 22.0;
hgx1["123.0"] = 22.0;
hgx1["111111ss111128.0"] = 28.0;
hgx1["11124.0"] = 22.0;
hgx1["1111125.0"] = 22.0;
hgx1["11111126.0"] = 22.0;
hgx1["111111127.0"] = 27.0;
hgx1["111111111128.0"] = 28.0;
hgx1["111111111111111111129.0"] = 29.0;
#endif #endif
#if 1 #if 1