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:
jimingham
2024-07-03 10:39:34 -07:00
committed by GitHub
parent 94471e6d23
commit 77d131eddb
13 changed files with 202 additions and 13 deletions

View File

@@ -2708,6 +2708,33 @@ bool ScriptInterpreterPythonImpl::RunScriptBasedParsedCommand(
return ret_val;
}
std::optional<std::string>
ScriptInterpreterPythonImpl::GetRepeatCommandForScriptedCommand(
StructuredData::GenericSP impl_obj_sp, Args &args) {
if (!impl_obj_sp || !impl_obj_sp->IsValid())
return std::nullopt;
lldb::DebuggerSP debugger_sp = m_debugger.shared_from_this();
if (!debugger_sp.get())
return std::nullopt;
std::optional<std::string> ret_val;
{
Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN,
Locker::FreeLock);
StructuredData::ArraySP args_arr_sp(new StructuredData::Array());
// For scripting commands, we send the command string:
std::string command;
args.GetQuotedCommandString(command);
ret_val = SWIGBridge::LLDBSwigPythonGetRepeatCommandForScriptedCommand(
static_cast<PyObject *>(impl_obj_sp->GetValue()), command);
}
return ret_val;
}
/// In Python, a special attribute __doc__ contains the docstring for an object
/// (function, method, class, ...) if any is defined Otherwise, the attribute's