[Logging] Replace Log::Printf with LLDB_LOG macro (NFC)

This patch replaces explicit calls to log::Printf with the new LLDB_LOGF
macro. The macro is similar to LLDB_LOG but supports printf-style format
strings, instead of formatv-style format strings.

So instead of writing:

  if (log)
    log->Printf("%s\n", str);

You'd write:

  LLDB_LOG(log, "%s\n", str);

This change was done mechanically with the command below. I replaced the
spurious if-checks with vim, since I know how to do multi-line
replacements with it.

  find . -type f -name '*.cpp' -exec \
  sed -i '' -E 's/log->Printf\(/LLDB_LOGF\(log, /g' "{}" +

Differential revision: https://reviews.llvm.org/D65128

llvm-svn: 366936
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index a6fdd8d..ce2073a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -354,10 +354,10 @@
 
   if (m_async_listener_sp->StartListeningForEvents(
           &m_async_broadcaster, async_event_mask) != async_event_mask) {
-    if (log)
-      log->Printf("ProcessGDBRemote::%s failed to listen for "
-                  "m_async_broadcaster events",
-                  __FUNCTION__);
+    LLDB_LOGF(log,
+              "ProcessGDBRemote::%s failed to listen for "
+              "m_async_broadcaster events",
+              __FUNCTION__);
   }
 
   const uint32_t gdb_event_mask =
@@ -365,9 +365,9 @@
       GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify;
   if (m_async_listener_sp->StartListeningForEvents(
           &m_gdb_comm, gdb_event_mask) != gdb_event_mask) {
-    if (log)
-      log->Printf("ProcessGDBRemote::%s failed to listen for m_gdb_comm events",
-                  __FUNCTION__);
+    LLDB_LOGF(log,
+              "ProcessGDBRemote::%s failed to listen for m_gdb_comm events",
+              __FUNCTION__);
   }
 
   const uint64_t timeout_seconds =
@@ -785,15 +785,15 @@
                                      pid, remote_url.str().c_str());
   }
 
-  if (log)
-    log->Printf("ProcessGDBRemote::%s pid %" PRIu64
-                ": normalizing target architecture initial triple: %s "
-                "(GetTarget().GetArchitecture().IsValid() %s, "
-                "m_gdb_comm.GetHostArchitecture().IsValid(): %s)",
-                __FUNCTION__, GetID(),
-                GetTarget().GetArchitecture().GetTriple().getTriple().c_str(),
-                GetTarget().GetArchitecture().IsValid() ? "true" : "false",
-                m_gdb_comm.GetHostArchitecture().IsValid() ? "true" : "false");
+  LLDB_LOGF(log,
+            "ProcessGDBRemote::%s pid %" PRIu64
+            ": normalizing target architecture initial triple: %s "
+            "(GetTarget().GetArchitecture().IsValid() %s, "
+            "m_gdb_comm.GetHostArchitecture().IsValid(): %s)",
+            __FUNCTION__, GetID(),
+            GetTarget().GetArchitecture().GetTriple().getTriple().c_str(),
+            GetTarget().GetArchitecture().IsValid() ? "true" : "false",
+            m_gdb_comm.GetHostArchitecture().IsValid() ? "true" : "false");
 
   if (error.Success() && !GetTarget().GetArchitecture().IsValid() &&
       m_gdb_comm.GetHostArchitecture().IsValid()) {
@@ -805,11 +805,11 @@
       GetTarget().SetArchitecture(m_gdb_comm.GetHostArchitecture());
   }
 
-  if (log)
-    log->Printf("ProcessGDBRemote::%s pid %" PRIu64
-                ": normalized target architecture triple: %s",
-                __FUNCTION__, GetID(),
-                GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
+  LLDB_LOGF(log,
+            "ProcessGDBRemote::%s pid %" PRIu64
+            ": normalized target architecture triple: %s",
+            __FUNCTION__, GetID(),
+            GetTarget().GetArchitecture().GetTriple().getTriple().c_str());
 
   if (error.Success()) {
     PlatformSP platform_sp = GetTarget().GetPlatform();
@@ -834,8 +834,7 @@
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
   Status error;
 
-  if (log)
-    log->Printf("ProcessGDBRemote::%s() entered", __FUNCTION__);
+  LLDB_LOGF(log, "ProcessGDBRemote::%s() entered", __FUNCTION__);
 
   uint32_t launch_flags = launch_info.GetFlags().Get();
   FileSpec stdin_file_spec{};
@@ -862,15 +861,17 @@
 
   if (log) {
     if (stdin_file_spec || stdout_file_spec || stderr_file_spec)
-      log->Printf("ProcessGDBRemote::%s provided with STDIO paths via "
-                  "launch_info: stdin=%s, stdout=%s, stderr=%s",
-                  __FUNCTION__,
-                  stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
-                  stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
-                  stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s provided with STDIO paths via "
+                "launch_info: stdin=%s, stdout=%s, stderr=%s",
+                __FUNCTION__,
+                stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
+                stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
+                stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
     else
-      log->Printf("ProcessGDBRemote::%s no STDIO paths given via launch_info",
-                  __FUNCTION__);
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s no STDIO paths given via launch_info",
+                __FUNCTION__);
   }
 
   const bool disable_stdio = (launch_flags & eLaunchFlagDisableSTDIO) != 0;
@@ -925,24 +926,23 @@
           if (!stderr_file_spec)
             stderr_file_spec = slave_name;
         }
-        if (log)
-          log->Printf(
-              "ProcessGDBRemote::%s adjusted STDIO paths for local platform "
-              "(IsHost() is true) using slave: stdin=%s, stdout=%s, stderr=%s",
-              __FUNCTION__,
-              stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
-              stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
-              stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
+        LLDB_LOGF(
+            log,
+            "ProcessGDBRemote::%s adjusted STDIO paths for local platform "
+            "(IsHost() is true) using slave: stdin=%s, stdout=%s, stderr=%s",
+            __FUNCTION__,
+            stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
+            stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
+            stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
       }
 
-      if (log)
-        log->Printf("ProcessGDBRemote::%s final STDIO paths after all "
-                    "adjustments: stdin=%s, stdout=%s, stderr=%s",
-                    __FUNCTION__,
-                    stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
-                    stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
-                    stderr_file_spec ? stderr_file_spec.GetCString()
-                                     : "<null>");
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s final STDIO paths after all "
+                "adjustments: stdin=%s, stdout=%s, stderr=%s",
+                __FUNCTION__,
+                stdin_file_spec ? stdin_file_spec.GetCString() : "<null>",
+                stdout_file_spec ? stdout_file_spec.GetCString() : "<null>",
+                stderr_file_spec ? stderr_file_spec.GetCString() : "<null>");
 
       if (stdin_file_spec)
         m_gdb_comm.SetSTDIN(stdin_file_spec);
@@ -988,9 +988,8 @@
       }
 
       if (GetID() == LLDB_INVALID_PROCESS_ID) {
-        if (log)
-          log->Printf("failed to connect to debugserver: %s",
-                      error.AsCString());
+        LLDB_LOGF(log, "failed to connect to debugserver: %s",
+                  error.AsCString());
         KillDebugserverProcess();
         return error;
       }
@@ -1020,8 +1019,7 @@
         }
       }
     } else {
-      if (log)
-        log->Printf("failed to connect to debugserver: %s", error.AsCString());
+      LLDB_LOGF(log, "failed to connect to debugserver: %s", error.AsCString());
     }
   } else {
     // Set our user ID to an invalid process ID.
@@ -1040,9 +1038,8 @@
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
 
   if (!connect_url.empty()) {
-    if (log)
-      log->Printf("ProcessGDBRemote::%s Connecting to %s", __FUNCTION__,
-                  connect_url.str().c_str());
+    LLDB_LOGF(log, "ProcessGDBRemote::%s Connecting to %s", __FUNCTION__,
+              connect_url.str().c_str());
     std::unique_ptr<ConnectionFileDescriptor> conn_up(
         new ConnectionFileDescriptor());
     if (conn_up) {
@@ -1116,8 +1113,7 @@
 
 void ProcessGDBRemote::DidLaunchOrAttach(ArchSpec &process_arch) {
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-  if (log)
-    log->Printf("ProcessGDBRemote::%s()", __FUNCTION__);
+  LLDB_LOGF(log, "ProcessGDBRemote::%s()", __FUNCTION__);
   if (GetID() != LLDB_INVALID_PROCESS_ID) {
     BuildDynamicRegisterInfo(false);
 
@@ -1130,43 +1126,42 @@
     const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture();
     if (remote_process_arch.IsValid()) {
       process_arch = remote_process_arch;
-      if (log)
-        log->Printf("ProcessGDBRemote::%s gdb-remote had process architecture, "
-                    "using %s %s",
-                    __FUNCTION__,
-                    process_arch.GetArchitectureName()
-                        ? process_arch.GetArchitectureName()
-                        : "<null>",
-                    process_arch.GetTriple().getTriple().c_str()
-                        ? process_arch.GetTriple().getTriple().c_str()
-                        : "<null>");
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s gdb-remote had process architecture, "
+                "using %s %s",
+                __FUNCTION__,
+                process_arch.GetArchitectureName()
+                    ? process_arch.GetArchitectureName()
+                    : "<null>",
+                process_arch.GetTriple().getTriple().c_str()
+                    ? process_arch.GetTriple().getTriple().c_str()
+                    : "<null>");
     } else {
       process_arch = m_gdb_comm.GetHostArchitecture();
-      if (log)
-        log->Printf("ProcessGDBRemote::%s gdb-remote did not have process "
-                    "architecture, using gdb-remote host architecture %s %s",
-                    __FUNCTION__,
-                    process_arch.GetArchitectureName()
-                        ? process_arch.GetArchitectureName()
-                        : "<null>",
-                    process_arch.GetTriple().getTriple().c_str()
-                        ? process_arch.GetTriple().getTriple().c_str()
-                        : "<null>");
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s gdb-remote did not have process "
+                "architecture, using gdb-remote host architecture %s %s",
+                __FUNCTION__,
+                process_arch.GetArchitectureName()
+                    ? process_arch.GetArchitectureName()
+                    : "<null>",
+                process_arch.GetTriple().getTriple().c_str()
+                    ? process_arch.GetTriple().getTriple().c_str()
+                    : "<null>");
     }
 
     if (process_arch.IsValid()) {
       const ArchSpec &target_arch = GetTarget().GetArchitecture();
       if (target_arch.IsValid()) {
-        if (log)
-          log->Printf(
-              "ProcessGDBRemote::%s analyzing target arch, currently %s %s",
-              __FUNCTION__,
-              target_arch.GetArchitectureName()
-                  ? target_arch.GetArchitectureName()
-                  : "<null>",
-              target_arch.GetTriple().getTriple().c_str()
-                  ? target_arch.GetTriple().getTriple().c_str()
-                  : "<null>");
+        LLDB_LOGF(log,
+                  "ProcessGDBRemote::%s analyzing target arch, currently %s %s",
+                  __FUNCTION__,
+                  target_arch.GetArchitectureName()
+                      ? target_arch.GetArchitectureName()
+                      : "<null>",
+                  target_arch.GetTriple().getTriple().c_str()
+                      ? target_arch.GetTriple().getTriple().c_str()
+                      : "<null>");
 
         // If the remote host is ARM and we have apple as the vendor, then
         // ARM executables and shared libraries can have mixed ARM
@@ -1180,16 +1175,16 @@
              process_arch.GetMachine() == llvm::Triple::thumb) &&
             process_arch.GetTriple().getVendor() == llvm::Triple::Apple) {
           GetTarget().SetArchitecture(process_arch);
-          if (log)
-            log->Printf("ProcessGDBRemote::%s remote process is ARM/Apple, "
-                        "setting target arch to %s %s",
-                        __FUNCTION__,
-                        process_arch.GetArchitectureName()
-                            ? process_arch.GetArchitectureName()
-                            : "<null>",
-                        process_arch.GetTriple().getTriple().c_str()
-                            ? process_arch.GetTriple().getTriple().c_str()
-                            : "<null>");
+          LLDB_LOGF(log,
+                    "ProcessGDBRemote::%s remote process is ARM/Apple, "
+                    "setting target arch to %s %s",
+                    __FUNCTION__,
+                    process_arch.GetArchitectureName()
+                        ? process_arch.GetArchitectureName()
+                        : "<null>",
+                    process_arch.GetTriple().getTriple().c_str()
+                        ? process_arch.GetTriple().getTriple().c_str()
+                        : "<null>");
         } else {
           // Fill in what is missing in the triple
           const llvm::Triple &remote_triple = process_arch.GetTriple();
@@ -1211,16 +1206,16 @@
           }
         }
 
-        if (log)
-          log->Printf("ProcessGDBRemote::%s final target arch after "
-                      "adjustments for remote architecture: %s %s",
-                      __FUNCTION__,
-                      target_arch.GetArchitectureName()
-                          ? target_arch.GetArchitectureName()
-                          : "<null>",
-                      target_arch.GetTriple().getTriple().c_str()
-                          ? target_arch.GetTriple().getTriple().c_str()
-                          : "<null>");
+        LLDB_LOGF(log,
+                  "ProcessGDBRemote::%s final target arch after "
+                  "adjustments for remote architecture: %s %s",
+                  __FUNCTION__,
+                  target_arch.GetArchitectureName()
+                      ? target_arch.GetArchitectureName()
+                      : "<null>",
+                  target_arch.GetTriple().getTriple().c_str()
+                      ? target_arch.GetTriple().getTriple().c_str()
+                      : "<null>");
       } else {
         // The target doesn't have a valid architecture yet, set it from the
         // architecture we got from the remote GDB server
@@ -1247,8 +1242,7 @@
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
   Status error;
 
-  if (log)
-    log->Printf("ProcessGDBRemote::%s()", __FUNCTION__);
+  LLDB_LOGF(log, "ProcessGDBRemote::%s()", __FUNCTION__);
 
   // Clear out and clean up from any current state
   Clear();
@@ -1359,8 +1353,7 @@
 Status ProcessGDBRemote::DoResume() {
   Status error;
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-  if (log)
-    log->Printf("ProcessGDBRemote::Resume()");
+  LLDB_LOGF(log, "ProcessGDBRemote::Resume()");
 
   ListenerSP listener_sp(
       Listener::MakeListener("gdb-remote.resume-packet-sent"));
@@ -1547,9 +1540,8 @@
       EventSP event_sp;
       if (!m_async_thread.IsJoinable()) {
         error.SetErrorString("Trying to resume but the async thread is dead.");
-        if (log)
-          log->Printf("ProcessGDBRemote::DoResume: Trying to resume but the "
-                      "async thread is dead.");
+        LLDB_LOGF(log, "ProcessGDBRemote::DoResume: Trying to resume but the "
+                       "async thread is dead.");
         return error;
       }
 
@@ -1560,14 +1552,13 @@
 
       if (!listener_sp->GetEvent(event_sp, std::chrono::seconds(5))) {
         error.SetErrorString("Resume timed out.");
-        if (log)
-          log->Printf("ProcessGDBRemote::DoResume: Resume timed out.");
+        LLDB_LOGF(log, "ProcessGDBRemote::DoResume: Resume timed out.");
       } else if (event_sp->BroadcasterIs(&m_async_broadcaster)) {
         error.SetErrorString("Broadcast continue, but the async thread was "
                              "killed before we got an ack back.");
-        if (log)
-          log->Printf("ProcessGDBRemote::DoResume: Broadcast continue, but the "
-                      "async thread was killed before we got an ack back.");
+        LLDB_LOGF(log,
+                  "ProcessGDBRemote::DoResume: Broadcast continue, but the "
+                  "async thread was killed before we got an ack back.");
         return error;
       }
     }
@@ -1979,8 +1970,7 @@
               if (watch_id == LLDB_INVALID_WATCH_ID) {
                 Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(
                     GDBR_LOG_WATCHPOINTS));
-                if (log)
-                  log->Printf("failed to find watchpoint");
+                LLDB_LOGF(log, "failed to find watchpoint");
               }
               thread_sp->SetStopInfo(StopInfo::CreateStopReasonWithWatchpointID(
                   *thread_sp, watch_id, wp_hit_addr));
@@ -2501,8 +2491,7 @@
 Status ProcessGDBRemote::DoDetach(bool keep_stopped) {
   Status error;
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-  if (log)
-    log->Printf("ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped);
+  LLDB_LOGF(log, "ProcessGDBRemote::DoDetach(keep_stopped: %i)", keep_stopped);
 
   error = m_gdb_comm.Detach(keep_stopped);
   if (log) {
@@ -2510,8 +2499,9 @@
       log->PutCString(
           "ProcessGDBRemote::DoDetach() detach packet sent successfully");
     else
-      log->Printf("ProcessGDBRemote::DoDetach() detach packet send failed: %s",
-                  error.AsCString() ? error.AsCString() : "<unknown error>");
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::DoDetach() detach packet send failed: %s",
+                error.AsCString() ? error.AsCString() : "<unknown error>");
   }
 
   if (!error.Success())
@@ -2530,8 +2520,7 @@
 Status ProcessGDBRemote::DoDestroy() {
   Status error;
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-  if (log)
-    log->Printf("ProcessGDBRemote::DoDestroy()");
+  LLDB_LOGF(log, "ProcessGDBRemote::DoDestroy()");
 
   // There is a bug in older iOS debugservers where they don't shut down the
   // process they are debugging properly.  If the process is sitting at a
@@ -2586,11 +2575,11 @@
               reason = stop_info_sp->GetStopReason();
             if (reason == eStopReasonBreakpoint ||
                 reason == eStopReasonException) {
-              if (log)
-                log->Printf(
-                    "ProcessGDBRemote::DoDestroy() - thread: 0x%4.4" PRIx64
-                    " stopped with reason: %s.",
-                    thread_sp->GetProtocolID(), stop_info_sp->GetDescription());
+              LLDB_LOGF(log,
+                        "ProcessGDBRemote::DoDestroy() - thread: 0x%4.4" PRIx64
+                        " stopped with reason: %s.",
+                        thread_sp->GetProtocolID(),
+                        stop_info_sp->GetDescription());
               stop_looks_like_crash = true;
               break;
             }
@@ -2622,10 +2611,10 @@
                 reason = stop_info_sp->GetStopReason();
               if (reason != eStopReasonBreakpoint &&
                   reason != eStopReasonException) {
-                if (log)
-                  log->Printf("ProcessGDBRemote::DoDestroy() - Suspending "
-                              "thread: 0x%4.4" PRIx64 " before running.",
-                              thread_sp->GetProtocolID());
+                LLDB_LOGF(log,
+                          "ProcessGDBRemote::DoDestroy() - Suspending "
+                          "thread: 0x%4.4" PRIx64 " before running.",
+                          thread_sp->GetProtocolID());
                 thread_sp->SetResumeState(eStateSuspended);
               }
             }
@@ -2669,30 +2658,28 @@
             int status;
             ::pid_t reap_pid;
             reap_pid = waitpid(GetID(), &status, WNOHANG);
-            if (log)
-              log->Printf("Reaped pid: %d, status: %d.\n", reap_pid, status);
+            LLDB_LOGF(log, "Reaped pid: %d, status: %d.\n", reap_pid, status);
           }
 #endif
           SetLastStopPacket(response);
           ClearThreadIDList();
           exit_status = response.GetHexU8();
         } else {
-          if (log)
-            log->Printf("ProcessGDBRemote::DoDestroy - got unexpected response "
-                        "to k packet: %s",
-                        response.GetStringRef().c_str());
+          LLDB_LOGF(log,
+                    "ProcessGDBRemote::DoDestroy - got unexpected response "
+                    "to k packet: %s",
+                    response.GetStringRef().c_str());
           exit_string.assign("got unexpected response to k packet: ");
           exit_string.append(response.GetStringRef());
         }
       } else {
-        if (log)
-          log->Printf("ProcessGDBRemote::DoDestroy - failed to send k packet");
+        LLDB_LOGF(log, "ProcessGDBRemote::DoDestroy - failed to send k packet");
         exit_string.assign("failed to send the k packet");
       }
     } else {
-      if (log)
-        log->Printf("ProcessGDBRemote::DoDestroy - killed or interrupted while "
-                    "attaching");
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::DoDestroy - killed or interrupted while "
+                "attaching");
       exit_string.assign("killed or interrupted while attaching.");
     }
   } else {
@@ -2715,8 +2702,7 @@
       response.GetStringRef().find(";reason:exec;") != std::string::npos;
   if (did_exec) {
     Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-    if (log)
-      log->Printf("ProcessGDBRemote::SetLastStopPacket () - detected exec");
+    LLDB_LOGF(log, "ProcessGDBRemote::SetLastStopPacket () - detected exec");
 
     m_thread_list_real.Clear();
     m_thread_list.Clear();
@@ -3078,11 +3064,11 @@
       m_addr_to_mmap_size[allocated_addr] = size;
     else {
       allocated_addr = LLDB_INVALID_ADDRESS;
-      if (log)
-        log->Printf("ProcessGDBRemote::%s no direct stub support for memory "
-                    "allocation, and InferiorCallMmap also failed - is stub "
-                    "missing register context save/restore capability?",
-                    __FUNCTION__);
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s no direct stub support for memory "
+                "allocation, and InferiorCallMmap also failed - is stub "
+                "missing register context save/restore capability?",
+                __FUNCTION__);
     }
   }
 
@@ -3173,17 +3159,17 @@
   const addr_t addr = bp_site->GetLoadAddress();
 
   // Log that a breakpoint was requested
-  if (log)
-    log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64
-                ") address = 0x%" PRIx64,
-                site_id, (uint64_t)addr);
+  LLDB_LOGF(log,
+            "ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64
+            ") address = 0x%" PRIx64,
+            site_id, (uint64_t)addr);
 
   // Breakpoint already exists and is enabled
   if (bp_site->IsEnabled()) {
-    if (log)
-      log->Printf("ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64
-                  ") address = 0x%" PRIx64 " -- SUCCESS (already enabled)",
-                  site_id, (uint64_t)addr);
+    LLDB_LOGF(log,
+              "ProcessGDBRemote::EnableBreakpointSite (size_id = %" PRIu64
+              ") address = 0x%" PRIx64 " -- SUCCESS (already enabled)",
+              site_id, (uint64_t)addr);
     return error;
   }
 
@@ -3231,8 +3217,7 @@
     // We reach here when software breakpoints have been found to be
     // unsupported. For future calls to set a breakpoint, we will not attempt
     // to set a breakpoint with a type that is known not to be supported.
-    if (log)
-      log->Printf("Software breakpoints are unsupported");
+    LLDB_LOGF(log, "Software breakpoints are unsupported");
 
     // So we will fall through and try a hardware breakpoint
   }
@@ -3270,8 +3255,7 @@
 
     // We will reach here when the stub gives an unsupported response to a
     // hardware breakpoint
-    if (log)
-      log->Printf("Hardware breakpoints are unsupported");
+    LLDB_LOGF(log, "Hardware breakpoints are unsupported");
 
     // Finally we will falling through to a #trap style breakpoint
   }
@@ -3293,10 +3277,10 @@
   addr_t addr = bp_site->GetLoadAddress();
   user_id_t site_id = bp_site->GetID();
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_BREAKPOINTS));
-  if (log)
-    log->Printf("ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64
-                ") addr = 0x%8.8" PRIx64,
-                site_id, (uint64_t)addr);
+  LLDB_LOGF(log,
+            "ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64
+            ") addr = 0x%8.8" PRIx64,
+            site_id, (uint64_t)addr);
 
   if (bp_site->IsEnabled()) {
     const size_t bp_op_size = GetSoftwareBreakpointTrapOpcode(bp_site);
@@ -3328,10 +3312,10 @@
     if (error.Success())
       bp_site->SetEnabled(false);
   } else {
-    if (log)
-      log->Printf("ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64
-                  ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
-                  site_id, (uint64_t)addr);
+    LLDB_LOGF(log,
+              "ProcessGDBRemote::DisableBreakpointSite (site_id = %" PRIu64
+              ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
+              site_id, (uint64_t)addr);
     return error;
   }
 
@@ -3363,14 +3347,13 @@
     addr_t addr = wp->GetLoadAddress();
     Log *log(
         ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_WATCHPOINTS));
-    if (log)
-      log->Printf("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ")",
-                  watchID);
+    LLDB_LOGF(log, "ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64 ")",
+              watchID);
     if (wp->IsEnabled()) {
-      if (log)
-        log->Printf("ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64
-                    ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.",
-                    watchID, (uint64_t)addr);
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::EnableWatchpoint(watchID = %" PRIu64
+                ") addr = 0x%8.8" PRIx64 ": watchpoint already enabled.",
+                watchID, (uint64_t)addr);
       return error;
     }
 
@@ -3403,16 +3386,16 @@
 
     addr_t addr = wp->GetLoadAddress();
 
-    if (log)
-      log->Printf("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
-                  ") addr = 0x%8.8" PRIx64,
-                  watchID, (uint64_t)addr);
+    LLDB_LOGF(log,
+              "ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
+              ") addr = 0x%8.8" PRIx64,
+              watchID, (uint64_t)addr);
 
     if (!wp->IsEnabled()) {
-      if (log)
-        log->Printf("ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
-                    ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
-                    watchID, (uint64_t)addr);
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::DisableWatchpoint (watchID = %" PRIu64
+                ") addr = 0x%8.8" PRIx64 " -- SUCCESS (already disabled)",
+                watchID, (uint64_t)addr);
       // See also 'class WatchpointSentry' within StopInfo.cpp. This disabling
       // attempt might come from the user-supplied actions, we'll route it in
       // order for the watchpoint object to intelligently process this action.
@@ -3447,8 +3430,7 @@
 Status ProcessGDBRemote::DoSignal(int signo) {
   Status error;
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-  if (log)
-    log->Printf("ProcessGDBRemote::DoSignal (signal = %d)", signo);
+  LLDB_LOGF(log, "ProcessGDBRemote::DoSignal (signal = %d)", signo);
 
   if (!m_gdb_comm.SendAsyncSignal(signo))
     error.SetErrorStringWithFormat("failed to send signal %i", signo);
@@ -3586,9 +3568,8 @@
     if (error.Fail()) {
       Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
 
-      if (log)
-        log->Printf("failed to start debugserver process: %s",
-                    error.AsCString());
+      LLDB_LOGF(log, "failed to start debugserver process: %s",
+                error.AsCString());
       return error;
     }
 
@@ -3614,15 +3595,14 @@
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
   const bool handled = true;
 
-  if (log)
-    log->Printf("ProcessGDBRemote::%s(process_wp, pid=%" PRIu64
-                ", signo=%i (0x%x), exit_status=%i)",
-                __FUNCTION__, debugserver_pid, signo, signo, exit_status);
+  LLDB_LOGF(log,
+            "ProcessGDBRemote::%s(process_wp, pid=%" PRIu64
+            ", signo=%i (0x%x), exit_status=%i)",
+            __FUNCTION__, debugserver_pid, signo, signo, exit_status);
 
   std::shared_ptr<ProcessGDBRemote> process_sp = process_wp.lock();
-  if (log)
-    log->Printf("ProcessGDBRemote::%s(process = %p)", __FUNCTION__,
-                static_cast<void *>(process_sp.get()));
+  LLDB_LOGF(log, "ProcessGDBRemote::%s(process = %p)", __FUNCTION__,
+            static_cast<void *>(process_sp.get()));
   if (!process_sp || process_sp->m_debugserver_pid != debugserver_pid)
     return handled;
 
@@ -3692,8 +3672,7 @@
 bool ProcessGDBRemote::StartAsyncThread() {
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
 
-  if (log)
-    log->Printf("ProcessGDBRemote::%s ()", __FUNCTION__);
+  LLDB_LOGF(log, "ProcessGDBRemote::%s ()", __FUNCTION__);
 
   std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex);
   if (!m_async_thread.IsJoinable()) {
@@ -3709,10 +3688,11 @@
       return false;
     }
     m_async_thread = *async_thread;
-  } else if (log)
-    log->Printf("ProcessGDBRemote::%s () - Called when Async thread was "
-                "already running.",
-                __FUNCTION__);
+  } else
+    LLDB_LOGF(log,
+              "ProcessGDBRemote::%s () - Called when Async thread was "
+              "already running.",
+              __FUNCTION__);
 
   return m_async_thread.IsJoinable();
 }
@@ -3720,8 +3700,7 @@
 void ProcessGDBRemote::StopAsyncThread() {
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
 
-  if (log)
-    log->Printf("ProcessGDBRemote::%s ()", __FUNCTION__);
+  LLDB_LOGF(log, "ProcessGDBRemote::%s ()", __FUNCTION__);
 
   std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex);
   if (m_async_thread.IsJoinable()) {
@@ -3733,8 +3712,9 @@
     // Stop the stdio thread
     m_async_thread.Join(nullptr);
     m_async_thread.Reset();
-  } else if (log)
-    log->Printf(
+  } else
+    LLDB_LOGF(
+        log,
         "ProcessGDBRemote::%s () - Called when Async thread was not running.",
         __FUNCTION__);
 }
@@ -3768,25 +3748,25 @@
   ProcessGDBRemote *process = (ProcessGDBRemote *)arg;
 
   Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-  if (log)
-    log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                ") thread starting...",
-                __FUNCTION__, arg, process->GetID());
+  LLDB_LOGF(log,
+            "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+            ") thread starting...",
+            __FUNCTION__, arg, process->GetID());
 
   EventSP event_sp;
   bool done = false;
   while (!done) {
-    if (log)
-      log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                  ") listener.WaitForEvent (NULL, event_sp)...",
-                  __FUNCTION__, arg, process->GetID());
+    LLDB_LOGF(log,
+              "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+              ") listener.WaitForEvent (NULL, event_sp)...",
+              __FUNCTION__, arg, process->GetID());
     if (process->m_async_listener_sp->GetEvent(event_sp, llvm::None)) {
       const uint32_t event_type = event_sp->GetType();
       if (event_sp->BroadcasterIs(&process->m_async_broadcaster)) {
-        if (log)
-          log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                      ") Got an event of type: %d...",
-                      __FUNCTION__, arg, process->GetID(), event_type);
+        LLDB_LOGF(log,
+                  "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+                  ") Got an event of type: %d...",
+                  __FUNCTION__, arg, process->GetID(), event_type);
 
         switch (event_type) {
         case eBroadcastBitAsyncContinue: {
@@ -3797,10 +3777,10 @@
             const char *continue_cstr =
                 (const char *)continue_packet->GetBytes();
             const size_t continue_cstr_len = continue_packet->GetByteSize();
-            if (log)
-              log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                          ") got eBroadcastBitAsyncContinue: %s",
-                          __FUNCTION__, arg, process->GetID(), continue_cstr);
+            LLDB_LOGF(log,
+                      "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+                      ") got eBroadcastBitAsyncContinue: %s",
+                      __FUNCTION__, arg, process->GetID(), continue_cstr);
 
             if (::strstr(continue_cstr, "vAttach") == nullptr)
               process->SetPrivateState(eStateRunning);
@@ -3891,18 +3871,18 @@
         break;
 
         case eBroadcastBitAsyncThreadShouldExit:
-          if (log)
-            log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                        ") got eBroadcastBitAsyncThreadShouldExit...",
-                        __FUNCTION__, arg, process->GetID());
+          LLDB_LOGF(log,
+                    "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+                    ") got eBroadcastBitAsyncThreadShouldExit...",
+                    __FUNCTION__, arg, process->GetID());
           done = true;
           break;
 
         default:
-          if (log)
-            log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                        ") got unknown event 0x%8.8x",
-                        __FUNCTION__, arg, process->GetID(), event_type);
+          LLDB_LOGF(log,
+                    "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+                    ") got unknown event 0x%8.8x",
+                    __FUNCTION__, arg, process->GetID(), event_type);
           done = true;
           break;
         }
@@ -3925,27 +3905,27 @@
         }
 
         default:
-          if (log)
-            log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                        ") got unknown event 0x%8.8x",
-                        __FUNCTION__, arg, process->GetID(), event_type);
+          LLDB_LOGF(log,
+                    "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+                    ") got unknown event 0x%8.8x",
+                    __FUNCTION__, arg, process->GetID(), event_type);
           done = true;
           break;
         }
       }
     } else {
-      if (log)
-        log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                    ") listener.WaitForEvent (NULL, event_sp) => false",
-                    __FUNCTION__, arg, process->GetID());
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+                ") listener.WaitForEvent (NULL, event_sp) => false",
+                __FUNCTION__, arg, process->GetID());
       done = true;
     }
   }
 
-  if (log)
-    log->Printf("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
-                ") thread exiting...",
-                __FUNCTION__, arg, process->GetID());
+  LLDB_LOGF(log,
+            "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64
+            ") thread exiting...",
+            __FUNCTION__, arg, process->GetID());
 
   return {};
 }
@@ -3977,8 +3957,7 @@
   // thread when it starts to
   // run so I can stop it if that's what I want to do.
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
-  if (log)
-    log->Printf("Hit New Thread Notification breakpoint.");
+  LLDB_LOGF(log, "Hit New Thread Notification breakpoint.");
   return false;
 }
 
@@ -4023,7 +4002,7 @@
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
   if (m_thread_create_bp_sp) {
     if (log && log->GetVerbose())
-      log->Printf("Enabled noticing new thread breakpoint.");
+      LLDB_LOGF(log, "Enabled noticing new thread breakpoint.");
     m_thread_create_bp_sp->SetEnabled(true);
   } else {
     PlatformSP platform_sp(GetTarget().GetPlatform());
@@ -4032,14 +4011,13 @@
           platform_sp->SetThreadCreationBreakpoint(GetTarget());
       if (m_thread_create_bp_sp) {
         if (log && log->GetVerbose())
-          log->Printf(
-              "Successfully created new thread notification breakpoint %i",
+          LLDB_LOGF(
+              log, "Successfully created new thread notification breakpoint %i",
               m_thread_create_bp_sp->GetID());
         m_thread_create_bp_sp->SetCallback(
             ProcessGDBRemote::NewThreadNotifyBreakpointHit, this, true);
       } else {
-        if (log)
-          log->Printf("Failed to create new thread notification breakpoint.");
+        LLDB_LOGF(log, "Failed to create new thread notification breakpoint.");
       }
     }
   }
@@ -4049,7 +4027,7 @@
 bool ProcessGDBRemote::StopNoticingNewThreads() {
   Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
   if (log && log->GetVerbose())
-    log->Printf("Disabling new thread notification breakpoint.");
+    LLDB_LOGF(log, "Disabling new thread notification breakpoint.");
 
   if (m_thread_create_bp_sp)
     m_thread_create_bp_sp->SetEnabled(false);
@@ -4325,19 +4303,18 @@
   }
 
   if (!m_gdb_comm.GetModuleInfo(module_file_spec, arch, module_spec)) {
-    if (log)
-      log->Printf("ProcessGDBRemote::%s - failed to get module info for %s:%s",
-                  __FUNCTION__, module_file_spec.GetPath().c_str(),
-                  arch.GetTriple().getTriple().c_str());
+    LLDB_LOGF(log, "ProcessGDBRemote::%s - failed to get module info for %s:%s",
+              __FUNCTION__, module_file_spec.GetPath().c_str(),
+              arch.GetTriple().getTriple().c_str());
     return false;
   }
 
   if (log) {
     StreamString stream;
     module_spec.Dump(stream);
-    log->Printf("ProcessGDBRemote::%s - got module info for (%s:%s) : %s",
-                __FUNCTION__, module_file_spec.GetPath().c_str(),
-                arch.GetTriple().getTriple().c_str(), stream.GetData());
+    LLDB_LOGF(log, "ProcessGDBRemote::%s - got module info for (%s:%s) : %s",
+              __FUNCTION__, module_file_spec.GetPath().c_str(),
+              arch.GetTriple().getTriple().c_str(), stream.GetData());
   }
 
   m_cached_module_specs[key] = module_spec;
@@ -4711,8 +4688,7 @@
     return Status(0, ErrorType::eErrorTypeGeneric);
 
   Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS);
-  if (log)
-    log->Printf("ProcessGDBRemote::%s", __FUNCTION__);
+  LLDB_LOGF(log, "ProcessGDBRemote::%s", __FUNCTION__);
 
   GDBRemoteCommunicationClient &comm = m_gdb_comm;
   bool can_use_svr4 = GetGlobalPluginProperties()->GetUseSVR4();
@@ -4730,8 +4706,7 @@
       return Status(0, ErrorType::eErrorTypeGeneric);
 
     // parse the xml file in memory
-    if (log)
-      log->Printf("parsing: %s", raw.c_str());
+    LLDB_LOGF(log, "parsing: %s", raw.c_str());
     XMLDocument doc;
 
     if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml"))
@@ -4791,10 +4766,11 @@
             module.get_base_is_offset(base_is_offset);
             module.get_dynamic(ld);
 
-            log->Printf("found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64
-                        "[%s], ld:0x%08" PRIx64 ", name:'%s')",
-                        lm, base, (base_is_offset ? "offset" : "absolute"), ld,
-                        name.c_str());
+            LLDB_LOGF(log,
+                      "found (link_map:0x%08" PRIx64 ", base:0x%08" PRIx64
+                      "[%s], ld:0x%08" PRIx64 ", name:'%s')",
+                      lm, base, (base_is_offset ? "offset" : "absolute"), ld,
+                      name.c_str());
           }
 
           list.add(module);
@@ -4802,9 +4778,8 @@
                        // node
         });
 
-    if (log)
-      log->Printf("found %" PRId32 " modules in total",
-                  (int)list.m_list.size());
+    LLDB_LOGF(log, "found %" PRId32 " modules in total",
+              (int)list.m_list.size());
   } else if (comm.GetQXferLibrariesReadSupported()) {
     list.clear();
 
@@ -4816,8 +4791,7 @@
                              lldberr))
       return Status(0, ErrorType::eErrorTypeGeneric);
 
-    if (log)
-      log->Printf("parsing: %s", raw.c_str());
+    LLDB_LOGF(log, "parsing: %s", raw.c_str());
     XMLDocument doc;
 
     if (!doc.ParseMemory(raw.c_str(), raw.size(), "noname.xml"))
@@ -4853,8 +4827,8 @@
             module.get_base(base);
             module.get_base_is_offset(base_is_offset);
 
-            log->Printf("found (base:0x%08" PRIx64 "[%s], name:'%s')", base,
-                        (base_is_offset ? "offset" : "absolute"), name.c_str());
+            LLDB_LOGF(log, "found (base:0x%08" PRIx64 "[%s], name:'%s')", base,
+                      (base_is_offset ? "offset" : "absolute"), name.c_str());
           }
 
           list.add(module);
@@ -4862,9 +4836,8 @@
                        // node
         });
 
-    if (log)
-      log->Printf("found %" PRId32 " modules in total",
-                  (int)list.m_list.size());
+    LLDB_LOGF(log, "found %" PRId32 " modules in total",
+              (int)list.m_list.size());
   } else {
     return Status(0, ErrorType::eErrorTypeGeneric);
   }
@@ -5149,7 +5122,8 @@
 
   if (!packet.consume_front(s_async_json_packet_prefix)) {
     if (log) {
-      log->Printf(
+      LLDB_LOGF(
+          log,
           "GDBRemoteCommunicationClientBase::%s() received $J packet "
           "but was not a StructuredData packet: packet starts with "
           "%s",
@@ -5166,14 +5140,16 @@
       StreamString json_str;
       json_sp->Dump(json_str);
       json_str.Flush();
-      log->Printf("ProcessGDBRemote::%s() "
-                  "received Async StructuredData packet: %s",
-                  __FUNCTION__, json_str.GetData());
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s() "
+                "received Async StructuredData packet: %s",
+                __FUNCTION__, json_str.GetData());
     } else {
-      log->Printf("ProcessGDBRemote::%s"
-                  "() received StructuredData packet:"
-                  " parse failure",
-                  __FUNCTION__);
+      LLDB_LOGF(log,
+                "ProcessGDBRemote::%s"
+                "() received StructuredData packet:"
+                " parse failure",
+                __FUNCTION__);
     }
   }
   return json_sp;