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"
|
2019-02-22 16:50:45 +00:00
|
|
|
#include "core/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);
|
|
|
|
|
2019-01-13 18:11:59 +00:00
|
|
|
refreshDeferrer = createRefreshDeferrer([this]() {
|
|
|
|
refreshBreakpoint();
|
|
|
|
});
|
|
|
|
|
2018-06-22 08:45:00 +00:00
|
|
|
setScrollMode();
|
2019-10-12 08:33:21 +00:00
|
|
|
|
2019-05-26 10:12:23 +00:00
|
|
|
actionDelBreakpoint = new QAction(tr("Delete breakpoint"), this);
|
2019-10-12 08:33:21 +00:00
|
|
|
actionDelBreakpoint->setShortcut(Qt::Key_Delete);
|
|
|
|
actionDelBreakpoint->setShortcutContext(Qt::WidgetShortcut);
|
2018-06-22 08:45:00 +00:00
|
|
|
connect(actionDelBreakpoint, &QAction::triggered, this, &BreakpointWidget::delBreakpoint);
|
2019-10-12 08:33:21 +00:00
|
|
|
ui->breakpointTreeView->addAction(actionDelBreakpoint);
|
|
|
|
|
|
|
|
actionToggleBreakpoint = new QAction(tr("Toggle breakpoint"), this);
|
|
|
|
actionToggleBreakpoint->setShortcut(Qt::Key_Space);
|
|
|
|
actionToggleBreakpoint->setShortcutContext(Qt::WidgetShortcut);
|
2018-06-22 08:45:00 +00:00
|
|
|
connect(actionToggleBreakpoint, &QAction::triggered, this, &BreakpointWidget::toggleBreakpoint);
|
2019-10-12 08:33:21 +00:00
|
|
|
ui->breakpointTreeView->addAction(actionToggleBreakpoint);
|
|
|
|
|
2018-06-22 08:45:00 +00:00
|
|
|
connect(Core(), &CutterCore::refreshAll, this, &BreakpointWidget::refreshBreakpoint);
|
|
|
|
connect(Core(), &CutterCore::breakpointsChanged, this, &BreakpointWidget::refreshBreakpoint);
|
2019-12-11 22:18:40 +00:00
|
|
|
connect(Core(), &CutterCore::codeRebased, 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
|
|
|
}
|
|
|
|
|
2019-01-13 18:11:59 +00:00
|
|
|
BreakpointWidget::~BreakpointWidget() = default;
|
2018-06-22 08:45:00 +00:00
|
|
|
|
|
|
|
void BreakpointWidget::refreshBreakpoint()
|
|
|
|
{
|
2019-01-13 18:11:59 +00:00
|
|
|
if (!refreshDeferrer->attemptRefresh(nullptr)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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>();
|
2019-07-19 19:21:12 +00:00
|
|
|
Core()->seekAndShow(item.addr);
|
2018-06-22 08:45:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2019-03-23 06:32:31 +00:00
|
|
|
BreakpointsDialog dialog(this);
|
2018-06-26 07:38:44 +00:00
|
|
|
|
2019-03-23 06:32:31 +00:00
|
|
|
if (dialog.exec()) {
|
|
|
|
QString bps = dialog.getBreakpoints();
|
2018-06-26 07:38:44 +00:00
|
|
|
if (!bps.isEmpty()) {
|
2019-03-23 10:54:34 +00:00
|
|
|
QStringList bpList = bps.split(QLatin1Char(' '), QString::SkipEmptyParts);
|
2018-11-26 22:34:34 +00:00
|
|
|
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
|
|
|
}
|