2018-06-12 08:43:14 +00:00
|
|
|
#include "DebugToolbar.h"
|
|
|
|
#include "MainWindow.h"
|
2018-07-06 07:55:50 +00:00
|
|
|
#include "dialogs/AttachProcDialog.h"
|
2018-06-12 08:43:14 +00:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QPainter>
|
2018-06-13 23:02:16 +00:00
|
|
|
#include <QToolButton>
|
|
|
|
#include <QMenu>
|
2018-07-25 08:59:40 +00:00
|
|
|
#include <QFileInfo>
|
2018-06-12 08:43:14 +00:00
|
|
|
|
|
|
|
DebugToolbar::DebugToolbar(MainWindow *main, QWidget *parent) :
|
|
|
|
QToolBar(parent),
|
|
|
|
main(main)
|
|
|
|
{
|
|
|
|
setObjectName("debugToolbar");
|
2018-07-01 21:29:38 +00:00
|
|
|
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");
|
2018-06-12 15:42:38 +00:00
|
|
|
QIcon stopIcon = QIcon(":/img/icons/media-stop_light.svg");
|
2018-06-12 08:43:14 +00:00
|
|
|
QIcon continueIcon = QIcon(":/img/icons/media-skip-forward_light.svg");
|
2018-06-13 23:02:16 +00:00
|
|
|
QIcon continueUntilMainIcon = QIcon(":/img/icons/continue_until_main.svg");
|
|
|
|
QIcon continueUntilCallIcon = QIcon(":/img/icons/continue_until_call.svg");
|
|
|
|
QIcon continueUntilSyscallIcon = QIcon(":/img/icons/continue_until_syscall.svg");
|
2018-06-12 08:43:14 +00:00
|
|
|
QIcon stepIcon = QIcon(":/img/icons/step_light.svg");
|
|
|
|
QIcon stepOverIcon = QIcon(":/img/icons/step_over_light.svg");
|
|
|
|
|
2018-07-01 21:29:38 +00:00
|
|
|
actionStart = new QAction(startDebugIcon, tr("Start debug"), parent);
|
2018-07-17 07:26:20 +00:00
|
|
|
actionStart->setShortcut(QKeySequence(Qt::Key_F9));
|
2018-07-01 21:29:38 +00:00
|
|
|
actionStartEmul = new QAction(startEmulIcon, tr("Start emulation"), parent);
|
2018-07-17 07:26:20 +00:00
|
|
|
actionAttach = new QAction(startAttachIcon, tr("Attach to process"), parent);
|
2018-06-12 15:42:38 +00:00
|
|
|
QAction *actionStop = new QAction(stopIcon, tr("Stop debug"), parent);
|
2018-07-17 07:26:20 +00:00
|
|
|
actionContinue = new QAction(continueIcon, tr("Continue"), parent);
|
|
|
|
actionContinue->setShortcut(QKeySequence(Qt::Key_F5));
|
|
|
|
actionContinueUntilMain = new QAction(continueUntilMainIcon, tr("Continue until main"), parent);
|
|
|
|
actionContinueUntilCall = new QAction(continueUntilCallIcon, tr("Continue until call"), parent);
|
|
|
|
actionContinueUntilSyscall = new QAction(continueUntilSyscallIcon, tr("Continue until syscall"), parent);
|
|
|
|
actionStep = new QAction(stepIcon, tr("Step"), parent);
|
|
|
|
actionStep->setShortcut(QKeySequence(Qt::Key_F7));
|
|
|
|
actionStepOver = new QAction(stepOverIcon, tr("Step over"), parent);
|
|
|
|
actionStepOver->setShortcut(QKeySequence(Qt::Key_F8));
|
2018-06-13 23:02:16 +00:00
|
|
|
|
2018-07-01 21:29:38 +00:00
|
|
|
QToolButton *startButton = new QToolButton;
|
|
|
|
startButton->setPopupMode(QToolButton::MenuButtonPopup);
|
|
|
|
connect(startButton, &QToolButton::triggered, startButton, &QToolButton::setDefaultAction);
|
|
|
|
QMenu *startMenu = new QMenu;
|
2018-07-26 09:46:17 +00:00
|
|
|
// startMenu->addAction(actionStart);
|
2018-07-01 21:29:38 +00:00
|
|
|
startMenu->addAction(actionStartEmul);
|
2018-07-26 09:46:17 +00:00
|
|
|
// startMenu->addAction(actionAttach);
|
|
|
|
// startButton->setDefaultAction(actionStart);
|
|
|
|
startButton->setDefaultAction(actionStartEmul);
|
2018-07-01 21:29:38 +00:00
|
|
|
startButton->setMenu(startMenu);
|
|
|
|
|
2018-06-13 23:02:16 +00:00
|
|
|
QToolButton *continueUntilButton = new QToolButton;
|
|
|
|
continueUntilButton->setPopupMode(QToolButton::MenuButtonPopup);
|
|
|
|
connect(continueUntilButton, &QToolButton::triggered, continueUntilButton, &QToolButton::setDefaultAction);
|
|
|
|
QMenu *continueUntilMenu = new QMenu;
|
|
|
|
continueUntilMenu->addAction(actionContinueUntilMain);
|
|
|
|
continueUntilMenu->addAction(actionContinueUntilCall);
|
|
|
|
continueUntilMenu->addAction(actionContinueUntilSyscall);
|
|
|
|
continueUntilButton->setMenu(continueUntilMenu);
|
|
|
|
continueUntilButton->setDefaultAction(actionContinueUntilMain);
|
|
|
|
|
2018-07-01 21:29:38 +00:00
|
|
|
addWidget(startButton);
|
2018-06-12 15:42:38 +00:00
|
|
|
addAction(actionStop);
|
2018-06-12 08:43:14 +00:00
|
|
|
addAction(actionContinue);
|
2018-06-13 23:02:16 +00:00
|
|
|
addWidget(continueUntilButton);
|
2018-06-12 08:43:14 +00:00
|
|
|
addAction(actionStep);
|
|
|
|
addAction(actionStepOver);
|
|
|
|
|
2018-07-17 07:26:20 +00:00
|
|
|
connect(actionStop, &QAction::triggered, Core(), &CutterCore::stopDebug);
|
|
|
|
connect(actionStop, &QAction::triggered, [=]() {
|
|
|
|
actionContinue->setVisible(true);
|
|
|
|
actionStart->setVisible(true);
|
|
|
|
actionStartEmul->setVisible(true);
|
|
|
|
actionAttach->setVisible(true);
|
|
|
|
actionContinueUntilMain->setVisible(true);
|
|
|
|
this->colorToolbar(false);
|
|
|
|
});
|
|
|
|
connect(actionStep, &QAction::triggered, Core(), &CutterCore::stepDebug);
|
|
|
|
connect(actionStart, &QAction::triggered, [=]() {
|
2018-07-25 08:59:40 +00:00
|
|
|
QString filename = Core()->getConfig("file.lastpath");
|
|
|
|
QFileInfo info(filename);
|
|
|
|
if (!info.isExecutable()) {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(QString("File '%1' does not have executable permissions.").arg(filename));
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
2018-07-17 07:26:20 +00:00
|
|
|
this->colorToolbar(true);
|
|
|
|
actionAttach->setVisible(false);
|
|
|
|
actionStartEmul->setVisible(false);
|
2018-07-25 08:59:40 +00:00
|
|
|
Core()->startDebug();
|
2018-07-17 07:26:20 +00:00
|
|
|
});
|
|
|
|
connect(actionAttach, &QAction::triggered, this, &DebugToolbar::attachProcessDialog);
|
|
|
|
connect(actionStartEmul, &QAction::triggered, Core(), &CutterCore::startEmulation);
|
|
|
|
connect(actionStartEmul, &QAction::triggered, [=]() {
|
|
|
|
actionContinue->setVisible(false);
|
|
|
|
actionStart->setVisible(false);
|
|
|
|
actionAttach->setVisible(false);
|
|
|
|
actionContinueUntilMain->setVisible(false);
|
|
|
|
continueUntilButton->setDefaultAction(actionContinueUntilSyscall);
|
|
|
|
this->colorToolbar(true);
|
|
|
|
});
|
|
|
|
connect(actionStepOver, &QAction::triggered, Core(), &CutterCore::stepOverDebug);
|
|
|
|
connect(actionContinue, &QAction::triggered, Core(), &CutterCore::continueDebug);
|
|
|
|
connect(actionContinueUntilMain, &QAction::triggered, this, &DebugToolbar::continueUntilMain);
|
2018-06-13 23:02:16 +00:00
|
|
|
connect(actionContinueUntilCall, &QAction::triggered, Core(), &CutterCore::continueUntilCall);
|
2018-07-17 07:26:20 +00:00
|
|
|
connect(actionContinueUntilSyscall, &QAction::triggered, Core(), &CutterCore::continueUntilSyscall);
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugToolbar::continueUntilMain()
|
|
|
|
{
|
|
|
|
Core()->continueUntilDebug(tr("main"));
|
2018-06-22 08:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugToolbar::colorToolbar(bool p)
|
|
|
|
{
|
|
|
|
if (p) {
|
|
|
|
this->setStyleSheet("QToolBar {background: green;}");
|
|
|
|
} else {
|
|
|
|
this->setStyleSheet("");
|
|
|
|
}
|
2018-07-01 21:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugToolbar::attachProcessDialog()
|
|
|
|
{
|
|
|
|
AttachProcDialog *dialog = new AttachProcDialog(this);
|
|
|
|
|
|
|
|
if (dialog->exec()) {
|
|
|
|
int pid = dialog->getPID();
|
|
|
|
attachProcess(pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugToolbar::attachProcess(int pid)
|
|
|
|
{
|
|
|
|
// hide unwanted buttons
|
|
|
|
this->colorToolbar(true);
|
|
|
|
this->actionStart->setVisible(false);
|
|
|
|
this->actionStartEmul->setVisible(false);
|
|
|
|
// attach
|
|
|
|
Core()->attachDebug(pid);
|
2018-06-12 08:43:14 +00:00
|
|
|
}
|