Commit 150af7af authored by hjk's avatar hjk

Debugger: Merge GdbEngine's {run,post,flush}Command

Since we don't keep a local queue anymore, the distinction is
no more needed. Also, this is close to the LLDB side now.

Also move remaining uses of DebuggerCommand::flags to
GdbEngine, since that's the only user.

Change-Id: I61ae0f4e5294e306ab0b202e80f27fb3e3f7a7d7
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
parent 25bb8411
......@@ -51,17 +51,10 @@ class DebuggerCommand
public:
typedef std::function<void(const DebuggerResponse &)> Callback;
DebuggerCommand() : flags(0) {}
DebuggerCommand(const char *f, int flags = 0, Callback cb = Callback())
: function(f), callback(cb), flags(flags)
{}
DebuggerCommand(const char *f, const QJsonValue &a, int flags = 0, Callback cb = Callback())
: function(f), args(a), callback(cb), flags(flags)
{}
DebuggerCommand(const char *f, Callback cb)
: function(f), callback(cb), flags(0)
{}
DebuggerCommand(const QByteArray &f) : function(f), flags(0) {}
DebuggerCommand() {}
DebuggerCommand(const char *f) : function(f) {}
DebuggerCommand(const QByteArray &f) : function(f) {}
DebuggerCommand(const char *f, const QJsonValue &a) : function(f), args(a) {}
void arg(const char *value);
void arg(const char *name, int value);
......@@ -81,6 +74,9 @@ public:
Callback callback;
uint postTime; // msecsSinceStartOfDay
int flags;
private:
void argHelper(const char *name, const QByteArray &value);
};
/*
......
......@@ -75,8 +75,9 @@ void GdbAttachEngine::runEngine()
{
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
const qint64 pid = runParameters().attachPID;
postCommand("attach " + QByteArray::number(pid), NoFlags,
[this](const DebuggerResponse &r) { handleAttach(r); });
DebuggerCommand cmd("attach " + QByteArray::number(pid));
cmd.callback = [this](const DebuggerResponse &r) { handleAttach(r); };
runCommand(cmd);
showStatusMessage(tr("Attached to process %1.").arg(inferiorPid()));
}
......
......@@ -212,8 +212,9 @@ void GdbCoreEngine::setupInferior()
// Do that first, otherwise no symbols are loaded.
QFileInfo fi(m_executable);
QByteArray path = fi.absoluteFilePath().toLocal8Bit();
postCommand("-file-exec-and-symbols \"" + path + '"', NoFlags,
CB(handleFileExecAndSymbols));
DebuggerCommand cmd("-file-exec-and-symbols \"" + path + '"');
cmd.callback = CB(handleFileExecAndSymbols);
runCommand(cmd);
}
void GdbCoreEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
......@@ -236,7 +237,9 @@ void GdbCoreEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
void GdbCoreEngine::runEngine()
{
CHECK_STATE(EngineRunRequested);
postCommand("target core " + coreFileName().toLocal8Bit(), NoFlags, CB(handleTargetCore));
DebuggerCommand cmd("target core " + coreFileName().toLocal8Bit());
cmd.callback = CB(handleTargetCore);
runCommand(cmd);
}
void GdbCoreEngine::handleTargetCore(const DebuggerResponse &response)
......@@ -249,7 +252,7 @@ void GdbCoreEngine::handleTargetCore(const DebuggerResponse &response)
// symbols yet. Load them in order of importance.
reloadStack();
reloadModulesInternal();
postCommand("p 5", NoFlags, CB(handleRoundTrip));
runCommand("p 5", CB(handleRoundTrip));
return;
}
showStatusMessage(tr("Attach to core \"%1\" failed:").arg(runParameters().coreFile)
......
This diff is collapsed.
......@@ -155,8 +155,6 @@ private: ////////// Gdb Command Management //////////
NeedsStop = 1,
// No need to wait for the reply before continuing inferior.
Discardable = 2,
// We can live without receiving an answer.
NonCriticalResponse = 8,
// Callback expects ResultRunning instead of ResultDone.
RunRequest = 16,
// Callback expects ResultExit instead of ResultDone.
......@@ -168,20 +166,18 @@ private: ////////// Gdb Command Management //////////
// This is a command that needs to be wrapped into -interpreter-exec console
ConsoleCommand = 512,
// This is the UpdateLocals commannd during which we ignore notifications
InUpdateLocals = 1024
InUpdateLocals = 1024,
// This is a command using the python interface
PythonCommand = 2048
};
Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag)
// Type and cookie are sender-internal data, opaque for the "event
// queue". resultNeeded == true increments m_pendingResults on
// send and decrements on receipt, effectively preventing
// watch model updates before everything is finished.
void flushCommand(const DebuggerCommand &cmd);
protected:
void runCommand(const DebuggerCommand &command);
void postCommand(const QByteArray &command,
int flags = NoFlags,
DebuggerCommand::Callback callback = DebuggerCommand::Callback());
void runCommand(const DebuggerCommand &command, int flags = NoFlags);
void runCommand(const QByteArray &command,
const DebuggerCommand::Callback &callback,
int flags = NoFlags);
private:
Q_SLOT void commandTimeout();
void setTokenBarrier();
......@@ -190,6 +186,7 @@ private:
void scheduleTestResponse(int testCase, const QByteArray &response);
QHash<int, DebuggerCommand> m_commandForToken;
QHash<int, int> m_flagsForToken;
int commandTimeoutTime() const;
QTimer m_commandTimer;
......@@ -395,12 +392,10 @@ protected:
void showToolTip();
void handleVarAssign(const DebuggerResponse &response);
void handleDetach(const DebuggerResponse &response);
void handleThreadGroupCreated(const GdbMi &result);
void handleThreadGroupExited(const GdbMi &result);
Q_SLOT void createFullBacktrace();
void handleCreateFullBacktrace(const DebuggerResponse &response);
void doUpdateLocals(const UpdateParameters &parameters) override;
void handleStackFrame(const DebuggerResponse &response);
......
......@@ -60,10 +60,10 @@ void GdbPlainEngine::setupInferior()
setEnvironmentVariables();
if (!runParameters().processArgs.isEmpty()) {
QString args = runParameters().processArgs;
postCommand("-exec-arguments " + toLocalEncoding(args));
runCommand("-exec-arguments " + toLocalEncoding(args));
}
postCommand("-file-exec-and-symbols \"" + execFilePath() + '"',
NoFlags, CB(handleFileExecAndSymbols));
runCommand("-file-exec-and-symbols \"" + execFilePath() + '"',
CB(handleFileExecAndSymbols));
}
void GdbPlainEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
......@@ -84,11 +84,10 @@ void GdbPlainEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
void GdbPlainEngine::runEngine()
{
if (runParameters().useContinueInsteadOfRun)
postCommand("-exec-continue", GdbEngine::RunRequest, CB(handleExecuteContinue));
runCommand("-exec-continue", CB(handleExecuteContinue), RunRequest);
else
postCommand("-exec-run", GdbEngine::RunRequest, CB(handleExecRun));
runCommand("-exec-run", CB(handleExecRun), RunRequest);
}
void GdbPlainEngine::handleExecRun(const DebuggerResponse &response)
{
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
......@@ -99,7 +98,7 @@ void GdbPlainEngine::handleExecRun(const DebuggerResponse &response)
showMessage(msgInferiorSetupOk(), StatusBar);
// FIXME: That's the wrong place for it.
if (boolSetting(EnableReverseDebugging))
postCommand("target record");
runCommand("target record");
} 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())
postCommand("set solib-search-path " + solibSearchPath.toLocal8Bit());
runCommand("set solib-search-path " + solibSearchPath.toLocal8Bit());
if (!args.isEmpty())
postCommand("-exec-arguments " + args.toLocal8Bit());
runCommand("-exec-arguments " + args.toLocal8Bit());
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))
postCommand("set target-async on", NoFlags, CB(handleSetTargetAsync));
runCommand("set target-async on", CB(handleSetTargetAsync));
if (executableFileName.isEmpty()) {
showMessage(tr("No symbol file given."), StatusBar);
......@@ -219,8 +219,8 @@ void GdbRemoteServerEngine::setupInferior()
}
if (!executableFileName.isEmpty()) {
postCommand("-file-exec-and-symbols \"" + executableFileName.toLocal8Bit() + '"',
NoFlags, CB(handleFileExecAndSymbols));
runCommand("-file-exec-and-symbols \"" + executableFileName.toLocal8Bit() + '"',
CB(handleFileExecAndSymbols));
}
}
......@@ -270,11 +270,11 @@ void GdbRemoteServerEngine::callTargetRemote()
}
if (m_isQnxGdb)
postCommand("target qnx " + channel, NoFlags, CB(handleTargetQnx));
runCommand("target qnx " + channel, CB(handleTargetQnx));
else if (runParameters().multiProcess)
postCommand("target extended-remote " + channel, NoFlags, CB(handleTargetExtendedRemote));
runCommand("target extended-remote " + channel, CB(handleTargetExtendedRemote));
else
postCommand("target remote " + channel, NoFlags, CB(handleTargetRemote));
runCommand("target remote " + channel, 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')))
postCommand(cmd.toLatin1());
runCommand(cmd.toLatin1());
}
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')))
postCommand(cmd.toLatin1());
runCommand(cmd.toLatin1());
}
if (runParameters().attachPID > 0) { // attach to pid if valid
// gdb server will stop the remote application itself.
postCommand("attach " + QByteArray::number(runParameters().attachPID),
NoFlags, CB(handleTargetExtendedAttach));
runCommand("attach " + QByteArray::number(runParameters().attachPID),
CB(handleTargetExtendedAttach));
} else {
postCommand("-gdb-set remote exec-file " + runParameters().remoteExecutable.toLatin1(),
NoFlags, CB(handleTargetExtendedAttach));
runCommand("-gdb-set remote exec-file " + runParameters().remoteExecutable.toLatin1(),
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)
postCommand("attach " + QByteArray::number(pid), NoFlags, CB(handleAttach));
runCommand("attach " + QByteArray::number(pid), CB(handleAttach));
else if (!remoteExecutable.isEmpty())
postCommand("set nto-executable " + remoteExecutable.toLatin1(), NoFlags, CB(handleSetNtoExecutable));
runCommand("set nto-executable " + remoteExecutable.toLatin1(), CB(handleSetNtoExecutable));
else
handleInferiorPrepared();
} else {
......@@ -409,7 +409,7 @@ void GdbRemoteServerEngine::runEngine()
const QString remoteExecutable = runParameters().remoteExecutable;
if (!remoteExecutable.isEmpty()) {
postCommand("-exec-run", GdbEngine::RunRequest, CB(handleExecRun));
runCommand("-exec-run", CB(handleExecRun), RunRequest);
} else {
notifyEngineRunAndInferiorStopOk();
continueInferiorInternal();
......@@ -434,7 +434,7 @@ void GdbRemoteServerEngine::interruptInferior2()
{
QTC_ASSERT(state() == InferiorStopRequested, qDebug() << state());
if (boolSetting(TargetAsync)) {
postCommand("-exec-interrupt", NoFlags, CB(handleInterruptInferior));
runCommand("-exec-interrupt", CB(handleInterruptInferior));
} else if (m_isQnxGdb && HostOsInfo::isWindowsHost()) {
m_gdbProc.interrupt();
} else {
......
......@@ -134,8 +134,9 @@ void GdbTermEngine::runEngine()
{
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
const qint64 attachedPID = m_stubProc.applicationPID();
postCommand("attach " + QByteArray::number(attachedPID), NoFlags,
[this](const DebuggerResponse &r) { handleStubAttached(r); });
DebuggerCommand cmd("attach " + QByteArray::number(attachedPID));
cmd.callback = [this](const DebuggerResponse &r) { handleStubAttached(r); };
runCommand(cmd);
}
void GdbTermEngine::handleStubAttached(const DebuggerResponse &response)
......
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