labath created this revision.

The main difference here is that in the WINLOG macros you can specify
log categories per call, whereas here you have to go the usual lldb
route of getting a Log* variable first. While this means you have to
write at least two statements, it usually means that each statement will
fit on a single line, whereas fitting the WINLOG invocation on a single
line was almost impossible. So the total size of code does not increase
even in functions with a single log statement, and functions with more
logging get shorter.

The downside here is reduced flexibility in specifying the log
categories, which a couple of functions used quite heavily (e.g.
RefreshStateAfterStop). For these I chose a single category used most
prominently and put everything into that, although a solution with
multiple log variables is definitely possible.


https://reviews.llvm.org/D30172

Files:
  source/Plugins/Process/Windows/Common/DebuggerThread.cpp
  source/Plugins/Process/Windows/Common/ProcessWindows.cpp
  source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
  source/Plugins/Process/Windows/Common/ProcessWindowsLog.h
  source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
  source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp

Index: source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
+++ source/Plugins/Process/Windows/Common/x86/RegisterContextWindows_x86.cpp
@@ -203,7 +203,8 @@
     return ReadRegisterHelper(CONTEXT_CONTROL, "EFLAGS", m_context.EFlags,
                               reg_value);
   default:
-    WINWARN_IFALL(WINDOWS_LOG_REGISTERS, "Requested unknown register %u", reg);
+    Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
+    LLDB_LOG(log, "Requested unknown register {0}", reg);
     break;
   }
   return false;
@@ -219,62 +220,52 @@
   if (!CacheAllRegisterValues())
     return false;
 
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
   uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
   switch (reg) {
   case lldb_eax_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EAX",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to EAX", reg_value.GetAsUInt32());
     m_context.Eax = reg_value.GetAsUInt32();
     break;
   case lldb_ebx_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBX",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to EBX", reg_value.GetAsUInt32());
     m_context.Ebx = reg_value.GetAsUInt32();
     break;
   case lldb_ecx_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ECX",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to ECX", reg_value.GetAsUInt32());
     m_context.Ecx = reg_value.GetAsUInt32();
     break;
   case lldb_edx_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDX",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to EDX", reg_value.GetAsUInt32());
     m_context.Edx = reg_value.GetAsUInt32();
     break;
   case lldb_edi_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EDI",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to EDI", reg_value.GetAsUInt32());
     m_context.Edi = reg_value.GetAsUInt32();
     break;
   case lldb_esi_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESI",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to ESI", reg_value.GetAsUInt32());
     m_context.Esi = reg_value.GetAsUInt32();
     break;
   case lldb_ebp_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EBP",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to EBP", reg_value.GetAsUInt32());
     m_context.Ebp = reg_value.GetAsUInt32();
     break;
   case lldb_esp_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to ESP",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to ESP", reg_value.GetAsUInt32());
     m_context.Esp = reg_value.GetAsUInt32();
     break;
   case lldb_eip_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EIP",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to EIP", reg_value.GetAsUInt32());
     m_context.Eip = reg_value.GetAsUInt32();
     break;
   case lldb_eflags_i386:
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Write value 0x%x to EFLAGS",
-                 reg_value.GetAsUInt32());
+    LLDB_LOG(log, "Write value {0:x} to EFLAGS", reg_value.GetAsUInt32());
     m_context.EFlags = reg_value.GetAsUInt32();
     break;
   default:
-    WINWARN_IFALL(WINDOWS_LOG_REGISTERS,
-                  "Write value 0x%x to unknown register %u",
-                  reg_value.GetAsUInt32(), reg);
+    LLDB_LOG(log, "Write value {0:x} to unknown register {1}",
+             reg_value.GetAsUInt32(), reg);
   }
 
   // Physically update the registers in the target process.
@@ -286,13 +277,12 @@
 bool RegisterContextWindows_x86::ReadRegisterHelper(
     DWORD flags_required, const char *reg_name, DWORD value,
     RegisterValue &reg_value) const {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
   if ((m_context.ContextFlags & flags_required) != flags_required) {
-    WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Thread context doesn't have %s",
-                 reg_name);
+    LLDB_LOG(log, "Thread context doesn't have {0}", reg_name);
     return false;
   }
-  WINLOG_IFALL(WINDOWS_LOG_REGISTERS, "Read value 0x%lx from %s", value,
-               reg_name);
+  LLDB_LOG(log, "Read value {0:x} from {1}", value, reg_name);
   reg_value.SetUInt32(value);
   return true;
 }
Index: source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
+++ source/Plugins/Process/Windows/Common/RegisterContextWindows.cpp
@@ -113,6 +113,7 @@
 bool RegisterContextWindows::HardwareSingleStep(bool enable) { return false; }
 
 bool RegisterContextWindows::CacheAllRegisterValues() {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_REGISTERS);
   if (!m_context_stale)
     return true;
 
@@ -122,14 +123,13 @@
   if (!::GetThreadContext(
           wthread.GetHostThread().GetNativeThread().GetSystemHandle(),
           &m_context)) {
-    WINERR_IFALL(
-        WINDOWS_LOG_REGISTERS,
-        "GetThreadContext failed with error %lu while caching register values.",
+    LLDB_LOG(
+        log,
+        "GetThreadContext failed with error {0} while caching register values.",
         ::GetLastError());
     return false;
   }
-  WINLOG_IFALL(WINDOWS_LOG_REGISTERS,
-               "GetThreadContext successfully updated the register values.");
+  LLDB_LOG(log, "successfully updated the register values.");
   m_context_stale = false;
   return true;
 }
Index: source/Plugins/Process/Windows/Common/ProcessWindowsLog.h
===================================================================
--- source/Plugins/Process/Windows/Common/ProcessWindowsLog.h
+++ source/Plugins/Process/Windows/Common/ProcessWindowsLog.h
@@ -44,9 +44,7 @@
     m_pluginname = pluginName.GetCString();
   }
 
-  static bool TestLogFlags(uint32_t mask, LogMaskReq req);
-
-  static lldb_private::Log *GetLog();
+  static lldb_private::Log *GetLogIfAny(uint32_t mask);
 
   static void DisableLog(const char **args,
                          lldb_private::Stream *feedback_strm);
@@ -59,30 +57,4 @@
   static void ListLogCategories(lldb_private::Stream *strm);
 };
 
-#define WINLOGF_IF(Flags, Req, Method, ...)                                    \
-  {                                                                            \
-    if (ProcessWindowsLog::TestLogFlags(Flags, Req)) {                         \
-      Log *log = ProcessWindowsLog::GetLog();                                  \
-      if (log)                                                                 \
-        log->Method(__VA_ARGS__);                                              \
-    }                                                                          \
-  }
-
-#define WINLOG_IFANY(Flags, ...)                                               \
-  WINLOGF_IF(Flags, LogMaskReq::Any, Printf, __VA_ARGS__)
-#define WINLOG_IFALL(Flags, ...)                                               \
-  WINLOGF_IF(Flags, LogMaskReq::All, Printf, __VA_ARGS__)
-#define WINLOGV_IFANY(Flags, ...)                                              \
-  WINLOGF_IF(Flags, LogMaskReq::Any, Verbose, __VA_ARGS__)
-#define WINLOGV_IFALL(Flags, ...)                                              \
-  WINLOGF_IF(Flags, LogMaskReq::All, Verbose, __VA_ARGS__)
-#define WINERR_IFANY(Flags, ...)                                               \
-  WINLOGF_IF(Flags, LogMaskReq::Any, Error, __VA_ARGS__)
-#define WINERR_IFALL(Flags, ...)                                               \
-  WINLOGF_IF(Flags, LogMaskReq::All, Error, __VA_ARGS__)
-#define WINWARN_IFANY(Flags, ...)                                              \
-  WINLOGF_IF(Flags, LogMaskReq::Any, Warning, __VA_ARGS__)
-#define WINWARN_IFALL(Flags, ...)                                              \
-  WINLOGF_IF(Flags, LogMaskReq::All, Warning, __VA_ARGS__)
-
 #endif // liblldb_ProcessWindowsLog_h_
Index: source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
+++ source/Plugins/Process/Windows/Common/ProcessWindowsLog.cpp
@@ -41,18 +41,8 @@
 
 void ProcessWindowsLog::Terminate() {}
 
-Log *ProcessWindowsLog::GetLog() { return (g_log_enabled) ? g_log : nullptr; }
-
-bool ProcessWindowsLog::TestLogFlags(uint32_t mask, LogMaskReq req) {
-  Log *log = GetLog();
-  if (!log)
-    return false;
-
-  uint32_t log_mask = log->GetMask().Get();
-  if (req == LogMaskReq::All)
-    return ((log_mask & mask) == mask);
-  else
-    return (log_mask & mask);
+Log *ProcessWindowsLog::GetLogIfAny(uint32_t mask) {
+  return (g_log_enabled && g_log->GetMask().AnySet(mask)) ? g_log : nullptr;
 }
 
 static uint32_t GetFlagBits(const char *arg) {
@@ -80,7 +70,7 @@
 }
 
 void ProcessWindowsLog::DisableLog(const char **args, Stream *feedback_strm) {
-  Log *log(GetLog());
+  Log *log(g_log);
   if (log) {
     uint32_t flag_bits = 0;
 
Index: source/Plugins/Process/Windows/Common/ProcessWindows.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -157,35 +157,30 @@
 uint32_t ProcessWindows::GetPluginVersion() { return 1; }
 
 Error ProcessWindows::EnableBreakpointSite(BreakpointSite *bp_site) {
-  WINLOG_IFALL(WINDOWS_LOG_BREAKPOINTS,
-               "EnableBreakpointSite called with bp_site 0x%p "
-               "(id=%d, addr=0x%llx)",
-               bp_site, bp_site->GetID(), bp_site->GetLoadAddress());
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_BREAKPOINTS);
+  LLDB_LOG(log, "bp_site = {0:x}, id={1}, addr={2:x}", bp_site,
+           bp_site->GetID(), bp_site->GetLoadAddress());
 
   Error error = EnableSoftwareBreakpoint(bp_site);
-  if (!error.Success()) {
-    WINERR_IFALL(WINDOWS_LOG_BREAKPOINTS, "EnableBreakpointSite failed.  %s",
-                 error.AsCString());
-  }
+  if (!error.Success())
+    LLDB_LOG(log, "error: {0}", error);
   return error;
 }
 
 Error ProcessWindows::DisableBreakpointSite(BreakpointSite *bp_site) {
-  WINLOG_IFALL(WINDOWS_LOG_BREAKPOINTS,
-               "DisableBreakpointSite called with bp_site 0x%p "
-               "(id=%d, addr=0x%llx)",
-               bp_site, bp_site->GetID(), bp_site->GetLoadAddress());
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_BREAKPOINTS);
+  LLDB_LOG(log, "bp_site = {0:x}, id={1}, addr={2:x}", bp_site,
+           bp_site->GetID(), bp_site->GetLoadAddress());
 
   Error error = DisableSoftwareBreakpoint(bp_site);
 
-  if (!error.Success()) {
-    WINERR_IFALL(WINDOWS_LOG_BREAKPOINTS, "DisableBreakpointSite failed.  %s",
-                 error.AsCString());
-  }
+  if (!error.Success())
+    LLDB_LOG(log, "error: {0}", error);
   return error;
 }
 
 Error ProcessWindows::DoDetach(bool keep_stopped) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
   DebuggerThreadSP debugger_thread;
   StateType private_state;
   {
@@ -198,23 +193,19 @@
     private_state = GetPrivateState();
 
     if (!m_session_data) {
-      WINWARN_IFALL(
-          WINDOWS_LOG_PROCESS,
-          "DoDetach called while state = %u, but there is no active session.",
-          private_state);
+      LLDB_LOG(log, "state = {0}, but there is no active session.",
+               private_state);
       return Error();
     }
 
     debugger_thread = m_session_data->m_debugger;
   }
 
   Error error;
   if (private_state != eStateExited && private_state != eStateDetached) {
-    WINLOG_IFALL(
-        WINDOWS_LOG_PROCESS,
-        "DoDetach called for process %p while state = %d.  Detaching...",
-        debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(),
-        private_state);
+    LLDB_LOG(log, "detaching from process {0} while state = {1}.",
+             debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(),
+             private_state);
     error = debugger_thread->StopDebugging(false);
     if (error.Success()) {
       SetPrivateState(eStateDetached);
@@ -224,9 +215,9 @@
     // we can be assured that no other thread will race for the session data.
     m_session_data.reset();
   } else {
-    WINERR_IFALL(
-        WINDOWS_LOG_PROCESS, "DoDetach called for process %p while state = "
-                             "%d, but cannot destroy in this state.",
+    LLDB_LOG(
+        log,
+        "error: process {0} in state = {1}, but cannot destroy in this state.",
         debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(),
         private_state);
   }
@@ -242,6 +233,7 @@
   // to acquire
   // the mutex.
 
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
   Error result;
   if (!launch_info.GetFlags().Test(eLaunchFlagDebug)) {
     StreamString stream;
@@ -251,7 +243,7 @@
     std::string message = stream.GetString();
     result.SetErrorString(message.c_str());
 
-    WINERR_IFALL(WINDOWS_LOG_PROCESS, "%s", message.c_str());
+    LLDB_LOG(log, "error: {0}", message);
     return result;
   }
 
@@ -266,23 +258,21 @@
   // Kick off the DebugLaunch asynchronously and wait for it to complete.
   result = debugger->DebugLaunch(launch_info);
   if (result.Fail()) {
-    WINERR_IFALL(WINDOWS_LOG_PROCESS, "DoLaunch failed launching '%s'.  %s",
-                 launch_info.GetExecutableFile().GetPath().c_str(),
-                 result.AsCString());
+    LLDB_LOG(log, "failed launching '{0}'. {1}",
+             launch_info.GetExecutableFile().GetPath(), result);
     return result;
   }
 
   HostProcess process;
   Error error = WaitForDebuggerConnection(debugger, process);
   if (error.Fail()) {
-    WINERR_IFALL(WINDOWS_LOG_PROCESS, "DoLaunch failed launching '%s'.  %s",
-                 launch_info.GetExecutableFile().GetPath().c_str(),
-                 error.AsCString());
+    LLDB_LOG(log, "failed launching '{0}'. {1}",
+             launch_info.GetExecutableFile().GetPath(), error);
     return error;
   }
 
-  WINLOG_IFALL(WINDOWS_LOG_PROCESS, "DoLaunch successfully launched '%s'",
-               launch_info.GetExecutableFile().GetPath().c_str());
+  LLDB_LOG(log, "successfully launched '{0}'",
+           launch_info.GetExecutableFile().GetPath());
 
   // We've hit the initial stop.  If eLaunchFlagsStopAtEntry was specified, the
   // private state
@@ -299,6 +289,7 @@
 
 Error ProcessWindows::DoAttachToProcessWithID(
     lldb::pid_t pid, const ProcessAttachInfo &attach_info) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
   m_session_data.reset(
       new ProcessWindowsData(!attach_info.GetContinueOnceAttached()));
 
@@ -310,27 +301,23 @@
   DWORD process_id = static_cast<DWORD>(pid);
   Error error = debugger->DebugAttach(process_id, attach_info);
   if (error.Fail()) {
-    WINLOG_IFALL(WINDOWS_LOG_PROCESS, "DoAttachToProcessWithID encountered an "
-                                      "error occurred initiating the "
-                                      "asynchronous attach.  %s",
-                 error.AsCString());
+    LLDB_LOG(
+        log,
+        "encountered an error occurred initiating the asynchronous attach. {0}",
+        error);
     return error;
   }
 
   HostProcess process;
   error = WaitForDebuggerConnection(debugger, process);
   if (error.Fail()) {
-    WINLOG_IFALL(WINDOWS_LOG_PROCESS, "DoAttachToProcessWithID encountered an "
-                                      "error waiting for the debugger to "
-                                      "connect.  %s",
-                 error.AsCString());
+    LLDB_LOG(log,
+             "encountered an error waiting for the debugger to connect. {0}",
+             error);
     return error;
   }
 
-  WINLOG_IFALL(
-      WINDOWS_LOG_PROCESS,
-      "DoAttachToProcessWithID successfully attached to process with pid=%lu",
-      process_id);
+  LLDB_LOG(log, "successfully attached to process with pid={0}", process_id);
 
   // We've hit the initial stop.  If eLaunchFlagsStopAtEntry was specified, the
   // private state
@@ -344,16 +331,15 @@
 }
 
 Error ProcessWindows::DoResume() {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
   llvm::sys::ScopedLock lock(m_mutex);
   Error error;
 
   StateType private_state = GetPrivateState();
   if (private_state == eStateStopped || private_state == eStateCrashed) {
-    WINLOG_IFALL(
-        WINDOWS_LOG_PROCESS,
-        "DoResume called for process %I64u while state is %u.  Resuming...",
-        m_session_data->m_debugger->GetProcess().GetProcessId(),
-        GetPrivateState());
+    LLDB_LOG(log, "process {0} is in state {1}.  Resuming...",
+             m_session_data->m_debugger->GetProcess().GetProcessId(),
+             GetPrivateState());
 
     ExceptionRecordSP active_exception =
         m_session_data->m_debugger->GetActiveException().lock();
@@ -365,8 +351,7 @@
           ExceptionResult::MaskException);
     }
 
-    WINLOG_IFANY(WINDOWS_LOG_PROCESS | WINDOWS_LOG_THREAD,
-                 "DoResume resuming %u threads.", m_thread_list.GetSize());
+    LLDB_LOG(log, "resuming {0} threads.", m_thread_list.GetSize());
 
     for (uint32_t i = 0; i < m_thread_list.GetSize(); ++i) {
       auto thread = std::static_pointer_cast<TargetThreadWindows>(
@@ -376,16 +361,15 @@
 
     SetPrivateState(eStateRunning);
   } else {
-    WINERR_IFALL(
-        WINDOWS_LOG_PROCESS,
-        "DoResume called for process %I64u but state is %u.  Returning...",
-        m_session_data->m_debugger->GetProcess().GetProcessId(),
-        GetPrivateState());
+    LLDB_LOG(log, "error: process %I64u is in state %u.  Returning...",
+             m_session_data->m_debugger->GetProcess().GetProcessId(),
+             GetPrivateState());
   }
   return error;
 }
 
 Error ProcessWindows::DoDestroy() {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
   DebuggerThreadSP debugger_thread;
   StateType private_state;
   {
@@ -399,40 +383,35 @@
     private_state = GetPrivateState();
 
     if (!m_session_data) {
-      WINWARN_IFALL(
-          WINDOWS_LOG_PROCESS,
-          "DoDestroy called while state = %u, but there is no active session.",
-          private_state);
+      LLDB_LOG(log, "warning: state = {0}, but there is no active session.",
+               private_state);
       return Error();
     }
 
     debugger_thread = m_session_data->m_debugger;
   }
 
   Error error;
   if (private_state != eStateExited && private_state != eStateDetached) {
-    WINLOG_IFALL(
-        WINDOWS_LOG_PROCESS, "DoDestroy called for process %p while state = "
-                             "%u.  Shutting down...",
-        debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(),
-        private_state);
+    LLDB_LOG(log, "Shutting down process {0} while state = {1}.",
+             debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(),
+             private_state);
     error = debugger_thread->StopDebugging(true);
 
     // By the time StopDebugging returns, there is no more debugger thread, so
     // we can be assured that no other thread will race for the session data.
     m_session_data.reset();
   } else {
-    WINERR_IFALL(
-        WINDOWS_LOG_PROCESS, "DoDestroy called for process %p while state = "
-                             "%d, but cannot destroy in this state.",
-        debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(),
-        private_state);
+    LLDB_LOG(log, "cannot destroy process {0} while state = {1}",
+             debugger_thread->GetProcess().GetNativeProcess().GetSystemHandle(),
+             private_state);
   }
 
   return error;
 }
 
 Error ProcessWindows::DoHalt(bool &caused_stop) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
   Error error;
   StateType state = GetPrivateState();
   if (state == eStateStopped)
@@ -444,10 +423,7 @@
                                           .GetSystemHandle());
     if (!caused_stop) {
       error.SetError(::GetLastError(), eErrorTypeWin32);
-      WINERR_IFALL(
-          WINDOWS_LOG_PROCESS,
-          "DoHalt called DebugBreakProcess, but it failed with error %u",
-          error.GetError());
+      LLDB_LOG(log, "DebugBreakProcess failed with error {0}", error);
     }
   }
   return error;
@@ -469,12 +445,11 @@
 }
 
 void ProcessWindows::RefreshStateAfterStop() {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION);
   llvm::sys::ScopedLock lock(m_mutex);
 
   if (!m_session_data) {
-    WINWARN_IFALL(
-        WINDOWS_LOG_PROCESS,
-        "RefreshStateAfterStop called with no active session.  Returning...");
+    LLDB_LOG(log, "no active session.  Returning...");
     return;
   }
 
@@ -484,11 +459,9 @@
       m_session_data->m_debugger->GetActiveException();
   ExceptionRecordSP active_exception = exception_record.lock();
   if (!active_exception) {
-    WINERR_IFALL(
-        WINDOWS_LOG_PROCESS,
-        "RefreshStateAfterStop called for process %I64u but there is no "
-        "active exception.  Why is the process stopped?",
-        m_session_data->m_debugger->GetProcess().GetProcessId());
+    LLDB_LOG(log, "there is no active exception in process {0}.  Why is the "
+                  "process stopped?",
+             m_session_data->m_debugger->GetProcess().GetProcessId());
     return;
   }
 
@@ -504,19 +477,15 @@
     const uint64_t pc = register_context->GetPC();
     BreakpointSiteSP site(GetBreakpointSiteList().FindByAddress(pc));
     if (site && site->ValidForThisThread(stop_thread.get())) {
-      WINLOG_IFANY(WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION |
-                       WINDOWS_LOG_STEP,
-                   "Single-stepped onto a breakpoint in process %I64u at "
-                   "address 0x%I64x with breakpoint site %d",
-                   m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
-                   site->GetID());
+      LLDB_LOG(log, "Single-stepped onto a breakpoint in process {0} at "
+                    "address {1:x} with breakpoint site {2}",
+               m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
+               site->GetID());
       stop_info = StopInfo::CreateStopReasonWithBreakpointSiteID(*stop_thread,
                                                                  site->GetID());
       stop_thread->SetStopInfo(stop_info);
     } else {
-      WINLOG_IFANY(WINDOWS_LOG_EXCEPTION | WINDOWS_LOG_STEP,
-                   "RefreshStateAfterStop single stepping thread %llu",
-                   stop_thread->GetID());
+      LLDB_LOG(log, "single stepping thread {0}", stop_thread->GetID());
       stop_info = StopInfo::CreateStopReasonToTrace(*stop_thread);
       stop_thread->SetStopInfo(stop_info);
     }
@@ -531,37 +500,32 @@
 
     BreakpointSiteSP site(GetBreakpointSiteList().FindByAddress(pc));
     if (site) {
-      WINLOG_IFANY(
-          WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION,
-          "RefreshStateAfterStop detected breakpoint in process %I64u at "
-          "address 0x%I64x with breakpoint site %d",
-          m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
-          site->GetID());
+      LLDB_LOG(log, "detected breakpoint in process {0} at address {1:x} with "
+                    "breakpoint site {2}",
+               m_session_data->m_debugger->GetProcess().GetProcessId(), pc,
+               site->GetID());
 
       if (site->ValidForThisThread(stop_thread.get())) {
-        WINLOG_IFALL(WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION,
-                     "Breakpoint site %d is valid for this thread (0x%I64x), "
-                     "creating stop info.",
-                     site->GetID(), stop_thread->GetID());
+        LLDB_LOG(log, "Breakpoint site {0} is valid for this thread ({1:x}), "
+                      "creating stop info.",
+                 site->GetID(), stop_thread->GetID());
 
         stop_info = StopInfo::CreateStopReasonWithBreakpointSiteID(
             *stop_thread, site->GetID());
         register_context->SetPC(pc);
       } else {
-        WINLOG_IFALL(WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION,
-                     "Breakpoint site %d is not valid for this thread, "
-                     "creating empty stop info.",
-                     site->GetID());
+        LLDB_LOG(log, "Breakpoint site {0} is not valid for this thread, "
+                      "creating empty stop info.",
+                 site->GetID());
       }
       stop_thread->SetStopInfo(stop_info);
       return;
     } else {
       // The thread hit a hard-coded breakpoint like an `int 3` or
       // `__debugbreak()`.
-      WINLOG_IFALL(
-          WINDOWS_LOG_BREAKPOINTS | WINDOWS_LOG_EXCEPTION,
-          "No breakpoint site matches for this thread. __debugbreak()?  "
-          "Creating stop info with the exception.");
+      LLDB_LOG(log,
+               "No breakpoint site matches for this thread. __debugbreak()?  "
+               "Creating stop info with the exception.");
       // FALLTHROUGH:  We'll treat this as a generic exception record in the
       // default case.
     }
@@ -577,7 +541,7 @@
     stop_info = StopInfo::CreateStopReasonWithException(
         *stop_thread, desc_stream.str().c_str());
     stop_thread->SetStopInfo(stop_info);
-    WINLOG_IFALL(WINDOWS_LOG_EXCEPTION, "%s", desc_stream.str().c_str());
+    LLDB_LOG(log, "{0}", desc_stream.str());
     return;
   }
   }
@@ -599,6 +563,7 @@
 
 bool ProcessWindows::UpdateThreadList(ThreadList &old_thread_list,
                                       ThreadList &new_thread_list) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_THREAD);
   // Add all the threads that were previously running and for which we did not
   // detect a thread exited event.
   int new_size = 0;
@@ -614,15 +579,10 @@
       new_thread_list.AddThread(old_thread);
       ++new_size;
       ++continued_threads;
-      WINLOGV_IFALL(
-          WINDOWS_LOG_THREAD,
-          "UpdateThreadList - Thread %llu was running and is still running.",
-          old_thread_id);
+      LLDB_LOGV(log, "Thread {0} was running and is still running.",
+                old_thread_id);
     } else {
-      WINLOGV_IFALL(
-          WINDOWS_LOG_THREAD,
-          "UpdateThreadList - Thread %llu was running and has exited.",
-          old_thread_id);
+      LLDB_LOGV(log, "Thread {0} was running and has exited.", old_thread_id);
       ++exited_threads;
     }
   }
@@ -635,15 +595,11 @@
     new_thread_list.AddThread(thread);
     ++new_size;
     ++new_threads;
-    WINLOGV_IFALL(WINDOWS_LOG_THREAD,
-                  "UpdateThreadList - Thread %llu is new since last update.",
-                  thread_info.first);
+    LLDB_LOGV(log, "Thread {0} is new since last update.", thread_info.first);
   }
 
-  WINLOG_IFALL(
-      WINDOWS_LOG_THREAD,
-      "UpdateThreadList - %d new threads, %d old threads, %d exited threads.",
-      new_threads, continued_threads, exited_threads);
+  LLDB_LOG(log, "{0} new threads, {1} old threads, {2} exited threads.",
+           new_threads, continued_threads, exited_threads);
 
   m_session_data->m_new_threads.clear();
   m_session_data->m_exited_threads.clear();
@@ -667,39 +623,35 @@
 
 size_t ProcessWindows::DoReadMemory(lldb::addr_t vm_addr, void *buf,
                                     size_t size, Error &error) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
   llvm::sys::ScopedLock lock(m_mutex);
 
   if (!m_session_data)
     return 0;
 
-  WINLOG_IFALL(WINDOWS_LOG_MEMORY,
-               "DoReadMemory attempting to read %u bytes from address 0x%I64x",
-               size, vm_addr);
+  LLDB_LOG(log, "attempting to read {0} bytes from address {1:x}", size,
+           vm_addr);
 
   HostProcess process = m_session_data->m_debugger->GetProcess();
   void *addr = reinterpret_cast<void *>(vm_addr);
   SIZE_T bytes_read = 0;
   if (!ReadProcessMemory(process.GetNativeProcess().GetSystemHandle(), addr,
                          buf, size, &bytes_read)) {
     error.SetError(GetLastError(), eErrorTypeWin32);
-    WINERR_IFALL(WINDOWS_LOG_MEMORY, "DoReadMemory failed with error code %u",
-                 error.GetError());
+    LLDB_LOG(log, "reading failed with error: {0}", error);
   }
   return bytes_read;
 }
 
 size_t ProcessWindows::DoWriteMemory(lldb::addr_t vm_addr, const void *buf,
                                      size_t size, Error &error) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
   llvm::sys::ScopedLock lock(m_mutex);
-  WINLOG_IFALL(
-      WINDOWS_LOG_MEMORY,
-      "DoWriteMemory attempting to write %u bytes into address 0x%I64x", size,
-      vm_addr);
+  LLDB_LOG(log, "attempting to write {0} bytes into address {1:x}", size,
+           vm_addr);
 
   if (!m_session_data) {
-    WINERR_IFANY(
-        WINDOWS_LOG_MEMORY,
-        "DoWriteMemory cannot write, there is no active debugger connection.");
+    LLDB_LOG(log, "cannot write, there is no active debugger connection.");
     return 0;
   }
 
@@ -711,37 +663,34 @@
     FlushInstructionCache(handle, addr, bytes_written);
   else {
     error.SetError(GetLastError(), eErrorTypeWin32);
-    WINLOG_IFALL(WINDOWS_LOG_MEMORY, "DoWriteMemory failed with error code %u",
-                 error.GetError());
+    LLDB_LOG(log, "writing failed with error: {0}", error);
   }
   return bytes_written;
 }
 
-#define BOOL_STR(b) ((b) ? "true" : "false")
-
 Error ProcessWindows::GetMemoryRegionInfo(lldb::addr_t vm_addr,
                                           MemoryRegionInfo &info) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_MEMORY);
   Error error;
   llvm::sys::ScopedLock lock(m_mutex);
   info.Clear();
 
   if (!m_session_data) {
     error.SetErrorString(
         "GetMemoryRegionInfo called with no debugging session.");
-    WINERR_IFALL(WINDOWS_LOG_MEMORY, "%s", error.AsCString());
+    LLDB_LOG(log, "error: {0}", error);
     return error;
   }
   HostProcess process = m_session_data->m_debugger->GetProcess();
   lldb::process_t handle = process.GetNativeProcess().GetSystemHandle();
   if (handle == nullptr || handle == LLDB_INVALID_PROCESS) {
     error.SetErrorString(
         "GetMemoryRegionInfo called with an invalid target process.");
-    WINERR_IFALL(WINDOWS_LOG_MEMORY, "%s", error.AsCString());
+    LLDB_LOG(log, "error: {0}", error);
     return error;
   }
 
-  WINLOG_IFALL(WINDOWS_LOG_MEMORY,
-               "GetMemoryRegionInfo getting info for address 0x%I64x", vm_addr);
+  LLDB_LOG(log, "getting info for address {0:x}", vm_addr);
 
   void *addr = reinterpret_cast<void *>(vm_addr);
   MEMORY_BASIC_INFORMATION mem_info = {};
@@ -762,10 +711,9 @@
       return error;
     } else {
       error.SetError(::GetLastError(), eErrorTypeWin32);
-      WINERR_IFALL(WINDOWS_LOG_MEMORY, "VirtualQueryEx returned error %u while "
-                                       "getting memory region info for address "
-                                       "0x%I64x",
-                   error.GetError(), vm_addr);
+      LLDB_LOG(log, "VirtualQueryEx returned error {0} while getting memory "
+                    "region info for address {1:x}",
+               error, vm_addr);
       return error;
     }
   }
@@ -807,10 +755,10 @@
   }
 
   error.SetError(::GetLastError(), eErrorTypeWin32);
-  WINLOGV_IFALL(WINDOWS_LOG_MEMORY, "Memory region info for address %llu: "
-                                    "readable=%s, executable=%s, writable=%s",
-                vm_addr, BOOL_STR(info.GetReadable()),
-                BOOL_STR(info.GetExecutable()), BOOL_STR(info.GetWritable()));
+  LLDB_LOGV(log, "Memory region info for address {0}: readable={1}, "
+                 "executable={2}, writable={3}",
+            vm_addr, info.GetReadable(), info.GetExecutable(),
+            info.GetWritable());
   return error;
 }
 
@@ -826,8 +774,8 @@
 
 void ProcessWindows::OnExitProcess(uint32_t exit_code) {
   // No need to acquire the lock since m_session_data isn't accessed.
-  WINLOG_IFALL(WINDOWS_LOG_PROCESS, "Process %llu exited with code %u", GetID(),
-               exit_code);
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
+  LLDB_LOG(log, "Process {0} exited with code {1}", GetID(), exit_code);
 
   TargetSP target = m_target_sp.lock();
   if (target) {
@@ -843,10 +791,9 @@
 
 void ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) {
   DebuggerThreadSP debugger = m_session_data->m_debugger;
-
-  WINLOG_IFALL(WINDOWS_LOG_PROCESS,
-               "Debugger connected to process %I64u.  Image base = 0x%I64x",
-               debugger->GetProcess().GetProcessId(), image_base);
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
+  LLDB_LOG(log, "Debugger connected to process {0}.  Image base = {1:x}",
+           debugger->GetProcess().GetProcessId(), image_base);
 
   ModuleSP module = GetTarget().GetExecutableModule();
   if (!module) {
@@ -890,6 +837,7 @@
 ExceptionResult
 ProcessWindows::OnDebugException(bool first_chance,
                                  const ExceptionRecord &record) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EXCEPTION);
   llvm::sys::ScopedLock lock(m_mutex);
 
   // FIXME: Without this check, occasionally when running the test suite there
@@ -902,10 +850,9 @@
   // full
   // lldb logs, and then add logging to the process plugin.
   if (!m_session_data) {
-    WINERR_IFANY(WINDOWS_LOG_EXCEPTION, "Debugger thread reported exception "
-                                        "0x%lx at address 0x%llu, but there is "
-                                        "no session.",
-                 record.GetExceptionCode(), record.GetExceptionAddress());
+    LLDB_LOG(log, "Debugger thread reported exception {0:x} at address {1:x}, "
+                  "but there is no session.",
+             record.GetExceptionCode(), record.GetExceptionAddress());
     return ExceptionResult::SendToApplication;
   }
 
@@ -921,29 +868,27 @@
     result = ExceptionResult::BreakInDebugger;
 
     if (!m_session_data->m_initial_stop_received) {
-      WINLOG_IFANY(WINDOWS_LOG_BREAKPOINTS, "Hit loader breakpoint at address "
-                                            "0x%I64x, setting initial stop "
-                                            "event.",
-                   record.GetExceptionAddress());
+      LLDB_LOG(
+          log,
+          "Hit loader breakpoint at address {0:x}, setting initial stop event.",
+          record.GetExceptionAddress());
       m_session_data->m_initial_stop_received = true;
       ::SetEvent(m_session_data->m_initial_stop_event);
     } else {
-      WINLOG_IFANY(WINDOWS_LOG_BREAKPOINTS,
-                   "Hit non-loader breakpoint at address 0x%I64x.",
-                   record.GetExceptionAddress());
+      LLDB_LOG(log, "Hit non-loader breakpoint at address {0:x}.",
+               record.GetExceptionAddress());
     }
     SetPrivateState(eStateStopped);
     break;
   case EXCEPTION_SINGLE_STEP:
     result = ExceptionResult::BreakInDebugger;
     SetPrivateState(eStateStopped);
     break;
   default:
-    WINLOG_IFANY(WINDOWS_LOG_EXCEPTION, "Debugger thread reported exception "
-                                        "0x%lx at address 0x%llx "
-                                        "(first_chance=%s)",
-                 record.GetExceptionCode(), record.GetExceptionAddress(),
-                 BOOL_STR(first_chance));
+    LLDB_LOG(log, "Debugger thread reported exception {0:x} at address {1:x} "
+                  "(first_chance={2})",
+             record.GetExceptionCode(), record.GetExceptionAddress(),
+             first_chance);
     // For non-breakpoints, give the application a chance to handle the
     // exception first.
     if (first_chance)
@@ -1011,41 +956,41 @@
 
 void ProcessWindows::OnDebuggerError(const Error &error, uint32_t type) {
   llvm::sys::ScopedLock lock(m_mutex);
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
 
   if (m_session_data->m_initial_stop_received) {
     // This happened while debugging.  Do we shutdown the debugging session, try
-    // to continue,
-    // or do something else?
-    WINERR_IFALL(WINDOWS_LOG_PROCESS, "Error %u occurred during debugging.  "
-                                      "Unexpected behavior may result.  %s",
-                 error.GetError(), error.AsCString());
+    // to continue, or do something else?
+    LLDB_LOG(log, "Error {0} occurred during debugging.  Unexpected behavior "
+                  "may result.  {1}",
+             error.GetError(), error);
   } else {
     // If we haven't actually launched the process yet, this was an error
     // launching the
     // process.  Set the internal error and signal the initial stop event so
     // that the DoLaunch
     // method wakes up and returns a failure.
     m_session_data->m_launch_error = error;
     ::SetEvent(m_session_data->m_initial_stop_event);
-    WINERR_IFALL(
-        WINDOWS_LOG_PROCESS,
-        "Error %u occurred launching the process before the initial stop.  %s",
-        error.GetError(), error.AsCString());
+    LLDB_LOG(
+        log,
+        "Error {0} occurred launching the process before the initial stop. {1}",
+        error.GetError(), error);
     return;
   }
 }
 
 Error ProcessWindows::WaitForDebuggerConnection(DebuggerThreadSP debugger,
                                                 HostProcess &process) {
   Error result;
-  WINLOG_IFANY(WINDOWS_LOG_PROCESS | WINDOWS_LOG_BREAKPOINTS,
-               "WaitForDebuggerConnection Waiting for loader breakpoint.");
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS |
+                                            WINDOWS_LOG_BREAKPOINTS);
+  LLDB_LOG(log, "Waiting for loader breakpoint.");
 
   // Block this function until we receive the initial stop from the process.
   if (::WaitForSingleObject(m_session_data->m_initial_stop_event, INFINITE) ==
       WAIT_OBJECT_0) {
-    WINLOG_IFANY(WINDOWS_LOG_PROCESS | WINDOWS_LOG_BREAKPOINTS,
-                 "WaitForDebuggerConnection hit loader breakpoint, returning.");
+    LLDB_LOG(log, "hit loader breakpoint, returning.");
 
     process = debugger->GetProcess();
     return m_session_data->m_launch_error;
Index: source/Plugins/Process/Windows/Common/DebuggerThread.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/DebuggerThread.cpp
+++ source/Plugins/Process/Windows/Common/DebuggerThread.cpp
@@ -61,41 +61,34 @@
 DebuggerThread::~DebuggerThread() { ::CloseHandle(m_debugging_ended_event); }
 
 Error DebuggerThread::DebugLaunch(const ProcessLaunchInfo &launch_info) {
-  WINLOG_IFALL(WINDOWS_LOG_PROCESS,
-               "DebuggerThread::DebugLaunch launching '%s'",
-               launch_info.GetExecutableFile().GetPath().c_str());
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
+  LLDB_LOG(log, "launching '{0}'", launch_info.GetExecutableFile().GetPath());
 
   Error error;
   DebugLaunchContext *context = new DebugLaunchContext(this, launch_info);
   HostThread slave_thread(ThreadLauncher::LaunchThread(
       "lldb.plugin.process-windows.slave[?]", DebuggerThreadLaunchRoutine,
       context, &error));
 
-  if (!error.Success()) {
-    WINERR_IFALL(WINDOWS_LOG_PROCESS,
-                 "DebugLaunch couldn't launch debugger thread.  %s",
-                 error.AsCString());
-  }
+  if (!error.Success())
+    LLDB_LOG(log, "couldn't launch debugger thread. {0}", error);
 
   return error;
 }
 
 Error DebuggerThread::DebugAttach(lldb::pid_t pid,
                                   const ProcessAttachInfo &attach_info) {
-  WINLOG_IFALL(WINDOWS_LOG_PROCESS,
-               "DebuggerThread::DebugAttach attaching to '%llu'", pid);
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
+  LLDB_LOG(log, "attaching to '{0}'", pid);
 
   Error error;
   DebugAttachContext *context = new DebugAttachContext(this, pid, attach_info);
   HostThread slave_thread(ThreadLauncher::LaunchThread(
       "lldb.plugin.process-windows.slave[?]", DebuggerThreadAttachRoutine,
       context, &error));
 
-  if (!error.Success()) {
-    WINERR_IFALL(WINDOWS_LOG_PROCESS,
-                 "DebugAttach couldn't attach to process '%llu'.  %s", pid,
-                 error.AsCString());
-  }
+  if (!error.Success())
+    LLDB_LOG(log, "couldn't attach to process '{0}'. {1}", pid, error);
 
   return error;
 }
@@ -123,9 +116,9 @@
   // thread routine has exited.
   std::shared_ptr<DebuggerThread> this_ref(shared_from_this());
 
-  WINLOG_IFALL(WINDOWS_LOG_PROCESS,
-               "DebuggerThread preparing to launch '%s' on background thread.",
-               launch_info.GetExecutableFile().GetPath().c_str());
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
+  LLDB_LOG(log, "preparing to launch '{0}' on background thread.",
+           launch_info.GetExecutableFile().GetPath());
 
   Error error;
   ProcessLauncherWindows launcher;
@@ -154,9 +147,9 @@
   // thread routine has exited.
   std::shared_ptr<DebuggerThread> this_ref(shared_from_this());
 
-  WINLOG_IFALL(WINDOWS_LOG_PROCESS, "DebuggerThread preparing to attach to "
-                                    "process '%llu' on background thread.",
-               pid);
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
+  LLDB_LOG(log, "preparing to attach to process '{0}' on background thread.",
+           pid);
 
   if (!DebugActiveProcess((DWORD)pid)) {
     Error error(::GetLastError(), eErrorTypeWin32);
@@ -179,9 +172,8 @@
 
   lldb::pid_t pid = m_process.GetProcessId();
 
-  WINLOG_IFALL(WINDOWS_LOG_PROCESS,
-               "StopDebugging('%s') called (inferior=%I64u).",
-               (terminate ? "true" : "false"), pid);
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS);
+  LLDB_LOG(log, "terminate = {0}, inferior={1}.", terminate, pid);
 
   // Set m_is_shutting_down to true if it was false.  Return if it was already
   // true.
@@ -200,10 +192,9 @@
     // next debug
     // event we get is the exit process event, and not some other event.
     BOOL terminate_suceeded = TerminateProcess(handle, 0);
-    WINLOG_IFALL(WINDOWS_LOG_PROCESS, "StopDebugging called "
-                                      "TerminateProcess(0x%p, 0) "
-                                      "(inferior=%I64u), success='%s'",
-                 handle, pid, (terminate_suceeded ? "true" : "false"));
+    LLDB_LOG(log,
+             "calling TerminateProcess({0}, 0) (inferior={1}), success={2}",
+             handle, pid, terminate_suceeded);
   }
 
   // If we're stuck waiting for an exception to continue (e.g. the user is at a
@@ -213,9 +204,7 @@
   // to make sure that the very next call to WaitForDebugEvent is an exit
   // process event.
   if (m_active_exception.get()) {
-    WINLOG_IFANY(WINDOWS_LOG_PROCESS | WINDOWS_LOG_EXCEPTION,
-                 "StopDebugging masking active exception");
-
+    LLDB_LOG(log, "masking active exception");
     ContinueAsyncException(ExceptionResult::MaskException);
   }
 
@@ -231,38 +220,31 @@
     }
   }
 
-  WINLOG_IFALL(
-      WINDOWS_LOG_PROCESS,
-      "StopDebugging waiting for detach from process %llu to complete.", pid);
+  LLDB_LOG(log, "waiting for detach from process {0} to complete.", pid);
 
   DWORD wait_result = WaitForSingleObject(m_debugging_ended_event, 5000);
   if (wait_result != WAIT_OBJECT_0) {
     error.SetError(GetLastError(), eErrorTypeWin32);
-    WINERR_IFALL(WINDOWS_LOG_PROCESS,
-                 "StopDebugging WaitForSingleObject(0x%p, 5000) returned %lu",
-                 m_debugging_ended_event, wait_result);
-  } else {
-    WINLOG_IFALL(
-        WINDOWS_LOG_PROCESS,
-        "StopDebugging detach from process %llu completed successfully.", pid);
-  }
+    LLDB_LOG(log, "error: WaitForSingleObject({0}, 5000) returned {1}",
+             m_debugging_ended_event, wait_result);
+  } else
+    LLDB_LOG(log, "detach from process {0} completed successfully.", pid);
 
   if (!error.Success()) {
-    WINERR_IFALL(WINDOWS_LOG_PROCESS, "StopDebugging encountered an error "
-                                      "while trying to stop process %llu.  %s",
-                 pid, error.AsCString());
+    LLDB_LOG(log, "encountered an error while trying to stop process {0}. {1}",
+             pid, error);
   }
   return error;
 }
 
 void DebuggerThread::ContinueAsyncException(ExceptionResult result) {
   if (!m_active_exception.get())
     return;
 
-  WINLOG_IFANY(
-      WINDOWS_LOG_PROCESS | WINDOWS_LOG_EXCEPTION,
-      "ContinueAsyncException called for inferior process %I64u, broadcasting.",
-      m_process.GetProcessId());
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_PROCESS |
+                                            WINDOWS_LOG_EXCEPTION);
+  LLDB_LOG(log, "broadcasting for inferior process {0}.",
+           m_process.GetProcessId());
 
   m_active_exception.reset();
   m_exception_pred.SetValue(result, eBroadcastAlways);
@@ -278,11 +260,12 @@
 }
 
 void DebuggerThread::DebugLoop() {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT);
   DEBUG_EVENT dbe = {};
   bool should_debug = true;
-  WINLOG_IFALL(WINDOWS_LOG_EVENT, "Entering WaitForDebugEvent loop");
+  LLDB_LOGV(log, "Entering WaitForDebugEvent loop");
   while (should_debug) {
-    WINLOGV_IFALL(WINDOWS_LOG_EVENT, "Calling WaitForDebugEvent");
+    LLDB_LOGV(log, "Calling WaitForDebugEvent");
     BOOL wait_result = WaitForDebugEvent(&dbe, INFINITE);
     if (wait_result) {
       DWORD continue_status = DBG_CONTINUE;
@@ -331,46 +314,42 @@
         break;
       }
 
-      WINLOGV_IFALL(
-          WINDOWS_LOG_EVENT,
-          "DebugLoop calling ContinueDebugEvent(%lu, %lu, %lu) on thread %lu.",
-          dbe.dwProcessId, dbe.dwThreadId, continue_status,
-          ::GetCurrentThreadId());
+      LLDB_LOGV(log, "calling ContinueDebugEvent({0}, {1}, {2}) on thread {3}.",
+                dbe.dwProcessId, dbe.dwThreadId, continue_status,
+                ::GetCurrentThreadId());
 
       ::ContinueDebugEvent(dbe.dwProcessId, dbe.dwThreadId, continue_status);
 
       if (m_detached) {
         should_debug = false;
       }
     } else {
-      WINERR_IFALL(
-          WINDOWS_LOG_EVENT,
-          "DebugLoop returned FALSE from WaitForDebugEvent.  Error = %lu",
-          ::GetLastError());
+      LLDB_LOG(log, "returned FALSE from WaitForDebugEvent.  Error = {0}",
+               ::GetLastError());
 
       should_debug = false;
     }
   }
   FreeProcessHandles();
 
-  WINLOG_IFALL(WINDOWS_LOG_EVENT, "WaitForDebugEvent loop completed, exiting.");
+  LLDB_LOG(log, "WaitForDebugEvent loop completed, exiting.");
   SetEvent(m_debugging_ended_event);
 }
 
 ExceptionResult
 DebuggerThread::HandleExceptionEvent(const EXCEPTION_DEBUG_INFO &info,
                                      DWORD thread_id) {
+  Log *log =
+      ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION);
   if (m_is_shutting_down) {
     // A breakpoint that occurs while `m_pid_to_detach` is non-zero is a magic
     // exception that
     // we use simply to wake up the DebuggerThread so that we can close out the
     // debug loop.
     if (m_pid_to_detach != 0 &&
         info.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT) {
-      WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION |
-                       WINDOWS_LOG_PROCESS,
-                   "Breakpoint exception is cue to detach from process 0x%lx",
-                   m_pid_to_detach.load());
+      LLDB_LOG(log, "Breakpoint exception is cue to detach from process {0:x}",
+               m_pid_to_detach.load());
       ::DebugActiveProcessStop(m_pid_to_detach);
       m_detached = true;
     }
@@ -385,36 +364,29 @@
 
   m_active_exception.reset(
       new ExceptionRecord(info.ExceptionRecord, thread_id));
-  WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION,
-               "HandleExceptionEvent encountered %s chance exception 0x%lx on "
-               "thread 0x%lx",
-               first_chance ? "first" : "second",
-               info.ExceptionRecord.ExceptionCode, thread_id);
+  LLDB_LOG(log, "encountered {0} chance exception {1:x} on thread {2:x}",
+           first_chance ? "first" : "second",
+           info.ExceptionRecord.ExceptionCode, thread_id);
 
   ExceptionResult result =
       m_debug_delegate->OnDebugException(first_chance, *m_active_exception);
   m_exception_pred.SetValue(result, eBroadcastNever);
 
-  WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION,
-               "DebuggerThread::HandleExceptionEvent waiting for ExceptionPred "
-               "!= BreakInDebugger");
-
+  LLDB_LOG(log, "waiting for ExceptionPred != BreakInDebugger");
   m_exception_pred.WaitForValueNotEqualTo(ExceptionResult::BreakInDebugger,
                                           result);
 
-  WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION,
-               "DebuggerThread::HandleExceptionEvent got ExceptionPred = %u",
-               m_exception_pred.GetValue());
-
+  LLDB_LOG(log, "got ExceptionPred = {0}", (int)m_exception_pred.GetValue());
   return result;
 }
 
 DWORD
 DebuggerThread::HandleCreateThreadEvent(const CREATE_THREAD_DEBUG_INFO &info,
                                         DWORD thread_id) {
-  WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD,
-               "HandleCreateThreadEvent Thread 0x%lx spawned in process %llu",
-               thread_id, m_process.GetProcessId());
+  Log *log =
+      ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD);
+  LLDB_LOG(log, "Thread {0:x} spawned in process {1}", thread_id,
+           m_process.GetProcessId());
   HostThread thread(info.hThread);
   thread.GetNativeThread().SetOwnsHandle(false);
   m_debug_delegate->OnCreateThread(thread);
@@ -424,10 +396,11 @@
 DWORD
 DebuggerThread::HandleCreateProcessEvent(const CREATE_PROCESS_DEBUG_INFO &info,
                                          DWORD thread_id) {
+  Log *log =
+      ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_PROCESS);
   uint32_t process_id = ::GetProcessId(info.hProcess);
 
-  WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_PROCESS,
-               "HandleCreateProcessEvent process %u spawned", process_id);
+  LLDB_LOG(log, "process {0} spawned", process_id);
 
   std::string thread_name;
   llvm::raw_string_ostream name_stream(thread_name);
@@ -452,20 +425,21 @@
 DWORD
 DebuggerThread::HandleExitThreadEvent(const EXIT_THREAD_DEBUG_INFO &info,
                                       DWORD thread_id) {
-  WINLOG_IFANY(
-      WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD,
-      "HandleExitThreadEvent Thread %lu exited with code %lu in process %llu",
-      thread_id, info.dwExitCode, m_process.GetProcessId());
+  Log *log =
+      ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD);
+  LLDB_LOG(log, "Thread {0} exited with code {1} in process {2}", thread_id,
+           info.dwExitCode, m_process.GetProcessId());
   m_debug_delegate->OnExitThread(thread_id, info.dwExitCode);
   return DBG_CONTINUE;
 }
 
 DWORD
 DebuggerThread::HandleExitProcessEvent(const EXIT_PROCESS_DEBUG_INFO &info,
                                        DWORD thread_id) {
-  WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD,
-               "HandleExitProcessEvent process %llu exited with code %lu",
-               m_process.GetProcessId(), info.dwExitCode);
+  Log *log =
+      ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD);
+  LLDB_LOG(log, "process {0} exited with code {1}", m_process.GetProcessId(),
+           info.dwExitCode);
 
   m_debug_delegate->OnExitProcess(info.dwExitCode);
 
@@ -476,11 +450,11 @@
 DWORD
 DebuggerThread::HandleLoadDllEvent(const LOAD_DLL_DEBUG_INFO &info,
                                    DWORD thread_id) {
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT);
   if (info.hFile == nullptr) {
     // Not sure what this is, so just ignore it.
-    WINWARN_IFALL(WINDOWS_LOG_EVENT, "Inferior %llu - HandleLoadDllEvent has "
-                                     "a NULL file handle, returning...",
-                  m_process.GetProcessId());
+    LLDB_LOG(log, "Warning: Inferior {0} has a NULL file handle, returning...",
+             m_process.GetProcessId());
     return DBG_CONTINUE;
   }
 
@@ -502,16 +476,15 @@
     ModuleSpec module_spec(file_spec);
     lldb::addr_t load_addr = reinterpret_cast<lldb::addr_t>(info.lpBaseOfDll);
 
-    WINLOG_IFALL(WINDOWS_LOG_EVENT, "Inferior %I64u - HandleLoadDllEvent DLL "
-                                    "'%s' loaded at address 0x%p...",
-                 m_process.GetProcessId(), path, info.lpBaseOfDll);
+    LLDB_LOG(log, "Inferior {0} - DLL '{1}' loaded at address {2:x}...",
+             m_process.GetProcessId(), path, info.lpBaseOfDll);
 
     m_debug_delegate->OnLoadDll(module_spec, load_addr);
   } else {
-    WINERR_IFALL(WINDOWS_LOG_EVENT, "Inferior %llu - HandleLoadDllEvent Error "
-                                    "%lu occurred calling "
-                                    "GetFinalPathNameByHandle",
-                 m_process.GetProcessId(), ::GetLastError());
+    LLDB_LOG(
+        log,
+        "Inferior {0} - Error {1} occurred calling GetFinalPathNameByHandle",
+        m_process.GetProcessId(), ::GetLastError());
   }
   // Windows does not automatically close info.hFile, so we need to do it.
   ::CloseHandle(info.hFile);
@@ -521,9 +494,9 @@
 DWORD
 DebuggerThread::HandleUnloadDllEvent(const UNLOAD_DLL_DEBUG_INFO &info,
                                      DWORD thread_id) {
-  WINLOG_IFALL(WINDOWS_LOG_EVENT,
-               "HandleUnloadDllEvent process %llu unloading DLL at addr 0x%p.",
-               m_process.GetProcessId(), info.lpBaseOfDll);
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT);
+  LLDB_LOG(log, "process {0} unloading DLL at addr {1:x}.",
+           m_process.GetProcessId(), info.lpBaseOfDll);
 
   m_debug_delegate->OnUnloadDll(
       reinterpret_cast<lldb::addr_t>(info.lpBaseOfDll));
@@ -538,9 +511,9 @@
 
 DWORD
 DebuggerThread::HandleRipEvent(const RIP_INFO &info, DWORD thread_id) {
-  WINERR_IFALL(WINDOWS_LOG_EVENT, "HandleRipEvent encountered error %lu "
-                                  "(type=%lu) in process %llu thread %lu",
-               info.dwError, info.dwType, m_process.GetProcessId(), thread_id);
+  Log *log = ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT);
+  LLDB_LOG(log, "encountered error {0} (type={1}) in process {2} thread {3}",
+           info.dwError, info.dwType, m_process.GetProcessId(), thread_id);
 
   Error error(info.dwError, eErrorTypeWin32);
   m_debug_delegate->OnDebuggerError(error, info.dwType);
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to