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