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_
21 // Other libraries and framework includes
23 #include "lldb/lldb-private.h"
24 #include "lldb/Core/ConstString.h"
25 #include "lldb/Core/Flags.h"
26 #include "lldb/Core/PluginInterface.h"
28 //----------------------------------------------------------------------
30 //----------------------------------------------------------------------
31 #define LLDB_LOG_FLAG_STDOUT (1u << 0)
32 #define LLDB_LOG_FLAG_STDERR (1u << 1)
33 #define LLDB_LOG_FLAG_FATAL (1u << 2)
34 #define LLDB_LOG_FLAG_ERROR (1u << 3)
35 #define LLDB_LOG_FLAG_WARNING (1u << 4)
36 #define LLDB_LOG_FLAG_DEBUG (1u << 5)
37 #define LLDB_LOG_FLAG_VERBOSE (1u << 6)
39 //----------------------------------------------------------------------
41 //----------------------------------------------------------------------
42 #define LLDB_LOG_OPTION_THREADSAFE (1u << 0)
43 #define LLDB_LOG_OPTION_VERBOSE (1u << 1)
44 #define LLDB_LOG_OPTION_DEBUG (1u << 2)
45 #define LLDB_LOG_OPTION_PREPEND_SEQUENCE (1u << 3)
46 #define LLDB_LOG_OPTION_PREPEND_TIMESTAMP (1u << 4)
47 #define LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD (1u << 5)
48 #define LLDB_LOG_OPTION_PREPEND_THREAD_NAME (1U << 6)
49 #define LLDB_LOG_OPTION_BACKTRACE (1U << 7)
51 //----------------------------------------------------------------------
53 //----------------------------------------------------------------------
54 namespace lldb_private {
60 //------------------------------------------------------------------
61 // Callback definitions for abstracted plug-in log access.
62 //------------------------------------------------------------------
63 typedef void (*DisableCallback) (const char **categories, Stream *feedback_strm);
64 typedef Log * (*EnableCallback) (lldb::StreamSP &log_stream_sp,
66 const char **categories,
67 Stream *feedback_strm);
68 typedef void (*ListCategoriesCallback) (Stream *strm);
72 DisableCallback disable;
73 EnableCallback enable;
74 ListCategoriesCallback list_categories;
77 //------------------------------------------------------------------
78 // Static accessors for logging channels
79 //------------------------------------------------------------------
81 RegisterLogChannel (const ConstString &channel,
82 const Log::Callbacks &log_callbacks);
85 UnregisterLogChannel (const ConstString &channel);
88 GetLogChannelCallbacks (const ConstString &channel,
89 Log::Callbacks &log_callbacks);
93 EnableAllLogChannels (lldb::StreamSP &log_stream_sp,
95 const char **categories,
96 Stream *feedback_strm);
99 DisableAllLogChannels (Stream *feedback_strm);
102 ListAllLogChannels (Stream *strm);
110 //------------------------------------------------------------------
112 //------------------------------------------------------------------
114 AutoCompleteChannelName (const char *channel_name,
115 StringList &matches);
117 //------------------------------------------------------------------
119 //------------------------------------------------------------------
122 Log (const lldb::StreamSP &stream_sp);
127 PutCString (const char *cstr);
130 Printf (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
133 VAPrintf (const char *format, va_list args);
136 PrintfWithFlags( uint32_t flags, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
139 LogIf (uint32_t mask, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
142 Debug (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
145 DebugVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
148 Error (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
151 FatalError (int err, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
154 Verbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
157 Warning (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
160 WarningVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
181 SetStream (const lldb::StreamSP &stream_sp)
183 m_stream_sp = stream_sp;
187 //------------------------------------------------------------------
189 //------------------------------------------------------------------
190 lldb::StreamSP m_stream_sp;
195 PrintfWithFlagsVarArg (uint32_t flags, const char *format, va_list args);
198 DISALLOW_COPY_AND_ASSIGN (Log);
202 class LogChannel : public PluginInterface
210 static lldb::LogChannelSP
211 FindPlugin (const char *plugin_name);
213 // categories is a an array of chars that ends with a NULL element.
215 Disable (const char **categories, Stream *feedback_strm) = 0;
218 Enable (lldb::StreamSP &log_stream_sp,
219 uint32_t log_options,
220 Stream *feedback_strm, // Feedback stream for argument errors etc
221 const char **categories) = 0;// The categories to enable within this logging stream, if empty, enable default set
224 ListCategories (Stream *strm) = 0;
227 std::unique_ptr<Log> m_log_ap;
230 DISALLOW_COPY_AND_ASSIGN (LogChannel);
234 } // namespace lldb_private
236 #endif // liblldb_Log_H_