Commit 65e13b70 authored by Friedemann Kleint's avatar Friedemann Kleint

Debugger: Fix autotests on Windows

Format pointers consistently using 0x%[l]x in printf/scanf.
Remove %p formatting as the existence of the prefix 0x
is platform-dependent (missing with MSVC), which caused
a scanf error and thus dumper crash for QAbstractItem.
Reviewed-by: default avatarck <qt-info@nokia.com>
parent fefd72b2
......@@ -57,6 +57,12 @@
#include <QtCore/QTextStream>
#include <QtCore/QVector>
#if (QT_POINTER_SIZE==4) // How to printf/scanf a pointer (uintptr_t)
# define POINTER_PRINTFORMAT "0x%x"
#else
# define POINTER_PRINTFORMAT "0x%lx"
#endif
#ifndef QT_BOOTSTRAPPED
#include <QtCore/QModelIndex>
......@@ -630,18 +636,10 @@ QDumper &QDumper::put(int i)
QDumper &QDumper::put(const void *p)
{
static char buf[100];
if (p) {
sprintf(buf, "%p", p);
// we get a '0x' prefix only on some implementations.
// if it isn't there, write it out manually.
if (buf[1] != 'x') {
put('0');
put('x');
}
put(buf);
pos += sprintf(outBuffer + pos, POINTER_PRINTFORMAT, reinterpret_cast<uintptr_t>(p));
} else {
put("<null>");
pos += sprintf(outBuffer + pos, "<null>");
}
return *this;
}
......@@ -1070,7 +1068,10 @@ static void qDumpQAbstractItem(QDumper &d)
QModelIndex mi;
{
ModelIndex *mm = reinterpret_cast<ModelIndex *>(&mi);
sscanf(d.templateParameters[0], "%d,%d,%p,%p", &mm->r, &mm->c, &mm->p, &mm->m);
mm->r = mm->c = 0;
mm->p = mm->m = 0;
sscanf(d.templateParameters[0], "%d,%d,"POINTER_PRINTFORMAT","POINTER_PRINTFORMAT, &mm->r, &mm->c,
reinterpret_cast<uintptr_t*>(&mm->p), reinterpret_cast<uintptr_t*>(&mm->m));
}
const QAbstractItemModel *m = mi.model();
const int rowCount = m->rowCount(mi);
......@@ -2149,8 +2150,8 @@ static void qDumpQVariantHelper(const QVariant *v, QString *value,
default: {
char buf[1000];
const char *format = (v->typeName()[0] == 'Q')
? "'"NS"%s "NS"qVariantValue<"NS"%s >'(*('"NS"QVariant'*)%p)"
: "'%s "NS"qVariantValue<%s >'(*('"NS"QVariant'*)%p)";
? "'"NS"%s "NS"qVariantValue<"NS"%s >'(*('"NS"QVariant'*)"POINTER_PRINTFORMAT")"
: "'%s "NS"qVariantValue<%s >'(*('"NS"QVariant'*)"POINTER_PRINTFORMAT")";
qsnprintf(buf, sizeof(buf) - 1, format, v->typeName(), v->typeName(), v);
*exp = QLatin1String(buf);
*numchild = 1;
......
......@@ -10,6 +10,12 @@
#include <QtTest/QtTest>
//#include <QtTest/qtest_gui.h>
#if (QT_POINTER_SIZE==4)
# define POINTER_PRINTFORMAT "0x%x"
#else
# define POINTER_PRINTFORMAT "0x%lx"
#endif
#undef NS
#ifdef QT_NAMESPACE
# define STRINGIFY0(s) #s
......@@ -387,7 +393,7 @@ static void testDumper(QByteArray expected0, const void *data, QByteArray outert
extraInt0, extraInt1, extraInt2, extraInt3);
QString expected(expected0);
char buf[100];
sprintf(buf, "%p", data);
sprintf(buf, POINTER_PRINTFORMAT, (uintptr_t)data);
if ((!expected.startsWith('t') && !expected.startsWith('f'))
|| expected.startsWith("type"))
expected = "tiname='$I',addr='$A'," + expected;
......@@ -417,7 +423,7 @@ static void testDumper(QByteArray expected0, const void *data, QByteArray outert
QByteArray str(const void *p)
{
char buf[100];
sprintf(buf, "%p", p);
sprintf(buf, POINTER_PRINTFORMAT, (uintptr_t)p);
return buf;
}
......@@ -880,7 +886,7 @@ void tst_Debugger::dumpQByteArray()
&ba, NS"QByteArray", true);
// Case 5: Regular and special characters and the replacement character.
ba = QByteArray("abc\a\n\r\e\'\"?");
ba = QByteArray("abc\a\n\r\033\'\"?");
testDumper("value='YWJjBwoNGyciPw==',valueencoded='1',type='"NS"QByteArray',"
"numchild='10',childtype='char',childnumchild='0',children=["
"{value='61 (97 'a')'},{value='62 (98 'b')'},"
......
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