CDB: Add further checking to avoid invalid set asserts.

Clear a failed call. _HAS_ITERATOR_DEBUGGING can unfortunately
not be turned off as it is not binary compatible with other code.
This commit is contained in:
Friedemann Kleint
2009-10-19 16:44:07 +02:00
parent 077c19a661
commit 9e10e11c9c
3 changed files with 157 additions and 50 deletions

View File

@@ -3178,6 +3178,14 @@ static void qDumpStdSetHelper(QDumper &d)
const int nn = set.size(); const int nn = set.size();
if (nn < 0) if (nn < 0)
return; return;
#ifdef Q_CC_MSVC
// This set has a head element pointer:
// "{ base class ; HeadType *_MyHead ; unsigned int _MySize }",
// which is valid even if the set is empty. Check that to avoid iterator asserts.
const void *headPtrAddress = addOffset(&set, sizeof(DummyType) - sizeof(unsigned int) - sizeof(void*));
if (const void *headPtr = deref(headPtrAddress))
qCheckAccess(headPtr);
#endif
Q_TYPENAME DummyType::const_iterator it = set.begin(); Q_TYPENAME DummyType::const_iterator it = set.begin();
const Q_TYPENAME DummyType::const_iterator cend = set.end(); const Q_TYPENAME DummyType::const_iterator cend = set.end();
for (int i = 0; i < nn && i < 10 && it != cend; ++i, ++it) for (int i = 0; i < nn && i < 10 && it != cend; ++i, ++it)

View File

@@ -48,13 +48,32 @@
// Test uninitialized variables allocing memory // Test uninitialized variables allocing memory
bool optTestUninitialized = false; bool optTestUninitialized = false;
bool optTestAll = false;
bool optEmptyContainers = false;
unsigned optVerbose = 0;
// Provide address of type of be tested.
// When testing unitialized memory, allocate at random.
template <class T> template <class T>
inline T* testAddress(T* in) inline T* testAddress(T* in)
{ {
return optTestUninitialized ? unsigned char *mem = 0;
(reinterpret_cast<T*>(new char[sizeof(T)])) if (optTestUninitialized) {
: in; mem = new unsigned char[sizeof(T)];
for (int i = 0; i < sizeof(T); i++) {
mem[i] = char(rand() % 255u);
}
} else {
mem = reinterpret_cast<unsigned char*>(in);
}
if (optVerbose) {
for (int i = 0; i < sizeof(T); i++) {
unsigned int b = mem[i];
printf("%2d %2x %3d\n", i, b, b);
}
fflush(stdout);
}
return reinterpret_cast<T*>(mem);
} }
/* Test program for Dumper development/porting. /* Test program for Dumper development/porting.
@@ -175,8 +194,10 @@ static int dumpQMapIntInt()
QMap<int,int> test; QMap<int,int> test;
QMapNode<int,int> mapNode; QMapNode<int,int> mapNode;
const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode; const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode;
test.insert(42, 43); if (!optEmptyContainers) {
test.insert(43, 44); test.insert(42, 43);
test.insert(43, 44);
}
prepareInBuffer("QMap", "local.qmapintint", "local.qmapintint", "int@int"); prepareInBuffer("QMap", "local.qmapintint", "local.qmapintint", "int@int");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(int), sizeof(mapNode), valueOffset); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(int), sizeof(mapNode), valueOffset);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -189,8 +210,10 @@ static int dumpQMapIntString()
QMap<int,QString> test; QMap<int,QString> test;
QMapNode<int,QString> mapNode; QMapNode<int,QString> mapNode;
const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode; const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode;
test.insert(42, QLatin1String("fortytwo")); if (!optEmptyContainers) {
test.insert(43, QLatin1String("fortytree")); test.insert(42, QLatin1String("fortytwo"));
test.insert(43, QLatin1String("fortytree"));
}
prepareInBuffer("QMap", "local.qmapintqstring", "local.qmapintqstring", "int@QString"); prepareInBuffer("QMap", "local.qmapintqstring", "local.qmapintqstring", "int@QString");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(QString), sizeof(mapNode), valueOffset); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(QString), sizeof(mapNode), valueOffset);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -201,8 +224,10 @@ static int dumpQMapIntString()
static int dumpQSetInt() static int dumpQSetInt()
{ {
QSet<int> test; QSet<int> test;
test.insert(42); if (!optEmptyContainers) {
test.insert(43); test.insert(42);
test.insert(43);
}
prepareInBuffer("QSet", "local.qsetint", "local.qsetint", "int"); prepareInBuffer("QSet", "local.qsetint", "local.qsetint", "int");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), 0, 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), 0, 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -216,9 +241,11 @@ static int dumpQMapQStringString()
QMap<QString,QString> test; QMap<QString,QString> test;
QMapNode<QString,QString> mapNode; QMapNode<QString,QString> mapNode;
const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode; const int valueOffset = (char*)&(mapNode.value) - (char*)&mapNode;
test.insert(QLatin1String("42s"), QLatin1String("fortytwo")); if (!optEmptyContainers) {
test.insert(QLatin1String("423"), QLatin1String("fortytree")); test.insert(QLatin1String("42s"), QLatin1String("fortytwo"));
prepareInBuffer("QMap", "local.qmapqstringqstring", "local.qmapqstringqstring", "QString@QString"); test.insert(QLatin1String("423"), QLatin1String("fortytree"));
}
prepareInBuffer("QMap", "local.qmapqstringqstring", "local.qmapqstringqstring", "QString@QString");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), sizeof(QString), sizeof(mapNode), valueOffset); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), sizeof(QString), sizeof(mapNode), valueOffset);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
fputc('\n', stdout); fputc('\n', stdout);
@@ -278,8 +305,10 @@ static int dumpStdWString()
static int dumpStdStringList() static int dumpStdStringList()
{ {
std::list<std::string> test; std::list<std::string> test;
test.push_back("item1"); if (!optEmptyContainers) {
test.push_back("item2"); test.push_back("item1");
test.push_back("item2");
}
prepareInBuffer("std::list", "local.stringlist", "local.stringlist", "std::string"); prepareInBuffer("std::list", "local.stringlist", "local.stringlist", "std::string");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<std::string>::allocator_type), 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<std::string>::allocator_type), 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -290,8 +319,10 @@ static int dumpStdStringList()
static int dumpStdStringQList() static int dumpStdStringQList()
{ {
QList<std::string> test; QList<std::string> test;
test.push_back("item1"); if (!optEmptyContainers) {
test.push_back("item2"); test.push_back("item1");
test.push_back("item2");
}
prepareInBuffer("QList", "local.stringqlist", "local.stringqlist", "std::string"); prepareInBuffer("QList", "local.stringqlist", "local.stringqlist", "std::string");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), 0, 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), 0, 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -302,8 +333,10 @@ static int dumpStdStringQList()
static int dumpStdIntList() static int dumpStdIntList()
{ {
std::list<int> test; std::list<int> test;
test.push_back(1); if (!optEmptyContainers) {
test.push_back(2); test.push_back(1);
test.push_back(2);
}
prepareInBuffer("std::list", "local.intlist", "local.intlist", "int"); prepareInBuffer("std::list", "local.intlist", "local.intlist", "int");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -314,8 +347,10 @@ static int dumpStdIntList()
static int dumpStdIntVector() static int dumpStdIntVector()
{ {
std::vector<int> test; std::vector<int> test;
test.push_back(1); if (!optEmptyContainers) {
test.push_back(2); test.push_back(1);
test.push_back(2);
}
prepareInBuffer("std::vector", "local.intvector", "local.intvector", "int"); prepareInBuffer("std::vector", "local.intvector", "local.intvector", "int");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -326,8 +361,10 @@ static int dumpStdIntVector()
static int dumpStdStringVector() static int dumpStdStringVector()
{ {
std::vector<std::string> test; std::vector<std::string> test;
test.push_back("item1"); if (!optEmptyContainers) {
test.push_back("item2"); test.push_back("item1");
test.push_back("item2");
}
prepareInBuffer("std::vector", "local.stringvector", "local.stringvector", "std::string"); prepareInBuffer("std::vector", "local.stringvector", "local.stringvector", "std::string");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<int>::allocator_type), 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<int>::allocator_type), 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -338,8 +375,10 @@ static int dumpStdStringVector()
static int dumpStdWStringVector() static int dumpStdWStringVector()
{ {
std::vector<std::wstring> test; std::vector<std::wstring> test;
test.push_back(L"item1"); if (!optEmptyContainers) {
test.push_back(L"item2"); test.push_back(L"item1");
test.push_back(L"item2");
}
prepareInBuffer("std::vector", "local.wstringvector", "local.wstringvector", "std::wstring"); prepareInBuffer("std::vector", "local.wstringvector", "local.wstringvector", "std::wstring");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::wstring), sizeof(std::list<int>::allocator_type), 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::wstring), sizeof(std::list<int>::allocator_type), 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -350,8 +389,10 @@ static int dumpStdWStringVector()
static int dumpStdIntSet() static int dumpStdIntSet()
{ {
std::set<int> test; std::set<int> test;
test.insert(1); if (!optEmptyContainers) {
test.insert(2); test.insert(1);
test.insert(2);
}
prepareInBuffer("std::set", "local.intset", "local.intset", "int"); prepareInBuffer("std::set", "local.intset", "local.intset", "int");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(int), sizeof(std::list<int>::allocator_type), 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -362,8 +403,10 @@ static int dumpStdIntSet()
static int dumpStdStringSet() static int dumpStdStringSet()
{ {
std::set<std::string> test; std::set<std::string> test;
test.insert("item1"); if (!optEmptyContainers) {
test.insert("item2"); test.insert("item1");
test.insert("item2");
}
prepareInBuffer("std::set", "local.stringset", "local.stringset", "std::string"); prepareInBuffer("std::set", "local.stringset", "local.stringset", "std::string");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<int>::allocator_type), 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(std::string), sizeof(std::list<int>::allocator_type), 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -374,8 +417,10 @@ static int dumpStdStringSet()
static int dumpStdQStringSet() static int dumpStdQStringSet()
{ {
std::set<QString> test; std::set<QString> test;
test.insert(QLatin1String("item1")); if (!optEmptyContainers) {
test.insert(QLatin1String("item2")); test.insert(QLatin1String("item1"));
test.insert(QLatin1String("item2"));
}
prepareInBuffer("std::set", "local.stringset", "local.stringset", "QString"); prepareInBuffer("std::set", "local.stringset", "local.stringset", "QString");
qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), sizeof(std::list<int>::allocator_type), 0, 0); qDumpObjectData440(2, 42, testAddress(&test), 1, sizeof(QString), sizeof(std::list<int>::allocator_type), 0, 0);
fputs(qDumpOutBuffer, stdout); fputs(qDumpOutBuffer, stdout);
@@ -385,9 +430,11 @@ static int dumpStdQStringSet()
static int dumpStdMapIntString() static int dumpStdMapIntString()
{ {
std::map<int,std::string> test; std::map<int,std::string> test;
std::map<int,std::string>::value_type entry(42, std::string("fortytwo")); std::map<int,std::string>::value_type entry(42, std::string("fortytwo"));
test.insert(entry); if (!optEmptyContainers) {
test.insert(entry);
}
const int valueOffset = (char*)&(entry.second) - (char*)&entry; const int valueOffset = (char*)&(entry.second) - (char*)&entry;
prepareInBuffer("std::map", "local.stdmapintstring", "local.stdmapintstring", prepareInBuffer("std::map", "local.stdmapintstring", "local.stdmapintstring",
"int@std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::less<int>@std::allocator<std::pair<const int,std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >"); "int@std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::less<int>@std::allocator<std::pair<const int,std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >");
@@ -402,7 +449,9 @@ static int dumpStdMapStringString()
typedef std::map<std::string,std::string> TestType; typedef std::map<std::string,std::string> TestType;
TestType test; TestType test;
const TestType::value_type entry("K", "V"); const TestType::value_type entry("K", "V");
test.insert(entry); if (!optEmptyContainers) {
test.insert(entry);
}
const int valueOffset = (char*)&(entry.second) - (char*)&entry; const int valueOffset = (char*)&(entry.second) - (char*)&entry;
prepareInBuffer("std::map", "local.stdmapstringstring", "local.stdmapstringstring", prepareInBuffer("std::map", "local.stdmapstringstring", "local.stdmapstringstring",
"std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::less<int>@std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >"); "std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::basic_string<char,std::char_traits<char>,std::allocator<char> >@std::less<int>@std::allocator<std::pair<const std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >");
@@ -502,6 +551,23 @@ static TypeDumpFunctionMap registerTypes()
return rc; return rc;
} }
static void usage(const char *b, const TypeDumpFunctionMap &tdm)
{
printf("Usage: %s [-v][-u][-e] <type1> <type2..>\n", b);
printf("Usage: %s [-v][-u][-e] -a excluded_type1 <excluded_type2...>\n", b);
printf("Options: -u Test uninitialized memory\n");
printf(" -e Empty containers\n");
printf(" -v Verbose\n");
printf(" -a Test all available types\n");
printf("Supported types: ");
const TypeDumpFunctionMap::const_iterator cend = tdm.constEnd();
for (TypeDumpFunctionMap::const_iterator it = tdm.constBegin(); it != cend; ++it) {
fputs(qPrintable(it.key()), stdout);
fputc(' ', stdout);
}
fputc('\n', stdout);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
printf("\nQt Creator Debugging Helper testing tool\n\n"); printf("\nQt Creator Debugging Helper testing tool\n\n");
@@ -515,30 +581,57 @@ int main(int argc, char *argv[])
const TypeDumpFunctionMap::const_iterator cend = tdm.constEnd(); const TypeDumpFunctionMap::const_iterator cend = tdm.constEnd();
if (argc < 2) { if (argc < 2) {
printf("Usage: %s [-a]|<type1> <type2..>\n", argv[0]); usage(argv[0], tdm);
printf("Supported types: ");
for (TypeDumpFunctionMap::const_iterator it = tdm.constBegin(); it != cend; ++it) {
fputs(qPrintable(it.key()), stdout);
fputc(' ', stdout);
}
fputc('\n', stdout);
return 0; return 0;
} }
// Parse args
QStringList tests;
for (int a = 1; a < argc; a++) {
const char *arg = argv[a];
if (arg[0] == '-') {
switch (arg[1]) {
case 'a':
optTestAll = true;
break;
case 'u':
optTestUninitialized = true;
break;
case 'v':
optVerbose++;
break;
case 'e':
optEmptyContainers = true;
break;
default:
fprintf(stderr, "Invalid option %s\n", arg);
usage(argv[0], tdm);
return -1;
}
} else {
tests.push_back(QLatin1String(arg));
}
}
// Go
int rc = 0; int rc = 0;
if (argc == 2 && !qstrcmp(argv[1], "-a")) { if (optTestAll) {
for (TypeDumpFunctionMap::const_iterator it = tdm.constBegin(); it != cend; ++it) { for (TypeDumpFunctionMap::const_iterator it = tdm.constBegin(); it != cend; ++it) {
printf("\nTesting: %s\n", qPrintable(it.key())); const QString test = it.key();
rc += (*it.value())(); if (tests.contains(test)) {
printf("\nSkipping: %s\n", qPrintable(test));
} else {
printf("\nTesting: %s\n", qPrintable(test));
rc += (*it.value())();
if (optTestUninitialized)
printf("Survived: %s\n", qPrintable(test));
}
} }
} else { } else {
for (int i = 1; i < argc; i++) { foreach(const QString &test, tests) {
const char *arg = argv[i]; printf("\nTesting: %s\n", qPrintable(test));
printf("\nTesting: %s\n", arg); const TypeDumpFunctionMap::const_iterator it = tdm.constFind(test);
const TypeDumpFunctionMap::const_iterator it = tdm.constFind(QLatin1String(arg));
if (it == cend) { if (it == cend) {
rc = -1; rc = -1;
fprintf(stderr, "\nUnhandled type: %s\n", argv[i]); fprintf(stderr, "\nUnhandled type: %s\n", qPrintable(test));
} else { } else {
rc = (*it.value())(); rc = (*it.value())();
} }

View File

@@ -563,8 +563,14 @@ CdbDumperHelper::CallResult
if (!writeToDebuggee(m_cif->debugDataSpaces, inBuffer, m_inBufferAddress, errorMessage)) if (!writeToDebuggee(m_cif->debugDataSpaces, inBuffer, m_inBufferAddress, errorMessage))
return CallFailed; return CallFailed;
} }
if (!CdbDebugEnginePrivate::executeDebuggerCommand(m_cif->debugControl, callCmd, errorMessage)) if (!CdbDebugEnginePrivate::executeDebuggerCommand(m_cif->debugControl, callCmd, errorMessage)) {
// Clear the outstanding call in case we triggered a debug library assert with a message box
QString clearError;
if (!CdbDebugEnginePrivate::executeDebuggerCommand(m_cif->debugControl, QLatin1String(".call /c"), &clearError)) {
*errorMessage += QString::fromLatin1("/Unable to clear call %1").arg(clearError);
}
return CallSyntaxError; return CallSyntaxError;
}
// Set up call and a temporary breakpoint after it. // Set up call and a temporary breakpoint after it.
// Try to skip debuggee crash exceptions and dumper exceptions // Try to skip debuggee crash exceptions and dumper exceptions
// by using 'gN' (go not handled -> pass handling to dumper __try/__catch block) // by using 'gN' (go not handled -> pass handling to dumper __try/__catch block)