From 40ce944381fb2a0e7005f8080c069eee6c4792fb Mon Sep 17 00:00:00 2001 From: mandlebro Date: Tue, 12 Jun 2018 16:42:38 +0100 Subject: [PATCH] added basic debug view and stop debug button to toolbar --- src/Cutter.cpp | 10 ++++++ src/Cutter.h | 3 ++ src/MainWindow.cpp | 57 ++++++++++++++++++++++++++++-- src/MainWindow.h | 4 +++ src/img/icons/media-stop_light.svg | 3 ++ src/resources.qrc | 3 ++ src/widgets/DebugToolbar.cpp | 4 +++ 7 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/img/icons/media-stop_light.svg diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 881a1be7..1205f11b 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -761,6 +761,16 @@ void CutterCore::startDebug() { cmd("ood"); emit registersChanged(); + emit changeDebugView(); +} + +void CutterCore::stopDebug() +{ + // @TODO should first obtain correct signal to send. + // Also, we do a ds since otherwise the process does not die. + cmd("dk 9; ds; e cfg.debug = false; oo"); + seek(tr("main")); + emit changeDefinedView(); } void CutterCore::continueDebug() diff --git a/src/Cutter.h b/src/Cutter.h index 2e6b0528..c72865de 100644 --- a/src/Cutter.h +++ b/src/Cutter.h @@ -469,6 +469,7 @@ public: QJsonDocument getStack(int size = 0x40); QJsonDocument getBacktrace(); void startDebug(); + void stopDebug(); void continueDebug(); void continueUntilDebug(QString offset); void stepDebug(); @@ -580,6 +581,8 @@ signals: void seekChanged(RVA offset); void raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType type); + void changeDefinedView(); + void changeDebugView(); public slots: diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 354095c7..e853ae87 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -250,6 +250,9 @@ void MainWindow::initUI() connect(core, SIGNAL(projectSaved(const QString &)), this, SLOT(projectSaved(const QString &))); + connect(core, &CutterCore::changeDebugView, this, &MainWindow::changeDebugView); + connect(core, &CutterCore::changeDefinedView, this, &MainWindow::changeDefinedView); + updateTasksIndicator(); connect(core->getAsyncTaskManager(), &AsyncTaskManager::tasksChanged, this, &MainWindow::updateTasksIndicator); @@ -475,11 +478,9 @@ void MainWindow::setPanelLock() void MainWindow::setTabLocation() { if (tabsOnTop) { - ui->centralTabWidget->setTabPosition(QTabWidget::North); this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::North); ui->actionTabs_on_Top->setChecked(true); } else { - ui->centralTabWidget->setTabPosition(QTabWidget::South); this->setTabPosition(Qt::AllDockWidgetAreas, QTabWidget::South); ui->actionTabs_on_Top->setChecked(false); } @@ -616,6 +617,26 @@ void MainWindow::showZenDocks() updateDockActionsChecked(); } +void MainWindow::showDebugDocks() +{ + const QList debugDocks = { functionsDock, + stringsDock, + graphDock, + disassemblyDock, + hexdumpDock, + searchDock, + stackDock, + registersDock, + backtraceDock + }; + for (auto w : dockWidgets) { + if (debugDocks.contains(w)) { + w->show(); + } + } + updateDockActionsChecked(); +} + void MainWindow::resetToDefaultLayout() { hideAllDocks(); @@ -654,6 +675,24 @@ void MainWindow::resetToZenLayout() Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly); } +void MainWindow::resetToDebugLayout() +{ + hideAllDocks(); + restoreDocks(); + showDebugDocks(); + disassemblyDock->raise(); + + // ugly workaround to set the default widths of functions + // if anyone finds a way to do this cleaner that also works, feel free to change it! + auto restoreFunctionDock = qhelpers::forceWidth(functionsDock->widget(), 200); + + qApp->processEvents(); + + restoreFunctionDock.restoreWidth(functionsDock->widget()); + + Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly); +} + void MainWindow::addOutput(const QString &msg) { consoleDock->addOutput(msg); @@ -862,6 +901,20 @@ void MainWindow::projectSaved(const QString &name) addOutput(tr("Project saved: ") + name); } +void MainWindow::changeDebugView() +{ + saveSettings(); + resetToDebugLayout(); +} + +void MainWindow::changeDefinedView() +{ + resetToDefaultLayout(); + readSettings(); + setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); + setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); +} + void MainWindow::mousePressEvent(QMouseEvent *event) { switch (event->button()) { diff --git a/src/MainWindow.h b/src/MainWindow.h index 4bd09244..1474e098 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -170,6 +170,8 @@ private slots: void mousePressEvent(QMouseEvent *event) override; bool eventFilter(QObject *object, QEvent *event); + void changeDebugView(); + void changeDefinedView(); private: CutterCore *core; @@ -230,11 +232,13 @@ private: void resetToDefaultLayout(); void resetToZenLayout(); + void resetToDebugLayout(); void restoreDocks(); void hideAllDocks(); void showDefaultDocks(); void showZenDocks(); + void showDebugDocks(); void updateDockActionsChecked(); void toggleDockWidget(QDockWidget *dock_widget, bool show); diff --git a/src/img/icons/media-stop_light.svg b/src/img/icons/media-stop_light.svg new file mode 100644 index 00000000..6c57c202 --- /dev/null +++ b/src/img/icons/media-stop_light.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/resources.qrc b/src/resources.qrc index afb799da..71bfebea 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -1,7 +1,9 @@ img/icons/arrow_left_light.svg + img/icons/arrow_left.svg img/icons/arrow_right_light.svg + img/icons/arrow_right.svg img/icons/sidebar.svg img/icons/undo.svg img/icons/redo.svg @@ -18,6 +20,7 @@ img/icons/plus.svg img/icons/play.svg img/icons/play_light.svg + img/icons/media-stop_light.svg img/icons/media-skip-forward_light.svg img/icons/continue_until_main.svg img/icons/step_light.svg diff --git a/src/widgets/DebugToolbar.cpp b/src/widgets/DebugToolbar.cpp index 65a4f051..91c78e26 100644 --- a/src/widgets/DebugToolbar.cpp +++ b/src/widgets/DebugToolbar.cpp @@ -10,22 +10,26 @@ DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) : { setObjectName("debugToolbar"); QIcon startIcon = QIcon(":/img/icons/play_light.svg"); + QIcon stopIcon = QIcon(":/img/icons/media-stop_light.svg"); QIcon continueIcon = QIcon(":/img/icons/media-skip-forward_light.svg"); QIcon continueUntilIcon = QIcon(":/img/icons/continue_until_main.svg"); QIcon stepIcon = QIcon(":/img/icons/step_light.svg"); QIcon stepOverIcon = QIcon(":/img/icons/step_over_light.svg"); QAction *actionStart = new QAction(startIcon, tr("Start debug"), parent); + QAction *actionStop = new QAction(stopIcon, tr("Stop debug"), parent); QAction *actionContinue = new QAction(continueIcon, tr("Continue"), parent); QAction *actionContinueUntilMain = new QAction(continueUntilIcon, tr("Continue until main"), parent); QAction *actionStep = new QAction(stepIcon, tr("Step"), parent); QAction *actionStepOver = new QAction(stepOverIcon, tr("Step over"), parent); addAction(actionStart); + addAction(actionStop); addAction(actionContinue); addAction(actionContinueUntilMain); addAction(actionStep); addAction(actionStepOver); + connect(actionStop, &QAction::triggered, Core(), &CutterCore::stopDebug); connect(actionStep, &QAction::triggered, Core(), &CutterCore::stepDebug); connect(actionStart, &QAction::triggered, Core(), &CutterCore::startDebug); connect(actionStepOver, &QAction::triggered, Core(), &CutterCore::stepOverDebug);