Skip to content

Commit 9e7a695

Browse files
committed
Remove glob logic for plugin names
We now only support matching plugin namespace or fully qualified names.
1 parent 779e727 commit 9e7a695

File tree

5 files changed

+64
-181
lines changed

5 files changed

+64
-181
lines changed

lldb/include/lldb/Interpreter/CommandOptionArgumentTable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static constexpr CommandObject::ArgumentTableEntry g_argument_table[] = {
314314
{ lldb::eArgTypeModule, "module", lldb::CompletionType::eModuleCompletion, {}, { nullptr, false }, "The name of a module loaded into the current target." },
315315
{ lldb::eArgTypeCPUName, "cpu-name", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The name of a CPU." },
316316
{ lldb::eArgTypeCPUFeatures, "cpu-features", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The CPU feature string." },
317+
{ lldb::eArgTypeManagedPlugin, "managed-plugin", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "Plugins managed by the PluginManager" },
317318
// clang-format on
318319
};
319320

lldb/include/lldb/lldb-enumerations.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ enum CommandArgumentType {
663663
eArgTypeModule,
664664
eArgTypeCPUName,
665665
eArgTypeCPUFeatures,
666+
eArgTypeManagedPlugin,
666667
eArgTypeLastArg // Always keep this entry as the last entry in this
667668
// enumeration!!
668669
};

lldb/source/Commands/CommandObjectPlugin.cpp

Lines changed: 44 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -50,63 +50,34 @@ class CommandObjectPluginLoad : public CommandObjectParsed {
5050
};
5151

5252
namespace {
53-
#define LLDB_OPTIONS_plugin_list
54-
#include "CommandOptions.inc"
55-
56-
// These option definitions are shared by the plugin list/enable/disable
57-
// commands.
58-
class PluginListCommandOptions : public Options {
59-
public:
60-
PluginListCommandOptions() = default;
61-
62-
~PluginListCommandOptions() override = default;
63-
64-
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
65-
ExecutionContext *execution_context) override {
66-
Status error;
67-
const int short_option = m_getopt_table[option_idx].val;
68-
69-
switch (short_option) {
70-
case 'x':
71-
m_exact_name_match = true;
72-
break;
73-
default:
74-
llvm_unreachable("Unimplemented option");
75-
}
76-
77-
return error;
78-
}
79-
80-
void OptionParsingStarting(ExecutionContext *execution_context) override {
81-
m_exact_name_match = false;
82-
}
83-
84-
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
85-
return llvm::ArrayRef(g_plugin_list_options);
86-
}
87-
88-
// Instance variables to hold the values for command options.
89-
bool m_exact_name_match = false;
90-
};
91-
9253
// Helper function to perform an action on each matching plugin.
9354
// The action callback is given the containing namespace along with plugin info
9455
// for each matching plugin.
9556
static int ActOnMatchingPlugins(
96-
llvm::GlobPattern pattern,
57+
const llvm::StringRef pattern,
9758
std::function<void(const PluginNamespace &plugin_namespace,
9859
const std::vector<RegisteredPluginInfo> &plugin_info)>
9960
action) {
10061
int num_matching = 0;
10162

10263
for (const PluginNamespace &plugin_namespace :
10364
PluginManager::GetPluginNamespaces()) {
65+
const bool match_namespace =
66+
pattern.empty() || pattern == plugin_namespace.name;
67+
10468
std::vector<RegisteredPluginInfo> matching_plugins;
10569
for (const RegisteredPluginInfo &plugin_info :
10670
plugin_namespace.get_info()) {
107-
std::string qualified_name =
108-
(plugin_namespace.name + "." + plugin_info.name).str();
109-
if (pattern.match(qualified_name))
71+
72+
// If we match the namespace, we can skip the plugin name check.
73+
bool match_qualified_name = false;
74+
if (!match_namespace) {
75+
std::string qualified_name =
76+
(plugin_namespace.name + "." + plugin_info.name).str();
77+
match_qualified_name = pattern == qualified_name;
78+
}
79+
80+
if (match_namespace || match_qualified_name)
11081
matching_plugins.push_back(plugin_info);
11182
}
11283

@@ -119,58 +90,10 @@ static int ActOnMatchingPlugins(
11990
return num_matching;
12091
}
12192

122-
// Return a string in glob syntax for matching plugins.
123-
static std::string GetPluginNamePatternString(llvm::StringRef user_input,
124-
bool add_default_glob) {
125-
std::string pattern_str = user_input.empty() ? "*" : user_input.str();
126-
127-
if (add_default_glob && pattern_str != "*")
128-
pattern_str = "*" + pattern_str + "*";
129-
130-
return pattern_str;
131-
}
132-
133-
// Attempts to create a glob pattern for a plugin name based on plugin command
134-
// input. Writes an error message to the `result` object if the glob cannot be
135-
// created successfully.
136-
//
137-
// The `glob_storage` is used to hold the string data for the glob pattern. The
138-
// llvm::GlobPattern only contains pointers into the string data so we need a
139-
// stable location that can outlive the glob pattern itself.
140-
std::optional<llvm::GlobPattern>
141-
TryCreatePluginPattern(const char *plugin_command_name, const Args &command,
142-
const PluginListCommandOptions &options,
143-
CommandReturnObject &result, std::string &glob_storage) {
144-
size_t argc = command.GetArgumentCount();
145-
if (argc > 1) {
146-
result.AppendErrorWithFormat("'%s' requires one argument",
147-
plugin_command_name);
148-
return {};
149-
}
150-
151-
llvm::StringRef user_pattern = argc == 1 ? command[0].ref() : "";
152-
153-
glob_storage =
154-
GetPluginNamePatternString(user_pattern, !options.m_exact_name_match);
155-
156-
auto glob_pattern = llvm::GlobPattern::create(glob_storage);
157-
158-
if (auto error = glob_pattern.takeError()) {
159-
std::string error_message =
160-
(llvm::Twine("Invalid plugin glob pattern: '") + glob_storage +
161-
"': " + llvm::toString(std::move(error)))
162-
.str();
163-
result.AppendError(error_message);
164-
return {};
165-
}
166-
167-
return *glob_pattern;
168-
}
169-
17093
// Call the "SetEnable" function for each matching plugins.
17194
// Used to share the majority of the code between the enable
17295
// and disable commands.
173-
int SetEnableOnMatchingPlugins(const llvm::GlobPattern &pattern,
96+
int SetEnableOnMatchingPlugins(const llvm::StringRef &pattern,
17497
CommandReturnObject &result, bool enabled) {
17598
return ActOnMatchingPlugins(
17699
pattern, [&](const PluginNamespace &plugin_namespace,
@@ -198,7 +121,7 @@ class CommandObjectPluginList : public CommandObjectParsed {
198121
: CommandObjectParsed(interpreter, "plugin list",
199122
"Report info about registered LLDB plugins.",
200123
nullptr) {
201-
AddSimpleArgumentList(eArgTypePlugin);
124+
AddSimpleArgumentList(eArgTypeManagedPlugin);
202125
SetHelpLong(R"(
203126
Display information about registered plugins.
204127
The plugin information is formatted as shown below:
@@ -211,54 +134,41 @@ An enabled plugin is marked with [+] and a disabled plugin is marked with [-].
211134
212135
Plugins can be listed by namespace and name with:
213136
214-
plugin list [<plugin-namespace>.][<plugin-name>]
137+
plugin list <plugin-namespace>[.<plugin-name>]
215138
216-
Plugin names are specified using glob patterns. The pattern will be matched
217-
against the plugins fully qualified name, which is composed of the namespace,
218-
followed by a '.', followed by the plugin name.
219-
220-
When no arguments are given the plugin selection string is the wildcard '*'.
221-
By default wildcards are added around the input to enable searching by
222-
substring. You can prevent these implicit wild cards by using the
223-
-x flag.
139+
Plugins can be listed by namespace alone or with a fully qualified name. When listed
140+
with just a namespace all plugins in that namespace are listed. When no arguments
141+
are given all plugins are listed.
224142
225143
Examples:
226-
List all plugins in the system-runtime namespace
227-
228-
(lldb) plugin list system-runtime.*
144+
List all plugins
229145
230-
List all plugins containing the string foo
146+
(lldb) plugin list
231147
232-
(lldb) plugin list foo
233-
234-
This is equivalent to
148+
List all plugins in the system-runtime namespace
235149
236-
(lldb) plugin list *foo*
150+
(lldb) plugin list system-runtime
237151
238-
List only a plugin matching a fully qualified name exactly
152+
List only the plugin 'foo' matching a fully qualified name exactly
239153
240-
(lldb) plugin list -x system-runtime.foo
154+
(lldb) plugin list system-runtime.foo
241155
)");
242156
}
243157

244158
~CommandObjectPluginList() override = default;
245159

246-
Options *GetOptions() override { return &m_options; }
247-
248160
protected:
249161
void DoExecute(Args &command, CommandReturnObject &result) override {
250-
std::string glob_storage;
251-
std::optional<llvm::GlobPattern> plugin_glob = TryCreatePluginPattern(
252-
"plugin list", command, m_options, result, glob_storage);
253-
254-
if (!plugin_glob) {
255-
assert(!result.Succeeded());
162+
size_t argc = command.GetArgumentCount();
163+
if (argc > 1) {
164+
result.AppendError("'plugin load' requires one argument");
256165
return;
257166
}
167+
llvm::StringRef pattern = argc ? command[0].ref() : "";
258168

259169
int num_matching = ActOnMatchingPlugins(
260-
*plugin_glob, [&](const PluginNamespace &plugin_namespace,
261-
const std::vector<RegisteredPluginInfo> &plugins) {
170+
pattern, [&](const PluginNamespace &plugin_namespace,
171+
const std::vector<RegisteredPluginInfo> &plugins) {
262172
result.AppendMessage(plugin_namespace.name);
263173
for (auto &plugin : plugins) {
264174
result.AppendMessageWithFormat(
@@ -271,73 +181,59 @@ List only a plugin matching a fully qualified name exactly
271181
result.AppendErrorWithFormat("Found no matching plugins");
272182
}
273183
}
274-
275-
PluginListCommandOptions m_options;
276184
};
277185

278186
class CommandObjectPluginEnable : public CommandObjectParsed {
279187
public:
280188
CommandObjectPluginEnable(CommandInterpreter &interpreter)
281189
: CommandObjectParsed(interpreter, "plugin enable",
282190
"Enable registered LLDB plugins.", nullptr) {
283-
AddSimpleArgumentList(eArgTypePlugin);
191+
AddSimpleArgumentList(eArgTypeManagedPlugin);
284192
}
285193

286194
~CommandObjectPluginEnable() override = default;
287195

288-
Options *GetOptions() override { return &m_options; }
289-
290196
protected:
291197
void DoExecute(Args &command, CommandReturnObject &result) override {
292-
std::string glob_storage;
293-
std::optional<llvm::GlobPattern> plugin_glob = TryCreatePluginPattern(
294-
"plugin enable", command, m_options, result, glob_storage);
295-
296-
if (!plugin_glob) {
297-
assert(!result.Succeeded());
198+
size_t argc = command.GetArgumentCount();
199+
if (argc > 1) {
200+
result.AppendError("'plugin enable' requires one argument");
298201
return;
299202
}
203+
llvm::StringRef pattern = argc ? command[0].ref() : "";
300204

301-
int num_matching = SetEnableOnMatchingPlugins(*plugin_glob, result, true);
205+
int num_matching = SetEnableOnMatchingPlugins(pattern, result, true);
302206

303207
if (num_matching == 0) {
304208
result.AppendErrorWithFormat("Found no matching plugins to enable");
305209
}
306210
}
307-
308-
PluginListCommandOptions m_options;
309211
};
310212

311213
class CommandObjectPluginDisable : public CommandObjectParsed {
312214
public:
313215
CommandObjectPluginDisable(CommandInterpreter &interpreter)
314216
: CommandObjectParsed(interpreter, "plugin disable",
315217
"Disable registered LLDB plugins.", nullptr) {
316-
AddSimpleArgumentList(eArgTypePlugin);
218+
AddSimpleArgumentList(eArgTypeManagedPlugin);
317219
}
318220

319221
~CommandObjectPluginDisable() override = default;
320222

321-
Options *GetOptions() override { return &m_options; }
322-
323223
protected:
324224
void DoExecute(Args &command, CommandReturnObject &result) override {
325-
std::string glob_storage;
326-
std::optional<llvm::GlobPattern> plugin_glob = TryCreatePluginPattern(
327-
"plugin disable", command, m_options, result, glob_storage);
328-
329-
if (!plugin_glob) {
330-
assert(!result.Succeeded());
225+
size_t argc = command.GetArgumentCount();
226+
if (argc > 1) {
227+
result.AppendError("'plugin disable' requires one argument");
331228
return;
332229
}
230+
llvm::StringRef pattern = argc ? command[0].ref() : "";
333231

334-
int num_matching = SetEnableOnMatchingPlugins(*plugin_glob, result, false);
232+
int num_matching = SetEnableOnMatchingPlugins(pattern, result, false);
335233

336234
if (num_matching == 0)
337235
result.AppendErrorWithFormat("Found no matching plugins to disable");
338236
}
339-
340-
PluginListCommandOptions m_options;
341237
};
342238

343239
CommandObjectPlugin::CommandObjectPlugin(CommandInterpreter &interpreter)

lldb/test/Shell/Commands/command-plugin-enable+disable.test

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ plugin list
1414
# CHECK: [+] systemruntime-macosx System runtime plugin for Mac OS X native libraries
1515

1616
# Test plugin disable disables a plugin.
17-
plugin disable systemruntime-macosx
18-
# CHECK-LABEL: plugin disable systemruntime-macosx
17+
plugin disable system-runtime.systemruntime-macosx
18+
# CHECK-LABEL: plugin disable system-runtime.systemruntime-macosx
1919
# CHECK: system-runtime
2020
# CHECK: [-] systemruntime-macosx System runtime plugin for Mac OS X native libraries
2121

@@ -25,8 +25,8 @@ plugin list
2525
# CHECK: [-] systemruntime-macosx System runtime plugin for Mac OS X native libraries
2626

2727
# Test plugin enable re-enables a plugin.
28-
plugin enable systemruntime-macosx
29-
# CHECK-LABEL: plugin enable systemruntime-macosx
28+
plugin enable system-runtime.systemruntime-macosx
29+
# CHECK-LABEL: plugin enable system-runtime.systemruntime-macosx
3030
# CHECK: system-runtime
3131
# CHECK: [+] systemruntime-macosx System runtime plugin for Mac OS X native libraries
3232

@@ -35,15 +35,15 @@ plugin list
3535
# CHECK: system-runtime
3636
# CHECK: [+] systemruntime-macosx System runtime plugin for Mac OS X native libraries
3737

38-
# Test plugin disable with wildcard works.
39-
plugin disable system*
40-
# CHECK-LABEL: plugin disable system*
38+
# Test plugin disable with namespace works.
39+
plugin disable system-runtime
40+
# CHECK-LABEL: plugin disable system-runtime
4141
# CHECK: system-runtime
4242
# CHECK: [-] systemruntime-macosx System runtime plugin for Mac OS X native libraries
4343

44-
# Test plugin enable with wildcard works.
45-
plugin enable system*
46-
# CHECK-LABEL: plugin enable system*
44+
# Test plugin enable with namespace works.
45+
plugin enable system-runtime
46+
# CHECK-LABEL: plugin enable system-runtime
4747
# CHECK: system-runtime
4848
# CHECK: [+] systemruntime-macosx System runtime plugin for Mac OS X native libraries
4949

0 commit comments

Comments
 (0)