From fb7f576ede1f65077b38df214c60095ef082499d Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 17 May 2011 11:30:44 +0200 Subject: [PATCH] debuggger: allow change of display for templated types --- share/qtcreator/gdbmacros/gdbmacros.py | 16 +++++----- src/plugins/debugger/gdb/gdbengine.cpp | 2 +- src/plugins/debugger/watchhandler.cpp | 32 ++++++++++++------- src/plugins/debugger/watchwindow.cpp | 24 +++++++++++--- .../gdbdebugger/simple/simple_gdbtest_app.cpp | 10 +++--- 5 files changed, 55 insertions(+), 29 deletions(-) diff --git a/share/qtcreator/gdbmacros/gdbmacros.py b/share/qtcreator/gdbmacros/gdbmacros.py index 298fdd31e3b..90706e119e1 100644 --- a/share/qtcreator/gdbmacros/gdbmacros.py +++ b/share/qtcreator/gdbmacros/gdbmacros.py @@ -2301,6 +2301,9 @@ def qdump__QScriptValue(d, item): # ####################################################################### +#def qform__Eigen__Matrix(): +# return "Transposed" + def qdump__Eigen__Matrix(d, item): innerType = templateArgument(item.value.type, 0) storage = item.value["m_storage"] @@ -2318,18 +2321,15 @@ def qdump__Eigen__Matrix(d, item): d.putField("keeporder", "1") d.putNumChild(nrows * ncols) - limit = 100 + limit = 10000 nncols = min(ncols, limit) nnrows = min(nrows, limit * limit / nncols) if d.isExpanded(item): + #format = d.itemFormat(item) # format == 1 is "Transposed" iname = item.iname with Children(d, nrows * ncols, innerType): - if ncols == 1: - for i in range(0, nnrows): - v = (p + i).dereference() - d.putSubItem(Item(v, item.iname)) - elif nrows == 1: - for i in range(0, nncols): + if ncols == 1 or nrows == 1: + for i in range(0, min(nrows * ncols, 10000)): v = (p + i).dereference() d.putSubItem(Item(v, item.iname)) elif rowMajor == 1: @@ -2342,7 +2342,7 @@ def qdump__Eigen__Matrix(d, item): for j in range(0, nncols): for i in range(0, nnrows): name = "[%d,%d]" % (i, j) - v = (p + i * ncols + j).dereference() + v = (p + i + j * nrows).dereference() d.putSubItem(Item(v, item.iname, None, name)) diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index b889f1b6a5b..a8807690131 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -3913,7 +3913,7 @@ void GdbEngine::insertData(const WatchData &data0) void GdbEngine::assignValueInDebugger(const WatchData *data, const QString &expression, const QVariant &value) { - if (hasPython()) { + if (hasPython() && !isIntOrFloatType(data->type)) { QByteArray cmd = "bbedit " + data->type.toHex() + ',' + expression.toUtf8().toHex() + ',' diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 21fbfdb84d8..8f863cf4672 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -81,6 +81,12 @@ QHash WatchHandler::m_watcherNames; QHash WatchHandler::m_typeFormats; int WatchHandler::m_unprintableBase = 0; +static QByteArray stripTemplate(const QByteArray &ba) +{ + int pos = ba.indexOf('<'); + return pos == -1 ? ba : ba.left(pos); +} + //////////////////////////////////////////////////////////////////// // // WatchItem @@ -577,7 +583,7 @@ int WatchModel::itemFormat(const WatchData &data) const const int individualFormat = m_handler->m_individualFormats.value(data.iname, -1); if (individualFormat != -1) return individualFormat; - return m_handler->m_typeFormats.value(data.type, -1); + return m_handler->m_typeFormats.value(stripTemplate(data.type), -1); } static inline QString expression(const WatchItem *item) @@ -717,13 +723,14 @@ QVariant WatchModel::data(const QModelIndex &idx, int role) const << tr("binary") << tr("octal"); // Hack: Compensate for namespaces. - QString type = data.type; + QString type = stripTemplate(data.type); int pos = type.indexOf("::Q"); if (pos >= 0 && type.count(':') == 2) type = type.mid(pos + 2); pos = type.indexOf('<'); if (pos >= 0) type = type.left(pos); + type.replace(':', '_'); return m_handler->m_reportedTypeFormats.value(type); } case LocalsTypeRole: @@ -731,7 +738,7 @@ QVariant WatchModel::data(const QModelIndex &idx, int role) const case LocalsRawTypeRole: return QString::fromLatin1(data.type); case LocalsTypeFormatRole: - return m_handler->m_typeFormats.value(data.type, -1); + return m_handler->m_typeFormats.value(stripTemplate(data.type), -1); case LocalsIndividualFormatRole: return m_handler->m_individualFormats.value(data.iname, -1); @@ -875,7 +882,8 @@ QVariant WatchModel::headerData(int section, Qt::Orientation orientation, int ro // Set this before using any of the below according to action static bool sortWatchDataAlphabetically = true; -static bool watchDataLessThan(const QByteArray &iname1, int sortId1, const QByteArray &iname2, int sortId2) +static bool watchDataLessThan(const QByteArray &iname1, int sortId1, + const QByteArray &iname2, int sortId2) { if (!sortWatchDataAlphabetically) return sortId1 < sortId2; @@ -902,9 +910,10 @@ static bool watchDataLessThan(const QByteArray &iname1, int sortId1, const QByte } // Sort key for watch data consisting of iname and numerical sort id. -struct WatchDataSortKey { - explicit WatchDataSortKey(const WatchData &wd) : - iname(wd.iname), sortId(wd.sortId) {} +struct WatchDataSortKey +{ + explicit WatchDataSortKey(const WatchData &wd) + : iname(wd.iname), sortId(wd.sortId) {} QByteArray iname; int sortId; }; @@ -1117,7 +1126,7 @@ void WatchModel::formatRequests(QByteArray *out, const WatchItem *item) const { int format = m_handler->m_individualFormats.value(item->iname, -1); if (format == -1) - format = m_handler->m_typeFormats.value(item->type, -1); + format = m_handler->m_typeFormats.value(stripTemplate(item->type), -1); if (format != -1) *out += item->iname + ":format=" + QByteArray::number(format) + ','; foreach (const WatchItem *child, item->children) @@ -1574,8 +1583,9 @@ QModelIndex WatchHandler::itemIndex(const QByteArray &iname) const return QModelIndex(); } -void WatchHandler::setFormat(const QByteArray &type, int format) +void WatchHandler::setFormat(const QByteArray &type0, int format) { + const QByteArray type = stripTemplate(type0); if (format == -1) m_typeFormats.remove(type); else @@ -1593,7 +1603,7 @@ int WatchHandler::format(const QByteArray &iname) const if (const WatchData *item = findItem(iname)) { int result = m_individualFormats.value(item->iname, -1); if (result == -1) - result = m_typeFormats.value(item->type, -1); + result = m_typeFormats.value(stripTemplate(item->type), -1); } return result; } @@ -1651,7 +1661,7 @@ QByteArray WatchHandler::individualFormatRequests() const void WatchHandler::addTypeFormats(const QByteArray &type, const QStringList &formats) { - m_reportedTypeFormats.insert(type, formats); + m_reportedTypeFormats.insert(stripTemplate(type), formats); } QString WatchHandler::editorContents() diff --git a/src/plugins/debugger/watchwindow.cpp b/src/plugins/debugger/watchwindow.cpp index 078e082a011..84adb5ec52a 100644 --- a/src/plugins/debugger/watchwindow.cpp +++ b/src/plugins/debugger/watchwindow.cpp @@ -146,15 +146,29 @@ private: // Watch model query helpers. static inline quint64 addressOf(const QModelIndex &m) - { return m.data(LocalsAddressRole).toULongLong(); } +{ + return m.data(LocalsAddressRole).toULongLong(); +} + static inline quint64 pointerValueOf(const QModelIndex &m) - { return m.data(LocalsPointerValueRole).toULongLong(); } +{ + return m.data(LocalsPointerValueRole).toULongLong(); +} + static inline QString nameOf(const QModelIndex &m) - { return m.data().toString(); } +{ + return m.data().toString(); +} + static inline QString typeOf(const QModelIndex &m) - { return m.data(LocalsTypeRole).toString(); } +{ + return m.data(LocalsTypeRole).toString(); +} + static inline uint sizeOf(const QModelIndex &m) - { return m.data(LocalsSizeRole).toUInt(); } +{ + return m.data(LocalsSizeRole).toUInt(); +} // Create a map of value->name for register markup typedef QMap RegisterMap; diff --git a/tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp b/tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp index 1d253f4eb14..d4cd9c3e03a 100644 --- a/tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp +++ b/tests/manual/gdbdebugger/simple/simple_gdbtest_app.cpp @@ -2590,6 +2590,8 @@ void testEigen() #if USE_EIGEN using namespace Eigen; + Vector3d test = Vector3d::Zero(); + Matrix3d myMatrix = Matrix3d::Constant(5); MatrixXd myDynamicMatrix(30, 10); @@ -2597,11 +2599,11 @@ void testEigen() myDynamicMatrix(1, 0) = 1; myDynamicMatrix(2, 0) = 2; - Matrix rowMajorMatrix1; - rowMajorMatrix1 << 34, 44; + Matrix colMajorMatrix; + colMajorMatrix << 0, 1, 2, 3, 4, 5; - Matrix rowMajorMatrix; - rowMajorMatrix << 0, 1, 2, 3; + Matrix rowMajorMatrix; + rowMajorMatrix << 0, 1, 2, 3, 4, 5; int i = 0; ++i;