1 //===-- Log.h ---------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Log_h_
11 #define liblldb_Log_h_
20 // Other libraries and framework includes
22 #include "lldb/lldb-private.h"
23 #include "lldb/Core/ConstString.h"
24 #include "lldb/Core/Flags.h"
25 #include "lldb/Core/PluginInterface.h"
27 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
30 #define LLDB_LOG_FLAG_STDOUT (1u << 0)
31 #define LLDB_LOG_FLAG_STDERR (1u << 1)
32 #define LLDB_LOG_FLAG_FATAL (1u << 2)
33 #define LLDB_LOG_FLAG_ERROR (1u << 3)
34 #define LLDB_LOG_FLAG_WARNING (1u << 4)
35 #define LLDB_LOG_FLAG_DEBUG (1u << 5)
36 #define LLDB_LOG_FLAG_VERBOSE (1u << 6)
38 //----------------------------------------------------------------------
40 //----------------------------------------------------------------------
41 #define LLDB_LOG_OPTION_THREADSAFE (1u << 0)
42 #define LLDB_LOG_OPTION_VERBOSE (1u << 1)
43 #define LLDB_LOG_OPTION_DEBUG (1u << 2)
44 #define LLDB_LOG_OPTION_PREPEND_SEQUENCE (1u << 3)
45 #define LLDB_LOG_OPTION_PREPEND_TIMESTAMP (1u << 4)
46 #define LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD (1u << 5)
47 #define LLDB_LOG_OPTION_PREPEND_THREAD_NAME (1U << 6)
48 #define LLDB_LOG_OPTION_BACKTRACE (1U << 7)
50 //----------------------------------------------------------------------
52 //----------------------------------------------------------------------
53 namespace lldb_private {
59 //------------------------------------------------------------------
60 // Callback definitions for abstracted plug-in log access.
61 //------------------------------------------------------------------
62 typedef void (*DisableCallback) (const char **categories, Stream *feedback_strm);
63 typedef Log * (*EnableCallback) (lldb::StreamSP &log_stream_sp,
65 const char **categories,
66 Stream *feedback_strm);
67 typedef void (*ListCategoriesCallback) (Stream *strm);
71 DisableCallback disable;
72 EnableCallback enable;
73 ListCategoriesCallback list_categories;
76 //------------------------------------------------------------------
77 // Static accessors for logging channels
78 //------------------------------------------------------------------
80 RegisterLogChannel (const ConstString &channel,
81 const Log::Callbacks &log_callbacks);
84 UnregisterLogChannel (const ConstString &channel);
87 GetLogChannelCallbacks (const ConstString &channel,
88 Log::Callbacks &log_callbacks);
92 EnableAllLogChannels (lldb::StreamSP &log_stream_sp,
94 const char **categories,
95 Stream *feedback_strm);
98 DisableAllLogChannels (Stream *feedback_strm);
101 ListAllLogChannels (Stream *strm);
109 //------------------------------------------------------------------
111 //------------------------------------------------------------------
113 AutoCompleteChannelName (const char *channel_name,
114 StringList &matches);
116 //------------------------------------------------------------------
118 //------------------------------------------------------------------
121 Log (const lldb::StreamSP &stream_sp);
126 PutCString (const char *cstr);
129 Printf (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
132 VAPrintf (const char *format, va_list args);
135 PrintfWithFlags( uint32_t flags, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
138 LogIf (uint32_t mask, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
141 Debug (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
144 DebugVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
147 Error (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
150 FatalError (int err, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
153 Verbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
156 Warning (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
159 WarningVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
180 SetStream (const lldb::StreamSP &stream_sp)
182 m_stream_sp = stream_sp;
186 //------------------------------------------------------------------
188 //------------------------------------------------------------------
189 lldb::StreamSP m_stream_sp;
194 PrintfWithFlagsVarArg (uint32_t flags, const char *format, va_list args);
197 DISALLOW_COPY_AND_ASSIGN (Log);
201 class LogChannel : public PluginInterface
209 static lldb::LogChannelSP
210 FindPlugin (const char *plugin_name);
212 // categories is a an array of chars that ends with a NULL element.
214 Disable (const char **categories, Stream *feedback_strm) = 0;
217 Enable (lldb::StreamSP &log_stream_sp,
218 uint32_t log_options,
219 Stream *feedback_strm, // Feedback stream for argument errors etc
220 const char **categories) = 0;// The categories to enable within this logging stream, if empty, enable default set
223 ListCategories (Stream *strm) = 0;
226 std::unique_ptr<Log> m_log_ap;
229 DISALLOW_COPY_AND_ASSIGN (LogChannel);
233 } // namespace lldb_private
235 #endif // liblldb_Log_H_