fix: crash when close debugger
This commit is contained in:
parent
f52ea9dcab
commit
4f61797a50
|
@ -617,7 +617,7 @@ DebugReader::DebugReader(Debugger* debugger, QObject *parent) : QThread(parent),
|
||||||
mStartSemaphore(0)
|
mStartSemaphore(0)
|
||||||
{
|
{
|
||||||
mDebugger = debugger;
|
mDebugger = debugger;
|
||||||
mProcess = nullptr;
|
mProcess = std::make_shared<QProcess>();
|
||||||
mCmdRunning = false;
|
mCmdRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1319,13 +1319,16 @@ void DebugReader::run()
|
||||||
mStop = false;
|
mStop = false;
|
||||||
mInferiorRunning = false;
|
mInferiorRunning = false;
|
||||||
mProcessExited = false;
|
mProcessExited = false;
|
||||||
bool errorOccurred = false;
|
mErrorOccured = false;
|
||||||
QString cmd = mDebuggerPath;
|
QString cmd = mDebuggerPath;
|
||||||
// QString arguments = "--annotate=2";
|
// QString arguments = "--annotate=2";
|
||||||
QString arguments = "--interpret=mi --silent";
|
QString arguments = "--interpret=mi --silent";
|
||||||
QString workingDir = QFileInfo(mDebuggerPath).path();
|
QString workingDir = QFileInfo(mDebuggerPath).path();
|
||||||
|
|
||||||
mProcess = std::make_shared<QProcess>();
|
mProcess = std::make_shared<QProcess>();
|
||||||
|
auto action = finally([&]{
|
||||||
|
mProcess.reset();
|
||||||
|
});
|
||||||
mProcess->setProgram(cmd);
|
mProcess->setProgram(cmd);
|
||||||
mProcess->setArguments(QProcess::splitCommand(arguments));
|
mProcess->setArguments(QProcess::splitCommand(arguments));
|
||||||
mProcess->setProcessChannelMode(QProcess::MergedChannels);
|
mProcess->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
@ -1346,7 +1349,7 @@ void DebugReader::run()
|
||||||
|
|
||||||
connect(mProcess.get(), &QProcess::errorOccurred,
|
connect(mProcess.get(), &QProcess::errorOccurred,
|
||||||
[&](){
|
[&](){
|
||||||
errorOccurred= true;
|
mErrorOccured= true;
|
||||||
});
|
});
|
||||||
QByteArray buffer;
|
QByteArray buffer;
|
||||||
QByteArray readed;
|
QByteArray readed;
|
||||||
|
@ -1367,7 +1370,7 @@ void DebugReader::run()
|
||||||
mProcess->kill();
|
mProcess->kill();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (errorOccurred)
|
if (mErrorOccured)
|
||||||
break;
|
break;
|
||||||
readed = mProcess->readAll();
|
readed = mProcess->readAll();
|
||||||
buffer += readed;
|
buffer += readed;
|
||||||
|
@ -1383,7 +1386,7 @@ void DebugReader::run()
|
||||||
msleep(1);
|
msleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (errorOccurred) {
|
if (mErrorOccured) {
|
||||||
emit processError(mProcess->error());
|
emit processError(mProcess->error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2222,9 +2225,10 @@ DebugTarget::DebugTarget(
|
||||||
mGDBServer(GDBServer),
|
mGDBServer(GDBServer),
|
||||||
mPort(port),
|
mPort(port),
|
||||||
mStop(false),
|
mStop(false),
|
||||||
mStartSemaphore(0)
|
mStartSemaphore(0),
|
||||||
|
mErrorOccured(false)
|
||||||
{
|
{
|
||||||
|
mProcess = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugTarget::stopDebug()
|
void DebugTarget::stopDebug()
|
||||||
|
@ -2240,7 +2244,7 @@ void DebugTarget::waitStart()
|
||||||
void DebugTarget::run()
|
void DebugTarget::run()
|
||||||
{
|
{
|
||||||
mStop = false;
|
mStop = false;
|
||||||
bool errorOccurred = false;
|
mErrorOccured = false;
|
||||||
|
|
||||||
//find first available port
|
//find first available port
|
||||||
QString cmd;
|
QString cmd;
|
||||||
|
@ -2255,6 +2259,9 @@ void DebugTarget::run()
|
||||||
QString workingDir = QFileInfo(mInferior).path();
|
QString workingDir = QFileInfo(mInferior).path();
|
||||||
|
|
||||||
mProcess = std::make_shared<QProcess>();
|
mProcess = std::make_shared<QProcess>();
|
||||||
|
auto action = finally([&]{
|
||||||
|
mProcess.reset();
|
||||||
|
});
|
||||||
mProcess->setProgram(cmd);
|
mProcess->setProgram(cmd);
|
||||||
mProcess->setArguments(QProcess::splitCommand(arguments));
|
mProcess->setArguments(QProcess::splitCommand(arguments));
|
||||||
mProcess->setProcessChannelMode(QProcess::MergedChannels);
|
mProcess->setProcessChannelMode(QProcess::MergedChannels);
|
||||||
|
@ -2285,7 +2292,7 @@ void DebugTarget::run()
|
||||||
|
|
||||||
connect(mProcess.get(), &QProcess::errorOccurred,
|
connect(mProcess.get(), &QProcess::errorOccurred,
|
||||||
[&](){
|
[&](){
|
||||||
errorOccurred= true;
|
mErrorOccured= true;
|
||||||
});
|
});
|
||||||
mProcess->start();
|
mProcess->start();
|
||||||
mProcess->waitForStarted(5000);
|
mProcess->waitForStarted(5000);
|
||||||
|
@ -2303,11 +2310,11 @@ void DebugTarget::run()
|
||||||
mProcess->kill();
|
mProcess->kill();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (errorOccurred)
|
if (mErrorOccured)
|
||||||
break;
|
break;
|
||||||
msleep(1);
|
msleep(1);
|
||||||
}
|
}
|
||||||
if (errorOccurred) {
|
if (mErrorOccured) {
|
||||||
emit processError(mProcess->error());
|
emit processError(mProcess->error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,7 @@ private:
|
||||||
bool mStop;
|
bool mStop;
|
||||||
std::shared_ptr<QProcess> mProcess;
|
std::shared_ptr<QProcess> mProcess;
|
||||||
QSemaphore mStartSemaphore;
|
QSemaphore mStartSemaphore;
|
||||||
|
bool mErrorOccured;
|
||||||
|
|
||||||
// QThread interface
|
// QThread interface
|
||||||
protected:
|
protected:
|
||||||
|
@ -410,6 +411,7 @@ private:
|
||||||
QRecursiveMutex mCmdQueueMutex;
|
QRecursiveMutex mCmdQueueMutex;
|
||||||
QSemaphore mStartSemaphore;
|
QSemaphore mStartSemaphore;
|
||||||
QQueue<PDebugCommand> mCmdQueue;
|
QQueue<PDebugCommand> mCmdQueue;
|
||||||
|
bool mErrorOccured;
|
||||||
|
|
||||||
//fOnInvalidateAllVars: TInvalidateAllVarsEvent;
|
//fOnInvalidateAllVars: TInvalidateAllVarsEvent;
|
||||||
bool mCmdRunning;
|
bool mCmdRunning;
|
||||||
|
|
|
@ -1668,8 +1668,8 @@ void MainWindow::debug()
|
||||||
mDebugger->sendCommand("-environment-cd", excludeTrailingPathDelimiter(debugFile.path())); // restore working directory
|
mDebugger->sendCommand("-environment-cd", excludeTrailingPathDelimiter(debugFile.path())); // restore working directory
|
||||||
if (pSettings->debugger().useGDBServer()) {
|
if (pSettings->debugger().useGDBServer()) {
|
||||||
mDebugger->sendCommand("-target-select",QString("remote localhost:%1").arg(pSettings->debugger().GDBServerPort()));
|
mDebugger->sendCommand("-target-select",QString("remote localhost:%1").arg(pSettings->debugger().GDBServerPort()));
|
||||||
if (debugInferiorhasBreakpoint()) {
|
if (!debugInferiorhasBreakpoint()) {
|
||||||
mDebugger->sendCommand("-break-insert","main");
|
mDebugger->sendCommand("-break-insert","-t main");
|
||||||
}
|
}
|
||||||
mDebugger->sendCommand("-exec-continue","");
|
mDebugger->sendCommand("-exec-continue","");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue