Commit 09f77930 authored by Friedemann Kleint's avatar Friedemann Kleint

Debugger: Do not use C99 types for pointers in sprintf() formats.

Pointer fit into long or long long (Win64).
Reviewed-by: default avatarOswald Buddenhagen <oswald.buddenhagen@nokia.com>
parent 224bae15
...@@ -57,16 +57,6 @@ ...@@ -57,16 +57,6 @@
#include <QtCore/QTextStream> #include <QtCore/QTextStream>
#include <QtCore/QVector> #include <QtCore/QVector>
#ifndef Q_OS_WIN
# include <stdint.h>
#endif
#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 #ifndef QT_BOOTSTRAPPED
#include <QtCore/QModelIndex> #include <QtCore/QModelIndex>
...@@ -641,7 +631,9 @@ QDumper &QDumper::put(int i) ...@@ -641,7 +631,9 @@ QDumper &QDumper::put(int i)
QDumper &QDumper::put(const void *p) QDumper &QDumper::put(const void *p)
{ {
if (p) { if (p) {
pos += sprintf(outBuffer + pos, POINTER_PRINTFORMAT, reinterpret_cast<uintptr_t>(p)); // Pointer is 'long long' on WIN_64, only
static const char *printFormat = sizeof(quintptr) == sizeof(long) ? "0x%lx" : "0x%llx";
pos += sprintf(outBuffer + pos, printFormat, reinterpret_cast<uintptr_t>(p));
} else { } else {
pos += sprintf(outBuffer + pos, "<null>"); pos += sprintf(outBuffer + pos, "<null>");
} }
...@@ -1073,8 +1065,10 @@ static void qDumpQAbstractItem(QDumper &d) ...@@ -1073,8 +1065,10 @@ static void qDumpQAbstractItem(QDumper &d)
{ {
ModelIndex *mm = reinterpret_cast<ModelIndex *>(&mi); ModelIndex *mm = reinterpret_cast<ModelIndex *>(&mi);
mm->r = mm->c = 0; mm->r = mm->c = 0;
mm->p = mm->m = 0; mm->p = mm->m = 0;
sscanf(d.templateParameters[0], "%d,%d,"POINTER_PRINTFORMAT","POINTER_PRINTFORMAT, &mm->r, &mm->c, static const char *printFormat = sizeof(quintptr) == sizeof(long) ?
"%d,%d,0x%lx,0x%lx" : "%d,%d,0x%llx,0x%llx";
sscanf(d.templateParameters[0], printFormat, &mm->r, &mm->c,
reinterpret_cast<uintptr_t*>(&mm->p), reinterpret_cast<uintptr_t*>(&mm->m)); reinterpret_cast<uintptr_t*>(&mm->p), reinterpret_cast<uintptr_t*>(&mm->m));
} }
const QAbstractItemModel *m = mi.model(); const QAbstractItemModel *m = mi.model();
...@@ -2152,10 +2146,14 @@ static void qDumpQVariantHelper(const QVariant *v, QString *value, ...@@ -2152,10 +2146,14 @@ static void qDumpQVariantHelper(const QVariant *v, QString *value,
break; break;
#endif #endif
default: { default: {
static const char *qTypeFormat = sizeof(quintptr) == sizeof(long) ?
"'"NS"%s "NS"qVariantValue<"NS"%s >'(*('"NS"QVariant'*)0x%lx)" :
"'"NS"%s "NS"qVariantValue<"NS"%s >'(*('"NS"QVariant'*)0x%llx)";
static const char *nonQTypeFormat = sizeof(quintptr) == sizeof(long) ?
"'%s "NS"qVariantValue<%s >'(*('"NS"QVariant'*)0x%lx)" :
"'%s "NS"qVariantValue<%s >'(*('"NS"QVariant'*)0x%llx)";
char buf[1000]; char buf[1000];
const char *format = (v->typeName()[0] == 'Q') const char *format = (v->typeName()[0] == 'Q') ? qTypeFormat : nonQTypeFormat;
? "'"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); qsnprintf(buf, sizeof(buf) - 1, format, v->typeName(), v->typeName(), v);
*exp = QLatin1String(buf); *exp = QLatin1String(buf);
*numchild = 1; *numchild = 1;
......
...@@ -10,11 +10,10 @@ ...@@ -10,11 +10,10 @@
#include <QtTest/QtTest> #include <QtTest/QtTest>
//#include <QtTest/qtest_gui.h> //#include <QtTest/qtest_gui.h>
#if (QT_POINTER_SIZE==4) static const char *pointerPrintFormat()
# define POINTER_PRINTFORMAT "0x%x" {
#else return sizeof(quintptr) == sizeof(long) ? "0x%lx" : "0x%llx";
# define POINTER_PRINTFORMAT "0x%lx" }
#endif
#undef NS #undef NS
#ifdef QT_NAMESPACE #ifdef QT_NAMESPACE
...@@ -393,7 +392,7 @@ static void testDumper(QByteArray expected0, const void *data, QByteArray outert ...@@ -393,7 +392,7 @@ static void testDumper(QByteArray expected0, const void *data, QByteArray outert
extraInt0, extraInt1, extraInt2, extraInt3); extraInt0, extraInt1, extraInt2, extraInt3);
QString expected(expected0); QString expected(expected0);
char buf[100]; char buf[100];
sprintf(buf, POINTER_PRINTFORMAT, (uintptr_t)data); sprintf(buf, pointerPrintFormat(), (uintptr_t)data);
if ((!expected.startsWith('t') && !expected.startsWith('f')) if ((!expected.startsWith('t') && !expected.startsWith('f'))
|| expected.startsWith("type")) || expected.startsWith("type"))
expected = "tiname='$I',addr='$A'," + expected; expected = "tiname='$I',addr='$A'," + expected;
...@@ -423,7 +422,7 @@ static void testDumper(QByteArray expected0, const void *data, QByteArray outert ...@@ -423,7 +422,7 @@ static void testDumper(QByteArray expected0, const void *data, QByteArray outert
QByteArray str(const void *p) QByteArray str(const void *p)
{ {
char buf[100]; char buf[100];
sprintf(buf, POINTER_PRINTFORMAT, (uintptr_t)p); sprintf(buf, pointerPrintFormat(), (uintptr_t)p);
return buf; return buf;
} }
...@@ -1975,7 +1974,7 @@ void tst_Debugger::dumpQObjectSignalList() ...@@ -1975,7 +1974,7 @@ void tst_Debugger::dumpQObjectSignalList()
"numchild='0',addr='$A',type='"NS"QObjectSignal'}," "numchild='0',addr='$A',type='"NS"QObjectSignal'},"
"{name='21',value='columnsMoved(QModelIndex,int,int,QModelIndex,int)'," "{name='21',value='columnsMoved(QModelIndex,int,int,QModelIndex,int)',"
"numchild='0',addr='$A',type='"NS"QObjectSignal'}]"; "numchild='0',addr='$A',type='"NS"QObjectSignal'}]";
testDumper(expected << "0" << "0" << "0" << "0" << "0" << "0", testDumper(expected << "0" << "0" << "0" << "0" << "0" << "0",
&m, NS"QObjectSignalList", true); &m, NS"QObjectSignalList", true);
......
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