Commit 2b16b97f authored by hjk's avatar hjk

Debugger: Make DebuggerEngine::runCommand() virtual.

Allows default implementation of e.g. stack retrieval in the base
class.

Change-Id: I96460b19aa31347b2c863736b4ce2b5046eb4de6
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 3febe4e7
This diff is collapsed.
......@@ -127,7 +127,7 @@ private slots:
void readyReadStandardError();
void processError();
void processFinished();
void runCommand(const DebuggerCommand &cmd, int flags = 0);
void runCommand(const DebuggerCommand &cmd) override;
void operateByInstructionTriggered(bool);
void verboseLogTriggered(bool);
......@@ -164,7 +164,7 @@ private:
ParseStackWow64 = 3 // Hit on a frame with 32bit emulation, switch debugger to 32 bit mode
};
enum CommandFlags {
NoCallBack = 0,
NoFlags = 0,
BuiltinCommand,
ExtensionCommand,
};
......
......@@ -1479,6 +1479,12 @@ void DebuggerEngine::watchPoint(const QPoint &)
{
}
void DebuggerEngine::runCommand(const DebuggerCommand &)
{
// Overridden in the engines that use the interface.
QTC_CHECK(false);
}
void DebuggerEngine::fetchDisassembler(DisassemblerAgent *)
{
}
......
......@@ -33,6 +33,7 @@
#include "debugger_global.h"
#include "debuggerconstants.h"
#include "debuggerprotocol.h"
#include "debuggerstartparameters.h"
#include <projectexplorer/devicesupport/idevice.h>
......@@ -61,7 +62,6 @@ namespace Internal {
class DebuggerEnginePrivate;
class DebuggerPluginPrivate;
class DisassemblerAgent;
class GdbMi;
class MemoryAgent;
class WatchData;
class WatchItem;
......@@ -217,6 +217,7 @@ public:
MemoryView = 0x4 //!< Open a separate view (using the pos-parameter).
};
virtual void runCommand(const DebuggerCommand &cmd);
virtual void openMemoryView(const MemoryViewSetupData &data);
virtual void fetchMemory(Internal::MemoryAgent *, QObject *,
quint64 addr, quint64 length);
......
......@@ -52,9 +52,10 @@ public:
typedef std::function<void(const DebuggerResponse &)> Callback;
DebuggerCommand() {}
DebuggerCommand(const char *f, int fl = 0) : function(f), flags(fl) {}
DebuggerCommand(const QByteArray &f, int fl = 0) : function(f), flags(fl) {}
DebuggerCommand(const char *f, const QJsonValue &a, int fl = 0) : function(f), args(a), flags(fl) {}
DebuggerCommand(const QByteArray &f) : function(f), flags(0) {}
DebuggerCommand(const QByteArray &f, const QJsonValue &a) : function(f), args(a), flags(0) {}
DebuggerCommand(const QByteArray &f, int fl) : function(f), flags(fl) {}
DebuggerCommand(const QByteArray &f, int fl, const Callback &cb) : function(f), callback(cb), flags(fl) {}
void arg(const char *value);
void arg(const char *name, int value);
......
......@@ -75,9 +75,8 @@ void GdbAttachEngine::runEngine()
{
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
const qint64 pid = runParameters().attachPID;
DebuggerCommand cmd("attach " + QByteArray::number(pid));
cmd.callback = [this](const DebuggerResponse &r) { handleAttach(r); };
runCommand(cmd);
runCommand({"attach " + QByteArray::number(pid), NoFlags,
[this](const DebuggerResponse &r) { handleAttach(r); }});
showStatusMessage(tr("Attached to process %1.").arg(inferiorPid()));
}
......
......@@ -212,9 +212,8 @@ void GdbCoreEngine::setupInferior()
// Do that first, otherwise no symbols are loaded.
QFileInfo fi(m_executable);
QByteArray path = fi.absoluteFilePath().toLocal8Bit();
DebuggerCommand cmd("-file-exec-and-symbols \"" + path + '"');
cmd.callback = CB(handleFileExecAndSymbols);
runCommand(cmd);
runCommand({"-file-exec-and-symbols \"" + path + '"', NoFlags,
CB(handleFileExecAndSymbols)});
}
void GdbCoreEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
......@@ -237,9 +236,8 @@ void GdbCoreEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
void GdbCoreEngine::runEngine()
{
CHECK_STATE(EngineRunRequested);
DebuggerCommand cmd("target core " + coreFileName().toLocal8Bit());
cmd.callback = CB(handleTargetCore);
runCommand(cmd);
runCommand({"target core " + coreFileName().toLocal8Bit(), NoFlags,
CB(handleTargetCore)});
}
void GdbCoreEngine::handleTargetCore(const DebuggerResponse &response)
......@@ -252,7 +250,7 @@ void GdbCoreEngine::handleTargetCore(const DebuggerResponse &response)
// symbols yet. Load them in order of importance.
reloadStack();
reloadModulesInternal();
runCommand("p 5", CB(handleRoundTrip));
runCommand({"p 5", NoFlags, CB(handleRoundTrip)});
return;
}
showStatusMessage(tr("Attach to core \"%1\" failed:").arg(runParameters().coreFile)
......
This diff is collapsed.
......@@ -172,12 +172,7 @@ private: ////////// Gdb Command Management //////////
};
Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag)
protected:
void runCommand(const DebuggerCommand &command);
void runCommand(const QByteArray &command, int flags);
void runCommand(const QByteArray &command,
const DebuggerCommand::Callback &callback,
int flags = NoFlags);
void runCommand(const DebuggerCommand &command) override;
private:
Q_SLOT void commandTimeout();
......
......@@ -60,10 +60,10 @@ void GdbPlainEngine::setupInferior()
setEnvironmentVariables();
if (!runParameters().processArgs.isEmpty()) {
QString args = runParameters().processArgs;
runCommand("-exec-arguments " + toLocalEncoding(args));
runCommand({"-exec-arguments " + toLocalEncoding(args), NoFlags});
}
runCommand("-file-exec-and-symbols \"" + execFilePath() + '"',
CB(handleFileExecAndSymbols));
runCommand({"-file-exec-and-symbols \"" + execFilePath() + '"', NoFlags,
CB(handleFileExecAndSymbols)});
}
void GdbPlainEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
......@@ -84,9 +84,9 @@ void GdbPlainEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
void GdbPlainEngine::runEngine()
{
if (runParameters().useContinueInsteadOfRun)
runCommand("-exec-continue", CB(handleExecuteContinue), RunRequest);
runCommand({"-exec-continue", RunRequest, CB(handleExecuteContinue)});
else
runCommand("-exec-run", CB(handleExecRun), RunRequest);
runCommand({"-exec-run", RunRequest, CB(handleExecRun)});
}
void GdbPlainEngine::handleExecRun(const DebuggerResponse &response)
{
......@@ -98,7 +98,7 @@ void GdbPlainEngine::handleExecRun(const DebuggerResponse &response)
showMessage(msgInferiorSetupOk(), StatusBar);
// FIXME: That's the wrong place for it.
if (boolSetting(EnableReverseDebugging))
runCommand("target record");
runCommand({"target record", NoFlags});
} else {
QString msg = fromLocalEncoding(response.data["msg"].data());
//QTC_CHECK(status() == InferiorRunOk);
......
......@@ -183,10 +183,10 @@ void GdbRemoteServerEngine::setupInferior()
// postCommand("set architecture " + remoteArch);
const QString solibSearchPath = rp.solibSearchPath.join(HostOsInfo::pathListSeparator());
if (!solibSearchPath.isEmpty())
runCommand("set solib-search-path " + solibSearchPath.toLocal8Bit());
runCommand({"set solib-search-path " + solibSearchPath.toLocal8Bit(), NoFlags});
if (!args.isEmpty())
runCommand("-exec-arguments " + args.toLocal8Bit());
runCommand({"-exec-arguments " + args.toLocal8Bit(), NoFlags});
setEnvironmentVariables();
......@@ -210,7 +210,7 @@ void GdbRemoteServerEngine::setupInferior()
// mi_execute_async_cli_command: Assertion `is_running (inferior_ptid)'
// failed.\nA problem internal to GDB has been detected,[...]
if (boolSetting(TargetAsync))
runCommand("set target-async on", CB(handleSetTargetAsync));
runCommand({"set target-async on", NoFlags, CB(handleSetTargetAsync)});
if (executableFileName.isEmpty()) {
showMessage(tr("No symbol file given."), StatusBar);
......@@ -219,8 +219,8 @@ void GdbRemoteServerEngine::setupInferior()
}
if (!executableFileName.isEmpty()) {
runCommand("-file-exec-and-symbols \"" + executableFileName.toLocal8Bit() + '"',
CB(handleFileExecAndSymbols));
runCommand({"-file-exec-and-symbols \"" + executableFileName.toLocal8Bit() + '"',
NoFlags, CB(handleFileExecAndSymbols)});
}
}
......@@ -270,11 +270,11 @@ void GdbRemoteServerEngine::callTargetRemote()
}
if (m_isQnxGdb)
runCommand("target qnx " + channel, CB(handleTargetQnx));
runCommand({"target qnx " + channel, NoFlags, CB(handleTargetQnx)});
else if (runParameters().multiProcess)
runCommand("target extended-remote " + channel, CB(handleTargetExtendedRemote));
runCommand({"target extended-remote " + channel, NoFlags, CB(handleTargetExtendedRemote)});
else
runCommand("target remote " + channel, CB(handleTargetRemote));
runCommand({"target remote " + channel, NoFlags, CB(handleTargetRemote)});
}
void GdbRemoteServerEngine::handleTargetRemote(const DebuggerResponse &response)
......@@ -287,7 +287,7 @@ void GdbRemoteServerEngine::handleTargetRemote(const DebuggerResponse &response)
QString postAttachCommands = stringSetting(GdbPostAttachCommands);
if (!postAttachCommands.isEmpty()) {
foreach (const QString &cmd, postAttachCommands.split(QLatin1Char('\n')))
runCommand(cmd.toLatin1());
runCommand({cmd.toLatin1(), NoFlags});
}
handleInferiorPrepared();
} else {
......@@ -307,15 +307,15 @@ void GdbRemoteServerEngine::handleTargetExtendedRemote(const DebuggerResponse &r
QString postAttachCommands = stringSetting(GdbPostAttachCommands);
if (!postAttachCommands.isEmpty()) {
foreach (const QString &cmd, postAttachCommands.split(QLatin1Char('\n')))
runCommand(cmd.toLatin1());
runCommand({cmd.toLatin1(), NoFlags});
}
if (runParameters().attachPID > 0) { // attach to pid if valid
// gdb server will stop the remote application itself.
runCommand("attach " + QByteArray::number(runParameters().attachPID),
CB(handleTargetExtendedAttach));
runCommand({"attach " + QByteArray::number(runParameters().attachPID),
NoFlags, CB(handleTargetExtendedAttach)});
} else {
runCommand("-gdb-set remote exec-file " + runParameters().remoteExecutable.toLatin1(),
CB(handleTargetExtendedAttach));
runCommand({"-gdb-set remote exec-file " + runParameters().remoteExecutable.toLatin1(),
NoFlags, CB(handleTargetExtendedAttach)});
}
} else {
QString msg = msgConnectRemoteServerFailed(
......@@ -349,9 +349,9 @@ void GdbRemoteServerEngine::handleTargetQnx(const DebuggerResponse &response)
const qint64 pid = isMasterEngine() ? runParameters().attachPID : masterEngine()->runParameters().attachPID;
const QString remoteExecutable = isMasterEngine() ? runParameters().remoteExecutable : masterEngine()->runParameters().remoteExecutable;
if (pid > -1)
runCommand("attach " + QByteArray::number(pid), CB(handleAttach));
runCommand({"attach " + QByteArray::number(pid), NoFlags, CB(handleAttach)});
else if (!remoteExecutable.isEmpty())
runCommand("set nto-executable " + remoteExecutable.toLatin1(), CB(handleSetNtoExecutable));
runCommand({"set nto-executable " + remoteExecutable.toLatin1(), NoFlags, CB(handleSetNtoExecutable)});
else
handleInferiorPrepared();
} else {
......@@ -409,7 +409,7 @@ void GdbRemoteServerEngine::runEngine()
const QString remoteExecutable = runParameters().remoteExecutable;
if (!remoteExecutable.isEmpty()) {
runCommand("-exec-run", CB(handleExecRun), RunRequest);
runCommand({"-exec-run", RunRequest, CB(handleExecRun)});
} else {
notifyEngineRunAndInferiorStopOk();
continueInferiorInternal();
......@@ -434,7 +434,7 @@ void GdbRemoteServerEngine::interruptInferior2()
{
QTC_ASSERT(state() == InferiorStopRequested, qDebug() << state());
if (boolSetting(TargetAsync)) {
runCommand("-exec-interrupt", CB(handleInterruptInferior));
runCommand({"-exec-interrupt", NoFlags, CB(handleInterruptInferior)});
} else if (m_isQnxGdb && HostOsInfo::isWindowsHost()) {
m_gdbProc.interrupt();
} else {
......
......@@ -134,9 +134,8 @@ void GdbTermEngine::runEngine()
{
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
const qint64 attachedPID = m_stubProc.applicationPID();
DebuggerCommand cmd("attach " + QByteArray::number(attachedPID));
cmd.callback = [this](const DebuggerResponse &r) { handleStubAttached(r); };
runCommand(cmd);
runCommand({"attach " + QByteArray::number(attachedPID), NoFlags,
[this](const DebuggerResponse &r) { handleStubAttached(r); }});
}
void GdbTermEngine::handleStubAttached(const DebuggerResponse &response)
......
......@@ -130,17 +130,17 @@ void LldbEngine::executeDebuggerCommand(const QString &command, DebuggerLanguage
runCommand(cmd);
}
void LldbEngine::runCommand(const DebuggerCommand &command_)
void LldbEngine::runCommand(const DebuggerCommand &cmd)
{
QTC_ASSERT(m_lldbProc.state() == QProcess::Running, notifyEngineIll());
const int tok = ++currentToken();
DebuggerCommand command = command_;
DebuggerCommand command = cmd;
command.arg("token", tok);
QByteArray token = QByteArray::number(tok);
QByteArray cmd = command.function + "(" + command.argsToPython() + ")";
showMessage(_(token + cmd + '\n'), LogInput);
QByteArray function = command.function + "(" + command.argsToPython() + ")";
showMessage(_(token + function + '\n'), LogInput);
m_commandForToken[currentToken()] = command;
m_lldbProc.write("script theDumper." + cmd + "\n");
m_lldbProc.write("script theDumper." + function + "\n");
}
void LldbEngine::debugLastCommand()
......@@ -151,7 +151,7 @@ void LldbEngine::debugLastCommand()
void LldbEngine::shutdownInferior()
{
QTC_ASSERT(state() == InferiorShutdownRequested, qDebug() << state());
runCommand(DebuggerCommand("shutdownInferior"));
runCommand({"shutdownInferior"});
}
void LldbEngine::shutdownEngine()
......@@ -405,37 +405,37 @@ void LldbEngine::runEngine()
void LldbEngine::interruptInferior()
{
showStatusMessage(tr("Interrupt requested..."), 5000);
runCommand("interruptInferior");
runCommand({"interruptInferior"});
}
void LldbEngine::executeStep()
{
notifyInferiorRunRequested();
runCommand("executeStep");
runCommand({"executeStep"});
}
void LldbEngine::executeStepI()
{
notifyInferiorRunRequested();
runCommand("executeStepI");
runCommand({"executeStepI"});
}
void LldbEngine::executeStepOut()
{
notifyInferiorRunRequested();
runCommand("executeStepOut");
runCommand({"executeStepOut"});
}
void LldbEngine::executeNext()
{
notifyInferiorRunRequested();
runCommand("executeNext");
runCommand({"executeNext"});
}
void LldbEngine::executeNextI()
{
notifyInferiorRunRequested();
runCommand("executeNextI");
runCommand({"executeNextI"});
}
void LldbEngine::continueInferior()
......@@ -984,7 +984,7 @@ void LldbEngine::reloadRegisters()
void LldbEngine::reloadDebuggingHelpers()
{
runCommand("reloadDumpers");
runCommand({"reloadDumpers"});
updateAll();
}
......@@ -1037,7 +1037,7 @@ void LldbEngine::fetchFullBacktrace()
Internal::openTextEditor(_("Backtrace $"),
QString::fromUtf8(QByteArray::fromHex(response.data.data())));
};
runCommand("fetchFullBacktrace");
runCommand(cmd);
}
void LldbEngine::fetchMemory(MemoryAgent *agent, QObject *editorToken,
......
......@@ -147,7 +147,7 @@ private:
void notifyEngineRemoteSetupFinished(const RemoteSetupResult &result) override;
void runCommand(const DebuggerCommand &cmd);
void runCommand(const DebuggerCommand &cmd) override;
void debugLastCommand() override;
private:
......
......@@ -300,7 +300,7 @@ void PdbEngine::loadAllSymbols()
void PdbEngine::reloadModules()
{
runCommand("listModules");
runCommand({"listModules"});
}
void PdbEngine::refreshModules(const GdbMi &modules)
......@@ -557,7 +557,7 @@ void PdbEngine::refreshStack(const GdbMi &stack)
void PdbEngine::updateAll()
{
runCommand("stackListFrames");
runCommand({"stackListFrames"});
updateLocals();
}
......
......@@ -98,7 +98,7 @@ private:
bool isSynchronous() const override { return true; }
void updateItem(const QByteArray &iname) override;
void runCommand(const DebuggerCommand &cmd);
void runCommand(const DebuggerCommand &cmd) override;
void postDirectCommand(const QByteArray &command);
void refreshLocation(const GdbMi &reportedLocation);
......
......@@ -612,7 +612,7 @@ void QmlEngine::shutdownInferior()
// "type" : "request",
// "command" : "disconnect",
// }
d->runCommand(DISCONNECT);
d->runCommand({DISCONNECT});
if (isSlaveEngine())
resetLocation();
......@@ -2504,7 +2504,7 @@ void QmlEnginePrivate::stateChanged(State state)
/// Start session.
flushSendBuffer();
runDirectCommand(CONNECT);
runCommand(VERSION); // Only used for logging.
runCommand({VERSION}); // Only used for logging.
}
}
......
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