- 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
- 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

View File

@ -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);
}
#endif
QString workingDir = QFileInfo(mInferior).path();
@ -2366,7 +2368,9 @@ void DebugTarget::run()
args->flags |= CREATE_NEW_CONSOLE;
args->flags &= ~CREATE_NO_WINDOW;
}
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) {

View File

@ -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<QProcess> mProcess;
QSemaphore mStartSemaphore;
bool mErrorOccured;
QString mInputFile;
// QThread interface
protected: