-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb] Add completions for plugin list/enable/disable #147775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |||||
| #include "lldb/Utility/Status.h" | ||||||
| #include "lldb/Utility/StringList.h" | ||||||
| #include "llvm/ADT/StringRef.h" | ||||||
| #include "llvm/ADT/Twine.h" | ||||||
| #include "llvm/Support/DynamicLibrary.h" | ||||||
| #include "llvm/Support/FileSystem.h" | ||||||
| #include "llvm/Support/raw_ostream.h" | ||||||
|
|
@@ -2473,3 +2474,34 @@ 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)); | ||||||
|
Comment on lines
+2494
to
+2497
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This StringRef will immediately point to deallocated stack memory after the lexical block ends. I took a cursory look at the APIs and it doesn't look like any of them copy the string. Is this a use-after-free or what makes this safe?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation of Checking the code,
And the
I believe the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, now that I see the code I remember I touched those lines not too long ago. Thanks for confirming. |
||||||
| } | ||||||
| } else if (plugin_ns.name.starts_with(name) && | ||||||
| !plugin_ns.get_info().empty()) { | ||||||
| // Otherwise check if the namespace is a prefix of the full name. | ||||||
| // Use a partial completion here so that we can either operate on the full | ||||||
| // namespace or tab-complete to the next level. | ||||||
| request.AddCompletion(plugin_ns.name, "", CompletionMode::Partial); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This eTerminatorCompletion is not good as it will change and any older binaries that linked against a previous version of LLDB could now get
eManagedPluginCompletioninstead ofeTerminatorCompletion. Can we remove theeTerminatorCompletion? It can cause API issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will follow up with a separate PR to remove it.