[Lldb-commits] [lldb] [lldb] Add completions for plugin list/enable/disable (PR #147775)

David Peixotto via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 10 10:22:07 PDT 2025


================
@@ -2473,3 +2474,35 @@ bool PluginManager::SetUnwindAssemblyPluginEnabled(llvm::StringRef name,
                                                    bool enable) {
   return GetUnwindAssemblyInstances().SetInstanceEnabled(name, enable);
 }
+
+void PluginManager::AutoCompletePluginName(llvm::StringRef name,
+                                           CompletionRequest &request) {
+  // Split the name into the namespace and the plugin name.
+  // If there is no dot then the ns_name will be equal to name and
+  // plugin_prefix will be empty.
+  llvm::StringRef ns_name, plugin_prefix;
+  std::tie(ns_name, plugin_prefix) = name.split('.');
+
+  for (const PluginNamespace &plugin_ns : GetPluginNamespaces()) {
+    // If the plugin namespace matches exactly then
+    // add all the plugins in this namespace as completions if the
+    // plugin names starts with the plugin_prefix. If the plugin_prefix
+    // is empty then it will match all the plugins (empty string is a
+    // prefix of everything).
+    if (plugin_ns.name == ns_name) {
+      for (const RegisteredPluginInfo &plugin : plugin_ns.get_info()) {
+        llvm::SmallString<128> buf;
+        if (plugin.name.starts_with(plugin_prefix))
+          request.AddCompletion(
+              (plugin_ns.name + "." + plugin.name).toStringRef(buf));
----------------
dmpots wrote:

The [documentation](https://github.com/llvm/llvm-project/blob/8d3f497eb834a84b954241b8c4293f8387e75576/lldb/include/lldb/Utility/CompletionRequest.h#L183C70-L184C76) of `AddCompletion` it says it will store a copy of the completion so it can be freed after.

Checking the code, `AddCompletion` calls `CompletionResult::AddResult` which constructs a new `Completion` object
https://github.com/llvm/llvm-project/blob/8d3f497eb834a84b954241b8c4293f8387e75576/lldb/source/Utility/CompletionRequest.cpp#L64

And the `Completion` object stores the value as a string and initializes it with a copy of the input StringRef.
https://github.com/llvm/llvm-project/blob/8d3f497eb834a84b954241b8c4293f8387e75576/lldb/include/lldb/Utility/CompletionRequest.h#L55

I believe the `StringRef` will point to valid memory for the lifetime of the call to `AddCompletion` and since it makes a copy of the data inside that function we should be safe.

https://github.com/llvm/llvm-project/pull/147775


More information about the lldb-commits mailing list