Add the ability for Script based commands to specify their "repeat command" (#94823)
Among other things, returning an empty string as the repeat command disables auto-repeat, which can be useful for state-changing commands. There's one remaining refinement to this setup, which is that for parsed script commands, it should be possible to change an option value, or add a new option value that wasn't originally specified, then ask lldb "make this back into a command string". That would make doing fancy things with repeat commands easier. That capability isn't present in the lldb_private side either, however. So that's for a next iteration. I haven't added this to the docs on adding commands yet. I wanted to make sure this was an acceptable approach before I spend the time to do that.
This commit is contained in:
@@ -728,6 +728,28 @@ bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallCommandObject(
|
||||
return true;
|
||||
}
|
||||
|
||||
std::optional<std::string>
|
||||
lldb_private::python::SWIGBridge::LLDBSwigPythonGetRepeatCommandForScriptedCommand(PyObject *implementor,
|
||||
std::string &command) {
|
||||
PyErr_Cleaner py_err_cleaner(true);
|
||||
|
||||
PythonObject self(PyRefType::Borrowed, implementor);
|
||||
auto pfunc = self.ResolveName<PythonCallable>("get_repeat_command");
|
||||
// If not implemented, repeat the exact command.
|
||||
if (!pfunc.IsAllocated())
|
||||
return std::nullopt;
|
||||
|
||||
PythonString command_str(command);
|
||||
PythonObject result = pfunc(command_str);
|
||||
|
||||
// A return of None is the equivalent of nullopt - means repeat
|
||||
// the command as is:
|
||||
if (result.IsNone())
|
||||
return std::nullopt;
|
||||
|
||||
return result.Str().GetString().str();
|
||||
}
|
||||
|
||||
#include "lldb/Interpreter/CommandReturnObject.h"
|
||||
|
||||
bool lldb_private::python::SWIGBridge::LLDBSwigPythonCallParsedCommandObject(
|
||||
|
||||
Reference in New Issue
Block a user