2018-06-22 08:45:00 +00:00
|
|
|
#include "BreakpointWidget.h"
|
|
|
|
#include "ui_BreakpointWidget.h"
|
2018-06-26 07:38:44 +00:00
|
|
|
#include "dialogs/BreakpointsDialog.h"
|
2018-06-22 08:45:00 +00:00
|
|
|
#include "MainWindow.h"
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/Helpers.h"
|
2018-06-22 08:45:00 +00:00
|
|
|
#include <QMenu>
|
|
|
|
|
|
|
|
BreakpointModel::BreakpointModel(QList<BreakpointDescription> *breakpoints, QObject *parent)
|
|
|
|
: QAbstractListModel(parent),
|
|
|
|
breakpoints(breakpoints)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int BreakpointModel::rowCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return breakpoints->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int BreakpointModel::columnCount(const QModelIndex &) const
|
|
|
|
{
|
|
|
|
return BreakpointModel::ColumnCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant BreakpointModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
if (index.row() >= breakpoints->count())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
const BreakpointDescription &breakpoint = breakpoints->at(index.row());
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (index.column()) {
|
|
|
|
case AddrColumn:
|
|
|
|
return RAddressString(breakpoint.addr);
|
|
|
|
case PermColumn:
|
|
|
|
return breakpoint.permission;
|
|
|
|
case HwColumn:
|
|
|
|
return breakpoint.hw;
|
|
|
|
case TraceColumn:
|
|
|
|
return breakpoint.trace;
|
|
|
|
case EnabledColumn:
|
|
|
|
return breakpoint.enabled;
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
case BreakpointDescriptionRole:
|
|
|
|
return QVariant::fromValue(breakpoint);
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant BreakpointModel::headerData(int section, Qt::Orientation, int role) const
|
|
|
|
{
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
switch (section) {
|
|
|
|
case AddrColumn:
|
|
|
|
return tr("Offset");
|
|
|
|
case PermColumn:
|
|
|
|
return tr("Permissions");
|
|
|
|
case HwColumn:
|
|
|
|
return tr("Hardware bp");
|
|
|
|
case TraceColumn:
|
|
|
|
return tr("Tracing");
|
|
|
|
case EnabledColumn:
|
|
|
|
return tr("Active");
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointProxyModel::BreakpointProxyModel(BreakpointModel *sourceModel, QObject *parent)
|
|
|
|
: QSortFilterProxyModel(parent)
|
|
|
|
{
|
|
|
|
setSourceModel(sourceModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BreakpointProxyModel::filterAcceptsRow(int row, const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
QModelIndex index = sourceModel()->index(row, 0, parent);
|
2018-09-30 20:00:53 +00:00
|
|
|
BreakpointDescription item = index.data(
|
|
|
|
BreakpointModel::BreakpointDescriptionRole).value<BreakpointDescription>();
|
2018-06-22 08:45:00 +00:00
|
|
|
return item.permission.contains(filterRegExp());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BreakpointProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
{
|
2018-09-30 20:00:53 +00:00
|
|
|
BreakpointDescription leftBreakpt = left.data(
|
|
|
|
BreakpointModel::BreakpointDescriptionRole).value<BreakpointDescription>();
|
|
|
|
BreakpointDescription rightBreakpt = right.data(
|
|
|
|
BreakpointModel::BreakpointDescriptionRole).value<BreakpointDescription>();
|
2018-06-22 08:45:00 +00:00
|
|
|
|
|
|
|
switch (left.column()) {
|
|
|
|
case BreakpointModel::AddrColumn:
|
|
|
|
return leftBreakpt.addr < rightBreakpt.addr;
|
|
|
|
case BreakpointModel::HwColumn:
|
|
|
|
return leftBreakpt.hw < rightBreakpt.hw;
|
|
|
|
case BreakpointModel::PermColumn:
|
|
|
|
return leftBreakpt.permission < rightBreakpt.permission;
|
|
|
|
case BreakpointModel::EnabledColumn:
|
|
|
|
return leftBreakpt.enabled < rightBreakpt.enabled;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return leftBreakpt.addr < rightBreakpt.addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointWidget::BreakpointWidget(MainWindow *main, QAction *action) :
|
|
|
|
CutterDockWidget(main, action),
|
|
|
|
ui(new Ui::BreakpointWidget)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
breakpointModel = new BreakpointModel(&breakpoints, this);
|
|
|
|
breakpointProxyModel = new BreakpointProxyModel(breakpointModel, this);
|
|
|
|
ui->breakpointTreeView->setModel(breakpointProxyModel);
|
|
|
|
ui->breakpointTreeView->sortByColumn(BreakpointModel::AddrColumn, Qt::AscendingOrder);
|
|
|
|
|
|
|
|
setScrollMode();
|
|
|
|
actionDelBreakpoint = new QAction(tr("Delete breakpoint"));
|
|
|
|
actionToggleBreakpoint = new QAction(tr("Toggle breakpoint"));
|
|
|
|
connect(actionDelBreakpoint, &QAction::triggered, this, &BreakpointWidget::delBreakpoint);
|
|
|
|
connect(actionToggleBreakpoint, &QAction::triggered, this, &BreakpointWidget::toggleBreakpoint);
|
|
|
|
connect(Core(), &CutterCore::refreshAll, this, &BreakpointWidget::refreshBreakpoint);
|
|
|
|
connect(Core(), &CutterCore::breakpointsChanged, this, &BreakpointWidget::refreshBreakpoint);
|
2018-07-01 21:29:38 +00:00
|
|
|
connect(Core(), &CutterCore::refreshCodeViews, this, &BreakpointWidget::refreshBreakpoint);
|
2018-06-26 07:38:44 +00:00
|
|
|
connect(ui->addBreakpoint, &QAbstractButton::clicked, this, &BreakpointWidget::addBreakpointDialog);
|
|
|
|
connect(ui->delBreakpoint, &QAbstractButton::clicked, this, &BreakpointWidget::delBreakpoint);
|
2018-06-22 08:45:00 +00:00
|
|
|
connect(ui->delAllBreakpoints, &QAbstractButton::clicked, Core(), &CutterCore::delAllBreakpoints);
|
|
|
|
ui->breakpointTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(ui->breakpointTreeView, SIGNAL(customContextMenuRequested(const QPoint &)),
|
2018-09-30 20:00:53 +00:00
|
|
|
this, SLOT(showBreakpointContextMenu(const QPoint &)));
|
2018-06-22 08:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointWidget::~BreakpointWidget() {}
|
|
|
|
|
|
|
|
void BreakpointWidget::refreshBreakpoint()
|
|
|
|
{
|
2018-10-10 11:33:55 +00:00
|
|
|
breakpointModel->beginResetModel();
|
2018-06-22 08:45:00 +00:00
|
|
|
breakpoints = Core()->getBreakpoints();
|
2018-10-10 11:33:55 +00:00
|
|
|
breakpointModel->endResetModel();
|
2018-06-22 08:45:00 +00:00
|
|
|
|
|
|
|
ui->breakpointTreeView->resizeColumnToContents(0);
|
|
|
|
ui->breakpointTreeView->resizeColumnToContents(1);
|
|
|
|
ui->breakpointTreeView->resizeColumnToContents(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::setScrollMode()
|
|
|
|
{
|
|
|
|
qhelpers::setVerticalScrollMode(ui->breakpointTreeView);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::on_breakpointTreeView_doubleClicked(const QModelIndex &index)
|
|
|
|
{
|
2018-09-30 20:00:53 +00:00
|
|
|
BreakpointDescription item = index.data(
|
|
|
|
BreakpointModel::BreakpointDescriptionRole).value<BreakpointDescription>();
|
2018-06-22 08:45:00 +00:00
|
|
|
Core()->seek(item.addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::showBreakpointContextMenu(const QPoint &pt)
|
|
|
|
{
|
|
|
|
QMenu *menu = new QMenu(ui->breakpointTreeView);
|
|
|
|
menu->clear();
|
|
|
|
menu->addAction(actionDelBreakpoint);
|
|
|
|
menu->addAction(actionToggleBreakpoint);
|
|
|
|
|
2018-07-24 23:13:16 +00:00
|
|
|
menu->exec(ui->breakpointTreeView->viewport()->mapToGlobal(pt));
|
2018-06-22 08:45:00 +00:00
|
|
|
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
|
|
delete menu;
|
|
|
|
}
|
|
|
|
|
2018-06-26 07:38:44 +00:00
|
|
|
void BreakpointWidget::addBreakpointDialog()
|
|
|
|
{
|
|
|
|
BreakpointsDialog *dialog = new BreakpointsDialog(this);
|
|
|
|
|
|
|
|
if (dialog->exec()) {
|
|
|
|
QString bps = dialog->getBreakpoints();
|
|
|
|
if (!bps.isEmpty()) {
|
2018-11-26 22:34:34 +00:00
|
|
|
QStringList bpList = bps.split(' ', QString::SkipEmptyParts);
|
|
|
|
for (const QString &bp : bpList) {
|
2018-07-17 07:26:20 +00:00
|
|
|
Core()->toggleBreakpoint(bp);
|
2018-06-26 07:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 08:45:00 +00:00
|
|
|
void BreakpointWidget::delBreakpoint()
|
|
|
|
{
|
|
|
|
BreakpointDescription bp = ui->breakpointTreeView->selectionModel()->currentIndex().data(
|
2018-09-30 20:00:53 +00:00
|
|
|
BreakpointModel::BreakpointDescriptionRole).value<BreakpointDescription>();
|
2018-06-22 08:45:00 +00:00
|
|
|
Core()->delBreakpoint(bp.addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointWidget::toggleBreakpoint()
|
|
|
|
{
|
|
|
|
BreakpointDescription bp = ui->breakpointTreeView->selectionModel()->currentIndex().data(
|
2018-09-30 20:00:53 +00:00
|
|
|
BreakpointModel::BreakpointDescriptionRole).value<BreakpointDescription>();
|
2018-06-22 08:45:00 +00:00
|
|
|
if (bp.enabled) {
|
|
|
|
Core()->disableBreakpoint(bp.addr);
|
|
|
|
} else {
|
|
|
|
Core()->enableBreakpoint(bp.addr);
|
|
|
|
}
|
2018-10-10 11:33:55 +00:00
|
|
|
}
|