aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python
diff options
context:
space:
mode:
authorjimingham <jingham@apple.com>2024-09-24 10:00:00 -0700
committerGitHub <noreply@github.com>2024-09-24 10:00:00 -0700
commit04b443e77845cd20ab5acc4356cee509316135dd (patch)
tree72ee14a4a01bba2b99af12c0b7524a931205b4b4 /lldb/source/Plugins/ScriptInterpreter/Python
parentc6bf59f26b2d74474a66182db6ebd576273bfb00 (diff)
downloadllvm-04b443e77845cd20ab5acc4356cee509316135dd.zip
llvm-04b443e77845cd20ab5acc4356cee509316135dd.tar.gz
llvm-04b443e77845cd20ab5acc4356cee509316135dd.tar.bz2
Add the ability to define custom completers to the parsed_cmd template. (#109062)
If your arguments or option values are of a type that naturally uses one of our common completion mechanisms, you will get completion for free. But if you have your own custom values or if you want to do fancy things like have `break set -s foo.dylib -n ba<TAB>` only complete on symbols in foo.dylib, you can use this new mechanism to achieve that.
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h9
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp40
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h8
3 files changed, 57 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
index 81ee9ea0..518a478 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
@@ -200,6 +200,15 @@ public:
LLDBSwigPythonGetRepeatCommandForScriptedCommand(PyObject *implementor,
std::string &command);
+ static StructuredData::DictionarySP
+ LLDBSwigPythonHandleArgumentCompletionForScriptedCommand(
+ PyObject *implementor, std::vector<llvm::StringRef> &args_impl,
+ size_t args_pos, size_t pos_in_arg);
+
+ static StructuredData::DictionarySP
+ LLDBSwigPythonHandleOptionArgumentCompletionForScriptedCommand(
+ PyObject *implementor, llvm::StringRef &long_option, size_t pos_in_arg);
+
static bool LLDBSwigPythonCallModuleInit(const char *python_module_name,
const char *session_dictionary_name,
lldb::DebuggerSP debugger);
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 155efc0..db1a10e 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -2720,6 +2720,46 @@ ScriptInterpreterPythonImpl::GetRepeatCommandForScriptedCommand(
return ret_val;
}
+StructuredData::DictionarySP
+ScriptInterpreterPythonImpl::HandleArgumentCompletionForScriptedCommand(
+ StructuredData::GenericSP impl_obj_sp, std::vector<llvm::StringRef> &args,
+ size_t args_pos, size_t char_in_arg) {
+ StructuredData::DictionarySP completion_dict_sp;
+ if (!impl_obj_sp || !impl_obj_sp->IsValid())
+ return completion_dict_sp;
+
+ {
+ Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+ completion_dict_sp =
+ SWIGBridge::LLDBSwigPythonHandleArgumentCompletionForScriptedCommand(
+ static_cast<PyObject *>(impl_obj_sp->GetValue()), args, args_pos,
+ char_in_arg);
+ }
+ return completion_dict_sp;
+}
+
+StructuredData::DictionarySP
+ScriptInterpreterPythonImpl::HandleOptionArgumentCompletionForScriptedCommand(
+ StructuredData::GenericSP impl_obj_sp, llvm::StringRef &long_option,
+ size_t char_in_arg) {
+ StructuredData::DictionarySP completion_dict_sp;
+ if (!impl_obj_sp || !impl_obj_sp->IsValid())
+ return completion_dict_sp;
+
+ {
+ Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN,
+ Locker::FreeLock);
+
+ completion_dict_sp = SWIGBridge::
+ LLDBSwigPythonHandleOptionArgumentCompletionForScriptedCommand(
+ static_cast<PyObject *>(impl_obj_sp->GetValue()), long_option,
+ char_in_arg);
+ }
+ return completion_dict_sp;
+}
+
/// In Python, a special attribute __doc__ contains the docstring for an object
/// (function, method, class, ...) if any is defined Otherwise, the attribute's
/// value is None.
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
index d15e2fd..2dc7847 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h
@@ -166,6 +166,14 @@ public:
GetRepeatCommandForScriptedCommand(StructuredData::GenericSP impl_obj_sp,
Args &args) override;
+ StructuredData::DictionarySP HandleArgumentCompletionForScriptedCommand(
+ StructuredData::GenericSP impl_obj_sp, std::vector<llvm::StringRef> &args,
+ size_t args_pos, size_t char_in_arg) override;
+
+ StructuredData::DictionarySP HandleOptionArgumentCompletionForScriptedCommand(
+ StructuredData::GenericSP impl_obj_sp, llvm::StringRef &long_options,
+ size_t char_in_arg) override;
+
Status GenerateFunction(const char *signature, const StringList &input,
bool is_callback) override;