Skip to content

Commit 0f6515f

Browse files
committed
Move PluginNamespace array into PluginManager
1 parent 05bc4d4 commit 0f6515f

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

lldb/include/lldb/Core/PluginManager.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
#include "lldb/lldb-enumerations.h"
1919
#include "lldb/lldb-forward.h"
2020
#include "lldb/lldb-private-interfaces.h"
21+
#include "llvm/ADT/ArrayRef.h"
2122
#include "llvm/ADT/StringRef.h"
2223

2324
#include <cstddef>
2425
#include <cstdint>
26+
#include <functional>
2527
#include <vector>
2628

2729
#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName) \
@@ -54,12 +56,33 @@ struct RegisteredPluginInfo {
5456
bool enabled = false;
5557
};
5658

59+
// Define some data structures to describe known plugin "namespaces".
60+
// The PluginManager is organized into a series of static functions
61+
// that operate on different types of plugins. For example SystemRuntime
62+
// and ObjectFile plugins.
63+
//
64+
// The namespace name is used a prefix when matching plugin names. For example,
65+
// if we have an "elf" plugin in the "object-file" namespace then we will
66+
// match a plugin name pattern against the "object-file.elf" name.
67+
//
68+
// The plugin namespace here is used so we can operate on all the plugins
69+
// of a given type so it is easy to enable or disable them as a group.
70+
using GetPluginInfo = std::function<std::vector<RegisteredPluginInfo>()>;
71+
using SetPluginEnabled = std::function<bool(llvm::StringRef, bool)>;
72+
struct PluginNamespace {
73+
llvm::StringRef name;
74+
GetPluginInfo get_info;
75+
SetPluginEnabled set_enabled;
76+
};
77+
5778
class PluginManager {
5879
public:
5980
static void Initialize();
6081

6182
static void Terminate();
6283

84+
static llvm::ArrayRef<PluginNamespace> GetPluginNamespaces();
85+
6386
// ABI
6487
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
6588
ABICreateInstance create_callback);

lldb/source/Commands/CommandObjectPlugin.cpp

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,6 @@ class PluginListCommandOptions : public Options {
8989
bool m_exact_name_match = false;
9090
};
9191

92-
// Define some data structures to describe known plugin "namespaces".
93-
// The PluginManager is organized into a series of static functions
94-
// that operate on different types of plugin. For example SystemRuntime
95-
// and ObjectFile plugins.
96-
//
97-
// The namespace name is used a prefix when matching plugin names. For example,
98-
// if we have an "elf" plugin in the "object-file" namespace then we will
99-
// match a plugin name pattern against the "object-file.elf" name.
100-
//
101-
// The plugin namespace here is used so we can operate on all the plugins
102-
// of a given type so it is easy to enable or disable them as a group.
103-
using GetPluginInfo = std::function<std::vector<RegisteredPluginInfo>()>;
104-
using SetPluginEnabled = std::function<bool(llvm::StringRef, bool)>;
105-
struct PluginNamespace {
106-
llvm::StringRef name;
107-
GetPluginInfo get_info;
108-
SetPluginEnabled set_enabled;
109-
};
110-
111-
// Currently supported set of plugin namespaces. This will be expanded
112-
// over time.
113-
PluginNamespace PluginNamespaces[] = {
114-
{"system-runtime", PluginManager::GetSystemRuntimePluginInfo,
115-
PluginManager::SetSystemRuntimePluginEnabled}};
116-
11792
// Helper function to perform an action on each matching plugin.
11893
// The action callback is given the containing namespace along with plugin info
11994
// for each matching plugin.
@@ -124,7 +99,8 @@ static int ActOnMatchingPlugins(
12499
action) {
125100
int num_matching = 0;
126101

127-
for (const PluginNamespace &plugin_namespace : PluginNamespaces) {
102+
for (const PluginNamespace &plugin_namespace :
103+
PluginManager::GetPluginNamespaces()) {
128104
std::vector<RegisteredPluginInfo> matching_plugins;
129105
for (const RegisteredPluginInfo &plugin_info :
130106
plugin_namespace.get_info()) {

lldb/source/Core/PluginManager.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ void PluginManager::Terminate() {
181181
plugin_map.clear();
182182
}
183183

184+
llvm::ArrayRef<PluginNamespace> PluginManager::GetPluginNamespaces() {
185+
// Currently supported set of plugin namespaces. This will be expanded
186+
// over time.
187+
static PluginNamespace PluginNamespaces[] = {
188+
{"system-runtime", PluginManager::GetSystemRuntimePluginInfo,
189+
PluginManager::SetSystemRuntimePluginEnabled}};
190+
191+
return PluginNamespaces;
192+
}
193+
184194
template <typename Callback> struct PluginInstance {
185195
typedef Callback CallbackType;
186196

0 commit comments

Comments
 (0)