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
24 // Flags that get filled in automatically before calling the log callback
26 #define DNBLOG_FLAG_FATAL (1u << 0)
27 #define DNBLOG_FLAG_ERROR (1u << 1)
28 #define DNBLOG_FLAG_WARNING (1u << 2)
29 #define DNBLOG_FLAG_DEBUG (1u << 3)
30 #define DNBLOG_FLAG_VERBOSE (1u << 4)
31 #define DNBLOG_FLAG_THREADED (1u << 5)
33 #define DNBLOG_ENABLED
35 #if defined(DNBLOG_ENABLED)
37 void _DNBLog(uint32_t flags
, const char *format
, ...)
38 __attribute__((format(printf
, 2, 3)));
39 void _DNBLogDebug(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
40 void _DNBLogDebugVerbose(const char *fmt
, ...)
41 __attribute__((format(printf
, 1, 2)));
42 void _DNBLogThreaded(const char *fmt
, ...)
43 __attribute__((format(printf
, 1, 2)));
44 void _DNBLogThreadedIf(uint32_t mask
, const char *fmt
, ...)
45 __attribute__((format(printf
, 2, 3)));
46 void _DNBLogError(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
47 void _DNBLogFatalError(int err
, const char *fmt
, ...)
48 __attribute__((format(printf
, 2, 3)));
49 void _DNBLogVerbose(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
50 void _DNBLogWarning(const char *fmt
, ...) __attribute__((format(printf
, 1, 2)));
51 void _DNBLogWarningVerbose(const char *fmt
, ...)
52 __attribute__((format(printf
, 1, 2)));
53 bool DNBLogCheckLogBit(uint32_t bit
);
54 uint32_t DNBLogSetLogMask(uint32_t mask
);
55 uint32_t DNBLogGetLogMask();
56 void DNBLogSetLogCallback(DNBCallbackLog callback
, void *baton
);
57 DNBCallbackLog
DNBLogGetLogCallback();
59 bool DNBLogEnabledForAny(uint32_t mask
);
61 void DNBLogSetDebug(int g
);
62 int DNBLogGetVerbose();
63 void DNBLogSetVerbose(int g
);
65 #define DNBLog(fmt, ...) \
67 if (DNBLogEnabled()) { \
68 _DNBLog(0, fmt, ##__VA_ARGS__); \
71 #define DNBLogDebug(fmt, ...) \
73 if (DNBLogEnabled()) { \
74 _DNBLogDebug(fmt, ##__VA_ARGS__); \
77 #define DNBLogDebugVerbose(fmt, ...) \
79 if (DNBLogEnabled()) { \
80 _DNBLogDebugVerbose(fmt, ##__VA_ARGS__); \
83 #define DNBLogThreaded(fmt, ...) \
85 if (DNBLogEnabled()) { \
86 _DNBLogThreaded(fmt, ##__VA_ARGS__); \
89 #define DNBLogThreadedIf(mask, fmt, ...) \
91 if (DNBLogEnabledForAny(mask)) { \
92 _DNBLogThreaded(fmt, ##__VA_ARGS__); \
95 #define DNBLogError(fmt, ...) \
97 if (DNBLogEnabled()) { \
98 _DNBLogError(fmt, ##__VA_ARGS__); \
101 #define DNBLogFatalError(err, fmt, ...) \
103 if (DNBLogEnabled()) { \
104 _DNBLogFatalError(err, fmt, ##__VA_ARGS__); \
107 #define DNBLogVerbose(fmt, ...) \
109 if (DNBLogEnabled()) { \
110 _DNBLogVerbose(fmt, ##__VA_ARGS__); \
113 #define DNBLogWarning(fmt, ...) \
115 if (DNBLogEnabled()) { \
116 _DNBLogWarning(fmt, ##__VA_ARGS__); \
119 #define DNBLogWarningVerbose(fmt, ...) \
121 if (DNBLogEnabled()) { \
122 _DNBLogWarningVerbose(fmt, ##__VA_ARGS__); \
126 #else // #if defined(DNBLOG_ENABLED)
128 #define DNBLogDebug(...) ((void)0)
129 #define DNBLogDebugVerbose(...) ((void)0)
130 #define DNBLogThreaded(...) ((void)0)
131 #define DNBLogThreadedIf(...) ((void)0)
132 #define DNBLogError(...) ((void)0)
133 #define DNBLogFatalError(...) ((void)0)
134 #define DNBLogVerbose(...) ((void)0)
135 #define DNBLogWarning(...) ((void)0)
136 #define DNBLogWarningVerbose(...) ((void)0)
137 #define DNBLogGetLogFile() ((FILE *)NULL)
138 #define DNBLogSetLogFile(f) ((void)0)
139 #define DNBLogCheckLogBit(bit) ((bool)false)
140 #define DNBLogSetLogMask(mask) ((uint32_t)0u)
141 #define DNBLogGetLogMask() ((uint32_t)0u)
142 #define DNBLogToASL() ((void)0)
143 #define DNBLogToFile() ((void)0)
144 #define DNBLogCloseLogFile() ((void)0)
146 #endif // #else defined(DNBLOG_ENABLED)
152 #endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBLOG_H