2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "registerwindow.h"
|
|
|
|
|
|
2009-03-24 14:41:15 +01:00
|
|
|
#include "debuggeractions.h"
|
2010-11-05 13:35:31 +01:00
|
|
|
#include "debuggerplugin.h"
|
|
|
|
|
#include "debuggeragents.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "debuggerconstants.h"
|
2010-11-05 13:35:31 +01:00
|
|
|
#include "debuggerengine.h"
|
|
|
|
|
#include "registerhandler.h"
|
2010-09-22 17:30:22 +02:00
|
|
|
#include "watchdelegatewidgets.h"
|
|
|
|
|
|
2009-08-18 08:34:48 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <utils/savedaction.h>
|
2009-08-18 08:34:48 +02:00
|
|
|
|
2009-03-24 14:41:15 +01:00
|
|
|
#include <QtCore/QDebug>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QHeaderView>
|
2009-08-18 08:34:48 +02:00
|
|
|
#include <QtGui/QItemDelegate>
|
2009-03-24 14:41:15 +01:00
|
|
|
#include <QtGui/QMenu>
|
2009-08-18 08:34:48 +02:00
|
|
|
#include <QtGui/QPainter>
|
2009-03-24 14:41:15 +01:00
|
|
|
#include <QtGui/QResizeEvent>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-11-05 13:35:31 +01:00
|
|
|
|
2009-08-18 08:34:48 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-11-05 13:35:31 +01:00
|
|
|
static DebuggerEngine *currentEngine()
|
|
|
|
|
{
|
|
|
|
|
return DebuggerPlugin::instance()->currentEngine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RegisterHandler *currentHandler()
|
|
|
|
|
{
|
|
|
|
|
DebuggerEngine *engine = currentEngine();
|
|
|
|
|
QTC_ASSERT(engine, return 0);
|
|
|
|
|
return engine->registerHandler();
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-18 08:34:48 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// RegisterDelegate
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class RegisterDelegate : public QItemDelegate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-11-05 13:35:31 +01:00
|
|
|
RegisterDelegate(QObject *parent)
|
|
|
|
|
: QItemDelegate(parent)
|
2009-08-18 08:34:48 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
|
2010-09-22 17:30:22 +02:00
|
|
|
const QModelIndex &index) const
|
2009-08-18 08:34:48 +02:00
|
|
|
{
|
2010-11-05 13:35:31 +01:00
|
|
|
Register reg = currentHandler()->registerAt(index.row());
|
2010-09-22 17:30:22 +02:00
|
|
|
IntegerWatchLineEdit *lineEdit = new IntegerWatchLineEdit(parent);
|
2010-11-05 13:35:31 +01:00
|
|
|
const int base = currentHandler()->numberBase();
|
|
|
|
|
const bool big = reg.value.size() > 16;
|
|
|
|
|
// Big integers are assumed to be hexadecimal.
|
|
|
|
|
lineEdit->setBigInt(big);
|
|
|
|
|
lineEdit->setBase(big ? 16 : base);
|
2010-09-22 17:30:22 +02:00
|
|
|
lineEdit->setSigned(false);
|
2009-08-18 08:34:48 +02:00
|
|
|
lineEdit->setAlignment(Qt::AlignRight);
|
|
|
|
|
return lineEdit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const
|
|
|
|
|
{
|
2010-09-22 17:30:22 +02:00
|
|
|
IntegerWatchLineEdit *lineEdit = qobject_cast<IntegerWatchLineEdit *>(editor);
|
2009-08-18 08:34:48 +02:00
|
|
|
QTC_ASSERT(lineEdit, return);
|
2010-09-22 17:30:22 +02:00
|
|
|
lineEdit->setModelData(index.data(Qt::EditRole));
|
2009-08-18 08:34:48 +02:00
|
|
|
}
|
|
|
|
|
|
2010-11-05 13:35:31 +01:00
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *,
|
|
|
|
|
const QModelIndex &index) const
|
2009-08-18 08:34:48 +02:00
|
|
|
{
|
2010-09-22 17:30:22 +02:00
|
|
|
if (index.column() != 1)
|
|
|
|
|
return;
|
|
|
|
|
IntegerWatchLineEdit *lineEdit = qobject_cast<IntegerWatchLineEdit*>(editor);
|
2009-08-18 08:34:48 +02:00
|
|
|
QTC_ASSERT(lineEdit, return);
|
2010-11-05 13:35:31 +01:00
|
|
|
currentEngine()->setRegisterValue(index.row(), lineEdit->text());
|
2009-08-18 08:34:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
|
|
|
|
|
const QModelIndex &) const
|
|
|
|
|
{
|
|
|
|
|
editor->setGeometry(option.rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
|
|
|
const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (index.column() == 1) {
|
2010-11-05 13:35:31 +01:00
|
|
|
bool paintRed = currentHandler()->registerAt(index.row()).changed;
|
2009-09-28 11:52:00 +02:00
|
|
|
QPen oldPen = painter->pen();
|
|
|
|
|
if (paintRed)
|
|
|
|
|
painter->setPen(QColor(200, 0, 0));
|
2009-08-18 08:34:48 +02:00
|
|
|
// FIXME: performance? this changes only on real font changes.
|
|
|
|
|
QFontMetrics fm(option.font);
|
|
|
|
|
int charWidth = fm.width(QLatin1Char('x'));
|
|
|
|
|
for (int i = '1'; i <= '9'; ++i)
|
|
|
|
|
charWidth = qMax(charWidth, fm.width(QLatin1Char(i)));
|
|
|
|
|
for (int i = 'a'; i <= 'f'; ++i)
|
|
|
|
|
charWidth = qMax(charWidth, fm.width(QLatin1Char(i)));
|
2009-09-28 11:52:00 +02:00
|
|
|
QString str = index.data(Qt::DisplayRole).toString();
|
2009-08-18 08:34:48 +02:00
|
|
|
int x = option.rect.x();
|
|
|
|
|
for (int i = 0; i < str.size(); ++i) {
|
|
|
|
|
QRect r = option.rect;
|
|
|
|
|
r.setX(x);
|
|
|
|
|
r.setWidth(charWidth);
|
|
|
|
|
x += charWidth;
|
|
|
|
|
painter->drawText(r, Qt::AlignHCenter, QString(str.at(i)));
|
|
|
|
|
}
|
2009-09-28 11:52:00 +02:00
|
|
|
if (paintRed)
|
|
|
|
|
painter->setPen(oldPen);
|
2009-08-18 08:34:48 +02:00
|
|
|
} else {
|
|
|
|
|
QItemDelegate::paint(painter, option, index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// RegisterWindow
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
RegisterWindow::RegisterWindow(QWidget *parent)
|
|
|
|
|
: QTreeView(parent), m_alwaysResizeColumnsToContents(true)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-05-05 10:14:35 +02:00
|
|
|
QAction *act = theDebuggerAction(UseAlternatingRowColors);
|
2010-09-09 12:41:03 +02:00
|
|
|
setFrameStyle(QFrame::NoFrame);
|
2008-12-02 12:01:29 +01:00
|
|
|
setWindowTitle(tr("Registers"));
|
2010-04-16 11:39:36 +02:00
|
|
|
setAttribute(Qt::WA_MacShowFocusRect, false);
|
2009-05-05 10:14:35 +02:00
|
|
|
setAlternatingRowColors(act->isChecked());
|
2008-12-02 12:01:29 +01:00
|
|
|
setRootIsDecorated(false);
|
2010-11-05 13:35:31 +01:00
|
|
|
setItemDelegate(new RegisterDelegate(this));
|
2009-05-05 10:14:35 +02:00
|
|
|
|
|
|
|
|
connect(act, SIGNAL(toggled(bool)),
|
2010-11-05 13:35:31 +01:00
|
|
|
SLOT(setAlternatingRowColorsHelper(bool)));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RegisterWindow::resizeEvent(QResizeEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
QTreeView::resizeEvent(ev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RegisterWindow::contextMenuEvent(QContextMenuEvent *ev)
|
|
|
|
|
{
|
|
|
|
|
QMenu menu;
|
|
|
|
|
|
2010-11-05 13:35:31 +01:00
|
|
|
DebuggerEngine *engine = currentEngine();
|
|
|
|
|
QTC_ASSERT(engine, return);
|
|
|
|
|
RegisterHandler *handler = currentHandler();
|
|
|
|
|
const unsigned engineCapabilities = engine->debuggerCapabilities();
|
|
|
|
|
const bool actionsEnabled = engine->debuggerActionsEnabled();
|
|
|
|
|
const int state = engine->state();
|
2010-02-05 10:23:55 +01:00
|
|
|
|
2010-02-12 10:52:09 +01:00
|
|
|
QAction *actReload = menu.addAction(tr("Reload Register Listing"));
|
2010-02-11 10:52:06 +01:00
|
|
|
actReload->setEnabled((engineCapabilities & RegisterCapability)
|
2010-07-09 17:07:59 +02:00
|
|
|
&& (state == InferiorStopOk || state == InferiorUnrunnable));
|
2010-02-05 10:23:55 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
menu.addSeparator();
|
|
|
|
|
|
2009-08-14 13:04:05 +02:00
|
|
|
QModelIndex idx = indexAt(ev->pos());
|
2010-11-05 13:35:31 +01:00
|
|
|
QString address = handler->registers().at(idx.row()).value;
|
2009-08-14 13:04:05 +02:00
|
|
|
QAction *actShowMemory = menu.addAction(QString());
|
|
|
|
|
if (address.isEmpty()) {
|
2010-02-12 10:52:09 +01:00
|
|
|
actShowMemory->setText(tr("Open Memory Editor"));
|
2009-08-14 13:04:05 +02:00
|
|
|
actShowMemory->setEnabled(false);
|
|
|
|
|
} else {
|
2010-02-12 10:52:09 +01:00
|
|
|
actShowMemory->setText(tr("Open Memory Editor at %1").arg(address));
|
2010-02-11 10:52:06 +01:00
|
|
|
actShowMemory->setEnabled(actionsEnabled
|
|
|
|
|
&& (engineCapabilities & ShowMemoryCapability));
|
2009-08-14 13:04:05 +02:00
|
|
|
}
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
|
2010-11-05 13:35:31 +01:00
|
|
|
const int base = handler->numberBase();
|
2009-08-13 16:16:19 +02:00
|
|
|
QAction *act16 = menu.addAction(tr("Hexadecimal"));
|
|
|
|
|
act16->setCheckable(true);
|
|
|
|
|
act16->setChecked(base == 16);
|
|
|
|
|
QAction *act10 = menu.addAction(tr("Decimal"));
|
|
|
|
|
act10->setCheckable(true);
|
|
|
|
|
act10->setChecked(base == 10);
|
|
|
|
|
QAction *act8 = menu.addAction(tr("Octal"));
|
|
|
|
|
act8->setCheckable(true);
|
|
|
|
|
act8->setChecked(base == 8);
|
|
|
|
|
QAction *act2 = menu.addAction(tr("Binary"));
|
|
|
|
|
act2->setCheckable(true);
|
|
|
|
|
act2->setChecked(base == 2);
|
2009-03-24 14:41:15 +01:00
|
|
|
menu.addSeparator();
|
2009-08-13 16:16:19 +02:00
|
|
|
|
2010-02-12 10:52:09 +01:00
|
|
|
QAction *actAdjust = menu.addAction(tr("Adjust Column Widths to Contents"));
|
2009-08-18 16:46:33 +02:00
|
|
|
QAction *actAlwaysAdjust =
|
2010-02-12 10:52:09 +01:00
|
|
|
menu.addAction(tr("Always Adjust Column Widths to Contents"));
|
2009-08-18 16:46:33 +02:00
|
|
|
actAlwaysAdjust->setCheckable(true);
|
|
|
|
|
actAlwaysAdjust->setChecked(m_alwaysResizeColumnsToContents);
|
|
|
|
|
menu.addSeparator();
|
|
|
|
|
|
2009-03-24 14:41:15 +01:00
|
|
|
menu.addAction(theDebuggerAction(SettingsDialog));
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QAction *act = menu.exec(ev->globalPos());
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-08-13 16:16:19 +02:00
|
|
|
if (act == actAdjust)
|
2008-12-02 12:01:29 +01:00
|
|
|
resizeColumnsToContents();
|
2009-08-13 16:16:19 +02:00
|
|
|
else if (act == actAlwaysAdjust)
|
2008-12-02 12:01:29 +01:00
|
|
|
setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents);
|
2009-08-13 16:16:19 +02:00
|
|
|
else if (act == actReload)
|
2010-11-05 13:35:31 +01:00
|
|
|
engine->reloadRegisters();
|
2009-08-14 13:04:05 +02:00
|
|
|
else if (act == actShowMemory)
|
2010-11-05 13:35:31 +01:00
|
|
|
(void) new MemoryViewAgent(engine, address);
|
|
|
|
|
else if (act == act16)
|
|
|
|
|
handler->setNumberBase(16);
|
|
|
|
|
else if (act == act10)
|
|
|
|
|
handler->setNumberBase(10);
|
|
|
|
|
else if (act == act8)
|
|
|
|
|
handler->setNumberBase(8);
|
|
|
|
|
else if (act == act2)
|
|
|
|
|
handler->setNumberBase(2);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RegisterWindow::resizeColumnsToContents()
|
|
|
|
|
{
|
|
|
|
|
resizeColumnToContents(0);
|
|
|
|
|
resizeColumnToContents(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RegisterWindow::setAlwaysResizeColumnsToContents(bool on)
|
|
|
|
|
{
|
|
|
|
|
m_alwaysResizeColumnsToContents = on;
|
|
|
|
|
QHeaderView::ResizeMode mode = on
|
|
|
|
|
? QHeaderView::ResizeToContents : QHeaderView::Interactive;
|
|
|
|
|
header()->setResizeMode(0, mode);
|
|
|
|
|
header()->setResizeMode(1, mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RegisterWindow::setModel(QAbstractItemModel *model)
|
|
|
|
|
{
|
|
|
|
|
QTreeView::setModel(model);
|
|
|
|
|
setAlwaysResizeColumnsToContents(true);
|
|
|
|
|
}
|
2009-08-18 08:34:48 +02:00
|
|
|
|
2010-06-16 11:08:54 +02:00
|
|
|
void RegisterWindow::reloadRegisters()
|
|
|
|
|
{
|
|
|
|
|
// FIXME: Only trigger when becoming visible?
|
2010-11-05 13:35:31 +01:00
|
|
|
currentEngine()->reloadRegisters();
|
2010-06-16 11:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
2009-08-18 08:34:48 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|