From b04972ddb40163c797d5580f9f144539b28db599 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Tue, 27 Jul 2021 00:14:24 +0800 Subject: [PATCH] work save --- RedPandaIDE/debugger.cpp | 38 ++++++++++++++++++++++++-------------- RedPandaIDE/debugger.h | 7 ++++--- RedPandaIDE/editor.cpp | 13 ++++++++++--- RedPandaIDE/mainwindow.cpp | 4 ++-- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 63820a61..a9005573 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -14,6 +14,11 @@ Debugger::Debugger(QObject *parent) : QObject(parent) { mBreakpointModel=new BreakpointModel(this); mBacktraceModel=new BacktraceModel(this); + mExecuting = false; + mUseUTF8 = false; + mReader = nullptr; + mCommandChanged = false; + mLeftPageIndexBackup = -1; } void Debugger::start() @@ -39,7 +44,7 @@ void Debugger::start() connect(mReader, &QThread::finished,this,&Debugger::stop); connect(mReader, &DebugReader::parseFinished,this,&Debugger::syncFinishedParsing,Qt::BlockingQueuedConnection); mReader->start(); - + mReader->mStartSemaphore.acquire(1); //fProcessID := pi.hProcess; @@ -428,9 +433,12 @@ bool Debugger::executing() const return mExecuting; } -DebugReader::DebugReader(Debugger* debugger, QObject *parent) : QThread(parent) +DebugReader::DebugReader(Debugger* debugger, QObject *parent) : QThread(parent), + mStartSemaphore(0) { mDebugger = debugger; + mProcess = nullptr; + mUseUTF8 = false; } void DebugReader::postCommand(const QString &Command, const QString &Params, bool UpdateWatch, bool ShowInConsole, DebugCommandSource Source) @@ -1118,7 +1126,7 @@ void DebugReader::runNextCmd() s+=' '+pCmd->params.toLocal8Bit(); } s+= "\n"; - if (mProcess.write(s)<0) { + if (mProcess->write(s)<0) { emit writeToDebugFailed(); } @@ -1182,11 +1190,12 @@ void DebugReader::run() QString arguments = "--annotate=2 --silent"; QString workingDir = QFileInfo(mDebuggerPath).path(); - mProcess.setProgram(cmd); - mProcess.setArguments(QProcess::splitCommand(arguments)); - mProcess.setWorkingDirectory(workingDir); + mProcess = new QProcess(); + mProcess->setProgram(cmd); + mProcess->setArguments(QProcess::splitCommand(arguments)); + mProcess->setWorkingDirectory(workingDir); - mProcess.connect(&mProcess, &QProcess::errorOccurred, + connect(mProcess, &QProcess::errorOccurred, [&](){ errorOccurred= true; }); @@ -1199,20 +1208,21 @@ void DebugReader::run() // process.connect(&mProcess, QOverload::of(&QProcess::finished),[&process,this](){ // this->error(COMPILE_PROCESS_END); // }); - mProcess.start(); - mProcess.waitForStarted(5000); + mProcess->start(); + mProcess->waitForStarted(5000); + mStartSemaphore.release(1); QByteArray buffer; while (true) { - mProcess.waitForFinished(100); - if (mProcess.state()!=QProcess::Running) { + mProcess->waitForFinished(100); + if (mProcess->state()!=QProcess::Running) { break; } if (mStop) { - mProcess.terminate(); + mProcess->terminate(); } if (errorOccurred) break; - buffer += mProcess.readAll(); + buffer += mProcess->readAll(); if (getLastAnnotation(buffer) == AnnotationType::TPrompt) { mOutput = buffer; processDebugOutput(); @@ -1221,7 +1231,7 @@ void DebugReader::run() } } if (errorOccurred) { - emit processError(mProcess.error()); + emit processError(mProcess->error()); } } diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index 97e832a5..9cb9d1cf 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include enum class DebugCommandSource { @@ -240,7 +241,8 @@ private: private: Debugger* mDebugger; QString mDebuggerPath; - QMutex mCmdQueueMutex; + QRecursiveMutex mCmdQueueMutex; + QSemaphore mStartSemaphore; QQueue mCmdQueue; int mUpdateCount; bool mInvalidateAllVars; @@ -251,8 +253,7 @@ private: QList mRegisters; QStringList mDisassembly; - - QProcess mProcess; + QProcess* mProcess; QMap mWatchVarList; // contains all parents //fWatchView: TTreeView; diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 624a88db..6f3f6154 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -445,12 +445,18 @@ void Editor::onGetEditingAreas(int Line, SynEditingAreaList &areaList) bool Editor::onGetSpecialLineColors(int Line, QColor &foreground, QColor &backgroundColor) { - if (Line == mActiveBreakpointLine) { + if (Line == mActiveBreakpointLine && + mActiveBreakpointForegroundColor.isValid() + && mActiveBreakpointBackgroundColor.isValid()) { foreground = mActiveBreakpointForegroundColor; backgroundColor = mActiveBreakpointBackgroundColor; - } else if (hasBreakpoint(Line)) { + return true; + } else if (hasBreakpoint(Line) && + mBreakpointForegroundColor.isValid() + && mBreakpointBackgroundColor.isValid()) { foreground = mBreakpointForegroundColor; backgroundColor = mBreakpointBackgroundColor; + return true; } // end else if Line = fErrorLine then begin // StrToThemeColor(tc, devEditor.Syntax.Values[cErr]); @@ -459,6 +465,7 @@ bool Editor::onGetSpecialLineColors(int Line, QColor &foreground, QColor &backgr // if (BG <> clNone) or (FG<>clNone) then // Special := TRUE; // end; + return false; } void Editor::copyToClipboard() @@ -1333,7 +1340,7 @@ void Editor::applyColorScheme(const QString& schemeName) item = pColorManager->getItem(schemeName,COLOR_SCHEME_BREAKPOINT); if (item) { this->mBreakpointForegroundColor = item->foreground(); - this->mBreakpointBackgroundColor = item->foreground(); + this->mBreakpointBackgroundColor = item->background(); } this->invalidate(); } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index bf74b14a..86629138 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -596,12 +596,12 @@ void MainWindow::debug() case CompileTarget::File: // Check if we enabled proper options debugEnabled = compilerSet->getOptionValue("-g3")!='0'; - stripEnabled = compilerSet->getOptionValue("-s")!=0; + stripEnabled = compilerSet->getOptionValue("-s")!='0'; // Ask the user if he wants to enable debugging... if (((!debugEnabled) || stripEnabled) && (QMessageBox::question(this, tr("Enable debugging"), - tr("You have not enabled debugging info (-g) and/or stripped it from the executable (-s) in Compiler Options.

Do you want to correct this now?") + tr("You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.

Do you want to correct this now?") ) == QMessageBox::Yes)) { // Enable debugging, disable stripping compilerSet->setOption("-g3",'1');