1 //===-- ProcessWindowsLog.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_ProcessWindowsLog_h_ 11 #define liblldb_ProcessWindowsLog_h_ 12 13 #include "lldb/Core/Log.h" 14 15 #define WINDOWS_LOG_VERBOSE (1u << 0) 16 #define WINDOWS_LOG_PROCESS (1u << 1) // Log process operations 17 #define WINDOWS_LOG_EXCEPTION (1u << 1) // Log exceptions 18 #define WINDOWS_LOG_THREAD (1u << 2) // Log thread operations 19 #define WINDOWS_LOG_MEMORY (1u << 3) // Log memory reads/writes calls 20 #define WINDOWS_LOG_BREAKPOINTS (1u << 4) // Log breakpoint operations 21 #define WINDOWS_LOG_STEP (1u << 5) // Log step operations 22 #define WINDOWS_LOG_REGISTERS (1u << 6) // Log register operations 23 #define WINDOWS_LOG_EVENT (1u << 7) // Low level debug events 24 #define WINDOWS_LOG_ALL (UINT32_MAX) 25 26 enum class LogMaskReq 27 { 28 All, 29 Any 30 }; 31 32 class ProcessWindowsLog 33 { 34 static const char *m_pluginname; 35 36 public: 37 // --------------------------------------------------------------------- 38 // Public Static Methods 39 // --------------------------------------------------------------------- 40 static void 41 Initialize(); 42 43 static void 44 Terminate(); 45 46 static void 47 RegisterPluginName(const char *pluginName) 48 { 49 m_pluginname = pluginName; 50 } 51 52 static void 53 RegisterPluginName(lldb_private::ConstString pluginName) 54 { 55 m_pluginname = pluginName.GetCString(); 56 } 57 58 static bool 59 TestLogFlags(uint32_t mask, LogMaskReq req); 60 61 static lldb_private::Log * 62 GetLog(); 63 64 static void 65 DisableLog(const char **args, lldb_private::Stream *feedback_strm); 66 67 static lldb_private::Log * 68 EnableLog(lldb::StreamSP &log_stream_sp, uint32_t log_options, 69 const char **args, lldb_private::Stream *feedback_strm); 70 71 static void 72 ListLogCategories(lldb_private::Stream *strm); 73 }; 74 75 #define WINLOGF_IF(Flags, Req, Method, ...) \ 76 { \ 77 if (ProcessWindowsLog::TestLogFlags(Flags, Req)) \ 78 { \ 79 Log *log = ProcessWindowsLog::GetLog(); \ 80 if (log) \ 81 log->Method(__VA_ARGS__); \ 82 } \ 83 } 84 85 #define WINLOG_IFANY(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::Any, Printf, __VA_ARGS__) 86 #define WINLOG_IFALL(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::All, Printf, __VA_ARGS__) 87 #define WINLOGV_IFANY(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::Any, Verbose, __VA_ARGS__) 88 #define WINLOGV_IFALL(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::All, Verbose, __VA_ARGS__) 89 #define WINLOGD_IFANY(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::Any, Debug, __VA_ARGS__) 90 #define WINLOGD_IFALL(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::All, Debug, __VA_ARGS__) 91 #define WINERR_IFANY(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::Any, Error, __VA_ARGS__) 92 #define WINERR_IFALL(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::All, Error, __VA_ARGS__) 93 #define WINWARN_IFANY(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::Any, Warning, __VA_ARGS__) 94 #define WINWARN_IFALL(Flags, ...) WINLOGF_IF(Flags, LogMaskReq::All, Warning, __VA_ARGS__) 95 96 #endif // liblldb_ProcessWindowsLog_h_ 97