From 13c79bb55d03bd86d5d3fe382fd037ee795e0d3a Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 29 Dec 2021 22:03:18 +0800 Subject: [PATCH] - enhancement: detach pausing console window - use "-var-update" gdb command instead of "noop" --- NEWS.md | 1 + RedPandaIDE/compiler/compilermanager.cpp | 17 ++++++- RedPandaIDE/compiler/compilermanager.h | 5 ++ RedPandaIDE/compiler/executablerunner.cpp | 56 ++++++++++------------- RedPandaIDE/compiler/executablerunner.h | 2 + RedPandaIDE/compiler/runner.cpp | 1 + RedPandaIDE/debugger.cpp | 2 +- RedPandaIDE/mainwindow.cpp | 1 + 8 files changed, 50 insertions(+), 35 deletions(-) diff --git a/NEWS.md b/NEWS.md index a274c0e0..e5455215 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ Version 0.12.5 For Dev-C++ 7 Beta - fix: wrong executable filename for source files in linux - enhancement: console pauser for linux - enhancement: redirect input to program in linux + - enhancement: detach pausing console window Version 0.12.4 For Dev-C++ 7 Beta - change: add copyright infos to each source file diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index c0721dcf..767d0a18 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -276,6 +276,7 @@ void CompilerManager::run(const QString &filename, const QString &arguments, con connect(mRunner, &Runner::finished, mRunner ,&Runner::deleteLater); connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished); connect(mRunner, &Runner::pausingForFinish, pMainWindow ,&MainWindow::onRunPausingForFinish); + connect(mRunner, &Runner::pausingForFinish, this ,&CompilerManager::onRunnerPausing); connect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured); mRunner->start(); } @@ -325,13 +326,17 @@ void CompilerManager::stopRun() } } +void CompilerManager::stopAllRunners() +{ + emit signalStopAllRunners(); +} + void CompilerManager::stopPausing() { QMutexLocker locker(&mRunnerMutex); if (mRunner!=nullptr && mRunner->pausing()) { disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); mRunner->stop(); - disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); mRunner=nullptr; } } @@ -368,6 +373,16 @@ void CompilerManager::onRunnerTerminated() mRunner=nullptr; } +void CompilerManager::onRunnerPausing() +{ + QMutexLocker locker(&mRunnerMutex); + disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); + disconnect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished); + disconnect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured); + connect(this, &CompilerManager::signalStopAllRunners, mRunner, &Runner::stop); + mRunner=nullptr; +} + void CompilerManager::onCompileIssue(PCompileIssue issue) { if (issue->type == CompileIssueType::Error) diff --git a/RedPandaIDE/compiler/compilermanager.h b/RedPandaIDE/compiler/compilermanager.h index 352db4c8..4e81e849 100644 --- a/RedPandaIDE/compiler/compilermanager.h +++ b/RedPandaIDE/compiler/compilermanager.h @@ -46,6 +46,7 @@ public: void runProblem(const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase); void runProblem(const QString& filename, const QString& arguments, const QString& workDir, QVector problemCases); void stopRun(); + void stopAllRunners(); void stopPausing(); void stopCompile(); void stopCheckSyntax(); @@ -58,8 +59,12 @@ public: int syntaxCheckIssueCount() const; +signals: + void signalStopAllRunners(); + private slots: void onRunnerTerminated(); + void onRunnerPausing(); void onCompileFinished(); void onCompileIssue(PCompileIssue issue); void onSyntaxCheckFinished(); diff --git a/RedPandaIDE/compiler/executablerunner.cpp b/RedPandaIDE/compiler/executablerunner.cpp index a4581738..fa7e419a 100644 --- a/RedPandaIDE/compiler/executablerunner.cpp +++ b/RedPandaIDE/compiler/executablerunner.cpp @@ -35,9 +35,9 @@ ExecutableRunner::ExecutableRunner(const QString &filename, const QString &argum ,QObject* parent): Runner(filename,arguments,workDir,parent), mRedirectInput(false), - mStartConsole(false) + mStartConsole(false), + mQuitSemaphore(0) { - } bool ExecutableRunner::startConsole() const @@ -192,6 +192,25 @@ void ExecutableRunner::run() #if defined(Q_OS_WIN) || defined(Q_OS_LINUX) if (mStartConsole && !mPausing && pBuf) { if (strncmp(pBuf,"FINISHED",sizeof("FINISHED"))==0) { +#ifdef Q_OS_WIN + if (pBuf) { + UnmapViewOfFile(pBuf); + pBuf = nullptr; + } + if (hSharedMemory!=INVALID_HANDLE_VALUE) { + hSharedMemory = INVALID_HANDLE_VALUE; + CloseHandle(hSharedMemory); + } +#elif defined(Q_OS_LINUX) + if (pBuf) { + munmap(pBuf,BUF_SIZE); + pBuf = nullptr; + } + if (fd_shm!=-1) { + shm_unlink("/REDPANDAIDECONSOLEPAUSER20211223"); + fd_shm = -1; + } +#endif setPausing(true); emit pausingForFinish(); } @@ -236,39 +255,10 @@ void ExecutableRunner::run() break; } } + mQuitSemaphore.release(1); } void ExecutableRunner::doStop() { - std::shared_ptr process = mProcess; - if (process) { -// qDebug()<<"??1"; -// process->closeReadChannel(QProcess::StandardOutput); -// process->closeReadChannel(QProcess::StandardError); -// process->closeWriteChannel(); -// qDebug()<<"??2"; -// #ifdef Q_OS_WIN -// if (!mStartConsole) { -// qDebug()<<"??3"; -// process->terminate(); -// qDebug()<<"??4"; -// if (process->waitForFinished(1000)) { -// return; -// } -// } -// #else -// process->terminate(); -// if (process->waitForFinished(1000)) { -// break; -// } -// #endif -// for (int i=0;i<10;i++) { -// qDebug()<<"??5"; -// process->kill(); -// qDebug()<<"??6"; -// if (process->waitForFinished(100)) { -// break; -// } -// } - } + mQuitSemaphore.acquire(1); } diff --git a/RedPandaIDE/compiler/executablerunner.h b/RedPandaIDE/compiler/executablerunner.h index 8f50bc0b..6d35036b 100644 --- a/RedPandaIDE/compiler/executablerunner.h +++ b/RedPandaIDE/compiler/executablerunner.h @@ -19,6 +19,7 @@ #include "runner.h" #include +#include class ExecutableRunner : public Runner { @@ -41,6 +42,7 @@ private: bool mRedirectInput; bool mStartConsole; std::shared_ptr mProcess; + QSemaphore mQuitSemaphore; // QThread interface protected: diff --git a/RedPandaIDE/compiler/runner.cpp b/RedPandaIDE/compiler/runner.cpp index c73b0d7f..bbb60cdf 100644 --- a/RedPandaIDE/compiler/runner.cpp +++ b/RedPandaIDE/compiler/runner.cpp @@ -15,6 +15,7 @@ * along with this program. If not, see . */ #include "runner.h" +#include Runner::Runner(const QString &filename, const QString &arguments, const QString &workDir ,QObject *parent) : QThread(parent), diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 30c26f0f..07b7e817 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -1241,7 +1241,7 @@ void DebugReader::asyncUpdate() { QMutexLocker locker(&mCmdQueueMutex); if (mCmdQueue.isEmpty()) - postCommand("noop","",DebugCommandSource::Other); + postCommand("-var-update"," --all-values *",DebugCommandSource::Other); mAsyncUpdated = false; } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index b9b565f1..4fa0783f 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -3655,6 +3655,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { } mTcpServer.close(); + mCompilerManager->stopAllRunners(); mCompilerManager->stopCompile(); mCompilerManager->stopRun(); if (!mShouldRemoveAllSettings)