Skip to content

Commit aea2cfb

Browse files
committed
Support multiple values for plugin disable
1 parent 8b66ff5 commit aea2cfb

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

lldb/source/Commands/CommandObjectPlugin.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,30 @@ List only the plugin 'foo' matching a fully qualified name exactly
261261
PluginListCommandOptions m_options;
262262
};
263263

264+
static void DoPluginEnableDisable(Args &command, CommandReturnObject &result,
265+
bool enable) {
266+
const char *name = enable ? "enable" : "disable";
267+
size_t argc = command.GetArgumentCount();
268+
if (argc == 0) {
269+
result.AppendErrorWithFormat("'plugin %s' requires one or more arguments",
270+
name);
271+
return;
272+
}
273+
result.SetStatus(eReturnStatusSuccessFinishResult);
274+
275+
for (size_t i = 0; i < argc; ++i) {
276+
llvm::StringRef pattern = command[i].ref();
277+
int num_matching = SetEnableOnMatchingPlugins(pattern, result, enable);
278+
279+
if (num_matching == 0) {
280+
result.AppendErrorWithFormat(
281+
"Found no matching plugins to %s for pattern '%s'", name,
282+
pattern.data());
283+
break;
284+
}
285+
}
286+
}
287+
264288
class CommandObjectPluginEnable : public CommandObjectParsed {
265289
public:
266290
CommandObjectPluginEnable(CommandInterpreter &interpreter)
@@ -273,23 +297,7 @@ class CommandObjectPluginEnable : public CommandObjectParsed {
273297

274298
protected:
275299
void DoExecute(Args &command, CommandReturnObject &result) override {
276-
size_t argc = command.GetArgumentCount();
277-
if (argc == 0) {
278-
result.AppendError("'plugin enable' requires one or more arguments");
279-
return;
280-
}
281-
result.SetStatus(eReturnStatusSuccessFinishResult);
282-
283-
for (size_t i = 0; i < argc; ++i)
284-
{
285-
llvm::StringRef pattern = command[i].ref();
286-
int num_matching = SetEnableOnMatchingPlugins(pattern, result, true);
287-
288-
if (num_matching == 0) {
289-
result.AppendErrorWithFormat("Found no matching plugins to enable for pattern '%s'",pattern.data());
290-
break;
291-
}
292-
}
300+
DoPluginEnableDisable(command, result, true);
293301
}
294302
};
295303

@@ -305,18 +313,7 @@ class CommandObjectPluginDisable : public CommandObjectParsed {
305313

306314
protected:
307315
void DoExecute(Args &command, CommandReturnObject &result) override {
308-
size_t argc = command.GetArgumentCount();
309-
if (argc != 1) {
310-
result.AppendError("'plugin disable' requires one argument");
311-
return;
312-
}
313-
llvm::StringRef pattern = command[0].ref();
314-
result.SetStatus(eReturnStatusSuccessFinishResult);
315-
316-
int num_matching = SetEnableOnMatchingPlugins(pattern, result, false);
317-
318-
if (num_matching == 0)
319-
result.AppendErrorWithFormat("Found no matching plugins to disable");
316+
DoPluginEnableDisable(command, result, false);
320317
}
321318
};
322319

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,18 @@ plugin disable instrumentation-runtime
6060
# Test plugin enable with multiple arguments.
6161
plugin enable system-runtime instrumentation-runtime
6262
# CHECK-LABEL: plugin enable system-runtime instrumentation-runtime
63-
CHECK: system-runtime
64-
CHECK: [+] systemruntime-macosx System runtime plugin for Mac OS X native libraries.
65-
CHECK: instrumentation-runtime
66-
CHECK: [+] AddressSanitizer AddressSanitizer instrumentation runtime plugin.
63+
# CHECK: system-runtime
64+
# CHECK: [+] systemruntime-macosx System runtime plugin for Mac OS X native libraries.
65+
# CHECK: instrumentation-runtime
66+
# CHECK: [+] AddressSanitizer AddressSanitizer instrumentation runtime plugin.
6767

68+
# Test plugin disable with multiple arguments.
69+
plugin disable system-runtime instrumentation-runtime
70+
# CHECK-LABEL: plugin disable system-runtime instrumentation-runtime
71+
# CHECK: system-runtime
72+
# CHECK: [-] systemruntime-macosx System runtime plugin for Mac OS X native libraries.
73+
# CHECK: instrumentation-runtime
74+
# CHECK: [-] AddressSanitizer AddressSanitizer instrumentation runtime plugin.
6875

6976
# Test plugin enable/disable for unknown plugin returns an error.
7077
# RUN: %lldb -o "plugin enable some-plugin-that-does-not-exist" 2>&1 | FileCheck %s --check-prefix=ERROR_PLUGIN_NOT_FOUND
@@ -77,5 +84,4 @@ CHECK: [+] AddressSanitizer AddressSanitizer instrumentation run
7784
# ERROR_ARGUMENTS_ENABLE: error: 'plugin enable' requires one or more arguments
7885

7986
# RUN: %lldb -o "plugin disable" 2>&1 | FileCheck %s --check-prefix=ERROR_ARGUMENTS_DISABLE
80-
# RUN: %lldb -o "plugin disable a b c" 2>&1 | FileCheck %s --check-prefix=ERROR_ARGUMENTS_DISABLE
81-
# ERROR_ARGUMENTS_DISABLE: error: 'plugin disable' requires one argument
87+
# ERROR_ARGUMENTS_DISABLE: error: 'plugin disable' requires one or more arguments

0 commit comments

Comments
 (0)