- enhancement: redirect stdio to a file while debugging ( must use gdb server mode to debug)

This commit is contained in:
Roy Qu 2022-01-12 18:47:50 +08:00
parent 351f4e86ed
commit 797a9b8498
3 changed files with 19 additions and 8 deletions

View File

@ -11,6 +11,7 @@ Red Panda C++ Version 0.13.2
- enhancement: modify values in the watch view by double click - 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: crash when refactor symbol and cursor is at the end of the identifier
- fix: refactor symbol doesn't work for 1-length identifiers - 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 Red Panda C++ Version 0.13.1
- enhancement: suppoort localization info in project templates - enhancement: suppoort localization info in project templates

View File

@ -107,6 +107,8 @@ bool Debugger::start(const QString& inferior)
mWatchModel->resetAllVarInfos(); mWatchModel->resetAllVarInfos();
if (pSettings->debugger().useGDBServer()) { if (pSettings->debugger().useGDBServer()) {
mTarget = new DebugTarget(inferior,compilerSet->debugServer(),pSettings->debugger().GDBServerPort()); mTarget = new DebugTarget(inferior,compilerSet->debugServer(),pSettings->debugger().GDBServerPort());
if (pSettings->executor().redirectInput())
mTarget->setInputFile(pSettings->executor().inputFilename());
connect(mTarget, &QThread::finished,[this](){ connect(mTarget, &QThread::finished,[this](){
if (mExecuting) { if (mExecuting) {
stop(); stop();
@ -2306,6 +2308,11 @@ DebugTarget::DebugTarget(
mProcess = nullptr; mProcess = nullptr;
} }
void DebugTarget::setInputFile(const QString &inputFile)
{
mInputFile = inputFile;
}
void DebugTarget::stopDebug() void DebugTarget::stopDebug()
{ {
mStop = true; mStop = true;
@ -2328,13 +2335,8 @@ void DebugTarget::run()
cmd= mGDBServer; cmd= mGDBServer;
arguments = QString(" localhost:%1 \"%2\"").arg(mPort).arg(mInferior); arguments = QString(" localhost:%1 \"%2\"").arg(mPort).arg(mInferior);
#else #else
if (programHasConsole(mInferior)) {
cmd= pSettings->environment().terminalPath(); cmd= pSettings->environment().terminalPath();
arguments = QString(" -e \"%1\" localhost:%2 \"%3\"").arg(mGDBServer).arg(mPort).arg(mInferior); 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);
}
#endif #endif
QString workingDir = QFileInfo(mInferior).path(); QString workingDir = QFileInfo(mInferior).path();
@ -2366,7 +2368,9 @@ void DebugTarget::run()
args->flags |= CREATE_NEW_CONSOLE; args->flags |= CREATE_NEW_CONSOLE;
args->flags &= ~CREATE_NO_WINDOW; args->flags &= ~CREATE_NO_WINDOW;
} }
if (mInputFile.isEmpty()) {
args->startupInfo -> dwFlags &= ~STARTF_USESTDHANDLES; args->startupInfo -> dwFlags &= ~STARTF_USESTDHANDLES;
}
}); });
#endif #endif
@ -2377,6 +2381,10 @@ void DebugTarget::run()
mProcess->start(); mProcess->start();
mProcess->waitForStarted(5000); mProcess->waitForStarted(5000);
mStartSemaphore.release(1); mStartSemaphore.release(1);
if (mProcess->state()==QProcess::Running && !mInputFile.isEmpty()) {
mProcess->write(readFileToByteArray(mInputFile));
mProcess->closeWriteChannel();
}
while (true) { while (true) {
mProcess->waitForFinished(1); mProcess->waitForFinished(1);
if (mProcess->state()!=QProcess::Running) { if (mProcess->state()!=QProcess::Running) {

View File

@ -350,6 +350,7 @@ public:
const QString& GDBServer, const QString& GDBServer,
int port, int port,
QObject *parent = nullptr); QObject *parent = nullptr);
void setInputFile(const QString& inputFile);
void stopDebug(); void stopDebug();
void waitStart(); void waitStart();
signals: signals:
@ -362,6 +363,7 @@ private:
std::shared_ptr<QProcess> mProcess; std::shared_ptr<QProcess> mProcess;
QSemaphore mStartSemaphore; QSemaphore mStartSemaphore;
bool mErrorOccured; bool mErrorOccured;
QString mInputFile;
// QThread interface // QThread interface
protected: protected: