1 //===-- DNBLog.h ------------------------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Created by Greg Clayton on 6/18/07. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBLOG_H 14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBLOG_H 15 16 #include "DNBDefs.h" 17 #include <cstdint> 18 #include <cstdio> 19 20 extern "C" { 21 22 // Flags that get filled in automatically before calling the log callback 23 // function 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) 30 31 #define DNBLOG_ENABLED 32 33 #if defined(DNBLOG_ENABLED) 34 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(); 56 bool DNBLogEnabled(); 57 bool DNBLogEnabledForAny(uint32_t mask); 58 int DNBLogGetDebug(); 59 void DNBLogSetDebug(int g); 60 int DNBLogGetVerbose(); 61 void DNBLogSetVerbose(int g); 62 63 #define DNBLog(fmt, ...) \ 64 do { \ 65 if (DNBLogEnabled()) { \ 66 _DNBLog(0, fmt, ##__VA_ARGS__); \ 67 } \ 68 } while (0) 69 #define DNBLogDebug(fmt, ...) \ 70 do { \ 71 if (DNBLogEnabled()) { \ 72 _DNBLogDebug(fmt, ##__VA_ARGS__); \ 73 } \ 74 } while (0) 75 #define DNBLogDebugVerbose(fmt, ...) \ 76 do { \ 77 if (DNBLogEnabled()) { \ 78 _DNBLogDebugVerbose(fmt, ##__VA_ARGS__); \ 79 } \ 80 } while (0) 81 #define DNBLogThreaded(fmt, ...) \ 82 do { \ 83 if (DNBLogEnabled()) { \ 84 _DNBLogThreaded(fmt, ##__VA_ARGS__); \ 85 } \ 86 } while (0) 87 #define DNBLogThreadedIf(mask, fmt, ...) \ 88 do { \ 89 if (DNBLogEnabledForAny(mask)) { \ 90 _DNBLogThreaded(fmt, ##__VA_ARGS__); \ 91 } \ 92 } while (0) 93 #define DNBLogError(fmt, ...) \ 94 do { \ 95 if (DNBLogEnabled()) { \ 96 _DNBLogError(fmt, ##__VA_ARGS__); \ 97 } \ 98 } while (0) 99 #define DNBLogFatalError(err, fmt, ...) \ 100 do { \ 101 if (DNBLogEnabled()) { \ 102 _DNBLogFatalError(err, fmt, ##__VA_ARGS__); \ 103 } \ 104 } while (0) 105 #define DNBLogVerbose(fmt, ...) \ 106 do { \ 107 if (DNBLogEnabled()) { \ 108 _DNBLogVerbose(fmt, ##__VA_ARGS__); \ 109 } \ 110 } while (0) 111 #define DNBLogWarning(fmt, ...) \ 112 do { \ 113 if (DNBLogEnabled()) { \ 114 _DNBLogWarning(fmt, ##__VA_ARGS__); \ 115 } \ 116 } while (0) 117 #define DNBLogWarningVerbose(fmt, ...) \ 118 do { \ 119 if (DNBLogEnabled()) { \ 120 _DNBLogWarningVerbose(fmt, ##__VA_ARGS__); \ 121 } \ 122 } while (0) 123 124 #else // #if defined(DNBLOG_ENABLED) 125 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) 143 144 #endif // #else defined(DNBLOG_ENABLED) 145 } 146 147 #endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBLOG_H 148