From 62527a04ae0f39734c77872db9e7f07f32a4b163 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 1 Aug 2021 23:24:37 +0800 Subject: [PATCH] work save --- RedPandaIDE/RedPandaIDE.pro | 9 +- RedPandaIDE/compiler/compilermanager.cpp | 7 +- RedPandaIDE/compiler/executablerunner.cpp | 6 +- RedPandaIDE/cpudialog.cpp | 14 -- RedPandaIDE/cpudialog.h | 22 -- RedPandaIDE/debugger.cpp | 135 ++++++++++-- RedPandaIDE/debugger.h | 29 ++- RedPandaIDE/editorlist.cpp | 7 +- RedPandaIDE/main.cpp | 1 + RedPandaIDE/mainwindow.cpp | 60 ++++-- RedPandaIDE/mainwindow.h | 8 + RedPandaIDE/mainwindow.ui | 33 ++- RedPandaIDE/settings.cpp | 91 +++++++- RedPandaIDE/settings.h | 38 +++- .../settingsdialog/debuggeneralwidget.cpp | 52 +++++ .../settingsdialog/debuggeneralwidget.h | 30 +++ .../settingsdialog/debuggeneralwidget.ui | 202 ++++++++++++++++++ RedPandaIDE/settingsdialog/settingsdialog.cpp | 5 + RedPandaIDE/settingsdialog/settingsdialog.h | 16 +- RedPandaIDE/widgets/cpudialog.cpp | 83 +++++++ RedPandaIDE/widgets/cpudialog.h | 33 +++ RedPandaIDE/{ => widgets}/cpudialog.ui | 31 ++- 22 files changed, 790 insertions(+), 122 deletions(-) delete mode 100644 RedPandaIDE/cpudialog.cpp delete mode 100644 RedPandaIDE/cpudialog.h create mode 100644 RedPandaIDE/settingsdialog/debuggeneralwidget.cpp create mode 100644 RedPandaIDE/settingsdialog/debuggeneralwidget.h create mode 100644 RedPandaIDE/settingsdialog/debuggeneralwidget.ui create mode 100644 RedPandaIDE/widgets/cpudialog.cpp create mode 100644 RedPandaIDE/widgets/cpudialog.h rename RedPandaIDE/{ => widgets}/cpudialog.ui (88%) diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 5a2df661..375f09c4 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -16,7 +16,8 @@ SOURCES += \ compiler/executablerunner.cpp \ compiler/filecompiler.cpp \ compiler/stdincompiler.cpp \ - cpudialog.cpp \ + settingsdialog/debuggeneralwidget.cpp \ + widgets/cpudialog.cpp \ debugger.cpp \ editor.cpp \ editorlist.cpp \ @@ -67,7 +68,8 @@ HEADERS += \ compiler/executablerunner.h \ compiler/filecompiler.h \ compiler/stdincompiler.h \ - cpudialog.h \ + settingsdialog/debuggeneralwidget.h \ + widgets/cpudialog.h \ debugger.h \ editor.h \ editorlist.h \ @@ -112,7 +114,8 @@ HEADERS += \ widgets/qpatchedcombobox.h FORMS += \ - cpudialog.ui \ + settingsdialog/debuggeneralwidget.ui \ + widgets/cpudialog.ui \ mainwindow.ui \ settingsdialog/compilersetdirectorieswidget.ui \ settingsdialog/compilersetoptionwidget.ui \ diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 612950d3..fbf4b45e 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -99,8 +99,8 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con } else { mRunner = new ExecutableRunner(filename,arguments,workDir); } - connect(mRunner, &ExecutableRunner::terminated, this ,&CompilerManager::onRunnerTerminated); - connect(mRunner, &ExecutableRunner::terminated, pMainWindow ,&MainWindow::onRunFinished); + connect(mRunner, &ExecutableRunner::finished, this ,&CompilerManager::onRunnerTerminated); + connect(mRunner, &ExecutableRunner::finished, pMainWindow ,&MainWindow::onRunFinished); connect(mRunner, &ExecutableRunner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured); mRunner->start(); } @@ -134,8 +134,9 @@ void CompilerManager::onCompileFinished() void CompilerManager::onRunnerTerminated() { QMutexLocker locker(&mRunnerMutex); - delete mRunner; + ExecutableRunner* p=mRunner; mRunner=nullptr; + p->deleteLater(); } void CompilerManager::onCompileIssue(PCompileIssue) diff --git a/RedPandaIDE/compiler/executablerunner.cpp b/RedPandaIDE/compiler/executablerunner.cpp index 96f7cf77..8916e664 100644 --- a/RedPandaIDE/compiler/executablerunner.cpp +++ b/RedPandaIDE/compiler/executablerunner.cpp @@ -49,8 +49,12 @@ void ExecutableRunner::run() break; } if (mStop) { + process.closeReadChannel(QProcess::StandardOutput); + process.closeReadChannel(QProcess::StandardError); + process.closeWriteChannel(); process.terminate(); - //break; + process.kill(); + break; } if (errorOccurred) break; diff --git a/RedPandaIDE/cpudialog.cpp b/RedPandaIDE/cpudialog.cpp deleted file mode 100644 index 5c8d5855..00000000 --- a/RedPandaIDE/cpudialog.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "cpudialog.h" -#include "ui_cpudialog.h" - -CPUDialog::CPUDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::CPUDialog) -{ - ui->setupUi(this); -} - -CPUDialog::~CPUDialog() -{ - delete ui; -} diff --git a/RedPandaIDE/cpudialog.h b/RedPandaIDE/cpudialog.h deleted file mode 100644 index 645a7acb..00000000 --- a/RedPandaIDE/cpudialog.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef CPUDIALOG_H -#define CPUDIALOG_H - -#include - -namespace Ui { -class CPUDialog; -} - -class CPUDialog : public QDialog -{ - Q_OBJECT - -public: - explicit CPUDialog(QWidget *parent = nullptr); - ~CPUDialog(); - -private: - Ui::CPUDialog *ui; -}; - -#endif // CPUDIALOG_H diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 53215f2b..df04953d 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -3,7 +3,7 @@ #include "mainwindow.h" #include "editor.h" #include "settings.h" -#include "cpudialog.h" +#include "widgets/cpudialog.h" #include #include @@ -16,6 +16,7 @@ Debugger::Debugger(QObject *parent) : QObject(parent) mBreakpointModel=new BreakpointModel(this); mBacktraceModel=new BacktraceModel(this); mWatchModel = new WatchModel(this); + mRegisterModel = new RegisterModel(this); mExecuting = false; mUseUTF8 = false; mReader = nullptr; @@ -74,8 +75,9 @@ void Debugger::clearUpReader() // MainForm.LeftPageControl.ActivePageIndex := LeftPageIndexBackup; // // Close CPU window -// if Assigned(CPUForm) then -// CPUForm.Close; + if (pMainWindow->cpuDialog()!=nullptr) { + pMainWindow->cpuDialog()->close(); + } // Free resources pMainWindow->removeActiveBreakpoints(); @@ -84,6 +86,8 @@ void Debugger::clearUpReader() pMainWindow->updateAppTitle(); + pMainWindow->updateDebugEval(""); + mBacktraceModel->clear(); for(PWatchVar var:mWatchModel->watchVars()) { @@ -109,6 +113,11 @@ void Debugger::onClearLocals() pMainWindow->txtLocals()->clear(); } +RegisterModel *Debugger::registerModel() const +{ + return mRegisterModel; +} + WatchModel *Debugger::watchModel() const { return mWatchModel; @@ -391,7 +400,9 @@ void Debugger::syncFinishedParsing() // An evaluation variable has been processed. Forward the results if (mReader->doevalready) { - emit evalReady(mReader->mEvalValue); + pMainWindow->updateDebugEval(mReader->mEvalValue); + mReader->mEvalValue=""; + mReader->doevalready = false; } // show command output @@ -427,12 +438,18 @@ void Debugger::syncFinishedParsing() } // Some part of the CPU form has been updated - if (pMainWindow->cpuDialog()->isVisible() && !mReader->doreceivedsignal) { -// if (mReader->doregistersready) -// CPUForm.OnRegistersReady; + if (pMainWindow->cpuDialog()!=nullptr && !mReader->doreceivedsignal) { + if (mReader->doregistersready) { + mRegisterModel->update(mReader->mRegisters); + mReader->mRegisters.clear(); + mReader->doregistersready = false; + } -// if (mReader->dodisassemblerready) -// CPUForm.OnAssemblerReady; + if (mReader->dodisassemblerready) { + pMainWindow->cpuDialog()->setDisassembly(mReader->mDisassembly); + mReader->mDisassembly.clear(); + mReader->dodisassemblerready = false; + } } if (mReader->doupdateexecution) { @@ -477,9 +494,8 @@ void Debugger::syncFinishedParsing() // CPU form updates itself when spawned, don't update twice! - if ((mReader->doupdatecpuwindow && !spawnedcpuform) && (pMainWindow->cpuDialog()->isVisible())) { - sendCommand("disas", ""); - sendCommand("info registers", ""); + if ((mReader->doupdatecpuwindow && !spawnedcpuform) && (pMainWindow->cpuDialog()!=nullptr)) { + pMainWindow->cpuDialog()->updateInfo(); } } @@ -573,12 +589,11 @@ AnnotationType DebugReader::getAnnotation(const QString &s) } else if ((mCurrentCmd) && (mCurrentCmd->command == "info args")) { //hack to catch params result = AnnotationType::TParam; - } else if (t.startsWith("rax ") || t.startsWith("eax ")) { + } else if ((mCurrentCmd) && (mCurrentCmd->command == "info") && (mCurrentCmd->params=="registers")) { // Hack fix to catch register dump result = AnnotationType::TInfoReg; - } else { - // Another hack to catch assembler - if (t.startsWith("Dump of assembler code for function ")) + } else if ((mCurrentCmd) && (mCurrentCmd->command == "disas")) { + // Another hack to catch assembler result = AnnotationType::TInfoAsm; } return result; @@ -750,9 +765,6 @@ QString DebugReader::getRemainingLine() void DebugReader::handleDisassembly() { - if (mDisassembly.isEmpty()) - return; - // Get info message QString s = getNextLine(); @@ -762,7 +774,7 @@ void DebugReader::handleDisassembly() s = getNextLine(); // Add lines of disassembly - while (!s.isEmpty() && (s != "End of assembler dump")) { + while (!s.isEmpty() && (s != "End of assembler dump.")) { mDisassembly.append(s); s = getNextLine(); } @@ -941,7 +953,7 @@ void DebugReader::handleRegisters() PRegister reg = std::make_shared(); // Cut name from 1 to first space int x = s.indexOf(' '); - reg->name = s.mid(0,x-1); + reg->name = s.mid(0,x); s.remove(0,x); // Remove spaces s = TrimLeft(s); @@ -950,14 +962,15 @@ void DebugReader::handleRegisters() x = s.indexOf('\t'); if (x<0) x = s.indexOf(' '); - reg->hexValue = s.mid(0,x - 1); + reg->hexValue = s.mid(0,x); s.remove(0,x); // delete tab too s = TrimLeft(s); // Remaining part contains decimal value reg->decValue = s; - mRegisters.append(reg); + if (!reg->name.trimmed().isEmpty()) + mRegisters.append(reg); s = getNextLine(); if (s.isEmpty()) break; @@ -1350,7 +1363,11 @@ void DebugReader::run() break; } if (mStop) { + mProcess->closeReadChannel(QProcess::StandardOutput); + mProcess->closeReadChannel(QProcess::StandardError); + mProcess->closeWriteChannel(); mProcess->terminate(); + mProcess->kill(); break; } if (errorOccurred) @@ -1722,3 +1739,75 @@ void WatchModel::notifyUpdated(PWatchVar var) qDebug()<<"dataChanged"<text; emit dataChanged(createIndex(row,0,var.get()),createIndex(row,0,var.get())); } + +RegisterModel::RegisterModel(QObject *parent):QAbstractTableModel(parent) +{ + +} + +int RegisterModel::rowCount(const QModelIndex &parent) const +{ + return mRegisters.count(); +} + +int RegisterModel::columnCount(const QModelIndex &parent) const +{ + return 3; +} + +QVariant RegisterModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + if (index.row()<0 || index.row() >= static_cast(mRegisters.size())) + return QVariant(); + PRegister reg = mRegisters[index.row()]; + if (!reg) + return QVariant(); + switch (role) { + case Qt::DisplayRole: + switch (index.column()) { + case 0: + return reg->name; + case 1: + return reg->hexValue; + case 2: + return reg->decValue; + default: + return QVariant(); + } + default: + return QVariant(); + } +} + +QVariant RegisterModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { + switch(section) { + case 0: + return tr("Register"); + case 1: + return tr("Value(Hex)"); + case 2: + return tr("Value(Dec)"); + } + } + return QVariant(); +} + +void RegisterModel::update(const QList ®s) +{ + beginResetModel(); + mRegisters.clear(); + mRegisters.append(regs); + endResetModel(); +} + + +void RegisterModel::clear() +{ + beginResetModel(); + mRegisters.clear(); + endResetModel(); +} diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index 0fc4e2cd..cf5a2def 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -82,6 +82,20 @@ struct Register { using PRegister = std::shared_ptr; +class RegisterModel: public QAbstractTableModel { + Q_OBJECT +public: + explicit RegisterModel(QObject* parent = nullptr); + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + void update(const QList& regs); + void clear(); +private: + QList mRegisters; +}; + class BreakpointModel: public QAbstractTableModel { Q_OBJECT // QAbstractItemModel interface @@ -199,10 +213,10 @@ public: WatchModel *watchModel() const; + RegisterModel *registerModel() const; + public slots: void stop(); -signals: - void evalReady(QString value); private: void sendWatchCommand(PWatchVar var); @@ -221,11 +235,12 @@ private slots: private: bool mExecuting; bool mCommandChanged; - BreakpointModel* mBreakpointModel; + BreakpointModel *mBreakpointModel; bool mUseUTF8; - BacktraceModel* mBacktraceModel; - WatchModel* mWatchModel; - DebugReader* mReader; + BacktraceModel *mBacktraceModel; + WatchModel *mWatchModel; + RegisterModel *mRegisterModel; + DebugReader *mReader; int mLeftPageIndexBackup; }; @@ -285,7 +300,7 @@ private: void skipSpaces(); void skipToAnnotation(); private: - Debugger* mDebugger; + Debugger *mDebugger; QString mDebuggerPath; QRecursiveMutex mCmdQueueMutex; QSemaphore mStartSemaphore; diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 24a45e7e..06e26cbb 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "settings.h" EditorList::EditorList(QTabWidget* leftPageWidget, QTabWidget* rightPageWidget, @@ -86,7 +87,11 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) { //todo: activate & focus the previous editor } - delete editor; + if (pSettings->history().addToOpenedFiles(editor->filename())) { + pMainWindow->rebuildOpenedFileHisotryMenu(); + } + + editor->deleteLater(); return true; } diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index 04c0b0d8..251543b9 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -70,6 +70,7 @@ int main(int argc, char *argv[]) settings->editor().load(); settings->executor().load(); settings->debugger().load(); + settings->history().load(); //Translation must be loaded after language setting is loaded QTranslator trans; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 6607032e..2b1479a1 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -6,7 +6,7 @@ #include "settings.h" #include "qsynedit/Constants.h" #include "debugger.h" -#include "cpudialog.h" +#include "widgets/cpudialog.h" #include @@ -87,7 +87,7 @@ MainWindow::MainWindow(QWidget *parent) ui->actionEncode_in_ANSI->setCheckable(true); ui->actionEncode_in_UTF_8->setCheckable(true); - mCPUDialog = new CPUDialog(this); + mCPUDialog = nullptr; updateEditorActions(); applySettings(); @@ -95,6 +95,7 @@ MainWindow::MainWindow(QWidget *parent) openCloseMessageSheet(false); mPreviousHeight = 250; + connect(ui->debugConsole,&QConsole::commandInput,this,&MainWindow::onDebugCommandInput); } MainWindow::~MainWindow() @@ -227,6 +228,7 @@ void MainWindow::applySettings() QApplication * app = dynamic_cast(QApplication::instance()); app->setFont(font); this->setFont(font); + updateDebuggerSettings(); } void MainWindow::removeActiveBreakpoints() @@ -322,6 +324,12 @@ void MainWindow::changeDebugOutputLastline(const QString &test) ui->debugConsole->changeLastLine(test); } +void MainWindow::updateDebugEval(const QString &value) +{ + ui->txtEvalOutput->clear(); + ui->txtEvalOutput->appendPlainText(value); +} + QPlainTextEdit *MainWindow::txtLocals() { return ui->txtLocals; @@ -403,6 +411,13 @@ void MainWindow::updateCompilerSet() mCompilerSet->setCurrentIndex(index); } +void MainWindow::updateDebuggerSettings() +{ + ui->debugConsole->setFont(QFont( + pSettings->debugger().fontName(), + pSettings->debugger().fontSize())); +} + void MainWindow::checkSyntaxInBack(Editor *e) { if (e==nullptr) @@ -1059,6 +1074,20 @@ void MainWindow::onRunFinished() updateAppTitle(); } +void MainWindow::cleanUpCPUDialog() +{ + CPUDialog* ptr=mCPUDialog; + mCPUDialog=nullptr; + ptr->deleteLater(); +} + +void MainWindow::onDebugCommandInput(const QString &command) +{ + if (mDebugger->executing()) { + mDebugger->sendCommand(command,""); + } +} + void MainWindow::on_actionCompile_triggered() { mCompileSuccessionTask.reset(); @@ -1331,8 +1360,6 @@ void MainWindow::on_actionStep_Over_triggered() mDebugger->invalidateAllVars(); mDebugger->sendCommand("next", ""); mDebugger->updateDebugInfo(); -// if (CPUForm) then -// CPUForm.UpdateInfo; mDebugger->refreshWatchVars(); } } @@ -1344,8 +1371,6 @@ void MainWindow::on_actionStep_Into_triggered() mDebugger->invalidateAllVars(); mDebugger->sendCommand("step", ""); mDebugger->updateDebugInfo(); -// if (CPUForm) then -// CPUForm.UpdateInfo; mDebugger->refreshWatchVars(); } @@ -1358,8 +1383,6 @@ void MainWindow::on_actionStep_Out_triggered() mDebugger->invalidateAllVars(); mDebugger->sendCommand("finish", ""); mDebugger->updateDebugInfo(); -// if (CPUForm) then -// CPUForm.UpdateInfo; mDebugger->refreshWatchVars(); } @@ -1375,8 +1398,6 @@ void MainWindow::on_actionRun_To_Cursor_triggered() mDebugger->sendCommand("tbreak", QString(" %1").arg(e->caretY())); mDebugger->sendCommand("continue", ""); mDebugger->updateDebugInfo(); - // if (CPUForm) then - // CPUForm.UpdateInfo; mDebugger->refreshWatchVars(); } } @@ -1390,8 +1411,6 @@ void MainWindow::on_actionContinue_triggered() mDebugger->invalidateAllVars(); mDebugger->sendCommand("continue", ""); mDebugger->updateDebugInfo(); -// if (CPUForm) then -// CPUForm.UpdateInfo; mDebugger->refreshWatchVars(); } } @@ -1420,3 +1439,20 @@ void MainWindow::on_actionAdd_Watch_triggered() mDebugger->addWatchVar(s); } } + +void MainWindow::on_actionView_CPU_Window_triggered() +{ + if (mCPUDialog==nullptr) { + mCPUDialog = new CPUDialog(this); + connect(mCPUDialog, &CPUDialog::closed, this, &MainWindow::cleanUpCPUDialog); + } + mCPUDialog->show(); +} + +void MainWindow::on_txtEvaludate_returnPressed() +{ + QString s=ui->txtEvaludate->text().trimmed(); + if (!s.isEmpty()) { + mDebugger->sendCommand("print",s,false); + } +} diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index e12fd9a4..55e03f82 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -52,6 +52,7 @@ public: void updateCompileActions(); void updateEditorColorSchemes(); void updateCompilerSet(); + void updateDebuggerSettings(); void checkSyntaxInBack(Editor* e); bool compile(bool rebuild=false); void runExecutable(const QString& exeName, const QString& filename=QString()); @@ -65,6 +66,7 @@ public: void updateAppTitle(); void addDebugOutput(const QString& text); void changeDebugOutputLastline(const QString& text); + void updateDebugEval(const QString& value); QPlainTextEdit* txtLocals(); @@ -159,6 +161,10 @@ private slots: void on_actionAdd_Watch_triggered(); + void on_actionView_CPU_Window_triggered(); + + void on_txtEvaludate_returnPressed(); + public slots: void onCompileLog(const QString& msg); void onCompileIssue(PCompileIssue issue); @@ -166,6 +172,8 @@ public slots: void onCompileErrorOccured(const QString& reason); void onRunErrorOccured(const QString& reason); void onRunFinished(); + void cleanUpCPUDialog(); + void onDebugCommandInput(const QString& command); private: void setupActions(); diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 47c493c9..703cf0ff 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -393,14 +393,7 @@ - - - - 0 - 0 - - - + @@ -415,8 +408,11 @@ + + QTabWidget::North + - 3 + 2 @@ -465,7 +461,11 @@ 0 - + + + Qt::ElideNone + + @@ -487,7 +487,11 @@ 0 - + + + Qt::ElideNone + + @@ -584,7 +588,9 @@ + + @@ -1067,6 +1073,11 @@ Add Watch... + + + View CPU Window... + + diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index a73dab77..7addfeb8 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -98,6 +98,11 @@ QString Settings::filename() const return mFilename; } +Settings::History& Settings::history() +{ + return mHistory; +} + Settings::Debugger& Settings::debugger() { return mDebugger; @@ -187,6 +192,11 @@ int Settings::_Base::intValue(const QString &key, int defaultValue) return value(key,defaultValue).toInt(); } +QStringList Settings::_Base::stringListValue(const QString &key, const QStringList &defaultValue) +{ + return value(key,defaultValue).toStringList(); +} + QColor Settings::_Base::colorValue(const QString &key, const QColor& defaultValue) { return value(key,defaultValue).value(); @@ -2275,14 +2285,93 @@ void Settings::Debugger::setShowAnnotations(bool showAnnotations) mShowAnnotations = showAnnotations; } +QString Settings::Debugger::fontName() const +{ + return mFontName; +} + +void Settings::Debugger::setFontName(const QString &fontName) +{ + mFontName = fontName; +} + +bool Settings::Debugger::useIntelStyle() const +{ + return mUseIntelStyle; +} + +void Settings::Debugger::setUseIntelStyle(bool useIntelStyle) +{ + mUseIntelStyle = useIntelStyle; +} + +int Settings::Debugger::fontSize() const +{ + return mFontSize; +} + +void Settings::Debugger::setFontSize(int fontSize) +{ + mFontSize = fontSize; +} + +bool Settings::Debugger::onlyShowMono() const +{ + return mOnlyShowMono; +} + +void Settings::Debugger::setOnlyShowMono(bool onlyShowMono) +{ + mOnlyShowMono = onlyShowMono; +} + void Settings::Debugger::doSave() { saveValue("show_command_log", mShowCommandLog); saveValue("show_annotations", mShowAnnotations); + saveValue("font_name",mFontName); + saveValue("only_show_mono",mOnlyShowMono); + saveValue("font_size",mFontSize); + boolValue("use_intel_style",mUseIntelStyle); } void Settings::Debugger::doLoad() { mShowCommandLog = boolValue("show_command_log",true); - mShowAnnotations = boolValue("show_annotations",true); + mShowAnnotations = boolValue("show_annotations",false); + mFontName = stringValue("font_name","Consolas"); + mOnlyShowMono = boolValue("only_show_mono",true); + mFontSize = intValue("font_size",10); + mUseIntelStyle = boolValue("use_intel_style",true); +} + +Settings::History::History(Settings *settings):_Base(settings, SETTING_HISTORY) +{ + +} + +bool Settings::History::addToOpenedFiles(const QString &filename) +{ + if (!QFile(filename).exists()) + return false; + if (openedFiles().indexOf(filename)>=0) + return false; + if (openedFiles().size()>=15) { + openedFiles().pop_front(); + } + openedFiles().append(filename); + return true; + +} + +void Settings::History::doSave() +{ + saveValue("opened_files", mOpenedFiles); + saveValue("opened_projects", mOpenedProjects); +} + +void Settings::History::doLoad() +{ + mOpenedFiles = stringListValue("opened_files"); + mOpenedProjects =stringListValue("opened_projects"); } diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 92e268d8..8b22111c 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -17,6 +17,7 @@ #define SETTING_ENVIRONMENT "Environment" #define SETTING_EXECUTOR "Executor" #define SETTING_DEBUGGER "Debugger" +#define SETTING_HISTORY "HISTORY" #define SETTING_COMPILTER_SETS "CompilerSets" #define SETTING_COMPILTER_SETS_DEFAULT_INDEX "defaultIndex" #define SETTING_COMPILTER_SETS_COUNT "count" @@ -57,6 +58,7 @@ private: QVariant value(const QString &key, const QVariant& defaultValue); bool boolValue(const QString &key, bool defaultValue); int intValue(const QString &key, int defaultValue); + QStringList stringListValue(const QString &key, const QStringList& defaultValue=QStringList()); QColor colorValue(const QString &key, const QColor& defaultValue); QString stringValue(const QString &key, const QString& defaultValue); void save(); @@ -369,6 +371,23 @@ public: void doLoad() override; }; + class History: public _Base { + public: + explicit History(Settings *settings); + + QStringList& openedFiles(); + QStringList& openedProjects(); + bool addToOpenedFiles(const QString& filename); + private: + QStringList mOpenedFiles; + QStringList mOpenedProjects; + + // _Base interface + protected: + void doSave() override; + void doLoad() override; + }; + class Executor: public _Base { public: explicit Executor(Settings * settings); @@ -398,9 +417,25 @@ public: bool showAnnotations() const; void setShowAnnotations(bool showAnnotations); + bool onlyShowMono() const; + void setOnlyShowMono(bool onlyShowMono); + + int fontSize() const; + void setFontSize(int fontSize); + + bool useIntelStyle() const; + void setUseIntelStyle(bool useIntelStyle); + + QString fontName() const; + void setFontName(const QString &fontName); + private: bool mShowCommandLog; bool mShowAnnotations; + QString mFontName; + bool mOnlyShowMono; + int mFontSize; + bool mUseIntelStyle; // _Base interface protected: @@ -585,9 +620,9 @@ public: Environment& environment(); Executor& executor(); Debugger& debugger(); + History& history(); QString filename() const; - private: QString mFilename; QSettings mSettings; @@ -597,6 +632,7 @@ private: CompilerSets mCompilerSets; Executor mExecutor; Debugger mDebugger; + History mHistory; }; diff --git a/RedPandaIDE/settingsdialog/debuggeneralwidget.cpp b/RedPandaIDE/settingsdialog/debuggeneralwidget.cpp new file mode 100644 index 00000000..97599cf9 --- /dev/null +++ b/RedPandaIDE/settingsdialog/debuggeneralwidget.cpp @@ -0,0 +1,52 @@ +#include "debuggeneralwidget.h" +#include "ui_debuggeneralwidget.h" +#include "../settings.h" +#include "../mainwindow.h" + +DebugGeneralWidget::DebugGeneralWidget(const QString& name, const QString& group, QWidget *parent) : + SettingsWidget(name,group,parent), + ui(new Ui::DebugGeneralWidget) +{ + ui->setupUi(this); +} + +DebugGeneralWidget::~DebugGeneralWidget() +{ + delete ui; +} + +void DebugGeneralWidget::doLoad() +{ + ui->chkOnlyMono->setChecked(pSettings->debugger().onlyShowMono()); + ui->cbFont->setCurrentFont(QFont(pSettings->debugger().fontName())); + ui->sbFontSize->setValue(pSettings->debugger().fontSize()); + ui->chkShowLog->setChecked(pSettings->debugger().showCommandLog()); + ui->chkShowFullAnnotation->setChecked(pSettings->debugger().showAnnotations()); + if (pSettings->debugger().useIntelStyle()) { + ui->rbIntel->setChecked(true); + } else { + ui->rbATT->setChecked(true); + } +} + +void DebugGeneralWidget::doSave() +{ + pSettings->debugger().setOnlyShowMono(ui->chkOnlyMono->isChecked()); + pSettings->debugger().setFontName(ui->cbFont->currentFont().family()); + pSettings->debugger().setFontSize(ui->sbFontSize->value()); + pSettings->debugger().setShowCommandLog(ui->chkShowLog->isChecked()); + pSettings->debugger().setShowAnnotations(ui->chkShowFullAnnotation->isChecked()); + pSettings->debugger().setUseIntelStyle(ui->rbIntel->isChecked()); + + pSettings->debugger().save(); + pMainWindow->updateDebuggerSettings(); +} + +void DebugGeneralWidget::on_chkOnlyMono_stateChanged(int) +{ + if (ui->chkOnlyMono->isChecked()) { + ui->cbFont->setFontFilters(QFontComboBox::FontFilter::MonospacedFonts); + } else { + ui->cbFont->setFontFilters(QFontComboBox::FontFilter::AllFonts); + } +} diff --git a/RedPandaIDE/settingsdialog/debuggeneralwidget.h b/RedPandaIDE/settingsdialog/debuggeneralwidget.h new file mode 100644 index 00000000..a8c84dbd --- /dev/null +++ b/RedPandaIDE/settingsdialog/debuggeneralwidget.h @@ -0,0 +1,30 @@ +#ifndef DEBUGGENERALWIDGET_H +#define DEBUGGENERALWIDGET_H + +#include +#include "settingswidget.h" + +namespace Ui { +class DebugGeneralWidget; +} + +class DebugGeneralWidget : public SettingsWidget +{ + Q_OBJECT + +public: + explicit DebugGeneralWidget(const QString& name, const QString& group, QWidget *parent = nullptr); + ~DebugGeneralWidget(); + +private: + Ui::DebugGeneralWidget *ui; + + // SettingsWidget interface +protected: + void doLoad() override; + void doSave() override; +private slots: + void on_chkOnlyMono_stateChanged(int arg1); +}; + +#endif // DEBUGGENERALWIDGET_H diff --git a/RedPandaIDE/settingsdialog/debuggeneralwidget.ui b/RedPandaIDE/settingsdialog/debuggeneralwidget.ui new file mode 100644 index 00000000..a9adc70e --- /dev/null +++ b/RedPandaIDE/settingsdialog/debuggeneralwidget.ui @@ -0,0 +1,202 @@ + + + DebugGeneralWidget + + + + 0 + 0 + 677 + 563 + + + + Form + + + + + + Debug Console + + + + 11 + + + 11 + + + 11 + + + 11 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Font: + + + + + + + + + + Show only monospaced fonts + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Size: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + Show debug logs in the debug console + + + + + + + Show full gdb annotations + + + + + + + + + + Disassembly Coding Style + + + + 11 + + + 11 + + + 11 + + + 11 + + + + + Intel + + + grpCPUDisassembly + + + + + + + AT&&T + + + grpCPUDisassembly + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index 7cffe955..8701feca 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -10,6 +10,7 @@ #include "editorsymbolcompletionwidget.h" #include "environmentappearencewidget.h" #include "executorgeneralwidget.h" +#include "debuggeneralwidget.h" #include #include #include @@ -63,6 +64,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) : pExecutorGeneralWidget->init(); addWidget(pExecutorGeneralWidget); + pDebugGeneralWidget = new DebugGeneralWidget(tr("General"),tr("Debugger")); + pDebugGeneralWidget->init(); + addWidget(pDebugGeneralWidget); + ui->widgetsView->expandAll(); //select the first widget of the first group auto groupIndex = ui->widgetsView->model()->index(0,0); diff --git a/RedPandaIDE/settingsdialog/settingsdialog.h b/RedPandaIDE/settingsdialog/settingsdialog.h index 0496491a..21166d07 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.h +++ b/RedPandaIDE/settingsdialog/settingsdialog.h @@ -19,6 +19,7 @@ class EditorColorSchemeWidget; class EditorSyntaxCheckWidget; class EnvironmentAppearenceWidget; class ExecutorGeneralWidget; +class DebugGeneralWidget; class SettingsWidget; class SettingsDialog : public QDialog { @@ -48,15 +49,16 @@ private: QList mSettingWidgets; QStandardItemModel model; - CompilerSetOptionWidget* pCompilerSetOptionWidget; - EditorGeneralWidget* pEditorGeneralWidget; - EditorFontWidget* pEditorFontWidget; + CompilerSetOptionWidget *pCompilerSetOptionWidget; + EditorGeneralWidget *pEditorGeneralWidget; + EditorFontWidget *pEditorFontWidget; EditorClipboardWidget *pEditorClipboardWidget; EditorColorSchemeWidget *pEditorColorSchemeWidget; - EnvironmentAppearenceWidget* pEnvironmentAppearenceWidget; - EditorSymbolCompletionWidget* pEditorSymbolCompletionWidget; - EditorSyntaxCheckWidget* pEditorSyntaxCheckWidget; - ExecutorGeneralWidget * pExecutorGeneralWidget; + EnvironmentAppearenceWidget *pEnvironmentAppearenceWidget; + EditorSymbolCompletionWidget *pEditorSymbolCompletionWidget; + EditorSyntaxCheckWidget *pEditorSyntaxCheckWidget; + ExecutorGeneralWidget *pExecutorGeneralWidget; + DebugGeneralWidget *pDebugGeneralWidget; }; #endif // SETTINGSDIALOG_H diff --git a/RedPandaIDE/widgets/cpudialog.cpp b/RedPandaIDE/widgets/cpudialog.cpp new file mode 100644 index 00000000..2cf03223 --- /dev/null +++ b/RedPandaIDE/widgets/cpudialog.cpp @@ -0,0 +1,83 @@ +#include "cpudialog.h" +#include "ui_cpudialog.h" +#include "../HighlighterManager.h" +#include "../mainwindow.h" +#include "../debugger.h" +#include "../settings.h" + +CPUDialog::CPUDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CPUDialog) +{ + ui->setupUi(this); + ui->txtCode->setHighlighter(highlighterManager.getAsmHighlighter()); + highlighterManager.applyColorScheme(ui->txtCode->highlighter(), + pSettings->editor().colorScheme()); + ui->lstRegister->setModel(pMainWindow->debugger()->registerModel()); + + ui->rdIntel->setChecked(true); +// RadioATT.Checked := devData.UseATTSyntax; +// RadioIntel.Checked := not devData.UseATTSyntax; + +// fRegisters := TList.Create; +// fAssembler := TStringList.Create; + updateInfo(); +} + +CPUDialog::~CPUDialog() +{ + delete ui; +} + +void CPUDialog::updateInfo() +{ + if (pMainWindow->debugger()->executing()) { + // Load the registers.. + sendSyntaxCommand(); + pMainWindow->debugger()->sendCommand("info", "registers"); + pMainWindow->debugger()->sendCommand("disas", ""); + } +} + +void CPUDialog::setDisassembly(const QStringList &lines) +{ + if (lines.size()>0) { + ui->txtFunctionName->setText(lines[0]); + } + int activeLine = -1; + for (int i=1;i")) { + activeLine = i; + } + ui->txtCode->lines()->add(line); + } + if (activeLine!=-1) + ui->txtCode->setCaretXY(BufferCoord{1,activeLine}); +} + +void CPUDialog::sendSyntaxCommand() +{ + // Set disassembly flavor + if (ui->rdIntel->isChecked()) { + pMainWindow->debugger()->sendCommand("set disassembly-flavor", "intel"); + } else { + pMainWindow->debugger()->sendCommand("set disassembly-flavor", "att"); + } +} + +void CPUDialog::closeEvent(QCloseEvent *event) +{ + QDialog::closeEvent(event); + emit closed(); +} + +void CPUDialog::on_rdIntel_toggled(bool) +{ + sendSyntaxCommand(); +} + +void CPUDialog::on_rdATT_toggled(bool) +{ + sendSyntaxCommand(); +} diff --git a/RedPandaIDE/widgets/cpudialog.h b/RedPandaIDE/widgets/cpudialog.h new file mode 100644 index 00000000..c8de9777 --- /dev/null +++ b/RedPandaIDE/widgets/cpudialog.h @@ -0,0 +1,33 @@ +#ifndef CPUDIALOG_H +#define CPUDIALOG_H + +#include + +namespace Ui { +class CPUDialog; +} + +class CPUDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CPUDialog(QWidget *parent = nullptr); + ~CPUDialog(); + void updateInfo(); + void setDisassembly(const QStringList& lines); +signals: + void closed(); +private: + void sendSyntaxCommand(); +private: + Ui::CPUDialog *ui; + // QWidget interface +protected: + void closeEvent(QCloseEvent *event) override; +private slots: + void on_rdIntel_toggled(bool checked); + void on_rdATT_toggled(bool checked); +}; + +#endif // CPUDIALOG_H diff --git a/RedPandaIDE/cpudialog.ui b/RedPandaIDE/widgets/cpudialog.ui similarity index 88% rename from RedPandaIDE/cpudialog.ui rename to RedPandaIDE/widgets/cpudialog.ui index 8033da3a..60101614 100644 --- a/RedPandaIDE/cpudialog.ui +++ b/RedPandaIDE/widgets/cpudialog.ui @@ -11,7 +11,7 @@ - Dialog + CPU Info @@ -28,12 +28,6 @@ - - - 0 - 0 - - Qt::Horizontal @@ -86,7 +80,7 @@ - + 0 @@ -154,21 +148,26 @@ - - - - 1 - 0 - + + + QAbstractItemView::NoEditTriggers - - 0 + + Qt::ElideNone + + + SynEdit + QFrame +
qsynedit/Synedit.h
+ 1 +
+