Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 1 | # Change Notes |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | This document describes an infrastructural feature called Structured |
Jason Molenda | 6546b9a | 2016-12-13 05:59:24 +0000 | [diff] [blame] | 6 | Data plugins. See the `DarwinLog.md` doc for a description of one |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 7 | such plugin that makes use of this feature. |
| 8 | |
| 9 | ## StructuredDataPlugin |
| 10 | |
| 11 | StructuredDataPlugin instances have the following characteristics: |
| 12 | |
| 13 | * Each plugin instance is bound to a single Process instance. |
| 14 | |
| 15 | * Each StructuredData feature has a type name that identifies the |
| 16 | feature. For instance, the type name for the DarwinLog feature is |
| 17 | "DarwinLog". This feature type name is used in various places. |
| 18 | |
| 19 | * The process monitor reports the list of supported StructuredData |
| 20 | features advertised by the process monitor. Process goes through the |
| 21 | list of supported feature type names, and asks each known |
| 22 | StructuredDataPlugin if it can handle the feature. The first plugin |
| 23 | that supports the feature is mapped to that Process instance for |
| 24 | that feature. Plugins are only mapped when the process monitor |
| 25 | advertises that a feature is supported. |
| 26 | |
| 27 | * The feature may send asynchronous messages in StructuredData format |
| 28 | to the Process instance. Process instances route the asynchronous |
| 29 | structured data messages to the plugin mapped to that feature type, |
| 30 | if one exists. |
| 31 | |
| 32 | * Plugins can request that the Process instance forward on |
| 33 | configuration data to the process monitor if the plugin needs/wants |
| 34 | to configure the feature. Plugins may call the new Process method |
| 35 | |
| 36 | ```C++ |
| 37 | virtual Error |
| 38 | ConfigureStructuredData(const ConstString &type_name, |
| 39 | const StructuredData::ObjectSP &config_sp) |
| 40 | ``` |
| 41 | |
Jason Molenda | 6546b9a | 2016-12-13 05:59:24 +0000 | [diff] [blame] | 42 | where `type_name` is the feature name and `config_sp` points to the |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 43 | configuration structured data, which may be nullptr. |
| 44 | |
| 45 | * Plugins for features present in a process are notified when modules |
| 46 | are loaded into the Process instance via this StructuredDataPlugin |
| 47 | method: |
| 48 | |
| 49 | ```C++ |
| 50 | virtual void |
| 51 | ModulesDidLoad(Process &process, ModuleList &module_list); |
| 52 | ``` |
| 53 | |
| 54 | * Plugins may optionally broadcast their received structured data as |
| 55 | an LLDB process-level event via the following new Process call: |
| 56 | |
| 57 | ```C++ |
| 58 | void |
| 59 | BroadcastStructuredData(const StructuredData::ObjectSP &object_sp, |
| 60 | const lldb::StructuredDataPluginSP &plugin_sp); |
| 61 | ``` |
| 62 | |
| 63 | IDE clients might use this feature to receive information about the |
| 64 | process as it is running to monitor memory usage, CPU usage, and |
| 65 | logging. |
| 66 | |
| 67 | Internally, the event type created is an instance of |
| 68 | EventDataStructuredData. |
| 69 | |
| 70 | * In the case where a plugin chooses to broadcast a received |
| 71 | StructuredData event, the command-line LLDB Debugger instance |
| 72 | listens for them. The Debugger instance then gives the plugin an |
| 73 | opportunity to display info to either the debugger output or error |
| 74 | stream at a time that is safe to write to them. The plugin can |
| 75 | choose to display something appropriate regarding the structured |
| 76 | data that time. |
| 77 | |
| 78 | * Plugins can provide a ProcessLaunchInfo filter method when the |
| 79 | plugin is registered. If such a filter method is provided, then |
| 80 | when a process is about to be launched for debugging, the filter |
| 81 | callback is invoked, given both the launch info and the target. The |
| 82 | plugin may then alter the launch info if needed to better support |
| 83 | the feature of the plugin. |
| 84 | |
| 85 | * The plugin is entirely independent of the type of Process-derived |
| 86 | class that it is working with. The only requirements from the |
| 87 | process monitor are the following feature-agnostic elements: |
| 88 | |
| 89 | * Provide a way to discover features supported by the process |
| 90 | monitor for the current process. |
| 91 | |
| 92 | * Specify the list of supported feature type names to Process. |
| 93 | The process monitor does this by calling the following new |
| 94 | method on Process: |
| 95 | |
| 96 | ```C++ |
| 97 | void |
| 98 | MapSupportedStructuredDataPlugins(const StructuredData::Array |
| 99 | &supported_type_names) |
| 100 | ``` |
| 101 | |
Jason Molenda | 6546b9a | 2016-12-13 05:59:24 +0000 | [diff] [blame] | 102 | The `supported_type_names` specifies an array of string entries, |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 103 | where each entry specifies the name of a StructuredData feature. |
| 104 | |
| 105 | * Provide a way to forward on configuration data for a feature type |
| 106 | to the process monitor. This is the manner by which LLDB can |
| 107 | configure a feature, perhaps based on settings or commands from |
| 108 | the user. The following virtual method on Process (described |
| 109 | earlier) does the job: |
| 110 | |
| 111 | ```C++ |
| 112 | virtual Error |
| 113 | ConfigureStructuredData(const ConstString &type_name, |
| 114 | const StructuredData::ObjectSP &config_sp) |
| 115 | ``` |
| 116 | |
| 117 | * Listen for asynchronous structured data packets from the process |
| 118 | monitor, and forward them on to Process via this new Process |
| 119 | member method: |
| 120 | |
| 121 | ```C++ |
| 122 | bool |
| 123 | RouteAsyncStructuredData(const StructuredData::ObjectSP object_sp) |
| 124 | ``` |
| 125 | |
| 126 | * StructuredData producers must send their top-level data as a |
| 127 | Dictionary type, with a key called 'type' specifying a string value, |
| 128 | where the value is equal to the StructuredData feature/type name |
| 129 | previously advertised. Everything else about the content of the |
| 130 | dictionary is entirely up to the feature. |
| 131 | |
Jason Molenda | 6546b9a | 2016-12-13 05:59:24 +0000 | [diff] [blame] | 132 | * StructuredDataPlugin commands show up under `plugin structured-data |
| 133 | plugin-name`. |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 134 | |
| 135 | * StructuredDataPlugin settings show up under |
Jason Molenda | 6546b9a | 2016-12-13 05:59:24 +0000 | [diff] [blame] | 136 | `plugin.structured-data.{plugin-name}`. |