Log.h revision 705d6782f95a38caa5cddf8dcc32d6b13fab20fc
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 <stdbool.h>
15#include <stdint.h>
16#include <signal.h>
17#include <stdio.h>
18#include <unistd.h>
19
20// C++ Includes
21// Other libraries and framework includes
22// Project 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"
27
28//----------------------------------------------------------------------
29// Logging types
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)
38
39//----------------------------------------------------------------------
40// Logging Options
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
50//----------------------------------------------------------------------
51// Logging Functions
52//----------------------------------------------------------------------
53namespace lldb_private {
54
55class Log
56{
57public:
58
59    //------------------------------------------------------------------
60    // Callback definitions for abstracted plug-in log access.
61    //------------------------------------------------------------------
62    typedef void (*DisableCallback) ();
63    typedef Log* (*EnableCallback) (lldb::StreamSP &log_stream_sp,
64                                    uint32_t log_options,
65                                    Args &args,
66                                    Stream *feedback_strm);
67    typedef void (*ListCategoriesCallback) (Stream *strm);
68
69    struct Callbacks
70    {
71        DisableCallback disable;
72        EnableCallback enable;
73        ListCategoriesCallback list_categories;
74    };
75
76    //------------------------------------------------------------------
77    // Static accessors for logging channels
78    //------------------------------------------------------------------
79    static void
80    RegisterLogChannel (const char *channel,
81                        const Log::Callbacks &log_callbacks);
82
83    static bool
84    UnregisterLogChannel (const char *channel);
85
86    static bool
87    GetLogChannelCallbacks (const char *channel,
88                            Log::Callbacks &log_callbacks);
89
90
91    static void
92    EnableAllLogChannels (lldb::StreamSP &log_stream_sp,
93                          uint32_t log_options,
94                          Args &args,
95                          Stream *feedback_strm);
96
97    static void
98    DisableAllLogChannels ();
99
100    static void
101    ListAllLogChannels (Stream *strm);
102
103    //------------------------------------------------------------------
104    // Member functions
105    //------------------------------------------------------------------
106    Log ();
107
108    Log (lldb::StreamSP &stream_sp);
109
110    ~Log ();
111
112    void
113    PutCString (const char *cstr);
114
115    void
116    Printf (const char *format, ...);
117
118    void
119    VAPrintf (const char *format, va_list args);
120
121    void
122    PrintfWithFlags( uint32_t flags, const char *format, ...);
123
124    void
125    LogIf (uint32_t mask, const char *fmt, ...);
126
127    void
128    Debug (const char *fmt, ...);
129
130    void
131    DebugVerbose (const char *fmt, ...);
132
133    void
134    Error (const char *fmt, ...);
135
136    void
137    FatalError (int err, const char *fmt, ...);
138
139    void
140    Verbose (const char *fmt, ...);
141
142    void
143    Warning (const char *fmt, ...);
144
145    void
146    WarningVerbose (const char *fmt, ...);
147
148    Flags &
149    GetOptions();
150
151    const Flags &
152    GetOptions() const;
153
154    Flags &
155    GetMask();
156
157    const Flags &
158    GetMask() const;
159
160    bool
161    GetVerbose() const;
162
163    bool
164    GetDebug() const;
165
166protected:
167    //------------------------------------------------------------------
168    // Member variables
169    //------------------------------------------------------------------
170    lldb::StreamSP m_stream_sp;
171    Flags m_options;
172    Flags m_mask_bits;
173
174    void
175    PrintfWithFlagsVarArg (uint32_t flags, const char *format, va_list args);
176
177private:
178    DISALLOW_COPY_AND_ASSIGN (Log);
179};
180
181
182class LogChannel : public PluginInterface
183{
184public:
185    LogChannel ();
186
187    virtual
188    ~LogChannel ();
189
190    static const char *
191    GetPluginSuffix ();
192
193    static lldb::LogChannelSP
194    FindPlugin (const char *plugin_name);
195
196    virtual void
197    Disable () = 0;
198
199    virtual bool
200    Enable (lldb::StreamSP &log_stream_sp,
201            uint32_t log_options,
202            Stream *feedback_strm,      // Feedback stream for argument errors etc
203            const Args &categories) = 0;// The categories to enable within this logging stream, if empty, enable default set
204
205    virtual void
206    ListCategories (Stream *strm) = 0;
207
208protected:
209    lldb::LogSP m_log_sp;
210
211private:
212    DISALLOW_COPY_AND_ASSIGN (LogChannel);
213};
214
215
216} // namespace lldb_private
217
218#endif  // liblldb_Log_H_
219