From 797a9b849879c1e195c7bd159ab19d8b9ef2f24a Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 12 Jan 2022 18:47:50 +0800 Subject: [PATCH] - enhancement: redirect stdio to a file while debugging ( must use gdb server mode to debug) --- NEWS.md | 1 + RedPandaIDE/debugger.cpp | 24 ++++++++++++++++-------- RedPandaIDE/debugger.h | 2 ++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index a3f23259..c5b976ab 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ Red Panda C++ Version 0.13.2 - enhancement: modify values in the watch view by double click - fix: crash when refactor symbol and cursor is at the end of the identifier - fix: refactor symbol doesn't work for 1-length identifiers + - enhancement: redirect stdio to a file while debugging ( must use gdb server mode to debug) Red Panda C++ Version 0.13.1 - enhancement: suppoort localization info in project templates diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 7eb36f4e..43ffad94 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -107,6 +107,8 @@ bool Debugger::start(const QString& inferior) mWatchModel->resetAllVarInfos(); if (pSettings->debugger().useGDBServer()) { mTarget = new DebugTarget(inferior,compilerSet->debugServer(),pSettings->debugger().GDBServerPort()); + if (pSettings->executor().redirectInput()) + mTarget->setInputFile(pSettings->executor().inputFilename()); connect(mTarget, &QThread::finished,[this](){ if (mExecuting) { stop(); @@ -2306,6 +2308,11 @@ DebugTarget::DebugTarget( mProcess = nullptr; } +void DebugTarget::setInputFile(const QString &inputFile) +{ + mInputFile = inputFile; +} + void DebugTarget::stopDebug() { mStop = true; @@ -2328,13 +2335,8 @@ void DebugTarget::run() cmd= mGDBServer; arguments = QString(" localhost:%1 \"%2\"").arg(mPort).arg(mInferior); #else - if (programHasConsole(mInferior)) { - cmd= pSettings->environment().terminalPath(); - arguments = QString(" -e \"%1\" localhost:%2 \"%3\"").arg(mGDBServer).arg(mPort).arg(mInferior); - } else { - cmd= mGDBServer; - arguments = QString(" localhost:%1 \"%2\"").arg(mPort).arg(mInferior); - } + cmd= pSettings->environment().terminalPath(); + arguments = QString(" -e \"%1\" localhost:%2 \"%3\"").arg(mGDBServer).arg(mPort).arg(mInferior); #endif QString workingDir = QFileInfo(mInferior).path(); @@ -2366,7 +2368,9 @@ void DebugTarget::run() args->flags |= CREATE_NEW_CONSOLE; args->flags &= ~CREATE_NO_WINDOW; } - args->startupInfo -> dwFlags &= ~STARTF_USESTDHANDLES; + if (mInputFile.isEmpty()) { + args->startupInfo -> dwFlags &= ~STARTF_USESTDHANDLES; + } }); #endif @@ -2377,6 +2381,10 @@ void DebugTarget::run() mProcess->start(); mProcess->waitForStarted(5000); mStartSemaphore.release(1); + if (mProcess->state()==QProcess::Running && !mInputFile.isEmpty()) { + mProcess->write(readFileToByteArray(mInputFile)); + mProcess->closeWriteChannel(); + } while (true) { mProcess->waitForFinished(1); if (mProcess->state()!=QProcess::Running) { diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index 7962967d..59f38c53 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -350,6 +350,7 @@ public: const QString& GDBServer, int port, QObject *parent = nullptr); + void setInputFile(const QString& inputFile); void stopDebug(); void waitStart(); signals: @@ -362,6 +363,7 @@ private: std::shared_ptr mProcess; QSemaphore mStartSemaphore; bool mErrorOccured; + QString mInputFile; // QThread interface protected: