- enhancement: detach pausing console window

- use "-var-update" gdb command instead of "noop"
This commit is contained in:
Roy Qu 2021-12-29 22:03:18 +08:00
parent 8ea5a2d5ba
commit 13c79bb55d
8 changed files with 50 additions and 35 deletions

View File

@ -8,6 +8,7 @@ Version 0.12.5 For Dev-C++ 7 Beta
- fix: wrong executable filename for source files in linux - fix: wrong executable filename for source files in linux
- enhancement: console pauser for linux - enhancement: console pauser for linux
- enhancement: redirect input to program in linux - enhancement: redirect input to program in linux
- enhancement: detach pausing console window
Version 0.12.4 For Dev-C++ 7 Beta Version 0.12.4 For Dev-C++ 7 Beta
- change: add copyright infos to each source file - change: add copyright infos to each source file

View File

@ -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, mRunner ,&Runner::deleteLater);
connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished); connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished);
connect(mRunner, &Runner::pausingForFinish, pMainWindow ,&MainWindow::onRunPausingForFinish); connect(mRunner, &Runner::pausingForFinish, pMainWindow ,&MainWindow::onRunPausingForFinish);
connect(mRunner, &Runner::pausingForFinish, this ,&CompilerManager::onRunnerPausing);
connect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured); connect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured);
mRunner->start(); mRunner->start();
} }
@ -325,13 +326,17 @@ void CompilerManager::stopRun()
} }
} }
void CompilerManager::stopAllRunners()
{
emit signalStopAllRunners();
}
void CompilerManager::stopPausing() void CompilerManager::stopPausing()
{ {
QMutexLocker locker(&mRunnerMutex); QMutexLocker locker(&mRunnerMutex);
if (mRunner!=nullptr && mRunner->pausing()) { if (mRunner!=nullptr && mRunner->pausing()) {
disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated);
mRunner->stop(); mRunner->stop();
disconnect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated);
mRunner=nullptr; mRunner=nullptr;
} }
} }
@ -368,6 +373,16 @@ void CompilerManager::onRunnerTerminated()
mRunner=nullptr; 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) void CompilerManager::onCompileIssue(PCompileIssue issue)
{ {
if (issue->type == CompileIssueType::Error) if (issue->type == CompileIssueType::Error)

View File

@ -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, POJProblemCase problemCase);
void runProblem(const QString& filename, const QString& arguments, const QString& workDir, QVector<POJProblemCase> problemCases); void runProblem(const QString& filename, const QString& arguments, const QString& workDir, QVector<POJProblemCase> problemCases);
void stopRun(); void stopRun();
void stopAllRunners();
void stopPausing(); void stopPausing();
void stopCompile(); void stopCompile();
void stopCheckSyntax(); void stopCheckSyntax();
@ -58,8 +59,12 @@ public:
int syntaxCheckIssueCount() const; int syntaxCheckIssueCount() const;
signals:
void signalStopAllRunners();
private slots: private slots:
void onRunnerTerminated(); void onRunnerTerminated();
void onRunnerPausing();
void onCompileFinished(); void onCompileFinished();
void onCompileIssue(PCompileIssue issue); void onCompileIssue(PCompileIssue issue);
void onSyntaxCheckFinished(); void onSyntaxCheckFinished();

View File

@ -35,9 +35,9 @@ ExecutableRunner::ExecutableRunner(const QString &filename, const QString &argum
,QObject* parent): ,QObject* parent):
Runner(filename,arguments,workDir,parent), Runner(filename,arguments,workDir,parent),
mRedirectInput(false), mRedirectInput(false),
mStartConsole(false) mStartConsole(false),
mQuitSemaphore(0)
{ {
} }
bool ExecutableRunner::startConsole() const bool ExecutableRunner::startConsole() const
@ -192,6 +192,25 @@ void ExecutableRunner::run()
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX) #if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
if (mStartConsole && !mPausing && pBuf) { if (mStartConsole && !mPausing && pBuf) {
if (strncmp(pBuf,"FINISHED",sizeof("FINISHED"))==0) { 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); setPausing(true);
emit pausingForFinish(); emit pausingForFinish();
} }
@ -236,39 +255,10 @@ void ExecutableRunner::run()
break; break;
} }
} }
mQuitSemaphore.release(1);
} }
void ExecutableRunner::doStop() void ExecutableRunner::doStop()
{ {
std::shared_ptr<QProcess> process = mProcess; mQuitSemaphore.acquire(1);
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;
// }
// }
}
} }

View File

@ -19,6 +19,7 @@
#include "runner.h" #include "runner.h"
#include <QProcess> #include <QProcess>
#include <QSemaphore>
class ExecutableRunner : public Runner class ExecutableRunner : public Runner
{ {
@ -41,6 +42,7 @@ private:
bool mRedirectInput; bool mRedirectInput;
bool mStartConsole; bool mStartConsole;
std::shared_ptr<QProcess> mProcess; std::shared_ptr<QProcess> mProcess;
QSemaphore mQuitSemaphore;
// QThread interface // QThread interface
protected: protected:

View File

@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include "runner.h" #include "runner.h"
#include <QDebug>
Runner::Runner(const QString &filename, const QString &arguments, const QString &workDir Runner::Runner(const QString &filename, const QString &arguments, const QString &workDir
,QObject *parent) : QThread(parent), ,QObject *parent) : QThread(parent),

View File

@ -1241,7 +1241,7 @@ void DebugReader::asyncUpdate()
{ {
QMutexLocker locker(&mCmdQueueMutex); QMutexLocker locker(&mCmdQueueMutex);
if (mCmdQueue.isEmpty()) if (mCmdQueue.isEmpty())
postCommand("noop","",DebugCommandSource::Other); postCommand("-var-update"," --all-values *",DebugCommandSource::Other);
mAsyncUpdated = false; mAsyncUpdated = false;
} }

View File

@ -3655,6 +3655,7 @@ void MainWindow::closeEvent(QCloseEvent *event) {
} }
mTcpServer.close(); mTcpServer.close();
mCompilerManager->stopAllRunners();
mCompilerManager->stopCompile(); mCompilerManager->stopCompile();
mCompilerManager->stopRun(); mCompilerManager->stopRun();
if (!mShouldRemoveAllSettings) if (!mShouldRemoveAllSettings)