diff --git a/bin/gdbmacros/gdbmacros.cpp b/bin/gdbmacros/gdbmacros.cpp index ca19e5870270f147d6b3ea9fc9cb083435fd16b8..a3b3de6a4de92e51bbc0d50788010beefd2460f8 100644 --- a/bin/gdbmacros/gdbmacros.cpp +++ b/bin/gdbmacros/gdbmacros.cpp @@ -2155,6 +2155,14 @@ static void qDumpStdMap(QDumper &d) P(d, "valuedisabled", "true"); P(d, "valueoffset", d.extraInt[2]); + // HACK: we need a properly const qualified version of the + // std::pair used. We extract it from the allocator parameter + // as it is there, and, equally importantly, in an order that + // gdb accepts when fed with it. + char *pairType = (char *)(d.templateParameters[3]) + 16; + pairType[strlen(pairType) - 2] = 0; + P(d, "pairtype", pairType); + if (d.dumpChildren) { bool simpleKey = isSimpleType(keyType); bool simpleValue = isShortKey(valueType); @@ -2177,7 +2185,7 @@ static void qDumpStdMap(QDumper &d) d.beginHash(); P(d, "name", "[" << i << "]"); P(d, "addr", it.operator->()); - P(d, "type", "std::pair"); + P(d, "type", pairType); d.endHash(); } } diff --git a/src/plugins/debugger/gdbengine.cpp b/src/plugins/debugger/gdbengine.cpp index 6e650917ce66a61754561cf6ce5aba80dc207457..e2bbfb3766e879929f842ad336b79cd8f1f0d19f 100644 --- a/src/plugins/debugger/gdbengine.cpp +++ b/src/plugins/debugger/gdbengine.cpp @@ -3022,8 +3022,13 @@ void GdbEngine::runCustomDumper(const WatchData & data0, bool dumpChildren) } 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. - extraArgs[2] = "(size_t)&(('std::pair'*)0)->second"; + // We read the type of the pair from the allocator argument because + // that gets the constness "right" (in the sense that gdb can + // read it back; + QString pairType = inners.at(3); + // remove 'std::allocator<...>': + pairType = pairType.mid(15, pairType.size() - 15 - 2); + extraArgs[2] = "(size_t)&(('" + pairType + "'*)0)->second"; extraArgs[3] = "0"; } else if (outertype == "std::basic_string") { //qDebug() << "EXTRACT TEMPLATE: " << outertype << inners; diff --git a/tests/manual/gdbdebugger/simple/app.cpp b/tests/manual/gdbdebugger/simple/app.cpp index ba36298eb1a129b6ad488f8927d717dc93ef1044..24626064e4f1fb4d66484cdedd5da404df3e5774 100644 --- a/tests/manual/gdbdebugger/simple/app.cpp +++ b/tests/manual/gdbdebugger/simple/app.cpp @@ -416,6 +416,11 @@ void testStdMap() gg3["33.0"] = Foo(33); gg3["44.0"] = Foo(44); + + std::map m1; + m1["22.0"] = Foo(22); + m1["33.0"] = Foo(33); + m1["44.0"] = Foo(44); #if 1 std::map gg; gg[11] = 1;