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/Logging.h"
26 #include "lldb/Core/PluginInterface.h"
28 //----------------------------------------------------------------------
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)
41 //----------------------------------------------------------------------
43 //----------------------------------------------------------------------
44 namespace lldb_private {
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);
60 DisableCallback disable;
61 EnableCallback enable;
62 ListCategoriesCallback list_categories;
65 //------------------------------------------------------------------
66 // Static accessors for logging channels
67 //------------------------------------------------------------------
69 RegisterLogChannel(const ConstString &channel, const Log::Callbacks &log_callbacks);
72 UnregisterLogChannel(const ConstString &channel);
75 GetLogChannelCallbacks(const ConstString &channel, Log::Callbacks &log_callbacks);
78 EnableLogChannel(lldb::StreamSP &log_stream_sp, uint32_t log_options, const char *channel,
79 const char **categories, Stream &error_stream);
82 EnableAllLogChannels(lldb::StreamSP &log_stream_sp, uint32_t log_options, const char **categories,
83 Stream *feedback_strm);
86 DisableAllLogChannels(Stream *feedback_strm);
89 ListAllLogChannels(Stream *strm);
97 //------------------------------------------------------------------
99 //------------------------------------------------------------------
101 AutoCompleteChannelName(const char *channel_name, StringList &matches);
103 //------------------------------------------------------------------
105 //------------------------------------------------------------------
108 Log(const lldb::StreamSP &stream_sp);
114 PutCString(const char *cstr);
117 Printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
120 VAPrintf(const char *format, va_list args);
123 LogIf(uint32_t mask, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
126 Debug(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
129 DebugVerbose(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
132 Error(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
135 VAError(const char *format, va_list args);
138 FatalError(int err, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
141 Verbose(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
144 Warning(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
147 WarningVerbose(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
168 SetStream(const lldb::StreamSP &stream_sp)
170 m_stream_sp = stream_sp;
174 //------------------------------------------------------------------
176 //------------------------------------------------------------------
177 lldb::StreamSP m_stream_sp;
182 DISALLOW_COPY_AND_ASSIGN(Log);
186 class LogChannel : public PluginInterface
191 virtual ~LogChannel();
193 static lldb::LogChannelSP FindPlugin(const char *plugin_name);
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;
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
203 virtual void ListCategories(Stream *strm) = 0;
206 std::unique_ptr<Log> m_log_ap;
209 DISALLOW_COPY_AND_ASSIGN(LogChannel);
213 } // namespace lldb_private
215 #endif // liblldb_Log_H_