[Lldb-commits] [lldb] r279198 - Add StructuredData plugin type; showcase with new DarwinLog feature
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 18 20:12:45 PDT 2016
Weird, you linked to a phabricator revision but i never saw it come across
to the mailing list
On Thu, Aug 18, 2016 at 8:00 PM Todd Fiala via lldb-commits <
lldb-commits at lists.llvm.org> wrote:
> Author: tfiala
> Date: Thu Aug 18 21:52:07 2016
> New Revision: 279198
>
> URL: http://llvm.org/viewvc/llvm-project?rev=279198&view=rev
> Log:
> Add StructuredData plugin type; showcase with new DarwinLog feature
>
> See docs/structured_data/StructuredDataPlugins.md for details.
>
> differential review: https://reviews.llvm.org/D22976
>
> reviewers: clayborg, jingham
>
> Added:
> lldb/trunk/docs/structured_data/
> lldb/trunk/docs/structured_data/DarwinLog.md
> lldb/trunk/docs/structured_data/StructuredDataPlugins.md
> lldb/trunk/include/lldb/API/SBStructuredData.h
> lldb/trunk/include/lldb/Target/StructuredDataPlugin.h
> lldb/trunk/include/lldb/Target/ThreadPlanCallOnFunctionExit.h
> lldb/trunk/packages/Python/lldbsuite/test/darwin_log.py
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/basic/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/basic/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/basic/TestDarwinLogBasic.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/basic/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/common/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/common/darwin_log_common.h
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity-chain/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity-chain/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity-chain/TestDarwinLogFilterMatchActivityChain.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity-chain/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/TestDarwinLogFilterMatchActivity.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/activity/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/category/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/category/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/category/TestDarwinLogFilterMatchCategory.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/category/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/message/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/message/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/message/TestDarwinLogFilterMatchMessage.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/message/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/subsystem/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/subsystem/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/subsystem/TestDarwinLogFilterMatchSubsystem.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/exact_match/subsystem/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/activity/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/activity-chain/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/activity-chain/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/activity-chain/TestDarwinLogFilterRegexActivityChain.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/activity-chain/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/activity/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/activity/TestDarwinLogFilterRegexActivity.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/activity/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/category/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/category/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/category/TestDarwinLogFilterRegexCategory.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/category/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/message/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/message/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/message/TestDarwinLogFilterRegexMessage.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/message/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/subsystem/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/subsystem/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/subsystem/TestDarwinLogFilterRegexSubsystem.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/filter/regex/subsystem/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/format/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/format/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/format/TestDarwinLogMessageFormat.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/format/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/debug/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/debug/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/debug/TestDarwinLogSourceDebug.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/debug/main.c
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/info/
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/info/Makefile
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/info/TestDarwinLogSourceInfo.py
>
> lldb/trunk/packages/Python/lldbsuite/test/functionalities/darwin_log/source/info/main.c
> lldb/trunk/scripts/interface/SBStructuredData.i
> lldb/trunk/source/API/SBStructuredData.cpp
> lldb/trunk/source/Plugins/StructuredData/
> lldb/trunk/source/Plugins/StructuredData/CMakeLists.txt
> lldb/trunk/source/Plugins/StructuredData/DarwinLog/
> lldb/trunk/source/Plugins/StructuredData/DarwinLog/CMakeLists.txt
>
> lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp
>
> lldb/trunk/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
> lldb/trunk/source/Target/StructuredDataPlugin.cpp
> lldb/trunk/source/Target/ThreadPlanCallOnFunctionExit.cpp
> lldb/trunk/tools/debugserver/source/JSON.cpp
> lldb/trunk/tools/debugserver/source/JSON.h
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h
>
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/CMakeLists.txt
>
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp
>
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogEvent.h
>
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogInterfaces.h
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h
>
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp
>
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h
>
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp
> lldb/trunk/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h
> lldb/trunk/tools/debugserver/source/MacOSX/OsLogger.cpp
> lldb/trunk/tools/debugserver/source/MacOSX/OsLogger.h
> Modified:
> lldb/trunk/.gitignore
> lldb/trunk/cmake/LLDBDependencies.cmake
> lldb/trunk/include/lldb/API/LLDB.h
> lldb/trunk/include/lldb/API/SBDefines.h
> lldb/trunk/include/lldb/API/SBError.h
> lldb/trunk/include/lldb/API/SBProcess.h
> lldb/trunk/include/lldb/API/SBStream.h
> lldb/trunk/include/lldb/Core/Broadcaster.h
> lldb/trunk/include/lldb/Core/Event.h
> lldb/trunk/include/lldb/Core/PluginManager.h
> lldb/trunk/include/lldb/Interpreter/Args.h
> lldb/trunk/include/lldb/Target/Process.h
> lldb/trunk/include/lldb/lldb-forward.h
> lldb/trunk/include/lldb/lldb-private-interfaces.h
> lldb/trunk/lldb.xcodeproj/project.pbxproj
> lldb/trunk/scripts/interface/SBProcess.i
> lldb/trunk/scripts/interface/SBTarget.i
> lldb/trunk/scripts/lldb.swig
> lldb/trunk/source/API/CMakeLists.txt
> lldb/trunk/source/API/SBDebugger.cpp
> lldb/trunk/source/API/SBProcess.cpp
> lldb/trunk/source/API/SystemInitializerFull.cpp
> lldb/trunk/source/Core/Debugger.cpp
> lldb/trunk/source/Core/Event.cpp
> lldb/trunk/source/Core/PluginManager.cpp
> lldb/trunk/source/Interpreter/Args.cpp
> lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
> lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.h
>
> lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
>
> lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
> lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
> lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
> lldb/trunk/source/Target/CMakeLists.txt
> lldb/trunk/source/Target/Platform.cpp
> lldb/trunk/source/Target/Process.cpp
> lldb/trunk/tools/debugserver/debugserver.xcodeproj/project.pbxproj
> lldb/trunk/tools/debugserver/source/CMakeLists.txt
> lldb/trunk/tools/debugserver/source/DNB.cpp
> lldb/trunk/tools/debugserver/source/DNB.h
> lldb/trunk/tools/debugserver/source/DNBDefs.h
> lldb/trunk/tools/debugserver/source/MacOSX/CMakeLists.txt
> lldb/trunk/tools/debugserver/source/RNBContext.cpp
> lldb/trunk/tools/debugserver/source/RNBContext.h
> lldb/trunk/tools/debugserver/source/RNBRemote.cpp
> lldb/trunk/tools/debugserver/source/RNBRemote.h
> lldb/trunk/tools/debugserver/source/debugserver.cpp
> lldb/trunk/tools/lldb-mi/MICmnLLDBDebugger.cpp
> lldb/trunk/tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
>
> Modified: lldb/trunk/.gitignore
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/.gitignore?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/.gitignore (original)
> +++ lldb/trunk/.gitignore Thu Aug 18 21:52:07 2016
> @@ -40,7 +40,18 @@ __pycache__/
>
> clang-module-cache
>
> +# Skip ctags-style tags files
> +tags
> +
> # We should ignore Xcode-style embedding of llvm/ at lldb root dir.
> # Do not add trailing '/'s, they skip symlinks.
> /llvm
> /DerivedData
> +
> +# Ignore test trace directories.
> +20??-??-??-??_??_??/
> +
> +# Ignore crashlog support files.
> +crashinfo.lock
> +crashinfo.so
> +
>
> Modified: lldb/trunk/cmake/LLDBDependencies.cmake
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/LLDBDependencies.cmake?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/cmake/LLDBDependencies.cmake (original)
> +++ lldb/trunk/cmake/LLDBDependencies.cmake Thu Aug 18 21:52:07 2016
> @@ -47,6 +47,7 @@ set( LLDB_USED_LIBS
> lldbPluginObjectContainerMachOArchive
> lldbPluginObjectContainerBSDArchive
> lldbPluginPlatformMacOSX
> + lldbPluginStructuredDataDarwinLog
> lldbPluginDynamicLoaderMacOSXDYLD
> lldbPluginUnwindAssemblyInstEmulation
> lldbPluginUnwindAssemblyX86
>
> Added: lldb/trunk/docs/structured_data/DarwinLog.md
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/docs/structured_data/DarwinLog.md?rev=279198&view=auto
>
> ==============================================================================
> --- lldb/trunk/docs/structured_data/DarwinLog.md (added)
> +++ lldb/trunk/docs/structured_data/DarwinLog.md Thu Aug 18 21:52:07 2016
> @@ -0,0 +1,160 @@
> +# Change Notes
> +
> +## Summary
> +
> +This document describes the DarwinLog logging feature.
> +
> +## StructuredDataDarwinLog feature
> +
> +The DarwinLog feature supports logging os_log*() and NSLog() messages
> +to the command-line lldb console, as well as making those messages
> +available to LLDB clients via the event system. Starting with fall
> +2016 OSes, Apple platforms introduce a new fire-hose, stream-style
> +logging system where the bulk of the log processing happens on the log
> +consumer side. This reduces logging impact on the system when there
> +are no consumers, making it cheaper to include logging at all times.
> +However, it also increases the work needed on the consumer end when
> +log messages are desired.
> +
> +The debugserver binary has been modified to support collection of
> +os_log*()/NSLog() messages, selection of which messages appear in the
> +stream, and fine-grained filtering of what gets passed on to the LLDB
> +client. DarwinLog also tracks the activity chain (i.e. os_activity()
> +hierarchy) in effect at the time the log messages were issued. The
> +user is able to configure a number of aspects related to the
> +formatting of the log message header fields.
> +
> +The DarwinLog support is written in a way which should support the
> +lldb client side on non-Apple clients talking to an Apple device or
> +macOS system; hence, the plugin support is built into all LLDB
> +clients, not just those built on an Apple platform.
> +
> +StructuredDataDarwinLog implements the 'DarwinLog' feature type, and
> +the plugin name for it shows up as 'darwin-log'.
> +
> +The user interface to the darwin-log support is via the following:
> +
> +* 'plugin structured-data darwin-log enable' command
> +
> + This is the main entry point for enabling the command. It can be
> + set before launching a process or while the process is running.
> + If the user wants to squelch seeing info-level or debug-level
> + messages, which is the default behavior, then the enable command
> + must be made prior to launching the process; otherwise, the
> + info-level and debug-level messages will always show up. Also,
> + there is a similar "echo os_log()/NSLog() messages to target
> + process stderr" mechanism which is properly disabled when enabling
> + the DarwinLog support prior to launch. This cannot be squelched
> + if enabling DarwinLog after launch.
> +
> + See the help for this command. There are a number of options
> + to shrink or expand the number of messages that are processed
> + on the remote side and sent over to the client, and other
> + options to control the formatting of messages displayed.
> +
> + This command is sticky. Once enabled, it will stay enabled for
> + future process launches.
> +
> +* 'plugin structured-data darwin-log disable' command
> +
> + Executing this command disables os_log() capture in the currently
> + running process and signals LLDB to stop attempting to launch
> + new processes with DarwinLog support enabled.
> +
> +* 'settings set \
> + plugin.structured-data.darwin-log.enable-on-startup'
> +
> + and
> +
> + 'settings set \
> + plugin.structured-data.darwin-log.auto-enable-options -- {options}'
> +
> + When enable-on-startup is set to true, then LLDB will automatically
> + enable DarwinLog on startup of relevant processes. It will use the
> + content provided in the auto-enable-options settings as the
> + options to pass to the enable command.
> +
> + Note the '--' required after auto-enable-command. That is necessary
> + for raw commands like settings set. The '--' will not become part
> + of the options for the enable command.
> +
> +### Message flow and related performance considerations
> +
> +os_log()-style collection is not free. The more data that must be
> +processed, the slower it will be. There are several knobs available
> +to the developer to limit how much data goes through the pipe, and how
> +much data ultimately goes over the wire to the LLDB client. The
> +user's goal should be to ensure he or she only collects as many log
> +messages are needed, but no more.
> +
> +The flow of data looks like the following:
> +
> +1. Data comes into debugserver from the low-level OS facility that
> + receives log messages. The data that comes through this pipe can
> + be limited or expanded by the '--debug', '--info' and
> + '--all-processes' options of the 'plugin structured-data darwin-log
> + enable' command. options. Exclude as many categories as possible
> + here (also the default). The knobs here are very coarse - for
> + example, whether to include os_log_info()-level or
> + os_log_debug()-level info, or to include callstacks in the log
> + message event data.
> +
> +2. The debugserver process filters the messages that arrive through a
> + message log filter that may be fully customized by the user. It
> + works similar to a rules-based packet filter: a set of rules are
> + matched against the log message, each rule tried in sequential
> + order. The first rule that matches then either accepts or rejects
> + the message. If the log message does not match any rule, then the
> + message gets the no-match (i.e. fall-through) action. The no-match
> + action defaults to accepting but may be set to reject.
> +
> + Filters can be added via the enable command's '--filter
> + {filter-spec}' option. Filters are added in order, and multiple
> + --filter entries can be provided to the enable command.
> +
> + Filters take the following form:
> +
> + {action} {attribute} {op}
> +
> + {action} :=
> + accept |
> + reject
> +
> + {attribute} :=
> + category | // The log message category
> + subsystem | // The log message subsystem}
> + activity | // The child-most activity in force
> + // at the time the message was logged.
> + activity-chain | // The complete activity chain, specified
> + // as {parent-activity}:{child-activity}:
> + // {grandchild-activity}
> + message | // The fully expanded message contents.
> + // Note this one is expensive because it
> + // requires expanding the message. Avoid
> + // this if possible, or add it further
> + // down the filter chain.
> +
> + {op} :=
> + match {exact-match-text} |
> + regex {search-regex} // uses C++ std::regex
> + // ECMAScript variant.
> +
> +e.g.
> + --filter "accept subsystem match com.example.mycompany.myproduct"
> + --filter "accept subsystem regex com.example.+"
> + --filter "reject category regex spammy-system-[[:digit:]]+"
> +
> +3. Messages that are accepted by the log message filter get sent to
> + the lldb client, where they are mapped to the
> + StructuredDataDarwinLog plugin. By default, command-line lldb will
> + issue a Process-level event containing the log message content, and
> + will request the plugin to print the message if the plugin is
> + enabled to do so.
> +
> +### Log message display
> +
> +Several settings control aspects of displaying log messages in
> +command-line LLDB. See the enable command's help for a description
> +of these.
> +
> +
>
> Added: lldb/trunk/docs/structured_data/StructuredDataPlugins.md
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/docs/structured_data/StructuredDataPlugins.md?rev=279198&view=auto
>
> ==============================================================================
> --- lldb/trunk/docs/structured_data/StructuredDataPlugins.md (added)
> +++ lldb/trunk/docs/structured_data/StructuredDataPlugins.md Thu Aug 18
> 21:52:07 2016
> @@ -0,0 +1,136 @@
> +# Change Notes
> +
> +## Overview
> +
> +This document describes an infrastructural feature called Structured
> +Data plugins. See the DarwinLog.md doc for a description of one
> +such plugin that makes use of this feature.
> +
> +## StructuredDataPlugin
> +
> +StructuredDataPlugin instances have the following characteristics:
> +
> +* Each plugin instance is bound to a single Process instance.
> +
> +* Each StructuredData feature has a type name that identifies the
> + feature. For instance, the type name for the DarwinLog feature is
> + "DarwinLog". This feature type name is used in various places.
> +
> +* The process monitor reports the list of supported StructuredData
> + features advertised by the process monitor. Process goes through the
> + list of supported feature type names, and asks each known
> + StructuredDataPlugin if it can handle the feature. The first plugin
> + that supports the feature is mapped to that Process instance for
> + that feature. Plugins are only mapped when the process monitor
> + advertises that a feature is supported.
> +
> +* The feature may send asynchronous messages in StructuredData format
> + to the Process instance. Process instances route the asynchronous
> + structured data messages to the plugin mapped to that feature type,
> + if one exists.
> +
> +* Plugins can request that the Process instance forward on
> + configuration data to the process monitor if the plugin needs/wants
> + to configure the feature. Plugins may call the new Process method
> +
> + ```C++
> + virtual Error
> + ConfigureStructuredData(const ConstString &type_name,
> + const StructuredData::ObjectSP &config_sp)
> + ```
> +
> + where type_name is the feature name and config_sp points to the
> + configuration structured data, which may be nullptr.
> +
> +* Plugins for features present in a process are notified when modules
> + are loaded into the Process instance via this StructuredDataPlugin
> + method:
> +
> + ```C++
> + virtual void
> + ModulesDidLoad(Process &process, ModuleList &module_list);
> + ```
> +
> +* Plugins may optionally broadcast their received structured data as
> + an LLDB process-level event via the following new Process call:
> +
> + ```C++
> + void
> + BroadcastStructuredData(const StructuredData::ObjectSP &object_sp,
> + const lldb::StructuredDataPluginSP &plugin_sp);
> + ```
> +
> + IDE clients might use this feature to receive information about the
> + process as it is running to monitor memory usage, CPU usage, and
> + logging.
> +
> + Internally, the event type created is an instance of
> + EventDataStructuredData.
> +
> +* In the case where a plugin chooses to broadcast a received
> + StructuredData event, the command-line LLDB Debugger instance
> + listens for them. The Debugger instance then gives the plugin an
> + opportunity to display info to either the debugger output or error
> + stream at a time that is safe to write to them. The plugin can
> + choose to display something appropriate regarding the structured
> + data that time.
> +
> +* Plugins can provide a ProcessLaunchInfo filter method when the
> + plugin is registered. If such a filter method is provided, then
> + when a process is about to be launched for debugging, the filter
> + callback is invoked, given both the launch info and the target. The
> + plugin may then alter the launch info if needed to better support
> + the feature of the plugin.
> +
> +* The plugin is entirely independent of the type of Process-derived
> + class that it is working with. The only requirements from the
> + process monitor are the following feature-agnostic elements:
> +
> + * Provide a way to discover features supported by the process
> + monitor for the current process.
> +
> + * Specify the list of supported feature type names to Process.
> + The process monitor does this by calling the following new
> + method on Process:
> +
> + ```C++
> + void
> + MapSupportedStructuredDataPlugins(const StructuredData::Array
> + &supported_type_names)
> + ```
> +
> + The supported_type_names specifies an array of string entries,
> + where each entry specifies the name of a StructuredData feature.
> +
> + * Provide a way to forward on configuration data for a feature type
> + to the process monitor. This is the manner by which LLDB can
> + configure a feature, perhaps based on settings or commands from
> + the user. The following virtual method on Process (described
> + earlier) does the job:
> +
> + ```C++
> + virtual Error
> + ConfigureStructuredData(const ConstString &type_name,
> + const StructuredData::ObjectSP &config_sp)
> + ```
> +
> + * Listen for asynchronous structured data packets from the process
> + monitor, and forward them on to Process via this new Process
> + member method:
> +
> + ```C++
> + bool
> + RouteAsyncStructuredData(const StructuredData::ObjectSP object_sp)
> + ```
> +
> +* StructuredData producers must send their top-level data as a
> + Dictionary type, with a key called 'type' specifying a string value,
> + where the value is equal to the StructuredData feature/type name
> + previously advertised. Everything else about the content of the
> + dictionary is entirely up to the feature.
> +
> +* StructuredDataPlugin commands show up under 'plugin structured-data
> + plugin-name'.
> +
> +* StructuredDataPlugin settings show up under
> + 'plugin.structured-data.{plugin-name}.
>
> Modified: lldb/trunk/include/lldb/API/LLDB.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/LLDB.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/API/LLDB.h (original)
> +++ lldb/trunk/include/lldb/API/LLDB.h Thu Aug 18 21:52:07 2016
> @@ -55,6 +55,7 @@
> #include "lldb/API/SBSourceManager.h"
> #include "lldb/API/SBStream.h"
> #include "lldb/API/SBStringList.h"
> +#include "lldb/API/SBStructuredData.h"
> #include "lldb/API/SBSymbol.h"
> #include "lldb/API/SBSymbolContext.h"
> #include "lldb/API/SBSymbolContextList.h"
>
> Modified: lldb/trunk/include/lldb/API/SBDefines.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDefines.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/API/SBDefines.h (original)
> +++ lldb/trunk/include/lldb/API/SBDefines.h Thu Aug 18 21:52:07 2016
> @@ -71,6 +71,7 @@ class LLDB_API SBSection;
> class LLDB_API SBSourceManager;
> class LLDB_API SBStream;
> class LLDB_API SBStringList;
> +class LLDB_API SBStructuredData;
> class LLDB_API SBSymbol;
> class LLDB_API SBSymbolContext;
> class LLDB_API SBSymbolContextList;
>
> Modified: lldb/trunk/include/lldb/API/SBError.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBError.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/API/SBError.h (original)
> +++ lldb/trunk/include/lldb/API/SBError.h Thu Aug 18 21:52:07 2016
> @@ -73,6 +73,7 @@ protected:
> friend class SBHostOS;
> friend class SBPlatform;
> friend class SBProcess;
> + friend class SBStructuredData;
> friend class SBThread;
> friend class SBTarget;
> friend class SBValue;
>
> Modified: lldb/trunk/include/lldb/API/SBProcess.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/API/SBProcess.h (original)
> +++ lldb/trunk/include/lldb/API/SBProcess.h Thu Aug 18 21:52:07 2016
> @@ -32,7 +32,8 @@ public:
> eBroadcastBitInterrupt = (1 << 1),
> eBroadcastBitSTDOUT = (1 << 2),
> eBroadcastBitSTDERR = (1 << 3),
> - eBroadcastBitProfileData = (1 << 4)
> + eBroadcastBitProfileData = (1 << 4),
> + eBroadcastBitStructuredData = (1 << 5)
> };
>
> SBProcess ();
> @@ -278,10 +279,16 @@ public:
>
> static bool
> GetInterruptedFromEvent (const lldb::SBEvent &event);
> -
> +
> + static lldb::SBStructuredData
> + GetStructuredDataFromEvent (const lldb::SBEvent &event);
> +
> static bool
> EventIsProcessEvent (const lldb::SBEvent &event);
>
> + static bool
> + EventIsStructuredDataEvent (const lldb::SBEvent &event);
> +
> lldb::SBBroadcaster
> GetBroadcaster () const;
>
>
> Modified: lldb/trunk/include/lldb/API/SBStream.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStream.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/API/SBStream.h (original)
> +++ lldb/trunk/include/lldb/API/SBStream.h Thu Aug 18 21:52:07 2016
> @@ -83,6 +83,7 @@ protected:
> friend class SBProcess;
> friend class SBSection;
> friend class SBSourceManager;
> + friend class SBStructuredData;
> friend class SBSymbol;
> friend class SBSymbolContext;
> friend class SBSymbolContextList;
>
> Added: lldb/trunk/include/lldb/API/SBStructuredData.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBStructuredData.h?rev=279198&view=auto
>
> ==============================================================================
> --- lldb/trunk/include/lldb/API/SBStructuredData.h (added)
> +++ lldb/trunk/include/lldb/API/SBStructuredData.h Thu Aug 18 21:52:07 2016
> @@ -0,0 +1,52 @@
> +//===-- SBStructuredData.h --------------------------------------*- C++
> -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef SBStructuredData_h
> +#define SBStructuredData_h
> +
> +#include "lldb/API/SBDefines.h"
> +#include "lldb/API/SBModule.h"
> +
> +namespace lldb {
> +
> + class SBStructuredData
> + {
> + public:
> +
> + SBStructuredData();
> +
> + SBStructuredData(const lldb::SBStructuredData &rhs);
> +
> + SBStructuredData(const lldb::EventSP &event_sp);
> +
> + ~SBStructuredData();
> +
> + lldb::SBStructuredData &
> + operator =(const lldb::SBStructuredData &rhs);
> +
> + bool
> + IsValid() const;
> +
> + void
> + Clear();
> +
> + lldb::SBError
> + GetAsJSON(lldb::SBStream &stream) const;
> +
> + lldb::SBError
> + GetDescription(lldb::SBStream &stream) const;
> +
> + private:
> +
> + class Impl;
> + std::unique_ptr<Impl> m_impl_up;
> + };
> +}
> +
> +#endif /* SBStructuredData_h */
>
> Modified: lldb/trunk/include/lldb/Core/Broadcaster.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Broadcaster.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/Core/Broadcaster.h (original)
> +++ lldb/trunk/include/lldb/Core/Broadcaster.h Thu Aug 18 21:52:07 2016
> @@ -272,11 +272,10 @@ private:
> /// //----------------------------------------------------------
> /// enum
> /// {
> -/// eBroadcastBitStateChanged = (1 << 0),
> -/// eBroadcastBitInterrupt = (1 << 1),
> -/// eBroadcastBitSTDOUT = (1 << 2),
> -/// eBroadcastBitSTDERR = (1 << 3),
> -/// eBroadcastBitProfileData = (1 << 4)
> +/// eBroadcastBitOne = (1 << 0),
> +/// eBroadcastBitTwo = (1 << 1),
> +/// eBroadcastBitThree = (1 << 2),
> +/// ...
> /// };
> /// \endcode
> //----------------------------------------------------------------------
>
> Modified: lldb/trunk/include/lldb/Core/Event.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Event.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/Core/Event.h (original)
> +++ lldb/trunk/include/lldb/Core/Event.h Thu Aug 18 21:52:07 2016
> @@ -20,6 +20,7 @@
> // Project includes
> #include "lldb/lldb-private.h"
> #include "lldb/Core/ConstString.h"
> +#include "lldb/Core/StructuredData.h"
> #include "lldb/Host/Predicate.h"
> #include "lldb/Core/Broadcaster.h"
>
> @@ -159,6 +160,80 @@ private:
> };
>
> //----------------------------------------------------------------------
> +/// This class handles one or more StructuredData::Dictionary entries
> +/// that are raised for structured data events.
> +//----------------------------------------------------------------------
> +
> +class EventDataStructuredData : public EventData
> +{
> +public:
> +
> + //------------------------------------------------------------------
> + // Constructors
> + //------------------------------------------------------------------
> + EventDataStructuredData();
> +
> + EventDataStructuredData(const lldb::ProcessSP &process_sp,
> + const StructuredData::ObjectSP &object_sp,
> + const lldb::StructuredDataPluginSP
> &plugin_sp);
> +
> + ~EventDataStructuredData() override;
> +
> + //------------------------------------------------------------------
> + // Member functions
> + //------------------------------------------------------------------
> + const ConstString &
> + GetFlavor() const override;
> +
> + void
> + Dump(Stream *s) const override;
> +
> + const lldb::ProcessSP&
> + GetProcess() const;
> +
> + const StructuredData::ObjectSP&
> + GetObject() const;
> +
> + const lldb::StructuredDataPluginSP&
> + GetStructuredDataPlugin() const;
> +
> + void
> + SetProcess(const lldb::ProcessSP &process_sp);
> +
> + void
> + SetObject(const StructuredData::ObjectSP &object_sp);
> +
> + void
> + SetStructuredDataPlugin(const lldb::StructuredDataPluginSP
> &plugin_sp);
> +
> + //------------------------------------------------------------------
> + // Static functions
> + //------------------------------------------------------------------
> + static const EventDataStructuredData*
> + GetEventDataFromEvent(const Event *event_ptr);
> +
> + static lldb::ProcessSP
> + GetProcessFromEvent(const Event *event_ptr);
> +
> + static StructuredData::ObjectSP
> + GetObjectFromEvent(const Event *event_ptr);
> +
> + static lldb::StructuredDataPluginSP
> + GetPluginFromEvent(const Event *event_ptr);
> +
> + static const ConstString &
> + GetFlavorString ();
> +
> +private:
> +
> + lldb::ProcessSP m_process_sp;
> + StructuredData::ObjectSP m_object_sp;
> + lldb::StructuredDataPluginSP m_plugin_sp;
> +
> + DISALLOW_COPY_AND_ASSIGN(EventDataStructuredData);
> +};
> +
> +//----------------------------------------------------------------------
> // lldb::Event
> //----------------------------------------------------------------------
> class Event
>
> Modified: lldb/trunk/include/lldb/Core/PluginManager.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/PluginManager.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/Core/PluginManager.h (original)
> +++ lldb/trunk/include/lldb/Core/PluginManager.h Thu Aug 18 21:52:07 2016
> @@ -328,6 +328,65 @@ public:
> CommandInterpreter &interpreter);
>
> //------------------------------------------------------------------
> + // StructuredDataPlugin
> + //------------------------------------------------------------------
> +
> + //------------------------------------------------------------------
> + /// Register a StructuredDataPlugin class along with optional
> + /// callbacks for debugger initialization and Process launch info
> + /// filtering and manipulation.
> + ///
> + /// @param[in] name
> + /// The name of the plugin.
> + ///
> + /// @param[in] description
> + /// A description string for the plugin.
> + ///
> + /// @param[in] create_callback
> + /// The callback that will be invoked to create an instance of
> + /// the callback. This may not be nullptr.
> + ///
> + /// @param[in] debugger_init_callback
> + /// An optional callback that will be made when a Debugger
> + /// instance is initialized.
> + ///
> + /// @param[in] filter_callback
> + /// An optional callback that will be invoked before LLDB
> + /// launches a process for debugging. The callback must
> + /// do the following:
> + /// 1. Only do something if the plugin's behavior is enabled.
> + /// 2. Only make changes for processes that are relevant to the
> + /// plugin. The callback gets a pointer to the Target, which
> + /// can be inspected as needed. The ProcessLaunchInfo is
> + /// provided in read-write mode, and may be modified by the
> + /// plugin if, for instance, additional environment variables
> + /// are needed to support the feature when enabled.
> + ///
> + /// @return
> + /// Returns true upon success; otherwise, false.
> + //------------------------------------------------------------------
> + static bool
> + RegisterPlugin(const ConstString &name,
> + const char *description,
> + StructuredDataPluginCreateInstance create_callback,
> + DebuggerInitializeCallback debugger_init_callback =
> nullptr,
> + StructuredDataFilterLaunchInfo filter_callback
> + = nullptr);
> +
> + static bool
> + UnregisterPlugin(StructuredDataPluginCreateInstance create_callback);
> +
> + static StructuredDataPluginCreateInstance
> + GetStructuredDataPluginCreateCallbackAtIndex(uint32_t idx);
> +
> + static StructuredDataPluginCreateInstance
> + GetStructuredDataPluginCreateCallbackForPluginName(const ConstString
> &name);
> +
> + static StructuredDataFilterLaunchInfo
> + GetStructuredDataFilterCallbackAtIndex(uint32_t idx,
> + bool &iteration_complete);
> +
> + //------------------------------------------------------------------
> // SymbolFile
> //------------------------------------------------------------------
> static bool
> @@ -531,6 +590,16 @@ public:
> static bool CreateSettingForOperatingSystemPlugin(Debugger &debugger,
> const
> lldb::OptionValuePropertiesSP &properties_sp,
> const ConstString
> &description, bool is_global_property);
> +
> + static lldb::OptionValuePropertiesSP
> + GetSettingForStructuredDataPlugin(Debugger &debugger,
> + const ConstString &setting_name);
> +
> + static bool
> + CreateSettingForStructuredDataPlugin(Debugger &debugger,
> + const
> lldb::OptionValuePropertiesSP &properties_sp,
> + const ConstString &description,
> + bool is_global_property);
> };
>
> } // namespace lldb_private
>
> Modified: lldb/trunk/include/lldb/Interpreter/Args.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/Interpreter/Args.h (original)
> +++ lldb/trunk/include/lldb/Interpreter/Args.h Thu Aug 18 21:52:07 2016
> @@ -451,6 +451,17 @@ public:
> LongestCommonPrefix (std::string &common_prefix);
>
> //------------------------------------------------------------------
> + /// Add or replace an environment variable with the given value.
> + ///
> + /// This command adds the environment variable if it is not already
> + /// present using the given value. If the environment variable is
> + /// already in the list, it replaces the first such occurrence
> + /// with the new value.
> + //------------------------------------------------------------------
> + void
> + AddOrReplaceEnvironmentVariable(const char *env_var_name,
> + const char *new_value);
> +
> /// Return whether a given environment variable exists.
> ///
> /// This command treats Args like a list of environment variables,
> @@ -460,12 +471,18 @@ public:
> /// @param[in] env_var_name
> /// Specifies the name of the environment variable to check.
> ///
> + /// @param[out] argument_index
> + /// If non-null, then when the environment variable is found,
> + /// the index of the argument position will be returned in
> + /// the size_t pointed to by this argument.
> + ///
> /// @return
> /// true if the specified env var name exists in the list in
> /// either of the above-mentioned formats; otherwise, false.
> //------------------------------------------------------------------
> bool
> - ContainsEnvironmentVariable(const char *env_var_name) const;
> + ContainsEnvironmentVariable(const char *env_var_name,
> + size_t *argument_index = nullptr) const;
>
> protected:
> //------------------------------------------------------------------
>
> Modified: lldb/trunk/include/lldb/Target/Process.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/Target/Process.h (original)
> +++ lldb/trunk/include/lldb/Target/Process.h Thu Aug 18 21:52:07 2016
> @@ -760,7 +760,8 @@ public:
> eBroadcastBitInterrupt = (1 << 1),
> eBroadcastBitSTDOUT = (1 << 2),
> eBroadcastBitSTDERR = (1 << 3),
> - eBroadcastBitProfileData = (1 << 4)
> + eBroadcastBitProfileData = (1 << 4),
> + eBroadcastBitStructuredData = (1 << 5),
> };
>
> enum
> @@ -3254,6 +3255,71 @@ public:
> AdvanceAddressToNextBranchInstruction (Address default_stop_addr,
> AddressRange range_bounds);
>
> + //------------------------------------------------------------------
> + /// Configure asynchronous structured data feature.
> + ///
> + /// Each Process type that supports using an asynchronous
> StructuredData
> + /// feature should implement this to enable/disable/configure the
> feature.
> + /// The default implementation here will always return an error
> indiciating
> + /// the feature is unsupported.
> + ///
> + /// StructuredDataPlugin implementations will call this to configure
> + /// a feature that has been reported as being supported.
> + ///
> + /// @param[in] type_name
> + /// The StructuredData type name as previously discovered by
> + /// the Process-derived instance.
> + ///
> + /// @param[in] config
> + /// Configuration data for the feature being enabled. This config
> + /// data, which may be null, will be passed along to the feature
> + /// to process. The feature will dictate whether this is a
> dictionary,
> + /// an array or some other object. If the feature needs to be
> + /// set up properly before it can be enabled, then the config
> should
> + /// also take an enable/disable flag.
> + ///
> + /// @return
> + /// Returns the result of attempting to configure the feature.
> + //------------------------------------------------------------------
> + virtual Error
> + ConfigureStructuredData(const ConstString &type_name,
> + const StructuredData::ObjectSP &config_sp);
> +
> + //------------------------------------------------------------------
> + /// Broadcasts the given structured data object from the given
> + /// plugin.
> + ///
> + /// StructuredDataPlugin instances can use this to optionally
> + /// broadcast any of their data if they want to make it available
> + /// for clients. The data will come in on the structured data
> + /// event bit (eBroadcastBitStructuredData).
> + ///
> + /// @param[in] object_sp
> + /// The structured data object to broadcast.
> + ///
> + /// @param[in] plugin_sp
> + /// The plugin that will be reported in the event's plugin
> + /// parameter.
> + //------------------------------------------------------------------
> + void
> + BroadcastStructuredData(const StructuredData::ObjectSP &object_sp,
> + const lldb::StructuredDataPluginSP
> &plugin_sp);
> +
> + //------------------------------------------------------------------
> + /// Returns the StructuredDataPlugin associated with a given type
> + /// name, if there is one.
> + ///
> + /// There will only be a plugin for a given StructuredDataType if the
> + /// debugged process monitor claims that the feature is supported.
> + /// This is one way to tell whether a feature is available.
> + ///
> + /// @return
> + /// The plugin if one is available for the specified feature;
> + /// otherwise, returns an empty shared pointer.
> + //------------------------------------------------------------------
> + lldb::StructuredDataPluginSP
> + GetStructuredDataPlugin(const ConstString &type_name) const;
> +
> protected:
> void
> SetState (lldb::EventSP &event_sp);
> @@ -3392,6 +3458,57 @@ protected:
> }
>
> //------------------------------------------------------------------
> + /// Loads any plugins associated with asynchronous structured data
> + /// and maps the relevant supported type name to the plugin.
> + ///
> + /// Processes can receive asynchronous structured data from the
> + /// process monitor. This method will load and map any structured
> + /// data plugins that support the given set of supported type names.
> + /// Later, if any of these features are enabled, the process monitor
> + /// is free to generate asynchronous structured data. The data must
> + /// come in as a single \b StructuredData::Dictionary. That
> dictionary
> + /// must have a string field named 'type', with a value that equals
> + /// the relevant type name string (one of the values in
> + /// \b supported_type_names).
> + ///
> + /// @param[in] supported_type_names
> + /// An array of zero or more type names. Each must be unique.
> + /// For each entry in the list, a StructuredDataPlugin will be
> + /// searched for that supports the structured data type name.
> + //------------------------------------------------------------------
> + void
> + MapSupportedStructuredDataPlugins(const StructuredData::Array
> + &supported_type_names);
> +
> + //------------------------------------------------------------------
> + /// Route the incoming structured data dictionary to the right plugin.
> + ///
> + /// The incoming structured data must be a dictionary, and it must
> + /// have a key named 'type' that stores a string value. The string
> + /// value must be the name of the structured data feature that
> + /// knows how to handle it.
> + ///
> + /// @param[in] object_sp
> + /// When non-null and pointing to a dictionary, the 'type'
> + /// key's string value is used to look up the plugin that
> + /// was registered for that structured data type. It then
> + /// calls the following method on the StructuredDataPlugin
> + /// instance:
> + ///
> + /// virtual void
> + /// HandleArrivalOfStructuredData(Process &process,
> + /// const ConstString &type_name,
> + /// const StructuredData::ObjectSP
> + /// &object_sp)
> + ///
> + /// @return
> + /// True if the structured data was routed to a plugin; otherwise,
> + /// false.
> + //------------------------------------------------------------------
> + bool
> + RouteAsyncStructuredData(const StructuredData::ObjectSP object_sp);
> +
> + //------------------------------------------------------------------
> // Type definitions
> //------------------------------------------------------------------
> typedef std::map<lldb::LanguageType, lldb::LanguageRuntimeSP>
> LanguageRuntimeCollection;
> @@ -3408,6 +3525,9 @@ protected:
> {
> }
> };
> +
> + using StructuredDataPluginMap = std::map<ConstString,
> +
> lldb::StructuredDataPluginSP>;
>
> //------------------------------------------------------------------
> // Member variables
> @@ -3477,7 +3597,9 @@ protected:
> bool m_can_interpret_function_calls; // Some targets, e.g the OSX
> kernel, don't support the ability to modify the stack.
> WarningsCollection m_warnings_issued; // A set of object
> pointers which have already had warnings printed
> std::mutex m_run_thread_plan_lock;
> -
> + StructuredDataPluginMap m_structured_data_plugin_map;
> +
> +
> enum {
> eCanJITDontKnow= 0,
> eCanJITYes,
> @@ -3562,7 +3684,7 @@ protected:
>
> void
> BroadcastAsyncProfileData(const std::string &one_profile_data);
> -
> +
> static void
> STDIOReadThreadBytesReceived (void *baton, const void *src, size_t
> src_len);
>
>
> Added: lldb/trunk/include/lldb/Target/StructuredDataPlugin.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/StructuredDataPlugin.h?rev=279198&view=auto
>
> ==============================================================================
> --- lldb/trunk/include/lldb/Target/StructuredDataPlugin.h (added)
> +++ lldb/trunk/include/lldb/Target/StructuredDataPlugin.h Thu Aug 18
> 21:52:07 2016
> @@ -0,0 +1,204 @@
> +//===-- StructuredDataPlugin.h ----------------------------------*- C++
> -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef StructuredDataPlugin_h
> +#define StructuredDataPlugin_h
> +
> +#include "lldb/Core/PluginInterface.h"
> +#include "lldb/Core/StructuredData.h"
> +
> +namespace lldb_private
> +{
> +
> +class CommandObjectMultiword;
> +
> +//
> -----------------------------------------------------------------------------
> +/// Plugin that supports process-related structured data sent
> asynchronously
> +/// from the debug monitor (e.g. debugserver, lldb-server, etc.)
> +///
> +/// This plugin type is activated by a Process-derived instance when that
> +/// instance detects that a given structured data feature is available.
> +///
> +/// StructuredDataPlugin instances are inherently tied to a process. The
> +/// main functionality they support is the ability to consume
> asynchronously-
> +/// delivered structured data from the process monitor, and do something
> +/// reasonable with it. Something reasonable can include broadcasting a
> +/// StructuredData event, which other parts of the system can then do with
> +/// as they please. An IDE could use this facility to retrieve CPU usage,
> +/// memory usage, and other run-time aspects of the process. That data
> +/// can then be displayed meaningfully to the user through the IDE.
> +
> +/// For command-line LLDB, the Debugger instance listens for the
> structured
> +/// data events raised by the plugin, and give the plugin both the output
> +/// and error streams such that the plugin can display something about the
> +/// event, at a time when the debugger ensures it is safe to write to the
> +/// output or error streams.
> +//
> -----------------------------------------------------------------------------
> +
> +class StructuredDataPlugin :
> + public PluginInterface,
> + public std::enable_shared_from_this<StructuredDataPlugin>
> +{
> +public:
> +
> + virtual ~StructuredDataPlugin();
> +
> + lldb::ProcessSP
> + GetProcess() const;
> +
> + //
> -------------------------------------------------------------------------
> + // Public instance API
> + //
> -------------------------------------------------------------------------
> +
> + //
> -------------------------------------------------------------------------
> + /// Return whether this plugin supports the given StructuredData
> feature.
> + ///
> + /// When Process is informed of a list of process-monitor-supported
> + /// structured data features, Process will go through the list of
> plugins,
> + /// one at a time, and have the first plugin that supports a given
> feature
> + /// be the plugin instantiated to handle that feature. There is a 1-1
> + /// correspondence between a Process instance and a
> StructuredDataPlugin
> + /// mapped to that process. A plugin can support handling multiple
> + /// features, and if that happens, there is a single plugin instance
> + /// created covering all of the mapped features for a given process.
> + ///
> + /// @param[in] type_name
> + /// The name of the feature tag supported by a process.
> + /// e.g. "darwin-log".
> + ///
> + /// @return
> + /// true if the plugin supports the feature; otherwise, false.
> + //
> -------------------------------------------------------------------------
> + virtual bool
> + SupportsStructuredDataType(const ConstString &type_name) = 0;
> +
> + //
> -------------------------------------------------------------------------
> + /// Handle the arrival of asynchronous structured data from the
> process.
> + ///
> + /// When asynchronous structured data arrives from the process
> monitor,
> + /// it is immediately delivered to the plugin mapped for that feature
> + /// if one exists. The structured data that arrives from a process
> + /// monitor must be a dictionary, and it must have a string field
> named
> + /// "type" that must contain the StructuredData feature name set as
> the
> + /// value. This is the manner in which the data is routed to the
> proper
> + /// plugin instance.
> + ///
> + /// @param[in] process
> + /// The process instance that just received the structured data.
> + /// This will always be the same process for a given instance of
> + /// a plugin.
> + ///
> + /// @param[in] type_name
> + /// The name of the feature tag for the asynchronous structured
> data.
> + /// Note this data will also be present in the \b object_sp
> dictionary
> + /// under the string value with key "type".
> + ///
> + /// @param[in] object_sp
> + /// A shared pointer to the structured data that arrived. This
> must
> + /// be a dictionary. The only key required is the aforementioned
> + /// key named "type" that must be a string value containing the
> + /// structured data type name.
> + //
> -------------------------------------------------------------------------
> + virtual void
> + HandleArrivalOfStructuredData(Process &process,
> + const ConstString &type_name,
> + const StructuredData::ObjectSP
> + &object_sp) = 0;
> +
> +
> + //
> -------------------------------------------------------------------------
> + /// Get a human-readable description of the contents of the data.
> + ///
> + /// In command-line LLDB, this method will be called by the Debugger
> + /// instance for each structured data event generated, and the output
> + /// will be printed to the LLDB console. If nothing is added to the
> stream,
> + /// nothing will be printed; otherwise, a newline will be added to
> the end
> + /// when displayed.
> + ///
> + /// @param[in] object_sp
> + /// A shared pointer to the structured data to format.
> + ///
> + /// @param[in] stream
> + /// The stream where the structured data should be pretty printed.
> + ///
> + /// @return
> + /// The error if formatting the object contents failed; otherwise,
> + /// success.
> + //
> -------------------------------------------------------------------------
> + virtual Error
> + GetDescription(const StructuredData::ObjectSP &object_sp,
> + lldb_private::Stream &stream) = 0;
> +
> + //
> -------------------------------------------------------------------------
> + /// Returns whether the plugin's features are enabled.
> + ///
> + /// This is a convenience method for plugins that can enable or
> disable
> + /// their functionality. It allows retrieval of this state without
> + /// requiring a cast.
> + ///
> + /// @param[in] type_name
> + /// The name of the feature tag for the asynchronous structured
> data.
> + /// This is needed for plugins that support more than one feature.
> + //
> -------------------------------------------------------------------------
> + virtual bool
> + GetEnabled(const ConstString &type_name) const;
> +
> + //
> -------------------------------------------------------------------------
> + /// Allow the plugin to do work related to modules that loaded in the
> + /// the corresponding process.
> + ///
> + /// This method defaults to doing nothing. Plugins can override it
> + /// if they have any behavior they want to enable/modify based on
> loaded
> + /// modules.
> + ///
> + /// @param[in] process
> + /// The process that just was notified of modules having been
> loaded.
> + /// This will always be the same process for a given instance of
> + /// a plugin.
> + ///
> + /// @param[in] module_list
> + /// The list of modules that the process registered as having just
> + /// loaded. See \b Process::ModulesDidLoad(...).
> + //
> -------------------------------------------------------------------------
> + virtual void
> + ModulesDidLoad(Process &process, ModuleList &module_list);
> +
> +protected:
> +
> + //
> -------------------------------------------------------------------------
> + // Derived-class API
> + //
> -------------------------------------------------------------------------
> + StructuredDataPlugin(const lldb::ProcessWP &process_wp);
> +
> + //
> -------------------------------------------------------------------------
> + /// Derived classes must call this before attempting to hook up
> commands
> + /// to the 'plugin structured-data' tree.
> + ///
> + /// This ensures the relevant command and options hook points for all
> + /// StructuredDataPlugin derived classes are available for this
> debugger.
> + /// If this has already happened, this call is a no-op.
> + ///
> + /// @param[in] debugger
> + /// The Debugger instance for which we're creating the required
> shared
> + /// components for the StructuredDataPlugin derived classes.
> + //
> -------------------------------------------------------------------------
> + static void
> + InitializeBasePluginForDebugger(Debugger &debugger);
> +
> +private:
> +
> + lldb::ProcessWP m_process_wp;
> +
> + DISALLOW_COPY_AND_ASSIGN(StructuredDataPlugin);
> +
> +};
> +
> +}
> +
> +#endif
>
> Added: lldb/trunk/include/lldb/Target/ThreadPlanCallOnFunctionExit.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ThreadPlanCallOnFunctionExit.h?rev=279198&view=auto
>
> ==============================================================================
> --- lldb/trunk/include/lldb/Target/ThreadPlanCallOnFunctionExit.h (added)
> +++ lldb/trunk/include/lldb/Target/ThreadPlanCallOnFunctionExit.h Thu Aug
> 18 21:52:07 2016
> @@ -0,0 +1,69 @@
> +//===-- ThreadPlanCallOnFunctionExit.h --------------------------*- C++
> -*-===//
> +//
> +// The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
>
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef ThreadPlanCallOnFunctionExit_h
> +#define ThreadPlanCallOnFunctionExit_h
> +
> +#include "lldb/Target/ThreadPlan.h"
> +
> +#include <functional>
> +
> +namespace lldb_private {
> +
> +//
> =============================================================================
> +/// This thread plan calls a function object when the current function
> exits.
> +//
> =============================================================================
> +
> +class ThreadPlanCallOnFunctionExit : public ThreadPlan
> +{
> +public:
> +
> + /// Definition for the callback made when the currently executing
> thread
> + /// finishes executing its function.
> + using Callback = std::function<void()>;
> +
> + ThreadPlanCallOnFunctionExit(Thread &thread, const Callback
> &callback);
> +
> + void
> + DidPush() override;
> +
> + //
> -------------------------------------------------------------------------
> + // ThreadPlan API
> + //
> -------------------------------------------------------------------------
> +
> + void
> + GetDescription (Stream *s, lldb::DescriptionLevel level) override;
> +
> + bool
> + ValidatePlan (Stream *error) override;
> +
> + bool
> + ShouldStop (Event *event_ptr) override;
> +
> + bool
> + WillStop () override;
> +
> +protected:
> +
> + bool
> + DoPlanExplainsStop (Event *event_ptr) override;
> +
> + lldb::StateType
> + GetPlanRunState () override;
> +
> +private:
> +
> + Callback m_callback;
> + lldb::ThreadPlanSP m_step_out_threadplan_sp;
> +
> +};
> +
> +}
> +
> +#endif /* ThreadPlanCallOnFunctionExit_h */
>
> Modified: lldb/trunk/include/lldb/lldb-forward.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/lldb-forward.h (original)
> +++ lldb/trunk/include/lldb/lldb-forward.h Thu Aug 18 21:52:07 2016
> @@ -91,6 +91,7 @@ class Error;
> class EvaluateExpressionOptions;
> class Event;
> class EventData;
> +class EventDataStructuredData;
> class ExecutionContext;
> class ExecutionContextRef;
> class ExecutionContextRefLocker;
> @@ -215,6 +216,7 @@ class StreamFile;
> class StreamString;
> class StringList;
> struct StringSummaryFormat;
> +class StructuredDataPlugin;
> class SystemRuntime;
> class TypeSummaryImpl;
> class TypeSummaryOptions;
> @@ -333,6 +335,7 @@ namespace lldb {
> typedef std::unique_ptr<lldb_private::DynamicLoader> DynamicLoaderUP;
> typedef std::shared_ptr<lldb_private::Event> EventSP;
> typedef std::shared_ptr<lldb_private::EventData> EventDataSP;
> + typedef std::shared_ptr<lldb_private::EventDataStructuredData>
> EventDataStructuredDataSP;
> typedef std::shared_ptr<lldb_private::ExecutionContextRef>
> ExecutionContextRefSP;
> typedef std::shared_ptr<lldb_private::ExpressionVariable>
> ExpressionVariableSP;
> typedef std::shared_ptr<lldb_private::File> FileSP;
> @@ -415,6 +418,10 @@ namespace lldb {
> typedef std::weak_ptr<lldb_private::Stream> StreamWP;
> typedef std::shared_ptr<lldb_private::StreamFile> StreamFileSP;
> typedef std::shared_ptr<lldb_private::StringSummaryFormat>
> StringTypeSummaryImplSP;
> + typedef std::shared_ptr<lldb_private::StructuredDataPlugin>
> + StructuredDataPluginSP;
> + typedef std::weak_ptr<lldb_private::StructuredDataPlugin>
> + StructuredDataPluginWP;
> typedef std::shared_ptr<lldb_private::SymbolFile> SymbolFileSP;
> typedef std::shared_ptr<lldb_private::SymbolFileType>
> SymbolFileTypeSP;
> typedef std::weak_ptr<lldb_private::SymbolFileType> SymbolFileTypeWP;
>
> Modified: lldb/trunk/include/lldb/lldb-private-interfaces.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-interfaces.h?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/include/lldb/lldb-private-interfaces.h (original)
> +++ lldb/trunk/include/lldb/lldb-private-interfaces.h Thu Aug 18 21:52:07
> 2016
> @@ -35,6 +35,9 @@ namespace lldb_private
> typedef Language *(*LanguageCreateInstance) (lldb::LanguageType
> language);
> typedef LanguageRuntime *(*LanguageRuntimeCreateInstance) (Process
> *process, lldb::LanguageType language);
> typedef lldb::CommandObjectSP (*LanguageRuntimeGetCommandObject)
> (CommandInterpreter& interpreter);
> + typedef lldb::StructuredDataPluginSP
> (*StructuredDataPluginCreateInstance)
> + (Process &process);
> + typedef Error (*StructuredDataFilterLaunchInfo)(ProcessLaunchInfo
> &launch_info, Target *target);
> typedef SystemRuntime *(*SystemRuntimeCreateInstance) (Process
> *process);
> typedef lldb::PlatformSP (*PlatformCreateInstance) (bool force, const
> ArchSpec *arch);
> typedef lldb::ProcessSP (*ProcessCreateInstance) (lldb::TargetSP
> target_sp, lldb::ListenerSP listener_sp, const FileSpec *crash_file_path);
>
> Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=279198&r1=279197&r2=279198&view=diff
>
> ==============================================================================
> --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
> +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Thu Aug 18 21:52:07 2016
> @@ -57,6 +57,8 @@
> 23059A0719532B96007B8189 /* LinuxSignals.cpp in Sources */
> = {isa = PBXBuildFile; fileRef = 23059A0519532B96007B8189 /*
> LinuxSignals.cpp */; };
> 23059A101958B319007B8189 /* SBUnixSignals.cpp in Sources
> */ = {isa = PBXBuildFile; fileRef = 23059A0F1958B319007B8189 /*
> SBUnixSignals.cpp */; };
> 23059A121958B3B2007B8189 /* SBUnixSignals.h in Headers */
> = {isa = PBXBuildFile; fileRef = 23059A111958B37B007B8189 /*
> SBUnixSignals.h */; settings = {ATTRIBUTES = (Public, ); }; };
> + 230EC4591D63C3A7008DF59F /* CMakeLists.txt in CopyFiles */
> = {isa = PBXBuildFile; fileRef = 230EC4571D63C3A7008DF59F /* CMakeLists.txt
> */; };
> + 230EC45B1D63C3BA008DF59F /*
> ThreadPlanCallOnFunctionExit.cpp in Sources */ = {isa = PBXBuildFile;
> fileRef = 230EC4581D63C3A7008DF59F /* ThreadPlanCallOnFunctionExit.cpp */;
> };
> 2326CF441BDD643700A5CEAC /* liblldb-core.a in Frameworks
> */ = {isa = PBXBuildFile; fileRef = 2689FFCA13353D7A00698AC0 /*
> liblldb-core.a */; };
> 2326CF491BDD67D800A5CEAC /* libncurses.dylib in Frameworks
> */ = {isa = PBXBuildFile; fileRef = 2326CF471BDD67C100A5CEAC /*
> libncurses.dylib */; };
> 2326CF4B1BDD681800A5CEAC /* libz.dylib in Frameworks */ =
> {isa = PBXBuildFile; fileRef = 2326CF4A1BDD681800A5CEAC /* libz.dylib */; };
> @@ -72,9 +74,15 @@
> 233B007F1960CB280090E598 /* ProcessLaunchInfo.cpp in
> Sources */ = {isa = PBXBuildFile; fileRef = 233B007E1960CB280090E598 /*
> ProcessLaunchInfo.cpp */; };
> 236124A41986B4E2004EFC37 /* IOObject.cpp in Sources */ =
> {isa = PBXBuildFile; fileRef = 236124A21986B4E2004EFC37 /* IOObject.cpp */;
> };
> 236124A51986B4E2004EFC37 /* Socket.cpp in Sources */ =
> {isa = PBXBuildFile; fileRef = 236124A31986B4E2004EFC37 /* Socket.cpp */; };
> + 2374D7461D4BAA1D005C9575 /* CMakeLists.txt in CopyFiles */
> = {isa = PBXBuildFile; fileRef = 2374D7431D4BAA1D005C9575 /* CMakeLists.txt
> */; };
> 2374D7521D4BB299005C9575 /* GDBRemoteClientBase.h in
> CopyFiles */ = {isa = PBXBuildFile; fileRef = 2374D74F1D4BB299005C9575 /*
> GDBRemoteClientBase.h */; };
> 2374D7531D4BB2FF005C9575 /* GDBRemoteClientBase.cpp in
> Sources *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160819/4bbb136b/attachment-0001.html>
More information about the lldb-commits
mailing list