diff --git a/lldb/docs/design/structureddataplugins.md b/lldb/docs/design/structureddataplugins.md deleted file mode 100644 --- a/lldb/docs/design/structureddataplugins.md +++ /dev/null @@ -1,442 +0,0 @@ -# Structured Data Plugins - -This document describes an infrastructural feature called Structured Data -plugins. See the DarwinLog documentation for a description of one such plugin -that makes use of this feature. - -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(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(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}`. - -## 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 true` - - 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. - - -## 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 true` - - 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. - - - diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py --- a/lldb/packages/Python/lldbsuite/test/configuration.py +++ b/lldb/packages/Python/lldbsuite/test/configuration.py @@ -29,7 +29,7 @@ # set to true if we are going to use categories for cherry-picking test cases use_categories = False # Categories we want to skip -skip_categories = ["darwin-log"] +skip_categories = [] # Categories we expect to fail xfail_categories = [] # use this to track per-category failures diff --git a/lldb/packages/Python/lldbsuite/test/darwin_log.py b/lldb/packages/Python/lldbsuite/test/darwin_log.py deleted file mode 100644 --- a/lldb/packages/Python/lldbsuite/test/darwin_log.py +++ /dev/null @@ -1,456 +0,0 @@ -""" -Base class for DarwinLog tests. -""" - -# System imports -from __future__ import print_function - -import json -import platform -import re -import sys -import threading - - -# lldb imports -import lldb -from lldb import SBProcess, SBTarget - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import lldbtest_config -from lldbsuite.test import lldbutil - - -def expand_darwinlog_command(command): - return "plugin structured-data darwin-log " + command - - -def expand_darwinlog_settings_set_command(command): - return "settings set plugin.structured-data.darwin-log." + command - - -class DarwinLogTestBase(lldbtest.TestBase): - """Base class for DarwinLog test cases that are pexpect-based.""" - NO_DEBUG_INFO_TESTCASE = True - - CONTINUE_REGEX = re.compile(r"Process \d+ resuming") - - def setUp(self): - # Call super's setUp(). - super(DarwinLogTestBase, self).setUp() - - # Until other systems support this, exit - # early if we're not macOS version 10.12 - # or greater. - version = platform.mac_ver()[0].split('.') - if ((int(version[0]) == 10) and (int(version[1]) < 12) or - (int(version[0]) < 10)): - self.skipTest("DarwinLog tests currently require macOS 10.12+") - return - - self.child = None - self.child_prompt = '(lldb) ' - self.strict_sources = False - self.enable_process_monitor_logging = False - - def run_lldb_to_breakpoint(self, exe, source_file, line, - enable_command=None, settings_commands=None): - - import pexpect - # Set self.child_prompt, which is "(lldb) ". - prompt = self.child_prompt - - # So that the child gets torn down after the test. - self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, - self.lldbOption, exe)) - child = self.child - - # Turn on logging for what the child sends back. - if self.TraceOn(): - child.logfile_read = sys.stdout - - if self.enable_process_monitor_logging: - if platform.system() == 'Darwin': - self.runCmd( - "settings set target.process.extra-startup-command " - "QSetLogging:bitmask=LOG_DARWIN_LOG;") - self.expect_prompt() - - # Run the enable command if we have one. - if enable_command is not None: - self.runCmd(enable_command) - self.expect_prompt() - - # Disable showing of source lines at our breakpoint. - # This is necessary for the logging tests, because the very - # text we want to match for output from the running inferior - # will show up in the source as well. We don't want the source - # output to erroneously make a match with our expected output. - self.runCmd("settings set stop-line-count-before 0") - self.expect_prompt() - self.runCmd("settings set stop-line-count-after 0") - self.expect_prompt() - - # While we're debugging, turn on packet logging. - self.runCmd("log enable -f /tmp/packets.log gdb-remote packets") - self.expect_prompt() - - # Prevent mirroring of NSLog/os_log content to stderr. We want log - # messages to come exclusively through our log channel. - self.runCmd( - "settings set target.env-vars IDE_DISABLED_OS_ACTIVITY_DT_MODE=1") - self.expect_prompt() - - # Run any darwin-log settings commands now, before we enable logging. - if settings_commands is not None: - for setting_command in settings_commands: - self.runCmd( - expand_darwinlog_settings_set_command(setting_command)) - self.expect_prompt() - - # Set breakpoint right before the os_log() macros. We don't - # set it on the os_log*() calls because these are a number of - # nested-scoped calls that will cause the debugger to stop - # multiple times on the same line. That is difficult to match - # os_log() content by since it is non-deterministic what the - # ordering between stops and log lines will be. This is why - # we stop before, and then have the process run in a sleep - # afterwards, so we get the log messages while the target - # process is "running" (sleeping). - child.sendline('breakpoint set -f %s -l %d' % (source_file, line)) - child.expect_exact(prompt) - - # Now run to the breakpoint that we just set. - child.sendline('run') - child.expect_exact(prompt) - - # Ensure we stopped at a breakpoint. - self.runCmd("thread list") - self.expect(re.compile(r"stop reason = breakpoint")) - - # Now we're ready to check if DarwinLog is available. - if not self.darwin_log_available(): - self.skipTest("DarwinLog not available") - - def runCmd(self, cmd): - self.child.sendline(cmd) - - def expect_prompt(self, exactly=True): - self.expect(self.child_prompt, exactly=exactly) - - def expect(self, pattern, exactly=False, *args, **kwargs): - if exactly: - return self.child.expect_exact(pattern, *args, **kwargs) - return self.child.expect(pattern, *args, **kwargs) - - def darwin_log_available(self): - self.runCmd("plugin structured-data darwin-log status") - self.expect(re.compile(r"Availability: ([\S]+)")) - return self.child.match is not None and ( - self.child.match.group(1) == "available") - - def do_test(self, enable_options, expect_regexes=None, - settings_commands=None): - """Test that a single fall-through reject rule rejects all logging.""" - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - # Build the darwin-log enable command. - enable_cmd = expand_darwinlog_command('enable') - if enable_options is not None and len(enable_options) > 0: - enable_cmd += ' ' + ' '.join(enable_options) - - exe = self.getBuildArtifact(self.exe_name) - self.run_lldb_to_breakpoint(exe, self.source, self.line, - enable_command=enable_cmd, - settings_commands=settings_commands) - self.expect_prompt() - - # Now go. - self.runCmd("process continue") - self.expect(self.CONTINUE_REGEX) - - if expect_regexes is None: - # Expect matching a log line or program exit. - # Test methods determine which ones are valid. - expect_regexes = ( - [re.compile(r"source-log-([^-]+)-(\S+)"), - re.compile(r"exited with status") - ]) - self.expect(expect_regexes) - - -def remove_add_mode_entry(log_entries): - """libtrace creates an "Add Mode:..." message when logging is enabled. - Strip this out of results since our test subjects don't create it.""" - return [entry for entry in log_entries - if "message" in entry and - not entry["message"].startswith("Add Mode:")] - - -class DarwinLogEventBasedTestBase(lldbtest.TestBase): - """Base class for event-based DarwinLog tests.""" - NO_DEBUG_INFO_TESTCASE = True - - class EventListenerThread(threading.Thread): - - def __init__(self, listener, process, trace_on, max_entry_count): - super( - DarwinLogEventBasedTestBase.EventListenerThread, - self).__init__() - self.process = process - self.listener = listener - self.trace_on = trace_on - self.max_entry_count = max_entry_count - self.exception = None - self.structured_data_event_count = 0 - self.wait_seconds = 2 - self.max_timeout_count = 4 - self.log_entries = [] - - def handle_structured_data_event(self, event): - structured_data = SBProcess.GetStructuredDataFromEvent(event) - if not structured_data.IsValid(): - if self.trace_on: - print("invalid structured data") - return - - # Track that we received a valid structured data event. - self.structured_data_event_count += 1 - - # Grab the individual log entries from the JSON. - stream = lldb.SBStream() - structured_data.GetAsJSON(stream) - dict = json.loads(stream.GetData()) - self.log_entries.extend(dict["events"]) - if self.trace_on: - print("Structured data (raw):", stream.GetData()) - - # Print the pretty-printed version. - if self.trace_on: - stream.Clear() - structured_data.PrettyPrint(stream) - print("Structured data (pretty print):", - stream.GetData()) - - def done(self, timeout_count): - """Returns True when we're done listening for events.""" - # See if we should consider the number of events retrieved. - if self.max_entry_count is not None: - if len(self.log_entries) >= self.max_entry_count: - # We've received the max threshold of events expected, - # we can exit here. - if self.trace_on: - print("Event listener thread exiting due to max " - "expected log entry count being reached.") - return True - - # If our event timeout count has exceeded our maximum timeout count, - # we're done. - if timeout_count >= self.max_timeout_count: - if self.trace_on: - print("Event listener thread exiting due to max number of " - "WaitForEvent() timeouts being reached.") - return True - - # If our process is dead, we're done. - if not self.process.is_alive: - if self.trace_on: - print("Event listener thread exiting due to test inferior " - "exiting.") - return True - - # We're not done. - return False - - def run(self): - event = lldb.SBEvent() - try: - timeout_count = 0 - - # Wait up to 4 times for the event to arrive. - while not self.done(timeout_count): - if self.trace_on: - print("Calling wait for event...") - if self.listener.WaitForEvent(self.wait_seconds, event): - while event.IsValid(): - # Check if it's a process event. - if SBProcess.EventIsStructuredDataEvent(event): - self.handle_structured_data_event(event) - else: - if self.trace_on: - print("ignoring unexpected event:", - lldbutil.get_description(event)) - # Grab the next event, if there is one. - event.Clear() - if not self.listener.GetNextEvent(event): - if self.trace_on: - print("listener has no more events " - "available at this time") - else: - if self.trace_on: - print("timeout occurred waiting for event...") - timeout_count += 1 - self.listener.Clear() - except Exception as e: - self.exception = e - - def setUp(self): - # Call super's setUp(). - super(DarwinLogEventBasedTestBase, self).setUp() - - # Until other systems support this, exit - # early if we're not macOS version 10.12 - # or greater. - version = platform.mac_ver()[0].split('.') - if ((int(version[0]) == 10) and (int(version[1]) < 12) or - (int(version[0]) < 10)): - self.skipTest("DarwinLog tests currently require macOS 10.12+") - return - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = 'a.out' - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - # Enable debugserver logging of the darwin log collection - # mechanism. - self.runCmd("settings set target.process.extra-startup-command " - "QSetLogging:bitmask=LOG_DARWIN_LOG;") - - def darwin_log_available(self): - match = self.match("plugin structured-data darwin-log status", - patterns=[r"Availability: ([\S]+)"]) - return match is not None and (match.group(1) == "available") - - def do_test(self, enable_options, settings_commands=None, - run_enable_after_breakpoint=False, max_entry_count=None): - """Runs the test inferior, returning collected events. - - This method runs the test inferior to the first breakpoint hit. - It then adds a listener for structured data events, and collects - all events from that point forward until end of execution of the - test inferior. It then returns those events. - - @return - A list of structured data events received, in the order they - were received. - """ - self.build(dictionary=self.d) - self.setTearDownCleanup(dictionary=self.d) - - exe = self.getBuildArtifact(self.exe_name) - - # Create a target by the debugger. - target = self.dbg.CreateTarget(exe) - self.assertTrue(target, lldbtest.VALID_TARGET) - - # Run the darwin-log settings commands. - if settings_commands is not None: - for setting_command in settings_commands: - self.runCmd( - expand_darwinlog_settings_set_command(setting_command)) - - # Build the darwin-log enable command. - enable_cmd = expand_darwinlog_command("enable") - if enable_options is not None and len(enable_options) > 0: - enable_cmd += ' ' + ' '.join(enable_options) - - # Run the darwin-log enable command now if we are not supposed - # to do it at the first breakpoint. This tests the start-up - # code, which has the benefit of being able to set os_log-related - # environment variables. - if not run_enable_after_breakpoint: - self.runCmd(enable_cmd) - - # Create the breakpoint. - breakpoint = target.BreakpointCreateByLocation(self.source, self.line) - self.assertIsNotNone(breakpoint) - self.assertTrue(breakpoint.IsValid()) - self.assertEqual(1, breakpoint.GetNumLocations(), - "Should have found one breakpoint") - - # Enable packet logging. - # self.runCmd("log enable -f /tmp/packets.log gdb-remote packets") - # self.runCmd("log enable lldb process") - - # Launch the process - doesn't stop at entry. - process = target.LaunchSimple(None, None, self.getBuildDir()) - self.assertIsNotNone(process, lldbtest.PROCESS_IS_VALID) - - # Keep track of whether we're tracing output. - trace_on = self.TraceOn() - - # Get the next thread that stops. - from lldbsuite.test.lldbutil import get_stopped_thread - thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) - - self.assertIsNotNone(thread, "There should be a thread stopped " - "due to breakpoint") - - # The process should be stopped at this point. - self.expect("process status", lldbtest.PROCESS_STOPPED, - patterns=['Process .* stopped']) - - # The stop reason of the thread should be breakpoint. - self.expect("thread list", lldbtest.STOPPED_DUE_TO_BREAKPOINT, - substrs=['stopped', 'stop reason = breakpoint']) - - # And our one and only breakpoint should have been hit. - self.assertEquals(breakpoint.GetHitCount(), 1) - - # Check if DarwinLog is available. This check cannot be done - # until after the process has started, as the feature availability - # comes through the stub. The stub isn't running until - # the target process is running. So this is really the earliest - # we can check. - if not self.darwin_log_available(): - self.skipTest("DarwinLog not available") - - # Now setup the structured data listener. - # - # Grab the broadcaster for the process. We'll be attaching our - # listener to it. - broadcaster = process.GetBroadcaster() - self.assertIsNotNone(broadcaster) - - listener = lldb.SBListener("SBStructuredData listener") - self.assertIsNotNone(listener) - - rc = broadcaster.AddListener( - listener, lldb.SBProcess.eBroadcastBitStructuredData) - self.assertTrue(rc, "Successfully add listener to process broadcaster") - - # Start the listening thread to retrieve the events. - # Bump up max entry count for the potentially included Add Mode: - # entry. - if max_entry_count is not None: - max_entry_count += 1 - event_thread = self.EventListenerThread(listener, process, trace_on, - max_entry_count) - event_thread.start() - - # Continue the test inferior. We should get any events after this. - process.Continue() - - # Wait until the event thread terminates. - # print("main thread now waiting for event thread to receive events.") - event_thread.join() - - # If the process is still alive, we kill it here. - if process.is_alive: - process.Kill() - - # Fail on any exceptions that occurred during event execution. - if event_thread.exception is not None: - # Re-raise it here so it shows up as a test error. - raise event_thread - - # Return the collected logging events. - return remove_add_mode_entry(event_thread.log_entries) diff --git a/lldb/packages/Python/lldbsuite/test/test_categories.py b/lldb/packages/Python/lldbsuite/test/test_categories.py --- a/lldb/packages/Python/lldbsuite/test/test_categories.py +++ b/lldb/packages/Python/lldbsuite/test/test_categories.py @@ -21,7 +21,6 @@ all_categories = { 'basic_process': 'Basic process execution sniff tests.', 'cmdline': 'Tests related to the LLDB command-line interface', - 'darwin-log': 'Darwin log tests', 'dataformatters': 'Tests related to the type command and the data formatters subsystem', 'debugserver': 'Debugserver tests', 'dsym': 'Tests that can be run with DSYM debug information', diff --git a/lldb/test/API/functionalities/darwin_log/basic/Makefile b/lldb/test/API/functionalities/darwin_log/basic/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/basic/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/basic/TestDarwinLogBasic.py b/lldb/test/API/functionalities/darwin_log/basic/TestDarwinLogBasic.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/basic/TestDarwinLogBasic.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - -# System imports - -# LLDB imports -from lldbsuite.test import darwin_log -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest - - -class TestDarwinLogBasic(darwin_log.DarwinLogEventBasedTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - @decorators.add_test_categories(['pyapi']) - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(archs=["i386"], bugnumber="rdar://28655626") - @decorators.expectedFailureAll(bugnumber="rdar://30645203") - def test_SBStructuredData_gets_broadcasted(self): - """Exercise SBStructuredData API.""" - - # Run the test. - log_entries = self.do_test(None, max_entry_count=2) - - # Validate that we received our two log entries. - self.assertEqual(len(log_entries), 1, - "Expected one log entry to arrive via events.") - self.assertEqual(log_entries[0]['message'], "Hello, world", - "Log message should match expected content.") diff --git a/lldb/test/API/functionalities/darwin_log/basic/main.c b/lldb/test/API/functionalities/darwin_log/basic/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/basic/main.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -#include "../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger = os_log_create("org.llvm.lldb.test", "basic-test"); - if (!logger) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_log(logger, "Hello, world"); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/categories b/lldb/test/API/functionalities/darwin_log/categories deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/categories +++ /dev/null @@ -1 +0,0 @@ -darwin-log diff --git a/lldb/test/API/functionalities/darwin_log/common/darwin_log_common.h b/lldb/test/API/functionalities/darwin_log/common/darwin_log_common.h deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/common/darwin_log_common.h +++ /dev/null @@ -1,6 +0,0 @@ -// The number of seconds to wait at the end of the test inferior before -// exiting. This delay is needed to ensure the logging infrastructure -// has flushed out the message. If we finished before all messages were -// flushed, then the test will never see the unflushed messages, causing -// some test logic to fail. -#define FINAL_WAIT_SECONDS 5 diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/Makefile b/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/TestDarwinLogFilterMatchActivityChain.py b/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/TestDarwinLogFilterMatchActivityChain.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/TestDarwinLogFilterMatchActivityChain.py +++ /dev/null @@ -1,120 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterMatchActivityChain(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterMatchActivityChain, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterMatchActivityChain, self).tearDown() - - # ========================================================================== - # activity-chain filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_chain_match(self): - """Test that fall-through reject, accept full-match activity chain works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity-chain match " - "parent-activity:child-activity\""]) - - # We should only see the second log message as we only accept - # that activity. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_activity_chain_partial_match(self): - """Test that fall-through reject, doesn't accept only partial match of activity-chain.""" - self.do_test( - ["--no-match-accepts false", - # Match the second fully. - "--filter \"accept activity-chain match parent-activity:child-activity\"", - "--filter \"accept activity-chain match parent-ac\""]) # Only partially match the first. - - # We should only see the second log message as we only accept - # that activity. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_activity_chain_full_match(self): - """Test that fall-through accept, reject match activity-chain works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject activity-chain match parent-activity\""]) - - # We should only see the second log message as we rejected the first - # via activity-chain rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_chain_second_rule(self): - """Test that fall-through reject, accept activity-chain on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity-chain match non-existent\"", - "--filter \"accept activity-chain match parent-activity:child-activity\""]) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the activity-chain of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/main.c b/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity-chain/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_log(logger_sub1, "source-log-sub1-cat1"); - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub2, "source-log-sub2-cat2"); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/Makefile b/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/TestDarwinLogFilterMatchActivity.py b/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/TestDarwinLogFilterMatchActivity.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/TestDarwinLogFilterMatchActivity.py +++ /dev/null @@ -1,124 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterMatchActivity(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterMatchActivity, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterMatchActivity, self).tearDown() - - # ========================================================================== - # activity filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_match(self): - """Test that fall-through reject, accept match activity works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity match child-activity\""] - ) - - # We should only see the second log message as we only accept - # that activity. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_activity_partial_match(self): - """Test that fall-through reject, accept match activity via partial match does not accept.""" - self.do_test( - ["--no-match-accepts false", - # Fully match second message. - "--filter \"accept activity match child-activity\"", - "--filter \"accept activity match parent-\""] # Only partially match first message. - ) - - # We should only see the second log message as we only accept - # that activity. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_activity_full_match(self): - """Test that fall-through accept, reject match activity works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject activity match parent-activity\""] - ) - - # We should only see the second log message as we rejected the first - # via activity rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_second_rule(self): - """Test that fall-through reject, accept regex activity on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity match non-existent\"", - "--filter \"accept activity match child-activity\"" - ] - ) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the activity of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/main.c b/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/activity/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_log(logger_sub1, "source-log-sub1-cat1"); - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub2, "source-log-sub2-cat2"); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/Makefile b/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/TestDarwinLogFilterMatchCategory.py b/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/TestDarwinLogFilterMatchCategory.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/TestDarwinLogFilterMatchCategory.py +++ /dev/null @@ -1,124 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterMatchCategory(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterMatchCategory, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterMatchCategory, self).tearDown() - - # ========================================================================== - # category filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_filter_accept_category_full_match(self): - """Test that fall-through reject, accept match single category works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept category match cat2\""] - ) - - # We should only see the second log message as we only accept - # that category. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_category_partial_match(self): - """Test that fall-through reject, accept regex category via partial match works.""" - self.do_test( - ["--no-match-accepts false", - # Fully match the second message. - "--filter \"accept category match cat2\"", - "--filter \"accept category match at1\""] # Only partially match first message. Should not show up. - ) - - # We should only see the second log message as we only accept - # that category. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_category_full_match(self): - """Test that fall-through accept, reject match category works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject category match cat1\""] - ) - - # We should only see the second log message as we rejected the first - # via category rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_category_second_rule(self): - """Test that fall-through reject, accept match category on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept category match non-existent\"", - "--filter \"accept category match cat2\"" - ] - ) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the category of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/main.c b/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/category/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_log(logger_sub1, "source-log-sub1-cat1"); - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub2, "source-log-sub2-cat2"); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/Makefile b/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/TestDarwinLogFilterMatchMessage.py b/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/TestDarwinLogFilterMatchMessage.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/TestDarwinLogFilterMatchMessage.py +++ /dev/null @@ -1,145 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb -import re - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterMatchMessage(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterMatchMessage, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - self.strict_sources = True - - # Turn on process monitor logging while we work out issues. - self.enable_process_monitor_logging = True - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterMatchMessage, self).tearDown() - - # ========================================================================== - # category filter tests - # ========================================================================== - - EXPECT_REGEXES = [ - re.compile(r"log message ([^-]+)-(\S+)"), - re.compile(r"exited with status") - ] - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_accept_message_full_match(self): - """Test that fall-through reject, accept match whole message works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept message match log message sub2-cat2\""], - expect_regexes=self.EXPECT_REGEXES - ) - - # We should only see the second log message as we only accept - # that message contents. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_no_accept_message_partial_match(self): - """Test that fall-through reject, match message via partial content match doesn't accept.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept message match log message sub2-cat2\"", - "--filter \"accept message match sub1-cat1\""], - expect_regexes=self.EXPECT_REGEXES - ) - - # We should only see the second log message as the partial match on - # the first message should not pass. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_reject_category_full_match(self): - """Test that fall-through accept, reject match message works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject message match log message sub1-cat1\""], - expect_regexes=self.EXPECT_REGEXES - ) - - # We should only see the second log message as we rejected the first - # via message contents rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_accept_category_second_rule(self): - """Test that fall-through reject, accept match category on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept message match non-existent\"", - "--filter \"accept message match log message sub2-cat2\""], - expect_regexes=self.EXPECT_REGEXES - ) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the category of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/main.c b/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/message/main.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_log(logger_sub1, "log message sub%d-cat%d", 1, 1); - os_log(logger_sub2, "log message sub%d-cat%d", 2, 2); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(1); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/Makefile b/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/TestDarwinLogFilterMatchSubsystem.py b/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/TestDarwinLogFilterMatchSubsystem.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/TestDarwinLogFilterMatchSubsystem.py +++ /dev/null @@ -1,124 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterMatchSubsystem(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterMatchSubsystem, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterMatchSubsystem, self).tearDown() - - # ========================================================================== - # subsystem filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_filter_accept_subsystem_full_match(self): - """Test that fall-through reject, accept match single subsystem works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept subsystem match org.llvm.lldb.test.sub2\""] - ) - - # We should only see the second log message as we only accept - # that subsystem. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_subsystem_partial_match(self): - """Test that fall-through reject, doesn't accept match subsystem via partial-match.""" - self.do_test( - ["--no-match-accepts false", - # Fully match second message subsystem. - "--filter \"accept subsystem match org.llvm.lldb.test.sub2\"", - "--filter \"accept subsystem match sub1\""] # Only partially match first subsystem. - ) - - # We should only see the second log message as we only accept - # that subsystem. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_subsystem_full_match(self): - """Test that fall-through accept, reject match subsystem works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject subsystem match org.llvm.lldb.test.sub1\""] - ) - - # We should only see the second log message as we rejected the first - # via subsystem rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_subsystem_second_rule(self): - """Test that fall-through reject, accept match subsystem on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept subsystem match non-existent\"", - "--filter \"accept subsystem match org.llvm.lldb.test.sub2\"" - ] - ) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the subsystem of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/main.c b/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/exact_match/subsystem/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_log(logger_sub1, "source-log-sub1-cat1"); - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub2, "source-log-sub2-cat2"); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/Makefile b/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/TestDarwinLogFilterRegexActivityChain.py b/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/TestDarwinLogFilterRegexActivityChain.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/TestDarwinLogFilterRegexActivityChain.py +++ /dev/null @@ -1,135 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterRegexActivityChain(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterRegexActivityChain, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterRegexActivityChain, self).tearDown() - - # ========================================================================== - # activity-chain filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_chain_full_match(self): - """Test that fall-through reject, accept full-match activity chain works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity-chain regex " - "parent-activity:child-activity\""]) - - # We should only see the second log message as we only accept - # that activity. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_chain_partial_match(self): - """Test that fall-through reject, accept activity-chain via partial match works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity-chain regex :child-activity\""]) - - # We should only see the second log message as we only accept - # that activity. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_activity_chain_full_match(self): - """Test that fall-through accept, reject activity-chain works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject activity-chain regex parent-activity:child-..tivity\""]) - - # We should only see the second log message as we rejected the first - # via activity-chain rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat1"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_activity_chain_partial_match(self): - """Test that fall-through accept, reject activity-chain by partial match works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject activity-chain regex ^p[^:]+$\""]) - - # We should only see the second log message as we rejected the first - # via activity-chain rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_chain_second_rule(self): - """Test that fall-through reject, accept activity-chain on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity-chain regex non-existent\"", - "--filter \"accept activity-chain regex child-activity\""]) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the activity-chain of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/main.c b/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/activity-chain/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_log(logger_sub1, "source-log-sub1-cat1"); - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub2, "source-log-sub2-cat2"); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/activity/Makefile b/lldb/test/API/functionalities/darwin_log/filter/regex/activity/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/activity/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/activity/TestDarwinLogFilterRegexActivity.py b/lldb/test/API/functionalities/darwin_log/filter/regex/activity/TestDarwinLogFilterRegexActivity.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/activity/TestDarwinLogFilterRegexActivity.py +++ /dev/null @@ -1,140 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterRegexActivity(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterRegexActivity, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterRegexActivity, self).tearDown() - - # ========================================================================== - # activity filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_full_match(self): - """Test that fall-through reject, accept regex full-match activity works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity regex child-activity\""] - ) - - # We should only see the second log message as we only accept - # that activity. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_partial_match(self): - """Test that fall-through reject, regex accept activity via partial match works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity regex child-.*\""] - ) - - # We should only see the second log message as we only accept - # that activity. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_activity_full_match(self): - """Test that fall-through accept, reject regex activity works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject activity regex parent-activity\""] - ) - - # We should only see the second log message as we rejected the first - # via activity rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_activity_partial_match(self): - """Test that fall-through accept, reject regex activity by partial match works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject activity regex p.+-activity\""] - ) - - # We should only see the second log message as we rejected the first - # via activity rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_activity_second_rule(self): - """Test that fall-through reject, accept regex activity on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept activity regex non-existent\"", - "--filter \"accept activity regex child-activity\"" - ] - ) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the activity of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/activity/main.c b/lldb/test/API/functionalities/darwin_log/filter/regex/activity/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/activity/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_log(logger_sub1, "source-log-sub1-cat1"); - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub2, "source-log-sub2-cat2"); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/category/Makefile b/lldb/test/API/functionalities/darwin_log/filter/regex/category/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/category/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/category/TestDarwinLogFilterRegexCategory.py b/lldb/test/API/functionalities/darwin_log/filter/regex/category/TestDarwinLogFilterRegexCategory.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/category/TestDarwinLogFilterRegexCategory.py +++ /dev/null @@ -1,140 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterRegexCategory(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterRegexCategory, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterRegexCategory, self).tearDown() - - # ========================================================================== - # category filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_filter_accept_category_full_match(self): - """Test that fall-through reject, accept regex single category works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept category regex cat2\""] - ) - - # We should only see the second log message as we only accept - # that category. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_category_partial_match(self): - """Test that fall-through reject, accept regex category via partial match works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept category regex .+2\""] - ) - - # We should only see the second log message as we only accept - # that category. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_category_full_match(self): - """Test that fall-through accept, reject regex category works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject category regex cat1\""] - ) - - # We should only see the second log message as we rejected the first - # via category rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_category_partial_match(self): - """Test that fall-through accept, reject regex category by partial match works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject category regex t1\""] - ) - - # We should only see the second log message as we rejected the first - # via category rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_category_second_rule(self): - """Test that fall-through reject, accept regex category on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept category regex non-existent\"", - "--filter \"accept category regex cat2\"" - ] - ) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the category of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/category/main.c b/lldb/test/API/functionalities/darwin_log/filter/regex/category/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/category/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_log(logger_sub1, "source-log-sub1-cat1"); - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub2, "source-log-sub2-cat2"); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/message/Makefile b/lldb/test/API/functionalities/darwin_log/filter/regex/message/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/message/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/message/TestDarwinLogFilterRegexMessage.py b/lldb/test/API/functionalities/darwin_log/filter/regex/message/TestDarwinLogFilterRegexMessage.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/message/TestDarwinLogFilterRegexMessage.py +++ /dev/null @@ -1,126 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - -# System imports - - -# LLDB imports -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterRegexMessage(darwin_log.DarwinLogEventBasedTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_accept_message_full_match(self): - """Test that fall-through reject, accept regex whole message works.""" - log_entries = self.do_test( - ["--no-match-accepts false", - # Note below, the four '\' characters are to get us two - # backslashes over on the gdb-remote side, which then - # becomes one as the cstr interprets it as an escape - # sequence. This needs to be rationalized. Initially I - # supported std::regex ECMAScript, which has the - # [[:digit:]] character classes and such. That was much - # more tenable. The backslashes have to travel through - # so many layers of escaping. (And note if you take - # off the Python raw string marker here, you need to put - # in 8 backslashes to go to two on the remote side.) - r'--filter "accept message regex log message sub2-cat\\\\d+"']) - - # We should have received at least one log entry. - self.assertIsNotNone(log_entries, - "Log entry list should not be None.") - self.assertEqual(len(log_entries), 1, - "Should receive one log entry.") - self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2", - "First os_log call should have been skipped.") - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_accept_message_partial_match(self): - """Test that fall-through reject, accept regex message via partial - match works.""" - log_entries = self.do_test( - ["--no-match-accepts false", - "--filter \"accept message regex [^-]+2\""]) - - # We should only see the second log message as we only accept - # that message contents. - self.assertIsNotNone(log_entries, - "Log entry list should not be None.") - self.assertEqual(len(log_entries), 1, - "Should receive one log entry.") - self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2", - "First os_log call should have been skipped.") - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_reject_message_full_match(self): - """Test that fall-through accept, reject regex message works.""" - log_entries = self.do_test( - ["--no-match-accepts true", - "--filter \"reject message regex log message sub1-cat1\""]) - - # We should only see the second log message as we rejected the first - # via message contents rejection. - self.assertIsNotNone(log_entries, - "Log entry list should not be None.") - self.assertEqual(len(log_entries), 1, - "Should receive one log entry.") - self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2", - "First os_log call should have been skipped.") - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_reject_message_partial_match(self): - """Test that fall-through accept, reject regex message by partial - match works.""" - log_entries = self.do_test( - ["--no-match-accepts true", - "--filter \"reject message regex t1\""]) - - # We should only see the second log message as we rejected the first - # via partial message contents rejection. - self.assertIsNotNone(log_entries, - "Log entry list should not be None.") - self.assertEqual(len(log_entries), 1, - "Should receive one log entry.") - self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2", - "First os_log call should have been skipped.") - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(oslist=["macosx"], - bugnumber="llvm.org/pr30299") - def test_filter_accept_message_second_rule(self): - """Test that fall-through reject, accept regex message on second rule - works.""" - log_entries = self.do_test( - ["--no-match-accepts false", - "--filter \"accept message regex non-existent\"", - "--filter \"accept message regex cat2\""]) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the message of the second log message. - self.assertIsNotNone(log_entries, - "Log entry list should not be None.") - self.assertEqual(len(log_entries), 1, - "Should receive one log entry.") - self.assertRegexpMatches(log_entries[0]["message"], r"sub2-cat2", - "First os_log call should have been skipped.") diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/message/main.c b/lldb/test/API/functionalities/darwin_log/filter/regex/message/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/message/main.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_log(logger_sub1, "log message sub%d-cat%d", 1, 1); - os_log(logger_sub2, "log message sub%d-cat%d", 2, 2); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/Makefile b/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/TestDarwinLogFilterRegexSubsystem.py b/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/TestDarwinLogFilterRegexSubsystem.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/TestDarwinLogFilterRegexSubsystem.py +++ /dev/null @@ -1,157 +0,0 @@ -""" -Test basic DarwinLog functionality provided by the StructuredDataDarwinLog -plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogFilterRegexSubsystem(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogFilterRegexSubsystem, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogFilterRegexSubsystem, self).tearDown() - - # ========================================================================== - # basic filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_fallthrough_reject(self): - """Test that a single fall-through reject regex rule rejects all logging.""" - self.do_test( - ["--no-match-accepts false"] - ) - - # We should not match any log lines. - self.assertIsNotNone(self.child.match) - self.assertFalse((len(self.child.match.groups()) > 0) and - (self.child.match.group(1) in ["sub1", "sub2"]), - "log line should not have been received") - - # ========================================================================== - # subsystem filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_filter_accept_subsystem_full_match(self): - """Test that fall-through reject, accept regex single subsystem works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept subsystem regex org.llvm.lldb.test.sub2\""] - ) - - # We should only see the second log message as we only accept - # that subsystem. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_subsystem_partial_match(self): - """Test that fall-through reject, accept regex subsystem via partial-match works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept subsystem regex org.llvm.+.sub2\""] - ) - - # We should only see the second log message as we only accept - # that subsystem. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_subsystem_full_match(self): - """Test that fall-through accept, reject regex subsystem works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject subsystem regex org.llvm.lldb.test.sub1\""] - ) - - # We should only see the second log message as we rejected the first - # via subsystem rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_reject_subsystem_partial_match(self): - """Test that fall-through accept, reject regex subsystem by partial match works.""" - self.do_test( - ["--no-match-accepts true", - "--filter \"reject subsystem regex org.*sub1\""] - ) - - # We should only see the second log message as we rejected the first - # via subsystem rejection. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_filter_accept_subsystem_second_rule(self): - """Test that fall-through reject, accept regex subsystem on second rule works.""" - self.do_test( - ["--no-match-accepts false", - "--filter \"accept subsystem regex non-existent\"", - "--filter \"accept subsystem regex org.llvm.lldb.test.sub2\"" - ] - ) - - # We should only see the second message since we reject by default, - # the first filter doesn't match any, and the second filter matches - # the subsystem of the second log message. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 0) and ( - self.child.match.group(1) == "sub2"), - "first log line should not be present, second log line " - "should be") diff --git a/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/main.c b/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/filter/regex/subsystem/main.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include - -#include "../../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_log(logger_sub1, "source-log-sub1-cat1"); - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub2, "source-log-sub2-cat2"); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/format/Makefile b/lldb/test/API/functionalities/darwin_log/format/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/format/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/format/TestDarwinLogMessageFormat.py b/lldb/test/API/functionalities/darwin_log/format/TestDarwinLogMessageFormat.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/format/TestDarwinLogMessageFormat.py +++ /dev/null @@ -1,187 +0,0 @@ -""" -Test DarwinLog log message formatting options provided by the -StructuredDataDarwinLog plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb -import re - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogMessageFormat(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogMessageFormat, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogMessageFormat, self).tearDown() - - # ========================================================================== - # Test settings around log message formatting - # ========================================================================== - - REGEXES = [ - re.compile(r"\[([^]]+)\] This is the log message."), # Match log - # with header. - re.compile(r"This is the log message."), # Match no-header content. - re.compile(r"exited with status") # Fallback if no log emitted. - ] - - @decorators.skipUnlessDarwin - def test_display_without_header_works(self): - """Test that turning off log message headers works as advertised.""" - self.do_test([], expect_regexes=self.REGEXES) - - # We should not match the first pattern as we shouldn't have header - # content. - self.assertIsNotNone(self.child.match) - self.assertFalse((len(self.child.match.groups()) > 0) and - (self.child.match.group(1) != ""), - "we should not have seen a header") - - @decorators.skipUnlessDarwin - def test_display_with_header_works(self): - """Test that displaying any header works.""" - self.do_test( - ["--timestamp-relative", "--subsystem", "--category", - "--activity-chain"], - expect_regexes=self.REGEXES, - settings_commands=[ - "display-header true" - ]) - - # We should match the first pattern as we should have header - # content. - self.assertIsNotNone(self.child.match) - self.assertTrue((len(self.child.match.groups()) > 0) and - (self.child.match.group(1) != ""), - "we should have printed a header") - - def assert_header_contains_timestamp(self, header): - fields = header.split(',') - self.assertGreater(len(fields), 0, - "there should have been header content present") - self.assertRegexpMatches(fields[0], - r"^\d+:\d{2}:\d{2}.\d{9}$", - "time field should match expected format") - - @decorators.skipUnlessDarwin - def test_header_timefield_only_works(self): - """Test that displaying a header with only the timestamp works.""" - self.do_test(["--timestamp-relative"], expect_regexes=self.REGEXES) - - # We should match the first pattern as we should have header - # content. - self.assertIsNotNone(self.child.match) - self.assertTrue((len(self.child.match.groups()) > 0) and - (self.child.match.group(1) != ""), - "we should have printed a header") - header = self.child.match.group(1) - self.assertEqual(len(header.split(',')), 1, - "there should only be one header field") - self.assert_header_contains_timestamp(header) - - @decorators.skipUnlessDarwin - def test_header_subsystem_only_works(self): - """Test that displaying a header with only the subsystem works.""" - self.do_test(["--subsystem"], expect_regexes=self.REGEXES) - - # We should match the first pattern as we should have header - # content. - self.assertIsNotNone(self.child.match) - self.assertTrue((len(self.child.match.groups()) > 0) and - (self.child.match.group(1) != ""), - "we should have printed a header") - header = self.child.match.group(1) - self.assertEqual(len(header.split(',')), 1, - "there should only be one header field") - self.assertEquals(header, - "subsystem=org.llvm.lldb.test.sub1") - - @decorators.skipUnlessDarwin - def test_header_category_only_works(self): - """Test that displaying a header with only the category works.""" - self.do_test(["--category"], expect_regexes=self.REGEXES) - - # We should match the first pattern as we should have header - # content. - self.assertIsNotNone(self.child.match) - self.assertTrue((len(self.child.match.groups()) > 0) and - (self.child.match.group(1) != ""), - "we should have printed a header") - header = self.child.match.group(1) - self.assertEqual(len(header.split(',')), 1, - "there should only be one header field") - self.assertEquals(header, - "category=cat1") - - @decorators.skipUnlessDarwin - def test_header_activity_chain_only_works(self): - """Test that displaying a header with only the activity chain works.""" - self.do_test(["--activity-chain"], expect_regexes=self.REGEXES) - - # We should match the first pattern as we should have header - # content. - self.assertIsNotNone(self.child.match) - self.assertTrue((len(self.child.match.groups()) > 0) and - (self.child.match.group(1) != ""), - "we should have printed a header") - header = self.child.match.group(1) - self.assertEqual(len(header.split(',')), 1, - "there should only be one header field") - self.assertEquals(header, - "activity-chain=parent-activity:child-activity") - - # @decorators.skipUnlessDarwin - # def test_header_activity_no_chain_only_works(self): - # """Test that displaying a header with only the activity works.""" - # self.do_test( - # [], - # expect_regexes=self.REGEXES, - # settings_commands=[ - # "display-header true", - # "format-include-timestamp false", - # "format-include-activity true", - # "format-include-category false", - # "format-include-subsystem false", - # "display-activity-chain false" - # ]) - - # # We should match the first pattern as we should have header - # # content. - # self.assertIsNotNone(self.child.match) - # self.assertTrue((len(self.child.match.groups()) > 0) and - # (self.child.match.group(1) != ""), - # "we should have printed a header") - # header = self.child.match.group(1) - # self.assertEqual(len(header.split(',')), 1, - # "there should only be one header field") - # self.assertEquals(header, - # "activity=child-activity") diff --git a/lldb/test/API/functionalities/darwin_log/format/main.c b/lldb/test/API/functionalities/darwin_log/format/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/format/main.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include - -#include "../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - if (!logger_sub1) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_activity_t parent_activity = os_activity_create("parent-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(parent_activity, ^{ - os_activity_t child_activity = os_activity_create("child-activity", - OS_ACTIVITY_CURRENT, OS_ACTIVITY_FLAG_DEFAULT); - os_activity_apply(child_activity, ^{ - os_log(logger_sub1, "This is the log message."); - }); - }); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/source/debug/Makefile b/lldb/test/API/functionalities/darwin_log/source/debug/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/source/debug/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/source/debug/TestDarwinLogSourceDebug.py b/lldb/test/API/functionalities/darwin_log/source/debug/TestDarwinLogSourceDebug.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/source/debug/TestDarwinLogSourceDebug.py +++ /dev/null @@ -1,78 +0,0 @@ -""" -Test DarwinLog "source include debug-level" functionality provided by the -StructuredDataDarwinLog plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogSourceDebug(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogSourceDebug, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - # Indicate we want strict-sources behavior. - self.strict_sources = True - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogSourceDebug, self).tearDown() - - # ========================================================================== - # source include/exclude debug filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - def test_source_default_exclude_debug(self): - """Test that default excluding of debug-level log messages works.""" - self.do_test([]) - - # We should only see the second log message as the first is a - # debug-level message and we're not including debug-level messages. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_source_explicitly_include_debug(self): - """Test that explicitly including debug-level log messages works.""" - self.do_test(["--debug"]) - - # We should only see the second log message as the first is a - # debug-level message and we're not including debug-level messages. - self.assertIsNotNone(self.child.match) - self.assertTrue((len(self.child.match.groups()) > 1) and - (self.child.match.group(2) == "cat1"), - "first log line should be present since we're " - "including debug-level log messages") diff --git a/lldb/test/API/functionalities/darwin_log/source/debug/main.c b/lldb/test/API/functionalities/darwin_log/source/debug/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/source/debug/main.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -#include "../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_log_debug(logger_sub1, "source-log-sub1-cat1"); - os_log(logger_sub2, "source-log-sub2-cat2"); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/test/API/functionalities/darwin_log/source/info/Makefile b/lldb/test/API/functionalities/darwin_log/source/info/Makefile deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/source/info/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -C_SOURCES := main.c - -include Makefile.rules diff --git a/lldb/test/API/functionalities/darwin_log/source/info/TestDarwinLogSourceInfo.py b/lldb/test/API/functionalities/darwin_log/source/info/TestDarwinLogSourceInfo.py deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/source/info/TestDarwinLogSourceInfo.py +++ /dev/null @@ -1,81 +0,0 @@ -""" -Test DarwinLog "source include info-level" functionality provided by the -StructuredDataDarwinLog plugin. - -These tests are currently only supported when running against Darwin -targets. -""" - - -import lldb - -from lldbsuite.test import decorators -from lldbsuite.test import lldbtest -from lldbsuite.test import darwin_log - - -class TestDarwinLogSourceInfo(darwin_log.DarwinLogTestBase): - - mydir = lldbtest.TestBase.compute_mydir(__file__) - - def setUp(self): - # Call super's setUp(). - super(TestDarwinLogSourceInfo, self).setUp() - - # Source filename. - self.source = 'main.c' - - # Output filename. - self.exe_name = self.getBuildArtifact("a.out") - self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} - - # Locate breakpoint. - self.line = lldbtest.line_number(self.source, '// break here') - - # Indicate we want strict-sources behavior. - self.strict_sources = True - - def tearDown(self): - # Shut down the process if it's still running. - if self.child: - self.runCmd('process kill') - self.expect_prompt() - self.runCmd('quit') - - # Let parent clean up - super(TestDarwinLogSourceInfo, self).tearDown() - - # ========================================================================== - # source include/exclude debug filter tests - # ========================================================================== - - @decorators.skipUnlessDarwin - @decorators.expectedFailureAll(bugnumber="rdar://27316264") - def test_source_exclude_info_level(self): - """Test that default excluding of info-level log messages works.""" - self.do_test([]) - - # We should only see the second log message as the first is an - # info-level message and we're not including debug-level messages. - self.assertIsNotNone(self.child.match) - self.assertTrue( - (len( - self.child.match.groups()) > 1) and ( - self.child.match.group(2) == "cat2"), - "first log line should not be present, second log line " - "should be") - - @decorators.skipUnlessDarwin - def test_source_include_info_level(self): - """Test that explicitly including info-level log messages works.""" - self.do_test( - ["--info"] - ) - - # We should only see the second log message as the first is a - # debug-level message and we're not including debug-level messages. - self.assertIsNotNone(self.child.match) - self.assertTrue((len(self.child.match.groups()) > 1) and - (self.child.match.group(2) == "cat1"), - "first log line should be present since we're " - "including info-level log messages") diff --git a/lldb/test/API/functionalities/darwin_log/source/info/main.c b/lldb/test/API/functionalities/darwin_log/source/info/main.c deleted file mode 100644 --- a/lldb/test/API/functionalities/darwin_log/source/info/main.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -#include "../../common/darwin_log_common.h" - -int main(int argc, char** argv) -{ - os_log_t logger_sub1 = os_log_create("org.llvm.lldb.test.sub1", "cat1"); - os_log_t logger_sub2 = os_log_create("org.llvm.lldb.test.sub2", "cat2"); - if (!logger_sub1 || !logger_sub2) - return 1; - - // Note we cannot use the os_log() line as the breakpoint because, as of - // the initial writing of this test, we get multiple breakpoints for that - // line, which confuses the pexpect test logic. - printf("About to log\n"); // break here - os_log_info(logger_sub1, "source-log-sub1-cat1"); - os_log(logger_sub2, "source-log-sub2-cat2"); - - // Sleep, as the darwin log reporting doesn't always happen until a bit - // later. We need the message to come out before the process terminates. - sleep(FINAL_WAIT_SECONDS); - - return 0; -} diff --git a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj --- a/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj +++ b/lldb/tools/debugserver/debugserver.xcodeproj/project.pbxproj @@ -9,24 +9,8 @@ /* Begin PBXBuildFile section */ 23043C9D1D35DBEC00FC25CA /* JSON.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 233B4EA51D2DB54300E98261 /* JSON.cpp */; }; 23043C9E1D35DBFA00FC25CA /* StringConvert.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 233B4EA81D2DB96A00E98261 /* StringConvert.cpp */; }; - 2307CCCB1D4A5D630016ABC0 /* LogFilterExactMatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 237821AE1D4917D20028B7A1 /* LogFilterExactMatch.cpp */; }; 233B4EA71D2DB54300E98261 /* JSON.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 233B4EA51D2DB54300E98261 /* JSON.cpp */; }; 233B4EA91D2DB96A00E98261 /* StringConvert.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 233B4EA81D2DB96A00E98261 /* StringConvert.cpp */; }; - 23562ED21D3424DF00AB2BD4 /* LogMessageOsLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23562ED01D3424DF00AB2BD4 /* LogMessageOsLog.cpp */; }; - 23562ED31D3424DF00AB2BD4 /* LogMessageOsLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23562ED01D3424DF00AB2BD4 /* LogMessageOsLog.cpp */; }; - 23562ED61D342A5A00AB2BD4 /* ActivityStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23562ED51D342A5A00AB2BD4 /* ActivityStore.cpp */; }; - 23562ED71D342A5A00AB2BD4 /* ActivityStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23562ED51D342A5A00AB2BD4 /* ActivityStore.cpp */; }; - 23562ED91D342B0000AB2BD4 /* LogMessage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23562ED81D342B0000AB2BD4 /* LogMessage.cpp */; }; - 23562EDA1D342B0000AB2BD4 /* LogMessage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23562ED81D342B0000AB2BD4 /* LogMessage.cpp */; }; - 237821B01D4917D20028B7A1 /* LogFilterExactMatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 237821AE1D4917D20028B7A1 /* LogFilterExactMatch.cpp */; }; - 23AC04C61D2F41A00072351D /* LogFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AC04C41D2F41A00072351D /* LogFilter.cpp */; }; - 23AC04C71D2F41A00072351D /* LogFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AC04C41D2F41A00072351D /* LogFilter.cpp */; }; - 23AC04CA1D2F42250072351D /* LogFilterChain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AC04C81D2F42250072351D /* LogFilterChain.cpp */; }; - 23AC04CB1D2F42250072351D /* LogFilterChain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AC04C81D2F42250072351D /* LogFilterChain.cpp */; }; - 23AC04CF1D2F58AF0072351D /* LogFilterRegex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AC04CD1D2F58AF0072351D /* LogFilterRegex.cpp */; }; - 23AC04D01D2F58AF0072351D /* LogFilterRegex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AC04CD1D2F58AF0072351D /* LogFilterRegex.cpp */; }; - 23AE72E41D25DECF00945BCE /* DarwinLogCollector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AE72E21D25DECF00945BCE /* DarwinLogCollector.cpp */; }; - 23AE72E51D25DEE100945BCE /* DarwinLogCollector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23AE72E21D25DECF00945BCE /* DarwinLogCollector.cpp */; }; 23D1B0291D497E8B00FF831B /* OsLogger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23D1B0271D497E8B00FF831B /* OsLogger.cpp */; }; 23D1B02A1D497E8B00FF831B /* OsLogger.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 23D1B0271D497E8B00FF831B /* OsLogger.cpp */; }; 264D5D581293835600ED4C01 /* DNBArch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 264D5D571293835600ED4C01 /* DNBArch.cpp */; }; @@ -108,27 +92,6 @@ 233B4EA51D2DB54300E98261 /* JSON.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSON.cpp; sourceTree = ""; }; 233B4EA61D2DB54300E98261 /* JSON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSON.h; sourceTree = ""; }; 233B4EA81D2DB96A00E98261 /* StringConvert.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringConvert.cpp; path = ../../../source/Host/common/StringConvert.cpp; sourceTree = ""; }; - 23562ECF1D34110D00AB2BD4 /* DarwinLogTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DarwinLogTypes.h; sourceTree = ""; }; - 23562ED01D3424DF00AB2BD4 /* LogMessageOsLog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogMessageOsLog.cpp; sourceTree = ""; }; - 23562ED11D3424DF00AB2BD4 /* LogMessageOsLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogMessageOsLog.h; sourceTree = ""; }; - 23562ED41D3426DD00AB2BD4 /* ActivityStore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ActivityStore.h; sourceTree = ""; }; - 23562ED51D342A5A00AB2BD4 /* ActivityStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ActivityStore.cpp; sourceTree = ""; }; - 23562ED81D342B0000AB2BD4 /* LogMessage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogMessage.cpp; sourceTree = ""; }; - 237821AD1D4917D20028B7A1 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - 237821AE1D4917D20028B7A1 /* LogFilterExactMatch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogFilterExactMatch.cpp; sourceTree = ""; }; - 237821AF1D4917D20028B7A1 /* LogFilterExactMatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogFilterExactMatch.h; sourceTree = ""; }; - 23AC04C41D2F41A00072351D /* LogFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogFilter.cpp; sourceTree = ""; }; - 23AC04C51D2F41A00072351D /* LogFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogFilter.h; sourceTree = ""; }; - 23AC04C81D2F42250072351D /* LogFilterChain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogFilterChain.cpp; sourceTree = ""; }; - 23AC04C91D2F42250072351D /* LogFilterChain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogFilterChain.h; sourceTree = ""; }; - 23AC04CC1D2F42F10072351D /* DarwinLogInterfaces.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DarwinLogInterfaces.h; sourceTree = ""; }; - 23AC04CD1D2F58AF0072351D /* LogFilterRegex.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LogFilterRegex.cpp; sourceTree = ""; }; - 23AC04CE1D2F58AF0072351D /* LogFilterRegex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogFilterRegex.h; sourceTree = ""; }; - 23AC04D11D2F60130072351D /* LogMessage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LogMessage.h; sourceTree = ""; }; - 23AE72E21D25DECF00945BCE /* DarwinLogCollector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DarwinLogCollector.cpp; sourceTree = ""; }; - 23AE72E31D25DECF00945BCE /* DarwinLogCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DarwinLogCollector.h; sourceTree = ""; }; - 23AE72E61D25DEFB00945BCE /* ActivityStreamSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ActivityStreamSPI.h; sourceTree = ""; }; - 23CF6F5E1D28A3760088ADC9 /* DarwinLogEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DarwinLogEvent.h; sourceTree = ""; }; 23D1B0271D497E8B00FF831B /* OsLogger.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OsLogger.cpp; sourceTree = ""; }; 23D1B0281D497E8B00FF831B /* OsLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OsLogger.h; sourceTree = ""; }; 260828DE0CBAF7F400F95054 /* DNBRuntimeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DNBRuntimeAction.h; sourceTree = ""; }; @@ -267,34 +230,6 @@ name = Products; sourceTree = ""; }; - 23AC04C31D2F3E9A0072351D /* DarwinLog */ = { - isa = PBXGroup; - children = ( - 237821AD1D4917D20028B7A1 /* CMakeLists.txt */, - 23562ED41D3426DD00AB2BD4 /* ActivityStore.h */, - 23562ED51D342A5A00AB2BD4 /* ActivityStore.cpp */, - 23AE72E61D25DEFB00945BCE /* ActivityStreamSPI.h */, - 23AE72E31D25DECF00945BCE /* DarwinLogCollector.h */, - 23AE72E21D25DECF00945BCE /* DarwinLogCollector.cpp */, - 23CF6F5E1D28A3760088ADC9 /* DarwinLogEvent.h */, - 23AC04CC1D2F42F10072351D /* DarwinLogInterfaces.h */, - 23562ECF1D34110D00AB2BD4 /* DarwinLogTypes.h */, - 23AC04C51D2F41A00072351D /* LogFilter.h */, - 23AC04C41D2F41A00072351D /* LogFilter.cpp */, - 23AC04C91D2F42250072351D /* LogFilterChain.h */, - 23AC04C81D2F42250072351D /* LogFilterChain.cpp */, - 237821AF1D4917D20028B7A1 /* LogFilterExactMatch.h */, - 237821AE1D4917D20028B7A1 /* LogFilterExactMatch.cpp */, - 23AC04CE1D2F58AF0072351D /* LogFilterRegex.h */, - 23AC04CD1D2F58AF0072351D /* LogFilterRegex.cpp */, - 23AC04D11D2F60130072351D /* LogMessage.h */, - 23562ED81D342B0000AB2BD4 /* LogMessage.cpp */, - 23562ED11D3424DF00AB2BD4 /* LogMessageOsLog.h */, - 23562ED01D3424DF00AB2BD4 /* LogMessageOsLog.cpp */, - ); - path = DarwinLog; - sourceTree = ""; - }; 266B5ECE1460A68200E43F0A /* arm64 */ = { isa = PBXGroup; children = ( @@ -395,7 +330,6 @@ 26C637E60C71334A0024798E /* MacOSX */ = { isa = PBXGroup; children = ( - 23AC04C31D2F3E9A0072351D /* DarwinLog */, 2695DD920D3EBFF6007E4CA2 /* CFBundle.h */, 2695DD910D3EBFF6007E4CA2 /* CFBundle.cpp */, 2695DD9A0D3EC160007E4CA2 /* CFString.h */, @@ -586,29 +520,21 @@ 26CE05B6115C36390022F371 /* MachTask.mm in Sources */, 26CE05B7115C363B0022F371 /* DNB.cpp in Sources */, AFEC3364194A8B0B00FF05C6 /* Genealogy.cpp in Sources */, - 23AC04CF1D2F58AF0072351D /* LogFilterRegex.cpp in Sources */, 233B4EA91D2DB96A00E98261 /* StringConvert.cpp in Sources */, - 23562ED21D3424DF00AB2BD4 /* LogMessageOsLog.cpp in Sources */, 26CE05B8115C363C0022F371 /* DNBBreakpoint.cpp in Sources */, 26CE05B9115C363D0022F371 /* DNBDataRef.cpp in Sources */, - 23AC04CA1D2F42250072351D /* LogFilterChain.cpp in Sources */, - 23562ED61D342A5A00AB2BD4 /* ActivityStore.cpp in Sources */, 26CE05BA115C363E0022F371 /* DNBLog.cpp in Sources */, - 23AC04C61D2F41A00072351D /* LogFilter.cpp in Sources */, 26CE05BB115C363F0022F371 /* DNBRegisterInfo.cpp in Sources */, 26CE05BC115C36420022F371 /* PThreadEvent.cpp in Sources */, 26CE05BD115C36430022F371 /* PThreadMutex.cpp in Sources */, 26CE05BE115C36440022F371 /* SysSignal.cpp in Sources */, - 23AE72E41D25DECF00945BCE /* DarwinLogCollector.cpp in Sources */, 26CE05BF115C364D0022F371 /* DNBArchImplX86_64.cpp in Sources */, 26CE05C0115C364F0022F371 /* DNBArchImplI386.cpp in Sources */, 26CE05C1115C36510022F371 /* DNBArchImpl.cpp in Sources */, 26CE05C5115C36590022F371 /* CFBundle.cpp in Sources */, 26CE05C3115C36580022F371 /* CFString.cpp in Sources */, - 23562ED91D342B0000AB2BD4 /* LogMessage.cpp in Sources */, 26CE05F1115C387C0022F371 /* PseudoTerminal.cpp in Sources */, 264D5D581293835600ED4C01 /* DNBArch.cpp in Sources */, - 237821B01D4917D20028B7A1 /* LogFilterExactMatch.cpp in Sources */, 266B5ED11460A68200E43F0A /* DNBArchImplARM64.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -629,38 +555,30 @@ 456F674D1AD46CE9002850C2 /* dbgnub-mig.defs in Sources */, 456F674E1AD46CE9002850C2 /* MachException.cpp in Sources */, 456F674F1AD46CE9002850C2 /* MachProcess.mm in Sources */, - 2307CCCB1D4A5D630016ABC0 /* LogFilterExactMatch.cpp in Sources */, 456F67501AD46CE9002850C2 /* MachThread.cpp in Sources */, 456F67511AD46CE9002850C2 /* MachThreadList.cpp in Sources */, 456F67521AD46CE9002850C2 /* MachVMMemory.cpp in Sources */, 456F67531AD46CE9002850C2 /* MachVMRegion.cpp in Sources */, - 23562ED71D342A5A00AB2BD4 /* ActivityStore.cpp in Sources */, 456F67541AD46CE9002850C2 /* MachTask.mm in Sources */, 456F67551AD46CE9002850C2 /* DNB.cpp in Sources */, 456F67561AD46CE9002850C2 /* Genealogy.cpp in Sources */, 456F67571AD46CE9002850C2 /* DNBBreakpoint.cpp in Sources */, 456F67581AD46CE9002850C2 /* DNBDataRef.cpp in Sources */, 456F67591AD46CE9002850C2 /* DNBLog.cpp in Sources */, - 23562ED31D3424DF00AB2BD4 /* LogMessageOsLog.cpp in Sources */, 456F675A1AD46CE9002850C2 /* DNBRegisterInfo.cpp in Sources */, 456F675B1AD46CE9002850C2 /* PThreadEvent.cpp in Sources */, 456F675C1AD46CE9002850C2 /* PThreadMutex.cpp in Sources */, 456F675D1AD46CE9002850C2 /* SysSignal.cpp in Sources */, - 23AE72E51D25DEE100945BCE /* DarwinLogCollector.cpp in Sources */, 456F675E1AD46CE9002850C2 /* DNBArchImplX86_64.cpp in Sources */, - 23562EDA1D342B0000AB2BD4 /* LogMessage.cpp in Sources */, 456F675F1AD46CE9002850C2 /* DNBArchImplI386.cpp in Sources */, 456F67601AD46CE9002850C2 /* DNBArchImpl.cpp in Sources */, - 23AC04C71D2F41A00072351D /* LogFilter.cpp in Sources */, 23043C9E1D35DBFA00FC25CA /* StringConvert.cpp in Sources */, AF588449206077BD00A0CB5A /* SocketAddress.cpp in Sources */, 456F67621AD46CE9002850C2 /* CFString.cpp in Sources */, - 23AC04CB1D2F42250072351D /* LogFilterChain.cpp in Sources */, AF48558D1D75127500D19C07 /* StdStringExtractor.cpp in Sources */, 456F67641AD46CE9002850C2 /* CFBundle.cpp in Sources */, 456F67651AD46CE9002850C2 /* PseudoTerminal.cpp in Sources */, 456F67671AD46CE9002850C2 /* DNBArch.cpp in Sources */, - 23AC04D01D2F58AF0072351D /* LogFilterRegex.cpp in Sources */, 456F67691AD46CE9002850C2 /* DNBArchImplARM64.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/lldb/tools/debugserver/source/CMakeLists.txt b/lldb/tools/debugserver/source/CMakeLists.txt --- a/lldb/tools/debugserver/source/CMakeLists.txt +++ b/lldb/tools/debugserver/source/CMakeLists.txt @@ -2,7 +2,6 @@ include(CheckLibraryExists) include_directories(${CMAKE_CURRENT_BINARY_DIR}/..) include_directories(${LLDB_SOURCE_DIR}/source) -include_directories(MacOSX/DarwinLog) include_directories(MacOSX) @@ -255,7 +254,6 @@ ${LOCKDOWN_LIBRARY} ${CAROUSELSERVICES_LIBRARY} lldbDebugserverArchSupport - lldbDebugserverDarwin_DarwinLog ${FOUNDATION_LIBRARY} ${SECURITY_LIBRARY} ${LIBCOMPRESSION} @@ -325,7 +323,6 @@ ${CORE_FOUNDATION_LIBRARY} ${FOUNDATION_LIBRARY} lldbDebugserverArchSupport - lldbDebugserverDarwin_DarwinLog ${SECURITY_LIBRARY} ${LIBCOMPRESSION}) if(HAVE_LIBCOMPRESSION) diff --git a/lldb/tools/debugserver/source/DNB.h b/lldb/tools/debugserver/source/DNB.h --- a/lldb/tools/debugserver/source/DNB.h +++ b/lldb/tools/debugserver/source/DNB.h @@ -15,7 +15,6 @@ #include "DNBDefs.h" #include "JSONGenerator.h" -#include "MacOSX/DarwinLog/DarwinLogEvent.h" #include "MacOSX/Genealogy.h" #include "MacOSX/ThreadInfo.h" #include "RNBContext.h" @@ -108,7 +107,6 @@ DNBProcessSetEnableAsyncProfiling(nub_process_t pid, nub_bool_t enable, uint64_t interval_usec, DNBProfileDataScanType scan_type) DNB_EXPORT; -DarwinLogEventVector DNBProcessGetAvailableDarwinLogEvents(nub_process_t pid); // Process status nub_bool_t DNBProcessIsAlive(nub_process_t pid) DNB_EXPORT; diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -46,7 +46,6 @@ #include "DNBLog.h" #include "DNBThreadResumeActions.h" #include "DNBTimer.h" -#include "MacOSX/DarwinLog/DarwinLogCollector.h" #include "MacOSX/Genealogy.h" #include "MacOSX/MachProcess.h" #include "MacOSX/MachTask.h" @@ -1660,10 +1659,6 @@ return 0; } -DarwinLogEventVector DNBProcessGetAvailableDarwinLogEvents(nub_process_t pid) { - return DarwinLogCollector::GetEventsForProcess(pid); -} - nub_size_t DNBProcessGetStopCount(nub_process_t pid) { MachProcessSP procSP; if (GetProcessSP(pid, procSP)) diff --git a/lldb/tools/debugserver/source/MacOSX/CMakeLists.txt b/lldb/tools/debugserver/source/MacOSX/CMakeLists.txt --- a/lldb/tools/debugserver/source/MacOSX/CMakeLists.txt +++ b/lldb/tools/debugserver/source/MacOSX/CMakeLists.txt @@ -26,8 +26,6 @@ include_directories(${CURRENT_SOURCE_DIR}/i386 ${CURRENT_SOURCE_DIR}/x86_64) endif() -add_subdirectory(DarwinLog) - include_directories(..) include_directories(${LLDB_SOURCE_DIR}/tools/debugserver/source) diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.h +++ /dev/null @@ -1,29 +0,0 @@ -//===-- ActivityStore.h -----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_ACTIVITYSTORE_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_ACTIVITYSTORE_H - -#include - -#include "ActivityStreamSPI.h" - -class ActivityStore { -public: - virtual ~ActivityStore(); - - virtual const char *GetActivityForID(os_activity_id_t activity_id) const = 0; - - virtual std::string - GetActivityChainForID(os_activity_id_t activity_id) const = 0; - -protected: - ActivityStore(); -}; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_ACTIVITYSTORE_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStore.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===-- ActivityStore.cpp ---------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "ActivityStore.h" - -ActivityStore::ActivityStore() {} - -ActivityStore::~ActivityStore() {} diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/ActivityStreamSPI.h +++ /dev/null @@ -1,190 +0,0 @@ -//===-- ActivityStreamSPI.h -------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_ACTIVITYSTREAMSPI_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_ACTIVITYSTREAMSPI_H - -#include -#include - -#define OS_ACTIVITY_MAX_CALLSTACK 32 - -// Enums - -enum { - OS_ACTIVITY_STREAM_PROCESS_ONLY = 0x00000001, - OS_ACTIVITY_STREAM_SKIP_DECODE = 0x00000002, - OS_ACTIVITY_STREAM_PAYLOAD = 0x00000004, - OS_ACTIVITY_STREAM_HISTORICAL = 0x00000008, - OS_ACTIVITY_STREAM_CALLSTACK = 0x00000010, - OS_ACTIVITY_STREAM_DEBUG = 0x00000020, - OS_ACTIVITY_STREAM_BUFFERED = 0x00000040, - OS_ACTIVITY_STREAM_NO_SENSITIVE = 0x00000080, - OS_ACTIVITY_STREAM_INFO = 0x00000100, - OS_ACTIVITY_STREAM_PROMISCUOUS = 0x00000200, - OS_ACTIVITY_STREAM_PRECISE_TIMESTAMPS = 0x00000200 -}; -typedef uint32_t os_activity_stream_flag_t; - -enum { - OS_ACTIVITY_STREAM_TYPE_ACTIVITY_CREATE = 0x0201, - OS_ACTIVITY_STREAM_TYPE_ACTIVITY_TRANSITION = 0x0202, - OS_ACTIVITY_STREAM_TYPE_ACTIVITY_USERACTION = 0x0203, - - OS_ACTIVITY_STREAM_TYPE_TRACE_MESSAGE = 0x0300, - - OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE = 0x0400, - OS_ACTIVITY_STREAM_TYPE_LEGACY_LOG_MESSAGE = 0x0480, - - OS_ACTIVITY_STREAM_TYPE_SIGNPOST_BEGIN = 0x0601, - OS_ACTIVITY_STREAM_TYPE_SIGNPOST_END = 0x0602, - OS_ACTIVITY_STREAM_TYPE_SIGNPOST_EVENT = 0x0603, - - OS_ACTIVITY_STREAM_TYPE_STATEDUMP_EVENT = 0x0A00, -}; -typedef uint32_t os_activity_stream_type_t; - -enum { - OS_ACTIVITY_STREAM_EVENT_STARTED = 1, - OS_ACTIVITY_STREAM_EVENT_STOPPED = 2, - OS_ACTIVITY_STREAM_EVENT_FAILED = 3, - OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED = 4, - OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED = 5, -}; -typedef uint32_t os_activity_stream_event_t; - -// Types - -typedef uint64_t os_activity_id_t; -typedef struct os_activity_stream_s *os_activity_stream_t; -typedef struct os_activity_stream_entry_s *os_activity_stream_entry_t; - -#define OS_ACTIVITY_STREAM_COMMON() \ - uint64_t trace_id; \ - uint64_t timestamp; \ - uint64_t thread; \ - const uint8_t *image_uuid; \ - const char *image_path; \ - struct timeval tv_gmt; \ - struct timezone tz; \ - uint32_t offset - -typedef struct os_activity_stream_common_s { - OS_ACTIVITY_STREAM_COMMON(); -} * os_activity_stream_common_t; - -struct os_activity_create_s { - OS_ACTIVITY_STREAM_COMMON(); - const char *name; - os_activity_id_t creator_aid; - uint64_t unique_pid; -}; - -struct os_activity_transition_s { - OS_ACTIVITY_STREAM_COMMON(); - os_activity_id_t transition_id; -}; - -typedef struct os_log_message_s { - OS_ACTIVITY_STREAM_COMMON(); - const char *format; - const uint8_t *buffer; - size_t buffer_sz; - const uint8_t *privdata; - size_t privdata_sz; - const char *subsystem; - const char *category; - uint32_t oversize_id; - uint8_t ttl; - bool persisted; -} * os_log_message_t; - -typedef struct os_trace_message_v2_s { - OS_ACTIVITY_STREAM_COMMON(); - const char *format; - const void *buffer; - size_t bufferLen; - xpc_object_t __unsafe_unretained payload; -} * os_trace_message_v2_t; - -typedef struct os_activity_useraction_s { - OS_ACTIVITY_STREAM_COMMON(); - const char *action; - bool persisted; -} * os_activity_useraction_t; - -typedef struct os_signpost_s { - OS_ACTIVITY_STREAM_COMMON(); - const char *format; - const uint8_t *buffer; - size_t buffer_sz; - const uint8_t *privdata; - size_t privdata_sz; - const char *subsystem; - const char *category; - uint64_t duration_nsec; - uint32_t callstack_depth; - uint64_t callstack[OS_ACTIVITY_MAX_CALLSTACK]; -} * os_signpost_t; - -typedef struct os_activity_statedump_s { - OS_ACTIVITY_STREAM_COMMON(); - char *message; - size_t message_size; - char image_path_buffer[PATH_MAX]; -} * os_activity_statedump_t; - -struct os_activity_stream_entry_s { - os_activity_stream_type_t type; - - // information about the process streaming the data - pid_t pid; - uint64_t proc_id; - const uint8_t *proc_imageuuid; - const char *proc_imagepath; - - // the activity associated with this streamed event - os_activity_id_t activity_id; - os_activity_id_t parent_id; - - union { - struct os_activity_stream_common_s common; - struct os_activity_create_s activity_create; - struct os_activity_transition_s activity_transition; - struct os_log_message_s log_message; - struct os_trace_message_v2_s trace_message; - struct os_activity_useraction_s useraction; - struct os_signpost_s signpost; - struct os_activity_statedump_s statedump; - }; -}; - -// Blocks - -typedef bool (^os_activity_stream_block_t)(os_activity_stream_entry_t entry, - int error); - -typedef void (^os_activity_stream_event_block_t)( - os_activity_stream_t stream, os_activity_stream_event_t event); - -// SPI entry point prototypes - -typedef os_activity_stream_t (*os_activity_stream_for_pid_t)( - pid_t pid, os_activity_stream_flag_t flags, - os_activity_stream_block_t stream_block); - -typedef void (*os_activity_stream_resume_t)(os_activity_stream_t stream); - -typedef void (*os_activity_stream_cancel_t)(os_activity_stream_t stream); - -typedef char *(*os_log_copy_formatted_message_t)(os_log_message_t log_message); - -typedef void (*os_activity_stream_set_event_handler_t)( - os_activity_stream_t stream, os_activity_stream_event_block_t block); - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_ACTIVITYSTREAMSPI_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/CMakeLists.txt b/lldb/tools/debugserver/source/MacOSX/DarwinLog/CMakeLists.txt deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Due to sources including headers like: -# #include "MacOSX/i386/DNBArchImplI386.h" -# we must include the grandparent directory... -include_directories(${LLDB_SOURCE_DIR}/tools/debugserver/source) - -add_library(lldbDebugserverDarwin_DarwinLog - ActivityStore.cpp - DarwinLogCollector.cpp - LogFilter.cpp - LogFilterChain.cpp - LogFilterExactMatch.cpp - LogFilterRegex.cpp - LogMessage.cpp - LogMessageOsLog.cpp - ) - -set_target_properties(lldbDebugserverDarwin_DarwinLog PROPERTIES FOLDER "lldb libraries/debugserver") diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.h +++ /dev/null @@ -1,107 +0,0 @@ -//===-- DarwinLogCollector.h ------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGCOLLECTOR_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGCOLLECTOR_H - -#include - -#include -#include -#include - -#include "ActivityStore.h" -#include "ActivityStreamSPI.h" -#include "DNBDefs.h" -#include "DarwinLogEvent.h" -#include "DarwinLogInterfaces.h" -#include "JSON.h" - -class DarwinLogCollector; -typedef std::shared_ptr DarwinLogCollectorSP; - -class DarwinLogCollector - : public std::enable_shared_from_this, - public ActivityStore { -public: - /// Return whether the os_log and activity tracing SPI is available. - /// - /// \return \b true if the activity stream support is available, - /// \b false otherwise. - static bool IsSupported(); - - /// Return a log function suitable for DNBLog to use as the internal - /// logging function. - /// - /// \return a DNBLog-style logging function if IsSupported() returns - /// true; otherwise, returns nullptr. - static DNBCallbackLog GetLogFunction(); - - static bool StartCollectingForProcess(nub_process_t pid, - const JSONObject &config); - - static bool CancelStreamForProcess(nub_process_t pid); - - static DarwinLogEventVector GetEventsForProcess(nub_process_t pid); - - ~DarwinLogCollector(); - - pid_t GetProcessID() const { return m_pid; } - - // ActivityStore API - const char *GetActivityForID(os_activity_id_t activity_id) const override; - - std::string - GetActivityChainForID(os_activity_id_t activity_id) const override; - -private: - DarwinLogCollector() = delete; - DarwinLogCollector(const DarwinLogCollector &) = delete; - DarwinLogCollector &operator=(const DarwinLogCollector &) = delete; - - explicit DarwinLogCollector(nub_process_t pid, - const LogFilterChainSP &filter_chain_sp); - - void SignalDataAvailable(); - - void SetActivityStream(os_activity_stream_t activity_stream); - - bool HandleStreamEntry(os_activity_stream_entry_t entry, int error); - - DarwinLogEventVector RemoveEvents(); - - void CancelActivityStream(); - - void GetActivityChainForID_internal(os_activity_id_t activity_id, - std::string &result, size_t depth) const; - - struct ActivityInfo { - ActivityInfo(const char *name, os_activity_id_t activity_id, - os_activity_id_t parent_activity_id) - : m_name(name), m_id(activity_id), m_parent_id(parent_activity_id) {} - - const std::string m_name; - const os_activity_id_t m_id; - const os_activity_id_t m_parent_id; - }; - - using ActivityMap = std::unordered_map; - - const nub_process_t m_pid; - os_activity_stream_t m_activity_stream; - DarwinLogEventVector m_events; - std::mutex m_events_mutex; - LogFilterChainSP m_filter_chain_sp; - - /// Mutex to protect activity info (activity name and parent structures) - mutable std::mutex m_activity_info_mutex; - /// Map of activity id to ActivityInfo - ActivityMap m_activity_map; -}; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGCOLLECTOR_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogCollector.cpp +++ /dev/null @@ -1,699 +0,0 @@ -//===-- DarwinLogCollector.cpp ----------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "DarwinLogCollector.h" -#include "ActivityStreamSPI.h" - -#include - -#include -#include -#include -#include - -#include "DNB.h" -#include "DNBLog.h" -#include "DarwinLogTypes.h" -#include "LogFilterChain.h" -#include "LogFilterExactMatch.h" -#include "LogFilterRegex.h" -#include "LogMessageOsLog.h" -#include "MachProcess.h" -#include "RNBContext.h" -#include "RNBDefs.h" -#include "RNBRemote.h" - -// Use an anonymous namespace for variables and methods that have no -// reason to leak out through the interface. -namespace { -/// Specify max depth that the activity parent-child chain will search -/// back to get the full activity chain name. If we do more than this, -/// we assume either we hit a loop or it's just too long. -static const size_t MAX_ACTIVITY_CHAIN_DEPTH = 10; - -// Used to tap into and retrieve logs from target process. -// (Consumer of os_log). -static os_activity_stream_for_pid_t s_os_activity_stream_for_pid; -static os_activity_stream_resume_t s_os_activity_stream_resume; -static os_activity_stream_cancel_t s_os_activity_stream_cancel; -static os_log_copy_formatted_message_t s_os_log_copy_formatted_message; -static os_activity_stream_set_event_handler_t - s_os_activity_stream_set_event_handler; - -bool LookupSPICalls() { - static std::once_flag s_once_flag; - static bool s_has_spi; - - std::call_once(s_once_flag, [] { - dlopen ("/System/Library/PrivateFrameworks/LoggingSupport.framework/LoggingSupport", RTLD_NOW); - s_os_activity_stream_for_pid = (os_activity_stream_for_pid_t)dlsym( - RTLD_DEFAULT, "os_activity_stream_for_pid"); - s_os_activity_stream_resume = (os_activity_stream_resume_t)dlsym( - RTLD_DEFAULT, "os_activity_stream_resume"); - s_os_activity_stream_cancel = (os_activity_stream_cancel_t)dlsym( - RTLD_DEFAULT, "os_activity_stream_cancel"); - s_os_log_copy_formatted_message = (os_log_copy_formatted_message_t)dlsym( - RTLD_DEFAULT, "os_log_copy_formatted_message"); - s_os_activity_stream_set_event_handler = - (os_activity_stream_set_event_handler_t)dlsym( - RTLD_DEFAULT, "os_activity_stream_set_event_handler"); - - // We'll indicate we're all set if every function entry point - // was found. - s_has_spi = (s_os_activity_stream_for_pid != nullptr) && - (s_os_activity_stream_resume != nullptr) && - (s_os_activity_stream_cancel != nullptr) && - (s_os_log_copy_formatted_message != nullptr) && - (s_os_activity_stream_set_event_handler != nullptr); - if (s_has_spi) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Found os_log SPI calls."); - // Tell LogMessageOsLog how to format messages when search - // criteria requires it. - LogMessageOsLog::SetFormatterFunction(s_os_log_copy_formatted_message); - } else { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Failed to find os_log SPI " - "calls."); - } - }); - - return s_has_spi; -} - -using Mutex = std::mutex; -static Mutex s_collector_mutex; -static std::vector s_collectors; - -static void TrackCollector(const DarwinLogCollectorSP &collector_sp) { - std::lock_guard locker(s_collector_mutex); - if (std::find(s_collectors.begin(), s_collectors.end(), collector_sp) != - s_collectors.end()) { - DNBLogThreadedIf(LOG_DARWIN_LOG, - "attempted to add same collector multiple times"); - return; - } - s_collectors.push_back(collector_sp); -} - -static void StopTrackingCollector(const DarwinLogCollectorSP &collector_sp) { - std::lock_guard locker(s_collector_mutex); - s_collectors.erase( - std::remove(s_collectors.begin(), s_collectors.end(), collector_sp), - s_collectors.end()); -} - -static DarwinLogCollectorSP FindCollectorForProcess(pid_t pid) { - std::lock_guard locker(s_collector_mutex); - for (const auto &collector_sp : s_collectors) { - if (collector_sp && (collector_sp->GetProcessID() == pid)) - return collector_sp; - } - return DarwinLogCollectorSP(); -} - -static FilterTarget TargetStringToEnum(const std::string &filter_target_name) { - if (filter_target_name == "activity") - return eFilterTargetActivity; - else if (filter_target_name == "activity-chain") - return eFilterTargetActivityChain; - else if (filter_target_name == "category") - return eFilterTargetCategory; - else if (filter_target_name == "message") - return eFilterTargetMessage; - else if (filter_target_name == "subsystem") - return eFilterTargetSubsystem; - else - return eFilterTargetInvalid; -} - -class Configuration { -public: - Configuration(const JSONObject &config) - : m_is_valid(false), - m_activity_stream_flags(OS_ACTIVITY_STREAM_PROCESS_ONLY), - m_filter_chain_sp(nullptr) { - // Parse out activity stream flags - if (!ParseSourceFlags(config)) { - m_is_valid = false; - return; - } - - // Parse filter rules - if (!ParseFilterRules(config)) { - m_is_valid = false; - return; - } - - // Everything worked. - m_is_valid = true; - } - - bool ParseSourceFlags(const JSONObject &config) { - // Get the source-flags dictionary. - auto source_flags_sp = config.GetObject("source-flags"); - if (!source_flags_sp) - return false; - if (!JSONObject::classof(source_flags_sp.get())) - return false; - - const JSONObject &source_flags = - *static_cast(source_flags_sp.get()); - - // Parse out the flags. - bool include_any_process = false; - bool include_callstacks = false; - bool include_info_level = false; - bool include_debug_level = false; - bool live_stream = false; - - if (!source_flags.GetObjectAsBool("any-process", include_any_process)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Source-flag 'any-process' missing from " - "configuration."); - return false; - } - if (!source_flags.GetObjectAsBool("callstacks", include_callstacks)) { - // We currently suppress the availability of this on the lldb - // side. We include here for devices when we enable in the - // future. - // DNBLogThreadedIf(LOG_DARWIN_LOG, - // "Source-flag 'callstacks' missing from " - // "configuration."); - - // OK. We just skip callstacks. - // return false; - } - if (!source_flags.GetObjectAsBool("info-level", include_info_level)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Source-flag 'info-level' missing from " - "configuration."); - return false; - } - if (!source_flags.GetObjectAsBool("debug-level", include_debug_level)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Source-flag 'debug-level' missing from " - "configuration."); - return false; - } - if (!source_flags.GetObjectAsBool("live-stream", live_stream)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Source-flag 'live-stream' missing from " - "configuration."); - return false; - } - - // Setup the SPI flags based on this. - m_activity_stream_flags = 0; - if (!include_any_process) - m_activity_stream_flags |= OS_ACTIVITY_STREAM_PROCESS_ONLY; - if (include_callstacks) - m_activity_stream_flags |= OS_ACTIVITY_STREAM_CALLSTACK; - if (include_info_level) - m_activity_stream_flags |= OS_ACTIVITY_STREAM_INFO; - if (include_debug_level) - m_activity_stream_flags |= OS_ACTIVITY_STREAM_DEBUG; - if (!live_stream) - m_activity_stream_flags |= OS_ACTIVITY_STREAM_BUFFERED; - - DNBLogThreadedIf(LOG_DARWIN_LOG, "m_activity_stream_flags = 0x%03x", - m_activity_stream_flags); - - return true; - } - - bool ParseFilterRules(const JSONObject &config) { - // Retrieve the default rule. - bool filter_default_accept = true; - if (!config.GetObjectAsBool("filter-fall-through-accepts", - filter_default_accept)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Setting 'filter-fall-through-accepts' " - "missing from configuration."); - return false; - } - m_filter_chain_sp = std::make_shared(filter_default_accept); - DNBLogThreadedIf(LOG_DARWIN_LOG, "DarwinLog no-match rule: %s.", - filter_default_accept ? "accept" : "reject"); - - // If we don't have the filter-rules array, we're done. - auto filter_rules_sp = config.GetObject("filter-rules"); - if (!filter_rules_sp) { - DNBLogThreadedIf(LOG_DARWIN_LOG, - "No 'filter-rules' config element, all log " - "entries will use the no-match action (%s).", - filter_default_accept ? "accept" : "reject"); - return true; - } - if (!JSONArray::classof(filter_rules_sp.get())) - return false; - const JSONArray &rules_config = - *static_cast(filter_rules_sp.get()); - - // Create the filters. - for (auto &rule_sp : rules_config.m_elements) { - if (!JSONObject::classof(rule_sp.get())) - return false; - const JSONObject &rule_config = *static_cast(rule_sp.get()); - - // Get whether this filter accepts or rejects. - bool filter_accepts = true; - if (!rule_config.GetObjectAsBool("accept", filter_accepts)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Filter 'accept' element missing."); - return false; - } - - // Grab the target log field attribute for the match. - std::string target_attribute; - if (!rule_config.GetObjectAsString("attribute", target_attribute)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Filter 'attribute' element missing."); - return false; - } - auto target_enum = TargetStringToEnum(target_attribute); - if (target_enum == eFilterTargetInvalid) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Filter attribute '%s' unsupported.", - target_attribute.c_str()); - return false; - } - - // Handle operation-specific fields and filter creation. - std::string filter_type; - if (!rule_config.GetObjectAsString("type", filter_type)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "Filter 'type' element missing."); - return false; - } - DNBLogThreadedIf(LOG_DARWIN_LOG, "Reading filter of type '%s'", - filter_type.c_str()); - - LogFilterSP filter_sp; - if (filter_type == "regex") { - // Grab the regex for the match. - std::string regex; - if (!rule_config.GetObjectAsString("regex", regex)) { - DNBLogError("Regex filter missing 'regex' element."); - return false; - } - DNBLogThreadedIf(LOG_DARWIN_LOG, "regex for filter: \"%s\"", - regex.c_str()); - - // Create the regex filter. - auto regex_filter = - new LogFilterRegex(filter_accepts, target_enum, regex); - filter_sp.reset(regex_filter); - - // Validate that the filter is okay. - if (!regex_filter->IsValid()) { - DNBLogError("Invalid regex in filter: " - "regex=\"%s\", error=%s", - regex.c_str(), regex_filter->GetErrorAsCString()); - return false; - } - } else if (filter_type == "match") { - // Grab the regex for the match. - std::string exact_text; - if (!rule_config.GetObjectAsString("exact_text", exact_text)) { - DNBLogError("Exact match filter missing " - "'exact_text' element."); - return false; - } - - // Create the filter. - filter_sp = std::make_shared( - filter_accepts, target_enum, exact_text); - } - - // Add the filter to the chain. - m_filter_chain_sp->AppendFilter(filter_sp); - } - return true; - } - - bool IsValid() const { return m_is_valid; } - - os_activity_stream_flag_t GetActivityStreamFlags() const { - return m_activity_stream_flags; - } - - const LogFilterChainSP &GetLogFilterChain() const { - return m_filter_chain_sp; - } - -private: - bool m_is_valid; - os_activity_stream_flag_t m_activity_stream_flags; - LogFilterChainSP m_filter_chain_sp; -}; -} - -bool DarwinLogCollector::IsSupported() { - // We're supported if we have successfully looked up the SPI entry points. - return LookupSPICalls(); -} - -bool DarwinLogCollector::StartCollectingForProcess(nub_process_t pid, - const JSONObject &config) { - // If we're currently collecting for this process, kill the existing - // collector. - if (CancelStreamForProcess(pid)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, - "%s() killed existing DarwinLog collector for pid %d.", - __FUNCTION__, pid); - } - - // If the process isn't alive, we're done. - if (!DNBProcessIsAlive(pid)) { - DNBLogThreadedIf(LOG_DARWIN_LOG, - "%s() cannot collect for pid %d: process not alive.", - __FUNCTION__, pid); - return false; - } - - // Validate the configuration. - auto spi_config = Configuration(config); - if (!spi_config.IsValid()) { - DNBLogThreadedIf(LOG_DARWIN_LOG, - "%s() invalid configuration, will not enable log " - "collection", - __FUNCTION__); - return false; - } - - // Create the stream collector that will manage collected data - // for this pid. - DarwinLogCollectorSP collector_sp( - new DarwinLogCollector(pid, spi_config.GetLogFilterChain())); - std::weak_ptr collector_wp(collector_sp); - - // Setup the stream handling block. - os_activity_stream_block_t block = - ^bool(os_activity_stream_entry_t entry, int error) { - // Check if our collector is still alive. - DarwinLogCollectorSP inner_collector_sp = collector_wp.lock(); - if (!inner_collector_sp) - return false; - return inner_collector_sp->HandleStreamEntry(entry, error); - }; - - os_activity_stream_event_block_t stream_event_block = ^void( - os_activity_stream_t stream, os_activity_stream_event_t event) { - switch (event) { - case OS_ACTIVITY_STREAM_EVENT_STARTED: - DNBLogThreadedIf(LOG_DARWIN_LOG, - "received stream event: " - "OS_ACTIVITY_STREAM_EVENT_STARTED, stream %p.", - (void *)stream); - break; - case OS_ACTIVITY_STREAM_EVENT_STOPPED: - DNBLogThreadedIf(LOG_DARWIN_LOG, - "received stream event: " - "OS_ACTIVITY_STREAM_EVENT_STOPPED, stream %p.", - (void *)stream); - break; - case OS_ACTIVITY_STREAM_EVENT_FAILED: - DNBLogThreadedIf(LOG_DARWIN_LOG, - "received stream event: " - "OS_ACTIVITY_STREAM_EVENT_FAILED, stream %p.", - (void *)stream); - break; - case OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED: - DNBLogThreadedIf(LOG_DARWIN_LOG, - "received stream event: " - "OS_ACTIVITY_STREAM_EVENT_CHUNK_STARTED, stream %p.", - (void *)stream); - break; - case OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED: - DNBLogThreadedIf(LOG_DARWIN_LOG, - "received stream event: " - "OS_ACTIVITY_STREAM_EVENT_CHUNK_FINISHED, stream %p.", - (void *)stream); - break; - } - }; - - // Create the stream. - os_activity_stream_t activity_stream = (*s_os_activity_stream_for_pid)( - pid, spi_config.GetActivityStreamFlags(), block); - collector_sp->SetActivityStream(activity_stream); - - // Specify the stream-related event handler. - (*s_os_activity_stream_set_event_handler)(activity_stream, - stream_event_block); - - // Start the stream. - (*s_os_activity_stream_resume)(activity_stream); - - TrackCollector(collector_sp); - return true; -} - -DarwinLogEventVector -DarwinLogCollector::GetEventsForProcess(nub_process_t pid) { - auto collector_sp = FindCollectorForProcess(pid); - if (!collector_sp) { - // We're not tracking a stream for this process. - return DarwinLogEventVector(); - } - - return collector_sp->RemoveEvents(); -} - -bool DarwinLogCollector::CancelStreamForProcess(nub_process_t pid) { - auto collector_sp = FindCollectorForProcess(pid); - if (!collector_sp) { - // We're not tracking a stream for this process. - return false; - } - - collector_sp->CancelActivityStream(); - StopTrackingCollector(collector_sp); - - return true; -} - -const char * -DarwinLogCollector::GetActivityForID(os_activity_id_t activity_id) const { - auto find_it = m_activity_map.find(activity_id); - return (find_it != m_activity_map.end()) ? find_it->second.m_name.c_str() - : nullptr; -} - -/// Retrieve the full parent-child chain for activity names. These -/// can be arbitrarily deep. This method assumes the caller has already -/// locked the activity mutex. -void DarwinLogCollector::GetActivityChainForID_internal( - os_activity_id_t activity_id, std::string &result, size_t depth) const { - if (depth > MAX_ACTIVITY_CHAIN_DEPTH) { - // Terminating condition - too deeply nested. - return; - } else if (activity_id == 0) { - // Terminating condition - no activity. - return; - } - - auto find_it = m_activity_map.find(activity_id); - if (find_it == m_activity_map.end()) { - // Terminating condition - no data for activity_id. - return; - } - - // Activity name becomes parent activity name chain + ':' + our activity - // name. - GetActivityChainForID_internal(find_it->second.m_parent_id, result, - depth + 1); - if (!result.empty()) - result += ':'; - result += find_it->second.m_name; -} - -std::string -DarwinLogCollector::GetActivityChainForID(os_activity_id_t activity_id) const { - std::string result; - { - std::lock_guard locker(m_activity_info_mutex); - GetActivityChainForID_internal(activity_id, result, 1); - } - return result; -} - -DarwinLogCollector::DarwinLogCollector(nub_process_t pid, - const LogFilterChainSP &filter_chain_sp) - : ActivityStore(), m_pid(pid), m_activity_stream(0), m_events(), - m_events_mutex(), m_filter_chain_sp(filter_chain_sp), - m_activity_info_mutex(), m_activity_map() {} - -DarwinLogCollector::~DarwinLogCollector() { - // Cancel the stream. - if (m_activity_stream) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "tearing down activity stream " - "collector for %d", - m_pid); - (*s_os_activity_stream_cancel)(m_activity_stream); - m_activity_stream = 0; - } else { - DNBLogThreadedIf(LOG_DARWIN_LOG, "no stream to tear down for %d", m_pid); - } -} - -void DarwinLogCollector::SignalDataAvailable() { - RNBRemoteSP remoteSP(g_remoteSP); - if (!remoteSP) { - // We're done. This is unexpected. - StopTrackingCollector(shared_from_this()); - return; - } - - RNBContext &ctx = remoteSP->Context(); - ctx.Events().SetEvents(RNBContext::event_darwin_log_data_available); - // Wait for the main thread to consume this notification if it requested - // we wait for it. - ctx.Events().WaitForResetAck(RNBContext::event_darwin_log_data_available); -} - -void DarwinLogCollector::SetActivityStream( - os_activity_stream_t activity_stream) { - m_activity_stream = activity_stream; -} - -bool DarwinLogCollector::HandleStreamEntry(os_activity_stream_entry_t entry, - int error) { - if ((error == 0) && (entry != nullptr)) { - if (entry->pid != m_pid) { - // For now, skip messages not originating from our process. - // Later we might want to keep all messages related to an event - // that we're tracking, even when it came from another process, - // possibly doing work on our behalf. - return true; - } - - switch (entry->type) { - case OS_ACTIVITY_STREAM_TYPE_ACTIVITY_CREATE: - DNBLogThreadedIf( - LOG_DARWIN_LOG, "received activity create: " - "%s, creator aid %" PRIu64 ", unique_pid %" PRIu64 - "(activity id=%" PRIu64 ", parent id=%" PRIu64 ")", - entry->activity_create.name, entry->activity_create.creator_aid, - entry->activity_create.unique_pid, entry->activity_id, - entry->parent_id); - { - std::lock_guard locker(m_activity_info_mutex); - m_activity_map.insert( - std::make_pair(entry->activity_id, - ActivityInfo(entry->activity_create.name, - entry->activity_id, entry->parent_id))); - } - break; - - case OS_ACTIVITY_STREAM_TYPE_ACTIVITY_TRANSITION: - DNBLogThreadedIf( - LOG_DARWIN_LOG, "received activity transition:" - "new aid: %" PRIu64 "(activity id=%" PRIu64 - ", parent id=%" PRIu64 ", tid %" PRIu64 ")", - entry->activity_transition.transition_id, entry->activity_id, - entry->parent_id, entry->activity_transition.thread); - break; - - case OS_ACTIVITY_STREAM_TYPE_LOG_MESSAGE: { - DNBLogThreadedIf( - LOG_DARWIN_LOG, "received log message: " - "(activity id=%" PRIu64 ", parent id=%" PRIu64 ", " - "tid %" PRIu64 "): format %s", - entry->activity_id, entry->parent_id, entry->log_message.thread, - entry->log_message.format ? entry->log_message.format - : ""); - - // Do the real work here. - { - // Ensure our process is still alive. If not, we can - // cancel the collection. - if (!DNBProcessIsAlive(m_pid)) { - // We're outta here. This is the manner in which we - // stop collecting for a process. - StopTrackingCollector(shared_from_this()); - return false; - } - - LogMessageOsLog os_log_message(*this, *entry); - if (!m_filter_chain_sp || - !m_filter_chain_sp->GetAcceptMessage(os_log_message)) { - // This log message was rejected by the filter, - // so stop processing it now. - return true; - } - - // Copy over the relevant bits from the message. - const struct os_log_message_s &log_message = entry->log_message; - - DarwinLogEventSP message_sp(new DarwinLogEvent()); - // Indicate this event is a log message event. - message_sp->AddStringItem("type", "log"); - - // Add the message contents (fully expanded). - // Consider expanding on the remote side. - // Then we don't pay for expansion until when it is - // used. - const char *message_text = os_log_message.GetMessage(); - if (message_text) - message_sp->AddStringItem("message", message_text); - - // Add some useful data fields. - message_sp->AddIntegerItem("timestamp", log_message.timestamp); - - // Do we want to do all activity name resolution on this - // side? Maybe. For now, send IDs and ID->name mappings - // and fix this up on that side. Later, when we add - // debugserver-side filtering, we'll want to get the - // activity names over here, so we should probably - // just send them as resolved strings. - message_sp->AddIntegerItem("activity_id", entry->activity_id); - message_sp->AddIntegerItem("parent_id", entry->parent_id); - message_sp->AddIntegerItem("thread_id", log_message.thread); - if (log_message.subsystem && strlen(log_message.subsystem) > 0) - message_sp->AddStringItem("subsystem", log_message.subsystem); - if (log_message.category && strlen(log_message.category) > 0) - message_sp->AddStringItem("category", log_message.category); - if (entry->activity_id != 0) { - std::string activity_chain = - GetActivityChainForID(entry->activity_id); - if (!activity_chain.empty()) - message_sp->AddStringItem("activity-chain", activity_chain); - } - - // Add it to the list for later collection. - { - std::lock_guard locker(m_events_mutex); - m_events.push_back(message_sp); - } - SignalDataAvailable(); - } - break; - } - } - } else { - DNBLogThreadedIf(LOG_DARWIN_LOG, "HandleStreamEntry: final call, " - "error %d", - error); - } - return true; -} - -DarwinLogEventVector DarwinLogCollector::RemoveEvents() { - DarwinLogEventVector returned_events; - { - std::lock_guard locker(m_events_mutex); - returned_events.swap(m_events); - } - DNBLogThreadedIf(LOG_DARWIN_LOG, "DarwinLogCollector::%s(): removing %lu " - "queued log entries", - __FUNCTION__, returned_events.size()); - return returned_events; -} - -void DarwinLogCollector::CancelActivityStream() { - if (!m_activity_stream) - return; - - DNBLogThreadedIf(LOG_DARWIN_LOG, - "DarwinLogCollector::%s(): canceling " - "activity stream %p", - __FUNCTION__, static_cast(m_activity_stream)); - (*s_os_activity_stream_cancel)(m_activity_stream); - m_activity_stream = nullptr; -} diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogEvent.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogEvent.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogEvent.h +++ /dev/null @@ -1,26 +0,0 @@ -//===-- DarwinLogEvent.h ----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGEVENT_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGEVENT_H - -#include -#include - -#include "JSONGenerator.h" - -// ============================================================================= -/// Each discrete unit of information is described as an event, such as -/// the emission of a single log message. -// ============================================================================= - -using DarwinLogEvent = JSONGenerator::Dictionary; -using DarwinLogEventSP = std::shared_ptr; -using DarwinLogEventVector = std::vector; - -#endif diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogInterfaces.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogInterfaces.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogInterfaces.h +++ /dev/null @@ -1,24 +0,0 @@ -//===-- DarwinLogInterfaces.h -----------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGINTERFACES_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGINTERFACES_H - -#include - -class ActivityStore; - -class LogFilter; -using LogFilterSP = std::shared_ptr; - -class LogFilterChain; -using LogFilterChainSP = std::shared_ptr; - -class LogMessage; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGINTERFACES_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/DarwinLogTypes.h +++ /dev/null @@ -1,21 +0,0 @@ -//===-- DarwinLogTypes.h ----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGTYPES_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGTYPES_H - -enum FilterTarget { - eFilterTargetInvalid, - eFilterTargetActivity, - eFilterTargetActivityChain, - eFilterTargetCategory, - eFilterTargetMessage, - eFilterTargetSubsystem -}; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_DARWINLOGTYPES_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.h +++ /dev/null @@ -1,29 +0,0 @@ -//===-- LogFilter.h ---------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTER_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTER_H - -#include "DarwinLogInterfaces.h" - -class LogFilter { -public: - virtual ~LogFilter(); - - virtual bool DoesMatch(const LogMessage &message) const = 0; - - bool MatchesAreAccepted() const { return m_matches_accept; } - -protected: - LogFilter(bool matches_accept) : m_matches_accept(matches_accept) {} - -private: - bool m_matches_accept; -}; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTER_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilter.cpp +++ /dev/null @@ -1,11 +0,0 @@ -//===-- LogFilter.cpp -------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "LogFilter.h" - -LogFilter::~LogFilter() {} diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.h +++ /dev/null @@ -1,37 +0,0 @@ -//===-- LogFilterChain.h ----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTERCHAIN_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTERCHAIN_H - -#include - -#include "DarwinLogInterfaces.h" - -class LogFilterChain { -public: - LogFilterChain(bool default_accept); - - void AppendFilter(const LogFilterSP &filter_sp); - - void ClearFilterChain(); - - bool GetDefaultAccepts() const; - - void SetDefaultAccepts(bool default_accepts); - - bool GetAcceptMessage(const LogMessage &message) const; - -private: - using FilterVector = std::vector; - - FilterVector m_filters; - bool m_default_accept; -}; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTERCHAIN_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterChain.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===-- LogFilterChain.cpp --------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "LogFilterChain.h" - -#include "LogFilter.h" - -LogFilterChain::LogFilterChain(bool default_accept) - : m_filters(), m_default_accept(default_accept) {} - -void LogFilterChain::AppendFilter(const LogFilterSP &filter_sp) { - if (filter_sp) - m_filters.push_back(filter_sp); -} - -void LogFilterChain::ClearFilterChain() { m_filters.clear(); } - -bool LogFilterChain::GetDefaultAccepts() const { return m_default_accept; } - -void LogFilterChain::SetDefaultAccepts(bool default_accept) { - m_default_accept = default_accept; -} - -bool LogFilterChain::GetAcceptMessage(const LogMessage &message) const { - for (auto filter_sp : m_filters) { - if (filter_sp->DoesMatch(message)) { - // This message matches this filter. If the filter accepts matches, - // this message matches; otherwise, it rejects matches. - return filter_sp->MatchesAreAccepted(); - } - } - - // None of the filters matched. Therefore, we do whatever the - // default fall-through rule says. - return m_default_accept; -} diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.h +++ /dev/null @@ -1,30 +0,0 @@ -//===-- LogFilterExactMatch.h -----------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTEREXACTMATCH_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTEREXACTMATCH_H - -#include - -#include "DarwinLogInterfaces.h" -#include "DarwinLogTypes.h" -#include "LogFilter.h" - -class LogFilterExactMatch : public LogFilter { -public: - LogFilterExactMatch(bool match_accepts, FilterTarget filter_target, - const std::string &match_text); - - bool DoesMatch(const LogMessage &message) const override; - -private: - const FilterTarget m_filter_target; - const std::string m_match_text; -}; - -#endif diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterExactMatch.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//===-- LogFilterExactMatch.cpp ---------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "LogFilterExactMatch.h" -#include "LogMessage.h" - -LogFilterExactMatch::LogFilterExactMatch(bool match_accepts, - FilterTarget filter_target, - const std::string &match_text) - : LogFilter(match_accepts), m_filter_target(filter_target), - m_match_text(match_text) {} - -bool LogFilterExactMatch::DoesMatch(const LogMessage &message) const { - switch (m_filter_target) { - case eFilterTargetActivity: - // Empty fields never match a condition. - if (!message.HasActivity()) - return false; - return m_match_text == message.GetActivity(); - case eFilterTargetActivityChain: - // Empty fields never match a condition. - if (!message.HasActivity()) - return false; - return m_match_text == message.GetActivityChain(); - case eFilterTargetCategory: - // Empty fields never match a condition. - if (!message.HasCategory()) - return false; - return m_match_text == message.GetCategory(); - case eFilterTargetMessage: { - const char *message_text = message.GetMessage(); - return (message_text != nullptr) && (m_match_text == message_text); - } - case eFilterTargetSubsystem: - // Empty fields never match a condition. - if (!message.HasSubsystem()) - return false; - return m_match_text == message.GetSubsystem(); - default: - // We don't know this type. - return false; - } -} diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.h +++ /dev/null @@ -1,43 +0,0 @@ -//===-- LogFilterRegex.h ----------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTERREGEX_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTERREGEX_H - -// C includes -#include - -// C++ includes -#include - -#include "DarwinLogInterfaces.h" -#include "DarwinLogTypes.h" -#include "LogFilter.h" - -class LogFilterRegex : public LogFilter { -public: - LogFilterRegex(bool match_accepts, FilterTarget filter_target, - const std::string ®ex); - - virtual ~LogFilterRegex(); - - bool IsValid() const { return m_is_valid; } - - const char *GetErrorAsCString() const { return m_error_text.c_str(); } - - bool DoesMatch(const LogMessage &message) const override; - -private: - const FilterTarget m_filter_target; - const std::string m_regex_text; - regex_t m_regex; - bool m_is_valid; - std::string m_error_text; -}; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGFILTERREGEX_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogFilterRegex.cpp +++ /dev/null @@ -1,94 +0,0 @@ -//===-- LogFilterRegex.cpp --------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "LogFilterRegex.h" - -#include "DNBLog.h" -#include "LogMessage.h" - -// Enable enhanced mode if it is available. This allows for things like -// \d for digit, \s for space, and many more, but it isn't available -// everywhere. -#if defined(REG_ENHANCED) -#define DEFAULT_COMPILE_FLAGS (REG_ENHANCED | REG_EXTENDED) -#else -#define DEFAULT_COMPILE_FLAGS (REG_EXTENDED) -#endif - -LogFilterRegex::LogFilterRegex(bool match_accepts, FilterTarget filter_target, - const std::string ®ex) - : LogFilter(match_accepts), m_filter_target(filter_target), - m_regex_text(regex), m_regex(), m_is_valid(false), m_error_text() { - // Clear it. - memset(&m_regex, 0, sizeof(m_regex)); - - // Compile it. - if (!regex.empty()) { - auto comp_err = ::regcomp(&m_regex, regex.c_str(), DEFAULT_COMPILE_FLAGS); - m_is_valid = (comp_err == 0); - if (!m_is_valid) { - char buffer[256]; - buffer[0] = '\0'; - ::regerror(comp_err, &m_regex, buffer, sizeof(buffer)); - m_error_text = buffer; - } - } -} - -LogFilterRegex::~LogFilterRegex() { - if (m_is_valid) { - // Free the regex internals. - regfree(&m_regex); - } -} - -bool LogFilterRegex::DoesMatch(const LogMessage &message) const { - switch (m_filter_target) { - case eFilterTargetActivity: - // Empty fields never match a condition. - if (!message.HasActivity()) - return false; - return ::regexec(&m_regex, message.GetActivity(), 0, nullptr, 0) == 0; - case eFilterTargetActivityChain: - // Empty fields never match a condition. - if (!message.HasActivity()) - return false; - return ::regexec(&m_regex, message.GetActivityChain().c_str(), 0, nullptr, - 0) == 0; - case eFilterTargetCategory: - // Empty fields never match a condition. - if (!message.HasCategory()) - return false; - return ::regexec(&m_regex, message.GetCategory(), 0, nullptr, 0) == 0; - case eFilterTargetMessage: { - const char *message_text = message.GetMessage(); - if (!message_text) { - DNBLogThreadedIf(LOG_DARWIN_LOG, - "LogFilterRegex: regex " - "\"%s\" no match due to nullptr message.", - m_regex_text.c_str()); - return false; - } - - bool match = ::regexec(&m_regex, message_text, 0, nullptr, 0) == 0; - DNBLogThreadedIf(LOG_DARWIN_LOG, "LogFilterRegex: regex " - "\"%s\" %s message \"%s\".", - m_regex_text.c_str(), match ? "matches" : "does not match", - message_text); - return match; - } - case eFilterTargetSubsystem: - // Empty fields never match a condition. - if (!message.HasSubsystem()) - return false; - return ::regexec(&m_regex, message.GetSubsystem(), 0, nullptr, 0) == 0; - default: - // We don't know this type. - return false; - } -} diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.h +++ /dev/null @@ -1,39 +0,0 @@ -//===-- LogMessage.h --------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGMESSAGE_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGMESSAGE_H - -#include - -class LogMessage { -public: - virtual ~LogMessage(); - - virtual bool HasActivity() const = 0; - - virtual const char *GetActivity() const = 0; - - virtual std::string GetActivityChain() const = 0; - - virtual bool HasCategory() const = 0; - - virtual const char *GetCategory() const = 0; - - virtual bool HasSubsystem() const = 0; - - virtual const char *GetSubsystem() const = 0; - - // This can be expensive, so once we ask for it, we'll cache the result. - virtual const char *GetMessage() const = 0; - -protected: - LogMessage(); -}; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGMESSAGE_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessage.cpp +++ /dev/null @@ -1,13 +0,0 @@ -//===-- LogMessage.cpp ------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "LogMessage.h" - -LogMessage::LogMessage() {} - -LogMessage::~LogMessage() {} diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.h +++ /dev/null @@ -1,56 +0,0 @@ -//===-- LogMessageOsLog.h ---------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGMESSAGEOSLOG_H -#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGMESSAGEOSLOG_H - -#include "DarwinLogInterfaces.h" - -#include "ActivityStreamSPI.h" -#include "LogMessage.h" - -using ActivityStreamEntry = struct os_activity_stream_entry_s; - -/// Provides a unified wrapper around os_log()-style log messages. -/// -/// The lifetime of this class is intended to be very short. The caller -/// must ensure that the passed in ActivityStore and ActivityStreamEntry -/// outlive this LogMessageOsLog entry. - -class LogMessageOsLog : public LogMessage { -public: - static void SetFormatterFunction(os_log_copy_formatted_message_t format_func); - - LogMessageOsLog(const ActivityStore &activity_store, - ActivityStreamEntry &entry); - - // API methods - - bool HasActivity() const override; - - const char *GetActivity() const override; - - std::string GetActivityChain() const override; - - bool HasCategory() const override; - - const char *GetCategory() const override; - - bool HasSubsystem() const override; - - const char *GetSubsystem() const override; - - const char *GetMessage() const override; - -private: - const ActivityStore &m_activity_store; - ActivityStreamEntry &m_entry; - mutable std::string m_message; -}; - -#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_DARWINLOG_LOGMESSAGEOSLOG_H diff --git a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp b/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp deleted file mode 100644 --- a/lldb/tools/debugserver/source/MacOSX/DarwinLog/LogMessageOsLog.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===-- LogMessageOsLog.cpp -------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "LogMessageOsLog.h" - -#include "ActivityStore.h" -#include "ActivityStreamSPI.h" - -namespace { -static os_log_copy_formatted_message_t s_log_copy_formatted_message; -} - -void LogMessageOsLog::SetFormatterFunction( - os_log_copy_formatted_message_t format_func) { - s_log_copy_formatted_message = format_func; -} - -LogMessageOsLog::LogMessageOsLog(const ActivityStore &activity_store, - ActivityStreamEntry &entry) - : LogMessage(), m_activity_store(activity_store), m_entry(entry), - m_message() {} - -bool LogMessageOsLog::HasActivity() const { return m_entry.activity_id != 0; } - -const char *LogMessageOsLog::GetActivity() const { - return m_activity_store.GetActivityForID(m_entry.activity_id); -} - -std::string LogMessageOsLog::GetActivityChain() const { - return m_activity_store.GetActivityChainForID(m_entry.activity_id); -} - -bool LogMessageOsLog::HasCategory() const { - return m_entry.log_message.category && (m_entry.log_message.category[0] != 0); -} - -const char *LogMessageOsLog::GetCategory() const { - return m_entry.log_message.category; -} - -bool LogMessageOsLog::HasSubsystem() const { - return m_entry.log_message.subsystem && - (m_entry.log_message.subsystem[0] != 0); -} - -const char *LogMessageOsLog::GetSubsystem() const { - return m_entry.log_message.subsystem; -} - -const char *LogMessageOsLog::GetMessage() const { - if (m_message.empty()) { - std::unique_ptr formatted_message( - s_log_copy_formatted_message(&m_entry.log_message)); - if (formatted_message) - m_message = formatted_message.get(); - // else - // TODO log - } - - // This is safe to return as we're not modifying it once we've formatted it. - return m_message.c_str(); -} diff --git a/lldb/tools/debugserver/source/RNBContext.h b/lldb/tools/debugserver/source/RNBContext.h --- a/lldb/tools/debugserver/source/RNBContext.h +++ b/lldb/tools/debugserver/source/RNBContext.h @@ -30,13 +30,11 @@ event_read_packet_available = 0x020, event_read_thread_running = 0x040, // Sticky event_read_thread_exiting = 0x080, - event_darwin_log_data_available = 0x100, normal_event_bits = event_proc_state_changed | event_proc_thread_exiting | event_proc_stdio_available | event_proc_profile_data | event_read_packet_available | - event_read_thread_exiting | - event_darwin_log_data_available, + event_read_thread_exiting , sticky_event_bits = event_proc_thread_running | event_read_thread_running, diff --git a/lldb/tools/debugserver/source/RNBContext.cpp b/lldb/tools/debugserver/source/RNBContext.cpp --- a/lldb/tools/debugserver/source/RNBContext.cpp +++ b/lldb/tools/debugserver/source/RNBContext.cpp @@ -258,8 +258,6 @@ s += "proc_stdio_available "; if (events & event_proc_profile_data) s += "proc_profile_data "; - if (events & event_darwin_log_data_available) - s += "darwin_log_data_available "; if (events & event_read_packet_available) s += "read_packet_available "; if (events & event_read_thread_running) diff --git a/lldb/tools/debugserver/source/RNBRemote.h b/lldb/tools/debugserver/source/RNBRemote.h --- a/lldb/tools/debugserver/source/RNBRemote.h +++ b/lldb/tools/debugserver/source/RNBRemote.h @@ -135,8 +135,6 @@ speed_test, // 'qSpeedTest:' set_detach_on_error, // 'QSetDetachOnError:' query_transfer, // 'qXfer:' - query_supported_async_json_packets, // 'QSupportedAsyncJSONPackets' - configure_darwin_log, // 'ConfigureDarwinLog:' unknown_type }; @@ -246,9 +244,6 @@ rnb_err_t HandlePacket_qXfer(const char *p); rnb_err_t HandlePacket_stop_process(const char *p); rnb_err_t HandlePacket_QSetDetachOnError(const char *p); - rnb_err_t HandlePacket_qStructuredDataPlugins(const char *p); - rnb_err_t HandlePacket_QConfigureDarwinLog(const char *p); - rnb_err_t SendStopReplyPacketForThread(nub_thread_t tid); rnb_err_t SendHexEncodedBytePacket(const char *header, const void *buf, size_t buf_len, const char *footer); @@ -257,7 +252,6 @@ void FlushSTDIO(); void SendAsyncProfileData(); rnb_err_t SendAsyncProfileDataPacket(char *buf, nub_size_t buf_size); - void SendAsyncDarwinLogData(); rnb_err_t SendAsyncJSONPacket(const JSONGenerator::Dictionary &dictionary); RNBContext &Context() { return m_ctx; } diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp --- a/lldb/tools/debugserver/source/RNBRemote.cpp +++ b/lldb/tools/debugserver/source/RNBRemote.cpp @@ -35,8 +35,6 @@ #include "DNBDataRef.h" #include "DNBLog.h" #include "DNBThreadResumeActions.h" -#include "DarwinLogCollector.h" -#include "DarwinLogEvent.h" #include "JSON.h" #include "JSONGenerator.h" #include "JSONGenerator.h" @@ -62,8 +60,6 @@ static const std::string OS_LOG_EVENTS_KEY_NAME("events"); static const std::string JSON_ASYNC_TYPE_KEY_NAME("type"); -static const DarwinLogEventVector::size_type DARWIN_LOG_MAX_EVENTS_PER_PACKET = - 10; // std::iostream formatting macros #define RAW_HEXBASE std::setfill('0') << std::hex << std::right @@ -499,15 +495,6 @@ "Test the maximum speed at which packet can be sent/received.")); t.push_back(Packet(query_transfer, &RNBRemote::HandlePacket_qXfer, NULL, "qXfer:", "Support the qXfer packet.")); - t.push_back( - Packet(query_supported_async_json_packets, - &RNBRemote::HandlePacket_qStructuredDataPlugins, NULL, - "qStructuredDataPlugins", - "Query for the structured data plugins supported by the remote.")); - t.push_back( - Packet(configure_darwin_log, &RNBRemote::HandlePacket_QConfigureDarwinLog, - NULL, "QConfigureDarwinLog:", - "Configure the DarwinLog structured data plugin support.")); } void RNBRemote::FlushSTDIO() { @@ -545,77 +532,6 @@ } } -void RNBRemote::SendAsyncDarwinLogData() { - DNBLogThreadedIf(LOG_DARWIN_LOG, "RNBRemote::%s(): enter", __FUNCTION__); - - if (!m_ctx.HasValidProcessID()) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "RNBRemote::%s(): ignoring due to" - "invalid process id", - __FUNCTION__); - return; - } - - nub_process_t pid = m_ctx.ProcessID(); - DarwinLogEventVector::size_type entry_count = 0; - - // NOTE: the current looping structure here does nothing - // to guarantee that we can send off async packets faster - // than we generate them. It will keep sending as long - // as there's data to send. - do { - DarwinLogEventVector events = DNBProcessGetAvailableDarwinLogEvents(pid); - entry_count = events.size(); - - DNBLogThreadedIf(LOG_DARWIN_LOG, "RNBRemote::%s(): outer loop enter", - __FUNCTION__); - - for (DarwinLogEventVector::size_type base_entry = 0; - base_entry < entry_count; - base_entry += DARWIN_LOG_MAX_EVENTS_PER_PACKET) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "RNBRemote::%s(): inner loop enter", - __FUNCTION__); - - // We limit the total number of entries we pack - // into a single JSON async packet just so it - // doesn't get too large. - JSONGenerator::Dictionary async_dictionary; - - // Specify the type of the JSON async data we're sending. - async_dictionary.AddStringItem(JSON_ASYNC_TYPE_KEY_NAME, "DarwinLog"); - - // Create an array entry in the dictionary to hold all - // the events going in this packet. - JSONGenerator::ArraySP events_array(new JSONGenerator::Array()); - async_dictionary.AddItem(OS_LOG_EVENTS_KEY_NAME, events_array); - - // We bundle up to DARWIN_LOG_MAX_EVENTS_PER_PACKET events in - // a single packet. - const auto inner_loop_bound = - std::min(base_entry + DARWIN_LOG_MAX_EVENTS_PER_PACKET, entry_count); - for (DarwinLogEventVector::size_type i = base_entry; i < inner_loop_bound; - ++i) { - DNBLogThreadedIf(LOG_DARWIN_LOG, "RNBRemote::%s(): adding " - "entry index %lu to the JSON packet", - __FUNCTION__, i); - events_array->AddItem(events[i]); - } - - // Send off the packet. - DNBLogThreadedIf(LOG_DARWIN_LOG, "RNBRemote::%s(): sending JSON " - "packet, %lu entries remain", - __FUNCTION__, entry_count - inner_loop_bound); - SendAsyncJSONPacket(async_dictionary); - } - - DNBLogThreadedIf(LOG_DARWIN_LOG, "RNBRemote::%s(): outer loop exit", - __FUNCTION__); - - } while (entry_count > 0); - - DNBLogThreadedIf(LOG_DARWIN_LOG, "RNBRemote::%s(): exit", - __PRETTY_FUNCTION__); -} - rnb_err_t RNBRemote::SendHexEncodedBytePacket(const char *header, const void *buf, size_t buf_len, const char *footer) { @@ -2436,89 +2352,6 @@ return SendPacket("OK"); } -rnb_err_t RNBRemote::HandlePacket_qStructuredDataPlugins(const char *p) { - // We'll return a JSON array of supported packet types. - // The type is significant. For each of the supported - // packet types that have been enabled, there will be a - // 'J' async packet sent to the client with payload data. - // This payload data will be a JSON dictionary, and the - // top level dictionary will contain a string field with - // its value set to the relevant packet type from this list. - JSONGenerator::Array supported_json_packets; - - // Check for DarwinLog (libtrace os_log/activity support). - if (DarwinLogCollector::IsSupported()) - supported_json_packets.AddItem( - JSONGenerator::StringSP(new JSONGenerator::String("DarwinLog"))); - - // Send back the array. - std::ostringstream stream; - supported_json_packets.Dump(stream); - return SendPacket(stream.str()); -} - -rnb_err_t RNBRemote::HandlePacket_QConfigureDarwinLog(const char *p) { - if (!DarwinLogCollector::IsSupported()) { - // We should never have been given this request. - return SendPacket("E89"); - } - - // Ensure we have a process. We expect a separate configure request for - // each process launched/attached. - const nub_process_t pid = m_ctx.ProcessID(); - if (pid == INVALID_NUB_PROCESS) - return SendPacket("E94"); - - // Get the configuration dictionary. - p += strlen("QConfigureDarwinLog:"); - - // The configuration dictionary is binary encoded. - std::vector unescaped_config_data = decode_binary_data(p, -1); - std::string unescaped_config_string((const char *)&unescaped_config_data[0], - unescaped_config_data.size()); - DNBLogThreadedIf(LOG_DARWIN_LOG, "DarwinLog: received config data: \"%s\"", - unescaped_config_string.c_str()); - auto configuration_sp = - JSONParser(unescaped_config_string.c_str()).ParseJSONValue(); - if (!configuration_sp) { - // Malformed request - we require configuration data - // indicating whether we're enabling or disabling. - return SendPacket("E90"); - } - - if (!JSONObject::classof(configuration_sp.get())) { - // Configuration data is not of the right type. - return SendPacket("E91"); - } - JSONObject &config_dict = *static_cast(configuration_sp.get()); - - // Check if we're enabling or disabling. - auto enabled_sp = config_dict.GetObject("enabled"); - if (!enabled_sp) { - // Missing required "enabled" field. - return SendPacket("E92"); - } - if (!JSONTrue::classof(enabled_sp.get()) && - !JSONFalse::classof(enabled_sp.get())) { - // Should be a boolean type, but wasn't. - return SendPacket("E93"); - } - const bool enabling = JSONTrue::classof(enabled_sp.get()); - - // TODO - handle other configuration parameters here. - - // Shut down any active activity stream for the process. - DarwinLogCollector::CancelStreamForProcess(pid); - - if (enabling) { - // Look up the procecess. - if (!DarwinLogCollector::StartCollectingForProcess(pid, config_dict)) - return SendPacket("E95"); - } - - return SendPacket("OK"); -} - rnb_err_t RNBRemote::HandlePacket_QListThreadsInStopReply(const char *p) { // If this packet is received, it allows us to send an extra key/value // pair in the stop reply packets where we will list all of the thread IDs diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp --- a/lldb/tools/debugserver/source/debugserver.cpp +++ b/lldb/tools/debugserver/source/debugserver.cpp @@ -526,10 +526,6 @@ // packets event_mask &= ~RNBContext::event_proc_stdio_available; event_mask &= ~RNBContext::event_proc_profile_data; - // When we enable async structured data packets over another logical - // channel, - // this can be relaxed. - event_mask &= ~RNBContext::event_darwin_log_data_available; } // We want to make sure we consume all process state changes and have @@ -556,10 +552,6 @@ remote->SendAsyncProfileData(); } - if (set_events & RNBContext::event_darwin_log_data_available) { - remote->SendAsyncDarwinLogData(); - } - if (set_events & RNBContext::event_read_packet_available) { // handleReceivedPacket will take care of resetting the // event_read_packet_available events when there are no more...