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();
if (pSettings->debugger().useGDBServer()) {
mTarget = new DebugTarget(inferior,compilerSet->debugServer(),pSettings->debugger().GDBServerPort());
connect(mTarget, &QThread::finished,[this](){
if (mExecuting) {
stop();
}
mTarget->deleteLater();
mTarget = nullptr;
});
mTarget->start();
mTarget->waitStart();
}
mReader = new DebugReader(this);
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::changeDebugConsoleLastLine,this,&Debugger::onChangeDebugConsoleLastline);
connect(mReader, &DebugReader::cmdStarted,pMainWindow, &MainWindow::disableDebugActions);
@ -138,24 +145,22 @@ bool Debugger::start(const QString& inferior)
}
void Debugger::stop() {
if (mExecuting) {
if (mTarget) {
mTarget->stopDebug();
mTarget = nullptr;
}
mReader->stopDebug();
}
}
void Debugger::clearUpReader()
void Debugger::cleanUpReader()
{
if (mExecuting) {
mExecuting = false;
if (mTarget) {
mTarget->deleteLater();
mTarget = nullptr;
}
//stop debugger
mReader->deleteLater();
mReader=nullptr;
if (pMainWindow->cpuDialog()!=nullptr) {
pMainWindow->cpuDialog()->close();
}

View File

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

View File

@ -335,7 +335,7 @@ const GDBMIResultParser::ParseObject &GDBMIResultParser::ParseValue::object() co
int GDBMIResultParser::ParseValue::intValue(int defaultValue) const
{
Q_ASSERT(mType == ParseValueType::Value);
//Q_ASSERT(mType == ParseValueType::Value);
bool ok;
int value = QString(mValue).toInt(&ok);
if (ok)
@ -346,7 +346,7 @@ int GDBMIResultParser::ParseValue::intValue(int defaultValue) const
int GDBMIResultParser::ParseValue::hexValue(int defaultValue) const
{
Q_ASSERT(mType == ParseValueType::Value);
//Q_ASSERT(mType == ParseValueType::Value);
bool ok;
int value = QString(mValue).toInt(&ok,16);
if (ok)
@ -357,7 +357,7 @@ int GDBMIResultParser::ParseValue::hexValue(int defaultValue) const
QString GDBMIResultParser::ParseValue::pathValue() const
{
Q_ASSERT(mType == ParseValueType::Value);
//Q_ASSERT(mType == ParseValueType::Value);
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
if (pSettings->debugger().useGDBServer()) {
mDebugger->sendCommand("-target-select",QString("remote localhost:%1").arg(pSettings->debugger().GDBServerPort()));
if (debugInferiorhasBreakpoint()) {
mDebugger->sendCommand("-break-insert","main");
}
mDebugger->sendCommand("-exec-continue","");
} else {
#ifdef Q_OS_WIN