Skip to content

Add commands to list/enable/disable plugins #134418

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

Merged
merged 28 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e240bda
Add commands to list/enable/disable plugins
dmpots Mar 11, 2025
e1c3d46
Apply suggestions from code review
dmpots Apr 4, 2025
681ceaa
Fix formatting and compile error
dmpots Apr 4, 2025
05bc4d4
Fix formatting
dmpots Apr 4, 2025
0f6515f
Move PluginNamespace array into PluginManager
dmpots Apr 11, 2025
779e727
Fix wording in comments and help
dmpots Apr 11, 2025
9e7a695
Remove glob logic for plugin names
dmpots Apr 12, 2025
314cb2d
Get rid of now unused plugin-list option
dmpots Apr 24, 2025
9b41e47
Get rid of unused include
dmpots Apr 24, 2025
0aad1f6
Include plugin info in stats
dmpots Apr 24, 2025
1f863a6
Fix formatting
dmpots Apr 24, 2025
ef976cc
Set success on plugin commands
dmpots Apr 25, 2025
a386406
Add plugin stats test
dmpots Apr 25, 2025
0e7e77f
Clean up formatting
dmpots Apr 25, 2025
3bc5395
[NFC] Refactor - move plugin name matching to PluginManager
dmpots May 31, 2025
4b8dcec
Move json generation into PluginManager
dmpots May 31, 2025
8f1cfdc
Require one argument for enable/disable
dmpots May 31, 2025
99ca1f4
Support json output format for plugin list
dmpots Jun 1, 2025
2633292
Add unit test for MatchPluginName
dmpots Jun 2, 2025
6ada430
Add unit test for PluginManager::GetJSON
dmpots Jun 2, 2025
6260522
Formatting
dmpots Jun 2, 2025
bfcde3d
cleanup uneeded check for argc == 0
dmpots Jun 5, 2025
29aa20d
Use -DAG on json check patterns
dmpots Jun 5, 2025
735dd1f
Add support for enable/disable instrumentation-runtime plugins
dmpots Jun 5, 2025
b31b8a8
Support multiple values in plugin list
dmpots Jun 5, 2025
8b66ff5
Support multiple values in plugin enable
dmpots Jun 6, 2025
aea2cfb
Support multiple values for plugin disable
dmpots Jun 6, 2025
b8d9ad7
Add comment for boolean parameter
dmpots Jun 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions lldb/include/lldb/Core/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-forward.h"
#include "lldb/lldb-private-interfaces.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/JSON.h"

#include <cstddef>
#include <cstdint>
#include <functional>
#include <vector>

#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName) \
Expand Down Expand Up @@ -54,12 +57,67 @@ struct RegisteredPluginInfo {
bool enabled = false;
};

// Define some data structures to describe known plugin "namespaces".
// The PluginManager is organized into a series of static functions
// that operate on different types of plugins. For example SystemRuntime
// and ObjectFile plugins.
//
// The namespace name is used a prefix when matching plugin names. For example,
// if we have an "macosx" plugin in the "system-runtime" namespace then we will
// match a plugin name pattern against the "system-runtime.macosx" name.
//
// The plugin namespace here is used so we can operate on all the plugins
// of a given type so it is easy to enable or disable them as a group.
using GetPluginInfo = std::function<std::vector<RegisteredPluginInfo>()>;
using SetPluginEnabled = std::function<bool(llvm::StringRef, bool)>;
struct PluginNamespace {
llvm::StringRef name;
GetPluginInfo get_info;
SetPluginEnabled set_enabled;
};

class PluginManager {
public:
static void Initialize();

static void Terminate();

// Support for enabling and disabling plugins.

// Return the plugins that can be enabled or disabled by the user.
static llvm::ArrayRef<PluginNamespace> GetPluginNamespaces();

// Generate a json object that describes the plugins that are available.
// This is a json representation of the plugin info returned by
// GetPluginNamespaces().
//
// {
// <plugin-namespace>: [
// {
// "enabled": <bool>,
// "name": <plugin-name>,
// },
// ...
// ],
// ...
// }
//
// If pattern is given it will be used to filter the plugins that are
// are returned. The pattern filters the plugin names using the
// PluginManager::MatchPluginName() function.
static llvm::json::Object GetJSON(llvm::StringRef pattern = "");

// Return true if the pattern matches the plugin name.
//
// The pattern matches the name if it is exactly equal to the namespace name
// or if it is equal to the qualified name, which is the namespace name
// followed by a dot and the plugin name (e.g. "system-runtime.foo").
//
// An empty pattern matches all plugins.
static bool MatchPluginName(llvm::StringRef pattern,
const PluginNamespace &plugin_ns,
const RegisteredPluginInfo &plugin);

Comment on lines +110 to +120
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used outside of PluginManager.cpp? If not, move to PluginManager.cpp as a static function or function in anonymous namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in ActOnMatchingPlugins so that we do not duplicate the matching logic in multiple places.

// ABI
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
ABICreateInstance create_callback);
Expand Down Expand Up @@ -486,6 +544,12 @@ class PluginManager {
static InstrumentationRuntimeCreateInstance
GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx);

static std::vector<RegisteredPluginInfo>
GetInstrumentationRuntimePluginInfo();

static bool SetInstrumentationRuntimePluginEnabled(llvm::StringRef name,
bool enabled);

// TypeSystem
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
TypeSystemCreateInstance create_callback,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ static constexpr CommandObject::ArgumentTableEntry g_argument_table[] = {
{ lldb::eArgTypeModule, "module", lldb::CompletionType::eModuleCompletion, {}, { nullptr, false }, "The name of a module loaded into the current target." },
{ lldb::eArgTypeCPUName, "cpu-name", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The name of a CPU." },
{ lldb::eArgTypeCPUFeatures, "cpu-features", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "The CPU feature string." },
{ lldb::eArgTypeManagedPlugin, "managed-plugin", lldb::CompletionType::eNoCompletion, {}, { nullptr, false }, "Plugins managed by the PluginManager" },
// clang-format on
};

Expand Down
9 changes: 9 additions & 0 deletions lldb/include/lldb/Target/Statistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,21 @@ struct StatisticsOptions {
return !GetSummaryOnly();
}

void SetIncludePlugins(bool value) { m_include_plugins = value; }
bool GetIncludePlugins() const {
if (m_include_plugins.has_value())
return m_include_plugins.value();
// Default to true in both default mode and summary mode.
return true;
}

private:
std::optional<bool> m_summary_only;
std::optional<bool> m_load_all_debug_info;
std::optional<bool> m_include_targets;
std::optional<bool> m_include_modules;
std::optional<bool> m_include_transcript;
std::optional<bool> m_include_plugins;
};

/// A class that represents statistics about a TypeSummaryProviders invocations
Expand Down
1 change: 1 addition & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ enum CommandArgumentType {
eArgTypeModule,
eArgTypeCPUName,
eArgTypeCPUFeatures,
eArgTypeManagedPlugin,
eArgTypeLastArg // Always keep this entry as the last entry in this
// enumeration!!
};
Expand Down
Loading
Loading