Debugger: Add libc++ std::unordered_set dumper

Change-Id: I0799791b2baffa61092c01699a4128f01151b53c
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
hjk
2014-01-15 11:49:09 +01:00
parent fb0d8661d3
commit 846ee38f2b
3 changed files with 159 additions and 129 deletions

View File

@@ -651,6 +651,19 @@ def qdump__std____1__unordered_map(d, value):
d.putPair(node["__value_"], i) d.putPair(node["__value_"], i)
node = node["__next_"] node = node["__next_"]
def qdump__std____1__unordered_set(d, value):
size = int(value["__table_"]["__p2_"]["__first_"])
d.putItemCount(size)
if d.isExpanded():
node = value["__table_"]["__p1_"]["__first_"]["__next_"]
valueType = d.templateArgument(value.type, 0)
with Children(d, size, childType=valueType, maxNumChild=1000):
for i in d.childRange():
d.putSubItem(i, node["__value_"])
node = node["__next_"]
def qdump__std____debug__unordered_set(d, value): def qdump__std____debug__unordered_set(d, value):
qdump__std__unordered_set(d, value) qdump__std__unordered_set(d, value)

View File

@@ -831,146 +831,158 @@ QString simplifySTLType(const QString &typeIn)
if (ifstreamRE.indexIn(type) != -1) if (ifstreamRE.indexIn(type) != -1)
type.replace(ifstreamRE.cap(0), QLatin1String("std::ifstream")); type.replace(ifstreamRE.cap(0), QLatin1String("std::ifstream"));
// std::__1::hash_node<int, void *>::value_type -> int
if (isLibCpp) {
//QRegExp hashNodeRE(QLatin1String("std::__hash_node<([^<>]*),\\s*void\\s*@>::value_type"));
QRegExp hashNodeRE(QLatin1String("std::__hash_node<([^<>]*),\\s*void\\s*@>::value_type"));
QTC_ASSERT(hashNodeRE.isValid(), return typeIn);
if (hashNodeRE.indexIn(type) != -1)
type.replace(hashNodeRE.cap(0), hashNodeRE.cap(1));
}
// Anything with a std::allocator // Anything with a std::allocator
int start = type.indexOf(QLatin1String("std::allocator<")); int start = type.indexOf(QLatin1String("std::allocator<"));
if (start == -1) if (start != -1) {
break; // search for matching '>'
// search for matching '>'
int pos;
int level = 0;
for (pos = start + 12; pos < type.size(); ++pos) {
int c = type.at(pos).unicode();
if (c == '<') {
++level;
} else if (c == '>') {
--level;
if (level == 0)
break;
}
}
const QString alloc = fixNestedTemplates(type.mid(start, pos + 1 - start).trimmed());
const QString inner = fixNestedTemplates(alloc.mid(15, alloc.size() - 16).trimmed());
const QString allocEsc = QRegExp::escape(alloc);
const QString innerEsc = QRegExp::escape(inner);
if (inner == QLatin1String("char")) { // std::string
simplifyStdString(QLatin1String("char"), QLatin1String("string"), &type);
} else if (inner == QLatin1String("wchar_t")) { // std::wstring
simplifyStdString(QLatin1String("wchar_t"), QLatin1String("wstring"), &type);
} else if (inner == QLatin1String("unsigned short")) { // std::wstring/MSVC
simplifyStdString(QLatin1String("unsigned short"), QLatin1String("wstring"), &type);
}
// std::vector, std::deque, std::list
QRegExp re1(QString::fromLatin1("(vector|list|deque)<%1, ?%2\\s*>").arg(innerEsc, allocEsc));
QTC_ASSERT(re1.isValid(), return typeIn);
if (re1.indexIn(type) != -1)
type.replace(re1.cap(0), QString::fromLatin1("%1<%2>").arg(re1.cap(1), inner));
// std::stack
QRegExp stackRE(QString::fromLatin1("stack<%1, ?std::deque<%2> >").arg(innerEsc, innerEsc));
stackRE.setMinimal(true);
QTC_ASSERT(stackRE.isValid(), return typeIn);
if (stackRE.indexIn(type) != -1)
type.replace(stackRE.cap(0), QString::fromLatin1("stack<%1>").arg(inner));
// std::hash<char>
QRegExp hashCharRE(QString::fromLatin1("hash<char, std::char_traits<char>, ?%1\\s*>").arg(allocEsc));
hashCharRE.setMinimal(true);
QTC_ASSERT(hashCharRE.isValid(), return typeIn);
if (hashCharRE.indexIn(type) != -1)
type.replace(hashCharRE.cap(0), QString::fromLatin1("hash<char>"));
// std::set
QRegExp setRE(QString::fromLatin1("set<%1, ?std::less<%2>, ?%3\\s*>").arg(innerEsc, innerEsc, allocEsc));
setRE.setMinimal(true);
QTC_ASSERT(setRE.isValid(), return typeIn);
if (setRE.indexIn(type) != -1)
type.replace(setRE.cap(0), QString::fromLatin1("set<%1>").arg(inner));
// std::unordered_set
QRegExp unorderedSetRE(QString::fromLatin1("unordered_set<%1, ?std::hash<%2>, ?std::equal_to<%3>, ?%4\\s*>")
.arg(innerEsc, innerEsc, innerEsc, allocEsc));
unorderedSetRE.setMinimal(true);
QTC_ASSERT(unorderedSetRE.isValid(), return typeIn);
if (unorderedSetRE.indexIn(type) != -1)
type.replace(unorderedSetRE.cap(0), QString::fromLatin1("unordered_set<%1>").arg(inner));
// std::map
if (inner.startsWith(QLatin1String("std::pair<"))) {
// search for outermost ',', split key and value
int pos; int pos;
int level = 0; int level = 0;
for (pos = 10; pos < inner.size(); ++pos) { for (pos = start + 12; pos < type.size(); ++pos) {
int c = inner.at(pos).unicode(); int c = type.at(pos).unicode();
if (c == '<') if (c == '<') {
++level; ++level;
else if (c == '>') } else if (c == '>') {
--level; --level;
else if (c == ',' && level == 0) if (level == 0)
break; break;
}
} }
const QString key = chopConst(inner.mid(10, pos - 10)); const QString alloc = fixNestedTemplates(type.mid(start, pos + 1 - start).trimmed());
const QString keyEsc = QRegExp::escape(key); const QString inner = fixNestedTemplates(alloc.mid(15, alloc.size() - 16).trimmed());
// Get value: MSVC: 'pair<a const ,b>', gcc: 'pair<const a, b>'
if (inner.at(++pos) == QLatin1Char(' ')) const QString allocEsc = QRegExp::escape(alloc);
pos++; const QString innerEsc = QRegExp::escape(inner);
const QString value = inner.mid(pos, inner.size() - pos - 1).trimmed(); if (inner == QLatin1String("char")) { // std::string
const QString valueEsc = QRegExp::escape(value); simplifyStdString(QLatin1String("char"), QLatin1String("string"), &type);
QRegExp mapRE1(QString::fromLatin1("map<%1, ?%2, ?std::less<%3 ?>, ?%4\\s*>") } else if (inner == QLatin1String("wchar_t")) { // std::wstring
.arg(keyEsc, valueEsc, keyEsc, allocEsc)); simplifyStdString(QLatin1String("wchar_t"), QLatin1String("wstring"), &type);
mapRE1.setMinimal(true); } else if (inner == QLatin1String("unsigned short")) { // std::wstring/MSVC
QTC_ASSERT(mapRE1.isValid(), return typeIn); simplifyStdString(QLatin1String("unsigned short"), QLatin1String("wstring"), &type);
if (mapRE1.indexIn(type) != -1) { }
type.replace(mapRE1.cap(0), QString::fromLatin1("map<%1, %2>").arg(key, value)); // std::vector, std::deque, std::list
} else { QRegExp re1(QString::fromLatin1("(vector|list|deque)<%1, ?%2\\s*>").arg(innerEsc, allocEsc));
QRegExp mapRE2(QString::fromLatin1("map<const %1, ?%2, ?std::less<const %3>, ?%4\\s*>") QTC_ASSERT(re1.isValid(), return typeIn);
if (re1.indexIn(type) != -1)
type.replace(re1.cap(0), QString::fromLatin1("%1<%2>").arg(re1.cap(1), inner));
// std::stack
QRegExp stackRE(QString::fromLatin1("stack<%1, ?std::deque<%2> >").arg(innerEsc, innerEsc));
stackRE.setMinimal(true);
QTC_ASSERT(stackRE.isValid(), return typeIn);
if (stackRE.indexIn(type) != -1)
type.replace(stackRE.cap(0), QString::fromLatin1("stack<%1>").arg(inner));
// std::hash<char>
QRegExp hashCharRE(QString::fromLatin1("hash<char, std::char_traits<char>, ?%1\\s*>").arg(allocEsc));
hashCharRE.setMinimal(true);
QTC_ASSERT(hashCharRE.isValid(), return typeIn);
if (hashCharRE.indexIn(type) != -1)
type.replace(hashCharRE.cap(0), QString::fromLatin1("hash<char>"));
// std::set
QRegExp setRE(QString::fromLatin1("set<%1, ?std::less<%2>, ?%3\\s*>").arg(innerEsc, innerEsc, allocEsc));
setRE.setMinimal(true);
QTC_ASSERT(setRE.isValid(), return typeIn);
if (setRE.indexIn(type) != -1)
type.replace(setRE.cap(0), QString::fromLatin1("set<%1>").arg(inner));
// std::unordered_set
QRegExp unorderedSetRE(QString::fromLatin1("unordered_set<%1, ?std::hash<%2>, ?std::equal_to<%3>, ?%4\\s*>")
.arg(innerEsc, innerEsc, innerEsc, allocEsc));
unorderedSetRE.setMinimal(true);
QTC_ASSERT(unorderedSetRE.isValid(), return typeIn);
if (unorderedSetRE.indexIn(type) != -1)
type.replace(unorderedSetRE.cap(0), QString::fromLatin1("unordered_set<%1>").arg(inner));
// std::map
if (inner.startsWith(QLatin1String("std::pair<"))) {
// search for outermost ',', split key and value
int pos;
int level = 0;
for (pos = 10; pos < inner.size(); ++pos) {
int c = inner.at(pos).unicode();
if (c == '<')
++level;
else if (c == '>')
--level;
else if (c == ',' && level == 0)
break;
}
const QString key = chopConst(inner.mid(10, pos - 10));
const QString keyEsc = QRegExp::escape(key);
// Get value: MSVC: 'pair<a const ,b>', gcc: 'pair<const a, b>'
if (inner.at(++pos) == QLatin1Char(' '))
pos++;
const QString value = inner.mid(pos, inner.size() - pos - 1).trimmed();
const QString valueEsc = QRegExp::escape(value);
QRegExp mapRE1(QString::fromLatin1("map<%1, ?%2, ?std::less<%3 ?>, ?%4\\s*>")
.arg(keyEsc, valueEsc, keyEsc, allocEsc)); .arg(keyEsc, valueEsc, keyEsc, allocEsc));
mapRE2.setMinimal(true); mapRE1.setMinimal(true);
if (mapRE2.indexIn(type) != -1) QTC_ASSERT(mapRE1.isValid(), return typeIn);
type.replace(mapRE2.cap(0), QString::fromLatin1("map<const %1, %2>").arg(key, value)); if (mapRE1.indexIn(type) != -1) {
type.replace(mapRE1.cap(0), QString::fromLatin1("map<%1, %2>").arg(key, value));
} else {
QRegExp mapRE2(QString::fromLatin1("map<const %1, ?%2, ?std::less<const %3>, ?%4\\s*>")
.arg(keyEsc, valueEsc, keyEsc, allocEsc));
mapRE2.setMinimal(true);
if (mapRE2.indexIn(type) != -1)
type.replace(mapRE2.cap(0), QString::fromLatin1("map<const %1, %2>").arg(key, value));
}
} }
}
// std::unordered_map // std::unordered_map
if (inner.startsWith(QLatin1String("std::pair<"))) { if (inner.startsWith(QLatin1String("std::pair<"))) {
// search for outermost ',', split key and value // search for outermost ',', split key and value
int pos; int pos;
int level = 0; int level = 0;
for (pos = 10; pos < inner.size(); ++pos) { for (pos = 10; pos < inner.size(); ++pos) {
int c = inner.at(pos).unicode(); int c = inner.at(pos).unicode();
if (c == '<') if (c == '<')
++level; ++level;
else if (c == '>') else if (c == '>')
--level; --level;
else if (c == ',' && level == 0) else if (c == ',' && level == 0)
break; break;
} }
const QString key = chopConst(inner.mid(10, pos - 10)); const QString key = chopConst(inner.mid(10, pos - 10));
const QString keyEsc = QRegExp::escape(key); const QString keyEsc = QRegExp::escape(key);
// Get value: MSVC: 'pair<a const ,b>', gcc: 'pair<const a, b>' // Get value: MSVC: 'pair<a const ,b>', gcc: 'pair<const a, b>'
if (inner.at(++pos) == QLatin1Char(' ')) if (inner.at(++pos) == QLatin1Char(' '))
pos++; pos++;
const QString value = inner.mid(pos, inner.size() - pos - 1).trimmed(); const QString value = inner.mid(pos, inner.size() - pos - 1).trimmed();
const QString valueEsc = QRegExp::escape(value); const QString valueEsc = QRegExp::escape(value);
QRegExp mapRE1(QString::fromLatin1("unordered_map<%1, ?%2, ?std::hash<%3 ?>, ?std::equal_to<%4 ?>, ?%5\\s*>") QRegExp mapRE1(QString::fromLatin1("unordered_map<%1, ?%2, ?std::hash<%3 ?>, ?std::equal_to<%4 ?>, ?%5\\s*>")
.arg(keyEsc, valueEsc, keyEsc, keyEsc, allocEsc)); .arg(keyEsc, valueEsc, keyEsc, keyEsc, allocEsc));
mapRE1.setMinimal(true); mapRE1.setMinimal(true);
QTC_ASSERT(mapRE1.isValid(), return typeIn); QTC_ASSERT(mapRE1.isValid(), return typeIn);
if (mapRE1.indexIn(type) != -1) if (mapRE1.indexIn(type) != -1)
type.replace(mapRE1.cap(0), QString::fromLatin1("unordered_map<%1, %2>").arg(key, value)); type.replace(mapRE1.cap(0), QString::fromLatin1("unordered_map<%1, %2>").arg(key, value));
if (isLibCpp) { if (isLibCpp) {
QRegExp mapRE2(QString::fromLatin1("unordered_map<std::string, ?%1, ?std::hash<char>, ?std::equal_to<std::string>, ?%2\\s*>") QRegExp mapRE2(QString::fromLatin1("unordered_map<std::string, ?%1, "
.arg(valueEsc, allocEsc)); "?std::hash<char>, ?std::equal_to<std::string>, ?%2\\s*>")
mapRE2.setMinimal(true); .arg(valueEsc, allocEsc));
QTC_ASSERT(mapRE2.isValid(), return typeIn); mapRE2.setMinimal(true);
if (mapRE2.indexIn(type) != -1) QTC_ASSERT(mapRE2.isValid(), return typeIn);
type.replace(mapRE2.cap(0), QString::fromLatin1("unordered_map<std::string, %2>").arg(value)); if (mapRE2.indexIn(type) != -1)
type.replace(mapRE2.cap(0), QString::fromLatin1("unordered_map<std::string, %2>").arg(value));
}
} }
} } // with std::allocator
} }
type.replace(QLatin1Char('@'), QLatin1Char('*')); type.replace(QLatin1Char('@'), QLatin1Char('*'));
type.replace(QLatin1String(" >"), QLatin1String(">")); type.replace(QLatin1String(" >"), QLatin1String(">"));
qDebug() << "TYPE: " << type;
return type; return type;
} }
} // namespace Internal } // namespace Internal

View File

@@ -50,6 +50,7 @@ const char *description[] =
"libc++_stringvector", "libc++_stringvector",
"libc++_unordered_map", "libc++_unordered_map",
"libc++_hash_node",
"msvc_stdstring", "msvc_stdstring",
"msvc_stdwstring", "msvc_stdwstring",
@@ -81,8 +82,11 @@ const char *input[] =
// libc++ // libc++
"std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >", "std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >",
"std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, std::__1::hash<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float> > >", "std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float, std::__1::hash<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, float> > >",
"std::__1::__hash_node<int, void *>::value_type",
// MSVC // MSVC
"class std::basic_string<char,std::char_traits<char>,std::allocator<char> >", "class std::basic_string<char,std::char_traits<char>,std::allocator<char> >",
"class std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >", "class std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >",
@@ -114,6 +118,7 @@ const char *output[] =
// libc++ // libc++
"std::vector<std::string>", "std::vector<std::string>",
"std::unordered_map<std::string, float>", "std::unordered_map<std::string, float>",
"int",
// MSVC // MSVC
"std::string", "std::string",
"std::wstring", "std::wstring",
@@ -137,15 +142,15 @@ public:
SimplifyTypesTest(); SimplifyTypesTest();
private Q_SLOTS: private Q_SLOTS:
void testCase1(); void test();
void testCase1_data(); void test_data();
}; };
SimplifyTypesTest::SimplifyTypesTest() SimplifyTypesTest::SimplifyTypesTest()
{ {
} }
void SimplifyTypesTest::testCase1() void SimplifyTypesTest::test()
{ {
QFETCH(QString, input); QFETCH(QString, input);
QFETCH(QString, expected); QFETCH(QString, expected);
@@ -153,7 +158,7 @@ void SimplifyTypesTest::testCase1()
QCOMPARE(output, expected); QCOMPARE(output, expected);
} }
void SimplifyTypesTest::testCase1_data() void SimplifyTypesTest::test_data()
{ {
QTest::addColumn<QString>("input"); QTest::addColumn<QString>("input");
QTest::addColumn<QString>("expected"); QTest::addColumn<QString>("expected");