|
19 | 19 | #include "lldb/lldb-enumerations.h"
|
20 | 20 | #include "lldb/lldb-forward.h"
|
21 | 21 | #include "lldb/lldb-private-interfaces.h"
|
| 22 | +#include "llvm/ADT/ArrayRef.h" |
22 | 23 | #include "llvm/ADT/StringRef.h"
|
| 24 | +#include "llvm/Support/JSON.h" |
23 | 25 |
|
24 | 26 | #include <cstddef>
|
25 | 27 | #include <cstdint>
|
| 28 | +#include <functional> |
26 | 29 | #include <vector>
|
27 | 30 |
|
28 | 31 | #define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName) \
|
@@ -55,12 +58,67 @@ struct RegisteredPluginInfo {
|
55 | 58 | bool enabled = false;
|
56 | 59 | };
|
57 | 60 |
|
| 61 | +// Define some data structures to describe known plugin "namespaces". |
| 62 | +// The PluginManager is organized into a series of static functions |
| 63 | +// that operate on different types of plugins. For example SystemRuntime |
| 64 | +// and ObjectFile plugins. |
| 65 | +// |
| 66 | +// The namespace name is used a prefix when matching plugin names. For example, |
| 67 | +// if we have an "macosx" plugin in the "system-runtime" namespace then we will |
| 68 | +// match a plugin name pattern against the "system-runtime.macosx" name. |
| 69 | +// |
| 70 | +// The plugin namespace here is used so we can operate on all the plugins |
| 71 | +// of a given type so it is easy to enable or disable them as a group. |
| 72 | +using GetPluginInfo = std::function<std::vector<RegisteredPluginInfo>()>; |
| 73 | +using SetPluginEnabled = std::function<bool(llvm::StringRef, bool)>; |
| 74 | +struct PluginNamespace { |
| 75 | + llvm::StringRef name; |
| 76 | + GetPluginInfo get_info; |
| 77 | + SetPluginEnabled set_enabled; |
| 78 | +}; |
| 79 | + |
58 | 80 | class PluginManager {
|
59 | 81 | public:
|
60 | 82 | static void Initialize();
|
61 | 83 |
|
62 | 84 | static void Terminate();
|
63 | 85 |
|
| 86 | + // Support for enabling and disabling plugins. |
| 87 | + |
| 88 | + // Return the plugins that can be enabled or disabled by the user. |
| 89 | + static llvm::ArrayRef<PluginNamespace> GetPluginNamespaces(); |
| 90 | + |
| 91 | + // Generate a json object that describes the plugins that are available. |
| 92 | + // This is a json representation of the plugin info returned by |
| 93 | + // GetPluginNamespaces(). |
| 94 | + // |
| 95 | + // { |
| 96 | + // <plugin-namespace>: [ |
| 97 | + // { |
| 98 | + // "enabled": <bool>, |
| 99 | + // "name": <plugin-name>, |
| 100 | + // }, |
| 101 | + // ... |
| 102 | + // ], |
| 103 | + // ... |
| 104 | + // } |
| 105 | + // |
| 106 | + // If pattern is given it will be used to filter the plugins that are |
| 107 | + // are returned. The pattern filters the plugin names using the |
| 108 | + // PluginManager::MatchPluginName() function. |
| 109 | + static llvm::json::Object GetJSON(llvm::StringRef pattern = ""); |
| 110 | + |
| 111 | + // Return true if the pattern matches the plugin name. |
| 112 | + // |
| 113 | + // The pattern matches the name if it is exactly equal to the namespace name |
| 114 | + // or if it is equal to the qualified name, which is the namespace name |
| 115 | + // followed by a dot and the plugin name (e.g. "system-runtime.foo"). |
| 116 | + // |
| 117 | + // An empty pattern matches all plugins. |
| 118 | + static bool MatchPluginName(llvm::StringRef pattern, |
| 119 | + const PluginNamespace &plugin_ns, |
| 120 | + const RegisteredPluginInfo &plugin); |
| 121 | + |
64 | 122 | // ABI
|
65 | 123 | static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
|
66 | 124 | ABICreateInstance create_callback);
|
@@ -491,6 +549,12 @@ class PluginManager {
|
491 | 549 | static InstrumentationRuntimeCreateInstance
|
492 | 550 | GetInstrumentationRuntimeCreateCallbackAtIndex(uint32_t idx);
|
493 | 551 |
|
| 552 | + static std::vector<RegisteredPluginInfo> |
| 553 | + GetInstrumentationRuntimePluginInfo(); |
| 554 | + |
| 555 | + static bool SetInstrumentationRuntimePluginEnabled(llvm::StringRef name, |
| 556 | + bool enabled); |
| 557 | + |
494 | 558 | // TypeSystem
|
495 | 559 | static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
|
496 | 560 | TypeSystemCreateInstance create_callback,
|
|
0 commit comments