diff --git a/src/plugins/debugger/gdb/coregdbadapter.cpp b/src/plugins/debugger/gdb/coregdbadapter.cpp index 9c4585791cac3ff6c0dcefdcd8b9d4f2ba0ec7c9..0c2356ec58139b6c4011d984ce13d010dd405755 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.cpp +++ b/src/plugins/debugger/gdb/coregdbadapter.cpp @@ -119,32 +119,59 @@ void CoreGdbAdapter::prepareInferior() void CoreGdbAdapter::startInferior() { QTC_ASSERT(state() == InferiorStarting, qDebug() << state()); - QFileInfo fi2(startParameters().coreFile); - // quoting core name below fails in gdb 6.8-debian - m_executable.clear(); - QString coreName = fi2.absoluteFilePath(); - m_engine->postCommand(_("target core ") + coreName, CB(handleTargetCore)); + QFileInfo fi(startParameters().coreFile); + m_executable = startParameters().executable; + if (m_executable.isEmpty()) { + // Extra round trip to get executable name from core file. + // This is sometimes not the full name, so it can't be used + // as the generic solution. + // Quoting core name below fails in gdb 6.8-debian. + QString coreName = fi.absoluteFilePath(); + m_engine->postCommand(_("target core ") + coreName, CB(handleTargetCore1)); + } else { + // Directly load symbols. + QFileInfo fi(m_executable); + m_engine->postCommand(_("-file-exec-and-symbols \"%1\"") + .arg(fi.absoluteFilePath()), CB(handleFileExecAndSymbols)); + } } -void CoreGdbAdapter::handleTargetCore(const GdbResponse &response) +void CoreGdbAdapter::handleTargetCore1(const GdbResponse &response) { QTC_ASSERT(state() == InferiorStarting, qDebug() << state()); if (response.resultClass == GdbResultDone) { - showStatusMessage(tr("Attached to core.")); - m_executable = startParameters().executable; - if (m_executable.isEmpty()) { - GdbMi console = response.data.findChild("consolestreamoutput"); - int pos1 = console.data().indexOf('`'); - int pos2 = console.data().indexOf('\''); - if (pos1 != -1 && pos2 != -1) - m_executable = console.data().mid(pos1 + 1, pos2 - pos1 - 1); + showStatusMessage(tr("Attached to core temporarily.")); + GdbMi console = response.data.findChild("consolestreamoutput"); + int pos1 = console.data().indexOf('`'); + int pos2 = console.data().indexOf('\''); + if (pos1 == -1 || pos2 == -1) { + setState(InferiorStartFailed); + emit inferiorStartFailed(tr("No binary found.")); + } else { + m_executable = console.data().mid(pos1 + 1, pos2 - pos1 - 1); + QTC_ASSERT(!m_executable.isEmpty(), /**/); + // Finish extra round. + m_engine->postCommand(_("detach"), CB(handleDetach1)); } + } else { + QTC_ASSERT(response.resultClass == GdbResultError, /**/); + const QByteArray msg = response.data.findChild("msg").data(); + setState(InferiorStartFailed); + emit inferiorStartFailed(msg); + } +} + +void CoreGdbAdapter::handleDetach1(const GdbResponse &response) +{ + QTC_ASSERT(state() == InferiorStarting, qDebug() << state()); + if (response.resultClass == GdbResultDone) { + // Load symbols. QFileInfo fi(m_executable); m_engine->postCommand(_("-file-exec-and-symbols \"%1\"") .arg(fi.absoluteFilePath()), CB(handleFileExecAndSymbols)); } else { QTC_ASSERT(response.resultClass == GdbResultError, /**/); - const QByteArray &msg = response.data.findChild("msg").data(); + const QByteArray msg = response.data.findChild("msg").data(); setState(InferiorStartFailed); emit inferiorStartFailed(msg); } @@ -155,8 +182,10 @@ void CoreGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response) QTC_ASSERT(state() == InferiorStarting, qDebug() << state()); if (response.resultClass == GdbResultDone) { showStatusMessage(tr("Symbols found.")); - setState(InferiorUnrunnable); - m_engine->updateAll(); + // Quoting core name below fails in gdb 6.8-debian. + QFileInfo fi(startParameters().coreFile); + QString coreName = fi.absoluteFilePath(); + m_engine->postCommand(_("target core ") + coreName, CB(handleTargetCore2)); } else if (response.resultClass == GdbResultError) { QString msg = tr("Symbols not found in \"%1\" failed:\n%2") .arg(__(response.data.findChild("msg").data())); @@ -167,6 +196,22 @@ void CoreGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response) } } +void CoreGdbAdapter::handleTargetCore2(const GdbResponse &response) +{ + QTC_ASSERT(state() == InferiorStarting, qDebug() << state()); + if (response.resultClass == GdbResultDone) { + showStatusMessage(tr("Attached to core.")); + setState(InferiorUnrunnable); + m_engine->updateAll(); + } else if (response.resultClass == GdbResultError) { + QString msg = tr("Attach to core \"%1\" failed:\n%2") + .arg(__(response.data.findChild("msg").data())); + setState(InferiorUnrunnable); + m_engine->updateAll(); + //setState(InferiorStartFailed); + // emit inferiorStartFailed(msg); + } +} void CoreGdbAdapter::interruptInferior() { // A core should never 'run' diff --git a/src/plugins/debugger/gdb/coregdbadapter.h b/src/plugins/debugger/gdb/coregdbadapter.h index 8cb74db99dfe2ce654c05ec11449be653ed5f279..273891d1337c77350d026d209e39cfd66e1c4a3e 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.h +++ b/src/plugins/debugger/gdb/coregdbadapter.h @@ -67,8 +67,10 @@ private: void interruptInferior(); void shutdown(); + void handleTargetCore1(const GdbResponse &response); + void handleDetach1(const GdbResponse &response); void handleFileExecAndSymbols(const GdbResponse &response); - void handleTargetCore(const GdbResponse &response); + void handleTargetCore2(const GdbResponse &response); void handleExit(const GdbResponse &response); Q_SLOT void handleGdbStarted();