forked from qt-creator/qt-creator
refactor attachAdapter
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
|
#include <QtGui/QMessageBox>
|
||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -70,93 +71,92 @@ void CoreGdbAdapter::startAdapter()
|
|||||||
void CoreGdbAdapter::startInferior()
|
void CoreGdbAdapter::startInferior()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
||||||
QFileInfo fi(startParameters().coreFile);
|
|
||||||
m_executable = startParameters().executable;
|
m_executable = startParameters().executable;
|
||||||
if (m_executable.isEmpty()) {
|
if (m_executable.isEmpty()) {
|
||||||
|
#ifdef EXE_FROM_CORE
|
||||||
// Extra round trip to get executable name from core file.
|
// Extra round trip to get executable name from core file.
|
||||||
// This is sometimes not the full name, so it can't be used
|
// This is sometimes not the full name, so it can't be used
|
||||||
// as the generic solution.
|
// as the generic solution.
|
||||||
// Quoting core name below fails in gdb 6.8-debian.
|
|
||||||
QString coreName = fi.absoluteFilePath();
|
m_round = 1;
|
||||||
m_engine->postCommand(_("target core ") + coreName, CB(handleTargetCore1));
|
loadCoreFile();
|
||||||
} else {
|
#else
|
||||||
// Directly load symbols.
|
showMessageBox(QMessageBox::Warning, tr("Error Loading Symbols"),
|
||||||
|
tr("No executable to load symbols from specified."));
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#ifdef EXE_FROM_CORE
|
||||||
|
m_round = 2;
|
||||||
|
#endif
|
||||||
|
loadExeAndSyms();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreGdbAdapter::loadExeAndSyms()
|
||||||
|
{
|
||||||
|
// Do that first, otherwise no symbols are loaded.
|
||||||
QFileInfo fi(m_executable);
|
QFileInfo fi(m_executable);
|
||||||
m_engine->postCommand(_("-file-exec-and-symbols \"%1\"")
|
m_engine->postCommand(_("-file-exec-and-symbols \"%1\"")
|
||||||
.arg(fi.absoluteFilePath()), CB(handleFileExecAndSymbols));
|
.arg(fi.absoluteFilePath()), CB(handleFileExecAndSymbols));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CoreGdbAdapter::handleTargetCore1(const GdbResponse &response)
|
|
||||||
{
|
|
||||||
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
|
||||||
if (response.resultClass == GdbResultDone) {
|
|
||||||
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) {
|
|
||||||
emit inferiorStartFailed(tr("No binary found."));
|
|
||||||
} else {
|
|
||||||
m_executable = console.data().mid(pos1 + 1, pos2 - pos1 - 1);
|
|
||||||
// Strip off command line arguments. FIXME: make robust.
|
|
||||||
if (m_executable.contains(' '))
|
|
||||||
m_executable = m_executable.section(' ', 0, 0);
|
|
||||||
QTC_ASSERT(!m_executable.isEmpty(), /**/);
|
|
||||||
// Finish extra round.
|
|
||||||
m_engine->postCommand(_("detach"), CB(handleDetach1));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const QByteArray msg = response.data.findChild("msg").data();
|
|
||||||
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 {
|
|
||||||
const QByteArray msg = response.data.findChild("msg").data();
|
|
||||||
emit inferiorStartFailed(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CoreGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
|
void CoreGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
||||||
if (response.resultClass == GdbResultDone) {
|
if (response.resultClass == GdbResultDone) {
|
||||||
showStatusMessage(tr("Symbols found."));
|
showStatusMessage(tr("Symbols found."));
|
||||||
|
} else {
|
||||||
|
QString msg = tr("Loading symbols from \"%1\" failed:\n").arg(m_executable)
|
||||||
|
+ __(response.data.findChild("msg").data());
|
||||||
|
showMessageBox(QMessageBox::Warning, tr("Error Loading Symbols"), msg);
|
||||||
|
}
|
||||||
|
loadCoreFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CoreGdbAdapter::loadCoreFile()
|
||||||
|
{
|
||||||
// Quoting core name below fails in gdb 6.8-debian.
|
// Quoting core name below fails in gdb 6.8-debian.
|
||||||
QFileInfo fi(startParameters().coreFile);
|
QFileInfo fi(startParameters().coreFile);
|
||||||
QString coreName = fi.absoluteFilePath();
|
QString coreName = fi.absoluteFilePath();
|
||||||
m_engine->postCommand(_("target core ") + coreName, CB(handleTargetCore2));
|
m_engine->postCommand(_("target core ") + coreName, CB(handleTargetCore));
|
||||||
} else {
|
|
||||||
QString msg = tr("Symbols not found in \"%1\" failed:\n%2")
|
|
||||||
.arg(__(response.data.findChild("msg").data()));
|
|
||||||
setState(InferiorUnrunnable);
|
|
||||||
m_engine->updateAll();
|
|
||||||
// emit inferiorStartFailed(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreGdbAdapter::handleTargetCore2(const GdbResponse &response)
|
void CoreGdbAdapter::handleTargetCore(const GdbResponse &response)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
|
||||||
if (response.resultClass == GdbResultDone) {
|
if (response.resultClass == GdbResultDone) {
|
||||||
|
#ifdef EXE_FROM_CORE
|
||||||
|
if (m_round == 1) {
|
||||||
|
m_round = 2;
|
||||||
|
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);
|
||||||
|
// Strip off command line arguments. FIXME: make robust.
|
||||||
|
int idx = m_executable.indexOf(_c(' '));
|
||||||
|
if (idx >= 0)
|
||||||
|
m_executable.truncate(idx);
|
||||||
|
if (!m_executable.isEmpty()) {
|
||||||
|
// Finish extra round ...
|
||||||
|
showStatusMessage(tr("Attached to core temporarily."));
|
||||||
|
m_engine->postCommand(_("detach"));
|
||||||
|
// ... and retry.
|
||||||
|
loadExeAndSyms();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showMessageBox(QMessageBox::Warning, tr("Error Loading Symbols"),
|
||||||
|
tr("Unable to determine executable from core file."));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
showStatusMessage(tr("Attached to core."));
|
showStatusMessage(tr("Attached to core."));
|
||||||
setState(InferiorUnrunnable);
|
setState(InferiorUnrunnable);
|
||||||
m_engine->updateAll();
|
m_engine->updateAll();
|
||||||
} else {
|
} else {
|
||||||
QString msg = tr("Attach to core \"%1\" failed:\n%2")
|
QString msg = tr("Attach to core \"%1\" failed:\n").arg(startParameters().coreFile)
|
||||||
.arg(__(response.data.findChild("msg").data()));
|
+ __(response.data.findChild("msg").data());
|
||||||
setState(InferiorUnrunnable);
|
emit inferiorStartFailed(msg);
|
||||||
m_engine->updateAll();
|
|
||||||
// emit inferiorStartFailed(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,6 +32,10 @@
|
|||||||
|
|
||||||
#include "abstractgdbadapter.h"
|
#include "abstractgdbadapter.h"
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
# define EXE_FROM_CORE
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Debugger {
|
namespace Debugger {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -55,11 +59,14 @@ public:
|
|||||||
void interruptInferior();
|
void interruptInferior();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleTargetCore1(const GdbResponse &response);
|
void loadExeAndSyms();
|
||||||
void handleDetach1(const GdbResponse &response);
|
void loadCoreFile();
|
||||||
void handleFileExecAndSymbols(const GdbResponse &response);
|
void handleFileExecAndSymbols(const GdbResponse &response);
|
||||||
void handleTargetCore2(const GdbResponse &response);
|
void handleTargetCore(const GdbResponse &response);
|
||||||
|
|
||||||
|
#ifdef EXE_FROM_CORE
|
||||||
|
int m_round;
|
||||||
|
#endif
|
||||||
QString m_executable;
|
QString m_executable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user