From 3b31b5c98ce1ef1cc5158326b77d96d484f81aeb Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 10 Dec 2008 16:31:50 +0100 Subject: work on std::list dumper; also a bit of refactoring --- bin/gdbmacros/gdbmacros.cpp | 155 +++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 97 deletions(-) (limited to 'bin') diff --git a/bin/gdbmacros/gdbmacros.cpp b/bin/gdbmacros/gdbmacros.cpp index e074ddd2a5..abca7066ee 100644 --- a/bin/gdbmacros/gdbmacros.cpp +++ b/bin/gdbmacros/gdbmacros.cpp @@ -407,12 +407,13 @@ struct QDumper QDumper &operator<<(unsigned int i); QDumper &operator<<(const void *p); QDumper &operator<<(qulonglong c); - void put(char c); - void addCommaIfNeeded(); - void putBase64Encoded(const char *buf, int n); QDumper &operator<<(const char *str); QDumper &operator<<(const QByteArray &ba); QDumper &operator<<(const QString &str); + void put(char c); + void addCommaIfNeeded(); + void putBase64Encoded(const char *buf, int n); + void putEllipsis(); void disarm(); void beginHash(); // start of data hash output @@ -658,6 +659,14 @@ void QDumper::endHash() put('}'); } +void QDumper::putEllipsis() +{ + d.beginHash(); + P(d, "name", "Warning:"); + P(d, "value", ""); + P(d, "type", d.innertype); + d.endHash(); +} // // Some helpers to keep the dumper code short @@ -816,6 +825,27 @@ static void qDumpInnerValue(QDumper &d, const char *type, const void *addr) } +static void qDumpInnerValueOrPointer(QDumper &d, + const char *type, const char *strippedtype, const void *addr) +{ + if (strippedtype) { + if (deref(addr)) { + P(d, "addr", deref(addr)); + P(d, "type", strippedtype); + qDumpInnerValueHelper(d, strippedtype, deref(addr)); + } else { + P(d, "addr", addr); + P(d, "type", strippedtype); + P(d, "value", ""); + P(d, "numchild", "0"); + } + } else { + P(d, "addr", addr); + P(d, "type", type); + qDumpInnerValueHelper(d, type, addr); + } +} + ////////////////////////////////////////////////////////////////////////////// static void qDumpQByteArray(QDumper &d) @@ -1213,9 +1243,8 @@ static void qDumpQList(QDumper &d) bool isInternal = innerSize <= int(sizeof(void*)) && isMovableType(d.innertype); - P(d, "internal", (int)isInternal); - - P(d, "childtype", d.innertype); + P(d, "internal", (int)isInternal); + P(d, "childtype", d.innertype); if (n > 1000) n = 1000; d << ",children=["; @@ -1245,11 +1274,8 @@ static void qDumpQList(QDumper &d) } d.endHash(); } - if (n < nn) { - d.beginHash(); - P(d, "value", ""); - d.endHash(); - } + if (n < nn) + d.putEllipsis(); d << "]"; } d.disarm(); @@ -1491,7 +1517,6 @@ static void qDumpQObject(QDumper &d) d.beginHash(); P(d, "name", "methods"); P(d, "exp", "*(class '"NS"QObject'*)" << d.data); - P(d, "type", NS"QObjectMethodList"); P(d, "value", "<" << mo->methodCount() << " items>"); P(d, "numchild", mo->methodCount()); d.endHash(); @@ -1877,11 +1902,7 @@ static void qDumpQSet(QDumper &d) d.endHash(); ++i; if (i > 10000) { - d.beginHash(); - P(d, "name", "Warning:"); - P(d, "value", ""); - P(d, "type", ""); - d.endHash(); + d.putEllipsis(); break; } } @@ -1936,13 +1957,8 @@ static void qDumpQStringList(QDumper &d) P(d, "valueencoded", "1"); d.endHash(); } - if (n < list.size()) { - d.beginHash(); - P(d, "name", "Warning:"); - P(d, "value", ""); - P(d, "type", ""); - d.endHash(); - } + if (n < list.size()) + d.putEllipsis(); d << "]"; } d.disarm(); @@ -2066,37 +2082,21 @@ static void qDumpQVector(QDumper &d) P(d, "valuedisabled", "true"); P(d, "numchild", n); if (d.dumpChildren) { - bool innerTypeIsPointer = isPointerType(d.innertype); QByteArray strippedInnerType = stripPointerType(d.innertype); - + const char *stripped = + isPointerType(d.innertype) ? strippedInnerType.data() : 0; if (n > 1000) n = 1000; d << ",children=["; for (int i = 0; i != n; ++i) { d.beginHash(); P(d, "name", "[" << i << "]"); - const void *p = addOffset(v, i * innersize + typeddatasize); - if (innerTypeIsPointer) { - if (deref(p)) { - //P(d, "value","@" << p); - qDumpInnerValue(d, strippedInnerType.data(), deref(p)); - } else { - P(d, "type", d.innertype); - P(d, "value", ""); - P(d, "numchild", "0"); - } - } else { - qDumpInnerValue(d, d.innertype, p); - } - d.endHash(); - } - if (n < nn) { - d.beginHash(); - P(d, "name", "[...]"); - P(d, "value", ""); - P(d, "type", d.innertype); + qDumpInnerValueOrPointer(d, d.innertype, stripped, + addOffset(v, i * innersize + typeddatasize)); d.endHash(); } + if (n < nn) + d.putEllipsis(); d << "]"; } d.disarm(); @@ -2111,23 +2111,17 @@ static void qDumpStdList(QDumper &d) qCheckAccess(p); p = deref(p); qCheckAccess(p); - p = deref(p); - qCheckAccess(p); p = deref(addOffset(d.data, sizeof(void*))); qCheckAccess(p); p = deref(addOffset(p, sizeof(void*))); qCheckAccess(p); p = deref(addOffset(p, sizeof(void*))); qCheckAccess(p); - p = deref(addOffset(p, sizeof(void*))); - qCheckAccess(p); int nn = 0; std::list::const_iterator it = list.begin(); - for (int i = 0; i < 101 && it != list.end(); ++i, ++it) { + for (nn < 101 && it != list.end(); ++nn, ++it) qCheckAccess(it.operator->()); - ++nn; - } if (nn > 100) P(d, "value", ""); @@ -2137,36 +2131,19 @@ static void qDumpStdList(QDumper &d) P(d, "valuedisabled", "true"); if (d.dumpChildren) { - unsigned innersize = d.extraInt[0]; - bool innerTypeIsPointer = isPointerType(d.innertype); QByteArray strippedInnerType = stripPointerType(d.innertype); + const char *stripped = + isPointerType(d.innertype) ? strippedInnerType.data() : 0; d << ",children=["; std::list::const_iterator it = list.begin(); for (int i = 0; i < 1000 && it != list.end(); ++i, ++it) { d.beginHash(); P(d, "name", "[" << i << "]"); - P(d, "type", d.innertype); - const void *p = it.operator->(); - if (innerTypeIsPointer) { - if (deref(p)) { - qDumpInnerValue(d, strippedInnerType.data(), deref(p)); - } else { - P(d, "type", d.innertype); - P(d, "value", ""); - P(d, "numchild", "0"); - } - } else { - qDumpInnerValue(d, d.innertype, p); - } - d.endHash(); - } - if (it != list.end()) { - d.beginHash(); - P(d, "name", "[...]"); - P(d, "value", ""); - P(d, "type", d.innertype); + qDumpInnerValueOrPointer(d, d.innertype, stripped, it.operator->()); d.endHash(); } + if (it != list.end()) + d.putEllipsis(); d << "]"; } d.disarm(); @@ -2238,37 +2215,21 @@ static void qDumpStdVector(QDumper &d) P(d, "numchild", n); if (d.dumpChildren) { unsigned innersize = d.extraInt[0]; - bool innerTypeIsPointer = isPointerType(d.innertype); QByteArray strippedInnerType = stripPointerType(d.innertype); - + const char *stripped = + isPointerType(d.innertype) ? strippedInnerType.data() : 0; if (n > 1000) n = 1000; d << ",children=["; for (int i = 0; i != n; ++i) { d.beginHash(); P(d, "name", "[" << i << "]"); - const void *p = addOffset(v->start, i * innersize); - if (innerTypeIsPointer) { - if (deref(p)) { - //P(d, "value","@" << p); - qDumpInnerValue(d, strippedInnerType.data(), deref(p)); - } else { - P(d, "type", d.innertype); - P(d, "value", ""); - P(d, "numchild", "0"); - } - } else { - qDumpInnerValue(d, d.innertype, p); - } - d.endHash(); - } - if (n < nn) { - d.beginHash(); - P(d, "name", "[...]"); - P(d, "value", ""); - P(d, "type", d.innertype); + qDumpInnerValueOrPointer(d, d.innertype, stripped, + addOffset(v->start, i * innersize)); d.endHash(); } + if (n < nn) + d.putEllipsis(); d << "]"; } d.disarm(); -- cgit v1.2.3