]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Core/Log.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / Core / Log.h
1 //===-- Log.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 liblldb_Log_h_
11 #define liblldb_Log_h_
12
13 // C Includes
14 #include <signal.h>
15 #include <stdarg.h>
16 #include <stdint.h>
17 #include <stdio.h>
18
19 // C++ Includes
20 // Other libraries and framework includes
21 // Project includes
22 #include "lldb/Core/ConstString.h"
23 #include "lldb/Core/Flags.h"
24 #include "lldb/Core/Logging.h"
25 #include "lldb/Core/PluginInterface.h"
26 #include "lldb/lldb-private.h"
27
28 #include "llvm/Support/FormatVariadic.h"
29
30 //----------------------------------------------------------------------
31 // Logging Options
32 //----------------------------------------------------------------------
33 #define LLDB_LOG_OPTION_THREADSAFE (1u << 0)
34 #define LLDB_LOG_OPTION_VERBOSE (1u << 1)
35 #define LLDB_LOG_OPTION_DEBUG (1u << 2)
36 #define LLDB_LOG_OPTION_PREPEND_SEQUENCE (1u << 3)
37 #define LLDB_LOG_OPTION_PREPEND_TIMESTAMP (1u << 4)
38 #define LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD (1u << 5)
39 #define LLDB_LOG_OPTION_PREPEND_THREAD_NAME (1U << 6)
40 #define LLDB_LOG_OPTION_BACKTRACE (1U << 7)
41 #define LLDB_LOG_OPTION_APPEND (1U << 8)
42
43 //----------------------------------------------------------------------
44 // Logging Functions
45 //----------------------------------------------------------------------
46 namespace lldb_private {
47
48 class Log final {
49 public:
50   //------------------------------------------------------------------
51   // Callback definitions for abstracted plug-in log access.
52   //------------------------------------------------------------------
53   typedef void (*DisableCallback)(const char **categories,
54                                   Stream *feedback_strm);
55   typedef Log *(*EnableCallback)(lldb::StreamSP &log_stream_sp,
56                                  uint32_t log_options, const char **categories,
57                                  Stream *feedback_strm);
58   typedef void (*ListCategoriesCallback)(Stream *strm);
59
60   struct Callbacks {
61     DisableCallback disable;
62     EnableCallback enable;
63     ListCategoriesCallback list_categories;
64   };
65
66   //------------------------------------------------------------------
67   // Static accessors for logging channels
68   //------------------------------------------------------------------
69   static void RegisterLogChannel(const ConstString &channel,
70                                  const Log::Callbacks &log_callbacks);
71
72   static bool UnregisterLogChannel(const ConstString &channel);
73
74   static bool GetLogChannelCallbacks(const ConstString &channel,
75                                      Log::Callbacks &log_callbacks);
76
77   static bool EnableLogChannel(lldb::StreamSP &log_stream_sp,
78                                uint32_t log_options, const char *channel,
79                                const char **categories, Stream &error_stream);
80
81   static void EnableAllLogChannels(lldb::StreamSP &log_stream_sp,
82                                    uint32_t log_options,
83                                    const char **categories,
84                                    Stream *feedback_strm);
85
86   static void DisableAllLogChannels(Stream *feedback_strm);
87
88   static void ListAllLogChannels(Stream *strm);
89
90   static void Initialize();
91
92   static void Terminate();
93
94   //------------------------------------------------------------------
95   // Auto completion
96   //------------------------------------------------------------------
97   static void AutoCompleteChannelName(const char *channel_name,
98                                       StringList &matches);
99
100   //------------------------------------------------------------------
101   // Member functions
102   //------------------------------------------------------------------
103   Log();
104
105   Log(const lldb::StreamSP &stream_sp);
106
107   ~Log();
108
109   void PutCString(const char *cstr);
110   void PutString(llvm::StringRef str);
111
112   template <typename... Args> void Format(const char *fmt, Args &&... args) {
113     PutString(llvm::formatv(fmt, std::forward<Args>(args)...).str());
114   }
115
116   // CLEANUP: Add llvm::raw_ostream &Stream() function.
117   void Printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
118
119   void VAPrintf(const char *format, va_list args);
120
121   void LogIf(uint32_t mask, const char *fmt, ...)
122       __attribute__((format(printf, 3, 4)));
123
124   void Debug(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
125
126   void Error(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
127
128   void VAError(const char *format, va_list args);
129
130   void Verbose(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
131
132   void Warning(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
133
134   Flags &GetOptions();
135
136   const Flags &GetOptions() const;
137
138   Flags &GetMask();
139
140   const Flags &GetMask() const;
141
142   bool GetVerbose() const;
143
144   bool GetDebug() const;
145
146   void SetStream(const lldb::StreamSP &stream_sp) { m_stream_sp = stream_sp; }
147
148 protected:
149   //------------------------------------------------------------------
150   // Member variables
151   //------------------------------------------------------------------
152   lldb::StreamSP m_stream_sp;
153   Flags m_options;
154   Flags m_mask_bits;
155
156 private:
157   DISALLOW_COPY_AND_ASSIGN(Log);
158 };
159
160 class LogChannel : public PluginInterface {
161 public:
162   LogChannel();
163
164   ~LogChannel() override;
165
166   static lldb::LogChannelSP FindPlugin(const char *plugin_name);
167
168   // categories is an array of chars that ends with a NULL element.
169   virtual void Disable(const char **categories, Stream *feedback_strm) = 0;
170
171   virtual bool
172   Enable(lldb::StreamSP &log_stream_sp, uint32_t log_options,
173          Stream *feedback_strm, // Feedback stream for argument errors etc
174          const char **categories) = 0; // The categories to enable within this
175                                        // logging stream, if empty, enable
176                                        // default set
177
178   virtual void ListCategories(Stream *strm) = 0;
179
180 protected:
181   std::unique_ptr<Log> m_log_ap;
182
183 private:
184   DISALLOW_COPY_AND_ASSIGN(LogChannel);
185 };
186
187 } // namespace lldb_private
188
189 #endif // liblldb_Log_h_