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 { All, Any };
27 
28 class ProcessWindowsLog {
29   static const char *m_pluginname;
30 
31 public:
32   // ---------------------------------------------------------------------
33   // Public Static Methods
34   // ---------------------------------------------------------------------
35   static void Initialize();
36 
37   static void Terminate();
38 
39   static void RegisterPluginName(const char *pluginName) {
40     m_pluginname = pluginName;
41   }
42 
43   static void RegisterPluginName(lldb_private::ConstString pluginName) {
44     m_pluginname = pluginName.GetCString();
45   }
46 
47   static bool TestLogFlags(uint32_t mask, LogMaskReq req);
48 
49   static lldb_private::Log *GetLog();
50 
51   static void DisableLog(const char **args,
52                          lldb_private::Stream *feedback_strm);
53 
54   static lldb_private::Log *
55   EnableLog(const std::shared_ptr<llvm::raw_ostream> &log_stream_sp,
56             uint32_t log_options, const char **args,
57             lldb_private::Stream *feedback_strm);
58 
59   static void ListLogCategories(lldb_private::Stream *strm);
60 };
61 
62 #define WINLOGF_IF(Flags, Req, Method, ...)                                    \
63   {                                                                            \
64     if (ProcessWindowsLog::TestLogFlags(Flags, Req)) {                         \
65       Log *log = ProcessWindowsLog::GetLog();                                  \
66       if (log)                                                                 \
67         log->Method(__VA_ARGS__);                                              \
68     }                                                                          \
69   }
70 
71 #define WINLOG_IFANY(Flags, ...)                                               \
72   WINLOGF_IF(Flags, LogMaskReq::Any, Printf, __VA_ARGS__)
73 #define WINLOG_IFALL(Flags, ...)                                               \
74   WINLOGF_IF(Flags, LogMaskReq::All, Printf, __VA_ARGS__)
75 #define WINLOGV_IFANY(Flags, ...)                                              \
76   WINLOGF_IF(Flags, LogMaskReq::Any, Verbose, __VA_ARGS__)
77 #define WINLOGV_IFALL(Flags, ...)                                              \
78   WINLOGF_IF(Flags, LogMaskReq::All, Verbose, __VA_ARGS__)
79 #define WINLOGD_IFANY(Flags, ...)                                              \
80   WINLOGF_IF(Flags, LogMaskReq::Any, Debug, __VA_ARGS__)
81 #define WINLOGD_IFALL(Flags, ...)                                              \
82   WINLOGF_IF(Flags, LogMaskReq::All, Debug, __VA_ARGS__)
83 #define WINERR_IFANY(Flags, ...)                                               \
84   WINLOGF_IF(Flags, LogMaskReq::Any, Error, __VA_ARGS__)
85 #define WINERR_IFALL(Flags, ...)                                               \
86   WINLOGF_IF(Flags, LogMaskReq::All, Error, __VA_ARGS__)
87 #define WINWARN_IFANY(Flags, ...)                                              \
88   WINLOGF_IF(Flags, LogMaskReq::Any, Warning, __VA_ARGS__)
89 #define WINWARN_IFALL(Flags, ...)                                              \
90   WINLOGF_IF(Flags, LogMaskReq::All, Warning, __VA_ARGS__)
91 
92 #endif // liblldb_ProcessWindowsLog_h_
93