]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.h
Fix a memory leak in if_delgroups() introduced in r334118.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / Plugins / StructuredData / DarwinLog / StructuredDataDarwinLog.h
1 //===-- StructuredDataDarwinLog.h -------------------------------*- C++ -*-===//
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
9 #ifndef StructuredDataDarwinLog_h
10 #define StructuredDataDarwinLog_h
11
12 #include "lldb/Target/StructuredDataPlugin.h"
13
14 #include <mutex>
15
16 // Forward declarations
17 namespace sddarwinlog_private {
18 class EnableCommand;
19 }
20
21 namespace lldb_private {
22
23 class StructuredDataDarwinLog : public StructuredDataPlugin {
24   friend sddarwinlog_private::EnableCommand;
25
26 public:
27   // Public static API
28
29   static void Initialize();
30
31   static void Terminate();
32
33   static ConstString GetStaticPluginName();
34
35   /// Return whether the DarwinLog functionality is enabled.
36   ///
37   /// The DarwinLog functionality is enabled if the user expicitly enabled
38   /// it with the enable command, or if the user has the setting set
39   /// that controls if we always enable it for newly created/attached
40   /// processes.
41   ///
42   /// \return
43   ///      True if DarwinLog support is/will be enabled for existing or
44   ///      newly launched/attached processes.
45   static bool IsEnabled();
46
47   // PluginInterface API
48
49   ConstString GetPluginName() override;
50
51   uint32_t GetPluginVersion() override;
52
53   // StructuredDataPlugin API
54
55   bool SupportsStructuredDataType(ConstString type_name) override;
56
57   void HandleArrivalOfStructuredData(
58       Process &process, ConstString type_name,
59       const StructuredData::ObjectSP &object_sp) override;
60
61   Status GetDescription(const StructuredData::ObjectSP &object_sp,
62                         lldb_private::Stream &stream) override;
63
64   bool GetEnabled(ConstString type_name) const override;
65
66   void ModulesDidLoad(Process &process, ModuleList &module_list) override;
67
68   ~StructuredDataDarwinLog() override;
69
70 private:
71   // Private constructors
72
73   StructuredDataDarwinLog(const lldb::ProcessWP &process_wp);
74
75   // Private static methods
76
77   static lldb::StructuredDataPluginSP CreateInstance(Process &process);
78
79   static void DebuggerInitialize(Debugger &debugger);
80
81   static bool InitCompletionHookCallback(void *baton,
82                                          StoppointCallbackContext *context,
83                                          lldb::user_id_t break_id,
84                                          lldb::user_id_t break_loc_id);
85
86   static Status FilterLaunchInfo(ProcessLaunchInfo &launch_info,
87                                  Target *target);
88
89   // Internal helper methods used by friend classes
90   void SetEnabled(bool enabled);
91
92   void AddInitCompletionHook(Process &process);
93
94   // Private methods
95
96   void DumpTimestamp(Stream &stream, uint64_t timestamp);
97
98   size_t DumpHeader(Stream &stream, const StructuredData::Dictionary &event);
99
100   size_t HandleDisplayOfEvent(const StructuredData::Dictionary &event,
101                               Stream &stream);
102
103   /// Call the enable command again, using whatever settings were initially
104   /// made.
105
106   void EnableNow();
107
108   // Private data
109   bool m_recorded_first_timestamp;
110   uint64_t m_first_timestamp_seen;
111   bool m_is_enabled;
112   std::mutex m_added_breakpoint_mutex;
113   bool m_added_breakpoint;
114   lldb::user_id_t m_breakpoint_id;
115 };
116 }
117
118 #endif /* StructuredDataPluginDarwinLog_hpp */