This revision was automatically updated to reflect the committed changes.
Closed by commit rL308282: Remove shared pointer from NativeProcessProtocol 
(authored by labath).

Changed prior to commit:
  https://reviews.llvm.org/D35123?vs=105637&id=107034#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35123

Files:
  lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
  lldb/trunk/include/lldb/Host/common/NativeThreadProtocol.h
  lldb/trunk/include/lldb/lldb-private-forward.h
  lldb/trunk/source/Host/common/NativeRegisterContext.cpp
  lldb/trunk/source/Host/common/NativeThreadProtocol.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
  lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h
  lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
  lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
  lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
  lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
  lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
  
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
  lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp

Index: lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp
===================================================================
--- lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp
+++ lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp
@@ -67,13 +67,13 @@
 // Dummy implementation to make sure the code compiles
 class NativeProcessFactory : public NativeProcessProtocol::Factory {
 public:
-  llvm::Expected<NativeProcessProtocolSP>
+  llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
   Launch(ProcessLaunchInfo &launch_info,
          NativeProcessProtocol::NativeDelegate &delegate,
          MainLoop &mainloop) const override {
     llvm_unreachable("Not implemented");
   }
-  llvm::Expected<NativeProcessProtocolSP>
+  llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
   Attach(lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &delegate,
          MainLoop &mainloop) const override {
     llvm_unreachable("Not implemented");
Index: lldb/trunk/source/Host/common/NativeRegisterContext.cpp
===================================================================
--- lldb/trunk/source/Host/common/NativeRegisterContext.cpp
+++ lldb/trunk/source/Host/common/NativeRegisterContext.cpp
@@ -345,17 +345,12 @@
     return error;
   }
 
-  NativeProcessProtocolSP process_sp(m_thread.GetProcess());
-  if (!process_sp) {
-    error.SetErrorString("invalid process");
-    return error;
-  }
-
+  NativeProcessProtocol &process = m_thread.GetProcess();
   uint8_t src[RegisterValue::kMaxRegisterByteSize];
 
   // Read the memory
   size_t bytes_read;
-  error = process_sp->ReadMemory(src_addr, src, src_len, bytes_read);
+  error = process.ReadMemory(src_addr, src, src_len, bytes_read);
   if (error.Fail())
     return error;
 
@@ -374,7 +369,7 @@
   // order of the memory data doesn't match the process. For now we are assuming
   // they are the same.
   lldb::ByteOrder byte_order;
-  if (!process_sp->GetByteOrder(byte_order)) {
+  if (process.GetByteOrder(byte_order)) {
     error.SetErrorString("NativeProcessProtocol::GetByteOrder () failed");
     return error;
   }
@@ -392,41 +387,37 @@
 
   Status error;
 
-  NativeProcessProtocolSP process_sp(m_thread.GetProcess());
-  if (process_sp) {
+  NativeProcessProtocol &process = m_thread.GetProcess();
 
-    // TODO: we might need to add a parameter to this function in case the byte
-    // order of the memory data doesn't match the process. For now we are
-    // assuming
-    // they are the same.
-    lldb::ByteOrder byte_order;
-    if (!process_sp->GetByteOrder(byte_order))
-      return Status("NativeProcessProtocol::GetByteOrder () failed");
+  // TODO: we might need to add a parameter to this function in case the byte
+  // order of the memory data doesn't match the process. For now we are
+  // assuming
+  // they are the same.
+  lldb::ByteOrder byte_order;
+  if (!process.GetByteOrder(byte_order))
+    return Status("NativeProcessProtocol::GetByteOrder () failed");
 
-    const size_t bytes_copied =
-        reg_value.GetAsMemoryData(reg_info, dst, dst_len, byte_order, error);
+  const size_t bytes_copied =
+      reg_value.GetAsMemoryData(reg_info, dst, dst_len, byte_order, error);
 
-    if (error.Success()) {
-      if (bytes_copied == 0) {
-        error.SetErrorString("byte copy failed.");
-      } else {
-        size_t bytes_written;
-        error =
-            process_sp->WriteMemory(dst_addr, dst, bytes_copied, bytes_written);
-        if (error.Fail())
-          return error;
-
-        if (bytes_written != bytes_copied) {
-          // This might happen if we read _some_ bytes but not all
-          error.SetErrorStringWithFormat("only wrote %" PRIu64 " of %" PRIu64
-                                         " bytes",
-                                         static_cast<uint64_t>(bytes_written),
-                                         static_cast<uint64_t>(bytes_copied));
-        }
+  if (error.Success()) {
+    if (bytes_copied == 0) {
+      error.SetErrorString("byte copy failed.");
+    } else {
+      size_t bytes_written;
+      error = process.WriteMemory(dst_addr, dst, bytes_copied, bytes_written);
+      if (error.Fail())
+        return error;
+
+      if (bytes_written != bytes_copied) {
+        // This might happen if we read _some_ bytes but not all
+        error.SetErrorStringWithFormat("only wrote %" PRIu64 " of %" PRIu64
+                                       " bytes",
+                                       static_cast<uint64_t>(bytes_written),
+                                       static_cast<uint64_t>(bytes_copied));
       }
     }
-  } else
-    error.SetErrorString("invalid process");
+  }
 
   return error;
 }
Index: lldb/trunk/source/Host/common/NativeThreadProtocol.cpp
===================================================================
--- lldb/trunk/source/Host/common/NativeThreadProtocol.cpp
+++ lldb/trunk/source/Host/common/NativeThreadProtocol.cpp
@@ -16,9 +16,9 @@
 using namespace lldb;
 using namespace lldb_private;
 
-NativeThreadProtocol::NativeThreadProtocol(NativeProcessProtocol *process,
+NativeThreadProtocol::NativeThreadProtocol(NativeProcessProtocol &process,
                                            lldb::tid_t tid)
-    : m_process_wp(process->shared_from_this()), m_tid(tid) {}
+    : m_process(process), m_tid(tid) {}
 
 Status NativeThreadProtocol::ReadRegister(uint32_t reg,
                                           RegisterValue &reg_value) {
@@ -62,7 +62,3 @@
     return Status("no register context");
   return register_context_sp->ReadAllRegisterValues(data_sp);
 }
-
-NativeProcessProtocolSP NativeThreadProtocol::GetProcess() {
-  return m_process_wp.lock();
-}
Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
===================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
@@ -114,7 +114,7 @@
   lldb::tid_t m_current_tid = LLDB_INVALID_THREAD_ID;
   lldb::tid_t m_continue_tid = LLDB_INVALID_THREAD_ID;
   std::recursive_mutex m_debugged_process_mutex;
-  NativeProcessProtocolSP m_debugged_process_sp;
+  std::unique_ptr<NativeProcessProtocol> m_debugged_process_up;
 
   Communication m_stdio_communication;
   MainLoop::ReadHandleUP m_stdio_handle_up;
Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -239,7 +239,7 @@
 
   {
     std::lock_guard<std::recursive_mutex> guard(m_debugged_process_mutex);
-    assert(!m_debugged_process_sp && "lldb-server creating debugged "
+    assert(!m_debugged_process_up && "lldb-server creating debugged "
                                      "process but one already exists");
     auto process_or =
         m_process_factory.Launch(m_process_launch_info, *this, m_mainloop);
@@ -250,7 +250,7 @@
           m_process_launch_info.GetArguments().GetArgumentAtIndex(0), status);
       return status;
     }
-    m_debugged_process_sp = *process_or;
+    m_debugged_process_up = std::move(*process_or);
   }
 
   // Handle mirroring of inferior stdout/stderr over the gdb-remote protocol
@@ -263,14 +263,13 @@
     // nullptr means it's not redirected to file or pty (in case of LLGS local)
     // at least one of stdio will be transferred pty<->gdb-remote
     // we need to give the pty master handle to this object to read and/or write
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-          " setting up stdout/stderr redirection via $O gdb-remote commands",
-          __FUNCTION__, m_debugged_process_sp->GetID());
+    LLDB_LOG(log,
+             "pid = {0}: setting up stdout/stderr redirection via $O "
+             "gdb-remote commands",
+             m_debugged_process_up->GetID());
 
     // Setup stdout/stderr mapping from inferior to $O
-    auto terminal_fd = m_debugged_process_sp->GetTerminalFileDescriptor();
+    auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor();
     if (terminal_fd >= 0) {
       if (log)
         log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s setting "
@@ -286,16 +285,15 @@
                     __FUNCTION__, terminal_fd);
     }
   } else {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " skipping stdout/stderr redirection via $O: inferior will "
-                  "communicate over client-provided file descriptors",
-                  __FUNCTION__, m_debugged_process_sp->GetID());
+    LLDB_LOG(log,
+             "pid = {0} skipping stdout/stderr redirection via $O: inferior "
+             "will communicate over client-provided file descriptors",
+             m_debugged_process_up->GetID());
   }
 
   printf("Launched '%s' as process %" PRIu64 "...\n",
          m_process_launch_info.GetArguments().GetArgumentAtIndex(0),
-         m_debugged_process_sp->GetID());
+         m_debugged_process_up->GetID());
 
   return Status();
 }
@@ -308,12 +306,12 @@
 
   // Before we try to attach, make sure we aren't already monitoring something
   // else.
-  if (m_debugged_process_sp &&
-      m_debugged_process_sp->GetID() != LLDB_INVALID_PROCESS_ID)
+  if (m_debugged_process_up &&
+      m_debugged_process_up->GetID() != LLDB_INVALID_PROCESS_ID)
     return Status("cannot attach to a process %" PRIu64
                   " when another process with pid %" PRIu64
                   " is being debugged.",
-                  pid, m_debugged_process_sp->GetID());
+                  pid, m_debugged_process_up->GetID());
 
   // Try to attach.
   auto process_or = m_process_factory.Attach(pid, *this, m_mainloop);
@@ -323,10 +321,10 @@
                                   status);
     return status;
   }
-  m_debugged_process_sp = *process_or;
+  m_debugged_process_up = std::move(*process_or);
 
   // Setup stdout/stderr mapping from inferior.
-  auto terminal_fd = m_debugged_process_sp->GetTerminalFileDescriptor();
+  auto terminal_fd = m_debugged_process_up->GetTerminalFileDescriptor();
   if (terminal_fd >= 0) {
     if (log)
       log->Printf("ProcessGDBRemoteCommunicationServerLLGS::%s setting "
@@ -597,18 +595,15 @@
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
 
   // Ensure we have a debugged process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(50);
 
-  if (log)
-    log->Printf(
-        "GDBRemoteCommunicationServerLLGS::%s preparing packet for pid %" PRIu64
-        " tid %" PRIu64,
-        __FUNCTION__, m_debugged_process_sp->GetID(), tid);
+  LLDB_LOG(log, "preparing packet for pid {0} tid {1}",
+           m_debugged_process_up->GetID(), tid);
 
   // Ensure we can get info on the given thread.
-  NativeThreadProtocolSP thread_sp(m_debugged_process_sp->GetThreadByID(tid));
+  NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadByID(tid));
   if (!thread_sp)
     return SendErrorResponse(51);
 
@@ -629,13 +624,11 @@
   // Output the T packet with the thread
   response.PutChar('T');
   int signum = tid_stop_info.details.signal.signo;
-  if (log) {
-    log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                " tid %" PRIu64
-                " got signal signo = %d, reason = %d, exc_type = %" PRIu64,
-                __FUNCTION__, m_debugged_process_sp->GetID(), tid, signum,
-                tid_stop_info.reason, tid_stop_info.details.exception.type);
-  }
+  LLDB_LOG(
+      log,
+      "pid {0}, tid {1}, got signal signo = {2}, reason = {3}, exc_type = {4}",
+      m_debugged_process_up->GetID(), tid, signum, int(tid_stop_info.reason),
+      tid_stop_info.details.exception.type);
 
   // Print the signal number.
   response.PutHex8(signum & 0xff);
@@ -673,9 +666,9 @@
     uint32_t thread_index = 0;
     NativeThreadProtocolSP listed_thread_sp;
     for (listed_thread_sp =
-             m_debugged_process_sp->GetThreadAtIndex(thread_index);
+             m_debugged_process_up->GetThreadAtIndex(thread_index);
          listed_thread_sp; ++thread_index,
-        listed_thread_sp = m_debugged_process_sp->GetThreadAtIndex(
+        listed_thread_sp = m_debugged_process_up->GetThreadAtIndex(
             thread_index)) {
       if (thread_index > 0)
         response.PutChar(',');
@@ -692,24 +685,23 @@
     if (thread_index > 0) {
       const bool threads_with_valid_stop_info_only = true;
       JSONArray::SP threads_info_sp = GetJSONThreadsInfo(
-          *m_debugged_process_sp, threads_with_valid_stop_info_only);
+          *m_debugged_process_up, threads_with_valid_stop_info_only);
       if (threads_info_sp) {
         response.PutCString("jstopinfo:");
         StreamString unescaped_response;
         threads_info_sp->Write(unescaped_response);
         response.PutCStringAsRawHex8(unescaped_response.GetData());
         response.PutChar(';');
-      } else if (log)
-        log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to prepare a "
-                    "jstopinfo field for pid %" PRIu64,
-                    __FUNCTION__, m_debugged_process_sp->GetID());
+      } else
+        LLDB_LOG(log, "failed to prepare a jstopinfo field for pid {0}",
+                 m_debugged_process_up->GetID());
     }
 
     uint32_t i = 0;
     response.PutCString("thread-pcs");
     char delimiter = ':';
     for (NativeThreadProtocolSP thread_sp;
-         (thread_sp = m_debugged_process_sp->GetThreadAtIndex(i)) != nullptr;
+         (thread_sp = m_debugged_process_up->GetThreadAtIndex(i)) != nullptr;
          ++i) {
       NativeRegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
       if (!reg_ctx_sp)
@@ -1069,8 +1061,8 @@
     StringExtractorGDBRemote &packet) {
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(68);
 
   if (!packet.ConsumeFront("jTraceStart:"))
@@ -1120,7 +1112,7 @@
 
   Status error;
   lldb::user_id_t uid = LLDB_INVALID_UID;
-  uid = m_debugged_process_sp->StartTrace(options, error);
+  uid = m_debugged_process_up->StartTrace(options, error);
   LLDB_LOG(log, "uid is {0} , error is {1}", uid, error.GetError());
   if (error.Fail())
     return SendErrorResponse(error);
@@ -1134,8 +1126,8 @@
 GDBRemoteCommunicationServerLLGS::Handle_jTraceStop(
     StringExtractorGDBRemote &packet) {
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(68);
 
   if (!packet.ConsumeFront("jTraceStop:"))
@@ -1157,7 +1149,7 @@
 
   json_dict->GetValueForKeyAsInteger("threadid", tid);
 
-  Status error = m_debugged_process_sp->StopTrace(uid, tid);
+  Status error = m_debugged_process_up->StopTrace(uid, tid);
 
   if (error.Fail())
     return SendErrorResponse(error);
@@ -1170,8 +1162,8 @@
     StringExtractorGDBRemote &packet) {
 
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(68);
 
   if (!packet.ConsumeFront("jTraceConfigRead:"))
@@ -1200,7 +1192,7 @@
   StreamGDBRemote response;
 
   options.setThreadID(threadid);
-  Status error = m_debugged_process_sp->GetTraceConfig(uid, options);
+  Status error = m_debugged_process_up->GetTraceConfig(uid, options);
 
   if (error.Fail())
     return SendErrorResponse(error);
@@ -1228,8 +1220,8 @@
     StringExtractorGDBRemote &packet) {
 
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(68);
 
   enum PacketType { MetaData, BufferData };
@@ -1274,9 +1266,9 @@
   llvm::MutableArrayRef<uint8_t> buf(buffer.get(), byte_count);
 
   if (tracetype == BufferData)
-    error = m_debugged_process_sp->GetData(uid, tid, buf, offset);
+    error = m_debugged_process_up->GetData(uid, tid, buf, offset);
   else if (tracetype == MetaData)
-    error = m_debugged_process_sp->GetMetaData(uid, tid, buf, offset);
+    error = m_debugged_process_up->GetMetaData(uid, tid, buf, offset);
 
   if (error.Fail())
     return SendErrorResponse(error);
@@ -1293,11 +1285,11 @@
 GDBRemoteCommunicationServerLLGS::Handle_qProcessInfo(
     StringExtractorGDBRemote &packet) {
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(68);
 
-  lldb::pid_t pid = m_debugged_process_sp->GetID();
+  lldb::pid_t pid = m_debugged_process_up->GetID();
 
   if (pid == LLDB_INVALID_PROCESS_ID)
     return SendErrorResponse(1);
@@ -1314,16 +1306,16 @@
 GDBRemoteCommunication::PacketResult
 GDBRemoteCommunicationServerLLGS::Handle_qC(StringExtractorGDBRemote &packet) {
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(68);
 
   // Make sure we set the current thread so g and p packets return
   // the data the gdb will expect.
-  lldb::tid_t tid = m_debugged_process_sp->GetCurrentThreadID();
+  lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
   SetCurrentThreadID(tid);
 
-  NativeThreadProtocolSP thread_sp = m_debugged_process_sp->GetCurrentThread();
+  NativeThreadProtocolSP thread_sp = m_debugged_process_up->GetCurrentThread();
   if (!thread_sp)
     return SendErrorResponse(69);
 
@@ -1339,20 +1331,15 @@
 
   StopSTDIOForwarding();
 
-  if (!m_debugged_process_sp) {
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s No debugged process found.",
-          __FUNCTION__);
+  if (!m_debugged_process_up) {
+    LLDB_LOG(log, "No debugged process found.");
     return PacketResult::Success;
   }
 
-  Status error = m_debugged_process_sp->Kill();
-  if (error.Fail() && log)
-    log->Printf("GDBRemoteCommunicationServerLLGS::%s Failed to kill debugged "
-                "process %" PRIu64 ": %s",
-                __FUNCTION__, m_debugged_process_sp->GetID(),
-                error.AsCString());
+  Status error = m_debugged_process_up->Kill();
+  if (error.Fail())
+    LLDB_LOG(log, "Failed to kill debugged process {0}: {1}",
+             m_debugged_process_up->GetID(), error);
 
   // No OK response for kill packet.
   // return SendOKResponse ();
@@ -1400,7 +1387,7 @@
     log->Printf("GDBRemoteCommunicationServerLLGS::%s called", __FUNCTION__);
 
   // Ensure we have a native process.
-  if (!m_debugged_process_sp) {
+  if (!m_debugged_process_up) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process "
                   "shared pointer",
@@ -1453,26 +1440,20 @@
   } else {
     // Send the signal to the process since we weren't targeting a specific
     // continue thread with the signal.
-    error = m_debugged_process_sp->Signal(signo);
+    error = m_debugged_process_up->Signal(signo);
     if (error.Fail()) {
-      if (log)
-        log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to send "
-                    "signal for process %" PRIu64 ": %s",
-                    __FUNCTION__, m_debugged_process_sp->GetID(),
-                    error.AsCString());
+      LLDB_LOG(log, "failed to send signal for process {0}: {1}",
+               m_debugged_process_up->GetID(), error);
 
       return SendErrorResponse(0x52);
     }
   }
 
   // Resume the threads.
-  error = m_debugged_process_sp->Resume(resume_actions);
+  error = m_debugged_process_up->Resume(resume_actions);
   if (error.Fail()) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to resume "
-                  "threads for process %" PRIu64 ": %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  error.AsCString());
+    LLDB_LOG(log, "failed to resume threads for process {0}: {1}",
+             m_debugged_process_up->GetID(), error);
 
     return SendErrorResponse(0x38);
   }
@@ -1492,15 +1473,13 @@
   // For now just support all continue.
   const bool has_continue_address = (packet.GetBytesLeft() > 0);
   if (has_continue_address) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s not implemented for "
-                  "c{address} variant [%s remains]",
-                  __FUNCTION__, packet.Peek());
+    LLDB_LOG(log, "not implemented for c[address] variant [{0} remains]",
+             packet.Peek());
     return SendUnimplementedResponse(packet.GetStringRef().c_str());
   }
 
   // Ensure we have a native process.
-  if (!m_debugged_process_sp) {
+  if (!m_debugged_process_up) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process "
                   "shared pointer",
@@ -1511,22 +1490,14 @@
   // Build the ResumeActionList
   ResumeActionList actions(StateType::eStateRunning, 0);
 
-  Status error = m_debugged_process_sp->Resume(actions);
+  Status error = m_debugged_process_up->Resume(actions);
   if (error.Fail()) {
-    if (log) {
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s c failed for process %" PRIu64
-          ": %s",
-          __FUNCTION__, m_debugged_process_sp->GetID(), error.AsCString());
-    }
+    LLDB_LOG(log, "c failed for process {0}: {1}",
+             m_debugged_process_up->GetID(), error);
     return SendErrorResponse(GDBRemoteServerError::eErrorResume);
   }
 
-  if (log)
-    log->Printf(
-        "GDBRemoteCommunicationServerLLGS::%s continued process %" PRIu64,
-        __FUNCTION__, m_debugged_process_sp->GetID());
-
+  LLDB_LOG(log, "continued process {0}", m_debugged_process_up->GetID());
   // No response required from continue.
   return PacketResult::Success;
 }
@@ -1570,11 +1541,8 @@
   }
 
   // Ensure we have a native process.
-  if (!m_debugged_process_sp) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s no debugged process "
-                  "shared pointer",
-                  __FUNCTION__);
+  if (!m_debugged_process_up) {
+    LLDB_LOG(log, "no debugged process");
     return SendErrorResponse(0x36);
   }
 
@@ -1635,44 +1603,30 @@
     thread_actions.Append(thread_action);
   }
 
-  Status error = m_debugged_process_sp->Resume(thread_actions);
+  Status error = m_debugged_process_up->Resume(thread_actions);
   if (error.Fail()) {
-    if (log) {
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s vCont failed for "
-                  "process %" PRIu64 ": %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  error.AsCString());
-    }
+    LLDB_LOG(log, "vCont failed for process {0}: {1}",
+             m_debugged_process_up->GetID(), error);
     return SendErrorResponse(GDBRemoteServerError::eErrorResume);
   }
 
-  if (log)
-    log->Printf(
-        "GDBRemoteCommunicationServerLLGS::%s continued process %" PRIu64,
-        __FUNCTION__, m_debugged_process_sp->GetID());
-
+  LLDB_LOG(log, "continued process {0}", m_debugged_process_up->GetID());
   // No response required from vCont.
   return PacketResult::Success;
 }
 
 void GDBRemoteCommunicationServerLLGS::SetCurrentThreadID(lldb::tid_t tid) {
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
-  if (log)
-    log->Printf("GDBRemoteCommunicationServerLLGS::%s setting current thread "
-                "id to %" PRIu64,
-                __FUNCTION__, tid);
+  LLDB_LOG(log, "setting current thread id to {0}", tid);
 
   m_current_tid = tid;
-  if (m_debugged_process_sp)
-    m_debugged_process_sp->SetCurrentThreadID(m_current_tid);
+  if (m_debugged_process_up)
+    m_debugged_process_up->SetCurrentThreadID(m_current_tid);
 }
 
 void GDBRemoteCommunicationServerLLGS::SetContinueThreadID(lldb::tid_t tid) {
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
-  if (log)
-    log->Printf("GDBRemoteCommunicationServerLLGS::%s setting continue thread "
-                "id to %" PRIu64,
-                __FUNCTION__, tid);
+  LLDB_LOG(log, "setting continue thread id to {0}", tid);
 
   m_continue_tid = tid;
 }
@@ -1683,10 +1637,10 @@
   // Handle the $? gdbremote command.
 
   // If no process, indicate error
-  if (!m_debugged_process_sp)
+  if (!m_debugged_process_up)
     return SendErrorResponse(02);
 
-  return SendStopReasonForState(m_debugged_process_sp->GetState());
+  return SendStopReasonForState(m_debugged_process_up->GetState());
 }
 
 GDBRemoteCommunication::PacketResult
@@ -1707,7 +1661,7 @@
   case eStateSuspended:
   case eStateStopped:
   case eStateCrashed: {
-    lldb::tid_t tid = m_debugged_process_sp->GetCurrentThreadID();
+    lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
     // Make sure we set the current thread so g and p packets return
     // the data the gdb will expect.
     SetCurrentThreadID(tid);
@@ -1717,15 +1671,11 @@
   case eStateInvalid:
   case eStateUnloaded:
   case eStateExited:
-    return SendWResponse(m_debugged_process_sp.get());
+    return SendWResponse(m_debugged_process_up.get());
 
   default:
-    if (log) {
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  ", current state reporting not handled: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  StateAsCString(process_state));
-    }
+    LLDB_LOG(log, "pid {0}, current state reporting not handled: {1}",
+             m_debugged_process_up->GetID(), process_state);
     break;
   }
 
@@ -1736,12 +1686,12 @@
 GDBRemoteCommunicationServerLLGS::Handle_qRegisterInfo(
     StringExtractorGDBRemote &packet) {
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(68);
 
   // Ensure we have a thread.
-  NativeThreadProtocolSP thread_sp(m_debugged_process_sp->GetThreadAtIndex(0));
+  NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadAtIndex(0));
   if (!thread_sp)
     return SendErrorResponse(69);
 
@@ -1945,47 +1895,33 @@
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
 
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s() no process (%s), "
-                  "returning OK",
-                  __FUNCTION__,
-                  m_debugged_process_sp ? "invalid process id"
-                                        : "null m_debugged_process_sp");
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
+    LLDB_LOG(log, "no process ({0}), returning OK",
+             m_debugged_process_up ? "invalid process id"
+                                   : "null m_debugged_process_up");
     return SendOKResponse();
   }
 
   StreamGDBRemote response;
   response.PutChar('m');
 
-  if (log)
-    log->Printf(
-        "GDBRemoteCommunicationServerLLGS::%s() starting thread iteration",
-        __FUNCTION__);
-
+  LLDB_LOG(log, "starting thread iteration");
   NativeThreadProtocolSP thread_sp;
   uint32_t thread_index;
   for (thread_index = 0,
-      thread_sp = m_debugged_process_sp->GetThreadAtIndex(thread_index);
+      thread_sp = m_debugged_process_up->GetThreadAtIndex(thread_index);
        thread_sp; ++thread_index,
-      thread_sp = m_debugged_process_sp->GetThreadAtIndex(thread_index)) {
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s() iterated thread %" PRIu32
-          "(%s, tid=0x%" PRIx64 ")",
-          __FUNCTION__, thread_index, thread_sp ? "is not null" : "null",
-          thread_sp ? thread_sp->GetID() : LLDB_INVALID_THREAD_ID);
+      thread_sp = m_debugged_process_up->GetThreadAtIndex(thread_index)) {
+    LLDB_LOG(log, "iterated thread {0}({1}, tid={2})", thread_index,
+             thread_sp ? "is not null" : "null",
+             thread_sp ? thread_sp->GetID() : LLDB_INVALID_THREAD_ID);
     if (thread_index > 0)
       response.PutChar(',');
     response.Printf("%" PRIx64, thread_sp->GetID());
   }
 
-  if (log)
-    log->Printf(
-        "GDBRemoteCommunicationServerLLGS::%s() finished thread iteration",
-        __FUNCTION__);
-
+  LLDB_LOG(log, "finished thread iteration");
   return SendPacketNoLock(response.GetString());
 }
 
@@ -2026,11 +1962,10 @@
   // Get the thread's register context.
   NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
   if (!reg_context_sp) {
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
-          " failed, no register context available for the thread",
-          __FUNCTION__, m_debugged_process_sp->GetID(), thread_sp->GetID());
+    LLDB_LOG(
+        log,
+        "pid {0} tid {1} failed, no register context available for the thread",
+        m_debugged_process_up->GetID(), thread_sp->GetID());
     return SendErrorResponse(0x15);
   }
 
@@ -2113,8 +2048,8 @@
 
   // Get process architecture.
   ArchSpec process_arch;
-  if (!m_debugged_process_sp ||
-      !m_debugged_process_sp->GetArchitecture(process_arch)) {
+  if (!m_debugged_process_up ||
+      !m_debugged_process_up->GetArchitecture(process_arch)) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to retrieve "
                   "inferior architecture",
@@ -2143,7 +2078,7 @@
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
           " failed, no register context available for the thread",
-          __FUNCTION__, m_debugged_process_sp->GetID(), thread_sp->GetID());
+          __FUNCTION__, m_debugged_process_up->GetID(), thread_sp->GetID());
     return SendErrorResponse(0x15);
   }
 
@@ -2197,8 +2132,8 @@
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
 
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     if (log)
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2241,7 +2176,7 @@
   // Ensure we have the given thread when not specifying -1 (all threads) or 0
   // (any thread).
   if (tid != LLDB_INVALID_THREAD_ID && tid != 0) {
-    NativeThreadProtocolSP thread_sp(m_debugged_process_sp->GetThreadByID(tid));
+    NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadByID(tid));
     if (!thread_sp) {
       if (log)
         log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64
@@ -2275,8 +2210,8 @@
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
 
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     if (log)
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2311,30 +2246,21 @@
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
 
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
-          __FUNCTION__);
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
+    LLDB_LOG(log, "failed, no process available");
     return SendErrorResponse(0x15);
   }
 
   // Interrupt the process.
-  Status error = m_debugged_process_sp->Interrupt();
+  Status error = m_debugged_process_up->Interrupt();
   if (error.Fail()) {
-    if (log) {
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s failed for process %" PRIu64
-          ": %s",
-          __FUNCTION__, m_debugged_process_sp->GetID(), error.AsCString());
-    }
+    LLDB_LOG(log, "failed for process {0}: {1}", m_debugged_process_up->GetID(),
+             error);
     return SendErrorResponse(GDBRemoteServerError::eErrorResume);
   }
 
-  if (log)
-    log->Printf("GDBRemoteCommunicationServerLLGS::%s stopped process %" PRIu64,
-                __FUNCTION__, m_debugged_process_sp->GetID());
+  LLDB_LOG(log, "stopped process {0}", m_debugged_process_up->GetID());
 
   // No response required from stop all.
   return PacketResult::Success;
@@ -2345,8 +2271,8 @@
     StringExtractorGDBRemote &packet) {
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     if (log)
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2388,22 +2314,22 @@
 
   // Retrieve the process memory.
   size_t bytes_read = 0;
-  Status error = m_debugged_process_sp->ReadMemoryWithoutTrap(
+  Status error = m_debugged_process_up->ReadMemoryWithoutTrap(
       read_addr, &buf[0], byte_count, bytes_read);
   if (error.Fail()) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
                   " mem 0x%" PRIx64 ": failed to read. Error: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(), read_addr,
+                  __FUNCTION__, m_debugged_process_up->GetID(), read_addr,
                   error.AsCString());
     return SendErrorResponse(0x08);
   }
 
   if (bytes_read == 0) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
                   " mem 0x%" PRIx64 ": read 0 of %" PRIu64 " requested bytes",
-                  __FUNCTION__, m_debugged_process_sp->GetID(), read_addr,
+                  __FUNCTION__, m_debugged_process_up->GetID(), read_addr,
                   byte_count);
     return SendErrorResponse(0x08);
   }
@@ -2426,8 +2352,8 @@
 GDBRemoteCommunicationServerLLGS::Handle_M(StringExtractorGDBRemote &packet) {
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
 
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     if (log)
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2455,10 +2381,7 @@
 
   const uint64_t byte_count = packet.GetHexMaxU64(false, 0);
   if (byte_count == 0) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s nothing to write: "
-                  "zero-length packet",
-                  __FUNCTION__);
+    LLDB_LOG(log, "nothing to write: zero-length packet");
     return PacketResult::Success;
   }
 
@@ -2476,36 +2399,29 @@
   StreamGDBRemote response;
   const uint64_t convert_count = packet.GetHexBytes(buf, 0);
   if (convert_count != byte_count) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " mem 0x%" PRIx64 ": asked to write %" PRIu64
-                  " bytes, but only found %" PRIu64 " to convert.",
-                  __FUNCTION__, m_debugged_process_sp->GetID(), write_addr,
-                  byte_count, convert_count);
+    LLDB_LOG(log,
+             "pid {0} mem {1:x}: asked to write {2} bytes, but only found {3} "
+             "to convert.",
+             m_debugged_process_up->GetID(), write_addr, byte_count,
+             convert_count);
     return SendIllFormedResponse(packet, "M content byte length specified did "
                                          "not match hex-encoded content "
                                          "length");
   }
 
   // Write the process memory.
   size_t bytes_written = 0;
-  Status error = m_debugged_process_sp->WriteMemory(write_addr, &buf[0],
+  Status error = m_debugged_process_up->WriteMemory(write_addr, &buf[0],
                                                     byte_count, bytes_written);
   if (error.Fail()) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " mem 0x%" PRIx64 ": failed to write. Error: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(), write_addr,
-                  error.AsCString());
+    LLDB_LOG(log, "pid {0} mem {1:x}: failed to write. Error: {2}",
+             m_debugged_process_up->GetID(), write_addr, error);
     return SendErrorResponse(0x09);
   }
 
   if (bytes_written == 0) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " mem 0x%" PRIx64 ": wrote 0 of %" PRIu64 " requested bytes",
-                  __FUNCTION__, m_debugged_process_sp->GetID(), write_addr,
-                  byte_count);
+    LLDB_LOG(log, "pid {0} mem {1:x}: wrote 0 of {2} requested bytes",
+             m_debugged_process_up->GetID(), write_addr, byte_count);
     return SendErrorResponse(0x09);
   }
 
@@ -2525,8 +2441,8 @@
 
   // Ensure we have a process running; otherwise, we can't figure this out
   // since we won't have a NativeProcessProtocol.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     if (log)
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2537,7 +2453,7 @@
   // Test if we can get any region back when asking for the region around NULL.
   MemoryRegionInfo region_info;
   const Status error =
-      m_debugged_process_sp->GetMemoryRegionInfo(0, region_info);
+      m_debugged_process_up->GetMemoryRegionInfo(0, region_info);
   if (error.Fail()) {
     // We don't support memory region info collection for this
     // NativeProcessProtocol.
@@ -2553,8 +2469,8 @@
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
 
   // Ensure we have a process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     if (log)
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2575,7 +2491,7 @@
   // Get the memory region info for the target address.
   MemoryRegionInfo region_info;
   const Status error =
-      m_debugged_process_sp->GetMemoryRegionInfo(read_addr, region_info);
+      m_debugged_process_up->GetMemoryRegionInfo(read_addr, region_info);
   if (error.Fail()) {
     // Return the error message.
 
@@ -2619,13 +2535,10 @@
 GDBRemoteCommunication::PacketResult
 GDBRemoteCommunicationServerLLGS::Handle_Z(StringExtractorGDBRemote &packet) {
   // Ensure we have a process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
-          __FUNCTION__);
+    LLDB_LOG(log, "failed, no process available");
     return SendErrorResponse(0x15);
   }
 
@@ -2693,42 +2606,33 @@
   if (want_breakpoint) {
     // Try to set the breakpoint.
     const Status error =
-        m_debugged_process_sp->SetBreakpoint(addr, size, want_hardware);
+        m_debugged_process_up->SetBreakpoint(addr, size, want_hardware);
     if (error.Success())
       return SendOKResponse();
     Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " failed to set breakpoint: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  error.AsCString());
+    LLDB_LOG(log, "pid {0} failed to set breakpoint: {1}",
+             m_debugged_process_up->GetID(), error);
     return SendErrorResponse(0x09);
   } else {
     // Try to set the watchpoint.
-    const Status error = m_debugged_process_sp->SetWatchpoint(
+    const Status error = m_debugged_process_up->SetWatchpoint(
         addr, size, watch_flags, want_hardware);
     if (error.Success())
       return SendOKResponse();
     Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " failed to set watchpoint: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  error.AsCString());
+    LLDB_LOG(log, "pid {0} failed to set watchpoint: {1}",
+             m_debugged_process_up->GetID(), error);
     return SendErrorResponse(0x09);
   }
 }
 
 GDBRemoteCommunication::PacketResult
 GDBRemoteCommunicationServerLLGS::Handle_z(StringExtractorGDBRemote &packet) {
   // Ensure we have a process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS));
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
-          __FUNCTION__);
+    LLDB_LOG(log, "failed, no process available");
     return SendErrorResponse(0x15);
   }
 
@@ -2790,27 +2694,21 @@
   if (want_breakpoint) {
     // Try to clear the breakpoint.
     const Status error =
-        m_debugged_process_sp->RemoveBreakpoint(addr, want_hardware);
+        m_debugged_process_up->RemoveBreakpoint(addr, want_hardware);
     if (error.Success())
       return SendOKResponse();
     Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " failed to remove breakpoint: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  error.AsCString());
+    LLDB_LOG(log, "pid {0} failed to remove breakpoint: {1}",
+             m_debugged_process_up->GetID(), error);
     return SendErrorResponse(0x09);
   } else {
     // Try to clear the watchpoint.
-    const Status error = m_debugged_process_sp->RemoveWatchpoint(addr);
+    const Status error = m_debugged_process_up->RemoveWatchpoint(addr);
     if (error.Success())
       return SendOKResponse();
     Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " failed to remove watchpoint: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  error.AsCString());
+    LLDB_LOG(log, "pid {0} failed to remove watchpoint: {1}",
+             m_debugged_process_up->GetID(), error);
     return SendErrorResponse(0x09);
   }
 }
@@ -2820,8 +2718,8 @@
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
 
   // Ensure we have a process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     if (log)
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -2840,7 +2738,7 @@
 
   // Double check that we have such a thread.
   // TODO investigate: on MacOSX we might need to do an UpdateThreads () here.
-  NativeThreadProtocolSP thread_sp = m_debugged_process_sp->GetThreadByID(tid);
+  NativeThreadProtocolSP thread_sp = m_debugged_process_up->GetThreadByID(tid);
   if (!thread_sp || thread_sp->GetID() != tid)
     return SendErrorResponse(0x33);
 
@@ -2853,12 +2751,12 @@
 
   // All other threads stop while we're single stepping a thread.
   actions.SetDefaultThreadActionIfNeeded(eStateStopped, 0);
-  Status error = m_debugged_process_sp->Resume(actions);
+  Status error = m_debugged_process_up->Resume(actions);
   if (error.Fail()) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
                   " tid %" PRIu64 " Resume() failed with error: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(), tid,
+                  __FUNCTION__, m_debugged_process_up->GetID(), tid,
                   error.AsCString());
     return SendErrorResponse(0x49);
   }
@@ -2901,17 +2799,17 @@
   // Grab the auxv data if we need it.
   if (!m_active_auxv_buffer_up) {
     // Make sure we have a valid process.
-    if (!m_debugged_process_sp ||
-        (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+    if (!m_debugged_process_up ||
+        (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
       if (log)
         log->Printf(
             "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
             __FUNCTION__);
       return SendErrorResponse(0x10);
     }
 
     // Grab the auxv data.
-    auto buffer_or_error = m_debugged_process_sp->GetAuxvData();
+    auto buffer_or_error = m_debugged_process_up->GetAuxvData();
     if (!buffer_or_error) {
       std::error_code ec = buffer_or_error.getError();
       LLDB_LOG(log, "no auxv data retrieved: {0}", ec.message());
@@ -2979,23 +2877,19 @@
   // Grab the register context for the thread.
   NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
   if (!reg_context_sp) {
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
-          " failed, no register context available for the thread",
-          __FUNCTION__, m_debugged_process_sp->GetID(), thread_sp->GetID());
+    LLDB_LOG(
+        log,
+        "pid {0} tid {1} failed, no register context available for the thread",
+        m_debugged_process_up->GetID(), thread_sp->GetID());
     return SendErrorResponse(0x15);
   }
 
   // Save registers to a buffer.
   DataBufferSP register_data_sp;
   Status error = reg_context_sp->ReadAllRegisterValues(register_data_sp);
   if (error.Fail()) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " failed to save all register values: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  error.AsCString());
+    LLDB_LOG(log, "pid {0} failed to save all register values: {1}",
+             m_debugged_process_up->GetID(), error);
     return SendErrorResponse(0x75);
   }
 
@@ -3029,10 +2923,8 @@
 
   const uint32_t save_id = packet.GetU32(0);
   if (save_id == 0) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s QRestoreRegisterState "
-                  "packet has malformed save id, expecting decimal uint32_t",
-                  __FUNCTION__);
+    LLDB_LOG(log, "QRestoreRegisterState packet has malformed save id, "
+                  "expecting decimal uint32_t");
     return SendErrorResponse(0x76);
   }
 
@@ -3050,11 +2942,10 @@
   // Grab the register context for the thread.
   NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
   if (!reg_context_sp) {
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64 " tid %" PRIu64
-          " failed, no register context available for the thread",
-          __FUNCTION__, m_debugged_process_sp->GetID(), thread_sp->GetID());
+    LLDB_LOG(
+        log,
+        "pid {0} tid {1} failed, no register context available for the thread",
+        m_debugged_process_up->GetID(), thread_sp->GetID());
     return SendErrorResponse(0x15);
   }
 
@@ -3066,10 +2957,9 @@
     // Find the register set buffer for the given save id.
     auto it = m_saved_registers_map.find(save_id);
     if (it == m_saved_registers_map.end()) {
-      if (log)
-        log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                    " does not have a register set save buffer for id %" PRIu32,
-                    __FUNCTION__, m_debugged_process_sp->GetID(), save_id);
+      LLDB_LOG(log,
+               "pid {0} does not have a register set save buffer for id {1}",
+               m_debugged_process_up->GetID(), save_id);
       return SendErrorResponse(0x77);
     }
     register_data_sp = it->second;
@@ -3080,11 +2970,8 @@
 
   Status error = reg_context_sp->WriteAllRegisterValues(register_data_sp);
   if (error.Fail()) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s pid %" PRIu64
-                  " failed to restore all register values: %s",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
-                  error.AsCString());
+    LLDB_LOG(log, "pid {0} failed to restore all register values: {1}",
+             m_debugged_process_up->GetID(), error);
     return SendErrorResponse(0x77);
   }
 
@@ -3124,7 +3011,7 @@
   }
 
   // Notify we attached by sending a stop packet.
-  return SendStopReasonForState(m_debugged_process_sp->GetState());
+  return SendStopReasonForState(m_debugged_process_up->GetState());
 }
 
 GDBRemoteCommunication::PacketResult
@@ -3134,8 +3021,8 @@
   StopSTDIOForwarding();
 
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)) {
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)) {
     if (log)
       log->Printf(
           "GDBRemoteCommunicationServerLLGS::%s failed, no process available",
@@ -3157,16 +3044,16 @@
       return SendIllFormedResponse(packet, "D failed to parse the process id");
   }
 
-  if (pid != LLDB_INVALID_PROCESS_ID && m_debugged_process_sp->GetID() != pid) {
+  if (pid != LLDB_INVALID_PROCESS_ID && m_debugged_process_up->GetID() != pid) {
     return SendIllFormedResponse(packet, "Invalid pid");
   }
 
-  const Status error = m_debugged_process_sp->Detach();
+  const Status error = m_debugged_process_up->Detach();
   if (error.Fail()) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to detach from "
                   "pid %" PRIu64 ": %s\n",
-                  __FUNCTION__, m_debugged_process_sp->GetID(),
+                  __FUNCTION__, m_debugged_process_up->GetID(),
                   error.AsCString());
     return SendErrorResponse(0x01);
   }
@@ -3197,24 +3084,18 @@
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS | LIBLLDB_LOG_THREAD));
 
   // Ensure we have a debugged process.
-  if (!m_debugged_process_sp ||
-      (m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID))
+  if (!m_debugged_process_up ||
+      (m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID))
     return SendErrorResponse(50);
-
-  if (log)
-    log->Printf("GDBRemoteCommunicationServerLLGS::%s preparing packet for pid "
-                "%" PRIu64,
-                __FUNCTION__, m_debugged_process_sp->GetID());
+  LLDB_LOG(log, "preparing packet for pid {0}", m_debugged_process_up->GetID());
 
   StreamString response;
   const bool threads_with_valid_stop_info_only = false;
   JSONArray::SP threads_array_sp = GetJSONThreadsInfo(
-      *m_debugged_process_sp, threads_with_valid_stop_info_only);
+      *m_debugged_process_up, threads_with_valid_stop_info_only);
   if (!threads_array_sp) {
-    if (log)
-      log->Printf("GDBRemoteCommunicationServerLLGS::%s failed to prepare a "
-                  "packet for pid %" PRIu64,
-                  __FUNCTION__, m_debugged_process_sp->GetID());
+    LLDB_LOG(log, "failed to prepare a packet for pid {0}",
+             m_debugged_process_up->GetID());
     return SendErrorResponse(52);
   }
 
@@ -3228,17 +3109,17 @@
 GDBRemoteCommunicationServerLLGS::Handle_qWatchpointSupportInfo(
     StringExtractorGDBRemote &packet) {
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)
+  if (!m_debugged_process_up ||
+      m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)
     return SendErrorResponse(68);
 
   packet.SetFilePos(strlen("qWatchpointSupportInfo"));
   if (packet.GetBytesLeft() == 0)
     return SendOKResponse();
   if (packet.GetChar() != ':')
     return SendErrorResponse(67);
 
-  auto hw_debug_cap = m_debugged_process_sp->GetHardwareDebugSupportInfo();
+  auto hw_debug_cap = m_debugged_process_up->GetHardwareDebugSupportInfo();
 
   StreamGDBRemote response;
   if (hw_debug_cap == llvm::None)
@@ -3253,8 +3134,8 @@
 GDBRemoteCommunicationServerLLGS::Handle_qFileLoadAddress(
     StringExtractorGDBRemote &packet) {
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp ||
-      m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)
+  if (!m_debugged_process_up ||
+      m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)
     return SendErrorResponse(67);
 
   packet.SetFilePos(strlen("qFileLoadAddress:"));
@@ -3266,7 +3147,7 @@
 
   lldb::addr_t file_load_address = LLDB_INVALID_ADDRESS;
   Status error =
-      m_debugged_process_sp->GetFileLoadAddress(file_name, file_load_address);
+      m_debugged_process_up->GetFileLoadAddress(file_name, file_load_address);
   if (error.Fail())
     return SendErrorResponse(69);
 
@@ -3302,10 +3183,10 @@
   }
 
   // Fail if we don't have a current process.
-  if (!m_debugged_process_sp)
+  if (!m_debugged_process_up)
     return SendErrorResponse(68);
 
-  Status error = m_debugged_process_sp->IgnoreSignals(signals);
+  Status error = m_debugged_process_up->IgnoreSignals(signals);
   if (error.Fail())
     return SendErrorResponse(69);
 
@@ -3342,8 +3223,8 @@
   NativeThreadProtocolSP thread_sp;
 
   // We have no thread if we don't have a process.
-  if (!m_debugged_process_sp ||
-      m_debugged_process_sp->GetID() == LLDB_INVALID_PROCESS_ID)
+  if (!m_debugged_process_up ||
+      m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)
     return thread_sp;
 
   // If the client hasn't asked for thread suffix support, there will not be a
@@ -3355,9 +3236,9 @@
       return thread_sp;
     else if (current_tid == 0) {
       // Pick a thread.
-      return m_debugged_process_sp->GetThreadAtIndex(0);
+      return m_debugged_process_up->GetThreadAtIndex(0);
     } else
-      return m_debugged_process_sp->GetThreadByID(current_tid);
+      return m_debugged_process_up->GetThreadByID(current_tid);
   }
 
   Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_THREAD));
@@ -3387,7 +3268,7 @@
   packet.SetFilePos(packet.GetFilePos() + strlen("thread:"));
   const lldb::tid_t tid = packet.GetHexMaxU64(false, 0);
   if (tid != 0)
-    return m_debugged_process_sp->GetThreadByID(tid);
+    return m_debugged_process_up->GetThreadByID(tid);
 
   return thread_sp;
 }
@@ -3397,9 +3278,9 @@
     // Use whatever the debug process says is the current thread id
     // since the protocol either didn't specify or specified we want
     // any/all threads marked as the current thread.
-    if (!m_debugged_process_sp)
+    if (!m_debugged_process_up)
       return LLDB_INVALID_THREAD_ID;
-    return m_debugged_process_sp->GetCurrentThreadID();
+    return m_debugged_process_up->GetCurrentThreadID();
   }
   // Use the specific current thread id set by the gdb remote protocol.
   return m_current_tid;
@@ -3420,9 +3301,9 @@
 FileSpec
 GDBRemoteCommunicationServerLLGS::FindModuleFile(const std::string &module_path,
                                                  const ArchSpec &arch) {
-  if (m_debugged_process_sp) {
+  if (m_debugged_process_up) {
     FileSpec file_spec;
-    if (m_debugged_process_sp
+    if (m_debugged_process_up
             ->GetLoadedModuleFileSpec(module_path.c_str(), file_spec)
             .Success()) {
       if (file_spec.Exists())
Index: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
===================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -34,11 +34,11 @@
 public:
   class Factory : public NativeProcessProtocol::Factory {
   public:
-    llvm::Expected<NativeProcessProtocolSP>
+    llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
     Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
            MainLoop &mainloop) const override;
 
-    llvm::Expected<NativeProcessProtocolSP>
+    llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
     Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
            MainLoop &mainloop) const override;
   };
Index: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -64,7 +64,7 @@
 // Public Static Methods
 // -----------------------------------------------------------------------------
 
-llvm::Expected<NativeProcessProtocolSP>
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
 NativeProcessNetBSD::Factory::Launch(ProcessLaunchInfo &launch_info,
                                      NativeDelegate &native_delegate,
                                      MainLoop &mainloop) const {
@@ -101,24 +101,25 @@
   LLDB_LOG(log, "pid = {0:x}, detected architecture {1}", pid,
            arch.GetArchitectureName());
 
-  std::shared_ptr<NativeProcessNetBSD> process_sp(new NativeProcessNetBSD(
+  std::unique_ptr<NativeProcessNetBSD> process_up(new NativeProcessNetBSD(
       pid, launch_info.GetPTY().ReleaseMasterFileDescriptor(), native_delegate,
       arch, mainloop));
 
-  status = process_sp->ReinitializeThreads();
+  status = process_up->ReinitializeThreads();
   if (status.Fail())
     return status.ToError();
 
-  for (const auto &thread_sp : process_sp->m_threads) {
+  for (const auto &thread_sp : process_up->m_threads) {
     static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
         SIGSTOP);
   }
-  process_sp->SetState(StateType::eStateStopped);
+  process_up->SetState(StateType::eStateStopped);
 
-  return process_sp;
+  return std::move(process_up);
 }
 
-llvm::Expected<NativeProcessProtocolSP> NativeProcessNetBSD::Factory::Attach(
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+NativeProcessNetBSD::Factory::Attach(
     lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
     MainLoop &mainloop) const {
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
@@ -130,14 +131,14 @@
   if (!status.Success())
     return status.ToError();
 
-  std::shared_ptr<NativeProcessNetBSD> process_sp(
+  std::unique_ptr<NativeProcessNetBSD> process_up(
       new NativeProcessNetBSD(pid, -1, native_delegate, arch, mainloop));
 
-  status = process_sp->Attach();
+  status = process_up->Attach();
   if (!status.Success())
     return status.ToError();
 
-  return process_sp;
+  return std::move(process_up);
 }
 
 // -----------------------------------------------------------------------------
@@ -787,7 +788,7 @@
   if (m_threads.empty())
     SetCurrentThreadID(thread_id);
 
-  auto thread_sp = std::make_shared<NativeThreadNetBSD>(this, thread_id);
+  auto thread_sp = std::make_shared<NativeThreadNetBSD>(*this, thread_id);
   m_threads.push_back(thread_sp);
   return thread_sp;
 }
Index: lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
===================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
@@ -24,7 +24,7 @@
   friend class NativeProcessNetBSD;
 
 public:
-  NativeThreadNetBSD(NativeProcessNetBSD *process, lldb::tid_t tid);
+  NativeThreadNetBSD(NativeProcessNetBSD &process, lldb::tid_t tid);
 
   // ---------------------------------------------------------------------
   // NativeThreadProtocol Interface
Index: lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
@@ -104,15 +104,9 @@
 }
 
 NativeProcessNetBSD &NativeRegisterContextNetBSD::GetProcess() {
-  auto process_sp =
-      std::static_pointer_cast<NativeProcessNetBSD>(m_thread.GetProcess());
-  assert(process_sp);
-  return *process_sp;
+  return static_cast<NativeProcessNetBSD &>(m_thread.GetProcess());
 }
 
 ::pid_t NativeRegisterContextNetBSD::GetProcessPid() {
-  NativeProcessNetBSD &process = GetProcess();
-  lldb::pid_t pid = process.GetID();
-
-  return pid;
+  return GetProcess().GetID();
 }
Index: lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
@@ -24,7 +24,7 @@
 using namespace lldb_private;
 using namespace lldb_private::process_netbsd;
 
-NativeThreadNetBSD::NativeThreadNetBSD(NativeProcessNetBSD *process,
+NativeThreadNetBSD::NativeThreadNetBSD(NativeProcessNetBSD &process,
                                        lldb::tid_t tid)
     : NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
       m_stop_info(), m_reg_context_sp(), m_stop_description() {}
@@ -144,12 +144,8 @@
   if (m_reg_context_sp)
     return m_reg_context_sp;
 
-  NativeProcessProtocolSP m_process_sp = m_process_wp.lock();
-  if (!m_process_sp)
-    return NativeRegisterContextSP();
-
   ArchSpec target_arch;
-  if (!m_process_sp->GetArchitecture(target_arch))
+  if (!m_process.GetArchitecture(target_arch))
     return NativeRegisterContextSP();
 
   const uint32_t concrete_frame_idx = 0;
Index: lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
+++ lldb/trunk/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
@@ -30,11 +30,7 @@
   // read.
   lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
 
-  NativeProcessProtocolSP process_sp(m_thread.GetProcess());
-  if (!process_sp)
-    return byte_order;
-
-  if (!process_sp->GetByteOrder(byte_order)) {
+  if (!m_thread.GetProcess().GetByteOrder(byte_order)) {
     // FIXME log here
   }
 
Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
===================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -42,11 +42,11 @@
 public:
   class Factory : public NativeProcessProtocol::Factory {
   public:
-    llvm::Expected<NativeProcessProtocolSP>
+    llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
     Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
            MainLoop &mainloop) const override;
 
-    llvm::Expected<NativeProcessProtocolSP>
+    llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
     Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
            MainLoop &mainloop) const override;
   };
@@ -160,15 +160,14 @@
   // Private Instance Methods
   // ---------------------------------------------------------------------
   NativeProcessLinux(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
-                     const ArchSpec &arch, MainLoop &mainloop);
+                     const ArchSpec &arch, MainLoop &mainloop,
+                     llvm::ArrayRef<::pid_t> tids);
 
   // Returns a list of process threads that we have attached to.
   static llvm::Expected<std::vector<::pid_t>> Attach(::pid_t pid);
 
   static Status SetDefaultPtraceOpts(const lldb::pid_t);
 
-  void InitializeThreads(llvm::ArrayRef<::pid_t> tids);
-
   void MonitorCallback(lldb::pid_t pid, bool exited, WaitStatus status);
 
   void WaitForNewThread(::pid_t tid);
Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -214,7 +214,7 @@
 // Public Static Methods
 // -----------------------------------------------------------------------------
 
-llvm::Expected<NativeProcessProtocolSP>
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
 NativeProcessLinux::Factory::Launch(ProcessLaunchInfo &launch_info,
                                     NativeDelegate &native_delegate,
                                     MainLoop &mainloop) const {
@@ -259,14 +259,13 @@
     return status.ToError();
   }
 
-  std::shared_ptr<NativeProcessLinux> process_sp(new NativeProcessLinux(
+  return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
       pid, launch_info.GetPTY().ReleaseMasterFileDescriptor(), native_delegate,
-      arch, mainloop));
-  process_sp->InitializeThreads({pid});
-  return process_sp;
+      arch, mainloop, {pid}));
 }
 
-llvm::Expected<NativeProcessProtocolSP> NativeProcessLinux::Factory::Attach(
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+NativeProcessLinux::Factory::Attach(
     lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
     MainLoop &mainloop) const {
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
@@ -282,19 +281,18 @@
   if (!tids_or)
     return tids_or.takeError();
 
-  std::shared_ptr<NativeProcessLinux> process_sp(
-      new NativeProcessLinux(pid, -1, native_delegate, arch, mainloop));
-  process_sp->InitializeThreads(*tids_or);
-  return process_sp;
+  return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
+      pid, -1, native_delegate, arch, mainloop, *tids_or));
 }
 
 // -----------------------------------------------------------------------------
 // Public Instance Methods
 // -----------------------------------------------------------------------------
 
 NativeProcessLinux::NativeProcessLinux(::pid_t pid, int terminal_fd,
                                        NativeDelegate &delegate,
-                                       const ArchSpec &arch, MainLoop &mainloop)
+                                       const ArchSpec &arch, MainLoop &mainloop,
+                                       llvm::ArrayRef<::pid_t> tids)
     : NativeProcessProtocol(pid, terminal_fd, delegate), m_arch(arch) {
   if (m_terminal_fd != -1) {
     Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
@@ -305,9 +303,7 @@
   m_sigchld_handle = mainloop.RegisterSignal(
       SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
   assert(m_sigchld_handle && status.Success());
-}
 
-void NativeProcessLinux::InitializeThreads(llvm::ArrayRef<::pid_t> tids) {
   for (const auto &tid : tids) {
     NativeThreadLinuxSP thread_sp = AddThread(tid);
     assert(thread_sp && "AddThread() returned a nullptr thread");
@@ -2009,7 +2005,7 @@
   if (m_threads.empty())
     SetCurrentThreadID(thread_id);
 
-  auto thread_sp = std::make_shared<NativeThreadLinux>(this, thread_id);
+  auto thread_sp = std::make_shared<NativeThreadLinux>(*this, thread_id);
   m_threads.push_back(thread_sp);
 
   if (m_pt_proces_trace_id != LLDB_INVALID_UID) {
Index: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h
===================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -27,7 +27,7 @@
   friend class NativeProcessLinux;
 
 public:
-  NativeThreadLinux(NativeProcessLinux *process, lldb::tid_t tid);
+  NativeThreadLinux(NativeProcessLinux &process, lldb::tid_t tid);
 
   // ---------------------------------------------------------------------
   // NativeThreadProtocol Interface
Index: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
===================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -85,7 +85,7 @@
 }
 }
 
-NativeThreadLinux::NativeThreadLinux(NativeProcessLinux *process,
+NativeThreadLinux::NativeThreadLinux(NativeProcessLinux &process,
                                      lldb::tid_t tid)
     : NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
       m_stop_info(), m_reg_context_sp(), m_stop_description() {}
@@ -144,12 +144,8 @@
   if (m_reg_context_sp)
     return m_reg_context_sp;
 
-  NativeProcessProtocolSP m_process_sp = m_process_wp.lock();
-  if (!m_process_sp)
-    return NativeRegisterContextSP();
-
   ArchSpec target_arch;
-  if (!m_process_sp->GetArchitecture(target_arch))
+  if (!m_process.GetArchitecture(target_arch))
     return NativeRegisterContextSP();
 
   const uint32_t concrete_frame_idx = 0;
@@ -460,20 +456,10 @@
   if (new_state == old_state)
     return;
 
-  NativeProcessProtocolSP m_process_sp = m_process_wp.lock();
-  lldb::pid_t pid =
-      m_process_sp ? m_process_sp->GetID() : LLDB_INVALID_PROCESS_ID;
-
-  // Log it.
-  log->Printf("NativeThreadLinux: thread (pid=%" PRIu64 ", tid=%" PRIu64
-              ") changing from state %s to %s",
-              pid, GetID(), StateAsCString(old_state),
-              StateAsCString(new_state));
+  LLDB_LOG(log, "pid={0}, tid={1}: changing from state {2} to {3}",
+           m_process.GetID(), GetID(), old_state, new_state);
 }
 
 NativeProcessLinux &NativeThreadLinux::GetProcess() {
-  auto process_sp = std::static_pointer_cast<NativeProcessLinux>(
-      NativeThreadProtocol::GetProcess());
-  assert(process_sp);
-  return *process_sp;
+  return static_cast<NativeProcessLinux &>(m_process);
 }
Index: lldb/trunk/include/lldb/lldb-private-forward.h
===================================================================
--- lldb/trunk/include/lldb/lldb-private-forward.h
+++ lldb/trunk/include/lldb/lldb-private-forward.h
@@ -30,10 +30,6 @@
 // SP/WP decls.
 // ---------------------------------------------------------------
 typedef std::shared_ptr<NativeBreakpoint> NativeBreakpointSP;
-typedef std::shared_ptr<lldb_private::NativeProcessProtocol>
-    NativeProcessProtocolSP;
-typedef std::weak_ptr<lldb_private::NativeProcessProtocol>
-    NativeProcessProtocolWP;
 typedef std::shared_ptr<lldb_private::NativeRegisterContext>
     NativeRegisterContextSP;
 typedef std::shared_ptr<lldb_private::NativeThreadProtocol>
Index: lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
===================================================================
--- lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
+++ lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
@@ -33,8 +33,7 @@
 //------------------------------------------------------------------
 // NativeProcessProtocol
 //------------------------------------------------------------------
-class NativeProcessProtocol
-    : public std::enable_shared_from_this<NativeProcessProtocol> {
+class NativeProcessProtocol {
   friend class SoftwareBreakpoint;
 
 public:
@@ -268,7 +267,7 @@
     ///     A NativeProcessProtocol shared pointer if the operation succeeded or
     ///     an error object if it failed.
     //------------------------------------------------------------------
-    virtual llvm::Expected<NativeProcessProtocolSP>
+    virtual llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
     Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
            MainLoop &mainloop) const = 0;
 
@@ -292,7 +291,7 @@
     ///     A NativeProcessProtocol shared pointer if the operation succeeded or
     ///     an error object if it failed.
     //------------------------------------------------------------------
-    virtual llvm::Expected<NativeProcessProtocolSP>
+    virtual llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
     Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
            MainLoop &mainloop) const = 0;
   };
Index: lldb/trunk/include/lldb/Host/common/NativeThreadProtocol.h
===================================================================
--- lldb/trunk/include/lldb/Host/common/NativeThreadProtocol.h
+++ lldb/trunk/include/lldb/Host/common/NativeThreadProtocol.h
@@ -23,7 +23,7 @@
 class NativeThreadProtocol
     : public std::enable_shared_from_this<NativeThreadProtocol> {
 public:
-  NativeThreadProtocol(NativeProcessProtocol *process, lldb::tid_t tid);
+  NativeThreadProtocol(NativeProcessProtocol &process, lldb::tid_t tid);
 
   virtual ~NativeThreadProtocol() {}
 
@@ -46,7 +46,7 @@
 
   lldb::tid_t GetID() const { return m_tid; }
 
-  NativeProcessProtocolSP GetProcess();
+  NativeProcessProtocol &GetProcess() { return m_process; }
 
   // ---------------------------------------------------------------------
   // Thread-specific watchpoints
@@ -64,7 +64,7 @@
   virtual Status RemoveHardwareBreakpoint(lldb::addr_t addr) = 0;
 
 protected:
-  NativeProcessProtocolWP m_process_wp;
+  NativeProcessProtocol &m_process;
   lldb::tid_t m_tid;
 };
 }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to