Commit d3f8d16f authored by hjk's avatar hjk
Browse files

Fixes: debugger: implement custom dumpers for std::set

Task:     246286
parent 99805d3c
......@@ -60,6 +60,7 @@ int qtGhVersion = QT_VERSION;
#include <list>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <ctype.h>
......@@ -2236,6 +2237,49 @@ static void qDumpStdMap(QDumper &d)
d.disarm();
}
static void qDumpStdSet(QDumper &d)
{
typedef std::set<int> DummyType;
const DummyType &set = *reinterpret_cast<const DummyType*>(d.data);
const void *p = d.data;
qCheckAccess(p);
p = deref(p);
int nn = set.size();
qCheck(nn >= 0);
DummyType::const_iterator it = set.begin();
for (int i = 0; i < nn && i < 10 && it != set.end(); ++i, ++it)
qCheckAccess(it.operator->());
P(d, "numchild", nn);
P(d, "value", "<" << nn << " items>");
P(d, "valuedisabled", "true");
P(d, "valueoffset", d.extraInt[0]);
if (d.dumpChildren) {
int valueOffset = 0; // d.extraInt[0];
QByteArray strippedInnerType = stripPointerType(d.innertype);
const char *stripped =
isPointerType(d.innertype) ? strippedInnerType.data() : 0;
P(d, "extra"," valueOffset: " << valueOffset);
d << ",children=[";
it = set.begin();
for (int i = 0; i < 1000 && it != set.end(); ++i, ++it) {
const void *node = it.operator->();
d.beginHash();
P(d, "name", i);
qDumpInnerValueOrPointer(d, d.innertype, stripped, node);
d.endHash();
}
if (it != set.end())
d.putEllipsis();
d << "]";
}
d.disarm();
}
static void qDumpStdString(QDumper &d)
{
const std::string &str = *reinterpret_cast<const std::string *>(d.data);
......@@ -2452,6 +2496,8 @@ static void handleProtocolVersion2and3(QDumper & d)
qDumpStdList(d);
else if (isEqual(type, "std::map"))
qDumpStdMap(d);
else if (isEqual(type, "std::set"))
qDumpStdSet(d);
else if (isEqual(type, "std::string") || isEqual(type, "string"))
qDumpStdString(d);
else if (isEqual(type, "std::wstring"))
......@@ -2527,6 +2573,7 @@ void qDumpObjectData440(
"\"std::basic_string\","
"\"std::list\","
"\"std::map\","
"\"std::set\","
"\"std::string\","
"\"std::vector\","
"\"std::wstring\","
......
......@@ -3195,6 +3195,11 @@ void GdbEngine::runCustomDumper(const WatchData &data0, bool dumpChildren)
} else if (outertype == "std::stack") {
// remove 'std::allocator<...>':
extraArgs[1] = "0";
} else if (outertype == "std::set") {
// remove 'std::less<...>':
extraArgs[1] = "0";
// remove 'std::allocator<...>':
extraArgs[2] = "0";
} else if (outertype == "std::map") {
// We don't want the comparator and the allocator confuse gdb.
// But we need the offset of the second item in the value pair.
......
......@@ -424,6 +424,16 @@ static QString niceType(QString type)
type.replace(re3.cap(0), "std::map<" + re3.cap(1) + ", " + re3.cap(2) + ">");
}
// std::set
static QRegExp re4("std::set<(.*), std::less<(.*)>, std::allocator<(.*)>\\s*>");
re1.setMinimal(true);
for (int i = 0; i != 10; ++i) {
if (re4.indexIn(type) == -1 || re4.cap(1) != re4.cap(2)
|| re4.cap(1) != re4.cap(3))
break;
type.replace(re4.cap(0), "std::set<" + re4.cap(1) + ">");
}
type.replace(" >", ">");
}
return type;
......
......@@ -54,6 +54,7 @@
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <string>
#include <vector>
......@@ -581,6 +582,22 @@ void testStdMap()
#endif
}
void testStdSet()
{
std::set<int> hgg0;
hgg0.insert(11);
hgg0.insert(22);
hgg0.insert(33);
#if 1
std::set<QString> hgg1;
hgg1.insert("22.0");
QObject ob;
std::set<QPointer<QObject> > hash;
QPointer<QObject> ptr(&ob);
#endif
}
void testStdStack()
{
std::stack<int *> plist1;
......@@ -969,6 +986,7 @@ int main(int argc, char *argv[])
testStdDeque();
testStdList();
testStdMap();
testStdSet();
testStdStack();
testStdString();
testStdVector();
......
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