Commit f5c6f667 authored by hjk's avatar hjk
Browse files

debugger: work on remote debugging using plain gdbserver

parent 063d13e0
......@@ -1294,6 +1294,7 @@ void DebuggerPlugin::startRemoteApplication()
StartRemoteDialog dlg(m_manager->mainWindow());
QStringList arches;
arches.append(_("i386:x86-64:intel"));
arches.append(_("i386"));
dlg.setRemoteArchitectures(arches);
dlg.setRemoteChannel(
configValue(_("LastRemoteChannel")).toString());
......
......@@ -99,11 +99,10 @@ void RemoteGdbAdapter::startAdapter()
QString location = theDebuggerStringSetting(GdbLocation);
/*
// FIXME: make asynchroneouis
// FIXME: make asynchroneous
// Start the remote server
if (startParameters().serverStartScript.isEmpty()) {
showStatusMessage(_("No server start script given. "
m_engine->showStatusMessage(_("No server start script given. "
"Assuming server runs already."));
} else {
if (!startParameters().workingDir.isEmpty())
......@@ -113,7 +112,6 @@ void RemoteGdbAdapter::startAdapter()
m_uploadProc.start(_("/bin/sh ") + startParameters().serverStartScript);
m_uploadProc.waitForStarted();
}
*/
// Start the debugger
m_gdbProc.start(location, gdbArgs);
......@@ -179,12 +177,28 @@ void RemoteGdbAdapter::prepareInferior()
{
QTC_ASSERT(state() == AdapterStarted, qDebug() << state());
setState(InferiorPreparing);
m_engine->postCommand(_("set architecture %1")
.arg(startParameters().remoteArchitecture));
if (!startParameters().processArgs.isEmpty())
m_engine->postCommand(_("-exec-arguments ")
+ startParameters().processArgs.join(_(" ")));
QFileInfo fi(m_engine->startParameters().executable);
m_engine->postCommand(_("-file-exec-and-symbols \"%1\"").arg(fi.absoluteFilePath()),
//qq->breakHandler()->setAllPending();
QFileInfo fi(startParameters().executable);
QString fileName = fi.absoluteFilePath();
m_engine->postCommand(_("-file-exec-and-symbols \"%1\"").arg(fileName),
CB(handleFileExecAndSymbols));
// works only for > 6.8
//postCommand(_("set target-async on"), CB(handleSetTargetAsync));
// a typical response on "old" gdb is:
// &"set target-async on\n"
//&"No symbol table is loaded. Use the \"file\" command.\n"
//^error,msg="No symbol table is loaded. Use the \"file\" command."
//postCommand(_("detach"));
//emit inferiorPreparationFailed(msg);
}
void RemoteGdbAdapter::handleFileExecAndSymbols(const GdbResultRecord &response, const QVariant &)
......@@ -192,11 +206,27 @@ void RemoteGdbAdapter::handleFileExecAndSymbols(const GdbResultRecord &response,
QTC_ASSERT(state() == InferiorPreparing, qDebug() << state());
if (response.resultClass == GdbResultDone) {
//m_breakHandler->clearBreakMarkers();
QString channel = startParameters().remoteChannel;
m_engine->postCommand(_("target remote %1").arg(channel),
CB(handleTargetRemote));
} else if (response.resultClass == GdbResultError) {
QString msg = tr("Starting remote executable failed:\n");
msg += __(response.data.findChild("msg").data());
setState(InferiorPreparationFailed);
emit inferiorPreparationFailed(msg);
}
}
void RemoteGdbAdapter::handleTargetRemote(const GdbResultRecord &record, const QVariant &)
{
QTC_ASSERT(state() == InferiorPreparing, qDebug() << state());
if (record.resultClass == GdbResultDone) {
setState(InferiorPrepared);
emit inferiorPrepared();
} else if (response.resultClass == GdbResultError) {
QString msg = tr("Starting executable failed:\n") +
__(response.data.findChild("msg").data());
} else if (record.resultClass == GdbResultError) {
// 16^error,msg="hd:5555: Connection timed out."
QString msg = tr("Connecting to remote server failed:\n");
msg += __(record.data.findChild("msg").data());
setState(InferiorPreparationFailed);
emit inferiorPreparationFailed(msg);
}
......@@ -206,22 +236,22 @@ void RemoteGdbAdapter::startInferior()
{
QTC_ASSERT(state() == InferiorPrepared, qDebug() << state());
setState(InferiorStarting);
m_engine->postCommand(_("-exec-run"), CB(handleExecRun));
m_engine->postCommand(_("attach"), CB(handleFirstContinue));
// FIXME: Is there a way to properly recognize a successful start?
setState(InferiorStarted);
emit inferiorStarted();
}
void RemoteGdbAdapter::handleExecRun(const GdbResultRecord &response, const QVariant &)
void RemoteGdbAdapter::handleFirstContinue(const GdbResultRecord &record, const QVariant &)
{
QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
if (response.resultClass == GdbResultRunning) {
setState(InferiorStarted);
emit inferiorStarted();
} else {
QTC_ASSERT(response.resultClass == GdbResultError, /**/);
const QByteArray &msg = response.data.findChild("msg").data();
//QTC_ASSERT(status() == DebuggerInferiorRunning, /**/);
//interruptInferior();
setState(InferiorStartFailed);
emit inferiorStartFailed(msg);
//QTC_ASSERT(state() == InferiorStarting, qDebug() << state());
QTC_ASSERT(state() == InferiorStarted, qDebug() << state());
if (record.resultClass == GdbResultDone) {
// inferiorStarted already emitted above, see FIXME
} else if (record.resultClass == GdbResultError) {
//QString msg = __(record.data.findChild("msg").data());
QString msg1 = tr("Connecting to remote server failed:\n");
emit inferiorStartFailed(msg1 + record.toString());
}
}
......@@ -232,20 +262,27 @@ void RemoteGdbAdapter::interruptInferior()
void RemoteGdbAdapter::shutdown()
{
if (state() == InferiorStarted) {
switch (state()) {
case AdapterNotRunning:
return;
case InferiorStarted:
setState(InferiorShuttingDown);
m_engine->postCommand(_("kill"), CB(handleKill));
return;
}
default:
QTC_ASSERT(false, qDebug() << state());
// fall through
if (state() == InferiorShutDown) {
case InferiorPreparationFailed:
case InferiorShutDown:
setState(AdapterShuttingDown);
m_engine->postCommand(_("-gdb-exit"), CB(handleExit));
return;
}
// FIXME: handle other states, too.
QTC_ASSERT(state() == AdapterNotRunning, qDebug() << state());
}
}
void RemoteGdbAdapter::handleKill(const GdbResultRecord &response, const QVariant &)
......
......@@ -74,7 +74,8 @@ private:
void handleFileExecAndSymbols(const GdbResultRecord &, const QVariant &);
void handleKill(const GdbResultRecord &, const QVariant &);
void handleExit(const GdbResultRecord &, const QVariant &);
void handleExecRun(const GdbResultRecord &response, const QVariant &);
void handleTargetRemote(const GdbResultRecord &response, const QVariant &);
void handleFirstContinue(const GdbResultRecord &response, const QVariant &);
void debugMessage(const QString &msg) { m_engine->debugMessage(msg); }
Q_SLOT void handleGdbFinished(int, QProcess::ExitStatus);
......
......@@ -7,9 +7,10 @@ targetdir=/tmp/run-${exename}
executable=${sourcedir}/${exename}
qtlibs=`ldd ${executable} | grep libQt | sed -e 's/^.*=> \(.*\) (.*)$/\1/'`
ssh ${account} "mkdir -p ${targetdir}"
scp ${executable} ${qtlibs} ${account}:${targetdir}
ssh ${account} "chrpath -r ${targetdir} ${targetdir}/*"
ssh -X ${account} "gdbserver localhost:5555 ${targetdir}/${exename}"
ssh ${account} "rm ${targetdir}/* ; rmdir ${targetdir}"
ssh ${account} "mkdir -p ${targetdir}" || exit 1
scp ${executable} ${qtlibs} ${account}:${targetdir} || exit 1
ssh ${account} "chrpath -r ${targetdir} ${targetdir}/*" || exit 1
ssh -X ${account} "gdbserver localhost:5555 ${targetdir}/${exename}" || exit 1
ssh ${account} "rm ${targetdir}/* ; rmdir ${targetdir}" || exit 1
exit 0
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