35#define DARWIN_LOG_TYPE_VALUE "DarwinLog"
43#pragma mark Anonymous Namespace
67 std::map<DebuggerWP, EnableOptionsSP, std::owner_less<DebuggerWP>>;
75 static std::mutex s_options_map_lock;
76 return s_options_map_lock;
85 DebuggerWP debugger_wp(debugger_sp);
86 auto find_it = options_map.find(debugger_wp);
87 if (find_it != options_map.end())
88 return find_it->second;
97 DebuggerWP debugger_wp(debugger_sp);
98 auto find_it = options_map.find(debugger_wp);
99 if (find_it != options_map.end())
100 find_it->second = options_sp;
102 options_map.insert(std::make_pair(debugger_wp, options_sp));
106#pragma mark Settings Handling
110#define LLDB_PROPERTIES_darwinlog
111#include "StructuredDataDarwinLogProperties.inc"
114#define LLDB_PROPERTIES_darwinlog
115#include "StructuredDataDarwinLogPropertiesEnum.inc"
122 return g_setting_name;
133 const uint32_t idx = ePropertyEnableOnStartup;
134 return GetPropertyAtIndexAs<bool>(
135 idx, g_darwinlog_properties[idx].default_uint_value != 0);
139 const uint32_t idx = ePropertyAutoEnableOptions;
140 return GetPropertyAtIndexAs<llvm::StringRef>(
141 idx, g_darwinlog_properties[idx].default_cstr_value);
166 static constexpr llvm::StringLiteral s_key_name(
"DarwinLog");
171 static constexpr llvm::StringLiteral s_event_type(
"log");
183 std::function<
FilterRuleSP(
bool accept,
size_t attribute_index,
196 auto find_it = map.find(operation);
197 if (find_it == map.end()) {
198 error.SetErrorStringWithFormat(
"unknown filter operation \""
204 return find_it->second(match_accepts, attribute, op_arg,
error);
278 const std::string &op_arg,
281 if (op_arg.empty()) {
282 error.SetErrorString(
"regex filter type requires a regex "
289 if (llvm::Error err = regex.GetError()) {
290 error.SetErrorString(llvm::toString(std::move(err)));
305 const std::string ®ex_text)
330 const std::string &op_arg,
332 if (op_arg.empty()) {
333 error.SetErrorString(
"exact match filter type requires an "
334 "argument containing the text that must "
335 "match the specified message attribute.");
350 const std::string &match_text)
377 "Specifies log messages from other related processes should be "
381 "Specifies debug-level log messages should be included. Specifying"
382 " --debug implies --info."},
385 "Specifies info-level log messages should be included."},
392 "Appends a filter rule to the log message filter chain. Multiple "
393 "rules may be added by specifying this option multiple times, "
394 "once per filter rule. Filter rules are processed in the order "
395 "they are specified, with the --no-match-accepts setting used "
396 "for any message that doesn't match one of the rules.\n"
398 " Filter spec format:\n"
400 " --filter \"{action} {attribute} {op}\"\n"
407 " activity | // message's most-derived activity\n"
408 " activity-chain | // message's {parent}:{child} activity\n"
409 " category | // message's category\n"
410 " message | // message's expanded contents\n"
411 " subsystem | // message's subsystem\n"
414 " match {exact-match-text} |\n"
415 " regex {search-regex}\n"
417 "The regex flavor used is the C++ std::regex ECMAScript format. "
418 "Prefer character classes like [[:digit:]] to \\d and the like, as "
419 "getting the backslashes escaped through properly is error-prone."},
422 "Specify whether logging events are live-streamed or buffered. "
423 "True indicates live streaming, false indicates buffered. The "
424 "default is true (live streaming). Live streaming will deliver "
425 "log messages with less delay, but buffered capture mode has less "
426 "of an observer effect."},
429 "Specify whether a log message that doesn't match any filter rule "
430 "is accepted or rejected, where true indicates accept. The "
434 "Specify whether os_log()/NSLog() messages are echoed to the "
435 "target program's stderr. When DarwinLog is enabled, we shut off "
436 "the mirroring of os_log()/NSLog() to the program's stderr. "
437 "Setting this flag to true will restore the stderr mirroring."
438 "The default is false."},
441 "Specify if the plugin should broadcast events. Broadcasting "
442 "log events is a requirement for displaying the log entries in "
443 "LLDB command-line. It is also required if LLDB clients want to "
444 "process log events. The default is true."},
448 "Include timestamp in the message header when printing a log "
449 "message. The timestamp is relative to the first displayed "
453 "Include the subsystem in the message header when displaying "
457 "Include the category in the message header when displaying "
461 "Include the activity parent-child chain in the message header "
462 "when displaying a log message. The activity hierarchy is "
463 "displayed as {grandparent-activity}:"
464 "{parent-activity}:{activity}[:...]."},
467 "Shortcut to specify that all header fields should be displayed."}};
496 switch (short_option) {
554 error.SetErrorStringWithFormat(
"unsupported option '%c'", short_option);
567 config_sp->AddBooleanItem(
"enabled", enabled);
574 auto source_flags_sp =
576 config_sp->AddItem(
"source-flags", source_flags_sp);
583 source_flags_sp->AddBooleanItem(
"live-stream",
m_live_stream);
586 config_sp->AddBooleanItem(
"filter-fall-through-accepts",
591 auto json_filter_rules_sp =
593 config_sp->AddItem(
"filter-rules", json_filter_rules_sp);
597 json_filter_rules_sp->AddItem(rule_sp->Serialize());
635 if (rule_text.empty()) {
636 error.SetErrorString(
"invalid rule_text");
661 auto action_end_pos = rule_text.find(
' ');
662 if (action_end_pos == std::string::npos) {
663 error.SetErrorStringWithFormat(
"could not parse filter rule "
664 "action from \"%s\"",
665 rule_text.str().c_str());
668 auto action = rule_text.substr(0, action_end_pos);
670 if (action ==
"accept")
672 else if (action ==
"reject")
675 error.SetErrorString(
"filter action must be \"accept\" or \"deny\"");
680 auto attribute_end_pos = rule_text.find(
" ", action_end_pos + 1);
681 if (attribute_end_pos == std::string::npos) {
682 error.SetErrorStringWithFormat(
"could not parse filter rule "
683 "attribute from \"%s\"",
684 rule_text.str().c_str());
687 auto attribute = rule_text.substr(action_end_pos + 1,
688 attribute_end_pos - (action_end_pos + 1));
690 if (attribute_index < 0) {
691 error.SetErrorStringWithFormat(
"filter rule attribute unknown: "
693 attribute.str().c_str());
698 auto operation_end_pos = rule_text.find(
" ", attribute_end_pos + 1);
699 auto operation = rule_text.substr(
700 attribute_end_pos + 1, operation_end_pos - (attribute_end_pos + 1));
705 std::string(rule_text.substr(operation_end_pos + 1)),
error);
707 if (rule_sp &&
error.Success())
715 if (attribute_name == Item.value())
740 const char *help,
const char *syntax)
746 const char *source_name) {
756 stream.
Printf(
"darwin-log source settings specify to exclude "
757 "%s messages, but setting "
758 "'plugin.structured-data.darwin-log."
759 "strict-sources' is disabled. This process will "
760 "automatically have %s messages included. Enable"
761 " the property and relaunch the target binary to have"
762 " these messages excluded.",
763 source_name, source_name);
777 DebuggerSP debugger_sp =
796 if (!process_sp->IsAlive()) {
802 auto plugin_sp = process_sp->GetStructuredDataPlugin(
804 if (!plugin_sp || (plugin_sp->GetPluginName() !=
806 result.
AppendError(
"failed to get StructuredDataPlugin for "
825 const Status error = process_sp->ConfigureStructuredData(
829 if (!
error.Success()) {
857 "Show whether Darwin log supported is available"
859 "plugin structured-data darwin-log status") {}
870 stream.PutCString(
"Availability: unknown (requires process)\n");
871 stream.PutCString(
"Enabled: not applicable "
872 "(requires process)\n");
874 auto plugin_sp = process_sp->GetStructuredDataPlugin(
876 stream.Printf(
"Availability: %s\n",
877 plugin_sp ?
"available" :
"unavailable");
880 plugin_sp ? plugin_sp->GetEnabled(
ConstString(plugin_name)) :
false;
881 stream.Printf(
"Enabled: %s\n", enabled ?
"true" :
"false");
885 DebuggerSP debugger_sp =
895 stream.PutCString(
"DarwinLog filter rules:\n");
899 if (options_sp->GetFilterRules().empty()) {
901 stream.PutCString(
"none\n");
905 for (
auto rule_sp : options_sp->GetFilterRules()) {
911 stream.Printf(
"%02d: ", rule_number);
912 rule_sp->Dump(stream);
913 stream.PutChar(
'\n');
920 stream.Printf(
"no-match behavior: %s\n",
921 options_sp->GetFallthroughAccepts() ?
"accept" :
"reject");
933 "Commands for configuring Darwin os_log "
937 auto enable_help =
"Enable Darwin log collection, or re-enable "
938 "with modified configuration.";
939 auto enable_syntax =
"plugin structured-data darwin-log enable";
940 auto enable_cmd_sp = CommandObjectSP(
943 "enable", enable_help, enable_syntax));
947 auto disable_help =
"Disable Darwin log collection.";
948 auto disable_syntax =
"plugin structured-data darwin-log disable";
949 auto disable_cmd_sp = CommandObjectSP(
952 "disable", disable_help, disable_syntax));
956 auto status_cmd_sp = CommandObjectSP(
new StatusCommand(interpreter));
972 options_sp->NotifyOptionParsingStarting(&exe_ctx);
977 auto options_property_sp =
979 "plugin.structured-data.darwin-log."
980 "auto-enable-options",
982 if (!
error.Success())
984 if (!options_property_sp) {
985 error.SetErrorString(
"failed to find option setting for "
986 "plugin.structured-data.darwin-log.");
990 const char *enable_options =
991 options_property_sp->GetAsString()->GetCurrentValue();
992 Args args(enable_options);
997 if (first_arg && (strcmp(first_arg,
"--") == 0))
1001 bool require_validation =
false;
1002 llvm::Expected<Args> args_or =
1003 options_sp->Parse(args, &exe_ctx, PlatformSP(), require_validation);
1006 log, args_or.takeError(),
1007 "Parsing plugin.structured-data.darwin-log.auto-enable-options value "
1012 if (!options_sp->VerifyOptions(result))
1022 command_stream <<
"plugin structured-data darwin-log enable";
1024 if (!enable_options.empty()) {
1025 command_stream <<
' ';
1026 command_stream << enable_options;
1039#pragma mark Public static API
1055#pragma mark StructuredDataPlugin API
1071 object_sp->Dump(json_stream);
1074 LLDB_LOGF(log,
"StructuredDataDarwinLog::%s() called with json: %s",
1075 __FUNCTION__, json_stream.
GetData());
1081 "StructuredDataDarwinLog::%s() StructuredData object "
1090 "StructuredDataDarwinLog::%s() StructuredData type "
1091 "expected to be %s but was %s, ignoring",
1102 if (options_sp && options_sp->GetBroadcastEvents()) {
1103 LLDB_LOGF(log,
"StructuredDataDarwinLog::%s() broadcasting event",
1115 error.SetErrorString(
"Internal error: message not set.");
1120 object.Dump(object_stream);
1121 object_stream.
Flush();
1123 error.SetErrorStringWithFormat(
"%s: %s", message, object_stream.
GetData());
1131 error.SetErrorString(
"No structured data.");
1145 llvm::StringRef type_name;
1156 object_sp->Dump(stream);
1165 "'events' field, expected to be an array",
1178 auto event =
object->GetAsDictionary();
1188 uint64_t timestamp = 0;
1189 if (event->GetValueForKeyAsInteger(
"timestamp", timestamp)) {
1217 LLDB_LOGF(log,
"StructuredDataDarwinLog::%s called (process uid %u)",
1226 "StructuredDataDarwinLog::%s not applicable, we're not "
1227 "enabled (process uid %u)",
1237 "StructuredDataDarwinLog::%s process uid %u's "
1238 "post-libtrace-init breakpoint is already set",
1247 const char *logging_module_cstr =
1249 if (!logging_module_cstr || (logging_module_cstr[0] == 0)) {
1252 "StructuredDataDarwinLog::%s no logging module name "
1253 "specified, we don't know where to set a breakpoint "
1263 bool found_logging_support_module =
false;
1264 for (
size_t i = 0; i < module_list.
GetSize(); ++i) {
1269 auto &file_spec = module_sp->GetFileSpec();
1270 found_logging_support_module =
1271 (file_spec.GetFilename() == logging_module_name);
1272 if (found_logging_support_module)
1276 if (!found_logging_support_module) {
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_name.
AsCString(),
1290 "StructuredDataDarwinLog::%s post-init hook breakpoint "
1291 "set for logging module %s (process uid %u)",
1292 __FUNCTION__, logging_module_name.
AsCString(),
1318#pragma mark Private instance methods
1324 m_first_timestamp_seen(0), m_is_enabled(false),
1325 m_added_breakpoint_mutex(), m_added_breakpoint(),
1330StructuredDataPluginSP
1334 llvm::Triple::VendorType::Apple) {
1335 auto process_wp = ProcessWP(process.shared_from_this());
1338 return StructuredDataPluginSP();
1348 llvm::StringRef parent_command_text =
"plugin structured-data";
1349 auto parent_command =
1351 if (!parent_command) {
1357 auto command_name =
"darwin-log";
1358 auto command_sp = CommandObjectSP(
new BaseCommand(interpreter));
1359 bool result = parent_command->LoadSubCommand(command_name, command_sp);
1366 const bool is_global_setting =
true;
1369 "Properties for the darwin-log plug-in.", is_global_setting);
1397 if (triple.getVendor() != llvm::Triple::Apple) {
1415 error.SetErrorString(
"requires a target to auto-enable DarwinLog.");
1419 DebuggerSP debugger_sp = target->
GetDebugger().shared_from_this();
1421 if (!options_sp && debugger_sp) {
1423 if (!options_sp || !
error.Success())
1431 if (!options_sp->GetEchoToStdErr()) {
1443 launch_info.
GetEnvironment()[
"IDE_DISABLED_OS_ACTIVITY_DT_MODE"] =
"1";
1448 const char *env_var_value;
1449 if (options_sp->GetIncludeDebugLevel())
1450 env_var_value =
"debug";
1451 else if (options_sp->GetIncludeInfoLevel())
1452 env_var_value =
"info";
1454 env_var_value =
"default";
1456 launch_info.
GetEnvironment()[
"OS_ACTIVITY_MODE"] = env_var_value;
1470 LLDB_LOGF(log,
"StructuredDataDarwinLog::%s() called", __FUNCTION__);
1475 "StructuredDataDarwinLog::%s() warning: no context, "
1485 "StructuredDataDarwinLog::%s() warning: invalid "
1486 "process in context, ignoring",
1490 LLDB_LOGF(log,
"StructuredDataDarwinLog::%s() call is for process uid %d",
1491 __FUNCTION__, process_sp->GetUniqueID());
1496 LLDB_LOG(log,
"warning: no plugin for feature {0} in process uid {1}",
1502 bool called_enable_method =
false;
1503 const auto process_uid = process_sp->GetUniqueID();
1505 std::weak_ptr<StructuredDataPlugin> plugin_wp(plugin_sp);
1507 [plugin_wp, &called_enable_method, log, process_uid]() {
1509 "StructuredDataDarwinLog::post-init callback: "
1510 "called (process uid %u)",
1513 auto strong_plugin_sp = plugin_wp.lock();
1514 if (!strong_plugin_sp) {
1516 "StructuredDataDarwinLog::post-init callback: "
1517 "plugin no longer exists, ignoring (process "
1524 if (!called_enable_method) {
1526 "StructuredDataDarwinLog::post-init callback: "
1527 "calling EnableNow() (process uid %u)",
1531 called_enable_method =
true;
1536 "StructuredDataDarwinLog::post-init callback: "
1537 "skipping EnableNow(), already called by "
1538 "callback [we hit this more than once] "
1548 "StructuredDataDarwinLog::%s() warning: failed to "
1549 "retrieve the current thread from the execution "
1550 "context, nowhere to run the thread plan (process uid "
1552 __FUNCTION__, process_sp->GetUniqueID());
1557 auto thread_plan_sp =
1559 const bool abort_other_plans =
false;
1560 thread_sp->QueueThreadPlan(thread_plan_sp, abort_other_plans);
1562 "StructuredDataDarwinLog::%s() queuing thread plan on "
1563 "trace library init method entry (process uid %u)",
1564 __FUNCTION__, process_sp->GetUniqueID());
1572 LLDB_LOGF(log,
"StructuredDataDarwinLog::%s() called (process uid %u)",
1580 "StructuredDataDarwinLog::%s() ignoring request, "
1581 "breakpoint already set (process uid %u)",
1596 auto module_file_spec =
1598 module_spec_list.
Append(module_file_spec);
1603 const char *func_name =
"_libtrace_init";
1607 const bool internal =
true;
1608 const bool hardware =
false;
1611 &module_spec_list, source_spec_list, func_name, eFunctionNameTypeFull,
1613 if (!breakpoint_sp) {
1616 "StructuredDataDarwinLog::%s() failed to set "
1617 "breakpoint in module %s, function %s (process uid %u)",
1627 "StructuredDataDarwinLog::%s() breakpoint set in module %s,"
1628 "function %s (process uid %u)",
1634 uint64_t timestamp) {
1646 stream.
Printf(
"%02" PRIu64
":%02" PRIu64
":%02" PRIu64
".%09" PRIu64, hours,
1647 minutes, seconds, nanos_remaining);
1661 DebuggerSP debugger_sp =
1662 process_sp->GetTarget().GetDebugger().shared_from_this();
1675 if (!options_sp->GetDisplayAnyHeaderFields())
1680 int header_count = 0;
1681 if (options_sp->GetDisplayTimestampRelative()) {
1682 uint64_t timestamp = 0;
1689 if (options_sp->GetDisplayActivityChain()) {
1690 llvm::StringRef activity_chain;
1692 !activity_chain.empty()) {
1693 if (header_count > 0)
1704 if (options_sp->GetDisplaySubsystem()) {
1705 llvm::StringRef subsystem;
1707 !subsystem.empty()) {
1708 if (header_count > 0)
1716 if (options_sp->GetDisplayCategory()) {
1717 llvm::StringRef category;
1719 !category.empty()) {
1720 if (header_count > 0)
1737 llvm::StringRef event_type;
1747 size_t total_bytes = 0;
1750 llvm::StringRef message;
1755 const auto len = message.size();
1759 stream.
Write(message.data(), len);
1764 total_bytes +=
sizeof(char);
1771 LLDB_LOGF(log,
"StructuredDataDarwinLog::%s() called", __FUNCTION__);
1778 "StructuredDataDarwinLog::%s() warning: failed to get "
1779 "valid process, skipping",
1783 LLDB_LOGF(log,
"StructuredDataDarwinLog::%s() call is for process uid %u",
1784 __FUNCTION__, process_sp->GetUniqueID());
1790 DebuggerSP debugger_sp =
1791 process_sp->GetTarget().GetDebugger().shared_from_this();
1794 "StructuredDataDarwinLog::%s() warning: failed to get "
1795 "debugger shared pointer, skipping (process uid %u)",
1796 __FUNCTION__, process_sp->GetUniqueID());
1804 auto &interpreter = debugger_sp->GetCommandInterpreter();
1809 "StructuredDataDarwinLog::%s() ran enable command "
1810 "successfully for (process uid %u)",
1811 __FUNCTION__, process_sp->GetUniqueID());
1814 "StructuredDataDarwinLog::%s() error: running "
1815 "enable command failed (process uid %u)",
1816 __FUNCTION__, process_sp->GetUniqueID());
1819 debugger_sp->GetID());
1825 auto config_sp = options_sp->BuildConfigurationData(
true);
1828 "StructuredDataDarwinLog::%s() warning: failed to "
1829 "build configuration data for enable options, skipping "
1831 __FUNCTION__, process_sp->GetUniqueID());
1837 const Status error = process_sp->ConfigureStructuredData(
1841 if (!
error.Success()) {
1843 "StructuredDataDarwinLog::%s() "
1844 "ConfigureStructuredData() call failed "
1845 "(process uid %u): %s",
1846 __FUNCTION__, process_sp->GetUniqueID(),
error.AsCString());
1848 debugger_sp->GetID());
1853 "StructuredDataDarwinLog::%s() success via direct "
1854 "configuration (process uid %u)",
1855 __FUNCTION__, process_sp->GetUniqueID());
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.
#define LLDB_LOGF(log,...)
#define LLDB_LOG_ERROR(log, error,...)
#define LLDB_PLUGIN_DEFINE(PluginName)
static void SetErrorWithJSON(Status &error, const char *message, StructuredData::Object &object)
llvm::Triple & GetTriple()
Architecture triple accessor.
A command line argument class.
void Shift()
Shifts the first argument C string value of the array off the argument array.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
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()
Target & GetSelectedOrDummyTarget(bool prefer_dummy=false)
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void void AppendWarning(llvm::StringRef in_string)
Stream & GetOutputStream()
A uniqued constant string class.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const char * GetCString() const
Get the string value as a C string.
A class to manage flag bits.
CommandInterpreter & GetCommandInterpreter()
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
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.
void Append(const FileSpec &file)
Append a FileSpec object to the list.
bool AnySet(ValueType mask) const
Test one or more flags.
A collection class for Module objects.
lldb::ModuleSP GetModuleAtIndex(size_t idx) const
Get the module shared pointer for the module at index idx.
size_t GetSize() const
Gets the size of the module list.
A command line option parsing protocol class.
std::vector< Option > m_getopt_table
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static lldb::OptionValuePropertiesSP GetSettingForPlatformPlugin(Debugger &debugger, ConstString 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()
ArchSpec & GetArchitecture()
A plug-in interface definition class for debugging a process.
void BroadcastStructuredData(const StructuredData::ObjectSP &object_sp, const lldb::StructuredDataPluginSP &plugin_sp)
Broadcasts the given structured data object from the given plugin.
uint32_t GetUniqueID() const
Target & GetTarget()
Get the target object pointer for this module.
lldb::OptionValuePropertiesSP m_collection_sp
virtual lldb::OptionValueSP GetPropertyValue(const ExecutionContext *exe_ctx, llvm::StringRef property_path, Status &error) const
General Outline: When we hit a breakpoint we need to package up whatever information is needed to eva...
ExecutionContextRef exe_ctx_ref
const char * GetData() const
void Flush() override
Flush the stream.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
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.
bool GetEnabled(ConstString type_name) const override
Returns whether the plugin's features are enabled.
static void DebuggerInitialize(Debugger &debugger)
bool SupportsStructuredDataType(ConstString type_name) override
Return whether this plugin supports the given StructuredData feature.
void HandleArrivalOfStructuredData(Process &process, ConstString type_name, const StructuredData::ObjectSP &object_sp) override
Handle the arrival of asynchronous structured data from the process.
lldb::user_id_t m_breakpoint_id
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)
void AddInitCompletionHook(Process &process)
StructuredDataDarwinLog(const lldb::ProcessWP &process_wp)
std::mutex m_added_breakpoint_mutex
size_t HandleDisplayOfEvent(const StructuredData::Dictionary &event, Stream &stream)
static lldb::StructuredDataPluginSP CreateInstance(Process &process)
bool m_recorded_first_timestamp
static llvm::StringRef GetStaticPluginName()
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.
~StructuredDataDarwinLog() override
void SetEnabled(bool enabled)
uint64_t m_first_timestamp_seen
Plugin that supports process-related structured data sent asynchronously from the debug monitor (e....
lldb::ProcessSP GetProcess() const
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
Dictionary * GetAsDictionary()
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
std::shared_ptr< Array > ArraySP
const lldb::ProcessSP & GetProcessSP() const
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)
const ArchSpec & GetArchitecture() const
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)
Options * GetOptions() override
void AppendStrictSourcesWarning(CommandReturnObject &result, const char *source_name)
bool DoExecute(Args &command, CommandReturnObject &result) override
EnableOptionsSP m_options_sp
bool GetDisplayActivityChain() const
Status ParseFilterRule(llvm::StringRef rule_text)
bool GetDisplayTimestampRelative() const
bool GetEchoToStdErr() const
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
bool GetIncludeInfoLevel() const
bool GetDisplaySubsystem() const
bool m_include_info_level
int MatchAttributeIndex(llvm::StringRef attribute_name) const
bool GetBroadcastEvents() const
bool m_include_any_process
bool m_filter_fall_through_accepts
const FilterRules & GetFilterRules() const
bool m_include_debug_level
bool m_display_timestamp_relative
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
FilterRules m_filter_rules
StructuredData::DictionarySP BuildConfigurationData(bool enabled)
bool m_display_activity_chain
bool GetFallthroughAccepts() const
void OptionParsingStarting(ExecutionContext *execution_context) override
bool GetDisplayAnyHeaderFields() const
bool GetIncludeDebugLevel() const
bool GetDisplayCategory() const
const std::string m_match_text
static ConstString StaticGetOperation()
static void RegisterOperation()
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)
virtual ~FilterRule()=default
const ConstString m_operation
bool GetMatchAccepts() const
static CreationFuncMap & GetCreationFuncMap()
ConstString GetOperationType() const
virtual void Dump(Stream &stream) const =0
FilterRule(bool accept, size_t attribute_index, ConstString operation)
const char * GetFilterAttribute() const
virtual void DoSerialization(StructuredData::Dictionary &dict) const =0
static void RegisterOperation(ConstString operation, const OperationCreationFunc &creation_func)
StructuredData::ObjectSP Serialize() const
const size_t m_attribute_index
std::map< ConstString, OperationCreationFunc > CreationFuncMap
static FilterRuleSP CreateRule(bool match_accepts, size_t attribute, ConstString operation, const std::string &op_arg, Status &error)
std::function< FilterRuleSP(bool accept, size_t attribute_index, const std::string &op_arg, Status &error)> OperationCreationFunc
static void RegisterOperation()
const std::string m_regex_text
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 ®ex_text)
static ConstString StaticGetOperation()
void Dump(Stream &stream) const override
Provides the status command.
bool DoExecute(Args &command, CommandReturnObject &result) override
StatusCommand(CommandInterpreter &interpreter)
const char * GetLoggingModuleName() const
StructuredDataDarwinLogProperties()
bool GetEnableOnStartup() const
llvm::StringRef GetAutoEnableOptions() const
~StructuredDataDarwinLogProperties() override=default
static ConstString & GetSettingName()
#define LLDB_INVALID_BREAK_ID
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.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
const uint64_t NANOS_PER_MILLI
EnableOptionsSP GetGlobalEnableOptions(const DebuggerSP &debugger_sp)
std::map< DebuggerWP, EnableOptionsSP, std::owner_less< DebuggerWP > > OptionsMap
const uint64_t NANOS_PER_SECOND
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.
const uint64_t NANOS_PER_HOUR
static bool DEFAULT_FILTER_FALLTHROUGH_ACCEPTS
static std::mutex & GetGlobalOptionsMapLock()
const uint64_t NANOS_PER_MINUTE
std::shared_ptr< FilterRule > FilterRuleSP
const uint64_t NANOS_PER_MICRO
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()
static void RegisterFilterOperations()
EnableOptionsSP ParseAutoEnableOptions(Status &error, Debugger &debugger)
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)