2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-12-17 10:10:04 +08:00
|
|
|
#include <QDesktopWidget>
|
2021-08-01 23:24:37 +08:00
|
|
|
#include "cpudialog.h"
|
|
|
|
#include "ui_cpudialog.h"
|
|
|
|
#include "../HighlighterManager.h"
|
|
|
|
#include "../mainwindow.h"
|
|
|
|
#include "../debugger.h"
|
|
|
|
#include "../settings.h"
|
2021-08-13 11:18:42 +08:00
|
|
|
#include "../colorscheme.h"
|
2021-12-22 22:04:34 +08:00
|
|
|
#include "../iconsmanager.h"
|
2021-08-01 23:24:37 +08:00
|
|
|
|
|
|
|
CPUDialog::CPUDialog(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::CPUDialog)
|
|
|
|
{
|
2021-08-13 11:18:42 +08:00
|
|
|
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
|
2021-08-01 23:24:37 +08:00
|
|
|
ui->setupUi(this);
|
2021-08-13 11:18:42 +08:00
|
|
|
ui->txtCode->setHighlighter(highlighterManager.getCppHighlighter());
|
2021-11-16 00:03:43 +08:00
|
|
|
ui->txtCode->setReadOnly(true);
|
|
|
|
ui->txtCode->gutter().setShowLineNumbers(false);
|
|
|
|
ui->txtCode->setCaretUseTextColor(true);
|
|
|
|
|
|
|
|
ui->txtCode->codeFolding().indentGuides = false;
|
|
|
|
ui->txtCode->codeFolding().fillIndents = false;
|
2021-11-19 07:52:36 +08:00
|
|
|
ui->txtCode->setGutterWidth(0);
|
2021-11-16 00:03:43 +08:00
|
|
|
ui->txtCode->setUseCodeFolding(false);
|
2021-08-01 23:24:37 +08:00
|
|
|
highlighterManager.applyColorScheme(ui->txtCode->highlighter(),
|
|
|
|
pSettings->editor().colorScheme());
|
2021-08-13 11:18:42 +08:00
|
|
|
PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE);
|
|
|
|
if (item) {
|
|
|
|
ui->txtCode->setActiveLineColor(item->background());
|
|
|
|
}
|
2021-11-16 00:03:43 +08:00
|
|
|
item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_TEXT);
|
|
|
|
if (item) {
|
|
|
|
ui->txtCode->setForegroundColor(item->foreground());
|
|
|
|
ui->txtCode->setBackgroundColor(item->background());
|
|
|
|
} else {
|
|
|
|
ui->txtCode->setForegroundColor(palette().color(QPalette::Text));
|
|
|
|
ui->txtCode->setBackgroundColor(palette().color(QPalette::Base));
|
|
|
|
}
|
2021-08-01 23:24:37 +08:00
|
|
|
ui->lstRegister->setModel(pMainWindow->debugger()->registerModel());
|
|
|
|
|
2021-08-13 11:18:42 +08:00
|
|
|
ui->rdIntel->setChecked(pSettings->debugger().useIntelStyle());
|
|
|
|
ui->chkBlendMode->setChecked(pSettings->debugger().blendMode());
|
2021-12-23 09:11:58 +08:00
|
|
|
resize(pSettings->ui().CPUDialogWidth(),pSettings->ui().CPUDialogHeight());
|
|
|
|
|
|
|
|
QList<int> sizes = ui->splitter->sizes();
|
|
|
|
int tabWidth = pSettings->ui().CPUDialogSplitterPos();
|
|
|
|
int totalSize = sizes[0] + sizes[1];
|
|
|
|
sizes[0] = tabWidth;
|
|
|
|
sizes[1] = std::max(1,totalSize - sizes[0]);
|
|
|
|
ui->splitter->setSizes(sizes);
|
|
|
|
|
2021-12-22 22:04:34 +08:00
|
|
|
updateIcons();
|
|
|
|
connect(pIconsManager,&IconsManager::actionIconsUpdated,
|
|
|
|
this, &CPUDialog::updateIcons);
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CPUDialog::~CPUDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUDialog::updateInfo()
|
|
|
|
{
|
|
|
|
if (pMainWindow->debugger()->executing()) {
|
|
|
|
// Load the registers..
|
|
|
|
sendSyntaxCommand();
|
2021-11-25 09:05:45 +08:00
|
|
|
pMainWindow->debugger()->sendCommand("-data-list-register-values", "N");
|
2021-08-13 11:18:42 +08:00
|
|
|
if (ui->chkBlendMode->isChecked())
|
|
|
|
pMainWindow->debugger()->sendCommand("disas", "/s");
|
|
|
|
else
|
|
|
|
pMainWindow->debugger()->sendCommand("disas", "");
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 10:46:38 +08:00
|
|
|
void CPUDialog::updateButtonStates(bool enable)
|
|
|
|
{
|
|
|
|
ui->btnStepIntoInstruction->setEnabled(enable);
|
|
|
|
ui->btnStepOverInstruction->setEnabled(enable);
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:42:56 +08:00
|
|
|
void CPUDialog::setDisassembly(const QString& file, const QString& funcName,const QStringList& lines)
|
2021-08-01 23:24:37 +08:00
|
|
|
{
|
2021-11-25 07:42:56 +08:00
|
|
|
ui->txtFunctionName->setText(QString("%1:%2").arg(file, funcName));
|
2021-08-01 23:24:37 +08:00
|
|
|
int activeLine = -1;
|
2021-08-13 11:18:42 +08:00
|
|
|
ui->txtCode->lines()->clear();
|
2021-11-25 07:42:56 +08:00
|
|
|
for (int i=0;i<lines.size();i++) {
|
2021-08-01 23:24:37 +08:00
|
|
|
QString line = lines[i];
|
|
|
|
if (line.startsWith("=>")) {
|
|
|
|
activeLine = i;
|
|
|
|
}
|
|
|
|
ui->txtCode->lines()->add(line);
|
|
|
|
}
|
|
|
|
if (activeLine!=-1)
|
2021-12-16 10:46:38 +08:00
|
|
|
ui->txtCode->setCaretXYEx(true,BufferCoord{1,activeLine+1});
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPUDialog::sendSyntaxCommand()
|
|
|
|
{
|
|
|
|
// Set disassembly flavor
|
|
|
|
if (ui->rdIntel->isChecked()) {
|
2021-11-24 22:16:40 +08:00
|
|
|
pMainWindow->debugger()->sendCommand("-gdb-set", "disassembly-flavor intel");
|
2021-08-01 23:24:37 +08:00
|
|
|
} else {
|
2021-11-24 22:16:40 +08:00
|
|
|
pMainWindow->debugger()->sendCommand("-gdb-set", "disassembly-flavor att");
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUDialog::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2021-12-23 09:11:58 +08:00
|
|
|
pSettings->ui().setCPUDialogWidth(width());
|
|
|
|
pSettings->ui().setCPUDialogHeight(height());
|
|
|
|
|
|
|
|
QList<int> sizes = ui->splitter->sizes();
|
|
|
|
pSettings->ui().setCPUDialogSplitterPos(sizes[0]);
|
|
|
|
|
2021-08-01 23:24:37 +08:00
|
|
|
QDialog::closeEvent(event);
|
|
|
|
emit closed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUDialog::on_rdIntel_toggled(bool)
|
|
|
|
{
|
|
|
|
sendSyntaxCommand();
|
2021-08-02 10:08:25 +08:00
|
|
|
pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked());
|
|
|
|
pSettings->debugger().save();
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPUDialog::on_rdATT_toggled(bool)
|
|
|
|
{
|
|
|
|
sendSyntaxCommand();
|
2021-08-02 10:08:25 +08:00
|
|
|
pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked());
|
|
|
|
pSettings->debugger().save();
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
2021-08-13 11:18:42 +08:00
|
|
|
|
2021-10-20 18:05:43 +08:00
|
|
|
void CPUDialog::on_chkBlendMode_stateChanged(int)
|
2021-08-13 11:18:42 +08:00
|
|
|
{
|
|
|
|
updateInfo();
|
|
|
|
pSettings->debugger().setBlendMode(ui->chkBlendMode->isCheckable());
|
|
|
|
pSettings->debugger().save();
|
|
|
|
}
|
2021-12-16 10:46:38 +08:00
|
|
|
|
|
|
|
void CPUDialog::on_btnStepOverInstruction_clicked()
|
|
|
|
{
|
|
|
|
pMainWindow->debugger()->sendCommand("-exec-next-instruction","");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CPUDialog::on_btnStepIntoInstruction_clicked()
|
|
|
|
{
|
|
|
|
pMainWindow->debugger()->sendCommand("-exec-step-instruction","");
|
|
|
|
}
|
|
|
|
|
2021-12-22 22:04:34 +08:00
|
|
|
void CPUDialog::updateIcons()
|
|
|
|
{
|
2021-12-23 00:24:52 +08:00
|
|
|
pIconsManager->setIcon(ui->btnStepIntoInstruction, IconsManager::ACTION_RUN_STEP_INTO_INSTRUCTION);
|
|
|
|
pIconsManager->setIcon(ui->btnStepOverInstruction, IconsManager::ACTION_RUN_STEP_OVER_INSTRUCTION);
|
2021-12-22 22:04:34 +08:00
|
|
|
}
|
|
|
|
|