1 //===-- DNBLog.h ------------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Created by Greg Clayton on 6/18/07.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBLOG_H
14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBLOG_H
22 // Flags that get filled in automatically before calling the log callback
24 #define DNBLOG_FLAG_FATAL (1u << 0)
25 #define DNBLOG_FLAG_ERROR (1u << 1)
26 #define DNBLOG_FLAG_WARNING (1u << 2)
27 #define DNBLOG_FLAG_DEBUG (1u << 3)
28 #define DNBLOG_FLAG_VERBOSE (1u << 4)
29 #define DNBLOG_FLAG_THREADED (1u << 5)
31 #define DNBLOG_ENABLED
33 #if defined(DNBLOG_ENABLED)
35 void _DNBLog(uint32_t flags
, const char *format
, ...)
36 __attribute__((format(printf
, 2, 3)));
37 void _DNBLogDebug(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
38 void _DNBLogDebugVerbose(const char *fmt
, ...)
39 __attribute__((format(printf
, 1, 2)));
40 void _DNBLogThreaded(const char *fmt
, ...)
41 __attribute__((format(printf
, 1, 2)));
42 void _DNBLogThreadedIf(uint32_t mask
, const char *fmt
, ...)
43 __attribute__((format(printf
, 2, 3)));
44 void _DNBLogError(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
45 void _DNBLogFatalError(int err
, const char *fmt
, ...)
46 __attribute__((format(printf
, 2, 3)));
47 void _DNBLogVerbose(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
48 void _DNBLogWarning(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
49 void _DNBLogWarningVerbose(const char *fmt
, ...)
50 __attribute__((format(printf
, 1, 2)));
51 bool DNBLogCheckLogBit(uint32_t bit
);
52 uint32_t DNBLogSetLogMask(uint32_t mask
);
53 uint32_t DNBLogGetLogMask();
54 void DNBLogSetLogCallback(DNBCallbackLog callback
, void *baton
);
55 DNBCallbackLog
DNBLogGetLogCallback();
57 bool DNBLogEnabledForAny(uint32_t mask
);
59 void DNBLogSetDebug(int g
);
60 int DNBLogGetVerbose();
61 void DNBLogSetVerbose(int g
);
63 #define DNBLog(fmt, ...) \
65 if (DNBLogEnabled()) { \
66 _DNBLog(0, fmt, ##__VA_ARGS__); \
69 #define DNBLogDebug(fmt, ...) \
71 if (DNBLogEnabled()) { \
72 _DNBLogDebug(fmt, ##__VA_ARGS__); \
75 #define DNBLogDebugVerbose(fmt, ...) \
77 if (DNBLogEnabled()) { \
78 _DNBLogDebugVerbose(fmt, ##__VA_ARGS__); \
81 #define DNBLogThreaded(fmt, ...) \
83 if (DNBLogEnabled()) { \
84 _DNBLogThreaded(fmt, ##__VA_ARGS__); \
87 #define DNBLogThreadedIf(mask, fmt, ...) \
89 if (DNBLogEnabledForAny(mask)) { \
90 _DNBLogThreaded(fmt, ##__VA_ARGS__); \
93 #define DNBLogError(fmt, ...) \
95 if (DNBLogEnabled()) { \
96 _DNBLogError(fmt, ##__VA_ARGS__); \
99 #define DNBLogFatalError(err, fmt, ...) \
101 if (DNBLogEnabled()) { \
102 _DNBLogFatalError(err, fmt, ##__VA_ARGS__); \
105 #define DNBLogVerbose(fmt, ...) \
107 if (DNBLogEnabled()) { \
108 _DNBLogVerbose(fmt, ##__VA_ARGS__); \
111 #define DNBLogWarning(fmt, ...) \
113 if (DNBLogEnabled()) { \
114 _DNBLogWarning(fmt, ##__VA_ARGS__); \
117 #define DNBLogWarningVerbose(fmt, ...) \
119 if (DNBLogEnabled()) { \
120 _DNBLogWarningVerbose(fmt, ##__VA_ARGS__); \
124 #else // #if defined(DNBLOG_ENABLED)
126 #define DNBLogDebug(...) ((void)0)
127 #define DNBLogDebugVerbose(...) ((void)0)
128 #define DNBLogThreaded(...) ((void)0)
129 #define DNBLogThreadedIf(...) ((void)0)
130 #define DNBLogError(...) ((void)0)
131 #define DNBLogFatalError(...) ((void)0)
132 #define DNBLogVerbose(...) ((void)0)
133 #define DNBLogWarning(...) ((void)0)
134 #define DNBLogWarningVerbose(...) ((void)0)
135 #define DNBLogGetLogFile() ((FILE *)NULL)
136 #define DNBLogSetLogFile(f) ((void)0)
137 #define DNBLogCheckLogBit(bit) ((bool)false)
138 #define DNBLogSetLogMask(mask) ((uint32_t)0u)
139 #define DNBLogGetLogMask() ((uint32_t)0u)
140 #define DNBLogToASL() ((void)0)
141 #define DNBLogToFile() ((void)0)
142 #define DNBLogCloseLogFile() ((void)0)
144 #endif // #else defined(DNBLOG_ENABLED)
147 #endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBLOG_H