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/>.
|
|
|
|
*/
|
2024-04-05 09:42:00 +08:00
|
|
|
#include <qsynedit/document.h>
|
2021-08-01 23:24:37 +08:00
|
|
|
#include "cpudialog.h"
|
|
|
|
#include "ui_cpudialog.h"
|
2022-12-10 21:23:49 +08:00
|
|
|
#include "../syntaxermanager.h"
|
2021-08-01 23:24:37 +08:00
|
|
|
#include "../mainwindow.h"
|
2024-03-08 10:06:18 +08:00
|
|
|
#include "../debugger/debugger.h"
|
2021-08-01 23:24:37 +08:00
|
|
|
#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),
|
2022-12-02 10:19:03 +08:00
|
|
|
ui(new Ui::CPUDialog),
|
2023-03-03 17:20:33 +08:00
|
|
|
mInited(false),
|
|
|
|
mSetting(false)
|
2021-08-01 23:24:37 +08:00
|
|
|
{
|
2021-08-13 11:18:42 +08:00
|
|
|
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
|
2022-02-02 17:34:37 +08:00
|
|
|
setWindowFlag(Qt::WindowContextHelpButtonHint,false);
|
2021-08-01 23:24:37 +08:00
|
|
|
ui->setupUi(this);
|
2024-03-31 21:27:02 +08:00
|
|
|
updateSyntaxer();
|
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);
|
2022-12-02 10:19:03 +08:00
|
|
|
ui->txtCode->setRightEdge(0);
|
2023-03-01 20:28:00 +08:00
|
|
|
QSynedit::EditorOptions options=ui->txtCode->getOptions();
|
2024-04-03 10:14:54 +08:00
|
|
|
options.setFlag(QSynedit::EditorOption::ScrollPastEof,false);
|
|
|
|
options.setFlag(QSynedit::EditorOption::ScrollPastEol,false);
|
|
|
|
options.setFlag(QSynedit::EditorOption::ShowRainbowColor, false);
|
2023-03-01 20:28:00 +08:00
|
|
|
ui->txtCode->setOptions(options);
|
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));
|
|
|
|
}
|
2022-03-01 22:03:54 +08:00
|
|
|
resetEditorFont(screenDPI());
|
2022-10-10 18:05:18 +08:00
|
|
|
QItemSelectionModel *m=ui->lstRegister->selectionModel();
|
2022-10-16 23:10:57 +08:00
|
|
|
ui->lstRegister->setModel(pMainWindow->debugger()->registerModel().get());
|
2022-10-10 18:05:18 +08:00
|
|
|
delete m;
|
2021-08-01 23:24:37 +08:00
|
|
|
|
2021-08-13 11:18:42 +08:00
|
|
|
ui->rdIntel->setChecked(pSettings->debugger().useIntelStyle());
|
2022-12-02 10:19:03 +08:00
|
|
|
if (!ui->rdIntel->isChecked())
|
|
|
|
ui->rdATT->setChecked(true);
|
2021-08-13 11:18:42 +08:00
|
|
|
ui->chkBlendMode->setChecked(pSettings->debugger().blendMode());
|
2021-12-23 09:11:58 +08:00
|
|
|
resize(pSettings->ui().CPUDialogWidth(),pSettings->ui().CPUDialogHeight());
|
|
|
|
|
2023-03-01 19:39:09 +08:00
|
|
|
onUpdateIcons();
|
2021-12-22 22:04:34 +08:00
|
|
|
connect(pIconsManager,&IconsManager::actionIconsUpdated,
|
2022-04-08 17:22:24 +08:00
|
|
|
this, &CPUDialog::onUpdateIcons);
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CPUDialog::~CPUDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPUDialog::updateInfo()
|
|
|
|
{
|
|
|
|
if (pMainWindow->debugger()->executing()) {
|
2024-03-10 11:15:10 +08:00
|
|
|
pMainWindow->debugger()->refreshFrame();
|
2021-08-01 23:24:37 +08:00
|
|
|
// Load the registers..
|
|
|
|
sendSyntaxCommand();
|
2024-03-10 11:15:10 +08:00
|
|
|
pMainWindow->debugger()->refreshRegisters();
|
|
|
|
pMainWindow->debugger()->disassembleCurrentFrame(ui->chkBlendMode->isChecked());
|
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);
|
|
|
|
}
|
|
|
|
|
2022-03-01 22:03:54 +08:00
|
|
|
void CPUDialog::updateDPI(float dpi)
|
|
|
|
{
|
|
|
|
QFont font(pSettings->environment().interfaceFont());
|
|
|
|
font.setPixelSize(pointToPixel(pSettings->environment().interfaceFontSize(),dpi));
|
|
|
|
font.setStyleStrategy(QFont::PreferAntialias);
|
|
|
|
setFont(font);
|
|
|
|
for (QWidget* p:findChildren<QWidget*>()) {
|
|
|
|
if (p!=ui->txtCode)
|
|
|
|
p->setFont(font);
|
|
|
|
}
|
|
|
|
resetEditorFont(dpi);
|
2023-03-01 19:39:09 +08:00
|
|
|
onUpdateIcons();
|
2022-03-01 22:03:54 +08:00
|
|
|
}
|
|
|
|
|
2023-03-03 17:20:33 +08:00
|
|
|
void CPUDialog::setDisassembly(const QString& file, const QString& funcName,const QStringList& lines,const QList<PTrace>& traces)
|
2021-08-01 23:24:37 +08:00
|
|
|
{
|
2023-03-03 17:20:33 +08:00
|
|
|
mSetting=true;
|
|
|
|
ui->cbCallStack->clear();
|
|
|
|
int currentIndex=-1;
|
|
|
|
for (int i=0;i<traces.count();i++) {
|
|
|
|
ui->cbCallStack->addItem(QString("%1:%2").arg(traces[i]->filename, traces[i]->funcname));
|
|
|
|
if (file==traces[i]->filename && funcName == traces[i]->funcname)
|
|
|
|
currentIndex=i;
|
|
|
|
}
|
|
|
|
ui->cbCallStack->setCurrentIndex(currentIndex);
|
2021-08-01 23:24:37 +08:00
|
|
|
int activeLine = -1;
|
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];
|
2024-04-01 16:59:19 +08:00
|
|
|
if (line.startsWith("=>") || line.startsWith("->")) {
|
2021-08-01 23:24:37 +08:00
|
|
|
activeLine = i;
|
|
|
|
}
|
|
|
|
}
|
2023-03-01 20:28:00 +08:00
|
|
|
ui->txtCode->document()->setContents(lines);
|
2024-03-31 21:27:02 +08:00
|
|
|
ui->txtCode->reparseDocument();
|
|
|
|
ui->txtCode->invalidate();
|
2021-08-01 23:24:37 +08:00
|
|
|
if (activeLine!=-1)
|
2023-03-01 20:28:00 +08:00
|
|
|
ui->txtCode->setCaretXYCentered(QSynedit::BufferCoord{1,activeLine+1});
|
2023-03-03 17:20:33 +08:00
|
|
|
mSetting=false;
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
|
2022-03-01 22:03:54 +08:00
|
|
|
void CPUDialog::resetEditorFont(float dpi)
|
2022-03-01 18:11:15 +08:00
|
|
|
{
|
2024-02-28 11:51:02 +08:00
|
|
|
QSynedit::EditorOptions options=ui->txtCode->getOptions();
|
2024-04-03 10:14:54 +08:00
|
|
|
options.setFlag(QSynedit::EditorOption::LigatureSupport, pSettings->editor().enableLigaturesSupport());
|
|
|
|
options.setFlag(QSynedit::EditorOption::ForceMonospace,
|
2024-02-28 11:51:02 +08:00
|
|
|
pSettings->editor().forceFixedFontWidth());
|
|
|
|
ui->txtCode->setOptions(options);
|
2024-02-26 15:15:26 +08:00
|
|
|
QFont f=QFont();
|
2024-02-29 19:17:14 +08:00
|
|
|
f.setFamily(pSettings->editor().fontName());
|
2024-03-13 19:17:25 +08:00
|
|
|
f.setFamilies(pSettings->editor().fontFamiliesWithControlFont());
|
2022-03-01 22:03:54 +08:00
|
|
|
f.setPixelSize(pointToPixel(pSettings->editor().fontSize(),dpi));
|
2024-03-11 17:38:51 +08:00
|
|
|
f.setStyleStrategy(QFont::PreferAntialias);
|
2022-03-01 18:11:15 +08:00
|
|
|
ui->txtCode->setFont(f);
|
|
|
|
}
|
|
|
|
|
2021-08-01 23:24:37 +08:00
|
|
|
void CPUDialog::sendSyntaxCommand()
|
|
|
|
{
|
2024-03-10 11:15:10 +08:00
|
|
|
pMainWindow->debugger()->setDisassemblyLanguage(ui->rdIntel->isChecked());
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
|
2024-03-31 21:27:02 +08:00
|
|
|
void CPUDialog::updateSyntaxer()
|
|
|
|
{
|
2024-04-01 16:59:19 +08:00
|
|
|
if (pSettings->debugger().blendMode() && pMainWindow->debugger()->supportDisassemlyBlendMode()) {
|
2024-03-31 21:27:02 +08:00
|
|
|
if (pSettings->debugger().useIntelStyle())
|
|
|
|
ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::MixedAssembly));
|
|
|
|
else
|
|
|
|
ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::MixedATTAssembly));
|
|
|
|
} else {
|
|
|
|
if (pSettings->debugger().useIntelStyle())
|
|
|
|
ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::Assembly));
|
|
|
|
else
|
|
|
|
ui->txtCode->setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::ATTAssembly));
|
|
|
|
}
|
|
|
|
syntaxerManager.applyColorScheme(ui->txtCode->syntaxer(),
|
|
|
|
pSettings->editor().colorScheme());
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2022-03-16 19:48:20 +08:00
|
|
|
updateInfo();
|
2021-08-02 10:08:25 +08:00
|
|
|
pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked());
|
|
|
|
pSettings->debugger().save();
|
2024-03-31 21:27:02 +08:00
|
|
|
updateSyntaxer();
|
2021-08-01 23:24:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPUDialog::on_rdATT_toggled(bool)
|
|
|
|
{
|
2022-03-16 19:48:20 +08:00
|
|
|
updateInfo();
|
2021-08-02 10:08:25 +08:00
|
|
|
pSettings->debugger().setUseIntelStyle(ui->rdIntel->isChecked());
|
|
|
|
pSettings->debugger().save();
|
2024-03-31 21:27:02 +08:00
|
|
|
updateSyntaxer();
|
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();
|
2024-03-31 21:27:02 +08:00
|
|
|
updateSyntaxer();
|
2021-08-13 11:18:42 +08:00
|
|
|
}
|
2021-12-16 10:46:38 +08:00
|
|
|
|
|
|
|
void CPUDialog::on_btnStepOverInstruction_clicked()
|
|
|
|
{
|
2024-03-10 11:15:10 +08:00
|
|
|
pMainWindow->debugger()->stepOverInstruction();
|
2021-12-16 10:46:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CPUDialog::on_btnStepIntoInstruction_clicked()
|
|
|
|
{
|
2024-03-10 11:15:10 +08:00
|
|
|
pMainWindow->debugger()->stepIntoInstruction();
|
2021-12-16 10:46:38 +08:00
|
|
|
}
|
|
|
|
|
2022-04-08 17:22:24 +08:00
|
|
|
void CPUDialog::onUpdateIcons()
|
2021-12-22 22:04:34 +08:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2022-12-02 10:19:03 +08:00
|
|
|
void CPUDialog::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
QDialog::showEvent(event);
|
|
|
|
if (!mInited) {
|
|
|
|
mInited=true;
|
|
|
|
|
|
|
|
QList<int> sizes = ui->splitter->sizes();
|
|
|
|
int tabWidth = pSettings->ui().CPUDialogSplitterPos();
|
|
|
|
int totalSize = sizes[0] + sizes[1];
|
|
|
|
sizes[0] = tabWidth;
|
|
|
|
sizes[1] = std::max(0,totalSize - sizes[0]);
|
|
|
|
ui->splitter->setSizes(sizes);
|
|
|
|
}
|
2024-04-01 16:59:19 +08:00
|
|
|
ui->chkBlendMode->setVisible(pMainWindow->debugger()->supportDisassemlyBlendMode());
|
2022-12-02 10:19:03 +08:00
|
|
|
}
|
|
|
|
|
2023-03-03 17:20:33 +08:00
|
|
|
|
|
|
|
void CPUDialog::on_cbCallStack_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
if (mSetting)
|
|
|
|
return ;
|
|
|
|
pMainWindow->switchCurrentStackTrace(index);
|
|
|
|
}
|
|
|
|
|