Added an option to stop the debug session and enabled continue and step back

This commit is contained in:
yossizap 2020-10-31 17:01:53 +00:00
parent 3ecf5ba98f
commit 570a43d750
5 changed files with 66 additions and 12 deletions

View File

@ -2135,7 +2135,7 @@ void CutterCore::setDebugPlugin(QString plugin)
setConfig("dbg.backend", plugin); setConfig("dbg.backend", plugin);
} }
void CutterCore::addTraceSession() void CutterCore::startTraceSession()
{ {
if (!currentlyDebugging) { if (!currentlyDebugging) {
return; return;
@ -2170,6 +2170,41 @@ void CutterCore::addTraceSession()
debugTask->startTask(); 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) void CutterCore::toggleBreakpoint(RVA addr)
{ {
cmdRaw(QString("dbs %1").arg(addr)); cmdRaw(QString("dbs %1").arg(addr));

View File

@ -402,7 +402,8 @@ public:
void stepOverDebug(); void stepOverDebug();
void stepOutDebug(); void stepOutDebug();
void stepBackDebug(); void stepBackDebug();
void addTraceSession(); void startTraceSession();
void stopTraceSession();
void addBreakpoint(const BreakpointDescription &config); void addBreakpoint(const BreakpointDescription &config);
void updateBreakpoint(int index, const BreakpointDescription &config); void updateBreakpoint(int index, const BreakpointDescription &config);

View File

@ -301,7 +301,7 @@ void MainWindow::initToolBar()
ui->menuDebug->addAction(debugActions->actionContinueUntilSyscall); ui->menuDebug->addAction(debugActions->actionContinueUntilSyscall);
ui->menuDebug->addAction(debugActions->actionContinueBack); ui->menuDebug->addAction(debugActions->actionContinueBack);
ui->menuDebug->addSeparator(); ui->menuDebug->addSeparator();
ui->menuDebug->addAction(debugActions->actionAddTraceSession); ui->menuDebug->addAction(debugActions->actionTrace);
// Sepparator between undo/redo and goto lineEdit // Sepparator between undo/redo and goto lineEdit
QWidget *spacer4 = new QWidget(); QWidget *spacer4 = new QWidget();

View File

@ -26,7 +26,8 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) :
QIcon startRemoteIcon = QIcon(":/img/icons/play_light_remote.svg"); QIcon startRemoteIcon = QIcon(":/img/icons/play_light_remote.svg");
QIcon continueBackIcon = QIcon(":/img/icons/reverse_continue.svg"); QIcon continueBackIcon = QIcon(":/img/icons/reverse_continue.svg");
QIcon stepBackIcon = QIcon(":/img/icons/reverse_step.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"); stopIcon = QIcon(":/img/icons/media-stop_light.svg");
restartIcon = QIcon(":/img/icons/spin_light.svg"); restartIcon = QIcon(":/img/icons/spin_light.svg");
detachIcon = QIcon(":/img/icons/detach_debugger.svg"); detachIcon = QIcon(":/img/icons/detach_debugger.svg");
@ -49,7 +50,8 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) :
QString stepOverLabel = tr("Step over"); QString stepOverLabel = tr("Step over");
QString stepOutLabel = tr("Step out"); QString stepOutLabel = tr("Step out");
QString stepBackLabel = tr("Step backwards"); 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"); suspendLabel = tr("Suspend the process");
continueLabel = tr("Continue"); continueLabel = tr("Continue");
restartDebugLabel = tr("Restart program"); restartDebugLabel = tr("Restart program");
@ -77,14 +79,13 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) :
actionStepOut->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F8)); actionStepOut->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F8));
actionStepBack = new QAction(stepBackIcon, stepBackLabel, this); actionStepBack = new QAction(stepBackIcon, stepBackLabel, this);
actionStepBack->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F7)); actionStepBack->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_F7));
actionAddTraceSession = new QAction(addTraceSessionIcon, addTraceSessionLabel, this); actionTrace = new QAction(startTraceIcon, startTraceLabel, this);
QToolButton *startButton = new QToolButton; QToolButton *startButton = new QToolButton;
startButton->setPopupMode(QToolButton::MenuButtonPopup); startButton->setPopupMode(QToolButton::MenuButtonPopup);
connect(startButton, &QToolButton::triggered, startButton, &QToolButton::setDefaultAction); connect(startButton, &QToolButton::triggered, startButton, &QToolButton::setDefaultAction);
QMenu *startMenu = new QMenu(startButton); QMenu *startMenu = new QMenu(startButton);
// only emulation is currently allowed
startMenu->addAction(actionStart); startMenu->addAction(actionStart);
startMenu->addAction(actionStartEmul); startMenu->addAction(actionStartEmul);
startMenu->addAction(actionAttach); startMenu->addAction(actionAttach);
@ -113,11 +114,11 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) :
toolBar->addAction(actionStepOut); toolBar->addAction(actionStepOut);
toolBar->addAction(actionStepBack); toolBar->addAction(actionStepBack);
toolBar->addAction(actionContinueBack); toolBar->addAction(actionContinueBack);
toolBar->addAction(actionAddTraceSession); toolBar->addAction(actionTrace);
allActions = {actionStop, actionAllContinues, actionContinue, actionContinueUntilCall, allActions = {actionStop, actionAllContinues, actionContinue, actionContinueUntilCall,
actionContinueUntilMain, actionContinueUntilSyscall, actionStep, actionStepOut, actionContinueUntilMain, actionContinueUntilSyscall, actionStep, actionStepOut,
actionStepOver, actionContinueBack, actionStepBack, actionAddTraceSession}; actionStepOver, actionContinueBack, actionStepBack, actionTrace};
// Hide all actions // Hide all actions
setAllActionsVisible(false); setAllActionsVisible(false);
@ -126,7 +127,7 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) :
// necessary to avoid staying stuck // necessary to avoid staying stuck
toggleActions = {actionStepOver, actionStep, actionStepOut, actionContinueUntilMain, toggleActions = {actionStepOver, actionStep, actionStepOut, actionContinueUntilMain,
actionContinueUntilCall, actionContinueUntilSyscall, actionStepBack, actionContinueUntilCall, actionContinueUntilSyscall, actionStepBack,
actionContinueBack, actionAddTraceSession}; actionContinueBack, actionTrace};
toggleConnectionActions = {actionAttach, actionStartRemote}; toggleConnectionActions = {actionAttach, actionStartRemote};
connect(Core(), &CutterCore::debugProcessFinished, this, [ = ](int pid) { connect(Core(), &CutterCore::debugProcessFinished, this, [ = ](int pid) {
@ -171,7 +172,10 @@ DebugActions::DebugActions(QToolBar *toolBar, MainWindow *main) :
continueUntilButton->setDefaultAction(actionContinueUntilMain); continueUntilButton->setDefaultAction(actionContinueUntilMain);
setAllActionsVisible(false); setAllActionsVisible(false);
}); });
connect(actionStep, &QAction::triggered, Core(), &CutterCore::stepDebug); connect(actionStep, &QAction::triggered, Core(), &CutterCore::stepDebug);
connect(actionStepBack, &QAction::triggered, Core(), &CutterCore::stepBackDebug);
connect(actionStart, &QAction::triggered, this, &DebugActions::startDebug); connect(actionStart, &QAction::triggered, this, &DebugActions::startDebug);
connect(actionAttach, &QAction::triggered, this, &DebugActions::attachProcessDialog); 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(actionContinueUntilMain, &QAction::triggered, this, &DebugActions::continueUntilMain);
connect(actionContinueUntilCall, &QAction::triggered, Core(), &CutterCore::continueUntilCall); connect(actionContinueUntilCall, &QAction::triggered, Core(), &CutterCore::continueUntilCall);
connect(actionContinueUntilSyscall, &QAction::triggered, Core(), &CutterCore::continueUntilSyscall); 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 // Switch between continue and suspend depending on the debugger's state
if (Core()->isDebugTaskInProgress()) { if (Core()->isDebugTaskInProgress()) {
Core()->suspendDebug(); 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); connect(Config(), &Configuration::interfaceThemeChanged, this, &DebugActions::chooseThemeIcons);
chooseThemeIcons(); chooseThemeIcons();
} }

View File

@ -33,7 +33,7 @@ public:
QAction *actionStepBack; QAction *actionStepBack;
QAction *actionStop; QAction *actionStop;
QAction *actionAllContinues; QAction *actionAllContinues;
QAction *actionAddTraceSession; QAction *actionTrace;
// Continue/suspend and start/restart interchange during runtime // Continue/suspend and start/restart interchange during runtime
QIcon continueIcon; QIcon continueIcon;