Added new buttons to breakpoint widget (#548)

* Added new buttons to breakpoint widget
This commit is contained in:
fcasal 2018-06-26 08:38:44 +01:00 committed by xarkes
parent 837ffef20f
commit 975e4c4a3d
11 changed files with 225 additions and 10 deletions

View File

@ -868,6 +868,13 @@ void CutterCore::addBreakpoint(RVA addr)
emit breakpointsChanged(); emit breakpointsChanged();
} }
void CutterCore::addBreakpoint(QString addr)
{
cmd("db " + addr);
emit instructionChanged(addr.toULongLong());
emit breakpointsChanged();
}
void CutterCore::delBreakpoint(RVA addr) void CutterCore::delBreakpoint(RVA addr)
{ {
cmd("db- " + RAddressString(addr)); cmd("db- " + RAddressString(addr));
@ -878,7 +885,7 @@ void CutterCore::delBreakpoint(RVA addr)
void CutterCore::delAllBreakpoints() void CutterCore::delAllBreakpoints()
{ {
cmd("db-*"); cmd("db-*");
emit breakpointsChanged(); emit deletedAllBreakpoints();
} }
void CutterCore::enableBreakpoint(RVA addr) void CutterCore::enableBreakpoint(RVA addr)

View File

@ -488,6 +488,7 @@ public:
void stepDebug(); void stepDebug();
void stepOverDebug(); void stepOverDebug();
void addBreakpoint(RVA addr); void addBreakpoint(RVA addr);
void addBreakpoint(QString addr);
void delBreakpoint(RVA addr); void delBreakpoint(RVA addr);
void delAllBreakpoints(); void delAllBreakpoints();
void enableBreakpoint(RVA addr); void enableBreakpoint(RVA addr);
@ -583,6 +584,7 @@ signals:
void registersChanged(); void registersChanged();
void instructionChanged(RVA offset); void instructionChanged(RVA offset);
void breakpointsChanged(); void breakpointsChanged();
void deletedAllBreakpoints();
void notesChanged(const QString &notes); void notesChanged(const QString &notes);
void projectSaved(const QString &name); void projectSaved(const QString &name);

View File

@ -179,7 +179,8 @@ SOURCES += \
widgets/DebugToolbar.cpp \ widgets/DebugToolbar.cpp \
widgets/MemoryMapWidget.cpp \ widgets/MemoryMapWidget.cpp \
dialogs/preferences/DebugOptionsWidget.cpp \ dialogs/preferences/DebugOptionsWidget.cpp \
widgets/BreakpointWidget.cpp widgets/BreakpointWidget.cpp \
dialogs/BreakpointsDialog.cpp
HEADERS += \ HEADERS += \
Cutter.h \ Cutter.h \
@ -270,7 +271,8 @@ HEADERS += \
widgets/DebugToolbar.h \ widgets/DebugToolbar.h \
widgets/MemoryMapWidget.h \ widgets/MemoryMapWidget.h \
dialogs/preferences/DebugOptionsWidget.h \ dialogs/preferences/DebugOptionsWidget.h \
widgets/BreakpointWidget.h widgets/BreakpointWidget.h \
dialogs/BreakpointsDialog.h
FORMS += \ FORMS += \
dialogs/AboutDialog.ui \ dialogs/AboutDialog.ui \
@ -322,7 +324,8 @@ FORMS += \
widgets/MemoryMapWidget.ui \ widgets/MemoryMapWidget.ui \
widgets/MemoryMapWidget.ui \ widgets/MemoryMapWidget.ui \
dialogs/preferences/DebugOptionsWidget.ui \ dialogs/preferences/DebugOptionsWidget.ui \
widgets/BreakpointWidget.ui widgets/BreakpointWidget.ui \
dialogs/BreakpointsDialog.ui
RESOURCES += \ RESOURCES += \
resources.qrc \ resources.qrc \

View File

@ -0,0 +1,47 @@
#include "BreakpointsDialog.h"
#include "ui_BreakpointsDialog.h"
BreakpointsDialog::BreakpointsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::BreakpointsDialog)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
// Event filter for capturing Ctrl/Cmd+Return
ui->textEdit->installEventFilter(this);
}
BreakpointsDialog::~BreakpointsDialog() {}
void BreakpointsDialog::on_buttonBox_accepted()
{
}
void BreakpointsDialog::on_buttonBox_rejected()
{
close();
}
QString BreakpointsDialog::getBreakpoints()
{
QString ret = ui->textEdit->document()->toPlainText();
return ret;
}
bool BreakpointsDialog::eventFilter(QObject *obj, QEvent *event)
{
Q_UNUSED(obj);
if (event -> type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast <QKeyEvent *> (event);
// Confirm comment by pressing Ctrl/Cmd+Return
if ((keyEvent -> modifiers() & Qt::ControlModifier) &&
((keyEvent -> key() == Qt::Key_Enter) || (keyEvent -> key() == Qt::Key_Return))) {
this->accept();
return true;
}
}
return false;
}

View File

@ -0,0 +1,28 @@
#pragma once
#include <QDialog>
#include <memory>
namespace Ui {
class BreakpointsDialog;
}
class BreakpointsDialog : public QDialog
{
Q_OBJECT
public:
explicit BreakpointsDialog(QWidget *parent = nullptr);
~BreakpointsDialog();
QString getBreakpoints();
private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
std::unique_ptr<Ui::BreakpointsDialog> ui;
bool eventFilter(QObject *obj, QEvent *event);
};

View File

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BreakpointsDialog</class>
<widget class="QDialog" name="BreakpointsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>118</height>
</rect>
</property>
<property name="windowTitle">
<string>Add breakpoints</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QPlainTextEdit" name="textEdit"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>BreakpointsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>BreakpointsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -1,5 +1,6 @@
#include "BreakpointWidget.h" #include "BreakpointWidget.h"
#include "ui_BreakpointWidget.h" #include "ui_BreakpointWidget.h"
#include "dialogs/BreakpointsDialog.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "utils/Helpers.h" #include "utils/Helpers.h"
#include <QMenu> #include <QMenu>
@ -135,6 +136,9 @@ BreakpointWidget::BreakpointWidget(MainWindow *main, QAction *action) :
connect(actionToggleBreakpoint, &QAction::triggered, this, &BreakpointWidget::toggleBreakpoint); connect(actionToggleBreakpoint, &QAction::triggered, this, &BreakpointWidget::toggleBreakpoint);
connect(Core(), &CutterCore::refreshAll, this, &BreakpointWidget::refreshBreakpoint); connect(Core(), &CutterCore::refreshAll, this, &BreakpointWidget::refreshBreakpoint);
connect(Core(), &CutterCore::breakpointsChanged, this, &BreakpointWidget::refreshBreakpoint); connect(Core(), &CutterCore::breakpointsChanged, this, &BreakpointWidget::refreshBreakpoint);
connect(Core(), &CutterCore::deletedAllBreakpoints, this, &BreakpointWidget::refreshBreakpoint);
connect(ui->addBreakpoint, &QAbstractButton::clicked, this, &BreakpointWidget::addBreakpointDialog);
connect(ui->delBreakpoint, &QAbstractButton::clicked, this, &BreakpointWidget::delBreakpoint);
connect(ui->delAllBreakpoints, &QAbstractButton::clicked, Core(), &CutterCore::delAllBreakpoints); connect(ui->delAllBreakpoints, &QAbstractButton::clicked, Core(), &CutterCore::delAllBreakpoints);
ui->breakpointTreeView->setContextMenuPolicy(Qt::CustomContextMenu); ui->breakpointTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->breakpointTreeView, SIGNAL(customContextMenuRequested(const QPoint &)), connect(ui->breakpointTreeView, SIGNAL(customContextMenuRequested(const QPoint &)),
@ -178,6 +182,21 @@ void BreakpointWidget::showBreakpointContextMenu(const QPoint &pt)
delete menu; delete menu;
} }
void BreakpointWidget::addBreakpointDialog()
{
BreakpointsDialog *dialog = new BreakpointsDialog(this);
if (dialog->exec()) {
QString bps = dialog->getBreakpoints();
if (!bps.isEmpty()) {
QStringList bpList = bps.split(" ", QString::SkipEmptyParts);
for ( QString bp : bpList) {
Core()->addBreakpoint(bp);
}
}
}
}
void BreakpointWidget::delBreakpoint() void BreakpointWidget::delBreakpoint()
{ {
BreakpointDescription bp = ui->breakpointTreeView->selectionModel()->currentIndex().data( BreakpointDescription bp = ui->breakpointTreeView->selectionModel()->currentIndex().data(

View File

@ -73,7 +73,7 @@ private slots:
void showBreakpointContextMenu(const QPoint &pt); void showBreakpointContextMenu(const QPoint &pt);
void delBreakpoint(); void delBreakpoint();
void toggleBreakpoint(); void toggleBreakpoint();
void addBreakpointDialog();
void refreshBreakpoint(); void refreshBreakpoint();
private: private:

View File

@ -51,11 +51,29 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QToolButton" name="delAllBreakpoints"> <layout class="QHBoxLayout" name="hLayout">
<property name="text"> <item>
<string>Delete all breakpoints</string> <widget class="QToolButton" name="addBreakpoint">
</property> <property name="text">
</widget> <string>Add new breakpoint</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="delBreakpoint">
<property name="text">
<string>Delete breakpoint</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignLeft">
<widget class="QToolButton" name="delAllBreakpoints">
<property name="text">
<string>Delete all breakpoints</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -36,6 +36,7 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent)
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshView())); connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(graphOptionsChanged()), this, SLOT(refreshView())); connect(Core(), SIGNAL(graphOptionsChanged()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshView())); connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshView()));
connect(Core(), SIGNAL(deletedAllBreakpoints()), this, SLOT(refreshView()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot())); connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot())); connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));

View File

@ -119,6 +119,7 @@ DisassemblyWidget::DisassemblyWidget(MainWindow *main, QAction *action)
refreshDisasm(); refreshDisasm();
} }
}); });
connect(Core(), SIGNAL(deletedAllBreakpoints()), this, SLOT(refreshDisasm()));
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot())); connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot())); connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));