Commit a61b6dfc authored by hjk's avatar hjk

Debugger: Move command flags to debugger command

Also, remove the need to mark GDB Python commands, detect the
need to use MI on the presence of non-Pythonic letters in
the command (space and hyphen).

Plan is to reuse even more almost shared code between engines.

Change-Id: I4e00debb07f2482637930675a28f464666b59553
Reviewed-by: default avatarhjk <hjk@qt.io>
parent c2eada27
......@@ -196,6 +196,21 @@ public:
const DebuggerRunParameters &runParameters() const;
DebuggerRunParameters &runParameters();
enum {
// Remove need to qualify each use.
NeedsTemporaryStop = DebuggerCommand::NeedsTemporaryStop,
NeedsFullStop = DebuggerCommand::NeedsFullStop,
Discardable = DebuggerCommand::Discardable,
ConsoleCommand = DebuggerCommand::ConsoleCommand,
NeedsFlush = DebuggerCommand::NeedsFlush,
ExitRequest = DebuggerCommand::ExitRequest,
RunRequest = DebuggerCommand::RunRequest,
LosesChild = DebuggerCommand::LosesChild,
RebuildBreakpointModel = DebuggerCommand::RebuildBreakpointModel,
InUpdateLocals = DebuggerCommand::InUpdateLocals,
Silent = DebuggerCommand::Silent
};
virtual bool canHandleToolTip(const DebuggerToolTipContext &) const;
virtual void expandItem(const QString &iname); // Called when item in tree gets expanded.
virtual void updateItem(const QString &iname); // Called for fresh watch items.
......
......@@ -50,6 +50,7 @@ public:
DebuggerCommand(const QString &f, const QJsonValue &a) : function(f), args(a) {}
DebuggerCommand(const QString &f, int fl) : function(f), flags(fl) {}
DebuggerCommand(const QString &f, int fl, const Callback &cb) : function(f), callback(cb), flags(fl) {}
DebuggerCommand(const QString &f, const Callback &cb) : function(f), callback(cb) {}
void arg(const char *value);
void arg(const char *name, bool value);
......@@ -65,6 +66,34 @@ public:
QString argsToPython() const;
QString argsToString() const;
enum CommandFlag {
NoFlags = 0,
// The command needs a stopped inferior.
NeedsTemporaryStop = 1,
// No need to wait for the reply before continuing inferior.
Discardable = 2,
// Needs a dummy extra command to force GDB output flushing.
NeedsFlush = 4,
// The command needs a stopped inferior and will stay stopped afterward.
NeedsFullStop = 8,
// Callback expects ResultRunning instead of ResultDone.
RunRequest = 16,
// Callback expects ResultExit instead of ResultDone.
ExitRequest = 32,
// Auto-set inferior shutdown related states.
LosesChild = 64,
// Trigger breakpoint model rebuild when no such commands are pending anymore.
RebuildBreakpointModel = 128,
// 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,
// Do not echo to log.
Silent = 4096
};
Q_DECLARE_FLAGS(CommandFlags, CommandFlag)
QString function;
QJsonValue args;
Callback callback;
......@@ -270,3 +299,5 @@ const char DisplayArrayData[] = "arraydata:separate";
} // namespace Internal
} // namespace Debugger
Q_DECLARE_OPERATORS_FOR_FLAGS(Debugger::Internal::DebuggerCommand::CommandFlags)
......@@ -61,7 +61,7 @@ void GdbAttachEngine::runEngine()
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
const qint64 pid = runParameters().attachPID;
showStatusMessage(tr("Attaching to process %1.").arg(pid));
runCommand({"attach " + QString::number(pid), NoFlags,
runCommand({"attach " + QString::number(pid),
[this](const DebuggerResponse &r) { handleAttach(r); }});
// In some cases we get only output like
// "Could not attach to process. If your uid matches the uid of the target\n"
......@@ -69,7 +69,7 @@ void GdbAttachEngine::runEngine()
// " again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf\n"
// " ptrace: Operation not permitted.\n"
// but no(!) ^ response. Use a second command to force *some* output
runCommand({"print 24", NoFlags});
runCommand({"print 24"});
}
void GdbAttachEngine::handleAttach(const DebuggerResponse &response)
......
......@@ -208,7 +208,7 @@ void GdbCoreEngine::setupInferior()
// Do that first, otherwise no symbols are loaded.
QFileInfo fi(m_executable);
QString path = fi.absoluteFilePath();
runCommand({"-file-exec-and-symbols \"" + path + '"', NoFlags,
runCommand({"-file-exec-and-symbols \"" + path + '"',
CB(handleFileExecAndSymbols)});
}
......@@ -232,8 +232,7 @@ void GdbCoreEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
void GdbCoreEngine::runEngine()
{
CHECK_STATE(EngineRunRequested);
runCommand({"target core " + coreFileName(), NoFlags,
CB(handleTargetCore)});
runCommand({"target core " + coreFileName(), CB(handleTargetCore)});
}
void GdbCoreEngine::handleTargetCore(const DebuggerResponse &response)
......@@ -253,7 +252,7 @@ void GdbCoreEngine::handleTargetCore(const DebuggerResponse &response)
// symbols yet. Load them in order of importance.
reloadStack();
reloadModulesInternal();
runCommand({"p 5", NoFlags, CB(handleRoundTrip)});
runCommand({"p 5", CB(handleRoundTrip)});
}
void GdbCoreEngine::handleRoundTrip(const DebuggerResponse &response)
......
This diff is collapsed.
......@@ -147,35 +147,7 @@ private:
// known function return value.
QString m_resultVarName;
private: ////////// Gdb Command Management //////////
public: // Otherwise the Qt flag macros are unhappy.
enum GdbCommandFlag {
NoFlags = 0,
// The command needs a stopped inferior.
NeedsTemporaryStop = 1,
// No need to wait for the reply before continuing inferior.
Discardable = 2,
// Needs a dummy extra command to force GDB output flushing.
NeedsFlush = 4,
// The command needs a stopped inferior and will stay stopped afterward.
NeedsFullStop = 8,
// Callback expects ResultRunning instead of ResultDone.
RunRequest = 16,
// Callback expects ResultExit instead of ResultDone.
ExitRequest = 32,
// Auto-set inferior shutdown related states.
LosesChild = 64,
// Trigger breakpoint model rebuild when no such commands are pending anymore.
RebuildBreakpointModel = 128,
// 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,
// This is a command using the python interface
PythonCommand = 2048
};
Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag)
protected: ////////// Gdb Command Management //////////
void runCommand(const DebuggerCommand &command) override;
......@@ -469,5 +441,3 @@ protected:
} // namespace Internal
} // namespace Debugger
Q_DECLARE_OPERATORS_FOR_FLAGS(Debugger::Internal::GdbEngine::GdbCommandFlags)
......@@ -54,15 +54,15 @@ void GdbPlainEngine::setupInferior()
setEnvironmentVariables();
const DebuggerRunParameters &rp = runParameters();
if (!rp.inferior.workingDirectory.isEmpty())
runCommand({"cd " + rp.inferior.workingDirectory, NoFlags});
runCommand({"cd " + rp.inferior.workingDirectory});
if (!rp.inferior.commandLineArguments.isEmpty()) {
QString args = rp.inferior.commandLineArguments;
runCommand({"-exec-arguments " + args, NoFlags});
runCommand({"-exec-arguments " + args});
}
QString executable = QFileInfo(runParameters().inferior.executable).absoluteFilePath();
runCommand({"-file-exec-and-symbols \"" + executable + '"', NoFlags,
CB(handleFileExecAndSymbols)});
runCommand({"-file-exec-and-symbols \"" + executable + '"',
CB(handleFileExecAndSymbols)});
}
void GdbPlainEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
......@@ -82,9 +82,9 @@ void GdbPlainEngine::handleFileExecAndSymbols(const DebuggerResponse &response)
void GdbPlainEngine::runEngine()
{
if (runParameters().useContinueInsteadOfRun)
runCommand({"-exec-continue", RunRequest, CB(handleExecuteContinue)});
runCommand({"-exec-continue", DebuggerCommand::RunRequest, CB(handleExecuteContinue)});
else
runCommand({"-exec-run", RunRequest, CB(handleExecRun)});
runCommand({"-exec-run", DebuggerCommand::RunRequest, CB(handleExecRun)});
}
void GdbPlainEngine::handleExecRun(const DebuggerResponse &response)
......@@ -97,7 +97,7 @@ void GdbPlainEngine::handleExecRun(const DebuggerResponse &response)
showMessage(msgInferiorSetupOk(), StatusBar);
// FIXME: That's the wrong place for it.
if (boolSetting(EnableReverseDebugging))
runCommand({"target record", NoFlags});
runCommand({"target record"});
} else {
QString msg = response.data["msg"].data();
//QTC_CHECK(status() == InferiorRunOk);
......
......@@ -177,10 +177,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, NoFlags});
runCommand({"set solib-search-path " + solibSearchPath});
if (!args.isEmpty())
runCommand({"-exec-arguments " + args, NoFlags});
runCommand({"-exec-arguments " + args});
setEnvironmentVariables();
......@@ -204,7 +204,7 @@ void GdbRemoteServerEngine::setupInferior()
// mi_execute_async_cli_command: Assertion `is_running (inferior_ptid)'
// failed.\nA problem internal to GDB has been detected,[...]
if (usesTargetAsync())
runCommand({"set target-async on", NoFlags, CB(handleSetTargetAsync)});
runCommand({"set target-async on", CB(handleSetTargetAsync)});
if (symbolFile.isEmpty()) {
showMessage(tr("No symbol file given."), StatusBar);
......@@ -214,7 +214,7 @@ void GdbRemoteServerEngine::setupInferior()
if (!symbolFile.isEmpty()) {
runCommand({"-file-exec-and-symbols \"" + symbolFile + '"',
NoFlags, CB(handleFileExecAndSymbols)});
CB(handleFileExecAndSymbols)});
}
}
......@@ -261,11 +261,11 @@ void GdbRemoteServerEngine::callTargetRemote()
}
if (m_isQnxGdb)
runCommand({"target qnx " + channel, NoFlags, CB(handleTargetQnx)});
runCommand({"target qnx " + channel, CB(handleTargetQnx)});
else if (runParameters().useExtendedRemote)
runCommand({"target extended-remote " + channel, NoFlags, CB(handleTargetExtendedRemote)});
runCommand({"target extended-remote " + channel, CB(handleTargetExtendedRemote)});
else
runCommand({"target remote " + channel, NoFlags, CB(handleTargetRemote)});
runCommand({"target remote " + channel, CB(handleTargetRemote)});
}
void GdbRemoteServerEngine::handleTargetRemote(const DebuggerResponse &response)
......@@ -277,7 +277,7 @@ void GdbRemoteServerEngine::handleTargetRemote(const DebuggerResponse &response)
showMessage(msgAttachedToStoppedInferior(), StatusBar);
QString commands = expand(stringSetting(GdbPostAttachCommands));
if (!commands.isEmpty())
runCommand({commands, NoFlags});
runCommand({commands});
handleInferiorPrepared();
} else {
// 16^error,msg="hd:5555: Connection timed out."
......@@ -293,14 +293,14 @@ void GdbRemoteServerEngine::handleTargetExtendedRemote(const DebuggerResponse &r
showMessage(msgAttachedToStoppedInferior(), StatusBar);
QString commands = expand(stringSetting(GdbPostAttachCommands));
if (!commands.isEmpty())
runCommand({commands, NoFlags});
runCommand({commands});
if (runParameters().attachPID > 0) { // attach to pid if valid
// gdb server will stop the remote application itself.
runCommand({"attach " + QString::number(runParameters().attachPID),
NoFlags, CB(handleTargetExtendedAttach)});
CB(handleTargetExtendedAttach)});
} else if (!runParameters().inferior.executable.isEmpty()) {
runCommand({"-gdb-set remote exec-file " + runParameters().inferior.executable,
NoFlags, CB(handleTargetExtendedAttach)});
CB(handleTargetExtendedAttach)});
} else {
const QString title = tr("No Remote Executable or Process ID Specified");
const QString msg = tr(
......@@ -350,9 +350,9 @@ void GdbRemoteServerEngine::handleTargetQnx(const DebuggerResponse &response)
const qint64 pid = rp.attachPID;
const QString remoteExecutable = rp.inferior.executable;
if (pid > -1)
runCommand({"attach " + QString::number(pid), NoFlags, CB(handleAttach)});
runCommand({"attach " + QString::number(pid), CB(handleAttach)});
else if (!remoteExecutable.isEmpty())
runCommand({"set nto-executable " + remoteExecutable, NoFlags, CB(handleSetNtoExecutable)});
runCommand({"set nto-executable " + remoteExecutable, CB(handleSetNtoExecutable)});
else
handleInferiorPrepared();
} else {
......@@ -408,7 +408,7 @@ void GdbRemoteServerEngine::runEngine()
notifyEngineRunAndInferiorStopOk();
continueInferiorInternal();
} else {
runCommand({"-exec-run", RunRequest, CB(handleExecRun)});
runCommand({"-exec-run", DebuggerCommand::RunRequest, CB(handleExecRun)});
}
}
......@@ -429,7 +429,7 @@ void GdbRemoteServerEngine::interruptInferior2()
{
QTC_ASSERT(state() == InferiorStopRequested, qDebug() << state());
if (usesTargetAsync()) {
runCommand({"-exec-interrupt", NoFlags, CB(handleInterruptInferior)});
runCommand({"-exec-interrupt", CB(handleInterruptInferior)});
} else if (m_isQnxGdb && HostOsInfo::isWindowsHost()) {
m_gdbProc.interrupt();
} else {
......
......@@ -128,7 +128,7 @@ void GdbTermEngine::runEngine()
{
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
const qint64 attachedPID = m_stubProc.applicationPID();
runCommand({"attach " + QString::number(attachedPID), NoFlags,
runCommand({"attach " + QString::number(attachedPID),
[this](const DebuggerResponse &r) { handleStubAttached(r); }});
}
......
......@@ -414,7 +414,7 @@ void LldbEngine::setupInferior()
}
};
cmd2.flags = LldbEngine::Silent;
cmd2.flags = Silent;
runCommand(cmd2);
}
......
......@@ -61,14 +61,6 @@ public:
explicit LldbEngine(const DebuggerRunParameters &runParameters);
~LldbEngine() override;
enum LldbCommandFlag {
NoFlags = 0,
// Do not echo to log.
Silent = 1,
// The command needs a stopped inferior and will stay stopped afterward.
NeedsFullStop = 8,
};
signals:
void outputReady(const QString &data);
......
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