Commit 9d20a2ab authored by Oswald Buddenhagen's avatar Oswald Buddenhagen

make attaching adapters more robust

to make the behavior consistent across gdb versions, ignore the initial
*stopped which gdb7 delivers while attaching.

Reviewed-By: hjk
parent 36a4fdda
......@@ -77,17 +77,9 @@ void AttachGdbAdapter::startInferior()
void AttachGdbAdapter::handleAttach(const GdbResponse &response)
{
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
if (response.resultClass == GdbResultDone) {
// We don't know the exact 6.8.50 build where gdb started emitting
// *stopped here, so allow for some slack.
if (m_engine->m_gdbVersion < 60850) {
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
setState(InferiorStopped);
} else if (m_engine->m_gdbVersion < 70000 && state() == InferiorStarting) {
setState(InferiorStopped);
} else {
QTC_ASSERT(state() == InferiorStopped, qDebug() << state());
}
setState(InferiorStopped);
debugMessage(_("INFERIOR ATTACHED"));
showStatusMessage(msgAttachedToStoppedInferior());
emit inferiorPrepared();
......
......@@ -889,6 +889,7 @@ void GdbEngine::updateAll()
{
QTC_ASSERT(state() == InferiorUnrunnable || state() == InferiorStopped, /**/);
tryLoadDebuggingHelpers();
reloadModulesInternal();
postCommand(_("-stack-list-frames"), WatchUpdate, CB(handleStackListFrames),
QVariant::fromValue<StackCookie>(StackCookie(false, true)));
manager()->stackHandler()->setCurrentIndex(0);
......@@ -1009,6 +1010,11 @@ void GdbEngine::handleAqcuiredInferior()
void GdbEngine::handleStopResponse(const GdbMi &data)
{
// This is gdb 7+'s initial *stopped in response to attach.
// For consistency, we just discard it.
if (state() == InferiorStarting)
return;
const QByteArray reason = data.findChild("reason").data();
if (isExitedReason(reason)) {
......@@ -1051,16 +1057,12 @@ void GdbEngine::handleStopResponse(const GdbMi &data)
return;
}
bool initHelpers = true;
if (state() == InferiorRunning) {
// Stop triggered by a breakpoint or otherwise not directly
// initiated by the user.
setState(InferiorStopping);
} else {
if (state() == InferiorStarting)
initHelpers = false;
else
QTC_ASSERT(state() == InferiorStopping, qDebug() << state());
QTC_ASSERT(state() == InferiorStopping, qDebug() << state());
}
setState(InferiorStopped);
......@@ -1138,8 +1140,7 @@ void GdbEngine::handleStopResponse(const GdbMi &data)
}
}
if (initHelpers && m_debuggingHelperState != DebuggingHelperUninitialized)
initHelpers = false;
bool initHelpers = (m_debuggingHelperState == DebuggingHelperUninitialized);
// Don't load helpers on stops triggered by signals unless it's
// an intentional trap.
if (initHelpers && reason == "signal-received"
......
......@@ -191,8 +191,9 @@ void RemoteGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
void RemoteGdbAdapter::handleTargetRemote(const GdbResponse &record)
{
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
if (record.resultClass == GdbResultDone) {
QTC_ASSERT(state() == InferiorStopped, qDebug() << state());
setState(InferiorStopped);
// gdb server will stop the remote application itself.
debugMessage(_("INFERIOR STARTED"));
showStatusMessage(msgAttachedToStoppedInferior());
......
......@@ -114,8 +114,9 @@ void TermGdbAdapter::startInferior()
void TermGdbAdapter::handleStubAttached(const GdbResponse &response)
{
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
if (response.resultClass == GdbResultDone) {
QTC_ASSERT(state() == InferiorStopped, qDebug() << state());
setState(InferiorStopped);
debugMessage(_("INFERIOR ATTACHED"));
emit inferiorPrepared();
} else if (response.resultClass == GdbResultError) {
......
......@@ -1616,6 +1616,7 @@ void TrkGdbAdapter::handleTargetRemote(const GdbResponse &record)
{
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
if (record.resultClass == GdbResultDone) {
setState(InferiorStopped);
emit inferiorPrepared();
} else {
QString msg = tr("Connecting to TRK server adapter failed:\n")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment