1 //===-- StructuredDataDarwinLog.h -------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef StructuredDataDarwinLog_h 11 #define StructuredDataDarwinLog_h 12 13 #include "lldb/Target/StructuredDataPlugin.h" 14 15 #include <mutex> 16 17 // Forward declarations 18 namespace sddarwinlog_private { 19 class EnableCommand; 20 } 21 22 namespace lldb_private { 23 24 class StructuredDataDarwinLog : public StructuredDataPlugin { 25 friend sddarwinlog_private::EnableCommand; 26 27 public: 28 // ------------------------------------------------------------------------- 29 // Public static API 30 // ------------------------------------------------------------------------- 31 32 static void Initialize(); 33 34 static void Terminate(); 35 36 static const ConstString &GetStaticPluginName(); 37 38 // ------------------------------------------------------------------------- 39 /// Return whether the DarwinLog functionality is enabled. 40 /// 41 /// The DarwinLog functionality is enabled if the user expicitly enabled 42 /// it with the enable command, or if the user has the setting set 43 /// that controls if we always enable it for newly created/attached 44 /// processes. 45 /// 46 /// @return 47 /// True if DarwinLog support is/will be enabled for existing or 48 /// newly launched/attached processes. 49 // ------------------------------------------------------------------------- 50 static bool IsEnabled(); 51 52 // ------------------------------------------------------------------------- 53 // PluginInterface API 54 // ------------------------------------------------------------------------- 55 56 ConstString GetPluginName() override; 57 58 uint32_t GetPluginVersion() override; 59 60 // ------------------------------------------------------------------------- 61 // StructuredDataPlugin API 62 // ------------------------------------------------------------------------- 63 64 bool SupportsStructuredDataType(const ConstString &type_name) override; 65 66 void HandleArrivalOfStructuredData( 67 Process &process, const ConstString &type_name, 68 const StructuredData::ObjectSP &object_sp) override; 69 70 Error GetDescription(const StructuredData::ObjectSP &object_sp, 71 lldb_private::Stream &stream) override; 72 73 bool GetEnabled(const ConstString &type_name) const override; 74 75 void ModulesDidLoad(Process &process, ModuleList &module_list) override; 76 77 private: 78 // ------------------------------------------------------------------------- 79 // Private constructors 80 // ------------------------------------------------------------------------- 81 82 StructuredDataDarwinLog(const lldb::ProcessWP &process_wp); 83 84 // ------------------------------------------------------------------------- 85 // Private static methods 86 // ------------------------------------------------------------------------- 87 88 static lldb::StructuredDataPluginSP CreateInstance(Process &process); 89 90 static void DebuggerInitialize(Debugger &debugger); 91 92 static bool InitCompletionHookCallback(void *baton, 93 StoppointCallbackContext *context, 94 lldb::user_id_t break_id, 95 lldb::user_id_t break_loc_id); 96 97 static Error FilterLaunchInfo(ProcessLaunchInfo &launch_info, Target *target); 98 99 // ------------------------------------------------------------------------- 100 // Internal helper methods used by friend classes 101 // ------------------------------------------------------------------------- 102 void SetEnabled(bool enabled); 103 104 void AddInitCompletionHook(Process &process); 105 106 // ------------------------------------------------------------------------- 107 // Private methods 108 // ------------------------------------------------------------------------- 109 110 void DumpTimestamp(Stream &stream, uint64_t timestamp); 111 112 size_t DumpHeader(Stream &stream, const StructuredData::Dictionary &event); 113 114 size_t HandleDisplayOfEvent(const StructuredData::Dictionary &event, 115 Stream &stream); 116 117 // ------------------------------------------------------------------------- 118 /// Call the enable command again, using whatever settings were initially 119 /// made. 120 // ------------------------------------------------------------------------- 121 122 void EnableNow(); 123 124 // ------------------------------------------------------------------------- 125 // Private data 126 // ------------------------------------------------------------------------- 127 bool m_recorded_first_timestamp; 128 uint64_t m_first_timestamp_seen; 129 bool m_is_enabled; 130 std::mutex m_added_breakpoint_mutex; 131 bool m_added_breakpoint; 132 }; 133 } 134 135 #endif /* StructuredDataPluginDarwinLog_hpp */ 136