2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "watchhandler.h"
|
2010-06-16 11:08:54 +02:00
|
|
|
|
|
|
|
|
#include "breakhandler.h"
|
2009-03-19 09:32:09 +01:00
|
|
|
#include "debuggeractions.h"
|
2010-11-10 11:39:01 +01:00
|
|
|
#include "debuggercore.h"
|
2011-11-07 20:07:14 +01:00
|
|
|
#include "debuggerdialogs.h"
|
2013-01-24 11:19:15 +01:00
|
|
|
#include "debuggerengine.h"
|
|
|
|
|
#include "debuggerinternalconstants.h"
|
|
|
|
|
#include "debuggerprotocol.h"
|
2015-09-14 12:53:35 +02:00
|
|
|
#include "debuggertooltipmanager.h"
|
2013-01-08 16:20:26 +01:00
|
|
|
#include "imageviewer.h"
|
2016-07-18 12:36:31 +02:00
|
|
|
#include "memoryagent.h"
|
|
|
|
|
#include "registerhandler.h"
|
|
|
|
|
#include "simplifytype.h"
|
|
|
|
|
#include "watchdelegatewidgets.h"
|
2013-01-24 11:19:15 +01:00
|
|
|
#include "watchutils.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-12-02 08:56:33 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
|
|
|
|
#include <coreplugin/messagebox.h>
|
|
|
|
|
|
|
|
|
|
#include <texteditor/syntaxhighlighter.h>
|
2014-12-02 08:56:33 +01:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2014-07-03 11:01:53 +02:00
|
|
|
#include <utils/basetreeview.h>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <utils/checkablemessagebox.h>
|
|
|
|
|
#include <utils/fancylineedit.h>
|
2008-12-09 16:18:28 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <utils/savedaction.h>
|
2015-03-19 20:44:18 +01:00
|
|
|
#include <utils/theme/theme.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QClipboard>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2014-01-08 14:10:56 +01:00
|
|
|
#include <QFile>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <QItemDelegate>
|
2015-12-16 17:17:38 +01:00
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonObject>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QMimeData>
|
2015-04-01 17:19:43 +02:00
|
|
|
#include <QPainter>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QProcess>
|
2013-06-07 17:57:25 +02:00
|
|
|
#include <QTabWidget>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTextEdit>
|
2016-09-21 18:52:49 +02:00
|
|
|
#include <QTableWidget>
|
2015-03-16 13:36:35 +01:00
|
|
|
#include <QTimer>
|
2016-07-18 12:36:31 +02:00
|
|
|
#include <QVBoxLayout>
|
2016-11-22 14:55:47 +01:00
|
|
|
#include <QToolTip>
|
2015-12-16 17:17:38 +01:00
|
|
|
|
2015-04-01 17:19:43 +02:00
|
|
|
#include <algorithm>
|
2014-08-28 17:33:47 +02:00
|
|
|
#include <cstring>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <ctype.h>
|
2009-04-02 11:41:36 +02:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
using namespace Core;
|
2015-01-29 09:58:23 +01:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2009-06-17 16:00:03 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-01-25 10:59:45 +01:00
|
|
|
// Creates debug output for accesses to the model.
|
|
|
|
|
enum { debugModel = 0 };
|
|
|
|
|
|
|
|
|
|
#define MODEL_DEBUG(s) do { if (debugModel) qDebug() << s; } while (0)
|
2012-05-18 02:28:41 +02:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static QHash<QString, int> theWatcherNames;
|
2015-03-16 09:10:36 +01:00
|
|
|
static int theWatcherCount = 0;
|
2016-06-07 17:04:53 +02:00
|
|
|
static QHash<QString, int> theTypeFormats;
|
|
|
|
|
static QHash<QString, int> theIndividualFormats;
|
2012-03-14 12:26:27 +01:00
|
|
|
static int theUnprintableBase = -1;
|
|
|
|
|
|
2014-05-17 21:00:22 +02:00
|
|
|
const char INameProperty[] = "INameProperty";
|
|
|
|
|
const char KeyProperty[] = "KeyProperty";
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
static QVariant createItemDelegate();
|
|
|
|
|
|
|
|
|
|
typedef QList<MemoryMarkup> MemoryMarkupList;
|
|
|
|
|
|
|
|
|
|
// Helper functionality to indicate the area of a member variable in
|
|
|
|
|
// a vector representing the memory area by a unique color
|
|
|
|
|
// number and tooltip. Parts of it will be overwritten when recursing
|
|
|
|
|
// over the children.
|
|
|
|
|
|
|
|
|
|
typedef QPair<int, QString> ColorNumberToolTip;
|
|
|
|
|
typedef QVector<ColorNumberToolTip> ColorNumberToolTips;
|
|
|
|
|
|
2016-04-05 13:27:24 +02:00
|
|
|
struct TypeInfo
|
|
|
|
|
{
|
|
|
|
|
TypeInfo(uint s = 0) : size(s) {}
|
|
|
|
|
uint size;
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
static const WatchModel *watchModel(const WatchItem *item)
|
|
|
|
|
{
|
|
|
|
|
return reinterpret_cast<const WatchModel *>(item->model());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
void readNumericVectorHelper(std::vector<double> *v, const QByteArray &ba)
|
|
|
|
|
{
|
|
|
|
|
const T *p = (const T *) ba.data();
|
|
|
|
|
const int n = ba.size() / sizeof(T);
|
|
|
|
|
v->resize(n);
|
|
|
|
|
// Losing precision in case of 64 bit ints is ok here, as the result
|
|
|
|
|
// is only used to plot data.
|
|
|
|
|
for (int i = 0; i != n; ++i)
|
|
|
|
|
(*v)[i] = static_cast<double>(p[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void readNumericVector(std::vector<double> *v, const QByteArray &rawData, DebuggerEncoding encoding)
|
|
|
|
|
{
|
|
|
|
|
switch (encoding.type) {
|
|
|
|
|
case DebuggerEncoding::HexEncodedSignedInteger:
|
|
|
|
|
switch (encoding.size) {
|
|
|
|
|
case 1:
|
|
|
|
|
readNumericVectorHelper<signed char>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
case 2:
|
|
|
|
|
readNumericVectorHelper<short>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
case 4:
|
|
|
|
|
readNumericVectorHelper<int>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
case 8:
|
|
|
|
|
readNumericVectorHelper<qint64>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case DebuggerEncoding::HexEncodedUnsignedInteger:
|
|
|
|
|
switch (encoding.size) {
|
|
|
|
|
case 1:
|
|
|
|
|
readNumericVectorHelper<char>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
case 2:
|
|
|
|
|
readNumericVectorHelper<unsigned short>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
case 4:
|
|
|
|
|
readNumericVectorHelper<unsigned int>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
case 8:
|
|
|
|
|
readNumericVectorHelper<quint64>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case DebuggerEncoding::HexEncodedFloat:
|
|
|
|
|
switch (encoding.size) {
|
|
|
|
|
case 4:
|
|
|
|
|
readNumericVectorHelper<float>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
case 8:
|
|
|
|
|
readNumericVectorHelper<double>(v, rawData);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
qDebug() << "ENCODING ERROR: " << encoding.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static QString stripForFormat(const QString &ba)
|
2011-11-30 11:09:10 +01:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
QString res;
|
2011-11-30 11:09:10 +01:00
|
|
|
res.reserve(ba.size());
|
|
|
|
|
int inArray = 0;
|
|
|
|
|
for (int i = 0; i != ba.size(); ++i) {
|
2016-06-07 17:04:53 +02:00
|
|
|
const QChar c = ba.at(i);
|
2011-11-30 11:09:10 +01:00
|
|
|
if (c == '<')
|
|
|
|
|
break;
|
|
|
|
|
if (c == '[')
|
|
|
|
|
++inArray;
|
|
|
|
|
if (c == ']')
|
|
|
|
|
--inArray;
|
|
|
|
|
if (c == ' ')
|
|
|
|
|
continue;
|
2012-07-19 23:35:41 +02:00
|
|
|
if (c == '&') // Treat references like the referenced type.
|
|
|
|
|
continue;
|
2011-11-30 11:09:10 +01:00
|
|
|
if (inArray && c >= '0' && c <= '9')
|
|
|
|
|
continue;
|
|
|
|
|
res.append(c);
|
|
|
|
|
}
|
|
|
|
|
return res;
|
2011-05-17 11:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-20 13:18:36 +01:00
|
|
|
static void saveWatchers()
|
|
|
|
|
{
|
|
|
|
|
setSessionValue("Watchers", WatchHandler::watchedExpressions());
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-01 17:19:43 +02:00
|
|
|
static void loadFormats()
|
|
|
|
|
{
|
|
|
|
|
QVariant value = sessionValue("DefaultFormats");
|
|
|
|
|
QMapIterator<QString, QVariant> it(value.toMap());
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
if (!it.key().isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
theTypeFormats.insert(it.key(), it.value().toInt());
|
2015-04-01 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value = sessionValue("IndividualFormats");
|
|
|
|
|
it = QMapIterator<QString, QVariant>(value.toMap());
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
if (!it.key().isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
theIndividualFormats.insert(it.key(), it.value().toInt());
|
2015-04-01 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void saveFormats()
|
|
|
|
|
{
|
|
|
|
|
QMap<QString, QVariant> formats;
|
2016-06-07 17:04:53 +02:00
|
|
|
QHashIterator<QString, int> it(theTypeFormats);
|
2015-04-01 17:19:43 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
const int format = it.value();
|
|
|
|
|
if (format != AutomaticFormat) {
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString key = it.key().trimmed();
|
2015-04-01 17:19:43 +02:00
|
|
|
if (!key.isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
formats.insert(key, format);
|
2015-04-01 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setSessionValue("DefaultFormats", formats);
|
|
|
|
|
|
|
|
|
|
formats.clear();
|
2016-06-07 17:04:53 +02:00
|
|
|
it = QHashIterator<QString, int>(theIndividualFormats);
|
2015-04-01 17:19:43 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
const int format = it.value();
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString key = it.key().trimmed();
|
2015-04-01 17:19:43 +02:00
|
|
|
if (!key.isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
formats.insert(key, format);
|
2015-04-01 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
setSessionValue("IndividualFormats", formats);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 09:11:07 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
2009-06-17 16:00:03 +02:00
|
|
|
//
|
2014-11-07 13:50:09 +01:00
|
|
|
// SeparatedView
|
2009-06-17 16:00:03 +02:00
|
|
|
//
|
2009-07-13 09:11:07 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
2009-06-17 16:00:03 +02:00
|
|
|
|
2014-05-17 21:00:22 +02:00
|
|
|
class SeparatedView : public QTabWidget
|
2012-12-30 22:35:25 -06:00
|
|
|
{
|
|
|
|
|
public:
|
2014-10-22 13:04:47 +02:00
|
|
|
SeparatedView() : QTabWidget(Internal::mainWindow())
|
2012-12-30 22:35:25 -06:00
|
|
|
{
|
|
|
|
|
setTabsClosable(true);
|
2014-11-07 13:50:09 +01:00
|
|
|
connect(this, &QTabWidget::tabCloseRequested, this, &SeparatedView::closeTab);
|
2012-12-30 22:35:25 -06:00
|
|
|
setWindowFlags(windowFlags() | Qt::Window);
|
|
|
|
|
setWindowTitle(WatchHandler::tr("Debugger - Qt Creator"));
|
2014-05-17 21:00:22 +02:00
|
|
|
|
2014-07-28 14:23:52 +02:00
|
|
|
QVariant geometry = sessionValue("DebuggerSeparateWidgetGeometry");
|
2015-04-01 17:19:43 +02:00
|
|
|
if (geometry.isValid()) {
|
|
|
|
|
QRect rc = geometry.toRect();
|
2016-09-21 18:52:49 +02:00
|
|
|
if (rc.width() < 400)
|
|
|
|
|
rc.setWidth(400);
|
|
|
|
|
if (rc.height() < 400)
|
|
|
|
|
rc.setHeight(400);
|
2015-04-01 17:19:43 +02:00
|
|
|
setGeometry(rc);
|
|
|
|
|
}
|
2014-05-17 21:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-01 17:19:43 +02:00
|
|
|
void saveGeometry()
|
2014-05-17 21:00:22 +02:00
|
|
|
{
|
2014-07-28 14:23:52 +02:00
|
|
|
setSessionValue("DebuggerSeparateWidgetGeometry", geometry());
|
2012-12-30 22:35:25 -06:00
|
|
|
}
|
|
|
|
|
|
2015-04-01 17:19:43 +02:00
|
|
|
~SeparatedView()
|
|
|
|
|
{
|
|
|
|
|
saveGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void removeObject(const QString &key)
|
2012-12-30 22:35:25 -06:00
|
|
|
{
|
2015-04-01 17:19:43 +02:00
|
|
|
saveGeometry();
|
2014-05-17 21:00:22 +02:00
|
|
|
if (QWidget *w = findWidget(key)) {
|
|
|
|
|
removeTab(indexOf(w));
|
|
|
|
|
sanitize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-07 13:50:09 +01:00
|
|
|
void closeTab(int index)
|
2014-05-17 21:00:22 +02:00
|
|
|
{
|
2015-04-01 17:19:43 +02:00
|
|
|
saveGeometry();
|
2014-05-17 21:00:22 +02:00
|
|
|
if (QObject *o = widget(index)) {
|
2016-06-07 17:04:53 +02:00
|
|
|
QString iname = o->property(INameProperty).toString();
|
2014-05-17 21:00:22 +02:00
|
|
|
theIndividualFormats.remove(iname);
|
2015-04-01 17:19:43 +02:00
|
|
|
saveFormats();
|
2014-05-17 21:00:22 +02:00
|
|
|
}
|
2012-12-30 22:35:25 -06:00
|
|
|
removeTab(index);
|
2014-05-17 21:00:22 +02:00
|
|
|
sanitize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sanitize()
|
|
|
|
|
{
|
|
|
|
|
if (count() == 0)
|
|
|
|
|
hide();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QWidget *findWidget(const QString &needle)
|
2014-05-17 21:00:22 +02:00
|
|
|
{
|
|
|
|
|
for (int i = count(); --i >= 0; ) {
|
|
|
|
|
QWidget *w = widget(i);
|
2016-06-07 17:04:53 +02:00
|
|
|
QString key = w->property(KeyProperty).toString();
|
2014-05-17 21:00:22 +02:00
|
|
|
if (key == needle)
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 00:49:22 +02:00
|
|
|
template <class T> T *prepareObject(const WatchItem *item)
|
2014-05-17 21:00:22 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString key = item->key();
|
2014-05-17 21:00:22 +02:00
|
|
|
T *t = 0;
|
|
|
|
|
if (QWidget *w = findWidget(key)) {
|
|
|
|
|
t = qobject_cast<T *>(w);
|
|
|
|
|
if (!t)
|
|
|
|
|
removeTab(indexOf(w));
|
|
|
|
|
}
|
|
|
|
|
if (!t) {
|
|
|
|
|
t = new T;
|
|
|
|
|
t->setProperty(KeyProperty, key);
|
2016-04-08 00:49:22 +02:00
|
|
|
addTab(t, item->name);
|
2014-05-17 21:00:22 +02:00
|
|
|
}
|
2016-04-08 00:49:22 +02:00
|
|
|
setProperty(INameProperty, item->iname);
|
2014-05-17 21:00:22 +02:00
|
|
|
|
|
|
|
|
setCurrentWidget(t);
|
|
|
|
|
show();
|
|
|
|
|
raise();
|
|
|
|
|
return t;
|
2012-12-30 22:35:25 -06:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-22 14:55:47 +01:00
|
|
|
class TextEdit : public QTextEdit
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
bool event(QEvent *ev) override
|
|
|
|
|
{
|
|
|
|
|
if (ev->type() == QEvent::ToolTip) {
|
|
|
|
|
auto hev = static_cast<QHelpEvent *>(ev);
|
|
|
|
|
QTextCursor cursor = cursorForPosition(hev->pos());
|
|
|
|
|
int nextPos = cursor.position();
|
|
|
|
|
if (document() && nextPos + 1 < document()->characterCount())
|
|
|
|
|
++nextPos;
|
|
|
|
|
cursor.setPosition(nextPos, QTextCursor::KeepAnchor);
|
|
|
|
|
QString msg = QString("Position: %1 Character: %2")
|
|
|
|
|
.arg(cursor.anchor()).arg(cursor.selectedText());
|
|
|
|
|
QToolTip::showText(hev->globalPos(), msg, this);
|
|
|
|
|
}
|
|
|
|
|
return QTextEdit::event(ev);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-17 21:00:22 +02:00
|
|
|
|
2014-11-07 13:50:09 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// WatchModel
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2009-06-17 16:00:03 +02:00
|
|
|
|
2014-11-07 13:50:09 +01:00
|
|
|
class WatchModel : public WatchModelBase
|
|
|
|
|
{
|
2015-03-23 12:41:06 +03:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Debugger::Internal::WatchModel)
|
2012-05-18 02:28:41 +02:00
|
|
|
public:
|
2015-03-20 13:18:36 +01:00
|
|
|
WatchModel(WatchHandler *handler, DebuggerEngine *engine);
|
2012-05-18 02:28:41 +02:00
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
static QString nameForFormat(int format);
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
QVariant data(const QModelIndex &idx, int role) const override;
|
|
|
|
|
bool setData(const QModelIndex &idx, const QVariant &value, int role) override;
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &idx) const override;
|
|
|
|
|
bool hasChildren(const QModelIndex &idx) const override;
|
|
|
|
|
bool canFetchMore(const QModelIndex &idx) const override;
|
|
|
|
|
void fetchMore(const QModelIndex &idx) override;
|
2012-05-18 02:28:41 +02:00
|
|
|
|
|
|
|
|
QString displayForAutoTest(const QByteArray &iname) const;
|
2012-10-09 16:13:29 +02:00
|
|
|
void reinitialize(bool includeInspectData = false);
|
2012-05-18 02:28:41 +02:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
WatchItem *findItem(const QString &iname) const;
|
2015-12-16 17:17:38 +01:00
|
|
|
|
2015-03-19 12:42:53 +01:00
|
|
|
void reexpandItems();
|
2012-05-18 02:28:41 +02:00
|
|
|
|
2015-04-01 17:19:43 +02:00
|
|
|
void showEditValue(const WatchItem *item);
|
2016-06-07 17:04:53 +02:00
|
|
|
void setTypeFormat(const QString &type, int format);
|
|
|
|
|
void setIndividualFormat(const QString &iname, int format);
|
2012-05-18 02:28:41 +02:00
|
|
|
|
|
|
|
|
QString removeNamespaces(QString str) const;
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
bool contextMenuEvent(const ItemViewEvent &ev);
|
|
|
|
|
QMenu *createFormatMenu(WatchItem *item);
|
|
|
|
|
QMenu *createMemoryMenu(WatchItem *item);
|
|
|
|
|
QMenu *createBreakpointMenu(WatchItem *item);
|
|
|
|
|
|
|
|
|
|
void addStackLayoutMemoryView(bool separateView, const QPoint &p);
|
|
|
|
|
|
|
|
|
|
void addVariableMemoryView(bool separateView, WatchItem *item, bool atPointerAddress,
|
|
|
|
|
const QPoint &pos);
|
|
|
|
|
MemoryMarkupList variableMemoryMarkup(WatchItem *item, const QString &rootName,
|
|
|
|
|
const QString &rootToolTip, quint64 address, quint64 size,
|
2016-08-03 22:19:34 +02:00
|
|
|
const RegisterMap ®isterMap, bool sizeIsEstimate);
|
2016-07-18 12:36:31 +02:00
|
|
|
int memberVariableRecursion(WatchItem *item, const QString &name, quint64 start,
|
|
|
|
|
quint64 end, int *colorNumberIn, ColorNumberToolTips *cnmv);
|
|
|
|
|
|
|
|
|
|
QString editorContents(const QModelIndexList &list = QModelIndexList());
|
|
|
|
|
void clearWatches();
|
|
|
|
|
void removeWatchItem(WatchItem *item);
|
|
|
|
|
void watchExpression(const QString &exp);
|
|
|
|
|
void watchExpression(const QString &exp, const QString &name);
|
|
|
|
|
void inputNewExpression();
|
|
|
|
|
|
2015-03-19 12:42:53 +01:00
|
|
|
public:
|
2012-05-18 02:28:41 +02:00
|
|
|
WatchHandler *m_handler; // Not owned.
|
2015-03-20 13:18:36 +01:00
|
|
|
DebuggerEngine *m_engine; // Not owned.
|
|
|
|
|
|
|
|
|
|
bool m_contentsValid;
|
2012-05-18 02:28:41 +02:00
|
|
|
|
|
|
|
|
WatchItem *m_localsRoot; // Not owned.
|
|
|
|
|
WatchItem *m_inspectorRoot; // Not owned.
|
|
|
|
|
WatchItem *m_watchRoot; // Not owned.
|
|
|
|
|
WatchItem *m_returnRoot; // Not owned.
|
|
|
|
|
WatchItem *m_tooltipRoot; // Not owned.
|
|
|
|
|
|
2015-03-20 11:45:08 +01:00
|
|
|
SeparatedView *m_separatedView; // Not owned.
|
2015-03-19 12:42:53 +01:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QSet<QString> m_expandedINames;
|
2015-03-17 13:26:20 +01:00
|
|
|
QTimer m_requestUpdateTimer;
|
2016-07-18 12:36:31 +02:00
|
|
|
bool m_grabbing = false;
|
2012-05-18 02:28:41 +02:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QHash<QString, TypeInfo> m_reportedTypeInfo;
|
2015-03-20 16:03:59 +01:00
|
|
|
QHash<QString, DisplayFormats> m_reportedTypeFormats; // Type name -> Dumper Formats
|
2016-06-07 17:04:53 +02:00
|
|
|
QHash<QString, QString> m_valueCache;
|
2012-05-18 02:28:41 +02:00
|
|
|
};
|
|
|
|
|
|
2015-03-20 13:18:36 +01:00
|
|
|
WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine)
|
|
|
|
|
: m_handler(handler), m_engine(engine), m_separatedView(new SeparatedView)
|
2012-05-18 02:28:41 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
setObjectName("WatchModel");
|
2015-01-29 09:58:23 +01:00
|
|
|
|
2016-08-02 12:31:34 +02:00
|
|
|
m_contentsValid = true;
|
2015-03-20 13:18:36 +01:00
|
|
|
|
2016-05-27 11:12:03 +02:00
|
|
|
setHeader({ tr("Name"), tr("Value"), tr("Type") });
|
2015-12-16 17:17:38 +01:00
|
|
|
m_localsRoot = new WatchItem;
|
|
|
|
|
m_localsRoot->iname = "local";
|
|
|
|
|
m_localsRoot->name = tr("Locals");
|
|
|
|
|
m_inspectorRoot = new WatchItem;
|
|
|
|
|
m_inspectorRoot->iname = "inspect";
|
|
|
|
|
m_inspectorRoot->name = tr("Inspector");
|
|
|
|
|
m_watchRoot = new WatchItem;
|
|
|
|
|
m_watchRoot->iname = "watch";
|
|
|
|
|
m_watchRoot->name = tr("Expressions");
|
|
|
|
|
m_returnRoot = new WatchItem;
|
|
|
|
|
m_returnRoot->iname = "return";
|
|
|
|
|
m_returnRoot->name = tr("Return Value");
|
|
|
|
|
m_tooltipRoot = new WatchItem;
|
|
|
|
|
m_tooltipRoot->iname = "tooltip";
|
|
|
|
|
m_tooltipRoot->name = tr("Tooltip");
|
2016-05-31 08:19:39 +02:00
|
|
|
auto root = new WatchItem;
|
2015-12-16 17:17:38 +01:00
|
|
|
root->appendChild(m_localsRoot);
|
|
|
|
|
root->appendChild(m_inspectorRoot);
|
|
|
|
|
root->appendChild(m_watchRoot);
|
|
|
|
|
root->appendChild(m_returnRoot);
|
|
|
|
|
root->appendChild(m_tooltipRoot);
|
2016-05-31 08:19:39 +02:00
|
|
|
setRootItem(root);
|
2012-05-18 02:28:41 +02:00
|
|
|
|
2015-03-17 13:26:20 +01:00
|
|
|
m_requestUpdateTimer.setSingleShot(true);
|
|
|
|
|
connect(&m_requestUpdateTimer, &QTimer::timeout,
|
|
|
|
|
this, &WatchModel::updateStarted);
|
|
|
|
|
|
2015-02-03 23:58:49 +02:00
|
|
|
connect(action(SortStructMembers), &SavedAction::valueChanged,
|
2015-07-16 13:29:05 +02:00
|
|
|
m_engine, &DebuggerEngine::updateLocals);
|
2015-02-03 23:58:49 +02:00
|
|
|
connect(action(ShowStdNamespace), &SavedAction::valueChanged,
|
2015-05-29 09:38:53 +02:00
|
|
|
m_engine, &DebuggerEngine::updateAll);
|
2015-02-03 23:58:49 +02:00
|
|
|
connect(action(ShowQtNamespace), &SavedAction::valueChanged,
|
2015-05-29 09:38:53 +02:00
|
|
|
m_engine, &DebuggerEngine::updateAll);
|
2015-12-16 14:13:44 +01:00
|
|
|
connect(action(ShowQObjectNames), &SavedAction::valueChanged,
|
|
|
|
|
m_engine, &DebuggerEngine::updateAll);
|
2009-06-17 16:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 16:13:29 +02:00
|
|
|
void WatchModel::reinitialize(bool includeInspectData)
|
2009-08-31 09:14:04 +02:00
|
|
|
{
|
2015-01-29 09:58:23 +01:00
|
|
|
m_localsRoot->removeChildren();
|
|
|
|
|
m_watchRoot->removeChildren();
|
|
|
|
|
m_returnRoot->removeChildren();
|
|
|
|
|
m_tooltipRoot->removeChildren();
|
|
|
|
|
if (includeInspectData)
|
|
|
|
|
m_inspectorRoot->removeChildren();
|
2009-08-31 09:14:04 +02:00
|
|
|
}
|
2010-06-23 15:13:51 +02:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
WatchItem *WatchModel::findItem(const QString &iname) const
|
2009-08-31 09:14:04 +02:00
|
|
|
{
|
2016-05-27 11:12:03 +02:00
|
|
|
return findNonRooItem([iname](WatchItem *item) { return item->iname == iname; });
|
2012-05-18 02:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static QString parentName(const QString &iname)
|
2009-07-10 14:36:28 +02:00
|
|
|
{
|
2012-05-18 02:28:41 +02:00
|
|
|
const int pos = iname.lastIndexOf('.');
|
2016-06-07 17:04:53 +02:00
|
|
|
return pos == -1 ? QString() : iname.left(pos);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static QString niceTypeHelper(const QString &typeIn)
|
2009-07-03 13:56:27 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
typedef QMap<QString, QString> Cache;
|
2010-09-24 10:35:22 +02:00
|
|
|
static Cache cache;
|
|
|
|
|
const Cache::const_iterator it = cache.constFind(typeIn);
|
2009-08-31 09:14:04 +02:00
|
|
|
if (it != cache.constEnd())
|
2009-07-03 13:56:27 +02:00
|
|
|
return it.value();
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString simplified = simplifyType(typeIn);
|
2010-11-25 13:51:54 +01:00
|
|
|
cache.insert(typeIn, simplified); // For simplicity, also cache unmodified types
|
|
|
|
|
return simplified;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-19 15:47:34 +02:00
|
|
|
QString WatchModel::removeNamespaces(QString str) const
|
2009-11-25 08:35:02 +01:00
|
|
|
{
|
2014-07-28 14:23:52 +02:00
|
|
|
if (!boolSetting(ShowStdNamespace))
|
2016-06-07 17:04:53 +02:00
|
|
|
str.remove("std::");
|
2014-07-28 14:23:52 +02:00
|
|
|
if (!boolSetting(ShowQtNamespace)) {
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString qtNamespace = m_engine->qtNamespace();
|
2010-09-24 10:35:22 +02:00
|
|
|
if (!qtNamespace.isEmpty())
|
2011-01-17 15:23:22 +01:00
|
|
|
str.remove(qtNamespace);
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-22 18:02:29 +01:00
|
|
|
static int formatToIntegerBase(int format)
|
2010-09-22 17:30:22 +02:00
|
|
|
{
|
|
|
|
|
switch (format) {
|
2014-04-15 18:13:03 +02:00
|
|
|
case HexadecimalIntegerFormat:
|
2011-02-22 18:02:29 +01:00
|
|
|
return 16;
|
2014-04-15 18:13:03 +02:00
|
|
|
case BinaryIntegerFormat:
|
2011-02-22 18:02:29 +01:00
|
|
|
return 2;
|
2014-04-15 18:13:03 +02:00
|
|
|
case OctalIntegerFormat:
|
2011-02-22 18:02:29 +01:00
|
|
|
return 8;
|
2010-09-22 17:30:22 +02:00
|
|
|
}
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-25 16:32:44 +01:00
|
|
|
template <class IntType> QString reformatInteger(IntType value, int format)
|
|
|
|
|
{
|
|
|
|
|
switch (format) {
|
2014-04-15 18:13:03 +02:00
|
|
|
case HexadecimalIntegerFormat:
|
2016-06-07 17:04:53 +02:00
|
|
|
return "(hex) " + QString::number(value, 16);
|
2014-04-15 18:13:03 +02:00
|
|
|
case BinaryIntegerFormat:
|
2016-06-07 17:04:53 +02:00
|
|
|
return "(bin) " + QString::number(value, 2);
|
2014-04-15 18:13:03 +02:00
|
|
|
case OctalIntegerFormat:
|
2016-06-07 17:04:53 +02:00
|
|
|
return "(oct) " + QString::number(value, 8);
|
2009-11-25 16:32:44 +01:00
|
|
|
}
|
2014-02-14 00:38:45 +01:00
|
|
|
return QString::number(value, 10); // not reached
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString reformatInteger(quint64 value, int format, int size, bool isSigned)
|
|
|
|
|
{
|
|
|
|
|
// Follow convention and don't show negative non-decimal numbers.
|
2014-05-22 17:41:01 +02:00
|
|
|
if (format != AutomaticFormat && format != DecimalIntegerFormat)
|
2014-02-14 00:38:45 +01:00
|
|
|
isSigned = false;
|
|
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
|
case 1:
|
|
|
|
|
value = value & 0xff;
|
|
|
|
|
return isSigned
|
|
|
|
|
? reformatInteger<qint8>(value, format)
|
|
|
|
|
: reformatInteger<quint8>(value, format);
|
|
|
|
|
case 2:
|
|
|
|
|
value = value & 0xffff;
|
|
|
|
|
return isSigned
|
|
|
|
|
? reformatInteger<qint16>(value, format)
|
|
|
|
|
: reformatInteger<quint16>(value, format);
|
|
|
|
|
case 4:
|
|
|
|
|
value = value & 0xffffffff;
|
|
|
|
|
return isSigned
|
|
|
|
|
? reformatInteger<qint32>(value, format)
|
|
|
|
|
: reformatInteger<quint32>(value, format);
|
|
|
|
|
default:
|
|
|
|
|
case 8: return isSigned
|
|
|
|
|
? reformatInteger<qint64>(value, format)
|
|
|
|
|
: reformatInteger<quint64>(value, format);
|
|
|
|
|
}
|
2009-11-25 16:32:44 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-09 16:39:36 +02:00
|
|
|
// Format printable (char-type) characters
|
2016-01-04 18:25:51 +01:00
|
|
|
static QString reformatCharacter(int code, int size, bool isSigned)
|
2010-04-09 16:39:36 +02:00
|
|
|
{
|
2013-10-13 22:29:22 +02:00
|
|
|
const QChar c = QChar(uint(code));
|
2016-01-04 18:25:51 +01:00
|
|
|
QString out;
|
2012-03-13 10:38:44 +01:00
|
|
|
if (c.isPrint())
|
2016-06-07 17:04:53 +02:00
|
|
|
out = QString("'") + c + "' ";
|
2016-01-04 18:25:51 +01:00
|
|
|
else if (code == 0)
|
2016-06-07 17:04:53 +02:00
|
|
|
out = "'\\0'";
|
2016-01-04 18:25:51 +01:00
|
|
|
else if (code == '\r')
|
2016-06-07 17:04:53 +02:00
|
|
|
out = "'\\r'";
|
2016-01-04 18:25:51 +01:00
|
|
|
else if (code == '\n')
|
2016-06-07 17:04:53 +02:00
|
|
|
out = "'\\n'";
|
2016-01-04 18:25:51 +01:00
|
|
|
else if (code == '\t')
|
2016-06-07 17:04:53 +02:00
|
|
|
out = "'\\t'";
|
2016-01-04 18:25:51 +01:00
|
|
|
else
|
2016-06-07 17:04:53 +02:00
|
|
|
out = " ";
|
2016-01-04 18:25:51 +01:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
out += '\t';
|
2016-01-04 18:25:51 +01:00
|
|
|
|
|
|
|
|
if (isSigned) {
|
|
|
|
|
out += QString::number(code);
|
|
|
|
|
if (code < 0)
|
2016-07-18 12:36:31 +02:00
|
|
|
out += QString("/%1 ").arg((1 << (8*size)) + code).left(2 + 2 * size);
|
2016-01-04 18:25:51 +01:00
|
|
|
else
|
|
|
|
|
out += QString(2 + 2 * size, QLatin1Char(' '));
|
|
|
|
|
} else {
|
|
|
|
|
out += QString::number(unsigned(code));
|
2010-04-09 16:39:36 +02:00
|
|
|
}
|
2016-01-04 18:25:51 +01:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
out += '\t';
|
2016-01-04 18:25:51 +01:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
out += QString("0x%1").arg(uint(code & ((1ULL << (8*size)) - 1)),
|
|
|
|
|
2 * size, 16, QLatin1Char('0'));
|
2016-01-04 18:25:51 +01:00
|
|
|
return out;
|
2010-04-09 16:39:36 +02:00
|
|
|
}
|
|
|
|
|
|
2011-08-03 14:36:07 +02:00
|
|
|
static QString quoteUnprintable(const QString &str)
|
|
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
if (theUnprintableBase == 0)
|
2011-08-03 14:36:07 +02:00
|
|
|
return str;
|
2011-08-03 17:04:32 +02:00
|
|
|
|
2011-08-03 14:36:07 +02:00
|
|
|
QString encoded;
|
2016-07-18 12:36:31 +02:00
|
|
|
if (theUnprintableBase == -1) {
|
2011-08-03 17:04:32 +02:00
|
|
|
foreach (const QChar c, str) {
|
|
|
|
|
int u = c.unicode();
|
2012-03-13 10:38:44 +01:00
|
|
|
if (c.isPrint())
|
2011-08-03 17:04:32 +02:00
|
|
|
encoded += c;
|
2014-09-29 09:19:25 +03:00
|
|
|
else if (u == '\r')
|
2016-06-07 17:04:53 +02:00
|
|
|
encoded += "\\r";
|
2014-09-29 09:19:25 +03:00
|
|
|
else if (u == '\t')
|
2016-06-07 17:04:53 +02:00
|
|
|
encoded += "\\t";
|
2014-09-29 09:19:25 +03:00
|
|
|
else if (u == '\n')
|
2016-06-07 17:04:53 +02:00
|
|
|
encoded += "\\n";
|
2011-08-03 17:04:32 +02:00
|
|
|
else
|
2016-07-18 12:36:31 +02:00
|
|
|
encoded += QString("\\%1").arg(c.unicode(), 3, 8, QLatin1Char('0'));
|
2011-08-03 17:04:32 +02:00
|
|
|
}
|
|
|
|
|
return encoded;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-03 14:36:07 +02:00
|
|
|
foreach (const QChar c, str) {
|
2016-07-18 12:36:31 +02:00
|
|
|
if (c.isPrint())
|
2011-08-03 14:36:07 +02:00
|
|
|
encoded += c;
|
2016-07-18 12:36:31 +02:00
|
|
|
else if (theUnprintableBase == 8)
|
|
|
|
|
encoded += QString("\\%1").arg(c.unicode(), 3, 8, QLatin1Char('0'));
|
|
|
|
|
else
|
|
|
|
|
encoded += QString("\\u%1").arg(c.unicode(), 4, 16, QLatin1Char('0'));
|
2011-08-03 14:36:07 +02:00
|
|
|
}
|
|
|
|
|
return encoded;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
static int itemFormat(const WatchItem *item)
|
2009-07-03 11:20:47 +02:00
|
|
|
{
|
2015-12-16 17:17:38 +01:00
|
|
|
const int individualFormat = theIndividualFormats.value(item->iname, AutomaticFormat);
|
|
|
|
|
if (individualFormat != AutomaticFormat)
|
|
|
|
|
return individualFormat;
|
|
|
|
|
return theTypeFormats.value(stripForFormat(item->type), AutomaticFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString formattedValue(const WatchItem *item)
|
|
|
|
|
{
|
|
|
|
|
if (item->type == "bool") {
|
2016-06-07 17:04:53 +02:00
|
|
|
if (item->value == "0")
|
2012-02-08 14:42:28 +01:00
|
|
|
return QLatin1String("false");
|
2016-06-07 17:04:53 +02:00
|
|
|
if (item->value == "1")
|
2012-02-08 14:42:28 +01:00
|
|
|
return QLatin1String("true");
|
2015-12-16 17:17:38 +01:00
|
|
|
return item->value;
|
2012-02-08 14:42:28 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
const int format = itemFormat(item);
|
2014-02-14 00:38:45 +01:00
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
// Append quoted, printable character also for decimal.
|
2015-04-01 10:32:28 +02:00
|
|
|
// FIXME: This is unreliable.
|
2016-01-04 18:25:51 +01:00
|
|
|
if (item->type.endsWith("char")) {
|
2014-04-15 18:13:03 +02:00
|
|
|
bool ok;
|
2015-12-16 17:17:38 +01:00
|
|
|
const int code = item->value.toInt(&ok);
|
|
|
|
|
bool isUnsigned = item->type == "unsigned char" || item->type == "uchar";
|
2016-01-04 18:25:51 +01:00
|
|
|
if (ok)
|
|
|
|
|
return reformatCharacter(code, 1, !isUnsigned);
|
|
|
|
|
} else if (item->type.endsWith("wchar_t")) {
|
|
|
|
|
bool ok;
|
|
|
|
|
const int code = item->value.toInt(&ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
return reformatCharacter(code, 4, false);
|
|
|
|
|
} else if (item->type.endsWith("QChar")) {
|
|
|
|
|
bool ok;
|
|
|
|
|
const int code = item->value.toInt(&ok);
|
|
|
|
|
if (ok)
|
|
|
|
|
return reformatCharacter(code, 2, false);
|
2014-04-15 18:13:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (format == HexadecimalIntegerFormat
|
|
|
|
|
|| format == DecimalIntegerFormat
|
|
|
|
|
|| format == OctalIntegerFormat
|
|
|
|
|
|| format == BinaryIntegerFormat) {
|
2016-06-07 17:04:53 +02:00
|
|
|
bool isSigned = item->value.startsWith('-');
|
2015-12-16 17:17:38 +01:00
|
|
|
quint64 raw = isSigned ? quint64(item->value.toLongLong()) : item->value.toULongLong();
|
|
|
|
|
return reformatInteger(raw, format, item->size, isSigned);
|
2009-12-08 16:00:06 +01:00
|
|
|
}
|
2011-05-17 12:58:53 +02:00
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
if (format == ScientificFloatFormat) {
|
2015-12-16 17:17:38 +01:00
|
|
|
double dd = item->value.toDouble();
|
2015-01-29 09:58:23 +01:00
|
|
|
return QString::number(dd, 'e');
|
2014-04-15 18:13:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (format == CompactFloatFormat) {
|
2015-12-16 17:17:38 +01:00
|
|
|
double dd = item->value.toDouble();
|
2015-01-29 09:58:23 +01:00
|
|
|
return QString::number(dd, 'g');
|
2014-04-15 18:13:03 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (item->type == "va_list")
|
|
|
|
|
return item->value;
|
2011-08-04 17:14:22 +02:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (!isPointerType(item->type) && !item->isVTablePointer()) {
|
2011-07-07 11:27:58 +02:00
|
|
|
bool ok = false;
|
2015-12-16 17:17:38 +01:00
|
|
|
qulonglong integer = item->value.toULongLong(&ok, 0);
|
2012-03-13 10:38:44 +01:00
|
|
|
if (ok) {
|
2015-12-16 17:17:38 +01:00
|
|
|
const int format = itemFormat(item);
|
|
|
|
|
return reformatInteger(integer, format, item->size, false);
|
2012-03-13 10:38:44 +01:00
|
|
|
}
|
2011-07-07 11:27:58 +02:00
|
|
|
}
|
2011-05-17 12:58:53 +02:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (item->elided) {
|
|
|
|
|
QString v = item->value;
|
2014-05-16 00:18:17 +02:00
|
|
|
v.chop(1);
|
2016-06-07 17:04:53 +02:00
|
|
|
QString len = item->elided > 0 ? QString::number(item->elided) : "unknown length";
|
|
|
|
|
return quoteUnprintable(v) + "\"... (" + len + ')';
|
2014-05-16 00:18:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
return quoteUnprintable(item->value);
|
2009-07-03 11:20:47 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-23 13:22:08 +02:00
|
|
|
// Get a pointer address from pointer values reported by the debugger.
|
|
|
|
|
// Fix CDB formatting of pointers "0x00000000`000003fd class foo *", or
|
|
|
|
|
// "0x00000000`000003fd "Hallo"", or check gdb formatting of characters.
|
|
|
|
|
static inline quint64 pointerValue(QString data)
|
|
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
const int blankPos = data.indexOf(' ');
|
2010-09-23 13:22:08 +02:00
|
|
|
if (blankPos != -1)
|
|
|
|
|
data.truncate(blankPos);
|
2016-06-07 17:04:53 +02:00
|
|
|
data.remove('`');
|
2011-07-07 15:00:11 +02:00
|
|
|
return data.toULongLong(0, 0);
|
2010-09-23 13:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-22 17:30:22 +02:00
|
|
|
// Return the type used for editing
|
2015-01-29 09:58:23 +01:00
|
|
|
int WatchItem::editType() const
|
2010-09-22 17:30:22 +02:00
|
|
|
{
|
2015-03-19 12:42:53 +01:00
|
|
|
if (type == "bool")
|
2010-09-22 17:30:22 +02:00
|
|
|
return QVariant::Bool;
|
2015-03-19 12:42:53 +01:00
|
|
|
if (isIntType(type))
|
|
|
|
|
return type.contains('u') ? QVariant::ULongLong : QVariant::LongLong;
|
|
|
|
|
if (isFloatType(type))
|
2010-09-22 17:30:22 +02:00
|
|
|
return QVariant::Double;
|
2010-09-23 13:22:08 +02:00
|
|
|
// Check for pointers using hex values (0xAD00 "Hallo")
|
2016-06-07 17:04:53 +02:00
|
|
|
if (isPointerType(type) && value.startsWith("0x"))
|
2010-09-23 13:22:08 +02:00
|
|
|
return QVariant::ULongLong;
|
2010-09-22 17:30:22 +02:00
|
|
|
return QVariant::String;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert to editable (see above)
|
2015-01-29 09:58:23 +01:00
|
|
|
QVariant WatchItem::editValue() const
|
2010-09-22 17:30:22 +02:00
|
|
|
{
|
2015-01-29 09:58:23 +01:00
|
|
|
switch (editType()) {
|
2010-09-22 17:30:22 +02:00
|
|
|
case QVariant::Bool:
|
2016-06-07 17:04:53 +02:00
|
|
|
return value != "0" && value != "false";
|
2010-09-22 17:30:22 +02:00
|
|
|
case QVariant::ULongLong:
|
2015-03-19 12:42:53 +01:00
|
|
|
if (isPointerType(type)) // Fix pointer values (0xAD00 "Hallo" -> 0xAD00)
|
|
|
|
|
return QVariant(pointerValue(value));
|
|
|
|
|
return QVariant(value.toULongLong());
|
2010-09-22 17:30:22 +02:00
|
|
|
case QVariant::LongLong:
|
2015-03-19 12:42:53 +01:00
|
|
|
return QVariant(value.toLongLong());
|
2010-09-22 17:30:22 +02:00
|
|
|
case QVariant::Double:
|
2015-03-19 12:42:53 +01:00
|
|
|
return QVariant(value.toDouble());
|
2010-09-22 17:30:22 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-07-18 15:41:56 +02:00
|
|
|
// Some string value: '0x434 "Hallo"':
|
|
|
|
|
// Remove quotes and replace newlines, which will cause line edit troubles.
|
2015-03-19 12:42:53 +01:00
|
|
|
QString stringValue = value;
|
2016-06-07 17:04:53 +02:00
|
|
|
if (stringValue.endsWith('"')) {
|
|
|
|
|
const int leadingDoubleQuote = stringValue.indexOf('"');
|
2011-07-18 15:41:56 +02:00
|
|
|
if (leadingDoubleQuote != stringValue.size() - 1) {
|
|
|
|
|
stringValue.truncate(stringValue.size() - 1);
|
|
|
|
|
stringValue.remove(0, leadingDoubleQuote + 1);
|
2016-06-07 17:04:53 +02:00
|
|
|
stringValue.replace("\n", "\\n");
|
2011-07-18 15:41:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-07-20 14:23:54 +02:00
|
|
|
return QVariant(quoteUnprintable(stringValue));
|
2010-09-22 17:30:22 +02:00
|
|
|
}
|
|
|
|
|
|
2011-08-19 15:47:34 +02:00
|
|
|
// Truncate value for item view, maintaining quotes.
|
|
|
|
|
static QString truncateValue(QString v)
|
2010-01-13 10:36:37 +01:00
|
|
|
{
|
|
|
|
|
enum { maxLength = 512 };
|
|
|
|
|
if (v.size() < maxLength)
|
|
|
|
|
return v;
|
2016-06-07 17:04:53 +02:00
|
|
|
const bool isQuoted = v.endsWith('"'); // check for 'char* "Hallo"'
|
2010-01-13 10:36:37 +01:00
|
|
|
v.truncate(maxLength);
|
2016-06-07 17:04:53 +02:00
|
|
|
v += QLatin1String(isQuoted ? "...\"" : "...");
|
2010-01-13 10:36:37 +01:00
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
static QString displayName(const WatchItem *item)
|
2011-11-25 18:50:54 +01:00
|
|
|
{
|
|
|
|
|
QString result;
|
2015-12-16 17:17:38 +01:00
|
|
|
|
|
|
|
|
const WatchItem *p = item->parentItem();
|
|
|
|
|
if (!p)
|
|
|
|
|
return result;
|
|
|
|
|
if (item->arrayIndex >= 0) {
|
2016-07-18 12:36:31 +02:00
|
|
|
result = QString("[%1]").arg(item->arrayIndex);
|
2015-01-29 09:58:23 +01:00
|
|
|
return result;
|
2015-12-16 17:17:38 +01:00
|
|
|
}
|
2016-06-07 17:04:53 +02:00
|
|
|
if (item->iname.startsWith("return") && item->name.startsWith('$'))
|
2015-01-29 09:58:23 +01:00
|
|
|
result = WatchModel::tr("returned value");
|
2016-06-07 17:04:53 +02:00
|
|
|
else if (item->name == "*")
|
|
|
|
|
result = '*' + p->name;
|
2013-03-06 10:03:29 +01:00
|
|
|
else
|
2015-12-16 17:17:38 +01:00
|
|
|
result = watchModel(item)->removeNamespaces(item->name);
|
2014-07-03 11:01:53 +02:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
// Simplify names that refer to base classes.
|
2016-06-07 17:04:53 +02:00
|
|
|
if (result.startsWith('[')) {
|
2014-07-03 11:01:53 +02:00
|
|
|
result = simplifyType(result);
|
|
|
|
|
if (result.size() > 30)
|
2016-06-07 17:04:53 +02:00
|
|
|
result = result.left(27) + "...]";
|
2014-07-03 11:01:53 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-06 10:03:29 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
static QString displayValue(const WatchItem *item)
|
2013-03-06 10:03:29 +01:00
|
|
|
{
|
2015-12-16 17:17:38 +01:00
|
|
|
QString result = watchModel(item)->removeNamespaces(truncateValue(formattedValue(item)));
|
|
|
|
|
if (result.isEmpty() && item->address)
|
|
|
|
|
result += QString::fromLatin1("@0x" + QByteArray::number(item->address, 16));
|
2015-03-19 12:42:53 +01:00
|
|
|
// if (origaddr)
|
|
|
|
|
// result += QString::fromLatin1(" (0x" + QByteArray::number(origaddr, 16) + ')');
|
2013-03-06 10:03:29 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
static QString displayType(const WatchItem *item)
|
2013-03-06 10:03:29 +01:00
|
|
|
{
|
2015-12-16 17:17:38 +01:00
|
|
|
QString result = niceTypeHelper(item->type);
|
|
|
|
|
if (item->bitsize)
|
2016-07-18 12:36:31 +02:00
|
|
|
result += QString(":%1").arg(item->bitsize);
|
2016-06-07 17:04:53 +02:00
|
|
|
result.remove('\'');
|
2015-12-16 17:17:38 +01:00
|
|
|
result = watchModel(item)->removeNamespaces(result);
|
2011-11-25 18:50:54 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
static QColor valueColor(const WatchItem *item, int column)
|
2015-04-15 18:48:32 +02:00
|
|
|
{
|
|
|
|
|
Theme::Color color = Theme::Debugger_WatchItem_ValueNormal;
|
2015-12-16 17:17:38 +01:00
|
|
|
if (const WatchModel *model = watchModel(item)) {
|
|
|
|
|
if (!model->m_contentsValid && !item->isInspect()) {
|
2015-04-15 18:48:32 +02:00
|
|
|
color = Theme::Debugger_WatchItem_ValueInvalid;
|
|
|
|
|
} else if (column == 1) {
|
2015-12-16 17:17:38 +01:00
|
|
|
if (!item->valueEnabled)
|
2015-04-15 18:48:32 +02:00
|
|
|
color = Theme::Debugger_WatchItem_ValueInvalid;
|
2015-12-16 17:17:38 +01:00
|
|
|
else if (!model->m_contentsValid && !item->isInspect())
|
2015-04-15 18:48:32 +02:00
|
|
|
color = Theme::Debugger_WatchItem_ValueInvalid;
|
2015-12-16 17:17:38 +01:00
|
|
|
else if (column == 1 && item->value.isEmpty()) // This might still show 0x...
|
2015-04-15 18:48:32 +02:00
|
|
|
color = Theme::Debugger_WatchItem_ValueInvalid;
|
2015-12-16 17:17:38 +01:00
|
|
|
else if (column == 1 && item->value != model->m_valueCache.value(item->iname))
|
2015-04-15 18:48:32 +02:00
|
|
|
color = Theme::Debugger_WatchItem_ValueChanged;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return creatorTheme()->color(color);
|
2015-02-09 09:00:21 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
static DisplayFormats typeFormatList(const WatchItem *item)
|
2009-06-17 16:00:03 +02:00
|
|
|
{
|
2015-12-16 17:17:38 +01:00
|
|
|
DisplayFormats formats;
|
|
|
|
|
|
|
|
|
|
// Types supported by dumpers:
|
|
|
|
|
// Hack: Compensate for namespaces.
|
2016-06-07 17:04:53 +02:00
|
|
|
QString t = stripForFormat(item->type);
|
|
|
|
|
int pos = t.indexOf("::Q");
|
|
|
|
|
if (pos >= 0 && t.count(':') == 2)
|
2015-12-16 17:17:38 +01:00
|
|
|
t.remove(0, pos + 2);
|
2016-06-07 17:04:53 +02:00
|
|
|
pos = t.indexOf('<');
|
2015-12-16 17:17:38 +01:00
|
|
|
if (pos >= 0)
|
|
|
|
|
t.truncate(pos);
|
2016-06-07 17:04:53 +02:00
|
|
|
t.replace(':', '_');
|
2015-12-16 17:17:38 +01:00
|
|
|
formats << watchModel(item)->m_reportedTypeFormats.value(t);
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
if (t.contains(']'))
|
2015-12-16 17:17:38 +01:00
|
|
|
formats.append(ArrayPlotFormat);
|
|
|
|
|
|
|
|
|
|
// Fixed artificial string and pointer types.
|
|
|
|
|
if (item->origaddr || isPointerType(item->type)) {
|
|
|
|
|
formats.append(RawFormat);
|
|
|
|
|
formats.append(Latin1StringFormat);
|
|
|
|
|
formats.append(SeparateLatin1StringFormat);
|
|
|
|
|
formats.append(Utf8StringFormat);
|
|
|
|
|
formats.append(SeparateUtf8StringFormat);
|
|
|
|
|
formats.append(Local8BitStringFormat);
|
|
|
|
|
formats.append(Utf16StringFormat);
|
|
|
|
|
formats.append(Ucs4StringFormat);
|
|
|
|
|
formats.append(Array10Format);
|
|
|
|
|
formats.append(Array100Format);
|
|
|
|
|
formats.append(Array1000Format);
|
|
|
|
|
formats.append(Array10000Format);
|
|
|
|
|
} else if (item->type.contains("char[") || item->type.contains("char [")) {
|
|
|
|
|
formats.append(RawFormat);
|
|
|
|
|
formats.append(Latin1StringFormat);
|
|
|
|
|
formats.append(SeparateLatin1StringFormat);
|
|
|
|
|
formats.append(Utf8StringFormat);
|
|
|
|
|
formats.append(SeparateUtf8StringFormat);
|
|
|
|
|
formats.append(Local8BitStringFormat);
|
|
|
|
|
formats.append(Utf16StringFormat);
|
|
|
|
|
formats.append(Ucs4StringFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fixed artificial floating point types.
|
|
|
|
|
bool ok = false;
|
|
|
|
|
item->value.toDouble(&ok);
|
|
|
|
|
if (ok) {
|
|
|
|
|
formats.append(CompactFloatFormat);
|
|
|
|
|
formats.append(ScientificFloatFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fixed artificial integral types.
|
|
|
|
|
QString v = item->value;
|
2016-06-07 17:04:53 +02:00
|
|
|
if (v.startsWith('-'))
|
2015-12-16 17:17:38 +01:00
|
|
|
v = v.mid(1);
|
|
|
|
|
v.toULongLong(&ok, 10);
|
|
|
|
|
if (!ok)
|
|
|
|
|
v.toULongLong(&ok, 16);
|
|
|
|
|
if (!ok)
|
|
|
|
|
v.toULongLong(&ok, 8);
|
|
|
|
|
if (ok) {
|
|
|
|
|
formats.append(DecimalIntegerFormat);
|
|
|
|
|
formats.append(HexadecimalIntegerFormat);
|
|
|
|
|
formats.append(BinaryIntegerFormat);
|
|
|
|
|
formats.append(OctalIntegerFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return formats;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant WatchModel::data(const QModelIndex &idx, int role) const
|
|
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
if (role == BaseTreeView::ItemDelegateRole)
|
|
|
|
|
return createItemDelegate();
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (role == BaseTreeView::ExtraIndicesForColumnWidth) {
|
|
|
|
|
QModelIndexList l;
|
|
|
|
|
foreach (TreeItem *item, m_watchRoot->children())
|
|
|
|
|
l.append(indexForItem(item));
|
|
|
|
|
foreach (TreeItem *item, m_returnRoot->children())
|
|
|
|
|
l.append(indexForItem(item));
|
|
|
|
|
return QVariant::fromValue(l);
|
|
|
|
|
}
|
2016-07-18 12:36:31 +02:00
|
|
|
|
2016-05-27 11:12:03 +02:00
|
|
|
const WatchItem *item = nonRootItemForIndex(idx);
|
2015-12-16 17:17:38 +01:00
|
|
|
if (!item)
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
|
|
const int column = idx.column();
|
2008-12-02 12:01:29 +01:00
|
|
|
switch (role) {
|
2011-05-10 15:57:33 +02:00
|
|
|
case LocalsNameRole:
|
2015-12-16 17:17:38 +01:00
|
|
|
return item->name;
|
2011-05-10 15:57:33 +02:00
|
|
|
|
2011-02-14 13:42:01 +01:00
|
|
|
case Qt::EditRole: {
|
2015-01-29 09:58:23 +01:00
|
|
|
switch (column) {
|
2011-02-14 13:42:01 +01:00
|
|
|
case 0:
|
2015-12-16 17:17:38 +01:00
|
|
|
return item->expression();
|
2011-02-14 13:42:01 +01:00
|
|
|
case 1:
|
2015-12-16 17:17:38 +01:00
|
|
|
return item->editValue();
|
2011-02-14 13:42:01 +01:00
|
|
|
case 2:
|
2016-06-07 17:04:53 +02:00
|
|
|
return item->type;
|
2011-02-14 13:42:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-06 10:03:29 +01:00
|
|
|
case Qt::DisplayRole: {
|
2015-01-29 09:58:23 +01:00
|
|
|
switch (column) {
|
2013-03-06 10:03:29 +01:00
|
|
|
case 0:
|
2015-12-16 17:17:38 +01:00
|
|
|
return displayName(item);
|
2013-03-06 10:03:29 +01:00
|
|
|
case 1:
|
2015-12-16 17:17:38 +01:00
|
|
|
return displayValue(item);
|
2013-03-06 10:03:29 +01:00
|
|
|
case 2:
|
2015-12-16 17:17:38 +01:00
|
|
|
return displayType(item);
|
2013-03-06 10:03:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-02-14 13:42:01 +01:00
|
|
|
|
2009-05-13 14:39:55 +02:00
|
|
|
case Qt::ToolTipRole:
|
2014-07-28 14:23:52 +02:00
|
|
|
return boolSetting(UseToolTipsInLocalsView)
|
2015-12-16 17:17:38 +01:00
|
|
|
? item->toToolTip() : QVariant();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-02-09 09:00:21 +01:00
|
|
|
case Qt::ForegroundRole:
|
2015-12-16 17:17:38 +01:00
|
|
|
return valueColor(item, column);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
case LocalsINameRole:
|
2015-12-16 17:17:38 +01:00
|
|
|
return item->iname;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
case LocalsExpandedRole:
|
2015-12-16 17:17:38 +01:00
|
|
|
return m_expandedINames.contains(item->iname);
|
2009-06-24 12:31:09 +02:00
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
case LocalsTypeFormatRole:
|
2015-12-16 17:17:38 +01:00
|
|
|
return theTypeFormats.value(stripForFormat(item->type), AutomaticFormat);
|
2009-12-08 16:00:06 +01:00
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
case LocalsIndividualFormatRole:
|
2015-12-16 17:17:38 +01:00
|
|
|
return theIndividualFormats.value(item->iname, AutomaticFormat);
|
2009-12-08 16:00:06 +01:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
2009-07-03 11:20:47 +02:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
bool WatchModel::setData(const QModelIndex &idx, const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
WatchItem *item = itemForIndex(idx);
|
2013-03-06 10:03:29 +01:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
if (role == BaseTreeView::ItemViewEventRole) {
|
|
|
|
|
ItemViewEvent ev = value.value<ItemViewEvent>();
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
if (ev.as<QContextMenuEvent>())
|
|
|
|
|
return contextMenuEvent(ev);
|
|
|
|
|
|
|
|
|
|
if (auto dev = ev.as<QDragEnterEvent>()) {
|
|
|
|
|
if (dev->mimeData()->hasText()) {
|
|
|
|
|
dev->setDropAction(Qt::CopyAction);
|
|
|
|
|
dev->accept();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-03-01 19:16:24 +01:00
|
|
|
}
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
if (auto dev = ev.as<QDragMoveEvent>()) {
|
|
|
|
|
if (dev->mimeData()->hasText()) {
|
|
|
|
|
dev->setDropAction(Qt::CopyAction);
|
|
|
|
|
dev->accept();
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
if (auto dev = ev.as<QDropEvent>()) {
|
|
|
|
|
if (dev->mimeData()->hasText()) {
|
|
|
|
|
QString exp;
|
|
|
|
|
QString data = dev->mimeData()->text();
|
|
|
|
|
foreach (const QChar c, data)
|
|
|
|
|
exp.append(c.isPrint() ? c : QChar(' '));
|
|
|
|
|
m_handler->watchVariable(exp);
|
|
|
|
|
//ev->acceptProposedAction();
|
|
|
|
|
dev->setDropAction(Qt::CopyAction);
|
|
|
|
|
dev->accept();
|
2011-03-01 19:16:24 +01:00
|
|
|
}
|
2016-07-18 12:36:31 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-06-16 11:08:54 +02:00
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
if (ev.as<QMouseEvent>(QEvent::MouseButtonPress)) {
|
|
|
|
|
m_grabbing = false;
|
|
|
|
|
ev.view()->releaseMouse();
|
|
|
|
|
m_engine->watchPoint(ev.globalPos());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ev.as<QMouseEvent>(QEvent::MouseButtonDblClick)) {
|
2016-09-21 14:56:59 +02:00
|
|
|
if (item && !item->parent()) { // if item is the invisible root item
|
2016-07-18 12:36:31 +02:00
|
|
|
inputNewExpression();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (auto kev = ev.as<QKeyEvent>(QEvent::KeyPress)) {
|
|
|
|
|
if (item && kev->key() == Qt::Key_Delete && item->isWatcher()) {
|
|
|
|
|
foreach (const QModelIndex &idx, ev.selectedRows())
|
|
|
|
|
removeWatchItem(itemForIndex(idx));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item && kev->key() == Qt::Key_Return
|
|
|
|
|
&& kev->modifiers() == Qt::ControlModifier
|
|
|
|
|
&& item->isLocal()) {
|
|
|
|
|
watchExpression(item->expression());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:28:41 +02:00
|
|
|
if (!idx.isValid())
|
|
|
|
|
return false; // Triggered by ModelTester.
|
|
|
|
|
|
2015-01-29 09:58:23 +01:00
|
|
|
QTC_ASSERT(item, return false);
|
2010-06-23 15:13:51 +02:00
|
|
|
|
|
|
|
|
switch (role) {
|
2010-09-24 10:35:22 +02:00
|
|
|
case Qt::EditRole:
|
2012-05-18 02:28:41 +02:00
|
|
|
switch (idx.column()) {
|
2015-03-06 11:32:39 +01:00
|
|
|
case 0: {
|
2016-06-07 17:04:53 +02:00
|
|
|
m_handler->updateWatchExpression(item, value.toString().trimmed());
|
2010-09-24 10:35:22 +02:00
|
|
|
break;
|
2015-03-06 11:32:39 +01:00
|
|
|
}
|
2010-09-24 10:35:22 +02:00
|
|
|
case 1: // Change value
|
2015-03-20 13:18:36 +01:00
|
|
|
m_engine->assignValueInDebugger(item, item->expression(), value);
|
2010-09-24 10:35:22 +02:00
|
|
|
break;
|
|
|
|
|
case 2: // TODO: Implement change type.
|
2015-03-20 13:18:36 +01:00
|
|
|
m_engine->assignValueInDebugger(item, item->expression(), value);
|
2010-09-24 10:35:22 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2016-09-20 14:11:25 +02:00
|
|
|
return true;
|
2016-04-13 14:38:33 +02:00
|
|
|
|
2010-06-23 15:13:51 +02:00
|
|
|
case LocalsExpandedRole:
|
|
|
|
|
if (value.toBool()) {
|
|
|
|
|
// Should already have been triggered by fetchMore()
|
2015-03-19 12:42:53 +01:00
|
|
|
//QTC_CHECK(m_expandedINames.contains(item->iname));
|
|
|
|
|
m_expandedINames.insert(item->iname);
|
2010-06-23 15:13:51 +02:00
|
|
|
} else {
|
2015-03-19 12:42:53 +01:00
|
|
|
m_expandedINames.remove(item->iname);
|
2010-06-23 15:13:51 +02:00
|
|
|
}
|
2015-03-26 16:59:51 +01:00
|
|
|
if (item->iname.contains('.'))
|
|
|
|
|
emit columnAdjustmentRequested();
|
2016-09-20 14:11:25 +02:00
|
|
|
return true;
|
2010-06-23 15:13:51 +02:00
|
|
|
|
|
|
|
|
case LocalsTypeFormatRole:
|
2015-04-01 17:19:43 +02:00
|
|
|
setTypeFormat(item->type, value.toInt());
|
2015-07-15 17:14:29 +02:00
|
|
|
m_engine->updateLocals();
|
2016-09-20 14:11:25 +02:00
|
|
|
return true;
|
2010-06-23 15:13:51 +02:00
|
|
|
|
|
|
|
|
case LocalsIndividualFormatRole: {
|
2015-04-01 17:19:43 +02:00
|
|
|
setIndividualFormat(item->iname, value.toInt());
|
2015-07-15 17:14:29 +02:00
|
|
|
m_engine->updateLocals();
|
2016-09-20 14:11:25 +02:00
|
|
|
return true;
|
2009-11-25 16:32:44 +01:00
|
|
|
}
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
case BaseTreeView::ItemActivatedRole:
|
|
|
|
|
m_engine->selectWatchData(item->iname);
|
2016-09-20 14:11:25 +02:00
|
|
|
return true;
|
2009-06-17 16:00:03 +02:00
|
|
|
}
|
2010-09-23 13:22:08 +02:00
|
|
|
|
2016-09-20 14:11:25 +02:00
|
|
|
return false;
|
2009-04-07 13:38:19 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
Qt::ItemFlags WatchModel::flags(const QModelIndex &idx) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-12-16 17:17:38 +01:00
|
|
|
if (!idx.isValid())
|
|
|
|
|
return 0;
|
|
|
|
|
|
2016-05-27 11:12:03 +02:00
|
|
|
const WatchItem *item = nonRootItemForIndex(idx);
|
2015-12-16 17:17:38 +01:00
|
|
|
if (!item)
|
|
|
|
|
return Qt::ItemIsEnabled|Qt::ItemIsSelectable;
|
|
|
|
|
|
|
|
|
|
const int column = idx.column();
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(m_engine, return Qt::ItemFlags());
|
|
|
|
|
const DebuggerState state = m_engine->state();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-02-17 16:31:43 +01:00
|
|
|
// Enabled, editable, selectable, checkable, and can be used both as the
|
2008-12-02 12:01:29 +01:00
|
|
|
// source of a drag and drop operation and as a drop target.
|
|
|
|
|
|
2015-01-29 09:58:23 +01:00
|
|
|
const Qt::ItemFlags notEditable = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
|
const Qt::ItemFlags editable = notEditable | Qt::ItemIsEditable;
|
2016-03-20 12:27:51 +02:00
|
|
|
bool isRunning = true;
|
|
|
|
|
switch (state) {
|
|
|
|
|
case InferiorStopOk:
|
|
|
|
|
case InferiorUnrunnable:
|
|
|
|
|
case DebuggerNotReady:
|
|
|
|
|
case DebuggerFinished:
|
|
|
|
|
isRunning = false;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (item->isWatcher()) {
|
|
|
|
|
if (state == InferiorUnrunnable)
|
|
|
|
|
return (column == 0 && item->iname.count('.') == 1) ? editable : notEditable;
|
2015-08-12 14:30:17 +02:00
|
|
|
|
2016-03-20 12:27:51 +02:00
|
|
|
if (isRunning && !m_engine->hasCapability(AddWatcherWhileRunningCapability))
|
|
|
|
|
return notEditable;
|
2015-12-16 17:17:38 +01:00
|
|
|
if (column == 0 && item->iname.count('.') == 1)
|
2010-09-23 08:19:49 +02:00
|
|
|
return editable; // Watcher names are editable.
|
2015-12-16 17:17:38 +01:00
|
|
|
if (column == 1 && item->arrayIndex >= 0)
|
|
|
|
|
return editable;
|
2010-09-23 08:19:49 +02:00
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
if (!item->name.isEmpty()) {
|
2010-07-22 15:34:35 +02:00
|
|
|
// FIXME: Forcing types is not implemented yet.
|
|
|
|
|
//if (idx.column() == 2)
|
|
|
|
|
// return editable; // Watcher types can be set by force.
|
2015-12-16 17:17:38 +01:00
|
|
|
if (column == 1 && item->valueEditable && !item->elided)
|
2010-07-22 15:34:35 +02:00
|
|
|
return editable; // Watcher values are sometimes editable.
|
|
|
|
|
}
|
2015-12-16 17:17:38 +01:00
|
|
|
} else if (item->isLocal()) {
|
2016-03-20 12:27:51 +02:00
|
|
|
if (state == InferiorUnrunnable)
|
|
|
|
|
return notEditable;
|
|
|
|
|
if (isRunning && !m_engine->hasCapability(AddWatcherWhileRunningCapability))
|
|
|
|
|
return notEditable;
|
2015-12-16 17:17:38 +01:00
|
|
|
if (column == 1 && item->valueEditable && !item->elided)
|
2010-07-22 15:34:35 +02:00
|
|
|
return editable; // Locals values are sometimes editable.
|
2015-12-16 17:17:38 +01:00
|
|
|
if (column == 1 && item->arrayIndex >= 0)
|
|
|
|
|
return editable;
|
|
|
|
|
} else if (item->isInspect()) {
|
|
|
|
|
if (column == 1 && item->valueEditable)
|
2012-05-23 14:55:48 +02:00
|
|
|
return editable; // Inspector values are sometimes editable.
|
2010-07-22 15:34:35 +02:00
|
|
|
}
|
2009-08-31 09:14:04 +02:00
|
|
|
return notEditable;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-16 17:17:38 +01:00
|
|
|
bool WatchModel::canFetchMore(const QModelIndex &idx) const
|
|
|
|
|
{
|
|
|
|
|
if (!idx.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// See "hasChildren" below.
|
2016-05-27 11:12:03 +02:00
|
|
|
const WatchItem *item = nonRootItemForIndex(idx);
|
2015-12-16 17:17:38 +01:00
|
|
|
if (!item)
|
|
|
|
|
return false;
|
|
|
|
|
if (!item->wantsChildren)
|
|
|
|
|
return false;
|
|
|
|
|
if (!m_contentsValid && !item->isInspect())
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchModel::fetchMore(const QModelIndex &idx)
|
|
|
|
|
{
|
|
|
|
|
if (!idx.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2016-05-27 11:12:03 +02:00
|
|
|
WatchItem *item = nonRootItemForIndex(idx);
|
2015-12-16 17:17:38 +01:00
|
|
|
if (item) {
|
|
|
|
|
m_expandedINames.insert(item->iname);
|
2016-08-03 13:13:06 +02:00
|
|
|
if (item->children().isEmpty())
|
2015-12-16 17:17:38 +01:00
|
|
|
m_engine->expandItem(item->iname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WatchModel::hasChildren(const QModelIndex &idx) const
|
|
|
|
|
{
|
2016-05-27 11:12:03 +02:00
|
|
|
const WatchItem *item = nonRootItemForIndex(idx);
|
2015-12-16 17:17:38 +01:00
|
|
|
if (!item)
|
|
|
|
|
return true;
|
2016-07-06 13:38:00 +02:00
|
|
|
if (item->childCount() > 0)
|
2015-12-16 17:17:38 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
// "Can fetch more", see above.
|
|
|
|
|
if (!item->wantsChildren)
|
|
|
|
|
return false;
|
|
|
|
|
if (!m_contentsValid && !item->isInspect())
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
static QString variableToolTip(const QString &name, const QString &type, quint64 offset)
|
|
|
|
|
{
|
|
|
|
|
return offset
|
|
|
|
|
? //: HTML tooltip of a variable in the memory editor
|
|
|
|
|
WatchModel::tr("<i>%1</i> %2 at #%3").arg(type, name).arg(offset)
|
|
|
|
|
: //: HTML tooltip of a variable in the memory editor
|
|
|
|
|
WatchModel::tr("<i>%1</i> %2").arg(type, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WatchModel::memberVariableRecursion(WatchItem *item,
|
|
|
|
|
const QString &name,
|
|
|
|
|
quint64 start, quint64 end,
|
|
|
|
|
int *colorNumberIn,
|
|
|
|
|
ColorNumberToolTips *cnmv)
|
|
|
|
|
{
|
|
|
|
|
int childCount = 0;
|
|
|
|
|
QTC_ASSERT(item, return childCount);
|
|
|
|
|
QModelIndex modelIndex = indexForItem(item);
|
|
|
|
|
const int rows = rowCount(modelIndex);
|
|
|
|
|
if (!rows)
|
|
|
|
|
return childCount;
|
|
|
|
|
const QString nameRoot = name.isEmpty() ? name : name + '.';
|
|
|
|
|
for (int r = 0; r < rows; r++) {
|
|
|
|
|
WatchItem *child = item->childAt(r);
|
|
|
|
|
const quint64 childAddress = item->address;
|
|
|
|
|
if (childAddress && childAddress >= start
|
|
|
|
|
&& (childAddress + item->size) <= end) { // Non-static, within area?
|
|
|
|
|
const QString childName = nameRoot + child->name;
|
|
|
|
|
const quint64 childOffset = childAddress - start;
|
|
|
|
|
const QString toolTip = variableToolTip(childName, item->type, childOffset);
|
|
|
|
|
const ColorNumberToolTip colorNumberNamePair((*colorNumberIn)++, toolTip);
|
|
|
|
|
const ColorNumberToolTips::iterator begin = cnmv->begin() + childOffset;
|
2016-08-03 23:29:58 +03:00
|
|
|
std::fill(begin, begin + item->size, colorNumberNamePair);
|
2016-07-18 12:36:31 +02:00
|
|
|
childCount++;
|
|
|
|
|
childCount += memberVariableRecursion(child, childName, start, end, colorNumberIn, cnmv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return childCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Creates markup for a variable in the memory view.
|
|
|
|
|
|
|
|
|
|
Marks the visible children with alternating colors in the parent, that is, for
|
|
|
|
|
\code
|
|
|
|
|
struct Foo {
|
|
|
|
|
char c1
|
|
|
|
|
char c2
|
|
|
|
|
int x2;
|
|
|
|
|
QPair<int, int> pair
|
|
|
|
|
}
|
|
|
|
|
\endcode
|
|
|
|
|
create something like:
|
|
|
|
|
\code
|
|
|
|
|
0 memberColor1
|
|
|
|
|
1 memberColor2
|
|
|
|
|
2 base color (padding area of parent)
|
|
|
|
|
3 base color
|
|
|
|
|
4 member color1
|
|
|
|
|
...
|
|
|
|
|
8 memberColor2 (pair.first)
|
|
|
|
|
...
|
|
|
|
|
12 memberColor1 (pair.second)
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
In addition, registers pointing into the area are shown as 1 byte-markers.
|
|
|
|
|
|
|
|
|
|
Fixme: When dereferencing a pointer, the size of the pointee is not
|
|
|
|
|
known, currently. So, we take an area of 1024 and fill the background
|
|
|
|
|
with the default color so that just the members are shown
|
|
|
|
|
(sizeIsEstimate=true). This could be fixed by passing the pointee size
|
|
|
|
|
as well from the debugger, but would require expensive type manipulation.
|
|
|
|
|
|
|
|
|
|
\note To recurse over the top level items of the model, pass an invalid model
|
|
|
|
|
index.
|
|
|
|
|
|
|
|
|
|
\sa Debugger::Internal::MemoryViewWidget
|
|
|
|
|
*/
|
|
|
|
|
MemoryMarkupList WatchModel::variableMemoryMarkup(WatchItem *item,
|
|
|
|
|
const QString &rootName,
|
|
|
|
|
const QString &rootToolTip,
|
|
|
|
|
quint64 address, quint64 size,
|
|
|
|
|
const RegisterMap ®isterMap,
|
2016-08-03 22:19:34 +02:00
|
|
|
bool sizeIsEstimate)
|
2016-07-18 12:36:31 +02:00
|
|
|
{
|
|
|
|
|
enum { debug = 0 };
|
|
|
|
|
enum { registerColorNumber = 0x3453 };
|
|
|
|
|
|
|
|
|
|
// Starting out from base, create an array representing the area
|
|
|
|
|
// filled with base color. Fill children with some unique color numbers,
|
|
|
|
|
// leaving the padding areas of the parent colored with the base color.
|
|
|
|
|
MemoryMarkupList result;
|
|
|
|
|
int colorNumber = 0;
|
|
|
|
|
ColorNumberToolTips ranges(size, ColorNumberToolTip(colorNumber, rootToolTip));
|
|
|
|
|
colorNumber++;
|
|
|
|
|
const int childCount = memberVariableRecursion(item,
|
|
|
|
|
rootName, address, address + size,
|
|
|
|
|
&colorNumber, &ranges);
|
|
|
|
|
if (sizeIsEstimate && !childCount)
|
|
|
|
|
return result; // Fixme: Exact size not known, no point in filling if no children.
|
|
|
|
|
// Punch in registers as 1-byte markers on top.
|
|
|
|
|
for (auto it = registerMap.constBegin(), end = registerMap.constEnd(); it != end; ++it) {
|
|
|
|
|
if (it.key() >= address) {
|
|
|
|
|
const quint64 offset = it.key() - address;
|
|
|
|
|
if (offset < size) {
|
|
|
|
|
ranges[offset] = ColorNumberToolTip(registerColorNumber,
|
|
|
|
|
WatchModel::tr("Register <i>%1</i>").arg(it.value()));
|
|
|
|
|
} else {
|
|
|
|
|
break; // Sorted.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // for registers.
|
|
|
|
|
if (debug) {
|
|
|
|
|
QDebug dbg = qDebug().nospace();
|
|
|
|
|
dbg << rootToolTip << ' ' << address << ' ' << size << '\n';
|
|
|
|
|
QString name;
|
|
|
|
|
for (unsigned i = 0; i < size; ++i)
|
|
|
|
|
if (name != ranges.at(i).second) {
|
|
|
|
|
dbg << ",[" << i << ' ' << ranges.at(i).first << ' '
|
|
|
|
|
<< ranges.at(i).second << ']';
|
|
|
|
|
name = ranges.at(i).second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Assign colors from a list, use base color for 0 (contrast to black text).
|
|
|
|
|
// Overwrite the first color (which is usually very bright) by the base color.
|
|
|
|
|
QList<QColor> colors = TextEditor::SyntaxHighlighter::generateColors(colorNumber + 2,
|
|
|
|
|
QColor(Qt::black));
|
2016-08-03 22:19:34 +02:00
|
|
|
QWidget *parent = ICore::dialogParent();
|
|
|
|
|
const QColor defaultBackground = parent->palette().color(QPalette::Normal, QPalette::Base);
|
2016-07-18 12:36:31 +02:00
|
|
|
colors[0] = sizeIsEstimate ? defaultBackground : Qt::lightGray;
|
|
|
|
|
const QColor registerColor = Qt::green;
|
|
|
|
|
int lastColorNumber = 0;
|
|
|
|
|
for (unsigned i = 0; i < size; ++i) {
|
|
|
|
|
const ColorNumberToolTip &range = ranges.at(i);
|
|
|
|
|
if (result.isEmpty() || lastColorNumber != range.first) {
|
|
|
|
|
lastColorNumber = range.first;
|
|
|
|
|
const QColor color = range.first == registerColorNumber ?
|
|
|
|
|
registerColor : colors.at(range.first);
|
|
|
|
|
result.push_back(MemoryMarkup(address + i, 1, color, range.second));
|
|
|
|
|
} else {
|
|
|
|
|
result.back().length++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
|
QDebug dbg = qDebug().nospace();
|
|
|
|
|
dbg << rootName << ' ' << address << ' ' << size << '\n';
|
|
|
|
|
QString name;
|
|
|
|
|
for (unsigned i = 0; i < size; ++i)
|
|
|
|
|
if (name != ranges.at(i).second) {
|
|
|
|
|
dbg << ',' << i << ' ' << ranges.at(i).first << ' '
|
|
|
|
|
<< ranges.at(i).second;
|
|
|
|
|
name = ranges.at(i).second;
|
|
|
|
|
}
|
|
|
|
|
dbg << '\n';
|
|
|
|
|
foreach (const MemoryMarkup &m, result)
|
|
|
|
|
dbg << m.address << ' ' << m.length << ' ' << m.toolTip << '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convenience to create a memory view of a variable.
|
|
|
|
|
void WatchModel::addVariableMemoryView(bool separateView,
|
|
|
|
|
WatchItem *item, bool atPointerAddress, const QPoint &pos)
|
|
|
|
|
{
|
|
|
|
|
MemoryViewSetupData data;
|
|
|
|
|
data.startAddress = atPointerAddress ? item->origaddr : item->address;
|
|
|
|
|
if (!data.startAddress)
|
|
|
|
|
return;
|
|
|
|
|
// Fixme: Get the size of pointee (see variableMemoryMarkup())?
|
|
|
|
|
const QString rootToolTip = variableToolTip(item->name, item->type, 0);
|
|
|
|
|
const bool sizeIsEstimate = atPointerAddress || item->size == 0;
|
|
|
|
|
const quint64 size = sizeIsEstimate ? 1024 : item->size;
|
|
|
|
|
data.markup = variableMemoryMarkup(item, item->name, rootToolTip,
|
|
|
|
|
data.startAddress, size,
|
|
|
|
|
m_engine->registerHandler()->registerMap(),
|
2016-08-03 22:19:34 +02:00
|
|
|
sizeIsEstimate);
|
|
|
|
|
data.separateView = separateView;
|
|
|
|
|
data.readOnly = separateView;
|
2016-07-18 12:36:31 +02:00
|
|
|
QString pat = atPointerAddress
|
|
|
|
|
? tr("Memory at Pointer's Address \"%1\" (0x%2)")
|
|
|
|
|
: tr("Memory at Object's Address \"%1\" (0x%2)");
|
|
|
|
|
data.title = pat.arg(item->name).arg(data.startAddress, 0, 16);
|
|
|
|
|
data.pos = pos;
|
|
|
|
|
m_engine->openMemoryView(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add a memory view of the stack layout showing local variables and registers.
|
|
|
|
|
void WatchModel::addStackLayoutMemoryView(bool separateView, const QPoint &p)
|
|
|
|
|
{
|
|
|
|
|
// Determine suitable address range from locals.
|
|
|
|
|
quint64 start = Q_UINT64_C(0xFFFFFFFFFFFFFFFF);
|
|
|
|
|
quint64 end = 0;
|
|
|
|
|
|
|
|
|
|
// Note: Unsorted 'locals' by default. Exclude 'Automatically dereferenced
|
|
|
|
|
// pointer' items as they are outside the address range.
|
|
|
|
|
rootItem()->childAt(0)->forFirstLevelChildren([&start, &end](WatchItem *item) {
|
|
|
|
|
if (item->origaddr == 0) {
|
|
|
|
|
const quint64 address = item->address;
|
|
|
|
|
if (address) {
|
|
|
|
|
if (address < start)
|
|
|
|
|
start = address;
|
|
|
|
|
const uint size = qMax(1u, item->size);
|
|
|
|
|
if (address + size > end)
|
|
|
|
|
end = address + size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (const quint64 remainder = end % 8)
|
|
|
|
|
end += 8 - remainder;
|
|
|
|
|
// Anything found and everything in a sensible range (static data in-between)?
|
|
|
|
|
if (end <= start || end - start > 100 * 1024) {
|
|
|
|
|
AsynchronousMessageBox::information(
|
|
|
|
|
tr("Cannot Display Stack Layout"),
|
|
|
|
|
tr("Could not determine a suitable address range."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Take a look at the register values. Extend the range a bit if suitable
|
|
|
|
|
// to show stack/stack frame pointers.
|
|
|
|
|
const RegisterMap regMap = m_engine->registerHandler()->registerMap();
|
|
|
|
|
for (auto it = regMap.constBegin(), cend = regMap.constEnd(); it != cend; ++it) {
|
|
|
|
|
const quint64 value = it.key();
|
|
|
|
|
if (value < start && start - value < 512)
|
|
|
|
|
start = value;
|
|
|
|
|
else if (value > end && value - end < 512)
|
|
|
|
|
end = value + 1;
|
|
|
|
|
}
|
|
|
|
|
// Indicate all variables.
|
|
|
|
|
MemoryViewSetupData data;
|
|
|
|
|
data.startAddress = start;
|
|
|
|
|
data.markup = variableMemoryMarkup(rootItem()->childAt(0), QString(),
|
2016-08-03 22:19:34 +02:00
|
|
|
QString(), start, end - start,
|
|
|
|
|
regMap, true);
|
|
|
|
|
data.separateView = separateView;
|
|
|
|
|
data.readOnly = separateView;
|
2016-07-18 12:36:31 +02:00
|
|
|
data.title = tr("Memory Layout of Local Variables at 0x%1").arg(start, 0, 16);
|
|
|
|
|
data.pos = p;
|
|
|
|
|
m_engine->openMemoryView(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Text for add watch action with truncated expression.
|
|
|
|
|
static QString addWatchActionText(QString exp)
|
|
|
|
|
{
|
|
|
|
|
if (exp.isEmpty())
|
|
|
|
|
return WatchModel::tr("Add Expression Evaluator");
|
|
|
|
|
if (exp.size() > 30) {
|
|
|
|
|
exp.truncate(30);
|
|
|
|
|
exp.append("...");
|
|
|
|
|
}
|
|
|
|
|
return WatchModel::tr("Add Expression Evaluator for \"%1\"").arg(exp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Text for add watch action with truncated expression.
|
|
|
|
|
static QString removeWatchActionText(QString exp)
|
|
|
|
|
{
|
|
|
|
|
if (exp.isEmpty())
|
|
|
|
|
return WatchModel::tr("Remove Expression Evaluator");
|
|
|
|
|
if (exp.size() > 30) {
|
|
|
|
|
exp.truncate(30);
|
|
|
|
|
exp.append("...");
|
|
|
|
|
}
|
|
|
|
|
return WatchModel::tr("Remove Expression Evaluator for \"%1\"")
|
|
|
|
|
.arg(exp.replace('&', "&&"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchModel::watchExpression(const QString &exp)
|
|
|
|
|
{
|
|
|
|
|
watchExpression(exp, QString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchModel::watchExpression(const QString &exp, const QString &name)
|
|
|
|
|
{
|
|
|
|
|
currentEngine()->watchHandler()->watchExpression(exp, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void copyToClipboard(const QString &clipboardText)
|
|
|
|
|
{
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
|
clipboard->setText(clipboardText, QClipboard::Selection);
|
|
|
|
|
clipboard->setText(clipboardText, QClipboard::Clipboard);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchModel::inputNewExpression()
|
|
|
|
|
{
|
|
|
|
|
QDialog dlg;
|
|
|
|
|
|
|
|
|
|
auto label = new QLabel(tr("Enter an expression to evaluate."), &dlg);
|
|
|
|
|
|
|
|
|
|
auto hint = new QLabel(QString("<html>%1</html>").arg(
|
|
|
|
|
tr("Note: Evaluators will be re-evaluated after each step. "
|
2016-11-01 15:16:04 +01:00
|
|
|
"For details, see the <a href=\""
|
2016-07-18 12:36:31 +02:00
|
|
|
"qthelp://org.qt-project.qtcreator/doc/creator-debug-mode.html#locals-and-expressions"
|
|
|
|
|
"\">documentation</a>.")), &dlg);
|
|
|
|
|
|
|
|
|
|
auto lineEdit = new FancyLineEdit(&dlg);
|
|
|
|
|
lineEdit->setHistoryCompleter("WatchItems");
|
|
|
|
|
lineEdit->clear(); // Undo "convenient" population with history item.
|
|
|
|
|
|
|
|
|
|
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, &dlg);
|
|
|
|
|
|
|
|
|
|
auto layout = new QVBoxLayout;
|
|
|
|
|
layout->addWidget(label, Qt::AlignLeft);
|
|
|
|
|
layout->addWidget(hint, Qt::AlignLeft);
|
|
|
|
|
layout->addWidget(lineEdit);
|
|
|
|
|
layout->addSpacing(10);
|
|
|
|
|
layout->addWidget(buttons);
|
|
|
|
|
dlg.setLayout(layout);
|
|
|
|
|
|
|
|
|
|
dlg.setWindowTitle(tr("New Evaluated Expression"));
|
|
|
|
|
|
|
|
|
|
connect(buttons, &QDialogButtonBox::accepted, lineEdit, &FancyLineEdit::onEditingFinished);
|
|
|
|
|
connect(buttons, &QDialogButtonBox::accepted, &dlg, &QDialog::accept);
|
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, &dlg, &QDialog::reject);
|
|
|
|
|
connect(hint, &QLabel::linkActivated, [](const QString &link) {
|
|
|
|
|
HelpManager::handleHelpRequest(link); });
|
|
|
|
|
|
|
|
|
|
if (dlg.exec() == QDialog::Accepted) {
|
|
|
|
|
const QString exp = lineEdit->text().trimmed();
|
|
|
|
|
if (!exp.isEmpty())
|
|
|
|
|
m_handler->watchExpression(exp, exp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WatchModel::contextMenuEvent(const ItemViewEvent &ev)
|
|
|
|
|
{
|
|
|
|
|
WatchItem *item = itemForIndex(ev.index());
|
|
|
|
|
|
|
|
|
|
const QString exp = item ? item->expression() : QString();
|
|
|
|
|
const QString name = item ? item->name : QString();
|
|
|
|
|
|
|
|
|
|
const bool canHandleWatches = m_engine->hasCapability(AddWatcherCapability);
|
|
|
|
|
const DebuggerState state = m_engine->state();
|
|
|
|
|
const bool canInsertWatches = state == InferiorStopOk
|
|
|
|
|
|| state == DebuggerNotReady
|
|
|
|
|
|| state == InferiorUnrunnable
|
|
|
|
|
|| (state == InferiorRunOk && m_engine->hasCapability(AddWatcherWhileRunningCapability));
|
|
|
|
|
|
|
|
|
|
bool canRemoveWatches = ((canHandleWatches && canInsertWatches) || state == DebuggerNotReady)
|
|
|
|
|
&& (item && item->isWatcher());
|
|
|
|
|
|
|
|
|
|
auto menu = new QMenu;
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Add New Expression Evaluator..."),
|
|
|
|
|
canHandleWatches && canInsertWatches,
|
2016-09-21 12:48:52 +02:00
|
|
|
[this] { inputNewExpression(); });
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
addAction(menu, addWatchActionText(exp),
|
|
|
|
|
// Suppress for top-level watchers.
|
|
|
|
|
canHandleWatches && !exp.isEmpty() && item && !(item->level() == 2 && item->isWatcher()),
|
|
|
|
|
[this, exp, name] { m_handler->watchExpression(exp, name); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, removeWatchActionText(exp),
|
|
|
|
|
canRemoveWatches && !exp.isEmpty() && item && item->isWatcher(),
|
|
|
|
|
[this, item] { removeWatchItem(item); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Remove All Expression Evaluators"),
|
|
|
|
|
canRemoveWatches && !m_handler->watchedExpressions().isEmpty(),
|
|
|
|
|
[this] { clearWatches(); });
|
|
|
|
|
|
2016-11-23 15:28:35 +01:00
|
|
|
// FIXME:
|
|
|
|
|
// addAction(menu, tr("Select Widget to Add into Expression Evaluator"),
|
|
|
|
|
// canHandleWatches && canInsertWatches && m_engine->hasCapability(WatchWidgetsCapability),
|
|
|
|
|
// [this, ev] { ev.view()->grabMouse(Qt::CrossCursor); m_grabbing = true; });
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
menu->addMenu(createFormatMenu(item));
|
|
|
|
|
menu->addMenu(createMemoryMenu(item));
|
|
|
|
|
menu->addMenu(createBreakpointMenu(item));
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Close Editor Tooltips"),
|
|
|
|
|
DebuggerToolTipManager::hasToolTips(),
|
|
|
|
|
[this] { DebuggerToolTipManager::closeAllToolTips(); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Copy View Contents to Clipboard"),
|
|
|
|
|
true,
|
|
|
|
|
[this] { copyToClipboard(editorContents()); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Copy Current Value to Clipboard"),
|
|
|
|
|
item,
|
|
|
|
|
[this, item] { copyToClipboard(item->value); });
|
|
|
|
|
|
|
|
|
|
// addAction(menu, tr("Copy Selected Rows to Clipboard"),
|
|
|
|
|
// selectionModel()->hasSelection(),
|
|
|
|
|
// [this] { copyToClipboard(editorContents(selectionModel()->selectedRows())); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Open View Contents in Editor"),
|
|
|
|
|
m_engine->debuggerActionsEnabled(),
|
|
|
|
|
[this] { Internal::openTextEditor(tr("Locals & Expressions"), editorContents()); });
|
|
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
|
|
|
|
menu->addAction(action(UseDebuggingHelpers));
|
|
|
|
|
menu->addAction(action(UseToolTipsInLocalsView));
|
|
|
|
|
menu->addAction(action(AutoDerefPointers));
|
|
|
|
|
menu->addAction(action(SortStructMembers));
|
|
|
|
|
menu->addAction(action(UseDynamicType));
|
|
|
|
|
menu->addAction(action(SettingsDialog));
|
|
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
menu->addAction(action(SettingsDialog));
|
|
|
|
|
menu->popup(ev.globalPos());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMenu *WatchModel::createBreakpointMenu(WatchItem *item)
|
|
|
|
|
{
|
|
|
|
|
auto menu = new QMenu(tr("Add Data Breakpoint"));
|
|
|
|
|
if (!item) {
|
|
|
|
|
menu->setEnabled(false);
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *act = nullptr;
|
|
|
|
|
BreakHandler *bh = m_engine->breakHandler();
|
|
|
|
|
|
|
|
|
|
const bool canSetWatchpoint = m_engine->hasCapability(WatchpointByAddressCapability);
|
|
|
|
|
const bool createPointerActions = item->origaddr && item->origaddr != item->address;
|
|
|
|
|
|
|
|
|
|
act = addAction(menu, tr("Add Data Breakpoint at Object's Address (0x%1)").arg(item->address, 0, 16),
|
|
|
|
|
tr("Add Data Breakpoint"),
|
|
|
|
|
canSetWatchpoint && item->address,
|
|
|
|
|
[bh, item] { bh->setWatchpointAtAddress(item->address, item->size); });
|
|
|
|
|
BreakpointParameters bp(WatchpointAtAddress);
|
|
|
|
|
bp.address = item->address;
|
|
|
|
|
act->setChecked(bh->findWatchpoint(bp));
|
2016-11-01 15:16:04 +01:00
|
|
|
act->setToolTip(tr("Stop the program when the data at the address is modified."));
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
act = addAction(menu, tr("Add Data Breakpoint at Pointer's Address (0x%1)").arg(item->origaddr, 0, 16),
|
|
|
|
|
tr("Add Data Breakpoint at Pointer's Address"),
|
|
|
|
|
canSetWatchpoint && item->address && createPointerActions,
|
|
|
|
|
// FIXME: an approximation. This should be target's sizeof(void)
|
|
|
|
|
[bh, item] { bh->setWatchpointAtAddress(item->origaddr, sizeof(void *)); });
|
|
|
|
|
if (isPointerType(item->type)) {
|
|
|
|
|
BreakpointParameters bp(WatchpointAtAddress);
|
|
|
|
|
bp.address = pointerValue(item->value);
|
|
|
|
|
act->setChecked(bh->findWatchpoint(bp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
act = addAction(menu, tr("Add Data Breakpoint at Expression \"%1\"").arg(item->name),
|
|
|
|
|
tr("Add Data Breakpoint at Expression"),
|
|
|
|
|
m_engine->hasCapability(WatchpointByExpressionCapability) && !item->name.isEmpty(),
|
|
|
|
|
[bh, item] { bh->setWatchpointAtExpression(item->name); });
|
2016-11-01 15:16:04 +01:00
|
|
|
act->setToolTip(tr("Stop the program when the data at the address given by the expression "
|
2016-07-18 12:36:31 +02:00
|
|
|
"is modified."));
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMenu *WatchModel::createMemoryMenu(WatchItem *item)
|
|
|
|
|
{
|
|
|
|
|
auto menu = new QMenu(tr("Open Memory Editor"));
|
|
|
|
|
if (!item || !m_engine->hasCapability(ShowMemoryCapability)) {
|
|
|
|
|
menu->setEnabled(false);
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool createPointerActions = item->origaddr && item->origaddr != item->address;
|
|
|
|
|
|
|
|
|
|
QPoint pos = QPoint(100, 100); // ev->globalPos
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Open Memory View at Object's Address (0x%1)").arg(item->address, 0, 16),
|
|
|
|
|
tr("Open Memory View at Object's Address"),
|
|
|
|
|
item->address,
|
|
|
|
|
[this, item, pos] { addVariableMemoryView(true, item, false, pos); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Open Memory View at Pointer's Address (0x%1)").arg(item->origaddr, 0, 16),
|
|
|
|
|
tr("Open Memory View at Pointer's Address"),
|
|
|
|
|
createPointerActions,
|
|
|
|
|
[this, item, pos] { addVariableMemoryView(true, item, true, pos); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Open Memory Editor at Object's Address (0x%1)").arg(item->address, 0, 16),
|
|
|
|
|
tr("Open Memory Editor at Object's Address"),
|
|
|
|
|
item->address,
|
|
|
|
|
[this, item, pos] { addVariableMemoryView(false, item, false, pos); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Open Memory Editor at Pointer's Address (0x%1)").arg(item->origaddr, 0, 16),
|
|
|
|
|
tr("Open Memory Editor at Pointer's Address"),
|
|
|
|
|
createPointerActions,
|
|
|
|
|
[this, item, pos] { addVariableMemoryView(false, item, true, pos); });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Open Memory Editor Showing Stack Layout"),
|
|
|
|
|
item && item->isLocal(),
|
|
|
|
|
[this, item, pos] { addStackLayoutMemoryView(false, pos); });
|
|
|
|
|
|
|
|
|
|
addAction(menu, tr("Open Memory Editor..."),
|
|
|
|
|
true,
|
|
|
|
|
[this, item] {
|
|
|
|
|
AddressDialog dialog;
|
|
|
|
|
if (item->address)
|
|
|
|
|
dialog.setAddress(item->address);
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
|
|
|
MemoryViewSetupData data;
|
|
|
|
|
data.startAddress = dialog.address();
|
|
|
|
|
m_engine->openMemoryView(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QMenu *WatchModel::createFormatMenu(WatchItem *item)
|
|
|
|
|
{
|
|
|
|
|
auto menu = new QMenu(tr("Change Value Display Format"));
|
|
|
|
|
if (!item) {
|
|
|
|
|
menu->setEnabled(false);
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DisplayFormats alternativeFormats = typeFormatList(item);
|
|
|
|
|
|
2016-11-11 18:06:41 +01:00
|
|
|
const QString iname = item->iname;
|
2016-07-18 12:36:31 +02:00
|
|
|
const int typeFormat = theTypeFormats.value(stripForFormat(item->type), AutomaticFormat);
|
2016-11-11 18:06:41 +01:00
|
|
|
const int individualFormat = theIndividualFormats.value(iname, AutomaticFormat);
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
auto addBaseChangeAction = [this, menu](const QString &text, int base) {
|
|
|
|
|
addCheckableAction(menu, text, true, theUnprintableBase == base, [this, base] {
|
|
|
|
|
theUnprintableBase = base;
|
|
|
|
|
layoutChanged(); // FIXME
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
addBaseChangeAction(tr("Treat All Characters as Printable"), 0);
|
|
|
|
|
addBaseChangeAction(tr("Show Unprintable Characters as Escape Sequences"), -1);
|
|
|
|
|
addBaseChangeAction(tr("Show Unprintable Characters as Octal"), 8);
|
|
|
|
|
addBaseChangeAction(tr("Show Unprintable Characters as Hexadecimal"), 16);
|
|
|
|
|
|
|
|
|
|
QAction *act = 0;
|
|
|
|
|
|
|
|
|
|
const QString spacer = " ";
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
|
2016-11-11 18:06:41 +01:00
|
|
|
addAction(menu, tr("Change Display for Object Named \"%1\":").arg(iname), false);
|
2016-07-18 12:36:31 +02:00
|
|
|
|
|
|
|
|
QString msg = (individualFormat == AutomaticFormat && typeFormat != AutomaticFormat)
|
|
|
|
|
? tr("Use Format for Type (Currently %1)").arg(nameForFormat(typeFormat))
|
|
|
|
|
: QString(tr("Use Display Format Based on Type") + ' ');
|
|
|
|
|
|
|
|
|
|
addCheckableAction(menu, spacer + msg, true, individualFormat == AutomaticFormat,
|
2016-11-11 18:06:41 +01:00
|
|
|
[this, iname] {
|
2016-07-18 12:36:31 +02:00
|
|
|
// FIXME: Extend to multi-selection.
|
|
|
|
|
//const QModelIndexList active = activeRows();
|
|
|
|
|
//foreach (const QModelIndex &idx, active)
|
|
|
|
|
// setModelData(LocalsIndividualFormatRole, AutomaticFormat, idx);
|
2016-11-11 18:06:41 +01:00
|
|
|
setIndividualFormat(iname, AutomaticFormat);
|
2016-07-18 12:36:31 +02:00
|
|
|
m_engine->updateLocals();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (int format : alternativeFormats) {
|
|
|
|
|
addCheckableAction(menu, spacer + nameForFormat(format), true, format == individualFormat,
|
2016-11-11 18:06:41 +01:00
|
|
|
[this, act, format, iname] {
|
|
|
|
|
setIndividualFormat(iname, format);
|
2016-07-18 12:36:31 +02:00
|
|
|
m_engine->updateLocals();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menu->addSeparator();
|
|
|
|
|
addAction(menu, tr("Change Display for Type \"%1\":").arg(item->type), false);
|
|
|
|
|
|
|
|
|
|
addCheckableAction(menu, spacer + tr("Automatic"), true, typeFormat == AutomaticFormat,
|
2016-11-11 18:06:41 +01:00
|
|
|
[this, iname] {
|
2016-07-18 12:36:31 +02:00
|
|
|
//const QModelIndexList active = activeRows();
|
|
|
|
|
//foreach (const QModelIndex &idx, active)
|
|
|
|
|
// setModelData(LocalsTypeFormatRole, AutomaticFormat, idx);
|
2016-11-11 18:06:41 +01:00
|
|
|
setTypeFormat(iname, AutomaticFormat);
|
2016-07-18 12:36:31 +02:00
|
|
|
m_engine->updateLocals();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (int format : alternativeFormats) {
|
|
|
|
|
addCheckableAction(menu, spacer + nameForFormat(format), true, format == typeFormat,
|
2016-11-11 18:06:41 +01:00
|
|
|
[this, act, format, iname] {
|
|
|
|
|
setTypeFormat(iname, format);
|
2016-07-18 12:36:31 +02:00
|
|
|
m_engine->updateLocals();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 12:51:37 +01:00
|
|
|
static inline QString msgArrayFormat(int n)
|
|
|
|
|
{
|
|
|
|
|
return WatchModel::tr("Array of %n items", 0, n);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
QString WatchModel::nameForFormat(int format)
|
|
|
|
|
{
|
|
|
|
|
switch (format) {
|
2015-03-31 09:29:34 +02:00
|
|
|
case AutomaticFormat: return tr("Automatic");
|
2015-03-20 16:03:59 +01:00
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
case RawFormat: return tr("Raw Data");
|
2016-06-27 16:46:40 +02:00
|
|
|
case SimpleFormat: return tr("Normal");
|
2015-03-31 09:29:34 +02:00
|
|
|
case EnhancedFormat: return tr("Enhanced");
|
2016-06-27 16:46:40 +02:00
|
|
|
case SeparateFormat: return tr("Separate Window");
|
2015-03-20 16:03:59 +01:00
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
case Latin1StringFormat: return tr("Latin1 String");
|
2015-03-20 16:03:59 +01:00
|
|
|
case SeparateLatin1StringFormat: return tr("Latin1 String in Separate Window");
|
2014-04-15 18:13:03 +02:00
|
|
|
case Utf8StringFormat: return tr("UTF-8 String");
|
2015-03-20 16:03:59 +01:00
|
|
|
case SeparateUtf8StringFormat: return tr("UTF-8 String in Separate Window");
|
2014-04-15 18:13:03 +02:00
|
|
|
case Local8BitStringFormat: return tr("Local 8-Bit String");
|
|
|
|
|
case Utf16StringFormat: return tr("UTF-16 String");
|
|
|
|
|
case Ucs4StringFormat: return tr("UCS-4 String");
|
2015-03-20 16:03:59 +01:00
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
case Array10Format: return msgArrayFormat(10);
|
|
|
|
|
case Array100Format: return msgArrayFormat(100);
|
|
|
|
|
case Array1000Format: return msgArrayFormat(1000);
|
|
|
|
|
case Array10000Format: return msgArrayFormat(10000);
|
2015-03-31 09:29:34 +02:00
|
|
|
case ArrayPlotFormat: return tr("Plot in Separate Window");
|
|
|
|
|
|
|
|
|
|
case CompactMapFormat: return tr("Display Keys and Values Side by Side");
|
|
|
|
|
case DirectQListStorageFormat: return tr("Force Display as Direct Storage Form");
|
|
|
|
|
case IndirectQListStorageFormat: return tr("Force Display as Indirect Storage Form");
|
|
|
|
|
|
|
|
|
|
case BoolTextFormat: return tr("Display Boolean Values as True or False");
|
|
|
|
|
case BoolIntegerFormat: return tr("Display Boolean Values as 1 or 0");
|
2015-03-20 16:03:59 +01:00
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
case DecimalIntegerFormat: return tr("Decimal Integer");
|
|
|
|
|
case HexadecimalIntegerFormat: return tr("Hexadecimal Integer");
|
|
|
|
|
case BinaryIntegerFormat: return tr("Binary Integer");
|
|
|
|
|
case OctalIntegerFormat: return tr("Octal Integer");
|
2015-03-20 16:03:59 +01:00
|
|
|
|
2014-04-15 18:13:03 +02:00
|
|
|
case CompactFloatFormat: return tr("Compact Float");
|
|
|
|
|
case ScientificFloatFormat: return tr("Scientific Float");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTC_CHECK(false);
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-17 16:00:03 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// WatchHandler
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
WatchHandler::WatchHandler(DebuggerEngine *engine)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-03-20 13:18:36 +01:00
|
|
|
m_model = new WatchModel(this, engine);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-05-18 02:28:41 +02:00
|
|
|
WatchHandler::~WatchHandler()
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2012-05-18 02:28:41 +02:00
|
|
|
// Do it manually to prevent calling back in model destructors
|
|
|
|
|
// after m_cache is destroyed.
|
|
|
|
|
delete m_model;
|
|
|
|
|
m_model = 0;
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void WatchHandler::cleanup()
|
|
|
|
|
{
|
2012-05-18 02:28:41 +02:00
|
|
|
m_model->m_expandedINames.clear();
|
2016-06-07 17:04:53 +02:00
|
|
|
theWatcherNames.remove(QString());
|
2015-03-18 13:28:45 +01:00
|
|
|
saveWatchers();
|
2012-05-18 02:28:41 +02:00
|
|
|
m_model->reinitialize();
|
2015-03-06 09:14:40 +01:00
|
|
|
emit m_model->updateFinished();
|
2016-04-20 15:09:57 +02:00
|
|
|
if (Internal::mainWindow())
|
|
|
|
|
m_model->m_separatedView->hide();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-09 15:26:33 +02:00
|
|
|
static bool sortByName(const WatchItem *a, const WatchItem *b)
|
2016-04-05 13:27:24 +02:00
|
|
|
{
|
2016-06-09 15:26:33 +02:00
|
|
|
return a->name < b->name;
|
2016-04-05 13:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchHandler::insertItems(const GdbMi &data)
|
2015-01-28 15:14:15 +01:00
|
|
|
{
|
2016-06-09 15:26:33 +02:00
|
|
|
QSet<WatchItem *> itemsToSort;
|
2016-04-05 13:27:24 +02:00
|
|
|
|
|
|
|
|
const bool sortStructMembers = boolSetting(SortStructMembers);
|
|
|
|
|
foreach (const GdbMi &child, data.children()) {
|
|
|
|
|
auto item = new WatchItem;
|
|
|
|
|
item->parse(child, sortStructMembers);
|
|
|
|
|
const TypeInfo ti = m_model->m_reportedTypeInfo.value(item->type);
|
|
|
|
|
if (ti.size && !item->size)
|
|
|
|
|
item->size = ti.size;
|
|
|
|
|
|
|
|
|
|
const bool added = insertItem(item);
|
|
|
|
|
if (added && item->level() == 2)
|
2016-06-09 15:26:33 +02:00
|
|
|
itemsToSort.insert(static_cast<WatchItem *>(item->parent()));
|
2016-04-05 13:27:24 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-09 15:26:33 +02:00
|
|
|
foreach (WatchItem *toplevel, itemsToSort)
|
2016-04-05 13:27:24 +02:00
|
|
|
toplevel->sortChildren(&sortByName);
|
2015-01-28 15:14:15 +01:00
|
|
|
}
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
void WatchHandler::removeItemByIName(const QString &iname)
|
|
|
|
|
{
|
|
|
|
|
m_model->removeWatchItem(m_model->findItem(iname));
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 13:27:24 +02:00
|
|
|
bool WatchHandler::insertItem(WatchItem *item)
|
2015-01-28 15:14:15 +01:00
|
|
|
{
|
2016-04-05 13:27:24 +02:00
|
|
|
QTC_ASSERT(!item->iname.isEmpty(), return false);
|
2015-07-03 13:48:00 +02:00
|
|
|
|
2016-04-05 13:27:24 +02:00
|
|
|
WatchItem *parent = m_model->findItem(parentName(item->iname));
|
|
|
|
|
QTC_ASSERT(parent, return false);
|
2015-05-20 13:57:06 +02:00
|
|
|
|
2015-07-03 13:48:00 +02:00
|
|
|
bool found = false;
|
|
|
|
|
const QVector<TreeItem *> siblings = parent->children();
|
|
|
|
|
for (int row = 0, n = siblings.size(); row < n; ++row) {
|
|
|
|
|
if (static_cast<WatchItem *>(siblings.at(row))->iname == item->iname) {
|
2016-07-04 15:53:53 +02:00
|
|
|
m_model->destroyItem(parent->children().at(row));
|
2015-07-03 13:48:00 +02:00
|
|
|
parent->insertChild(row, item);
|
|
|
|
|
found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-05-29 09:38:53 +02:00
|
|
|
}
|
2015-07-03 13:48:00 +02:00
|
|
|
if (!found)
|
|
|
|
|
parent->appendChild(item);
|
2015-03-20 14:13:27 +01:00
|
|
|
|
2015-07-17 12:28:00 +02:00
|
|
|
item->update();
|
|
|
|
|
|
2016-06-16 09:19:07 +02:00
|
|
|
m_model->showEditValue(item);
|
2016-06-09 15:26:33 +02:00
|
|
|
item->forAllChildren([this](WatchItem *sub) { m_model->showEditValue(sub); });
|
2016-04-05 13:27:24 +02:00
|
|
|
|
|
|
|
|
return !found;
|
2015-01-28 15:14:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchModel::reexpandItems()
|
|
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
foreach (const QString &iname, m_expandedINames) {
|
2015-03-03 10:01:50 +01:00
|
|
|
if (WatchItem *item = findItem(iname)) {
|
2015-04-22 12:37:39 +02:00
|
|
|
emit itemIsExpanded(indexForItem(item));
|
2015-03-03 10:01:50 +01:00
|
|
|
emit inameIsExpanded(iname);
|
|
|
|
|
} else {
|
|
|
|
|
// Can happen. We might have stepped into another frame
|
|
|
|
|
// not containing that iname, but we still like to
|
|
|
|
|
// remember the expanded state of iname in case we step
|
|
|
|
|
// out of the frame again.
|
|
|
|
|
}
|
2015-01-28 15:14:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-09 16:13:29 +02:00
|
|
|
void WatchHandler::removeAllData(bool includeInspectData)
|
2012-05-18 02:28:41 +02:00
|
|
|
{
|
2012-10-09 16:13:29 +02:00
|
|
|
m_model->reinitialize(includeInspectData);
|
2009-07-13 12:28:47 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-08 15:50:47 +02:00
|
|
|
/*!
|
|
|
|
|
If a displayed item differs from the cached entry it is considered
|
|
|
|
|
"new", and correspondingly marked in red. Calling \c resetValueCache()
|
|
|
|
|
stores the currently displayed items in the cache, effectively
|
|
|
|
|
marking the value as known, and consequently painted black.
|
|
|
|
|
*/
|
2012-09-21 16:46:06 +02:00
|
|
|
void WatchHandler::resetValueCache()
|
2012-05-31 14:26:08 +02:00
|
|
|
{
|
2012-09-21 16:46:06 +02:00
|
|
|
m_model->m_valueCache.clear();
|
2016-05-27 11:12:03 +02:00
|
|
|
m_model->forAllItems([this](WatchItem *item) {
|
|
|
|
|
m_model->m_valueCache[item->iname] = item->value;
|
2015-01-29 09:58:23 +01:00
|
|
|
});
|
2012-05-31 14:26:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-03-18 13:28:45 +01:00
|
|
|
void WatchHandler::resetWatchers()
|
|
|
|
|
{
|
|
|
|
|
loadSessionData();
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-03 13:28:28 +01:00
|
|
|
void WatchHandler::notifyUpdateStarted(const UpdateParameters &updateParameters)
|
2015-03-06 09:14:40 +01:00
|
|
|
{
|
2016-11-03 13:28:28 +01:00
|
|
|
QStringList inames = updateParameters.partialVariables();
|
|
|
|
|
if (inames.isEmpty())
|
2016-11-18 09:01:08 +01:00
|
|
|
inames = QStringList({ "local", "return" });
|
2016-11-03 13:28:28 +01:00
|
|
|
|
2016-06-09 15:26:33 +02:00
|
|
|
auto marker = [](WatchItem *item) { item->outdated = true; };
|
2015-07-06 09:46:08 +02:00
|
|
|
|
|
|
|
|
if (inames.isEmpty()) {
|
2016-06-24 09:36:42 +02:00
|
|
|
m_model->forItemsAtLevel<1>([marker](WatchItem *item) {
|
2016-06-09 15:26:33 +02:00
|
|
|
item->forAllChildren(marker);
|
2016-05-04 16:41:15 +02:00
|
|
|
});
|
2015-07-06 09:46:08 +02:00
|
|
|
} else {
|
2016-05-27 11:12:03 +02:00
|
|
|
for (auto iname : inames) {
|
2015-07-06 09:46:08 +02:00
|
|
|
if (WatchItem *item = m_model->findItem(iname))
|
2016-06-09 15:26:33 +02:00
|
|
|
item->forAllChildren(marker);
|
2015-07-06 09:46:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-17 13:26:20 +01:00
|
|
|
m_model->m_requestUpdateTimer.start(80);
|
2015-03-20 13:18:36 +01:00
|
|
|
m_model->m_contentsValid = false;
|
2015-03-18 13:28:45 +01:00
|
|
|
updateWatchersWindow();
|
2015-03-06 09:14:40 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-17 13:26:20 +01:00
|
|
|
void WatchHandler::notifyUpdateFinished()
|
2015-03-06 09:14:40 +01:00
|
|
|
{
|
2016-05-27 11:12:03 +02:00
|
|
|
QList<WatchItem *> toRemove;
|
|
|
|
|
m_model->forSelectedItems([this, &toRemove](WatchItem *item) {
|
|
|
|
|
if (item->outdated) {
|
|
|
|
|
toRemove.append(item);
|
2015-07-06 09:46:08 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-05-27 11:12:03 +02:00
|
|
|
return true;
|
|
|
|
|
});
|
2015-03-06 09:14:40 +01:00
|
|
|
|
2016-05-27 11:12:03 +02:00
|
|
|
foreach (auto item, toRemove)
|
2016-07-04 15:53:53 +02:00
|
|
|
m_model->destroyItem(item);
|
2015-01-28 15:14:15 +01:00
|
|
|
|
2016-08-01 16:00:07 +02:00
|
|
|
m_model->forAllItems([this](WatchItem *item) {
|
|
|
|
|
if (item->wantsChildren && isExpandedIName(item->iname)) {
|
|
|
|
|
m_model->m_engine->showMessage(QString("ADJUSTING CHILD EXPECTATION FOR " + item->iname));
|
|
|
|
|
item->wantsChildren = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-03-20 13:18:36 +01:00
|
|
|
m_model->m_contentsValid = true;
|
2015-02-09 15:27:18 +01:00
|
|
|
updateWatchersWindow();
|
2015-07-06 09:46:08 +02:00
|
|
|
m_model->reexpandItems();
|
|
|
|
|
m_model->m_requestUpdateTimer.stop();
|
|
|
|
|
emit m_model->updateFinished();
|
2015-01-28 15:14:15 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-08 10:44:10 +02:00
|
|
|
void WatchHandler::reexpandItems()
|
|
|
|
|
{
|
|
|
|
|
m_model->reexpandItems();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
void WatchModel::removeWatchItem(WatchItem *item)
|
2009-06-24 12:31:09 +02:00
|
|
|
{
|
2016-07-18 12:36:31 +02:00
|
|
|
QTC_ASSERT(item, return);
|
2015-03-19 12:42:53 +01:00
|
|
|
if (item->isWatcher()) {
|
|
|
|
|
theWatcherNames.remove(item->exp);
|
2012-05-24 16:49:18 +02:00
|
|
|
saveWatchers();
|
|
|
|
|
}
|
2016-07-18 12:36:31 +02:00
|
|
|
destroyItem(item);
|
|
|
|
|
m_handler->updateWatchersWindow();
|
2012-05-18 02:28:41 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QString WatchHandler::watcherName(const QString &exp)
|
2009-04-15 10:06:31 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
return "watch." + QString::number(theWatcherNames[exp]);
|
2009-04-15 10:06:31 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void WatchHandler::watchExpression(const QString &exp, const QString &name)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-11-25 16:32:07 +01:00
|
|
|
// Do not insert the same entry more then once.
|
2015-03-18 13:28:45 +01:00
|
|
|
if (exp.isEmpty() || theWatcherNames.contains(exp))
|
2010-07-22 15:34:35 +02:00
|
|
|
return;
|
|
|
|
|
|
2015-03-18 13:28:45 +01:00
|
|
|
theWatcherNames[exp] = theWatcherCount++;
|
2013-08-10 21:22:02 +02:00
|
|
|
|
2015-03-19 12:42:53 +01:00
|
|
|
auto item = new WatchItem;
|
|
|
|
|
item->exp = exp;
|
2016-06-07 17:04:53 +02:00
|
|
|
item->name = name.isEmpty() ? exp : name;
|
2015-03-19 12:42:53 +01:00
|
|
|
item->iname = watcherName(exp);
|
2016-04-05 13:27:24 +02:00
|
|
|
insertItem(item);
|
2011-02-28 18:55:54 +01:00
|
|
|
saveWatchers();
|
|
|
|
|
|
2015-03-20 13:18:36 +01:00
|
|
|
if (m_model->m_engine->state() == DebuggerNotReady) {
|
2015-03-19 12:42:53 +01:00
|
|
|
item->setValue(QString(QLatin1Char(' ')));
|
2015-08-11 14:13:06 +02:00
|
|
|
item->update();
|
|
|
|
|
} else {
|
2016-05-17 15:01:46 +02:00
|
|
|
m_model->m_engine->updateWatchData(item->iname);
|
2015-08-11 14:13:06 +02:00
|
|
|
}
|
|
|
|
|
updateWatchersWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void WatchHandler::updateWatchExpression(WatchItem *item, const QString &newExp)
|
2015-08-11 14:13:06 +02:00
|
|
|
{
|
|
|
|
|
if (newExp.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (item->exp != newExp) {
|
|
|
|
|
theWatcherNames.insert(newExp, theWatcherNames.value(item->exp));
|
|
|
|
|
theWatcherNames.remove(item->exp);
|
|
|
|
|
item->exp = newExp;
|
2016-06-07 17:04:53 +02:00
|
|
|
item->name = newExp;
|
2015-08-11 14:13:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveWatchers();
|
|
|
|
|
if (m_model->m_engine->state() == DebuggerNotReady) {
|
|
|
|
|
item->setValue(QString(QLatin1Char(' ')));
|
|
|
|
|
item->update();
|
2010-11-23 13:28:18 +01:00
|
|
|
} else {
|
2015-07-15 17:14:29 +02:00
|
|
|
m_model->m_engine->updateItem(item->iname);
|
2010-11-23 13:28:18 +01:00
|
|
|
}
|
2010-06-16 11:08:54 +02:00
|
|
|
updateWatchersWindow();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-10-29 12:59:53 +01:00
|
|
|
// Watch something obtained from the editor.
|
|
|
|
|
// Prefer to watch an existing local variable by its expression
|
|
|
|
|
// (address) if it can be found. Default to watchExpression().
|
|
|
|
|
void WatchHandler::watchVariable(const QString &exp)
|
|
|
|
|
{
|
2015-12-16 17:17:38 +01:00
|
|
|
if (const WatchItem *localVariable = findCppLocalVariable(exp))
|
2016-06-07 17:04:53 +02:00
|
|
|
watchExpression(localVariable->exp, exp);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2012-10-29 12:59:53 +01:00
|
|
|
watchExpression(exp);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 11:14:50 +01:00
|
|
|
static void swapEndian(char *d, int nchar)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-03-12 11:14:50 +01:00
|
|
|
QTC_ASSERT(nchar % 4 == 0, return);
|
|
|
|
|
for (int i = 0; i < nchar; i += 4) {
|
|
|
|
|
char c = d[i];
|
|
|
|
|
d[i] = d[i + 3];
|
|
|
|
|
d[i + 3] = c;
|
|
|
|
|
c = d[i + 1];
|
|
|
|
|
d[i + 1] = d[i + 2];
|
|
|
|
|
d[i + 2] = c;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 18:52:49 +02:00
|
|
|
template <class T> void readOne(const char *p, QString *res, int size)
|
|
|
|
|
{
|
|
|
|
|
T r = 0;
|
|
|
|
|
memcpy(&r, p, size);
|
|
|
|
|
res->setNum(r);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-01 17:19:43 +02:00
|
|
|
void WatchModel::showEditValue(const WatchItem *item)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString &format = item->editformat;
|
2016-04-08 00:49:22 +02:00
|
|
|
if (format.isEmpty()) {
|
|
|
|
|
// Nothing
|
|
|
|
|
m_separatedView->removeObject(item->key());
|
|
|
|
|
} else if (format == DisplayImageData || format == DisplayImageFile) {
|
|
|
|
|
// QImage
|
|
|
|
|
int width = 0, height = 0, nbytes = 0, imformat = 0;
|
2010-03-17 13:03:34 +01:00
|
|
|
QByteArray ba;
|
2012-10-29 23:35:56 +02:00
|
|
|
uchar *bits = 0;
|
2016-04-08 00:49:22 +02:00
|
|
|
if (format == DisplayImageData) {
|
2016-06-07 17:04:53 +02:00
|
|
|
ba = QByteArray::fromHex(item->editvalue.toUtf8());
|
2013-07-01 11:43:56 +02:00
|
|
|
QTC_ASSERT(ba.size() > 16, return);
|
2010-03-17 13:03:34 +01:00
|
|
|
const int *header = (int *)(ba.data());
|
2012-12-28 18:57:33 +01:00
|
|
|
if (!ba.at(0) && !ba.at(1)) // Check on 'width' for Python dumpers returning 4-byte swapped-data.
|
2013-07-01 11:43:56 +02:00
|
|
|
swapEndian(ba.data(), 16);
|
|
|
|
|
bits = 16 + (uchar *)(ba.data());
|
2010-03-17 13:03:34 +01:00
|
|
|
width = header[0];
|
|
|
|
|
height = header[1];
|
2013-07-01 11:43:56 +02:00
|
|
|
nbytes = header[2];
|
2016-04-08 00:49:22 +02:00
|
|
|
imformat = header[3];
|
|
|
|
|
} else if (format == DisplayImageFile) {
|
2016-06-07 17:04:53 +02:00
|
|
|
QTextStream ts(item->editvalue.toUtf8());
|
2010-03-17 13:03:34 +01:00
|
|
|
QString fileName;
|
2016-04-08 00:49:22 +02:00
|
|
|
ts >> width >> height >> nbytes >> imformat >> fileName;
|
2010-03-17 13:03:34 +01:00
|
|
|
QFile f(fileName);
|
|
|
|
|
f.open(QIODevice::ReadOnly);
|
|
|
|
|
ba = f.readAll();
|
|
|
|
|
bits = (uchar*)ba.data();
|
2013-07-01 11:43:56 +02:00
|
|
|
nbytes = width * height;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2013-07-01 11:43:56 +02:00
|
|
|
QTC_ASSERT(0 < width && width < 10000, return);
|
|
|
|
|
QTC_ASSERT(0 < height && height < 10000, return);
|
|
|
|
|
QTC_ASSERT(0 < nbytes && nbytes < 10000 * 10000, return);
|
2016-04-08 00:49:22 +02:00
|
|
|
QTC_ASSERT(0 < imformat && imformat < 32, return);
|
|
|
|
|
QImage im(width, height, QImage::Format(imformat));
|
2014-08-28 17:33:47 +02:00
|
|
|
std::memcpy(im.bits(), bits, nbytes);
|
2016-04-08 00:49:22 +02:00
|
|
|
ImageViewer *v = m_separatedView->prepareObject<ImageViewer>(item);
|
2015-04-01 17:19:43 +02:00
|
|
|
v->setInfo(item->address ?
|
2016-06-07 17:04:53 +02:00
|
|
|
tr("%1 Object at %2").arg(item->type, item->hexAddress()) :
|
|
|
|
|
tr("%1 Object at Unknown Address").arg(item->type) + " " +
|
2015-04-01 17:19:43 +02:00
|
|
|
ImageViewer::tr("Size: %1x%2, %3 byte, format: %4, depth: %5")
|
|
|
|
|
.arg(width).arg(height).arg(nbytes).arg(im.format()).arg(im.depth())
|
|
|
|
|
);
|
2014-05-17 21:00:22 +02:00
|
|
|
v->setImage(im);
|
2016-04-08 00:49:22 +02:00
|
|
|
} else if (format == DisplayLatin1String
|
|
|
|
|
|| format == DisplayUtf8String
|
|
|
|
|
|| format == DisplayUtf16String
|
|
|
|
|
|| format == DisplayUcs4String) {
|
|
|
|
|
// String data.
|
2016-06-07 17:04:53 +02:00
|
|
|
QByteArray ba = QByteArray::fromHex(item->editvalue.toUtf8());
|
2012-10-04 13:03:01 +02:00
|
|
|
QString str;
|
2016-04-08 00:49:22 +02:00
|
|
|
if (format == DisplayLatin1String)
|
2012-10-04 13:03:01 +02:00
|
|
|
str = QString::fromLatin1(ba.constData(), ba.size());
|
2016-04-08 00:49:22 +02:00
|
|
|
else if (format == DisplayUtf8String)
|
2012-10-04 13:03:01 +02:00
|
|
|
str = QString::fromUtf8(ba.constData(), ba.size());
|
2016-04-08 00:49:22 +02:00
|
|
|
else if (format == DisplayUtf16String)
|
|
|
|
|
str = QString::fromUtf16((ushort *)ba.constData(), ba.size() / 2);
|
|
|
|
|
else if (format == DisplayUtf16String)
|
|
|
|
|
str = QString::fromUcs4((uint *)ba.constData(), ba.size() / 4);
|
2016-11-22 14:55:47 +01:00
|
|
|
m_separatedView->prepareObject<TextEdit>(item)->setPlainText(str);
|
2016-04-08 00:49:22 +02:00
|
|
|
} else if (format == DisplayPlotData) {
|
|
|
|
|
// Plots
|
2015-04-01 17:19:43 +02:00
|
|
|
std::vector<double> data;
|
2016-06-07 17:04:53 +02:00
|
|
|
readNumericVector(&data, QByteArray::fromHex(item->editvalue.toUtf8()), item->editencoding);
|
2016-04-08 00:49:22 +02:00
|
|
|
m_separatedView->prepareObject<PlotViewer>(item)->setData(data);
|
2016-09-21 18:52:49 +02:00
|
|
|
} else if (format.startsWith(DisplayArrayData)) {
|
|
|
|
|
QString innerType = format.section(':', 2, 2);
|
|
|
|
|
int innerSize = format.section(':', 3, 3).toInt();
|
|
|
|
|
QTC_ASSERT(0 <= innerSize && innerSize <= 8, return);
|
|
|
|
|
// int hint = format.section(':', 4, 4).toInt();
|
|
|
|
|
int ndims = format.section(':', 5, 5).toInt();
|
|
|
|
|
int ncols = format.section(':', 6, 6).toInt();
|
|
|
|
|
int nrows = format.section(':', 7, 7).toInt();
|
|
|
|
|
QTC_ASSERT(ndims == 2, qDebug() << "Display format: " << format; return);
|
|
|
|
|
QByteArray ba = QByteArray::fromHex(item->editvalue.toUtf8());
|
|
|
|
|
|
|
|
|
|
void (*reader)(const char *p, QString *res, int size) = 0;
|
|
|
|
|
if (innerType == "int")
|
|
|
|
|
reader = &readOne<qlonglong>;
|
|
|
|
|
else if (innerType == "uint")
|
|
|
|
|
reader = &readOne<qulonglong>;
|
|
|
|
|
else if (innerType == "float") {
|
|
|
|
|
if (innerSize == 4)
|
|
|
|
|
reader = &readOne<float>;
|
|
|
|
|
else if (innerSize == 4)
|
|
|
|
|
reader = &readOne<double>;
|
|
|
|
|
}
|
|
|
|
|
QTC_ASSERT(reader, return);
|
|
|
|
|
auto table = m_separatedView->prepareObject<QTableWidget>(item);
|
|
|
|
|
table->setRowCount(nrows);
|
|
|
|
|
table->setColumnCount(ncols);
|
|
|
|
|
QString s;
|
|
|
|
|
const char *p = ba.constBegin();
|
|
|
|
|
for (int i = 0; i < nrows; ++i) {
|
|
|
|
|
for (int j = 0; j < ncols; ++j) {
|
|
|
|
|
reader(p, &s, innerSize);
|
|
|
|
|
table->setItem(i, j, new QTableWidgetItem(s));
|
|
|
|
|
p += innerSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-08 00:49:22 +02:00
|
|
|
} else {
|
|
|
|
|
QTC_ASSERT(false, qDebug() << "Display format: " << format);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
void WatchModel::clearWatches()
|
2011-01-14 17:28:37 +01:00
|
|
|
{
|
2012-03-14 12:26:27 +01:00
|
|
|
if (theWatcherNames.isEmpty())
|
2011-01-14 17:28:37 +01:00
|
|
|
return;
|
2014-12-02 08:56:33 +01:00
|
|
|
|
2015-02-03 23:58:49 +02:00
|
|
|
const QDialogButtonBox::StandardButton ret = CheckableMessageBox::doNotAskAgainQuestion(
|
2016-07-18 12:36:31 +02:00
|
|
|
ICore::mainWindow(), tr("Remove All Expression Evaluators"),
|
2014-12-02 08:56:33 +01:00
|
|
|
tr("Are you sure you want to remove all expression evaluators?"),
|
2016-07-18 12:36:31 +02:00
|
|
|
ICore::settings(), "RemoveAllWatchers");
|
2014-12-02 08:56:33 +01:00
|
|
|
if (ret != QDialogButtonBox::Yes)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
m_watchRoot->removeChildren();
|
2012-03-14 12:26:27 +01:00
|
|
|
theWatcherNames.clear();
|
2015-03-16 09:10:36 +01:00
|
|
|
theWatcherCount = 0;
|
2016-07-18 12:36:31 +02:00
|
|
|
m_handler->updateWatchersWindow();
|
2011-01-14 17:28:37 +01:00
|
|
|
saveWatchers();
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void WatchHandler::updateWatchersWindow()
|
|
|
|
|
{
|
2015-03-06 14:25:33 +01:00
|
|
|
emit m_model->columnAdjustmentRequested();
|
|
|
|
|
|
2010-06-23 14:11:52 +02:00
|
|
|
// Force show/hide of watchers and return view.
|
2015-03-18 13:28:45 +01:00
|
|
|
int showWatch = !theWatcherNames.isEmpty();
|
2015-04-22 14:49:14 +02:00
|
|
|
int showReturn = m_model->m_returnRoot->childCount() != 0;
|
2014-10-22 13:04:47 +02:00
|
|
|
Internal::updateWatchersWindow(showWatch, showReturn);
|
2010-06-16 11:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-04 18:11:09 +01:00
|
|
|
QStringList WatchHandler::watchedExpressions()
|
2008-12-17 17:43:01 +01:00
|
|
|
{
|
2009-12-04 13:22:39 +01:00
|
|
|
// Filter out invalid watchers.
|
2009-06-23 13:43:23 +02:00
|
|
|
QStringList watcherNames;
|
2016-06-07 17:04:53 +02:00
|
|
|
QHashIterator<QString, int> it(theWatcherNames);
|
2009-07-03 11:20:47 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString &watcherName = it.key();
|
2010-07-23 18:20:13 +02:00
|
|
|
if (!watcherName.isEmpty())
|
2016-06-07 17:04:53 +02:00
|
|
|
watcherNames.push_back(watcherName);
|
2009-06-23 13:43:23 +02:00
|
|
|
}
|
2009-12-04 13:22:39 +01:00
|
|
|
return watcherNames;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:43:01 +01:00
|
|
|
void WatchHandler::saveSessionData()
|
|
|
|
|
{
|
|
|
|
|
saveWatchers();
|
2013-11-28 14:28:20 +01:00
|
|
|
saveFormats();
|
2008-12-17 17:43:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchHandler::loadSessionData()
|
|
|
|
|
{
|
2013-11-28 14:28:20 +01:00
|
|
|
loadFormats();
|
2012-03-14 12:26:27 +01:00
|
|
|
theWatcherNames.clear();
|
2015-03-16 09:10:36 +01:00
|
|
|
theWatcherCount = 0;
|
2014-07-28 14:23:52 +02:00
|
|
|
QVariant value = sessionValue("Watchers");
|
2015-01-29 09:58:23 +01:00
|
|
|
m_model->m_watchRoot->removeChildren();
|
2010-11-25 16:32:07 +01:00
|
|
|
foreach (const QString &exp, value.toStringList())
|
2015-03-19 22:35:39 +02:00
|
|
|
watchExpression(exp.trimmed());
|
2010-11-04 18:11:09 +01:00
|
|
|
}
|
2010-06-25 09:53:23 +02:00
|
|
|
|
2014-11-07 13:50:09 +01:00
|
|
|
WatchModelBase *WatchHandler::model() const
|
2009-06-17 16:00:03 +02:00
|
|
|
{
|
2012-05-18 02:28:41 +02:00
|
|
|
return m_model;
|
2009-07-10 14:36:28 +02:00
|
|
|
}
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2015-03-19 12:42:53 +01:00
|
|
|
const WatchItem *WatchHandler::watchItem(const QModelIndex &idx) const
|
2009-06-17 16:00:03 +02:00
|
|
|
{
|
2016-06-09 15:34:48 +02:00
|
|
|
return m_model->itemForIndex(idx);
|
2008-12-17 17:43:01 +01:00
|
|
|
}
|
2009-06-17 16:00:03 +02:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void WatchHandler::fetchMore(const QString &iname) const
|
2012-11-23 17:15:29 +01:00
|
|
|
{
|
2015-12-16 17:17:38 +01:00
|
|
|
if (WatchItem *item = m_model->findItem(iname)) {
|
|
|
|
|
m_model->m_expandedINames.insert(iname);
|
2016-08-03 13:13:06 +02:00
|
|
|
if (item->children().isEmpty())
|
2015-12-16 17:17:38 +01:00
|
|
|
m_model->m_engine->expandItem(iname);
|
|
|
|
|
}
|
2012-11-23 17:15:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
WatchItem *WatchHandler::findItem(const QString &iname) const
|
2015-01-28 15:14:15 +01:00
|
|
|
{
|
|
|
|
|
return m_model->findItem(iname);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-19 12:42:53 +01:00
|
|
|
const WatchItem *WatchHandler::findCppLocalVariable(const QString &name) const
|
2012-08-31 11:34:27 +02:00
|
|
|
{
|
|
|
|
|
// Can this be found as a local variable?
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString localsPrefix("local.");
|
|
|
|
|
QString iname = localsPrefix + name;
|
2015-03-19 12:42:53 +01:00
|
|
|
if (const WatchItem *item = findItem(iname))
|
|
|
|
|
return item;
|
2014-11-11 11:00:32 +01:00
|
|
|
// // Nope, try a 'local.this.m_foo'.
|
|
|
|
|
// iname.insert(localsPrefix.size(), "this.");
|
|
|
|
|
// if (const WatchData *wd = findData(iname))
|
|
|
|
|
// return wd;
|
2012-08-31 11:34:27 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void WatchModel::setTypeFormat(const QString &type0, int format)
|
2009-07-03 11:20:47 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
const QString type = stripForFormat(type0);
|
2014-04-15 18:13:03 +02:00
|
|
|
if (format == AutomaticFormat)
|
2012-03-14 12:26:27 +01:00
|
|
|
theTypeFormats.remove(type);
|
2010-05-19 15:15:56 +02:00
|
|
|
else
|
2012-03-14 12:26:27 +01:00
|
|
|
theTypeFormats[type] = format;
|
2013-11-28 14:28:20 +01:00
|
|
|
saveFormats();
|
2015-05-29 09:38:53 +02:00
|
|
|
m_engine->updateAll();
|
2009-07-03 11:20:47 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void WatchModel::setIndividualFormat(const QString &iname, int format)
|
2015-04-01 17:19:43 +02:00
|
|
|
{
|
|
|
|
|
if (format == AutomaticFormat)
|
|
|
|
|
theIndividualFormats.remove(iname);
|
|
|
|
|
else
|
|
|
|
|
theIndividualFormats[iname] = format;
|
|
|
|
|
saveFormats();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
int WatchHandler::format(const QString &iname) const
|
2010-03-11 18:55:52 +01:00
|
|
|
{
|
2014-04-15 18:13:03 +02:00
|
|
|
int result = AutomaticFormat;
|
2015-01-29 09:58:23 +01:00
|
|
|
if (const WatchItem *item = m_model->findItem(iname)) {
|
2015-03-19 12:42:53 +01:00
|
|
|
result = theIndividualFormats.value(item->iname, AutomaticFormat);
|
2014-04-15 18:13:03 +02:00
|
|
|
if (result == AutomaticFormat)
|
2015-03-19 12:42:53 +01:00
|
|
|
result = theTypeFormats.value(stripForFormat(item->type), AutomaticFormat);
|
2010-03-11 18:55:52 +01:00
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-20 16:03:59 +01:00
|
|
|
QString WatchHandler::nameForFormat(int format)
|
|
|
|
|
{
|
|
|
|
|
return WatchModel::nameForFormat(format);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static QString formatStringFromFormatCode(int code)
|
2015-12-15 09:06:00 +01:00
|
|
|
{
|
|
|
|
|
switch (code) {
|
|
|
|
|
// Taken from debuggerprotocol.h, DisplayFormat.
|
|
|
|
|
case Latin1StringFormat:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("latin");
|
2015-12-15 09:06:00 +01:00
|
|
|
case SeparateLatin1StringFormat:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("latin:separate");
|
2015-12-15 09:06:00 +01:00
|
|
|
case Utf8StringFormat:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("utf8");
|
2015-12-15 09:06:00 +01:00
|
|
|
case SeparateUtf8StringFormat:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("utf8:separate");
|
2015-12-15 09:06:00 +01:00
|
|
|
case Utf16StringFormat:
|
2016-06-07 17:04:53 +02:00
|
|
|
return QLatin1String("utf16");
|
2015-12-15 09:06:00 +01:00
|
|
|
}
|
2016-06-07 17:04:53 +02:00
|
|
|
return QString();
|
2015-12-15 09:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QString WatchHandler::typeFormatRequests() const
|
2010-04-27 08:53:18 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
QString ba;
|
2012-03-14 12:26:27 +01:00
|
|
|
if (!theTypeFormats.isEmpty()) {
|
2016-06-07 17:04:53 +02:00
|
|
|
QHashIterator<QString, int> it(theTypeFormats);
|
2010-03-11 18:55:52 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
2014-04-15 18:13:03 +02:00
|
|
|
const int format = it.value();
|
2015-03-20 16:03:59 +01:00
|
|
|
if (format != AutomaticFormat) {
|
2016-06-07 17:04:53 +02:00
|
|
|
ba.append(toHex(it.key()));
|
2014-04-15 18:13:03 +02:00
|
|
|
ba.append('=');
|
2015-12-15 09:06:00 +01:00
|
|
|
ba.append(formatStringFromFormatCode(format));
|
2014-04-15 18:13:03 +02:00
|
|
|
ba.append(',');
|
|
|
|
|
}
|
2010-03-11 18:55:52 +01:00
|
|
|
}
|
|
|
|
|
ba.chop(1);
|
|
|
|
|
}
|
2010-04-27 08:53:18 +02:00
|
|
|
return ba;
|
|
|
|
|
}
|
2010-03-11 18:55:52 +01:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QString WatchHandler::individualFormatRequests() const
|
2010-04-27 08:53:18 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
QString res;
|
2012-03-14 12:26:27 +01:00
|
|
|
if (!theIndividualFormats.isEmpty()) {
|
2016-06-07 17:04:53 +02:00
|
|
|
QHashIterator<QString, int> it(theIndividualFormats);
|
2010-03-11 18:55:52 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
2014-04-15 18:13:03 +02:00
|
|
|
const int format = it.value();
|
2015-03-20 16:03:59 +01:00
|
|
|
if (format != AutomaticFormat) {
|
2016-06-07 17:04:53 +02:00
|
|
|
res.append(it.key());
|
|
|
|
|
res.append('=');
|
|
|
|
|
res.append(formatStringFromFormatCode(it.value()));
|
|
|
|
|
res.append(',');
|
2014-04-15 18:13:03 +02:00
|
|
|
}
|
2010-03-11 18:55:52 +01:00
|
|
|
}
|
2016-06-07 17:04:53 +02:00
|
|
|
res.chop(1);
|
2010-03-11 18:55:52 +01:00
|
|
|
}
|
2016-06-07 17:04:53 +02:00
|
|
|
return res;
|
2010-03-11 18:55:52 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-12 11:31:02 +01:00
|
|
|
void WatchHandler::appendFormatRequests(DebuggerCommand *cmd)
|
|
|
|
|
{
|
2015-09-14 13:40:35 +02:00
|
|
|
QJsonArray expanded;
|
2016-06-07 17:04:53 +02:00
|
|
|
QSetIterator<QString> jt(m_model->m_expandedINames);
|
2015-09-14 13:40:35 +02:00
|
|
|
while (jt.hasNext())
|
2016-06-07 17:04:53 +02:00
|
|
|
expanded.append(jt.next());
|
2015-09-14 13:40:35 +02:00
|
|
|
|
|
|
|
|
cmd->arg("expanded", expanded);
|
2015-02-12 11:31:02 +01:00
|
|
|
|
2015-09-14 13:40:35 +02:00
|
|
|
QJsonObject typeformats;
|
2016-06-07 17:04:53 +02:00
|
|
|
QHashIterator<QString, int> it(theTypeFormats);
|
2015-02-12 11:31:02 +01:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
|
|
|
|
const int format = it.value();
|
2015-03-20 16:03:59 +01:00
|
|
|
if (format != AutomaticFormat)
|
2016-06-07 17:04:53 +02:00
|
|
|
typeformats.insert(it.key(), format);
|
2015-02-12 11:31:02 +01:00
|
|
|
}
|
2015-09-14 13:40:35 +02:00
|
|
|
cmd->arg("typeformats", typeformats);
|
2015-02-12 11:31:02 +01:00
|
|
|
|
2015-09-14 13:40:35 +02:00
|
|
|
QJsonObject formats;
|
2016-06-07 17:04:53 +02:00
|
|
|
QHashIterator<QString, int> it2(theIndividualFormats);
|
2015-02-12 11:31:02 +01:00
|
|
|
while (it2.hasNext()) {
|
|
|
|
|
it2.next();
|
|
|
|
|
const int format = it2.value();
|
2015-03-20 16:03:59 +01:00
|
|
|
if (format != AutomaticFormat)
|
2016-06-07 17:04:53 +02:00
|
|
|
formats.insert(it2.key(), format);
|
2015-02-12 11:31:02 +01:00
|
|
|
}
|
2015-09-14 13:40:35 +02:00
|
|
|
cmd->arg("formats", formats);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
static inline QJsonObject watcher(const QString &iname, const QString &exp)
|
2015-09-14 13:40:35 +02:00
|
|
|
{
|
|
|
|
|
QJsonObject watcher;
|
2016-06-07 17:04:53 +02:00
|
|
|
watcher.insert("iname", iname);
|
|
|
|
|
watcher.insert("exp", toHex(exp));
|
2015-09-14 13:40:35 +02:00
|
|
|
return watcher;
|
2015-02-12 11:31:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-14 12:53:35 +02:00
|
|
|
void WatchHandler::appendWatchersAndTooltipRequests(DebuggerCommand *cmd)
|
|
|
|
|
{
|
2015-09-14 13:40:35 +02:00
|
|
|
QJsonArray watchers;
|
2015-09-14 12:53:35 +02:00
|
|
|
DebuggerToolTipContexts toolTips = DebuggerToolTipManager::pendingTooltips(m_model->m_engine);
|
2015-09-14 13:40:35 +02:00
|
|
|
foreach (const DebuggerToolTipContext &p, toolTips)
|
2016-06-07 17:04:53 +02:00
|
|
|
watchers.append(watcher(p.iname, p.expression));
|
2015-09-14 12:53:35 +02:00
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QHashIterator<QString, int> it(WatchHandler::watcherNames());
|
2015-09-14 12:53:35 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
|
it.next();
|
2016-06-07 17:04:53 +02:00
|
|
|
watchers.append(watcher("watch." + QString::number(it.value()), it.key()));
|
2015-09-14 12:53:35 +02:00
|
|
|
}
|
2015-09-14 13:40:35 +02:00
|
|
|
cmd->arg("watchers", watchers);
|
2015-09-14 12:53:35 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 19:09:08 +01:00
|
|
|
void WatchHandler::addDumpers(const GdbMi &dumpers)
|
|
|
|
|
{
|
|
|
|
|
foreach (const GdbMi &dumper, dumpers.children()) {
|
2015-03-20 16:03:59 +01:00
|
|
|
DisplayFormats formats;
|
|
|
|
|
formats.append(RawFormat);
|
2016-06-07 17:04:53 +02:00
|
|
|
QString reportedFormats = dumper["formats"].data();
|
|
|
|
|
foreach (const QString &format, reportedFormats.split(',')) {
|
2015-03-20 16:03:59 +01:00
|
|
|
if (int f = format.toInt())
|
|
|
|
|
formats.append(DisplayFormat(f));
|
2015-01-23 19:09:08 +01:00
|
|
|
}
|
|
|
|
|
addTypeFormats(dumper["type"].data(), formats);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void WatchHandler::addTypeFormats(const QString &type, const DisplayFormats &formats)
|
2010-06-25 09:07:14 +02:00
|
|
|
{
|
2016-06-07 17:04:53 +02:00
|
|
|
m_model->m_reportedTypeFormats.insert(stripForFormat(type), formats);
|
2010-06-25 09:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
QString WatchModel::editorContents(const QModelIndexList &list)
|
2010-09-08 09:09:09 +02:00
|
|
|
{
|
|
|
|
|
QString contents;
|
2015-03-19 12:42:53 +01:00
|
|
|
QTextStream ts(&contents);
|
2016-07-18 12:36:31 +02:00
|
|
|
forAllItems([&ts, this, list](WatchItem *item) {
|
|
|
|
|
if (list.isEmpty() || list.contains(indexForItem(item))) {
|
2016-06-03 17:02:23 +02:00
|
|
|
const QChar tab = QLatin1Char('\t');
|
2016-06-07 17:04:53 +02:00
|
|
|
const QChar nl = '\n';
|
2016-06-03 17:02:23 +02:00
|
|
|
ts << QString(item->level(), tab) << item->name << tab << displayValue(item) << tab
|
|
|
|
|
<< item->type << nl;
|
|
|
|
|
}
|
2016-05-27 11:12:03 +02:00
|
|
|
});
|
2010-11-05 19:38:40 +01:00
|
|
|
return contents;
|
2010-09-08 09:09:09 +02:00
|
|
|
}
|
|
|
|
|
|
2012-01-17 18:44:02 +01:00
|
|
|
void WatchHandler::scheduleResetLocation()
|
|
|
|
|
{
|
2015-03-20 13:18:36 +01:00
|
|
|
m_model->m_contentsValid = false;
|
2012-01-17 18:44:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WatchHandler::resetLocation()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
void WatchHandler::setCurrentItem(const QString &iname)
|
2012-04-18 14:20:54 +02:00
|
|
|
{
|
2015-03-20 13:18:36 +01:00
|
|
|
if (WatchItem *item = m_model->findItem(iname)) {
|
2015-04-22 12:37:39 +02:00
|
|
|
QModelIndex idx = m_model->indexForItem(item);
|
2015-03-20 13:18:36 +01:00
|
|
|
emit m_model->currentIndexRequested(idx);
|
|
|
|
|
}
|
2012-04-18 14:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QHash<QString, int> WatchHandler::watcherNames()
|
2012-03-14 12:26:27 +01:00
|
|
|
{
|
|
|
|
|
return theWatcherNames;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
bool WatchHandler::isExpandedIName(const QString &iname) const
|
2012-05-18 02:28:41 +02:00
|
|
|
{
|
|
|
|
|
return m_model->m_expandedINames.contains(iname);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 17:04:53 +02:00
|
|
|
QSet<QString> WatchHandler::expandedINames() const
|
2012-05-18 02:28:41 +02:00
|
|
|
{
|
|
|
|
|
return m_model->m_expandedINames;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-05 13:27:24 +02:00
|
|
|
void WatchHandler::recordTypeInfo(const GdbMi &typeInfo)
|
|
|
|
|
{
|
|
|
|
|
if (typeInfo.type() == GdbMi::List) {
|
|
|
|
|
foreach (const GdbMi &s, typeInfo.children()) {
|
2016-06-07 17:04:53 +02:00
|
|
|
QString typeName = fromHex(s["name"].data());
|
2016-04-05 13:27:24 +02:00
|
|
|
TypeInfo ti(s["size"].data().toUInt());
|
|
|
|
|
m_model->m_reportedTypeInfo.insert(typeName, ti);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 12:36:31 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// WatchDelegate
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class WatchDelegate : public QItemDelegate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
|
|
|
|
|
const QModelIndex &index) const override
|
|
|
|
|
{
|
|
|
|
|
const WatchModelBase *model = qobject_cast<const WatchModelBase *>(index.model());
|
|
|
|
|
QTC_ASSERT(model, return 0);
|
|
|
|
|
|
|
|
|
|
WatchItem *item = model->nonRootItemForIndex(index);
|
|
|
|
|
QTC_ASSERT(item, return 0);
|
|
|
|
|
|
|
|
|
|
// Value column: Custom editor. Apply integer-specific settings.
|
|
|
|
|
if (index.column() == 1) {
|
|
|
|
|
QVariant::Type editType = QVariant::Type(item->editType());
|
|
|
|
|
if (editType == QVariant::Bool)
|
|
|
|
|
return new BooleanComboBox(parent);
|
|
|
|
|
|
|
|
|
|
WatchLineEdit *edit = WatchLineEdit::create(editType, parent);
|
|
|
|
|
edit->setFrame(false);
|
|
|
|
|
|
|
|
|
|
if (auto intEdit = qobject_cast<IntegerWatchLineEdit *>(edit)) {
|
|
|
|
|
if (isPointerType(item->type))
|
|
|
|
|
intEdit->setBase(16); // Pointers using 0x-convention
|
|
|
|
|
else
|
|
|
|
|
intEdit->setBase(formatToIntegerBase(itemFormat(item)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return edit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Standard line edits for the rest.
|
|
|
|
|
auto lineEdit = new FancyLineEdit(parent);
|
|
|
|
|
lineEdit->setFrame(false);
|
|
|
|
|
lineEdit->setHistoryCompleter("WatchItems");
|
|
|
|
|
return lineEdit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
|
|
|
|
|
const QModelIndex &) const override
|
|
|
|
|
{
|
|
|
|
|
editor->setGeometry(option.rect);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static QVariant createItemDelegate()
|
|
|
|
|
{
|
|
|
|
|
return QVariant::fromValue(static_cast<QAbstractItemDelegate *>(new WatchDelegate));
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-17 16:00:03 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|
2016-11-22 14:55:47 +01:00
|
|
|
|
|
|
|
|
#include "watchhandler.moc"
|