Commit 17f9204b authored by hjk's avatar hjk

debugger: refactoring in the gdbengine

parent 7f54f9d3
......@@ -430,6 +430,7 @@ private:
BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
// FIXME: Remove engine-specific state
QSharedPointer<DebuggerStartParameters> m_startParameters;
DebuggerRunControl *m_runControl;
QString m_dumperLib;
......
......@@ -138,6 +138,20 @@ static QByteArray parsePlainConsoleStream(const GdbResultRecord &record)
return out.mid(pos + 3);
}
///////////////////////////////////////////////////////////////////////
//
// GdbProcess
//
///////////////////////////////////////////////////////////////////////
void GdbProcess::attach(GdbEngine *engine) const
{
QFileInfo fi(engine->startParameters().executable);
QString fileName = fi.absoluteFilePath();
engine->postCommand(_("-file-exec-and-symbols ") + fileName,
&GdbEngine::handleFileExecAndSymbols, "handleFileExecAndSymbols");
}
///////////////////////////////////////////////////////////////////////
//
// GdbEngine
......@@ -1678,26 +1692,28 @@ void GdbEngine::startDebugger2()
} else if (m_startParameters.useTerminal) {
qq->breakHandler()->setAllPending();
} else if (q->startMode() == StartInternal || q->startMode() == StartExternal) {
QFileInfo fi(m_startParameters.executable);
QString fileName = _c('"') + fi.absoluteFilePath() + _c('"');
postCommand(_("-file-exec-and-symbols ") + fileName, CB(handleFileExecAndSymbols));
//postCommand(_("file ") + fileName, handleFileExecAndSymbols);
#ifdef Q_OS_MAC
postCommand(_("sharedlibrary apply-load-rules all"));
#endif
if (!m_startParameters.processArgs.isEmpty())
postCommand(_("-exec-arguments ") + m_startParameters.processArgs.join(_(" ")));
#ifndef Q_OS_MAC
if (!m_dumperInjectionLoad)
postCommand(_("set auto-solib-add off"));
postCommand(_("info target"), CB(handleStart));
#else
// On MacOS, breaking in at the entry point wreaks havoc.
postCommand(_("tbreak main"));
m_waitingForFirstBreakpointToBeHit = true;
qq->notifyInferiorRunningRequested();
postCommand(_("-exec-run"), CB(handleExecRun));
#endif
m_gdbProc->attach(this);
if (m_gdbProc->isAdapter()) {
qq->notifyInferiorRunningRequested();
postCommand(_("-exec-continue"), CB(handleExecContinue));
} else {
#ifdef Q_OS_MAC
postCommand(_("sharedlibrary apply-load-rules all"));
#endif
if (!m_startParameters.processArgs.isEmpty())
postCommand(_("-exec-arguments ") + m_startParameters.processArgs.join(_(" ")));
#ifdef Q_OS_MAC
// On MacOS, breaking in at the entry point wreaks havoc.
postCommand(_("tbreak main"));
m_waitingForFirstBreakpointToBeHit = true;
qq->notifyInferiorRunningRequested();
postCommand(_("-exec-run"), CB(handleExecRun));
#else
if (!m_dumperInjectionLoad)
postCommand(_("set auto-solib-add off"));
postCommand(_("info target"), CB(handleStart));
#endif
}
qq->breakHandler()->setAllPending();
}
......@@ -1724,16 +1740,11 @@ void GdbEngine::handleStart(const GdbResultRecord &response, const QVariant &)
QString msg = _(response.data.findChild("consolestreamoutput").data());
QRegExp needle(_("\\bEntry point: (0x[0-9a-f]+)\\b"));
if (needle.indexIn(msg) != -1) {
if (m_gdbProc->isAdapter()) {
postCommand(_("-exec-continue"), CB(handleExecRun));
qq->notifyInferiorRunningRequested();
} else {
//debugMessage(_("STREAM: ") + msg + " " + needle.cap(1));
postCommand(_("tbreak *") + needle.cap(1));
m_waitingForFirstBreakpointToBeHit = true;
qq->notifyInferiorRunningRequested();
postCommand(_("-exec-run"), CB(handleExecRun));
}
//debugMessage(_("STREAM: ") + msg + " " + needle.cap(1));
postCommand(_("tbreak *") + needle.cap(1));
m_waitingForFirstBreakpointToBeHit = true;
qq->notifyInferiorRunningRequested();
postCommand(_("-exec-run"), CB(handleExecRun));
} else {
debugMessage(_("PARSING START ADDRESS FAILED: ") + msg);
}
......@@ -1771,7 +1782,6 @@ void GdbEngine::handleAttach(const GdbResultRecord &, const QVariant &)
void GdbEngine::handleSetTargetAsync(const GdbResultRecord &record, const QVariant &)
{
if (record.resultClass == GdbResultDone) {
//postCommand(_("info target"), handleStart);
qq->notifyInferiorRunningRequested();
postCommand(_("target remote %1").arg(q->startParameters()->remoteChannel),
CB(handleTargetRemote));
......
......@@ -107,6 +107,7 @@ public:
void setWorkingDirectory(const QString &dir) { m_proc.setWorkingDirectory(dir); }
void setEnvironment(const QStringList &env) { m_proc.setEnvironment(env); }
bool isAdapter() const { return false; }
void attach(GdbEngine *engine) const;
private:
QProcess m_proc;
......@@ -126,6 +127,11 @@ signals:
void applicationOutputAvailable(const QString &output);
private:
friend class GdbProcess;
friend class SymbianAdapter;
const DebuggerStartParameters &startParameters() const
{ return m_startParameters; }
//
// IDebuggerEngine implementation
//
......@@ -206,6 +212,7 @@ public: // otherwise the Qt flag macros are unhappy
};
Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag)
private:
typedef void (GdbEngine::*GdbCommandCallback)(const GdbResultRecord &record, const QVariant &cookie);
......
......@@ -36,6 +36,8 @@
namespace Debugger {
namespace Internal {
class GdbEngine;
// GdbProcessBase is inherited by GdbProcess and the gdb/trk Adapter.
// In the GdbProcess case it's just a wrapper around a QProcess running
// gdb, in the Adapter case it's the interface to the gdb process in
......@@ -62,6 +64,8 @@ public:
virtual void setEnvironment(const QStringList &env) = 0;
virtual bool isAdapter() const = 0;
virtual void attach(GdbEngine *engine) const = 0;
signals:
void error(QProcess::ProcessError);
void started();
......
......@@ -28,9 +28,11 @@
**************************************************************************/
#include "symbianadapter.h"
#ifndef STANDALONE_RUNNER
#include "gdb/gdbengine.h"
#endif
#define TrkCB(s) TrkCallback(this, &SymbianAdapter::s)
#define GdbCB(s) GdbCallback(this, &SymbianAdapter::s)
using namespace trk;
......@@ -1307,7 +1309,7 @@ void SymbianAdapter::sendGdbMessage(const QString &msg, GdbCallback callback,
data.command = msg;
data.callback = callback;
data.cookie = cookie;
logMessage(QString("<- GDB: %2").arg(msg));
logMessage(QString("<- ADAPTER TO GDB: %2").arg(msg));
m_gdbProc.write(msg.toLatin1() + "\n");
}
......@@ -1410,5 +1412,17 @@ void SymbianAdapter::setEnvironment(const QStringList &env)
m_gdbProc.setEnvironment(env);
}
void SymbianAdapter::attach(GdbEngine *engine) const
{
#ifdef STANDALONE_RUNNER
#else
QString fileName = engine->startParameters().executable;
engine->postCommand(_("add-symbol-file \"%1\" %2").arg(fileName)
.arg(m_session.codeseg));
engine->postCommand(_("symbol-file \"%1\"").arg(fileName));
engine->postCommand(_("target remote ") + gdbServerName());
#endif
}
} // namespace Internal
} // namespace Debugger
......@@ -132,6 +132,7 @@ public:
void setWorkingDirectory(const QString &dir);
void setEnvironment(const QStringList &env);
bool isAdapter() const { return true; }
void attach(GdbEngine *engine) const;
//
// TRK
......
......@@ -4,6 +4,8 @@ TEMPLATE = app
DEBUGGERHOME = ../../../src/plugins/debugger/symbian
INCLUDEPATH *= $$DEBUGGERHOME
DEFINES += STANDALONE_RUNNER
QT += network
win32:CONFIG+=console
......
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