From d96150528d4a0fe3907575dd27c1804e06056b5b Mon Sep 17 00:00:00 2001 From: mandlebro Date: Wed, 3 Oct 2018 12:30:12 +0100 Subject: [PATCH] Debug toolbar update --- src/Cutter.cpp | 2 +- src/MainWindow.cpp | 4 +-- src/widgets/BacktraceWidget.cpp | 1 + src/widgets/DebugToolbar.cpp | 44 ++++++++++++++++++++++++++++----- src/widgets/DebugToolbar.h | 3 +++ 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 3be26b64..fb2ac2e7 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -906,7 +906,7 @@ void CutterCore::startEmulation() emit registersChanged(); if (!currentlyDebugging || !currentlyEmulating) { // prevent register flags from appearing during debug/emul - // setConfig("asm.flags", false); + setConfig("asm.flags", false); // allows to view self-modifying code changes or other binary changes setConfig("io.cache", true); currentlyDebugging = true; diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 09a2f8ab..8918e9c1 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -132,9 +132,9 @@ void MainWindow::initUI() DebugToolbar *debugToolbar = new DebugToolbar(this); ui->mainToolBar->addWidget(debugToolbar); // Debug menu - ui->menuDebug->addAction(debugToolbar->actionStart); + // ui->menuDebug->addAction(debugToolbar->actionStart); ui->menuDebug->addAction(debugToolbar->actionStartEmul); - ui->menuDebug->addAction(debugToolbar->actionAttach); + // ui->menuDebug->addAction(debugToolbar->actionAttach); ui->menuDebug->addSeparator(); ui->menuDebug->addAction(debugToolbar->actionStep); ui->menuDebug->addAction(debugToolbar->actionStepOver); diff --git a/src/widgets/BacktraceWidget.cpp b/src/widgets/BacktraceWidget.cpp index ecc1039f..9fcb04e4 100644 --- a/src/widgets/BacktraceWidget.cpp +++ b/src/widgets/BacktraceWidget.cpp @@ -20,6 +20,7 @@ BacktraceWidget::BacktraceWidget(MainWindow *main, QAction *action) : modelBacktrace->setHorizontalHeaderItem(4, new QStandardItem(tr("Frame Size"))); viewBacktrace->setFont(Config()->getFont()); viewBacktrace->setModel(modelBacktrace); + viewBacktrace->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); ui->verticalLayout->addWidget(viewBacktrace); connect(Core(), &CutterCore::refreshAll, this, &BacktraceWidget::updateContents); diff --git a/src/widgets/DebugToolbar.cpp b/src/widgets/DebugToolbar.cpp index 32bf3de3..6d91a971 100644 --- a/src/widgets/DebugToolbar.cpp +++ b/src/widgets/DebugToolbar.cpp @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) : @@ -13,6 +13,9 @@ DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) : main(main) { setObjectName("debugToolbar"); + setIconSize(QSize(20, 20)); + + // define icons QIcon startDebugIcon = QIcon(":/img/icons/play_light_debug.svg"); QIcon startEmulIcon = QIcon(":/img/icons/play_light_emul.svg"); QIcon startAttachIcon = QIcon(":/img/icons/play_light_attach.svg"); @@ -24,7 +27,9 @@ DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) : QIcon stepIcon = QIcon(":/img/icons/step_light.svg"); QIcon stepOverIcon = QIcon(":/img/icons/step_over_light.svg"); QIcon stepOutIcon = QIcon(":/img/icons/step_out_light.svg"); + QIcon restartIcon = QIcon(":/img/icons/spin_light.svg"); + // define actions actionStart = new QAction(startDebugIcon, tr("Start debug"), parent); actionStart->setShortcut(QKeySequence(Qt::Key_F9)); actionStartEmul = new QAction(startEmulIcon, tr("Start emulation"), parent); @@ -47,10 +52,12 @@ DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) : startButton->setPopupMode(QToolButton::MenuButtonPopup); connect(startButton, &QToolButton::triggered, startButton, &QToolButton::setDefaultAction); QMenu *startMenu = new QMenu; + + // only emulation is currently allowed // startMenu->addAction(actionStart); - startMenu->addAction(actionStartEmul); // startMenu->addAction(actionAttach); // startButton->setDefaultAction(actionStart); + startMenu->addAction(actionStartEmul); startButton->setDefaultAction(actionStartEmul); startButton->setMenu(startMenu); @@ -65,14 +72,19 @@ DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) : continueUntilButton->setMenu(continueUntilMenu); continueUntilButton->setDefaultAction(actionContinueUntilMain); + // define toolbar widgets and actions addWidget(startButton); addAction(actionStop); addAction(actionContinue); - addWidget(continueUntilButton); + actionAllContinues = addWidget(continueUntilButton); addAction(actionStep); addAction(actionStepOver); addAction(actionStepOut); + allActions = {actionStop, actionAllContinues, actionContinue, actionContinueUntilCall, actionContinueUntilMain, actionContinueUntilSyscall, actionStep, actionStepOut, actionStepOver}; + // hide allactions + setAllActionsVisible(false); + connect(actionStop, &QAction::triggered, Core(), &CutterCore::stopDebug); connect(actionStop, &QAction::triggered, [ = ]() { actionContinue->setVisible(true); @@ -82,11 +94,18 @@ DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) : actionContinueUntilMain->setVisible(true); actionStepOut->setVisible(true); this->colorToolbar(false); - actionStop->setText("Stop debug"); + actionStop->setText("Stop session"); + actionStart->setText("Start debug"); + actionStartEmul->setText("Start emulation"); + actionStart->setIcon(startDebugIcon); + actionStartEmul->setIcon(startEmulIcon); colorToolbar(false); + setAllActionsVisible(false); }); connect(actionStep, &QAction::triggered, Core(), &CutterCore::stepDebug); - connect(actionStart, &QAction::triggered, [=]() { + connect(actionStart, &QAction::triggered, [ = ]() { + setAllActionsVisible(true); + QString filename = Core()->getConfig("file.path").split(" ").first(); QFileInfo info(filename); if (!Core()->currentlyDebugging && !info.isExecutable()) { @@ -98,17 +117,22 @@ DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) : colorToolbar(true); actionAttach->setVisible(false); actionStartEmul->setVisible(false); + actionStart->setText("Restart program"); + actionStart->setIcon(restartIcon); Core()->startDebug(); }); + connect(actionAttach, &QAction::triggered, this, &DebugToolbar::attachProcessDialog); connect(actionStartEmul, &QAction::triggered, Core(), &CutterCore::startEmulation); connect(actionStartEmul, &QAction::triggered, [ = ]() { - actionContinue->setVisible(false); + setAllActionsVisible(true); actionStart->setVisible(false); actionAttach->setVisible(false); actionContinueUntilMain->setVisible(false); actionStepOut->setVisible(false); continueUntilButton->setDefaultAction(actionContinueUntilSyscall); + actionStartEmul->setText("Restart emulation"); + actionStartEmul->setIcon(restartIcon); actionStop->setText("Stop emulation"); colorToolbar(true); }); @@ -158,10 +182,18 @@ void DebugToolbar::attachProcessDialog() void DebugToolbar::attachProcess(int pid) { // hide unwanted buttons + setAllActionsVisible(true); colorToolbar(true); actionStart->setVisible(false); actionStartEmul->setVisible(false); actionStop->setText("Detach from process"); // attach Core()->attachDebug(pid); +} + +void DebugToolbar::setAllActionsVisible(bool visible) +{ + for (QAction *action : allActions) { + action->setVisible(visible); + } } \ No newline at end of file diff --git a/src/widgets/DebugToolbar.h b/src/widgets/DebugToolbar.h index 4fea4604..2ff8556e 100644 --- a/src/widgets/DebugToolbar.h +++ b/src/widgets/DebugToolbar.h @@ -22,13 +22,16 @@ public: QAction *actionStepOver; QAction *actionStepOut; QAction *actionStop; + QAction *actionAllContinues; private: MainWindow *main; + QList allActions; private slots: void continueUntilMain(); void colorToolbar(bool p); void attachProcessDialog(); void attachProcess(int pid); + void setAllActionsVisible(bool visible); }; \ No newline at end of file