LLDB mainline
StructuredDataDarwinLog.cpp
Go to the documentation of this file.
1//===-- StructuredDataDarwinLog.cpp ---------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11#include <cstring>
12
13#include <memory>
14#include <sstream>
15
17#include "lldb/Core/Debugger.h"
18#include "lldb/Core/Module.h"
28#include "lldb/Target/Process.h"
29#include "lldb/Target/Target.h"
32#include "lldb/Utility/Log.h"
34
35#include "llvm/ADT/StringMap.h"
36
37#define DARWIN_LOG_TYPE_VALUE "DarwinLog"
38
39using namespace lldb;
40using namespace lldb_private;
41
43
44#pragma mark -
45#pragma mark Anonymous Namespace
46
47// Anonymous namespace
48
50const uint64_t NANOS_PER_MICRO = 1000;
51const uint64_t NANOS_PER_MILLI = NANOS_PER_MICRO * 1000;
52const uint64_t NANOS_PER_SECOND = NANOS_PER_MILLI * 1000;
53const uint64_t NANOS_PER_MINUTE = NANOS_PER_SECOND * 60;
54const uint64_t NANOS_PER_HOUR = NANOS_PER_MINUTE * 60;
55
57
58/// Global, sticky enable switch. If true, the user has explicitly
59/// run the enable command. When a process launches or is attached to,
60/// we will enable DarwinLog if either the settings for auto-enable is
61/// on, or if the user had explicitly run enable at some point prior
62/// to the launch/attach.
64
65class EnableOptions;
66using EnableOptionsSP = std::shared_ptr<EnableOptions>;
67
69 std::map<DebuggerWP, EnableOptionsSP, std::owner_less<DebuggerWP>>;
70
72 static OptionsMap s_options_map;
73 return s_options_map;
74}
75
76static std::mutex &GetGlobalOptionsMapLock() {
77 static std::mutex s_options_map_lock;
78 return s_options_map_lock;
79}
80
82 if (!debugger_sp)
83 return EnableOptionsSP();
84
85 std::lock_guard<std::mutex> locker(GetGlobalOptionsMapLock());
86 OptionsMap &options_map = GetGlobalOptionsMap();
87 DebuggerWP debugger_wp(debugger_sp);
88 auto find_it = options_map.find(debugger_wp);
89 if (find_it != options_map.end())
90 return find_it->second;
91 else
92 return EnableOptionsSP();
93}
94
95void SetGlobalEnableOptions(const DebuggerSP &debugger_sp,
96 const EnableOptionsSP &options_sp) {
97 std::lock_guard<std::mutex> locker(GetGlobalOptionsMapLock());
98 OptionsMap &options_map = GetGlobalOptionsMap();
99 DebuggerWP debugger_wp(debugger_sp);
100 auto find_it = options_map.find(debugger_wp);
101 if (find_it != options_map.end())
102 find_it->second = options_sp;
103 else
104 options_map.insert(std::make_pair(debugger_wp, options_sp));
105}
106
107#pragma mark -
108#pragma mark Settings Handling
109
110/// Code to handle the StructuredDataDarwinLog settings
111
112#define LLDB_PROPERTIES_darwinlog
113#include "StructuredDataDarwinLogProperties.inc"
114
115enum {
116#define LLDB_PROPERTIES_darwinlog
117#include "StructuredDataDarwinLogPropertiesEnum.inc"
118};
119
121public:
122 static llvm::StringRef GetSettingName() {
123 static constexpr llvm::StringLiteral g_setting_name("darwin-log");
124 return g_setting_name;
125 }
126
128 m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName());
129 m_collection_sp->Initialize(g_darwinlog_properties);
130 }
131
133
134 bool GetEnableOnStartup() const {
135 const uint32_t idx = ePropertyEnableOnStartup;
136 return GetPropertyAtIndexAs<bool>(
137 idx, g_darwinlog_properties[idx].default_uint_value != 0);
138 }
139
140 llvm::StringRef GetAutoEnableOptions() const {
141 const uint32_t idx = ePropertyAutoEnableOptions;
142 return GetPropertyAtIndexAs<llvm::StringRef>(
143 idx, g_darwinlog_properties[idx].default_cstr_value);
144 }
145
146 const char *GetLoggingModuleName() const { return "libsystem_trace.dylib"; }
147};
148
150 static StructuredDataDarwinLogProperties g_settings;
151 return g_settings;
152}
153
154const char *const s_filter_attributes[] = {
155 "activity", // current activity
156 "activity-chain", // entire activity chain, each level separated by ':'
157 "category", // category of the log message
158 "message", // message contents, fully expanded
159 "subsystem" // subsystem of the log message
160
161 // Consider implementing this action as it would be cheaper to filter.
162 // "message" requires always formatting the message, which is a waste of
163 // cycles if it ends up being rejected. "format", // format string
164 // used to format message text
165};
166
167static llvm::StringRef GetDarwinLogTypeName() {
168 static constexpr llvm::StringLiteral s_key_name("DarwinLog");
169 return s_key_name;
170}
171
172static llvm::StringRef GetLogEventType() {
173 static constexpr llvm::StringLiteral s_event_type("log");
174 return s_event_type;
175}
176
177class FilterRule;
178using FilterRuleSP = std::shared_ptr<FilterRule>;
179
181public:
182 virtual ~FilterRule() = default;
183
185 std::function<FilterRuleSP(bool accept, size_t attribute_index,
186 const std::string &op_arg, Status &error)>;
187
188 static void RegisterOperation(llvm::StringRef operation,
189 const OperationCreationFunc &creation_func) {
190 GetCreationFuncMap().insert(std::make_pair(operation, creation_func));
191 }
192
193 static FilterRuleSP CreateRule(bool match_accepts, size_t attribute,
194 llvm::StringRef operation,
195 const std::string &op_arg, Status &error) {
196 // Find the creation func for this type of filter rule.
197 auto map = GetCreationFuncMap();
198 auto find_it = map.find(operation);
199 if (find_it == map.end()) {
201 "unknown filter operation \"{0}\"", operation);
202 return FilterRuleSP();
203 }
204
205 return find_it->second(match_accepts, attribute, op_arg, error);
206 }
207
210
211 // Indicate whether this is an accept or reject rule.
212 dict_p->AddBooleanItem("accept", m_accept);
213
214 // Indicate which attribute of the message this filter references. This can
215 // drop into the rule-specific DoSerialization if we get to the point where
216 // not all FilterRule derived classes work on an attribute. (e.g. logical
217 // and/or and other compound operations).
219
220 // Indicate the type of the rule.
221 dict_p->AddStringItem("type", GetOperationType());
222
223 // Let the rule add its own specific details here.
224 DoSerialization(*dict_p);
225
226 return StructuredData::ObjectSP(dict_p);
227 }
228
229 virtual void Dump(Stream &stream) const = 0;
230
231 llvm::StringRef GetOperationType() const { return m_operation; }
232
233protected:
234 FilterRule(bool accept, size_t attribute_index, llvm::StringRef operation)
235 : m_accept(accept), m_attribute_index(attribute_index),
236 m_operation(operation) {}
237
238 virtual void DoSerialization(StructuredData::Dictionary &dict) const = 0;
239
240 bool GetMatchAccepts() const { return m_accept; }
241
242 const char *GetFilterAttribute() const {
244 }
245
246private:
247 using CreationFuncMap = llvm::StringMap<OperationCreationFunc>;
248
250 static CreationFuncMap s_map;
251 return s_map;
252 }
253
254 const bool m_accept;
255 const size_t m_attribute_index;
256 // The lifetime of m_operation should be static.
257 const llvm::StringRef m_operation;
258};
259
260using FilterRules = std::vector<FilterRuleSP>;
261
263public:
264 static void RegisterOperation() {
266 }
267
268 void Dump(Stream &stream) const override {
269 stream.Printf("%s %s regex %s", GetMatchAccepts() ? "accept" : "reject",
271 }
272
273protected:
274 void DoSerialization(StructuredData::Dictionary &dict) const override {
275 dict.AddStringItem("regex", m_regex_text);
276 }
277
278private:
279 static FilterRuleSP CreateOperation(bool accept, size_t attribute_index,
280 const std::string &op_arg,
281 Status &error) {
282 // We treat the op_arg as a regex. Validate it.
283 if (op_arg.empty()) {
284 error = Status::FromErrorString("regex filter type requires a regex "
285 "argument");
286 return FilterRuleSP();
287 }
288
289 // Instantiate the regex so we can report any errors.
290 auto regex = RegularExpression(op_arg);
291 if (llvm::Error err = regex.GetError()) {
292 error = Status::FromError(std::move(err));
293 return FilterRuleSP();
294 }
295
296 // We passed all our checks, this appears fine.
297 error.Clear();
298 return FilterRuleSP(new RegexFilterRule(accept, attribute_index, op_arg));
299 }
300
301 static llvm::StringRef StaticGetOperation() {
302 static constexpr llvm::StringLiteral s_operation("regex");
303 return s_operation;
304 }
305
306 RegexFilterRule(bool accept, size_t attribute_index,
307 const std::string &regex_text)
308 : FilterRule(accept, attribute_index, StaticGetOperation()),
309 m_regex_text(regex_text) {}
310
311 const std::string m_regex_text;
312};
313
315public:
316 static void RegisterOperation() {
318 }
319
320 void Dump(Stream &stream) const override {
321 stream.Printf("%s %s match %s", GetMatchAccepts() ? "accept" : "reject",
323 }
324
325protected:
326 void DoSerialization(StructuredData::Dictionary &dict) const override {
327 dict.AddStringItem("exact_text", m_match_text);
328 }
329
330private:
331 static FilterRuleSP CreateOperation(bool accept, size_t attribute_index,
332 const std::string &op_arg,
333 Status &error) {
334 if (op_arg.empty()) {
335 error = Status::FromErrorString("exact match filter type requires an "
336 "argument containing the text that must "
337 "match the specified message attribute.");
338 return FilterRuleSP();
339 }
340
341 error.Clear();
342 return FilterRuleSP(
343 new ExactMatchFilterRule(accept, attribute_index, op_arg));
344 }
345
346 static llvm::StringRef StaticGetOperation() {
347 static constexpr llvm::StringLiteral s_operation("match");
348 return s_operation;
349 }
350
351 ExactMatchFilterRule(bool accept, size_t attribute_index,
352 const std::string &match_text)
353 : FilterRule(accept, attribute_index, StaticGetOperation()),
354 m_match_text(match_text) {}
355
356 const std::string m_match_text;
357};
358
362}
363
364// =========================================================================
365// Commands
366// =========================================================================
367
368/// Provides the main on-off switch for enabling darwin logging.
369///
370/// It is valid to run the enable command when logging is already enabled.
371/// This resets the logging with whatever settings are currently set.
372
374 // Source stream include/exclude options (the first-level filter). This one
375 // should be made as small as possible as everything that goes through here
376 // must be processed by the process monitor.
377 {LLDB_OPT_SET_ALL, false, "any-process", 'a', OptionParser::eNoArgument,
378 nullptr, {}, 0, eArgTypeNone,
379 "Specifies log messages from other related processes should be "
380 "included."},
381 {LLDB_OPT_SET_ALL, false, "debug", 'd', OptionParser::eNoArgument, nullptr,
382 {}, 0, eArgTypeNone,
383 "Specifies debug-level log messages should be included. Specifying"
384 " --debug implies --info."},
385 {LLDB_OPT_SET_ALL, false, "info", 'i', OptionParser::eNoArgument, nullptr,
386 {}, 0, eArgTypeNone,
387 "Specifies info-level log messages should be included."},
389 nullptr, {}, 0, eArgRawInput,
390 // There doesn't appear to be a great way for me to have these multi-line,
391 // formatted tables in help. This looks mostly right but there are extra
392 // linefeeds added at seemingly random spots, and indentation isn't
393 // handled properly on those lines.
394 "Appends a filter rule to the log message filter chain. Multiple "
395 "rules may be added by specifying this option multiple times, "
396 "once per filter rule. Filter rules are processed in the order "
397 "they are specified, with the --no-match-accepts setting used "
398 "for any message that doesn't match one of the rules.\n"
399 "\n"
400 " Filter spec format:\n"
401 "\n"
402 " --filter \"{action} {attribute} {op}\"\n"
403 "\n"
404 " {action} :=\n"
405 " accept |\n"
406 " reject\n"
407 "\n"
408 " {attribute} :=\n"
409 " activity | // message's most-derived activity\n"
410 " activity-chain | // message's {parent}:{child} activity\n"
411 " category | // message's category\n"
412 " message | // message's expanded contents\n"
413 " subsystem | // message's subsystem\n"
414 "\n"
415 " {op} :=\n"
416 " match {exact-match-text} |\n"
417 " regex {search-regex}\n"
418 "\n"
419 "The regex flavor used is the C++ std::regex ECMAScript format. "
420 "Prefer character classes like [[:digit:]] to \\d and the like, as "
421 "getting the backslashes escaped through properly is error-prone."},
422 {LLDB_OPT_SET_ALL, false, "live-stream", 'l',
424 "Specify whether logging events are live-streamed or buffered. "
425 "True indicates live streaming, false indicates buffered. The "
426 "default is true (live streaming). Live streaming will deliver "
427 "log messages with less delay, but buffered capture mode has less "
428 "of an observer effect."},
429 {LLDB_OPT_SET_ALL, false, "no-match-accepts", 'n',
431 "Specify whether a log message that doesn't match any filter rule "
432 "is accepted or rejected, where true indicates accept. The "
433 "default is true."},
434 {LLDB_OPT_SET_ALL, false, "echo-to-stderr", 'e',
436 "Specify whether os_log()/NSLog() messages are echoed to the "
437 "target program's stderr. When DarwinLog is enabled, we shut off "
438 "the mirroring of os_log()/NSLog() to the program's stderr. "
439 "Setting this flag to true will restore the stderr mirroring."
440 "The default is false."},
441 {LLDB_OPT_SET_ALL, false, "broadcast-events", 'b',
443 "Specify if the plugin should broadcast events. Broadcasting "
444 "log events is a requirement for displaying the log entries in "
445 "LLDB command-line. It is also required if LLDB clients want to "
446 "process log events. The default is true."},
447 // Message formatting options
448 {LLDB_OPT_SET_ALL, false, "timestamp-relative", 'r',
450 "Include timestamp in the message header when printing a log "
451 "message. The timestamp is relative to the first displayed "
452 "message."},
453 {LLDB_OPT_SET_ALL, false, "subsystem", 's', OptionParser::eNoArgument,
454 nullptr, {}, 0, eArgTypeNone,
455 "Include the subsystem in the message header when displaying "
456 "a log message."},
457 {LLDB_OPT_SET_ALL, false, "category", 'c', OptionParser::eNoArgument,
458 nullptr, {}, 0, eArgTypeNone,
459 "Include the category in the message header when displaying "
460 "a log message."},
461 {LLDB_OPT_SET_ALL, false, "activity-chain", 'C', OptionParser::eNoArgument,
462 nullptr, {}, 0, eArgTypeNone,
463 "Include the activity parent-child chain in the message header "
464 "when displaying a log message. The activity hierarchy is "
465 "displayed as {grandparent-activity}:"
466 "{parent-activity}:{activity}[:...]."},
467 {LLDB_OPT_SET_ALL, false, "all-fields", 'A', OptionParser::eNoArgument,
468 nullptr, {}, 0, eArgTypeNone,
469 "Shortcut to specify that all header fields should be displayed."}};
470
471class EnableOptions : public Options {
472public:
474 : Options(),
476 m_filter_rules() {}
477
478 void OptionParsingStarting(ExecutionContext *execution_context) override {
479 m_include_debug_level = false;
480 m_include_info_level = false;
481 m_include_any_process = false;
483 m_echo_to_stderr = false;
485 m_display_subsystem = false;
486 m_display_category = false;
488 m_broadcast_events = true;
489 m_live_stream = true;
490 m_filter_rules.clear();
491 }
492
493 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
494 ExecutionContext *execution_context) override {
496
497 const int short_option = m_getopt_table[option_idx].val;
498 switch (short_option) {
499 case 'a':
501 break;
502
503 case 'A':
505 m_display_category = true;
506 m_display_subsystem = true;
508 break;
509
510 case 'b':
512 OptionArgParser::ToBoolean(option_arg, true, nullptr);
513 break;
514
515 case 'c':
516 m_display_category = true;
517 break;
518
519 case 'C':
521 break;
522
523 case 'd':
525 break;
526
527 case 'e':
528 m_echo_to_stderr = OptionArgParser::ToBoolean(option_arg, false, nullptr);
529 break;
530
531 case 'f':
532 return ParseFilterRule(option_arg);
533
534 case 'i':
536 break;
537
538 case 'l':
539 m_live_stream = OptionArgParser::ToBoolean(option_arg, false, nullptr);
540 break;
541
542 case 'n':
544 OptionArgParser::ToBoolean(option_arg, true, nullptr);
545 break;
546
547 case 'r':
549 break;
550
551 case 's':
552 m_display_subsystem = true;
553 break;
554
555 default:
556 error = Status::FromErrorStringWithFormat("unsupported option '%c'",
557 short_option);
558 }
559 return error;
560 }
561
562 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
563 return llvm::ArrayRef(g_enable_option_table);
564 }
565
568
569 // Set the basic enabled state.
570 config_sp->AddBooleanItem("enabled", enabled);
571
572 // If we're disabled, there's nothing more to add.
573 if (!enabled)
574 return config_sp;
575
576 // Handle source stream flags.
577 auto source_flags_sp =
579 config_sp->AddItem("source-flags", source_flags_sp);
580
581 source_flags_sp->AddBooleanItem("any-process", m_include_any_process);
582 source_flags_sp->AddBooleanItem("debug-level", m_include_debug_level);
583 // The debug-level flag, if set, implies info-level.
584 source_flags_sp->AddBooleanItem("info-level", m_include_info_level ||
586 source_flags_sp->AddBooleanItem("live-stream", m_live_stream);
587
588 // Specify default filter rule (the fall-through)
589 config_sp->AddBooleanItem("filter-fall-through-accepts",
591
592 // Handle filter rules
593 if (!m_filter_rules.empty()) {
594 auto json_filter_rules_sp =
596 config_sp->AddItem("filter-rules", json_filter_rules_sp);
597 for (auto &rule_sp : m_filter_rules) {
598 if (!rule_sp)
599 continue;
600 json_filter_rules_sp->AddItem(rule_sp->Serialize());
601 }
602 }
603 return config_sp;
604 }
605
607
608 bool GetIncludeInfoLevel() const {
609 // Specifying debug level implies info level.
611 }
612
613 const FilterRules &GetFilterRules() const { return m_filter_rules; }
614
616
617 bool GetEchoToStdErr() const { return m_echo_to_stderr; }
618
621 }
622
624 bool GetDisplayCategory() const { return m_display_category; }
626
630 }
631
632 bool GetBroadcastEvents() const { return m_broadcast_events; }
633
634private:
635 Status ParseFilterRule(llvm::StringRef rule_text) {
637
638 if (rule_text.empty()) {
639 error = Status::FromErrorString("invalid rule_text");
640 return error;
641 }
642
643 // filter spec format:
644 //
645 // {action} {attribute} {op}
646 //
647 // {action} :=
648 // accept |
649 // reject
650 //
651 // {attribute} :=
652 // category |
653 // subsystem |
654 // activity |
655 // activity-chain |
656 // message |
657 // format
658 //
659 // {op} :=
660 // match {exact-match-text} |
661 // regex {search-regex}
662
663 // Parse action.
664 auto action_end_pos = rule_text.find(' ');
665 if (action_end_pos == std::string::npos) {
666 error = Status::FromErrorStringWithFormat("could not parse filter rule "
667 "action from \"%s\"",
668 rule_text.str().c_str());
669 return error;
670 }
671 auto action = rule_text.substr(0, action_end_pos);
672 bool accept;
673 if (action == "accept")
674 accept = true;
675 else if (action == "reject")
676 accept = false;
677 else {
679 "filter action must be \"accept\" or \"deny\"");
680 return error;
681 }
682
683 // parse attribute
684 auto attribute_end_pos = rule_text.find(" ", action_end_pos + 1);
685 if (attribute_end_pos == std::string::npos) {
686 error = Status::FromErrorStringWithFormat("could not parse filter rule "
687 "attribute from \"%s\"",
688 rule_text.str().c_str());
689 return error;
690 }
691 auto attribute = rule_text.substr(action_end_pos + 1,
692 attribute_end_pos - (action_end_pos + 1));
693 auto attribute_index = MatchAttributeIndex(attribute);
694 if (attribute_index < 0) {
695 error =
696 Status::FromErrorStringWithFormat("filter rule attribute unknown: "
697 "%s",
698 attribute.str().c_str());
699 return error;
700 }
701
702 // parse operation
703 auto operation_end_pos = rule_text.find(" ", attribute_end_pos + 1);
704 auto operation = rule_text.substr(
705 attribute_end_pos + 1, operation_end_pos - (attribute_end_pos + 1));
706
707 // add filter spec
708 auto rule_sp = FilterRule::CreateRule(
709 accept, attribute_index, operation,
710 std::string(rule_text.substr(operation_end_pos + 1)), error);
711
712 if (rule_sp && error.Success())
713 m_filter_rules.push_back(rule_sp);
714
715 return error;
716 }
717
718 int MatchAttributeIndex(llvm::StringRef attribute_name) const {
719 for (const auto &Item : llvm::enumerate(s_filter_attributes)) {
720 if (attribute_name == Item.value())
721 return Item.index();
722 }
723
724 // We didn't match anything.
725 return -1;
726 }
727
732 bool m_echo_to_stderr = false;
735 bool m_display_category = false;
738 bool m_live_stream = true;
740};
741
743public:
744 EnableCommand(CommandInterpreter &interpreter, bool enable, const char *name,
745 const char *help, const char *syntax)
746 : CommandObjectParsed(interpreter, name, help, syntax), m_enable(enable),
747 m_options_sp(enable ? new EnableOptions() : nullptr) {}
748
749protected:
751 const char *source_name) {
752 if (!source_name)
753 return;
754
755 // Check if we're *not* using strict sources. If not, then the user is
756 // going to get debug-level info anyways, probably not what they're
757 // expecting. Unfortunately we can only fix this by adding an env var,
758 // which would have had to have happened already. Thus, a warning is the
759 // best we can do here.
760 StreamString stream;
761 stream.Printf("darwin-log source settings specify to exclude "
762 "%s messages, but setting "
763 "'plugin.structured-data.darwin-log."
764 "strict-sources' is disabled. This process will "
765 "automatically have %s messages included. Enable"
766 " the property and relaunch the target binary to have"
767 " these messages excluded.",
768 source_name, source_name);
769 result.AppendWarning(stream.GetString());
770 }
771
772 void DoExecute(Args &command, CommandReturnObject &result) override {
773 // First off, set the global sticky state of enable/disable based on this
774 // command execution.
776
777 // Next, if this is an enable, save off the option data. We will need it
778 // later if a process hasn't been launched or attached yet.
779 if (m_enable) {
780 // Save off enabled configuration so we can apply these parsed options
781 // the next time an attach or launch occurs.
782 DebuggerSP debugger_sp =
783 GetCommandInterpreter().GetDebugger().shared_from_this();
785 }
786
787 // Now check if we have a running process. If so, we should instruct the
788 // process monitor to enable/disable DarwinLog support now.
789 Target &target = GetTarget();
790
791 // Grab the active process.
792 auto process_sp = target.GetProcessSP();
793 if (!process_sp) {
794 // No active process, so there is nothing more to do right now.
796 return;
797 }
798
799 // If the process is no longer alive, we can't do this now. We'll catch it
800 // the next time the process is started up.
801 if (!process_sp->IsAlive()) {
803 return;
804 }
805
806 // Get the plugin for the process.
807 auto plugin_sp =
808 process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName());
809 if (!plugin_sp || (plugin_sp->GetPluginName() !=
811 result.AppendError("failed to get StructuredDataPlugin for "
812 "the process");
813 }
815 *static_cast<StructuredDataDarwinLog *>(plugin_sp.get());
816
817 if (m_enable) {
818 // Hook up the breakpoint for the process that detects when libtrace has
819 // been sufficiently initialized to really start the os_log stream. This
820 // is insurance to assure us that logging is really enabled. Requesting
821 // that logging be enabled for a process before libtrace is initialized
822 // results in a scenario where no errors occur, but no logging is
823 // captured, either. This step is to eliminate that possibility.
824 plugin.AddInitCompletionHook(*process_sp);
825 }
826
827 // Send configuration to the feature by way of the process. Construct the
828 // options we will use.
829 auto config_sp = m_options_sp->BuildConfigurationData(m_enable);
830 const Status error =
831 process_sp->ConfigureStructuredData(GetDarwinLogTypeName(), config_sp);
832
833 // Report results.
834 if (!error.Success()) {
835 result.AppendError(error.AsCString());
836 // Our configuration failed, so we're definitely disabled.
837 plugin.SetEnabled(false);
838 } else {
840 // Our configuration succeeded, so we're enabled/disabled per whichever
841 // one this command is setup to do.
842 plugin.SetEnabled(m_enable);
843 }
844 }
845
846 Options *GetOptions() override {
847 // We don't have options when this represents disable.
848 return m_enable ? m_options_sp.get() : nullptr;
849 }
850
851private:
852 const bool m_enable;
854};
855
856/// Provides the status command.
858public:
860 : CommandObjectParsed(interpreter, "status",
861 "Show whether Darwin log supported is available"
862 " and enabled.",
863 "plugin structured-data darwin-log status") {}
864
865protected:
866 void DoExecute(Args &command, CommandReturnObject &result) override {
867 auto &stream = result.GetOutputStream();
868
869 // Figure out if we've got a process. If so, we can tell if DarwinLog is
870 // available for that process.
871 Target &target = GetTarget();
872 auto process_sp = target.GetProcessSP();
873 if (!process_sp) {
874 stream.PutCString("Availability: unknown (requires process)\n");
875 stream.PutCString("Enabled: not applicable "
876 "(requires process)\n");
877 } else {
878 auto plugin_sp =
879 process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName());
880 stream.Printf("Availability: %s\n",
881 plugin_sp ? "available" : "unavailable");
882 const bool enabled =
883 plugin_sp ? plugin_sp->GetEnabled(
885 : false;
886 stream.Printf("Enabled: %s\n", enabled ? "true" : "false");
887 }
888
889 // Display filter settings.
890 DebuggerSP debugger_sp =
891 GetCommandInterpreter().GetDebugger().shared_from_this();
892 auto options_sp = GetGlobalEnableOptions(debugger_sp);
893 if (!options_sp) {
894 // Nothing more to do.
896 return;
897 }
898
899 // Print filter rules
900 stream.PutCString("DarwinLog filter rules:\n");
901
902 stream.IndentMore();
903
904 if (options_sp->GetFilterRules().empty()) {
905 stream.Indent();
906 stream.PutCString("none\n");
907 } else {
908 // Print each of the filter rules.
909 int rule_number = 0;
910 for (auto rule_sp : options_sp->GetFilterRules()) {
911 ++rule_number;
912 if (!rule_sp)
913 continue;
914
915 stream.Indent();
916 stream.Printf("%02d: ", rule_number);
917 rule_sp->Dump(stream);
918 stream.PutChar('\n');
919 }
920 }
921 stream.IndentLess();
922
923 // Print no-match handling.
924 stream.Indent();
925 stream.Printf("no-match behavior: %s\n",
926 options_sp->GetFallthroughAccepts() ? "accept" : "reject");
927
929 }
930};
931
932/// Provides the darwin-log base command
934public:
936 : CommandObjectMultiword(interpreter, "plugin structured-data darwin-log",
937 "Commands for configuring Darwin os_log "
938 "support.",
939 "") {
940 // enable
941 auto enable_help = "Enable Darwin log collection, or re-enable "
942 "with modified configuration.";
943 auto enable_syntax = "plugin structured-data darwin-log enable";
944 auto enable_cmd_sp = CommandObjectSP(
945 new EnableCommand(interpreter,
946 true, // enable
947 "enable", enable_help, enable_syntax));
948 LoadSubCommand("enable", enable_cmd_sp);
949
950 // disable
951 auto disable_help = "Disable Darwin log collection.";
952 auto disable_syntax = "plugin structured-data darwin-log disable";
953 auto disable_cmd_sp = CommandObjectSP(
954 new EnableCommand(interpreter,
955 false, // disable
956 "disable", disable_help, disable_syntax));
957 LoadSubCommand("disable", disable_cmd_sp);
958
959 // status
960 auto status_cmd_sp = CommandObjectSP(new StatusCommand(interpreter));
961 LoadSubCommand("status", status_cmd_sp);
962 }
963};
964
966 Log *log = GetLog(LLDBLog::Process);
967 // We are abusing the options data model here so that we can parse options
968 // without requiring the Debugger instance.
969
970 // We have an empty execution context at this point. We only want to parse
971 // options, and we don't need any context to do this here. In fact, we want
972 // to be able to parse the enable options before having any context.
973 ExecutionContext exe_ctx;
974
975 EnableOptionsSP options_sp(new EnableOptions());
976 options_sp->NotifyOptionParsingStarting(&exe_ctx);
977
978 CommandReturnObject result(debugger.GetUseColor());
979
980 // Parse the arguments.
981 auto options_property_sp =
982 debugger.GetPropertyValue(nullptr,
983 "plugin.structured-data.darwin-log."
984 "auto-enable-options",
985 error);
986 if (!error.Success())
987 return EnableOptionsSP();
988 if (!options_property_sp) {
989 error = Status::FromErrorString("failed to find option setting for "
990 "plugin.structured-data.darwin-log.");
991 return EnableOptionsSP();
992 }
993
994 const char *enable_options =
995 options_property_sp->GetAsString()->GetCurrentValue();
996 Args args(enable_options);
997 if (args.GetArgumentCount() > 0) {
998 // Eliminate the initial '--' that would be required to set the settings
999 // that themselves include '-' and/or '--'.
1000 const char *first_arg = args.GetArgumentAtIndex(0);
1001 if (first_arg && (strcmp(first_arg, "--") == 0))
1002 args.Shift();
1003 }
1004
1005 bool require_validation = false;
1006 llvm::Expected<Args> args_or =
1007 options_sp->Parse(args, &exe_ctx, PlatformSP(), require_validation);
1008 if (!args_or) {
1010 log, args_or.takeError(),
1011 "Parsing plugin.structured-data.darwin-log.auto-enable-options value "
1012 "failed: {0}");
1013 return EnableOptionsSP();
1014 }
1015
1016 if (!options_sp->VerifyOptions(result))
1017 return EnableOptionsSP();
1018
1019 // We successfully parsed and validated the options.
1020 return options_sp;
1021}
1022
1024 StreamString command_stream;
1025
1026 command_stream << "plugin structured-data darwin-log enable";
1027 auto enable_options = GetGlobalProperties().GetAutoEnableOptions();
1028 if (!enable_options.empty()) {
1029 command_stream << ' ';
1030 command_stream << enable_options;
1031 }
1032
1033 // Run the command.
1034 CommandReturnObject return_object(interpreter.GetDebugger().GetUseColor());
1035 interpreter.HandleCommand(command_stream.GetData(), eLazyBoolNo,
1036 return_object);
1037 return return_object.Succeeded();
1038}
1039}
1040using namespace sddarwinlog_private;
1041
1042#pragma mark -
1043#pragma mark Public static API
1044
1045// Public static API
1046
1050 GetStaticPluginName(), "Darwin os_log() and os_activity() support",
1052}
1053
1056}
1057
1058#pragma mark -
1059#pragma mark StructuredDataPlugin API
1060
1061// StructuredDataPlugin API
1062
1064 llvm::StringRef type_name) {
1065 return type_name == GetDarwinLogTypeName();
1066}
1067
1069 Process &process, llvm::StringRef type_name,
1070 const StructuredData::ObjectSP &object_sp) {
1071 Log *log = GetLog(LLDBLog::Process);
1072 if (log) {
1073 StreamString json_stream;
1074 if (object_sp)
1075 object_sp->Dump(json_stream);
1076 else
1077 json_stream.PutCString("<null>");
1078 LLDB_LOGF(log, "StructuredDataDarwinLog::%s() called with json: %s",
1079 __FUNCTION__, json_stream.GetData());
1080 }
1081
1082 // Ignore empty structured data.
1083 if (!object_sp) {
1084 LLDB_LOGF(log,
1085 "StructuredDataDarwinLog::%s() StructuredData object "
1086 "is null",
1087 __FUNCTION__);
1088 return;
1089 }
1090
1091 // Ignore any data that isn't for us.
1092 if (type_name != GetDarwinLogTypeName()) {
1093 LLDB_LOG(log,
1094 "StructuredData type expected to be {0} but was {1}, ignoring",
1095 GetDarwinLogTypeName(), type_name);
1096 return;
1097 }
1098
1099 // Broadcast the structured data event if we have that enabled. This is the
1100 // way that the outside world (all clients) get access to this data. This
1101 // plugin sets policy as to whether we do that.
1102 DebuggerSP debugger_sp = process.GetTarget().GetDebugger().shared_from_this();
1103 auto options_sp = GetGlobalEnableOptions(debugger_sp);
1104 if (options_sp && options_sp->GetBroadcastEvents()) {
1105 LLDB_LOGF(log, "StructuredDataDarwinLog::%s() broadcasting event",
1106 __FUNCTION__);
1107 process.BroadcastStructuredData(object_sp, shared_from_this());
1108 }
1109
1110 // Later, hang on to a configurable amount of these and allow commands to
1111 // inspect, including showing backtraces.
1112}
1113
1114static void SetErrorWithJSON(Status &error, const char *message,
1115 StructuredData::Object &object) {
1116 if (!message) {
1117 error = Status::FromErrorString("Internal error: message not set.");
1118 return;
1119 }
1120
1121 StreamString object_stream;
1122 object.Dump(object_stream);
1123 object_stream.Flush();
1124
1125 error = Status::FromErrorStringWithFormat("%s: %s", message,
1126 object_stream.GetData());
1127}
1128
1130 const StructuredData::ObjectSP &object_sp, lldb_private::Stream &stream) {
1131 Status error;
1132
1133 if (!object_sp) {
1134 error = Status::FromErrorString("No structured data.");
1135 return error;
1136 }
1137
1138 // Log message payload objects will be dictionaries.
1139 const StructuredData::Dictionary *dictionary = object_sp->GetAsDictionary();
1140 if (!dictionary) {
1141 SetErrorWithJSON(error, "Structured data should have been a dictionary "
1142 "but wasn't",
1143 *object_sp);
1144 return error;
1145 }
1146
1147 // Validate this is really a message for our plugin.
1148 llvm::StringRef type_name;
1149 if (!dictionary->GetValueForKeyAsString("type", type_name)) {
1150 SetErrorWithJSON(error, "Structured data doesn't contain mandatory "
1151 "type field",
1152 *object_sp);
1153 return error;
1154 }
1155
1156 if (type_name != GetDarwinLogTypeName()) {
1157 // This is okay - it simply means the data we received is not a log
1158 // message. We'll just format it as is.
1159 object_sp->Dump(stream);
1160 return error;
1161 }
1162
1163 // DarwinLog dictionaries store their data
1164 // in an array with key name "events".
1165 StructuredData::Array *events = nullptr;
1166 if (!dictionary->GetValueForKeyAsArray("events", events) || !events) {
1167 SetErrorWithJSON(error, "Log structured data is missing mandatory "
1168 "'events' field, expected to be an array",
1169 *object_sp);
1170 return error;
1171 }
1172
1173 events->ForEach(
1174 [&stream, &error, &object_sp, this](StructuredData::Object *object) {
1175 if (!object) {
1176 // Invalid. Stop iterating.
1177 SetErrorWithJSON(error, "Log event entry is null", *object_sp);
1178 return false;
1179 }
1180
1181 auto event = object->GetAsDictionary();
1182 if (!event) {
1183 // Invalid, stop iterating.
1184 SetErrorWithJSON(error, "Log event is not a dictionary", *object_sp);
1185 return false;
1186 }
1187
1188 // If we haven't already grabbed the first timestamp value, do that
1189 // now.
1191 uint64_t timestamp = 0;
1192 if (event->GetValueForKeyAsInteger("timestamp", timestamp)) {
1193 m_first_timestamp_seen = timestamp;
1195 }
1196 }
1197
1198 HandleDisplayOfEvent(*event, stream);
1199 return true;
1200 });
1201
1202 stream.Flush();
1203 return error;
1204}
1205
1206bool StructuredDataDarwinLog::GetEnabled(llvm::StringRef type_name) const {
1207 if (type_name == GetStaticPluginName())
1208 return m_is_enabled;
1209 return false;
1210}
1211
1213 m_is_enabled = enabled;
1214}
1215
1217 ModuleList &module_list) {
1218 Log *log = GetLog(LLDBLog::Process);
1219 LLDB_LOGF(log, "StructuredDataDarwinLog::%s called (process uid %u)",
1220 __FUNCTION__, process.GetUniqueID());
1221
1222 // Check if we should enable the darwin log support on startup/attach.
1223 if (!GetGlobalProperties().GetEnableOnStartup() &&
1225 // We're neither auto-enabled or explicitly enabled, so we shouldn't try to
1226 // enable here.
1227 LLDB_LOGF(log,
1228 "StructuredDataDarwinLog::%s not applicable, we're not "
1229 "enabled (process uid %u)",
1230 __FUNCTION__, process.GetUniqueID());
1231 return;
1232 }
1233
1234 // If we already added the breakpoint, we've got nothing left to do.
1235 {
1236 std::lock_guard<std::mutex> locker(m_added_breakpoint_mutex);
1237 if (m_added_breakpoint) {
1238 LLDB_LOGF(log,
1239 "StructuredDataDarwinLog::%s process uid %u's "
1240 "post-libtrace-init breakpoint is already set",
1241 __FUNCTION__, process.GetUniqueID());
1242 return;
1243 }
1244 }
1245
1246 // The logging support module name, specifies the name of the image name that
1247 // must be loaded into the debugged process before we can try to enable
1248 // logging.
1249 const char *logging_module_cstr =
1250 GetGlobalProperties().GetLoggingModuleName();
1251 if (!logging_module_cstr || (logging_module_cstr[0] == 0)) {
1252 // We need this. Bail.
1253 LLDB_LOGF(log,
1254 "StructuredDataDarwinLog::%s no logging module name "
1255 "specified, we don't know where to set a breakpoint "
1256 "(process uid %u)",
1257 __FUNCTION__, process.GetUniqueID());
1258 return;
1259 }
1260
1261 // We need to see libtrace in the list of modules before we can enable
1262 // tracing for the target process.
1263 bool found_logging_support_module = false;
1264 for (size_t i = 0; i < module_list.GetSize(); ++i) {
1265 auto module_sp = module_list.GetModuleAtIndex(i);
1266 if (!module_sp)
1267 continue;
1268
1269 auto &file_spec = module_sp->GetFileSpec();
1270 found_logging_support_module =
1271 (file_spec.GetFilename() == logging_module_cstr);
1272 if (found_logging_support_module)
1273 break;
1274 }
1275
1276 if (!found_logging_support_module) {
1277 LLDB_LOGF(log,
1278 "StructuredDataDarwinLog::%s logging module %s "
1279 "has not yet been loaded, can't set a breakpoint "
1280 "yet (process uid %u)",
1281 __FUNCTION__, logging_module_cstr, process.GetUniqueID());
1282 return;
1283 }
1284
1285 // Time to enqueue the breakpoint so we can wait for logging support to be
1286 // initialized before we try to tap the libtrace stream.
1287 AddInitCompletionHook(process);
1288 LLDB_LOGF(log,
1289 "StructuredDataDarwinLog::%s post-init hook breakpoint "
1290 "set for logging module %s (process uid %u)",
1291 __FUNCTION__, logging_module_cstr, process.GetUniqueID());
1292
1293 // We need to try the enable here as well, which will succeed in the event
1294 // that we're attaching to (rather than launching) the process and the
1295 // process is already past initialization time. In that case, the completion
1296 // breakpoint will never get hit and therefore won't start that way. It
1297 // doesn't hurt much beyond a bit of bandwidth if we end up doing this twice.
1298 // It hurts much more if we don't get the logging enabled when the user
1299 // expects it.
1300 EnableNow();
1301}
1302
1303// public destructor
1304
1307 ProcessSP process_sp(GetProcess());
1308 if (process_sp) {
1309 process_sp->GetTarget().RemoveBreakpointByID(m_breakpoint_id);
1311 }
1312 }
1313}
1314
1315#pragma mark -
1316#pragma mark Private instance methods
1317
1318// Private constructors
1319
1321 : StructuredDataPlugin(process_wp), m_recorded_first_timestamp(false),
1322 m_first_timestamp_seen(0), m_is_enabled(false),
1323 m_added_breakpoint_mutex(), m_added_breakpoint(),
1324 m_breakpoint_id(LLDB_INVALID_BREAK_ID) {}
1325
1326// Private static methods
1327
1330 // Currently only Apple targets support the os_log/os_activity protocol.
1331 if (process.GetTarget().GetArchitecture().GetTriple().getVendor() ==
1332 llvm::Triple::VendorType::Apple) {
1333 auto process_wp = ProcessWP(process.shared_from_this());
1334 return StructuredDataPluginSP(new StructuredDataDarwinLog(process_wp));
1335 } else {
1336 return StructuredDataPluginSP();
1337 }
1338}
1339
1341 // Setup parent class first.
1343
1344 // Get parent command.
1345 auto &interpreter = debugger.GetCommandInterpreter();
1346 llvm::StringRef parent_command_text = "plugin structured-data";
1347 auto parent_command =
1348 interpreter.GetCommandObjectForCommand(parent_command_text);
1349 if (!parent_command) {
1350 // Ut oh, parent failed to create parent command.
1351 // TODO log
1352 return;
1353 }
1354
1355 auto command_name = "darwin-log";
1356 auto command_sp = CommandObjectSP(new BaseCommand(interpreter));
1357 bool result = parent_command->LoadSubCommand(command_name, command_sp);
1358 if (!result) {
1359 // TODO log it once we setup structured data logging
1360 }
1361
1364 const bool is_global_setting = true;
1366 debugger, GetGlobalProperties().GetValueProperties(),
1367 "Properties for the darwin-log plug-in.", is_global_setting);
1368 }
1369}
1370
1372 Target *target) {
1373 Status error;
1374
1375 // If we're not debugging this launched process, there's nothing for us to do
1376 // here.
1377 if (!launch_info.GetFlags().AnySet(eLaunchFlagDebug))
1378 return error;
1379
1380 // Darwin os_log() support automatically adds debug-level and info-level
1381 // messages when a debugger is attached to a process. However, with
1382 // integrated support for debugging built into the command-line LLDB, the
1383 // user may specifically set to *not* include debug-level and info-level
1384 // content. When the user is using the integrated log support, we want to
1385 // put the kabosh on that automatic adding of info and debug level. This is
1386 // done by adding an environment variable to the process on launch. (This
1387 // also means it is not possible to suppress this behavior if attaching to an
1388 // already-running app).
1389 // Log *log = GetLog(LLDBLog::Platform);
1390
1391 // If the target architecture is not one that supports DarwinLog, we have
1392 // nothing to do here.
1393 auto &triple = target ? target->GetArchitecture().GetTriple()
1394 : launch_info.GetArchitecture().GetTriple();
1395 if (triple.getVendor() != llvm::Triple::Apple) {
1396 return error;
1397 }
1398
1399 // If DarwinLog is not enabled (either by explicit user command or via the
1400 // auto-enable option), then we have nothing to do.
1401 if (!GetGlobalProperties().GetEnableOnStartup() &&
1403 // Nothing to do, DarwinLog is not enabled.
1404 return error;
1405 }
1406
1407 // If we don't have parsed configuration info, that implies we have enable-
1408 // on-startup set up, but we haven't yet attempted to run the enable command.
1409 if (!target) {
1410 // We really can't do this without a target. We need to be able to get to
1411 // the debugger to get the proper options to do this right.
1412 // TODO log.
1413 error =
1414 Status::FromErrorString("requires a target to auto-enable DarwinLog.");
1415 return error;
1416 }
1417
1418 DebuggerSP debugger_sp = target->GetDebugger().shared_from_this();
1419 auto options_sp = GetGlobalEnableOptions(debugger_sp);
1420 if (!options_sp && debugger_sp) {
1421 options_sp = ParseAutoEnableOptions(error, *debugger_sp.get());
1422 if (!options_sp || !error.Success())
1423 return error;
1424
1425 // We already parsed the options, save them now so we don't generate them
1426 // again until the user runs the command manually.
1427 SetGlobalEnableOptions(debugger_sp, options_sp);
1428 }
1429
1430 if (!options_sp->GetEchoToStdErr()) {
1431 // The user doesn't want to see os_log/NSLog messages echo to stderr. That
1432 // mechanism is entirely separate from the DarwinLog support. By default we
1433 // don't want to get it via stderr, because that would be in duplicate of
1434 // the explicit log support here.
1435
1436 // Here we need to strip out any OS_ACTIVITY_DT_MODE setting to prevent
1437 // echoing of os_log()/NSLog() to stderr in the target program.
1438 launch_info.GetEnvironment().erase("OS_ACTIVITY_DT_MODE");
1439
1440 // We will also set the env var that tells any downstream launcher from
1441 // adding OS_ACTIVITY_DT_MODE.
1442 launch_info.GetEnvironment()["IDE_DISABLED_OS_ACTIVITY_DT_MODE"] = "1";
1443 }
1444
1445 // Set the OS_ACTIVITY_MODE env var appropriately to enable/disable debug and
1446 // info level messages.
1447 const char *env_var_value;
1448 if (options_sp->GetIncludeDebugLevel())
1449 env_var_value = "debug";
1450 else if (options_sp->GetIncludeInfoLevel())
1451 env_var_value = "info";
1452 else
1453 env_var_value = "default";
1454
1455 launch_info.GetEnvironment()["OS_ACTIVITY_MODE"] = env_var_value;
1456
1457 return error;
1458}
1459
1461 void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id,
1462 lldb::user_id_t break_loc_id) {
1463 // We hit the init function. We now want to enqueue our new thread plan,
1464 // which will in turn enqueue a StepOut thread plan. When the StepOut
1465 // finishes and control returns to our new thread plan, that is the time when
1466 // we can execute our logic to enable the logging support.
1467
1468 Log *log = GetLog(LLDBLog::Process);
1469 LLDB_LOGF(log, "StructuredDataDarwinLog::%s() called", __FUNCTION__);
1470
1471 // Get the current thread.
1472 if (!context) {
1473 LLDB_LOGF(log,
1474 "StructuredDataDarwinLog::%s() warning: no context, "
1475 "ignoring",
1476 __FUNCTION__);
1477 return false;
1478 }
1479
1480 // Get the plugin from the process.
1481 auto process_sp = context->exe_ctx_ref.GetProcessSP();
1482 if (!process_sp) {
1483 LLDB_LOGF(log,
1484 "StructuredDataDarwinLog::%s() warning: invalid "
1485 "process in context, ignoring",
1486 __FUNCTION__);
1487 return false;
1488 }
1489 LLDB_LOGF(log, "StructuredDataDarwinLog::%s() call is for process uid %d",
1490 __FUNCTION__, process_sp->GetUniqueID());
1491
1492 auto plugin_sp = process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName());
1493 if (!plugin_sp) {
1494 LLDB_LOG(log, "warning: no plugin for feature {0} in process uid {1}",
1495 GetDarwinLogTypeName(), process_sp->GetUniqueID());
1496 return false;
1497 }
1498
1499 // Create the callback for when the thread plan completes.
1500 bool called_enable_method = false;
1501 const auto process_uid = process_sp->GetUniqueID();
1502
1503 std::weak_ptr<StructuredDataPlugin> plugin_wp(plugin_sp);
1505 [plugin_wp, &called_enable_method, log, process_uid]() {
1506 LLDB_LOGF(log,
1507 "StructuredDataDarwinLog::post-init callback: "
1508 "called (process uid %u)",
1509 process_uid);
1510
1511 auto strong_plugin_sp = plugin_wp.lock();
1512 if (!strong_plugin_sp) {
1513 LLDB_LOGF(log,
1514 "StructuredDataDarwinLog::post-init callback: "
1515 "plugin no longer exists, ignoring (process "
1516 "uid %u)",
1517 process_uid);
1518 return;
1519 }
1520 // Make sure we only call it once, just in case the thread plan hits
1521 // the breakpoint twice.
1522 if (!called_enable_method) {
1523 LLDB_LOGF(log,
1524 "StructuredDataDarwinLog::post-init callback: "
1525 "calling EnableNow() (process uid %u)",
1526 process_uid);
1527 static_cast<StructuredDataDarwinLog *>(strong_plugin_sp.get())
1528 ->EnableNow();
1529 called_enable_method = true;
1530 } else {
1531 // Our breakpoint was hit more than once. Unexpected but no harm
1532 // done. Log it.
1533 LLDB_LOGF(log,
1534 "StructuredDataDarwinLog::post-init callback: "
1535 "skipping EnableNow(), already called by "
1536 "callback [we hit this more than once] "
1537 "(process uid %u)",
1538 process_uid);
1539 }
1540 };
1541
1542 // Grab the current thread.
1543 auto thread_sp = context->exe_ctx_ref.GetThreadSP();
1544 if (!thread_sp) {
1545 LLDB_LOGF(log,
1546 "StructuredDataDarwinLog::%s() warning: failed to "
1547 "retrieve the current thread from the execution "
1548 "context, nowhere to run the thread plan (process uid "
1549 "%u)",
1550 __FUNCTION__, process_sp->GetUniqueID());
1551 return false;
1552 }
1553
1554 // Queue the thread plan.
1555 auto thread_plan_sp =
1556 ThreadPlanSP(new ThreadPlanCallOnFunctionExit(*thread_sp, callback));
1557 const bool abort_other_plans = false;
1558 thread_sp->QueueThreadPlan(thread_plan_sp, abort_other_plans);
1559 LLDB_LOGF(log,
1560 "StructuredDataDarwinLog::%s() queuing thread plan on "
1561 "trace library init method entry (process uid %u)",
1562 __FUNCTION__, process_sp->GetUniqueID());
1563
1564 // We return false here to indicate that it isn't a public stop.
1565 return false;
1566}
1567
1569 Log *log = GetLog(LLDBLog::Process);
1570 LLDB_LOGF(log, "StructuredDataDarwinLog::%s() called (process uid %u)",
1571 __FUNCTION__, process.GetUniqueID());
1572
1573 // Make sure we haven't already done this.
1574 {
1575 std::lock_guard<std::mutex> locker(m_added_breakpoint_mutex);
1576 if (m_added_breakpoint) {
1577 LLDB_LOGF(log,
1578 "StructuredDataDarwinLog::%s() ignoring request, "
1579 "breakpoint already set (process uid %u)",
1580 __FUNCTION__, process.GetUniqueID());
1581 return;
1582 }
1583
1584 // We're about to do this, don't let anybody else try to do it.
1585 m_added_breakpoint = true;
1586 }
1587
1588 // Set a breakpoint for the process that will kick in when libtrace has
1589 // finished its initialization.
1590 Target &target = process.GetTarget();
1591
1592 // Build up the module list.
1593 FileSpecList module_spec_list;
1594 auto module_file_spec =
1595 FileSpec(GetGlobalProperties().GetLoggingModuleName());
1596 module_spec_list.Append(module_file_spec);
1597
1598 // We aren't specifying a source file set.
1599 FileSpecList *source_spec_list = nullptr;
1600
1601 const char *func_name = "_libtrace_init";
1602 const lldb::addr_t offset = 0;
1603 const LazyBool skip_prologue = eLazyBoolCalculate;
1604 // This is an internal breakpoint - the user shouldn't see it.
1605 const bool internal = true;
1606 const bool hardware = false;
1607
1608 auto breakpoint_sp = target.CreateBreakpoint(
1609 &module_spec_list, source_spec_list, func_name, eFunctionNameTypeFull,
1610 eLanguageTypeC, offset, skip_prologue, internal, hardware);
1611 if (!breakpoint_sp) {
1612 // Huh? Bail here.
1613 LLDB_LOGF(log,
1614 "StructuredDataDarwinLog::%s() failed to set "
1615 "breakpoint in module %s, function %s (process uid %u)",
1616 __FUNCTION__, GetGlobalProperties().GetLoggingModuleName(),
1617 func_name, process.GetUniqueID());
1618 return;
1619 }
1620
1621 // Set our callback.
1622 breakpoint_sp->SetCallback(InitCompletionHookCallback, nullptr);
1623 m_breakpoint_id = breakpoint_sp->GetID();
1624 LLDB_LOGF(log,
1625 "StructuredDataDarwinLog::%s() breakpoint set in module %s,"
1626 "function %s (process uid %u)",
1627 __FUNCTION__, GetGlobalProperties().GetLoggingModuleName(),
1628 func_name, process.GetUniqueID());
1629}
1630
1632 uint64_t timestamp) {
1633 const uint64_t delta_nanos = timestamp - m_first_timestamp_seen;
1634
1635 const uint64_t hours = delta_nanos / NANOS_PER_HOUR;
1636 uint64_t nanos_remaining = delta_nanos % NANOS_PER_HOUR;
1637
1638 const uint64_t minutes = nanos_remaining / NANOS_PER_MINUTE;
1639 nanos_remaining = nanos_remaining % NANOS_PER_MINUTE;
1640
1641 const uint64_t seconds = nanos_remaining / NANOS_PER_SECOND;
1642 nanos_remaining = nanos_remaining % NANOS_PER_SECOND;
1643
1644 stream.Printf("%02" PRIu64 ":%02" PRIu64 ":%02" PRIu64 ".%09" PRIu64, hours,
1645 minutes, seconds, nanos_remaining);
1646}
1647
1648size_t
1650 const StructuredData::Dictionary &event) {
1651 StreamString stream;
1652
1653 ProcessSP process_sp = GetProcess();
1654 if (!process_sp) {
1655 // TODO log
1656 return 0;
1657 }
1658
1659 DebuggerSP debugger_sp =
1660 process_sp->GetTarget().GetDebugger().shared_from_this();
1661 if (!debugger_sp) {
1662 // TODO log
1663 return 0;
1664 }
1665
1666 auto options_sp = GetGlobalEnableOptions(debugger_sp);
1667 if (!options_sp) {
1668 // TODO log
1669 return 0;
1670 }
1671
1672 // Check if we should even display a header.
1673 if (!options_sp->GetDisplayAnyHeaderFields())
1674 return 0;
1675
1676 stream.PutChar('[');
1677
1678 int header_count = 0;
1679 if (options_sp->GetDisplayTimestampRelative()) {
1680 uint64_t timestamp = 0;
1681 if (event.GetValueForKeyAsInteger("timestamp", timestamp)) {
1682 DumpTimestamp(stream, timestamp);
1683 ++header_count;
1684 }
1685 }
1686
1687 if (options_sp->GetDisplayActivityChain()) {
1688 llvm::StringRef activity_chain;
1689 if (event.GetValueForKeyAsString("activity-chain", activity_chain) &&
1690 !activity_chain.empty()) {
1691 if (header_count > 0)
1692 stream.PutChar(',');
1693
1694 // Display the activity chain, from parent-most to child-most activity,
1695 // separated by a colon (:).
1696 stream.PutCString("activity-chain=");
1697 stream.PutCString(activity_chain);
1698 ++header_count;
1699 }
1700 }
1701
1702 if (options_sp->GetDisplaySubsystem()) {
1703 llvm::StringRef subsystem;
1704 if (event.GetValueForKeyAsString("subsystem", subsystem) &&
1705 !subsystem.empty()) {
1706 if (header_count > 0)
1707 stream.PutChar(',');
1708 stream.PutCString("subsystem=");
1709 stream.PutCString(subsystem);
1710 ++header_count;
1711 }
1712 }
1713
1714 if (options_sp->GetDisplayCategory()) {
1715 llvm::StringRef category;
1716 if (event.GetValueForKeyAsString("category", category) &&
1717 !category.empty()) {
1718 if (header_count > 0)
1719 stream.PutChar(',');
1720 stream.PutCString("category=");
1721 stream.PutCString(category);
1722 ++header_count;
1723 }
1724 }
1725 stream.PutCString("] ");
1726
1727 output_stream.PutCString(stream.GetString());
1728
1729 return stream.GetSize();
1730}
1731
1733 const StructuredData::Dictionary &event, Stream &stream) {
1734 // Check the type of the event.
1735 llvm::StringRef event_type;
1736 if (!event.GetValueForKeyAsString("type", event_type)) {
1737 // Hmm, we expected to get events that describe what they are. Continue
1738 // anyway.
1739 return 0;
1740 }
1741
1742 if (event_type != GetLogEventType())
1743 return 0;
1744
1745 size_t total_bytes = 0;
1746
1747 // Grab the message content.
1748 llvm::StringRef message;
1749 if (!event.GetValueForKeyAsString("message", message))
1750 return true;
1751
1752 // Display the log entry.
1753 const auto len = message.size();
1754
1755 total_bytes += DumpHeader(stream, event);
1756
1757 stream.Write(message.data(), len);
1758 total_bytes += len;
1759
1760 // Add an end of line.
1761 stream.PutChar('\n');
1762 total_bytes += sizeof(char);
1763
1764 return total_bytes;
1765}
1766
1768 Log *log = GetLog(LLDBLog::Process);
1769 LLDB_LOGF(log, "StructuredDataDarwinLog::%s() called", __FUNCTION__);
1770
1771 // Run the enable command.
1772 auto process_sp = GetProcess();
1773 if (!process_sp) {
1774 // Nothing to do.
1775 LLDB_LOGF(log,
1776 "StructuredDataDarwinLog::%s() warning: failed to get "
1777 "valid process, skipping",
1778 __FUNCTION__);
1779 return;
1780 }
1781 LLDB_LOGF(log, "StructuredDataDarwinLog::%s() call is for process uid %u",
1782 __FUNCTION__, process_sp->GetUniqueID());
1783
1784 // If we have configuration data, we can directly enable it now. Otherwise,
1785 // we need to run through the command interpreter to parse the auto-run
1786 // options (which is the only way we get here without having already-parsed
1787 // configuration data).
1788 DebuggerSP debugger_sp =
1789 process_sp->GetTarget().GetDebugger().shared_from_this();
1790 if (!debugger_sp) {
1791 LLDB_LOGF(log,
1792 "StructuredDataDarwinLog::%s() warning: failed to get "
1793 "debugger shared pointer, skipping (process uid %u)",
1794 __FUNCTION__, process_sp->GetUniqueID());
1795 return;
1796 }
1797
1798 auto options_sp = GetGlobalEnableOptions(debugger_sp);
1799 if (!options_sp) {
1800 // We haven't run the enable command yet. Just do that now, it'll take
1801 // care of the rest.
1802 auto &interpreter = debugger_sp->GetCommandInterpreter();
1803 const bool success = RunEnableCommand(interpreter);
1804 if (log) {
1805 if (success)
1806 LLDB_LOGF(log,
1807 "StructuredDataDarwinLog::%s() ran enable command "
1808 "successfully for (process uid %u)",
1809 __FUNCTION__, process_sp->GetUniqueID());
1810 else
1811 LLDB_LOGF(log,
1812 "StructuredDataDarwinLog::%s() error: running "
1813 "enable command failed (process uid %u)",
1814 __FUNCTION__, process_sp->GetUniqueID());
1815 }
1816 Debugger::ReportError("failed to configure DarwinLog support",
1817 debugger_sp->GetID());
1818 return;
1819 }
1820
1821 // We've previously been enabled. We will re-enable now with the previously
1822 // specified options.
1823 auto config_sp = options_sp->BuildConfigurationData(true);
1824 if (!config_sp) {
1825 LLDB_LOGF(log,
1826 "StructuredDataDarwinLog::%s() warning: failed to "
1827 "build configuration data for enable options, skipping "
1828 "(process uid %u)",
1829 __FUNCTION__, process_sp->GetUniqueID());
1830 return;
1831 }
1832
1833 // We can run it directly.
1834 // Send configuration to the feature by way of the process.
1835 const Status error =
1836 process_sp->ConfigureStructuredData(GetDarwinLogTypeName(), config_sp);
1837
1838 // Report results.
1839 if (!error.Success()) {
1840 LLDB_LOGF(log,
1841 "StructuredDataDarwinLog::%s() "
1842 "ConfigureStructuredData() call failed "
1843 "(process uid %u): %s",
1844 __FUNCTION__, process_sp->GetUniqueID(), error.AsCString());
1845 Debugger::ReportError("failed to configure DarwinLog support",
1846 debugger_sp->GetID());
1847 m_is_enabled = false;
1848 } else {
1849 m_is_enabled = true;
1850 LLDB_LOGF(log,
1851 "StructuredDataDarwinLog::%s() success via direct "
1852 "configuration (process uid %u)",
1853 __FUNCTION__, process_sp->GetUniqueID());
1854 }
1855}
static llvm::raw_ostream & error(Stream &strm)
static DynamicLoaderDarwinKernelProperties & GetGlobalProperties()
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:369
#define LLDB_LOGF(log,...)
Definition: Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:392
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:32
static void SetErrorWithJSON(Status &error, const char *message, StructuredData::Object &object)
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:461
A command line argument class.
Definition: Args.h:33
void Shift()
Shifts the first argument C string value of the array off the argument array.
Definition: Args.cpp:295
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:120
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:273
bool HandleCommand(const char *command_line, LazyBool add_to_history, const ExecutionContext &override_context, CommandReturnObject &result)
CommandObject * GetCommandObjectForCommand(llvm::StringRef &command_line)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandInterpreter & GetCommandInterpreter()
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void void AppendWarning(llvm::StringRef in_string)
A class to manage flag bits.
Definition: Debugger.h:80
CommandInterpreter & GetCommandInterpreter()
Definition: Debugger.h:168
bool GetUseColor() const
Definition: Debugger.cpp:421
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
Definition: Debugger.cpp:1628
lldb::ThreadSP GetThreadSP() const
Get accessor that creates a strong reference from the weak thread reference contained in this object.
lldb::ProcessSP GetProcessSP() const
Get accessor that creates a strong reference from the weak process reference contained in this object...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file collection class.
Definition: FileSpecList.h:91
void Append(const FileSpec &file)
Append a FileSpec object to the list.
A file utility class.
Definition: FileSpec.h:56
bool AnySet(ValueType mask) const
Test one or more flags.
Definition: Flags.h:90
A collection class for Module objects.
Definition: ModuleList.h:103
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
Definition: ModuleList.cpp:429
size_t GetSize() const
Gets the size of the module list.
Definition: ModuleList.cpp:638
A command line option parsing protocol class.
Definition: Options.h:58
std::vector< Option > m_getopt_table
Definition: Options.h:198
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static lldb::OptionValuePropertiesSP GetSettingForPlatformPlugin(Debugger &debugger, llvm::StringRef setting_name)
static bool CreateSettingForStructuredDataPlugin(Debugger &debugger, const lldb::OptionValuePropertiesSP &properties_sp, llvm::StringRef description, bool is_global_property)
static bool UnregisterPlugin(ABICreateInstance create_callback)
Environment & GetEnvironment()
Definition: ProcessInfo.h:88
ArchSpec & GetArchitecture()
Definition: ProcessInfo.h:62
A plug-in interface definition class for debugging a process.
Definition: Process.h:343
void BroadcastStructuredData(const StructuredData::ObjectSP &object_sp, const lldb::StructuredDataPluginSP &plugin_sp)
Broadcasts the given structured data object from the given plugin.
Definition: Process.cpp:4534
uint32_t GetUniqueID() const
Definition: Process.h:549
Target & GetTarget()
Get the target object pointer for this module.
Definition: Process.h:1246
lldb::OptionValuePropertiesSP m_collection_sp
virtual lldb::OptionValueSP GetPropertyValue(const ExecutionContext *exe_ctx, llvm::StringRef property_path, Status &error) const
An error handling class.
Definition: Status.h:115
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:138
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition: Status.h:148
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition: Status.cpp:137
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
const char * GetData() const
Definition: StreamString.h:45
void Flush() override
Flush the stream.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition: Stream.h:112
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
size_t PutChar(char ch)
Definition: Stream.cpp:131
virtual void Flush()=0
Flush the stream.
Status GetDescription(const StructuredData::ObjectSP &object_sp, lldb_private::Stream &stream) override
Get a human-readable description of the contents of the data.
static void DebuggerInitialize(Debugger &debugger)
void DumpTimestamp(Stream &stream, uint64_t timestamp)
static bool InitCompletionHookCallback(void *baton, StoppointCallbackContext *context, lldb::user_id_t break_id, lldb::user_id_t break_loc_id)
StructuredDataDarwinLog(const lldb::ProcessWP &process_wp)
size_t HandleDisplayOfEvent(const StructuredData::Dictionary &event, Stream &stream)
void HandleArrivalOfStructuredData(Process &process, llvm::StringRef type_name, const StructuredData::ObjectSP &object_sp) override
Handle the arrival of asynchronous structured data from the process.
static lldb::StructuredDataPluginSP CreateInstance(Process &process)
static Status FilterLaunchInfo(ProcessLaunchInfo &launch_info, Target *target)
void EnableNow()
Call the enable command again, using whatever settings were initially made.
size_t DumpHeader(Stream &stream, const StructuredData::Dictionary &event)
void ModulesDidLoad(Process &process, ModuleList &module_list) override
Allow the plugin to do work related to modules that loaded in the the corresponding process.
bool GetEnabled(llvm::StringRef type_name) const override
Returns whether the plugin's features are enabled.
bool SupportsStructuredDataType(llvm::StringRef type_name) override
Return whether this plugin supports the given StructuredData feature.
Plugin that supports process-related structured data sent asynchronously from the debug monitor (e....
static void InitializeBasePluginForDebugger(Debugger &debugger)
Derived classes must call this before attempting to hook up commands to the 'plugin structured-data' ...
bool ForEach(std::function< bool(Object *object)> const &foreach_callback) const
void AddBooleanItem(llvm::StringRef key, bool value)
bool GetValueForKeyAsInteger(llvm::StringRef key, IntType &result) const
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
void AddStringItem(llvm::StringRef key, llvm::StringRef value)
bool GetValueForKeyAsArray(llvm::StringRef key, Array *&result) const
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< Array > ArraySP
Debugger & GetDebugger()
Definition: Target.h:1080
const lldb::ProcessSP & GetProcessSP() const
Definition: Target.cpp:297
lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, uint32_t column, lldb::addr_t offset, LazyBool check_inlines, LazyBool skip_prologue, bool internal, bool request_hardware, LazyBool move_to_nearest_code)
Definition: Target.cpp:472
const ArchSpec & GetArchitecture() const
Definition: Target.h:1039
This thread plan calls a function object when the current function exits.
std::function< void()> Callback
Definition for the callback made when the currently executing thread finishes executing its function.
Provides the darwin-log base command.
BaseCommand(CommandInterpreter &interpreter)
EnableCommand(CommandInterpreter &interpreter, bool enable, const char *name, const char *help, const char *syntax)
void DoExecute(Args &command, CommandReturnObject &result) override
void AppendStrictSourcesWarning(CommandReturnObject &result, const char *source_name)
Status ParseFilterRule(llvm::StringRef rule_text)
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
int MatchAttributeIndex(llvm::StringRef attribute_name) const
const FilterRules & GetFilterRules() const
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
StructuredData::DictionarySP BuildConfigurationData(bool enabled)
void OptionParsingStarting(ExecutionContext *execution_context) override
static FilterRuleSP CreateOperation(bool accept, size_t attribute_index, const std::string &op_arg, Status &error)
void DoSerialization(StructuredData::Dictionary &dict) const override
void Dump(Stream &stream) const override
ExactMatchFilterRule(bool accept, size_t attribute_index, const std::string &match_text)
static void RegisterOperation(llvm::StringRef operation, const OperationCreationFunc &creation_func)
static CreationFuncMap & GetCreationFuncMap()
llvm::StringMap< OperationCreationFunc > CreationFuncMap
FilterRule(bool accept, size_t attribute_index, llvm::StringRef operation)
virtual void Dump(Stream &stream) const =0
virtual void DoSerialization(StructuredData::Dictionary &dict) const =0
static FilterRuleSP CreateRule(bool match_accepts, size_t attribute, llvm::StringRef operation, const std::string &op_arg, Status &error)
StructuredData::ObjectSP Serialize() const
std::function< FilterRuleSP(bool accept, size_t attribute_index, const std::string &op_arg, Status &error)> OperationCreationFunc
static FilterRuleSP CreateOperation(bool accept, size_t attribute_index, const std::string &op_arg, Status &error)
void DoSerialization(StructuredData::Dictionary &dict) const override
RegexFilterRule(bool accept, size_t attribute_index, const std::string &regex_text)
void Dump(Stream &stream) const override
StatusCommand(CommandInterpreter &interpreter)
void DoExecute(Args &command, CommandReturnObject &result) override
#define LLDB_INVALID_BREAK_ID
Definition: lldb-defines.h:37
#define LLDB_OPT_SET_ALL
Definition: lldb-defines.h:110
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:332
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
Definition: lldb-forward.h:453
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:333
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:388
@ eLanguageTypeC
Non-standardized C, such as K&R.
std::shared_ptr< lldb_private::StructuredDataPlugin > StructuredDataPluginSP
Definition: lldb-forward.h:438
std::weak_ptr< lldb_private::Debugger > DebuggerWP
Definition: lldb-forward.h:340
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
std::shared_ptr< lldb_private::Debugger > DebuggerSP
Definition: lldb-forward.h:339
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
std::weak_ptr< lldb_private::Process > ProcessWP
Definition: lldb-forward.h:392
uint64_t user_id_t
Definition: lldb-types.h:82
uint64_t addr_t
Definition: lldb-types.h:80
EnableOptionsSP GetGlobalEnableOptions(const DebuggerSP &debugger_sp)
std::map< DebuggerWP, EnableOptionsSP, std::owner_less< DebuggerWP > > OptionsMap
static OptionsMap & GetGlobalOptionsMap()
const char *const s_filter_attributes[]
bool RunEnableCommand(CommandInterpreter &interpreter)
static llvm::StringRef GetLogEventType()
void SetGlobalEnableOptions(const DebuggerSP &debugger_sp, const EnableOptionsSP &options_sp)
static bool s_is_explicitly_enabled
Global, sticky enable switch.
static bool DEFAULT_FILTER_FALLTHROUGH_ACCEPTS
static std::mutex & GetGlobalOptionsMapLock()
std::shared_ptr< FilterRule > FilterRuleSP
static llvm::StringRef GetDarwinLogTypeName()
std::vector< FilterRuleSP > FilterRules
std::shared_ptr< EnableOptions > EnableOptionsSP
static constexpr OptionDefinition g_enable_option_table[]
Provides the main on-off switch for enabling darwin logging.
static StructuredDataDarwinLogProperties & GetGlobalProperties()
EnableOptionsSP ParseAutoEnableOptions(Status &error, Debugger &debugger)
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)