From 570a43d750bb8b15da078db85a7d50c2ee5cbc70 Mon Sep 17 00:00:00 2001 From: yossizap Date: Sat, 31 Oct 2020 17:01:53 +0000 Subject: [PATCH] Added an option to stop the debug session and enabled continue and step back --- src/core/Cutter.cpp | 37 +++++++++++++++++++++++++++++++++++- src/core/Cutter.h | 3 ++- src/core/MainWindow.cpp | 2 +- src/widgets/DebugActions.cpp | 34 +++++++++++++++++++++++++-------- src/widgets/DebugActions.h | 2 +- 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index d207a5be..a79e3655 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -2135,7 +2135,7 @@ void CutterCore::setDebugPlugin(QString plugin) setConfig("dbg.backend", plugin); } -void CutterCore::addTraceSession() +void CutterCore::startTraceSession() { if (!currentlyDebugging) { return; @@ -2170,6 +2170,41 @@ void CutterCore::addTraceSession() debugTask->startTask(); } +void CutterCore::stopTraceSession() +{ + if (!currentlyDebugging) { + return; + } + + if (currentlyEmulating) { + if (!asyncCmdEsil("aets-", debugTask)) { + return; + } + } else { + if (!asyncCmd("dts-", debugTask)) { + return; + } + } + emit debugTaskStateChanged(); + + connect(debugTask.data(), &R2Task::finished, this, [this] () { + if (debugTaskDialog) { + delete debugTaskDialog; + } + debugTask.clear(); + + emit debugTaskStateChanged(); + }); + + debugTaskDialog = new R2TaskDialog(debugTask); + debugTaskDialog->setBreakOnClose(true); + debugTaskDialog->setAttribute(Qt::WA_DeleteOnClose); + debugTaskDialog->setDesc(tr("Stopping debug session...")); + debugTaskDialog->show(); + + debugTask->startTask(); +} + void CutterCore::toggleBreakpoint(RVA addr) { cmdRaw(QString("dbs %1").arg(addr)); diff --git a/src/core/Cutter.h b/src/core/Cutter.h index 4c54fbd6..487ce04b 100644 --- a/src/core/Cutter.h +++ b/src/core/Cutter.h @@ -402,7 +402,8 @@ public: void stepOverDebug(); void stepOutDebug(); void stepBackDebug(); - void addTraceSession(); + void startTraceSession(); + void stopTraceSession(); void addBreakpoint(const BreakpointDescription &config); void updateBreakpoint(int index, const BreakpointDescription &config); diff --git a/src/core/MainWindow.cpp b/src/core/MainWindow.cpp index 385a3cd0..4b343211 100644 --- a/src/core/MainWindow.cpp +++ b/src/core/MainWindow.cpp @@ -301,7 +301,7 @@ void MainWindow::initToolBar() ui->menuDebug->addAction(debugActions->actionContinueUntilSyscall); ui->menuDebug->addAction(debugActions->actionContinueBack); ui->menuDebug->addSeparator(); - ui->menuDebug->addAction(debugActions->actionAddTraceSession); + ui->menuDebug->addAction(debugActions->actionTrace); // Sepparator between undo/redo and goto lineEdit QWidget *spacer4 = new QWidget(); diff --git a/src/widgets/DebugActions.cpp b/src/widgets/DebugActions.cpp index b8f3380e..bdb39cd6 100644 --- a/src/widgets/DebugActions.cpp +++ b/src/widgets/DebugActions.cpp @@ -26,7 +26,8 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : QIcon startRemoteIcon = QIcon(":/img/icons/play_light_remote.svg"); QIcon continueBackIcon = QIcon(":/img/icons/reverse_continue.svg"); QIcon stepBackIcon = QIcon(":/img/icons/reverse_step.svg"); - QIcon addTraceSessionIcon = QIcon(":/img/icons/record_trace.svg"); + QIcon startTraceIcon = QIcon(":/img/icons/record_trace.svg"); + QIcon stopTraceIcon = QIcon(":/img/icons/record_trace.svg"); stopIcon = QIcon(":/img/icons/media-stop_light.svg"); restartIcon = QIcon(":/img/icons/spin_light.svg"); detachIcon = QIcon(":/img/icons/detach_debugger.svg"); @@ -49,7 +50,8 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : QString stepOverLabel = tr("Step over"); QString stepOutLabel = tr("Step out"); QString stepBackLabel = tr("Step backwards"); - QString addTraceSessionLabel = tr("Add trace session"); + QString startTraceLabel = tr("Start trace session"); + QString stopTraceLabel = tr("Stop trace session"); suspendLabel = tr("Suspend the process"); continueLabel = tr("Continue"); restartDebugLabel = tr("Restart program"); @@ -77,14 +79,13 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : actionStepOut->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F8)); actionStepBack = new QAction(stepBackIcon, stepBackLabel, this); actionStepBack->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F7)); - actionAddTraceSession = new QAction(addTraceSessionIcon, addTraceSessionLabel, this); + actionTrace = new QAction(startTraceIcon, startTraceLabel, this); QToolButton *startButton = new QToolButton; startButton->setPopupMode(QToolButton::MenuButtonPopup); connect(startButton, &QToolButton::triggered, startButton, &QToolButton::setDefaultAction); QMenu *startMenu = new QMenu(startButton); - // only emulation is currently allowed startMenu->addAction(actionStart); startMenu->addAction(actionStartEmul); startMenu->addAction(actionAttach); @@ -113,11 +114,11 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : toolBar->addAction(actionStepOut); toolBar->addAction(actionStepBack); toolBar->addAction(actionContinueBack); - toolBar->addAction(actionAddTraceSession); + toolBar->addAction(actionTrace); allActions = {actionStop, actionAllContinues, actionContinue, actionContinueUntilCall, actionContinueUntilMain, actionContinueUntilSyscall, actionStep, actionStepOut, - actionStepOver, actionContinueBack, actionStepBack, actionAddTraceSession}; + actionStepOver, actionContinueBack, actionStepBack, actionTrace}; // Hide all actions setAllActionsVisible(false); @@ -126,7 +127,7 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : // necessary to avoid staying stuck toggleActions = {actionStepOver, actionStep, actionStepOut, actionContinueUntilMain, actionContinueUntilCall, actionContinueUntilSyscall, actionStepBack, - actionContinueBack, actionAddTraceSession}; + actionContinueBack, actionTrace}; toggleConnectionActions = {actionAttach, actionStartRemote}; connect(Core(), &CutterCore::debugProcessFinished, this, [ = ](int pid) { @@ -171,7 +172,10 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : continueUntilButton->setDefaultAction(actionContinueUntilMain); setAllActionsVisible(false); }); + connect(actionStep, &QAction::triggered, Core(), &CutterCore::stepDebug); + connect(actionStepBack, &QAction::triggered, Core(), &CutterCore::stepBackDebug); + connect(actionStart, &QAction::triggered, this, &DebugActions::startDebug); connect(actionAttach, &QAction::triggered, this, &DebugActions::attachProcessDialog); @@ -195,7 +199,8 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : connect(actionContinueUntilMain, &QAction::triggered, this, &DebugActions::continueUntilMain); connect(actionContinueUntilCall, &QAction::triggered, Core(), &CutterCore::continueUntilCall); connect(actionContinueUntilSyscall, &QAction::triggered, Core(), &CutterCore::continueUntilSyscall); - connect(actionContinue, &QAction::triggered, Core(), [ = ]() { + connect(actionContinueBack, &QAction::triggered, Core(), &CutterCore::continueBackDebug); + connect(actionContinue, &QAction::triggered, Core(), [=]() { // Switch between continue and suspend depending on the debugger's state if (Core()->isDebugTaskInProgress()) { Core()->suspendDebug(); @@ -204,6 +209,19 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) : } }); + connect(actionTrace, &QAction::triggered, Core(), [=]() { + // Check if a debug session was created to switch between start and stop + if (!Core()->core()->dbg->session) { + Core()->startTraceSession(); + actionTrace->setText(stopTraceLabel); + actionTrace->setIcon(stopTraceIcon); + } else { + Core()->stopTraceSession(); + actionTrace->setText(startTraceLabel); + actionTrace->setIcon(startTraceIcon); + } + }); + connect(Config(), &Configuration::interfaceThemeChanged, this, &DebugActions::chooseThemeIcons); chooseThemeIcons(); } diff --git a/src/widgets/DebugActions.h b/src/widgets/DebugActions.h index 75e7069d..e55189df 100644 --- a/src/widgets/DebugActions.h +++ b/src/widgets/DebugActions.h @@ -33,7 +33,7 @@ public: QAction *actionStepBack; QAction *actionStop; QAction *actionAllContinues; - QAction *actionAddTraceSession; + QAction *actionTrace; // Continue/suspend and start/restart interchange during runtime QIcon continueIcon;