diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:51:52 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:51:52 +0000 |
| commit | 5f29bb8a675e8f96452b632e7129113f7dec850e (patch) | |
| tree | 3d3f2a0d3ad10872a4dcaba8ec8d1d20c87ab147 /source/Plugins/StructuredData/DarwinLog | |
| parent | 88c643b6fec27eec436c8d138fee6346e92337d6 (diff) | |
Notes
Diffstat (limited to 'source/Plugins/StructuredData/DarwinLog')
| -rw-r--r-- | source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp | 72 | ||||
| -rw-r--r-- | source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h | 39 |
2 files changed, 32 insertions, 79 deletions
diff --git a/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp b/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp index 6e3792bff9c4..81a27125c036 100644 --- a/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp +++ b/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp @@ -1,18 +1,16 @@ //===-- StructuredDataDarwinLog.cpp -----------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "StructuredDataDarwinLog.h" -// C includes #include <string.h> -// C++ includes +#include <memory> #include <sstream> #include "lldb/Breakpoint/StoppointCallbackContext.h" @@ -41,9 +39,7 @@ using namespace lldb_private; #pragma mark - #pragma mark Anonymous Namespace -// ----------------------------------------------------------------------------- // Anonymous namespace -// ----------------------------------------------------------------------------- namespace sddarwinlog_private { const uint64_t NANOS_PER_MICRO = 1000; @@ -54,13 +50,11 @@ const uint64_t NANOS_PER_HOUR = NANOS_PER_MINUTE * 60; static bool DEFAULT_FILTER_FALLTHROUGH_ACCEPTS = true; -//------------------------------------------------------------------ /// Global, sticky enable switch. If true, the user has explicitly /// run the enable command. When a process launches or is attached to, /// we will enable DarwinLog if either the settings for auto-enable is /// on, or if the user had explicitly run enable at some point prior /// to the launch/attach. -//------------------------------------------------------------------ static bool s_is_explicitly_enabled; class EnableOptions; @@ -108,9 +102,7 @@ void SetGlobalEnableOptions(const DebuggerSP &debugger_sp, #pragma mark - #pragma mark Settings Handling -//------------------------------------------------------------------ /// Code to handle the StructuredDataDarwinLog settings -//------------------------------------------------------------------ static constexpr PropertyDefinition g_properties[] = { { @@ -145,11 +137,11 @@ public: } StructuredDataDarwinLogProperties() : Properties() { - m_collection_sp.reset(new OptionValueProperties(GetSettingName())); + m_collection_sp = std::make_shared<OptionValueProperties>(GetSettingName()); m_collection_sp->Initialize(g_properties); } - virtual ~StructuredDataDarwinLogProperties() {} + ~StructuredDataDarwinLogProperties() override {} bool GetEnableOnStartup() const { const uint32_t idx = ePropertyEnableOnStartup; @@ -172,7 +164,7 @@ using StructuredDataDarwinLogPropertiesSP = static const StructuredDataDarwinLogPropertiesSP &GetGlobalProperties() { static StructuredDataDarwinLogPropertiesSP g_settings_sp; if (!g_settings_sp) - g_settings_sp.reset(new StructuredDataDarwinLogProperties()); + g_settings_sp = std::make_shared<StructuredDataDarwinLogProperties>(); return g_settings_sp; } @@ -189,12 +181,12 @@ const char *const s_filter_attributes[] = { // used to format message text }; -static const ConstString &GetDarwinLogTypeName() { +static ConstString GetDarwinLogTypeName() { static const ConstString s_key_name("DarwinLog"); return s_key_name; } -static const ConstString &GetLogEventType() { +static ConstString GetLogEventType() { static const ConstString s_event_type("log"); return s_event_type; } @@ -210,13 +202,13 @@ public: std::function<FilterRuleSP(bool accept, size_t attribute_index, const std::string &op_arg, Status &error)>; - static void RegisterOperation(const ConstString &operation, + static void RegisterOperation(ConstString operation, const OperationCreationFunc &creation_func) { GetCreationFuncMap().insert(std::make_pair(operation, creation_func)); } static FilterRuleSP CreateRule(bool match_accepts, size_t attribute, - const ConstString &operation, + ConstString operation, const std::string &op_arg, Status &error) { // Find the creation func for this type of filter rule. auto map = GetCreationFuncMap(); @@ -254,10 +246,10 @@ public: virtual void Dump(Stream &stream) const = 0; - const ConstString &GetOperationType() const { return m_operation; } + ConstString GetOperationType() const { return m_operation; } protected: - FilterRule(bool accept, size_t attribute_index, const ConstString &operation) + FilterRule(bool accept, size_t attribute_index, ConstString operation) : m_accept(accept), m_attribute_index(attribute_index), m_operation(operation) {} @@ -326,7 +318,7 @@ private: return FilterRuleSP(new RegexFilterRule(accept, attribute_index, op_arg)); } - static const ConstString &StaticGetOperation() { + static ConstString StaticGetOperation() { static ConstString s_operation("regex"); return s_operation; } @@ -371,7 +363,7 @@ private: new ExactMatchFilterRule(accept, attribute_index, op_arg)); } - static const ConstString &StaticGetOperation() { + static ConstString StaticGetOperation() { static ConstString s_operation("match"); return s_operation; } @@ -393,12 +385,10 @@ static void RegisterFilterOperations() { // Commands // ========================================================================= -// ------------------------------------------------------------------------- /// Provides the main on-off switch for enabling darwin logging. /// /// It is valid to run the enable command when logging is already enabled. /// This resets the logging with whatever settings are currently set. -// ------------------------------------------------------------------------- static constexpr OptionDefinition g_enable_option_table[] = { // Source stream include/exclude options (the first-level filter). This one @@ -858,7 +848,7 @@ protected: // that logging be enabled for a process before libtrace is initialized // results in a scenario where no errors occur, but no logging is // captured, either. This step is to eliminate that possibility. - plugin.AddInitCompletionHook(*process_sp.get()); + plugin.AddInitCompletionHook(*process_sp); } // Send configuration to the feature by way of the process. Construct the @@ -892,9 +882,7 @@ private: EnableOptionsSP m_options_sp; }; -// ------------------------------------------------------------------------- /// Provides the status command. -// ------------------------------------------------------------------------- class StatusCommand : public CommandObjectParsed { public: StatusCommand(CommandInterpreter &interpreter) @@ -920,7 +908,7 @@ protected: process_sp->GetStructuredDataPlugin(GetDarwinLogTypeName()); stream.Printf("Availability: %s\n", plugin_sp ? "available" : "unavailable"); - auto &plugin_name = StructuredDataDarwinLog::GetStaticPluginName(); + ConstString plugin_name = StructuredDataDarwinLog::GetStaticPluginName(); const bool enabled = plugin_sp ? plugin_sp->GetEnabled(plugin_name) : false; stream.Printf("Enabled: %s\n", enabled ? "true" : "false"); @@ -970,9 +958,7 @@ protected: } }; -// ------------------------------------------------------------------------- /// Provides the darwin-log base command -// ------------------------------------------------------------------------- class BaseCommand : public CommandObjectMultiword { public: BaseCommand(CommandInterpreter &interpreter) @@ -1084,9 +1070,7 @@ using namespace sddarwinlog_private; #pragma mark - #pragma mark Public static API -// ----------------------------------------------------------------------------- // Public static API -// ----------------------------------------------------------------------------- void StructuredDataDarwinLog::Initialize() { RegisterFilterOperations(); @@ -1099,7 +1083,7 @@ void StructuredDataDarwinLog::Terminate() { PluginManager::UnregisterPlugin(&CreateInstance); } -const ConstString &StructuredDataDarwinLog::GetStaticPluginName() { +ConstString StructuredDataDarwinLog::GetStaticPluginName() { static ConstString s_plugin_name("darwin-log"); return s_plugin_name; } @@ -1107,9 +1091,7 @@ const ConstString &StructuredDataDarwinLog::GetStaticPluginName() { #pragma mark - #pragma mark PluginInterface API -// ----------------------------------------------------------------------------- // PluginInterface API -// ----------------------------------------------------------------------------- ConstString StructuredDataDarwinLog::GetPluginName() { return GetStaticPluginName(); @@ -1120,17 +1102,15 @@ uint32_t StructuredDataDarwinLog::GetPluginVersion() { return 1; } #pragma mark - #pragma mark StructuredDataPlugin API -// ----------------------------------------------------------------------------- // StructuredDataPlugin API -// ----------------------------------------------------------------------------- bool StructuredDataDarwinLog::SupportsStructuredDataType( - const ConstString &type_name) { + ConstString type_name) { return type_name == GetDarwinLogTypeName(); } void StructuredDataDarwinLog::HandleArrivalOfStructuredData( - Process &process, const ConstString &type_name, + Process &process, ConstString type_name, const StructuredData::ObjectSP &object_sp) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); if (log) { @@ -1269,7 +1249,7 @@ Status StructuredDataDarwinLog::GetDescription( return error; } -bool StructuredDataDarwinLog::GetEnabled(const ConstString &type_name) const { +bool StructuredDataDarwinLog::GetEnabled(ConstString type_name) const { if (type_name == GetStaticPluginName()) return m_is_enabled; else @@ -1372,9 +1352,7 @@ void StructuredDataDarwinLog::ModulesDidLoad(Process &process, EnableNow(); } -// ----------------------------------------------------------------------------- // public destructor -// ----------------------------------------------------------------------------- StructuredDataDarwinLog::~StructuredDataDarwinLog() { if (m_breakpoint_id != LLDB_INVALID_BREAK_ID) { @@ -1389,9 +1367,7 @@ StructuredDataDarwinLog::~StructuredDataDarwinLog() { #pragma mark - #pragma mark Private instance methods -// ----------------------------------------------------------------------------- // Private constructors -// ----------------------------------------------------------------------------- StructuredDataDarwinLog::StructuredDataDarwinLog(const ProcessWP &process_wp) : StructuredDataPlugin(process_wp), m_recorded_first_timestamp(false), @@ -1399,9 +1375,7 @@ StructuredDataDarwinLog::StructuredDataDarwinLog(const ProcessWP &process_wp) m_added_breakpoint_mutex(), m_added_breakpoint(), m_breakpoint_id(LLDB_INVALID_BREAK_ID) {} -// ----------------------------------------------------------------------------- // Private static methods -// ----------------------------------------------------------------------------- StructuredDataPluginSP StructuredDataDarwinLog::CreateInstance(Process &process) { @@ -1636,8 +1610,8 @@ bool StructuredDataDarwinLog::InitCompletionHookCallback( } // Queue the thread plan. - auto thread_plan_sp = ThreadPlanSP( - new ThreadPlanCallOnFunctionExit(*thread_sp.get(), callback)); + auto thread_plan_sp = + ThreadPlanSP(new ThreadPlanCallOnFunctionExit(*thread_sp, callback)); const bool abort_other_plans = false; thread_sp->QueueThreadPlan(thread_plan_sp, abort_other_plans); if (log) diff --git a/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h b/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h index 77b6e7be71c7..8fa1eed66efb 100644 --- a/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h +++ b/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h @@ -1,9 +1,8 @@ //===-- StructuredDataDarwinLog.h -------------------------------*- C++ -*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -25,17 +24,14 @@ class StructuredDataDarwinLog : public StructuredDataPlugin { friend sddarwinlog_private::EnableCommand; public: - // ------------------------------------------------------------------------- // Public static API - // ------------------------------------------------------------------------- static void Initialize(); static void Terminate(); - static const ConstString &GetStaticPluginName(); + static ConstString GetStaticPluginName(); - // ------------------------------------------------------------------------- /// Return whether the DarwinLog functionality is enabled. /// /// The DarwinLog functionality is enabled if the user expicitly enabled @@ -43,49 +39,40 @@ public: /// that controls if we always enable it for newly created/attached /// processes. /// - /// @return + /// \return /// True if DarwinLog support is/will be enabled for existing or /// newly launched/attached processes. - // ------------------------------------------------------------------------- static bool IsEnabled(); - // ------------------------------------------------------------------------- // PluginInterface API - // ------------------------------------------------------------------------- ConstString GetPluginName() override; uint32_t GetPluginVersion() override; - // ------------------------------------------------------------------------- // StructuredDataPlugin API - // ------------------------------------------------------------------------- - bool SupportsStructuredDataType(const ConstString &type_name) override; + bool SupportsStructuredDataType(ConstString type_name) override; void HandleArrivalOfStructuredData( - Process &process, const ConstString &type_name, + Process &process, ConstString type_name, const StructuredData::ObjectSP &object_sp) override; Status GetDescription(const StructuredData::ObjectSP &object_sp, lldb_private::Stream &stream) override; - bool GetEnabled(const ConstString &type_name) const override; + bool GetEnabled(ConstString type_name) const override; void ModulesDidLoad(Process &process, ModuleList &module_list) override; - ~StructuredDataDarwinLog(); + ~StructuredDataDarwinLog() override; private: - // ------------------------------------------------------------------------- // Private constructors - // ------------------------------------------------------------------------- StructuredDataDarwinLog(const lldb::ProcessWP &process_wp); - // ------------------------------------------------------------------------- // Private static methods - // ------------------------------------------------------------------------- static lldb::StructuredDataPluginSP CreateInstance(Process &process); @@ -99,16 +86,12 @@ private: static Status FilterLaunchInfo(ProcessLaunchInfo &launch_info, Target *target); - // ------------------------------------------------------------------------- // Internal helper methods used by friend classes - // ------------------------------------------------------------------------- void SetEnabled(bool enabled); void AddInitCompletionHook(Process &process); - // ------------------------------------------------------------------------- // Private methods - // ------------------------------------------------------------------------- void DumpTimestamp(Stream &stream, uint64_t timestamp); @@ -117,16 +100,12 @@ private: size_t HandleDisplayOfEvent(const StructuredData::Dictionary &event, Stream &stream); - // ------------------------------------------------------------------------- /// Call the enable command again, using whatever settings were initially /// made. - // ------------------------------------------------------------------------- void EnableNow(); - // ------------------------------------------------------------------------- // Private data - // ------------------------------------------------------------------------- bool m_recorded_first_timestamp; uint64_t m_first_timestamp_seen; bool m_is_enabled; |
