debugger: refactoring in the gdbengine

This commit is contained in:
hjk
2009-09-11 12:30:53 +02:00
parent 7f54f9d339
commit 17f9204bba
7 changed files with 72 additions and 33 deletions

View File

@@ -430,6 +430,7 @@ private:
BreakpointData *findBreakpoint(const QString &fileName, int lineNumber); BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos); void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
// FIXME: Remove engine-specific state
QSharedPointer<DebuggerStartParameters> m_startParameters; QSharedPointer<DebuggerStartParameters> m_startParameters;
DebuggerRunControl *m_runControl; DebuggerRunControl *m_runControl;
QString m_dumperLib; QString m_dumperLib;

View File

@@ -138,6 +138,20 @@ static QByteArray parsePlainConsoleStream(const GdbResultRecord &record)
return out.mid(pos + 3); 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 // GdbEngine
@@ -1678,26 +1692,28 @@ void GdbEngine::startDebugger2()
} else if (m_startParameters.useTerminal) { } else if (m_startParameters.useTerminal) {
qq->breakHandler()->setAllPending(); qq->breakHandler()->setAllPending();
} else if (q->startMode() == StartInternal || q->startMode() == StartExternal) { } else if (q->startMode() == StartInternal || q->startMode() == StartExternal) {
QFileInfo fi(m_startParameters.executable); m_gdbProc->attach(this);
QString fileName = _c('"') + fi.absoluteFilePath() + _c('"'); if (m_gdbProc->isAdapter()) {
postCommand(_("-file-exec-and-symbols ") + fileName, CB(handleFileExecAndSymbols)); qq->notifyInferiorRunningRequested();
//postCommand(_("file ") + fileName, handleFileExecAndSymbols); postCommand(_("-exec-continue"), CB(handleExecContinue));
#ifdef Q_OS_MAC } else {
postCommand(_("sharedlibrary apply-load-rules all")); #ifdef Q_OS_MAC
#endif postCommand(_("sharedlibrary apply-load-rules all"));
if (!m_startParameters.processArgs.isEmpty()) #endif
postCommand(_("-exec-arguments ") + m_startParameters.processArgs.join(_(" "))); if (!m_startParameters.processArgs.isEmpty())
#ifndef Q_OS_MAC postCommand(_("-exec-arguments ") + m_startParameters.processArgs.join(_(" ")));
if (!m_dumperInjectionLoad) #ifdef Q_OS_MAC
postCommand(_("set auto-solib-add off")); // On MacOS, breaking in at the entry point wreaks havoc.
postCommand(_("info target"), CB(handleStart)); postCommand(_("tbreak main"));
#else m_waitingForFirstBreakpointToBeHit = true;
// On MacOS, breaking in at the entry point wreaks havoc. qq->notifyInferiorRunningRequested();
postCommand(_("tbreak main")); postCommand(_("-exec-run"), CB(handleExecRun));
m_waitingForFirstBreakpointToBeHit = true; #else
qq->notifyInferiorRunningRequested(); if (!m_dumperInjectionLoad)
postCommand(_("-exec-run"), CB(handleExecRun)); postCommand(_("set auto-solib-add off"));
#endif postCommand(_("info target"), CB(handleStart));
#endif
}
qq->breakHandler()->setAllPending(); qq->breakHandler()->setAllPending();
} }
@@ -1724,16 +1740,11 @@ void GdbEngine::handleStart(const GdbResultRecord &response, const QVariant &)
QString msg = _(response.data.findChild("consolestreamoutput").data()); QString msg = _(response.data.findChild("consolestreamoutput").data());
QRegExp needle(_("\\bEntry point: (0x[0-9a-f]+)\\b")); QRegExp needle(_("\\bEntry point: (0x[0-9a-f]+)\\b"));
if (needle.indexIn(msg) != -1) { if (needle.indexIn(msg) != -1) {
if (m_gdbProc->isAdapter()) { //debugMessage(_("STREAM: ") + msg + " " + needle.cap(1));
postCommand(_("-exec-continue"), CB(handleExecRun)); postCommand(_("tbreak *") + needle.cap(1));
qq->notifyInferiorRunningRequested(); m_waitingForFirstBreakpointToBeHit = true;
} else { qq->notifyInferiorRunningRequested();
//debugMessage(_("STREAM: ") + msg + " " + needle.cap(1)); postCommand(_("-exec-run"), CB(handleExecRun));
postCommand(_("tbreak *") + needle.cap(1));
m_waitingForFirstBreakpointToBeHit = true;
qq->notifyInferiorRunningRequested();
postCommand(_("-exec-run"), CB(handleExecRun));
}
} else { } else {
debugMessage(_("PARSING START ADDRESS FAILED: ") + msg); 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 &) void GdbEngine::handleSetTargetAsync(const GdbResultRecord &record, const QVariant &)
{ {
if (record.resultClass == GdbResultDone) { if (record.resultClass == GdbResultDone) {
//postCommand(_("info target"), handleStart);
qq->notifyInferiorRunningRequested(); qq->notifyInferiorRunningRequested();
postCommand(_("target remote %1").arg(q->startParameters()->remoteChannel), postCommand(_("target remote %1").arg(q->startParameters()->remoteChannel),
CB(handleTargetRemote)); CB(handleTargetRemote));

View File

@@ -107,6 +107,7 @@ public:
void setWorkingDirectory(const QString &dir) { m_proc.setWorkingDirectory(dir); } void setWorkingDirectory(const QString &dir) { m_proc.setWorkingDirectory(dir); }
void setEnvironment(const QStringList &env) { m_proc.setEnvironment(env); } void setEnvironment(const QStringList &env) { m_proc.setEnvironment(env); }
bool isAdapter() const { return false; } bool isAdapter() const { return false; }
void attach(GdbEngine *engine) const;
private: private:
QProcess m_proc; QProcess m_proc;
@@ -126,6 +127,11 @@ signals:
void applicationOutputAvailable(const QString &output); void applicationOutputAvailable(const QString &output);
private: private:
friend class GdbProcess;
friend class SymbianAdapter;
const DebuggerStartParameters &startParameters() const
{ return m_startParameters; }
// //
// IDebuggerEngine implementation // IDebuggerEngine implementation
// //
@@ -206,6 +212,7 @@ public: // otherwise the Qt flag macros are unhappy
}; };
Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag) Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag)
private: private:
typedef void (GdbEngine::*GdbCommandCallback)(const GdbResultRecord &record, const QVariant &cookie); typedef void (GdbEngine::*GdbCommandCallback)(const GdbResultRecord &record, const QVariant &cookie);

View File

@@ -36,6 +36,8 @@
namespace Debugger { namespace Debugger {
namespace Internal { namespace Internal {
class GdbEngine;
// GdbProcessBase is inherited by GdbProcess and the gdb/trk Adapter. // GdbProcessBase is inherited by GdbProcess and the gdb/trk Adapter.
// In the GdbProcess case it's just a wrapper around a QProcess running // 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 // 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 void setEnvironment(const QStringList &env) = 0;
virtual bool isAdapter() const = 0; virtual bool isAdapter() const = 0;
virtual void attach(GdbEngine *engine) const = 0;
signals: signals:
void error(QProcess::ProcessError); void error(QProcess::ProcessError);
void started(); void started();

View File

@@ -28,9 +28,11 @@
**************************************************************************/ **************************************************************************/
#include "symbianadapter.h" #include "symbianadapter.h"
#ifndef STANDALONE_RUNNER
#include "gdb/gdbengine.h"
#endif
#define TrkCB(s) TrkCallback(this, &SymbianAdapter::s) #define TrkCB(s) TrkCallback(this, &SymbianAdapter::s)
#define GdbCB(s) GdbCallback(this, &SymbianAdapter::s)
using namespace trk; using namespace trk;
@@ -1307,7 +1309,7 @@ void SymbianAdapter::sendGdbMessage(const QString &msg, GdbCallback callback,
data.command = msg; data.command = msg;
data.callback = callback; data.callback = callback;
data.cookie = cookie; data.cookie = cookie;
logMessage(QString("<- GDB: %2").arg(msg)); logMessage(QString("<- ADAPTER TO GDB: %2").arg(msg));
m_gdbProc.write(msg.toLatin1() + "\n"); m_gdbProc.write(msg.toLatin1() + "\n");
} }
@@ -1410,5 +1412,17 @@ void SymbianAdapter::setEnvironment(const QStringList &env)
m_gdbProc.setEnvironment(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 Internal
} // namespace Debugger } // namespace Debugger

View File

@@ -132,6 +132,7 @@ public:
void setWorkingDirectory(const QString &dir); void setWorkingDirectory(const QString &dir);
void setEnvironment(const QStringList &env); void setEnvironment(const QStringList &env);
bool isAdapter() const { return true; } bool isAdapter() const { return true; }
void attach(GdbEngine *engine) const;
// //
// TRK // TRK

View File

@@ -4,6 +4,8 @@ TEMPLATE = app
DEBUGGERHOME = ../../../src/plugins/debugger/symbian DEBUGGERHOME = ../../../src/plugins/debugger/symbian
INCLUDEPATH *= $$DEBUGGERHOME INCLUDEPATH *= $$DEBUGGERHOME
DEFINES += STANDALONE_RUNNER
QT += network QT += network
win32:CONFIG+=console win32:CONFIG+=console