fix: gdb server can be correctly stopped

This commit is contained in:
Roy Qu 2021-12-25 19:22:29 +08:00
parent f2504e1f43
commit f52ea9dcab
4 changed files with 20 additions and 12 deletions

View File

@ -85,12 +85,19 @@ 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());
connect(mTarget, &QThread::finished,[this](){
if (mExecuting) {
stop();
}
mTarget->deleteLater();
mTarget = nullptr;
});
mTarget->start(); mTarget->start();
mTarget->waitStart(); mTarget->waitStart();
} }
mReader = new DebugReader(this); mReader = new DebugReader(this);
mReader->setDebuggerPath(debuggerPath); mReader->setDebuggerPath(debuggerPath);
connect(mReader, &QThread::finished,this,&Debugger::clearUpReader); connect(mReader, &QThread::finished,this,&Debugger::cleanUpReader);
connect(mReader, &DebugReader::parseFinished,this,&Debugger::syncFinishedParsing,Qt::BlockingQueuedConnection); connect(mReader, &DebugReader::parseFinished,this,&Debugger::syncFinishedParsing,Qt::BlockingQueuedConnection);
connect(mReader, &DebugReader::changeDebugConsoleLastLine,this,&Debugger::onChangeDebugConsoleLastline); connect(mReader, &DebugReader::changeDebugConsoleLastLine,this,&Debugger::onChangeDebugConsoleLastline);
connect(mReader, &DebugReader::cmdStarted,pMainWindow, &MainWindow::disableDebugActions); connect(mReader, &DebugReader::cmdStarted,pMainWindow, &MainWindow::disableDebugActions);
@ -138,24 +145,22 @@ bool Debugger::start(const QString& inferior)
} }
void Debugger::stop() { void Debugger::stop() {
if (mExecuting) { if (mExecuting) {
if (mTarget) {
mTarget->stopDebug();
mTarget = nullptr;
}
mReader->stopDebug(); mReader->stopDebug();
} }
} }
void Debugger::clearUpReader() void Debugger::cleanUpReader()
{ {
if (mExecuting) { if (mExecuting) {
mExecuting = false; mExecuting = false;
if (mTarget) {
mTarget->deleteLater();
mTarget = nullptr;
}
//stop debugger //stop debugger
mReader->deleteLater(); mReader->deleteLater();
mReader=nullptr; mReader=nullptr;
if (pMainWindow->cpuDialog()!=nullptr) { if (pMainWindow->cpuDialog()!=nullptr) {
pMainWindow->cpuDialog()->close(); pMainWindow->cpuDialog()->close();
} }

View File

@ -252,7 +252,7 @@ private slots:
void updateEval(const QString& value); void updateEval(const QString& value);
void updateDisassembly(const QString& file, const QString& func,const QStringList& value); void updateDisassembly(const QString& file, const QString& func,const QStringList& value);
void onChangeDebugConsoleLastline(const QString& text); void onChangeDebugConsoleLastline(const QString& text);
void clearUpReader(); void cleanUpReader();
void updateRegisterNames(const QStringList& registerNames); void updateRegisterNames(const QStringList& registerNames);
void updateRegisterValues(const QHash<int,QString>& values); void updateRegisterValues(const QHash<int,QString>& values);
void refreshWatchVars(); void refreshWatchVars();

View File

@ -335,7 +335,7 @@ const GDBMIResultParser::ParseObject &GDBMIResultParser::ParseValue::object() co
int GDBMIResultParser::ParseValue::intValue(int defaultValue) const int GDBMIResultParser::ParseValue::intValue(int defaultValue) const
{ {
Q_ASSERT(mType == ParseValueType::Value); //Q_ASSERT(mType == ParseValueType::Value);
bool ok; bool ok;
int value = QString(mValue).toInt(&ok); int value = QString(mValue).toInt(&ok);
if (ok) if (ok)
@ -346,7 +346,7 @@ int GDBMIResultParser::ParseValue::intValue(int defaultValue) const
int GDBMIResultParser::ParseValue::hexValue(int defaultValue) const int GDBMIResultParser::ParseValue::hexValue(int defaultValue) const
{ {
Q_ASSERT(mType == ParseValueType::Value); //Q_ASSERT(mType == ParseValueType::Value);
bool ok; bool ok;
int value = QString(mValue).toInt(&ok,16); int value = QString(mValue).toInt(&ok,16);
if (ok) if (ok)
@ -357,7 +357,7 @@ int GDBMIResultParser::ParseValue::hexValue(int defaultValue) const
QString GDBMIResultParser::ParseValue::pathValue() const QString GDBMIResultParser::ParseValue::pathValue() const
{ {
Q_ASSERT(mType == ParseValueType::Value); //Q_ASSERT(mType == ParseValueType::Value);
return QFileInfo(QString::fromLocal8Bit(mValue)).absoluteFilePath(); return QFileInfo(QString::fromLocal8Bit(mValue)).absoluteFilePath();
} }

View File

@ -1668,6 +1668,9 @@ 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()) {
mDebugger->sendCommand("-break-insert","main");
}
mDebugger->sendCommand("-exec-continue",""); mDebugger->sendCommand("-exec-continue","");
} else { } else {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN