This revision was automatically updated to reflect the committed changes.
Closed by commit rL316007: Remove shared_pointer from NativeThreadProtocol 
(authored by labath).

Changed prior to commit:
  https://reviews.llvm.org/D35618?vs=107289&id=119338#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35618

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/NativeProcessProtocol.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
  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/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
  
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h

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
@@ -121,7 +121,7 @@
 
   bool HasThreadNoLock(lldb::tid_t thread_id);
 
-  NativeThreadNetBSDSP AddThread(lldb::tid_t thread_id);
+  NativeThreadNetBSD &AddThread(lldb::tid_t thread_id);
 
   void MonitorCallback(lldb::pid_t pid, int signal);
   void MonitorExited(lldb::pid_t pid, WaitStatus status);
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
@@ -109,10 +109,8 @@
   if (status.Fail())
     return status.ToError();
 
-  for (const auto &thread_sp : process_up->m_threads) {
-    static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
-        SIGSTOP);
-  }
+  for (const auto &thread : process_up->m_threads)
+    static_cast<NativeThreadNetBSD &>(*thread).SetStoppedBySignal(SIGSTOP);
   process_up->SetState(StateType::eStateStopped);
 
   return std::move(process_up);
@@ -198,9 +196,9 @@
     // Handle SIGSTOP from LLGS (LLDB GDB Server)
     if (info.psi_siginfo.si_code == SI_USER &&
         info.psi_siginfo.si_pid == ::getpid()) {
-      /* Stop Tracking All Threads attached to Process */
-      for (const auto &thread_sp : m_threads) {
-        static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
+      /* Stop Tracking all Threads attached to Process */
+      for (const auto &thread : m_threads) {
+        static_cast<NativeThreadNetBSD &>(*thread).SetStoppedBySignal(
             SIGSTOP, &info.psi_siginfo);
       }
     }
@@ -221,18 +219,15 @@
 
   switch (info.psi_siginfo.si_code) {
   case TRAP_BRKPT:
-    for (const auto &thread_sp : m_threads) {
-      static_pointer_cast<NativeThreadNetBSD>(thread_sp)
-          ->SetStoppedByBreakpoint();
-      FixupBreakpointPCAsNeeded(
-          *static_pointer_cast<NativeThreadNetBSD>(thread_sp));
+    for (const auto &thread : m_threads) {
+      static_cast<NativeThreadNetBSD &>(*thread).SetStoppedByBreakpoint();
+      FixupBreakpointPCAsNeeded(static_cast<NativeThreadNetBSD &>(*thread));
     }
     SetState(StateType::eStateStopped, true);
     break;
   case TRAP_TRACE:
-    for (const auto &thread_sp : m_threads) {
-      static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedByTrace();
-    }
+    for (const auto &thread : m_threads)
+      static_cast<NativeThreadNetBSD &>(*thread).SetStoppedByTrace();
     SetState(StateType::eStateStopped, true);
     break;
   case TRAP_EXEC: {
@@ -245,49 +240,44 @@
     // Let our delegate know we have just exec'd.
     NotifyDidExec();
 
-    for (const auto &thread_sp : m_threads) {
-      static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedByExec();
-    }
+    for (const auto &thread : m_threads)
+      static_cast<NativeThreadNetBSD &>(*thread).SetStoppedByExec();
     SetState(StateType::eStateStopped, true);
   } break;
   case TRAP_DBREG: {
     // If a watchpoint was hit, report it
     uint32_t wp_index;
-    Status error =
-        static_pointer_cast<NativeThreadNetBSD>(m_threads[info.psi_lwpid])
-            ->GetRegisterContext()
-            ->GetWatchpointHitIndex(wp_index,
-                                    (uintptr_t)info.psi_siginfo.si_addr);
+    Status error = static_cast<NativeThreadNetBSD &>(*m_threads[info.psi_lwpid])
+                       .GetRegisterContext()
+                       ->GetWatchpointHitIndex(
+                           wp_index, (uintptr_t)info.psi_siginfo.si_addr);
     if (error.Fail())
       LLDB_LOG(log,
                "received error while checking for watchpoint hits, pid = "
                "{0}, LWP = {1}, error = {2}",
                GetID(), info.psi_lwpid, error);
     if (wp_index != LLDB_INVALID_INDEX32) {
-      for (const auto &thread_sp : m_threads) {
-        static_pointer_cast<NativeThreadNetBSD>(thread_sp)
-            ->SetStoppedByWatchpoint(wp_index);
-      }
+      for (const auto &thread : m_threads)
+        static_cast<NativeThreadNetBSD &>(*thread).SetStoppedByWatchpoint(
+            wp_index);
       SetState(StateType::eStateStopped, true);
       break;
     }
 
     // If a breakpoint was hit, report it
     uint32_t bp_index;
-    error = static_pointer_cast<NativeThreadNetBSD>(m_threads[info.psi_lwpid])
-                ->GetRegisterContext()
+    error = static_cast<NativeThreadNetBSD &>(*m_threads[info.psi_lwpid])
+                .GetRegisterContext()
                 ->GetHardwareBreakHitIndex(bp_index,
                                            (uintptr_t)info.psi_siginfo.si_addr);
     if (error.Fail())
       LLDB_LOG(log,
                "received error while checking for hardware "
                "breakpoint hits, pid = {0}, LWP = {1}, error = {2}",
                GetID(), info.psi_lwpid, error);
     if (bp_index != LLDB_INVALID_INDEX32) {
-      for (const auto &thread_sp : m_threads) {
-        static_pointer_cast<NativeThreadNetBSD>(thread_sp)
-            ->SetStoppedByBreakpoint();
-      }
+      for (const auto &thread : m_threads)
+        static_cast<NativeThreadNetBSD &>(*thread).SetStoppedByBreakpoint();
       SetState(StateType::eStateStopped, true);
       break;
     }
@@ -300,8 +290,8 @@
   const auto siginfo_err =
       PtraceWrapper(PT_GET_SIGINFO, pid, &info, sizeof(info));
 
-  for (const auto &thread_sp : m_threads) {
-    static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
+  for (const auto &thread : m_threads) {
+    static_cast<NativeThreadNetBSD &>(*thread).SetStoppedBySignal(
         info.psi_siginfo.si_signo, &info.psi_siginfo);
   }
   SetState(StateType::eStateStopped, true);
@@ -433,13 +423,13 @@
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
   LLDB_LOG(log, "pid {0}", GetID());
 
-  const auto &thread_sp = m_threads[0];
+  const auto &thread = m_threads[0];
   const ResumeAction *const action =
-      resume_actions.GetActionForThread(thread_sp->GetID(), true);
+      resume_actions.GetActionForThread(thread->GetID(), true);
 
   if (action == nullptr) {
     LLDB_LOG(log, "no action specified for pid {0} tid {1}", GetID(),
-             thread_sp->GetID());
+             thread->GetID());
     return Status();
   }
 
@@ -452,9 +442,8 @@
                                                action->signal);
     if (!error.Success())
       return error;
-    for (const auto &thread_sp : m_threads) {
-      static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetRunning();
-    }
+    for (const auto &thread : m_threads)
+      static_cast<NativeThreadNetBSD &>(*thread).SetRunning();
     SetState(eStateRunning, true);
     break;
   }
@@ -464,9 +453,8 @@
                                                action->signal);
     if (!error.Success())
       return error;
-    for (const auto &thread_sp : m_threads) {
-      static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStepping();
-    }
+    for (const auto &thread : m_threads)
+      static_cast<NativeThreadNetBSD &>(*thread).SetStepping();
     SetState(eStateStepping, true);
     break;
 
@@ -478,7 +466,7 @@
     return Status("NativeProcessNetBSD::%s (): unexpected state %s specified "
                   "for pid %" PRIu64 ", tid %" PRIu64,
                   __FUNCTION__, StateAsCString(action->state), GetID(),
-                  thread_sp->GetID());
+                  thread->GetID());
   }
 
   return Status();
@@ -764,9 +752,9 @@
 }
 
 bool NativeProcessNetBSD::HasThreadNoLock(lldb::tid_t thread_id) {
-  for (auto thread_sp : m_threads) {
-    assert(thread_sp && "thread list should not contain NULL threads");
-    if (thread_sp->GetID() == thread_id) {
+  for (const auto &thread : m_threads) {
+    assert(thread && "thread list should not contain NULL threads");
+    if (thread->GetID() == thread_id) {
       // We have this thread.
       return true;
     }
@@ -776,7 +764,7 @@
   return false;
 }
 
-NativeThreadNetBSDSP NativeProcessNetBSD::AddThread(lldb::tid_t thread_id) {
+NativeThreadNetBSD &NativeProcessNetBSD::AddThread(lldb::tid_t thread_id) {
 
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
   LLDB_LOG(log, "pid {0} adding thread with tid {1}", GetID(), thread_id);
@@ -788,9 +776,8 @@
   if (m_threads.empty())
     SetCurrentThreadID(thread_id);
 
-  auto thread_sp = std::make_shared<NativeThreadNetBSD>(*this, thread_id);
-  m_threads.push_back(thread_sp);
-  return thread_sp;
+  m_threads.push_back(llvm::make_unique<NativeThreadNetBSD>(*this, thread_id));
+  return static_cast<NativeThreadNetBSD &>(*m_threads.back());
 }
 
 Status NativeProcessNetBSD::Attach() {
@@ -811,10 +798,8 @@
   if (status.Fail())
     return status;
 
-  for (const auto &thread_sp : m_threads) {
-    static_pointer_cast<NativeThreadNetBSD>(thread_sp)->SetStoppedBySignal(
-        SIGSTOP);
-  }
+  for (const auto &thread : m_threads)
+    static_cast<NativeThreadNetBSD &>(*thread).SetStoppedBySignal(SIGSTOP);
 
   // Let our process instance know the thread has stopped.
   SetState(StateType::eStateStopped);
@@ -928,7 +913,7 @@
   }
   // Reinitialize from scratch threads and register them in process
   while (info.pl_lwpid != 0) {
-    NativeThreadNetBSDSP thread_sp = AddThread(info.pl_lwpid);
+    AddThread(info.pl_lwpid);
     error = PtraceWrapper(PT_LWPINFO, GetID(), &info, sizeof(info));
     if (error.Fail()) {
       return error;
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
@@ -102,7 +102,7 @@
   Status GetFileLoadAddress(const llvm::StringRef &file_name,
                             lldb::addr_t &load_addr) override;
 
-  NativeThreadLinuxSP GetThreadByID(lldb::tid_t id);
+  NativeThreadLinux *GetThreadByID(lldb::tid_t id);
 
   llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
   GetAuxvData() const override {
@@ -203,7 +203,7 @@
 
   bool StopTrackingThread(lldb::tid_t thread_id);
 
-  NativeThreadLinuxSP AddThread(lldb::tid_t thread_id);
+  NativeThreadLinux &AddThread(lldb::tid_t thread_id);
 
   Status GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
 
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
@@ -305,10 +305,9 @@
   assert(m_sigchld_handle && status.Success());
 
   for (const auto &tid : tids) {
-    NativeThreadLinuxSP thread_sp = AddThread(tid);
-    assert(thread_sp && "AddThread() returned a nullptr thread");
-    thread_sp->SetStoppedBySignal(SIGSTOP);
-    ThreadWasCreated(*thread_sp);
+    NativeThreadLinux &thread = AddThread(tid);
+    thread.SetStoppedBySignal(SIGSTOP);
+    ThreadWasCreated(thread);
   }
 
   // Let our process instance know the thread has stopped.
@@ -478,11 +477,11 @@
     LLDB_LOG(log, "tid {0}, si_code: {1}, si_pid: {2}", pid, info.si_code,
              info.si_pid);
 
-    auto thread_sp = AddThread(pid);
+    NativeThreadLinux &thread = AddThread(pid);
 
     // Resume the newly created thread.
-    ResumeThread(*thread_sp, eStateRunning, LLDB_INVALID_SIGNAL_NUMBER);
-    ThreadWasCreated(*thread_sp);
+    ResumeThread(thread, eStateRunning, LLDB_INVALID_SIGNAL_NUMBER);
+    ThreadWasCreated(thread);
     return;
   }
 
@@ -549,12 +548,9 @@
 void NativeProcessLinux::WaitForNewThread(::pid_t tid) {
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
 
-  NativeThreadLinuxSP new_thread_sp = GetThreadByID(tid);
-
-  if (new_thread_sp) {
+  if (GetThreadByID(tid)) {
     // We are already tracking the thread - we got the event on the new thread
-    // (see
-    // MonitorSignal) before this one. We are done.
+    // (see MonitorSignal) before this one. We are done.
     return;
   }
 
@@ -587,10 +583,10 @@
   }
 
   LLDB_LOG(log, "pid = {0}: tracking new thread tid {1}", GetID(), tid);
-  new_thread_sp = AddThread(tid);
+  NativeThreadLinux &new_thread = AddThread(tid);
 
-  ResumeThread(*new_thread_sp, eStateRunning, LLDB_INVALID_SIGNAL_NUMBER);
-  ThreadWasCreated(*new_thread_sp);
+  ResumeThread(new_thread, eStateRunning, LLDB_INVALID_SIGNAL_NUMBER);
+  ThreadWasCreated(new_thread);
 }
 
 void NativeProcessLinux::MonitorSIGTRAP(const siginfo_t &info,
@@ -630,7 +626,6 @@
   }
 
   case (SIGTRAP | (PTRACE_EVENT_EXEC << 8)): {
-    NativeThreadLinuxSP main_thread_sp;
     LLDB_LOG(log, "received exec event, code = {0}", info.si_code ^ SIGTRAP);
 
     // Exec clears any pending notifications.
@@ -640,44 +635,26 @@
     // which only copies the main thread.
     LLDB_LOG(log, "exec received, stop tracking all but main thread");
 
-    for (auto thread_sp : m_threads) {
-      const bool is_main_thread = thread_sp && thread_sp->GetID() == GetID();
-      if (is_main_thread) {
-        main_thread_sp = std::static_pointer_cast<NativeThreadLinux>(thread_sp);
-        LLDB_LOG(log, "found main thread with tid {0}, keeping",
-                 main_thread_sp->GetID());
-      } else {
-        LLDB_LOG(log, "discarding non-main-thread tid {0} due to exec",
-                 thread_sp->GetID());
-      }
+    for (auto i = m_threads.begin(); i != m_threads.end();) {
+      if ((*i)->GetID() == GetID())
+        i = m_threads.erase(i);
+      else
+        ++i;
     }
+    assert(m_threads.size() == 1);
+    auto *main_thread = static_cast<NativeThreadLinux *>(m_threads[0].get());
 
-    m_threads.clear();
-
-    if (main_thread_sp) {
-      m_threads.push_back(main_thread_sp);
-      SetCurrentThreadID(main_thread_sp->GetID());
-      main_thread_sp->SetStoppedByExec();
-    } else {
-      SetCurrentThreadID(LLDB_INVALID_THREAD_ID);
-      LLDB_LOG(log,
-               "pid {0} no main thread found, discarded all threads, "
-               "we're in a no-thread state!",
-               GetID());
-    }
+    SetCurrentThreadID(main_thread->GetID());
+    main_thread->SetStoppedByExec();
 
     // Tell coordinator about about the "new" (since exec) stopped main thread.
-    ThreadWasCreated(*main_thread_sp);
+    ThreadWasCreated(*main_thread);
 
     // Let our delegate know we have just exec'd.
     NotifyDidExec();
 
-    // If we have a main thread, indicate we are stopped.
-    assert(main_thread_sp && "exec called during ptraced process but no main "
-                             "thread metadata tracked");
-
     // Let the process know we're stopped.
-    StopRunningThreads(main_thread_sp->GetID());
+    StopRunningThreads(main_thread->GetID());
 
     break;
   }
@@ -1115,44 +1092,44 @@
   bool software_single_step = !SupportHardwareSingleStepping();
 
   if (software_single_step) {
-    for (auto thread_sp : m_threads) {
-      assert(thread_sp && "thread list should not contain NULL threads");
+    for (const auto &thread : m_threads) {
+      assert(thread && "thread list should not contain NULL threads");
 
       const ResumeAction *const action =
-          resume_actions.GetActionForThread(thread_sp->GetID(), true);
+          resume_actions.GetActionForThread(thread->GetID(), true);
       if (action == nullptr)
         continue;
 
       if (action->state == eStateStepping) {
         Status error = SetupSoftwareSingleStepping(
-            static_cast<NativeThreadLinux &>(*thread_sp));
+            static_cast<NativeThreadLinux &>(*thread));
         if (error.Fail())
           return error;
       }
     }
   }
 
-  for (auto thread_sp : m_threads) {
-    assert(thread_sp && "thread list should not contain NULL threads");
+  for (const auto &thread : m_threads) {
+    assert(thread && "thread list should not contain NULL threads");
 
     const ResumeAction *const action =
-        resume_actions.GetActionForThread(thread_sp->GetID(), true);
+        resume_actions.GetActionForThread(thread->GetID(), true);
 
     if (action == nullptr) {
       LLDB_LOG(log, "no action specified for pid {0} tid {1}", GetID(),
-               thread_sp->GetID());
+               thread->GetID());
       continue;
     }
 
     LLDB_LOG(log, "processing resume action state {0} for pid {1} tid {2}",
-             action->state, GetID(), thread_sp->GetID());
+             action->state, GetID(), thread->GetID());
 
     switch (action->state) {
     case eStateRunning:
     case eStateStepping: {
       // Run the thread, possibly feeding it the signal.
       const int signo = action->signal;
-      ResumeThread(static_cast<NativeThreadLinux &>(*thread_sp), action->state,
+      ResumeThread(static_cast<NativeThreadLinux &>(*thread), action->state,
                    signo);
       break;
     }
@@ -1165,7 +1142,7 @@
       return Status("NativeProcessLinux::%s (): unexpected state %s specified "
                     "for pid %" PRIu64 ", tid %" PRIu64,
                     __FUNCTION__, StateAsCString(action->state), GetID(),
-                    thread_sp->GetID());
+                    thread->GetID());
     }
   }
 
@@ -1191,8 +1168,8 @@
   if (GetID() == LLDB_INVALID_PROCESS_ID)
     return error;
 
-  for (auto thread_sp : m_threads) {
-    Status e = Detach(thread_sp->GetID());
+  for (const auto &thread : m_threads) {
+    Status e = Detach(thread->GetID());
     if (e.Fail())
       error =
           e; // Save the error, but still attempt to detach from other threads.
@@ -1222,44 +1199,40 @@
   // the chosen thread that will be the stop-reason thread.
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
 
-  NativeThreadProtocolSP running_thread_sp;
-  NativeThreadProtocolSP stopped_thread_sp;
+  NativeThreadProtocol *running_thread = nullptr;
+  NativeThreadProtocol *stopped_thread = nullptr;
 
   LLDB_LOG(log, "selecting running thread for interrupt target");
-  for (auto thread_sp : m_threads) {
-    // The thread shouldn't be null but lets just cover that here.
-    if (!thread_sp)
-      continue;
-
+  for (const auto &thread : m_threads) {
     // If we have a running or stepping thread, we'll call that the
     // target of the interrupt.
-    const auto thread_state = thread_sp->GetState();
+    const auto thread_state = thread->GetState();
     if (thread_state == eStateRunning || thread_state == eStateStepping) {
-      running_thread_sp = thread_sp;
+      running_thread = thread.get();
       break;
-    } else if (!stopped_thread_sp && StateIsStoppedState(thread_state, true)) {
+    } else if (!stopped_thread && StateIsStoppedState(thread_state, true)) {
       // Remember the first non-dead stopped thread.  We'll use that as a backup
       // if there are no running threads.
-      stopped_thread_sp = thread_sp;
+      stopped_thread = thread.get();
     }
   }
 
-  if (!running_thread_sp && !stopped_thread_sp) {
+  if (!running_thread && !stopped_thread) {
     Status error("found no running/stepping or live stopped threads as target "
                  "for interrupt");
     LLDB_LOG(log, "skipping due to error: {0}", error);
 
     return error;
   }
 
-  NativeThreadProtocolSP deferred_signal_thread_sp =
-      running_thread_sp ? running_thread_sp : stopped_thread_sp;
+  NativeThreadProtocol *deferred_signal_thread =
+      running_thread ? running_thread : stopped_thread;
 
   LLDB_LOG(log, "pid {0} {1} tid {2} chosen for interrupt target", GetID(),
-           running_thread_sp ? "running" : "stopped",
-           deferred_signal_thread_sp->GetID());
+           running_thread ? "running" : "stopped",
+           deferred_signal_thread->GetID());
 
-  StopRunningThreads(deferred_signal_thread_sp->GetID());
+  StopRunningThreads(deferred_signal_thread->GetID());
 
   return Status();
 }
@@ -1975,9 +1948,9 @@
 }
 
 bool NativeProcessLinux::HasThreadNoLock(lldb::tid_t thread_id) {
-  for (auto thread_sp : m_threads) {
-    assert(thread_sp && "thread list should not contain NULL threads");
-    if (thread_sp->GetID() == thread_id) {
+  for (const auto &thread : m_threads) {
+    assert(thread && "thread list should not contain NULL threads");
+    if (thread->GetID() == thread_id) {
       // We have this thread.
       return true;
     }
@@ -2006,7 +1979,7 @@
   return found;
 }
 
-NativeThreadLinuxSP NativeProcessLinux::AddThread(lldb::tid_t thread_id) {
+NativeThreadLinux &NativeProcessLinux::AddThread(lldb::tid_t thread_id) {
   Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
   LLDB_LOG(log, "pid {0} adding thread with tid {1}", GetID(), thread_id);
 
@@ -2017,8 +1990,7 @@
   if (m_threads.empty())
     SetCurrentThreadID(thread_id);
 
-  auto thread_sp = std::make_shared<NativeThreadLinux>(*this, thread_id);
-  m_threads.push_back(thread_sp);
+  m_threads.push_back(llvm::make_unique<NativeThreadLinux>(*this, thread_id));
 
   if (m_pt_proces_trace_id != LLDB_INVALID_UID) {
     auto traceMonitor = ProcessorTraceMonitor::Create(
@@ -2034,7 +2006,7 @@
     }
   }
 
-  return thread_sp;
+  return static_cast<NativeThreadLinux &>(*m_threads.back());
 }
 
 Status
@@ -2156,8 +2128,8 @@
   return Status("No load address found for specified file.");
 }
 
-NativeThreadLinuxSP NativeProcessLinux::GetThreadByID(lldb::tid_t tid) {
-  return std::static_pointer_cast<NativeThreadLinux>(
+NativeThreadLinux *NativeProcessLinux::GetThreadByID(lldb::tid_t tid) {
+  return static_cast<NativeThreadLinux *>(
       NativeProcessProtocol::GetThreadByID(tid));
 }
 
@@ -2212,9 +2184,9 @@
 
   // Request a stop for all the thread stops that need to be stopped
   // and are not already known to be stopped.
-  for (const auto &thread_sp : m_threads) {
-    if (StateIsRunningState(thread_sp->GetState()))
-      static_pointer_cast<NativeThreadLinux>(thread_sp)->RequestStop();
+  for (const auto &thread : m_threads) {
+    if (StateIsRunningState(thread->GetState()))
+      static_cast<NativeThreadLinux *>(thread.get())->RequestStop();
   }
 
   SignalIfAllThreadsStopped();
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
@@ -110,8 +110,6 @@
   WatchpointIndexMap m_hw_break_index_map;
   std::unique_ptr<SingleStepWorkaround> m_step_workaround;
 };
-
-typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP;
 } // namespace process_linux
 } // namespace lldb_private
 
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
@@ -234,7 +234,7 @@
 
   void HandleInferiorState_Stopped(NativeProcessProtocol *process);
 
-  NativeThreadProtocolSP GetThreadFromSuffix(StringExtractorGDBRemote &packet);
+  NativeThreadProtocol *GetThreadFromSuffix(StringExtractorGDBRemote &packet);
 
   uint32_t GetNextSavedRegistersID();
 
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
@@ -523,16 +523,16 @@
 
   // Ensure we can get info on the given thread.
   uint32_t thread_idx = 0;
-  for (NativeThreadProtocolSP thread_sp;
-       (thread_sp = process.GetThreadAtIndex(thread_idx)) != nullptr;
+  for (NativeThreadProtocol *thread;
+       (thread = process.GetThreadAtIndex(thread_idx)) != nullptr;
        ++thread_idx) {
 
-    lldb::tid_t tid = thread_sp->GetID();
+    lldb::tid_t tid = thread->GetID();
 
     // Grab the reason this thread stopped.
     struct ThreadStopInfo tid_stop_info;
     std::string description;
-    if (!thread_sp->GetStopReason(tid_stop_info, description))
+    if (!thread->GetStopReason(tid_stop_info, description))
       return nullptr;
 
     const int signum = tid_stop_info.details.signal.signo;
@@ -548,15 +548,15 @@
     threads_array_sp->AppendObject(thread_obj_sp);
 
     if (!abridged) {
-      if (JSONObject::SP registers_sp = GetRegistersAsJSON(*thread_sp))
+      if (JSONObject::SP registers_sp = GetRegistersAsJSON(*thread))
         thread_obj_sp->SetObject("registers", registers_sp);
     }
 
     thread_obj_sp->SetObject("tid", std::make_shared<JSONNumber>(tid));
     if (signum != 0)
       thread_obj_sp->SetObject("signal", std::make_shared<JSONNumber>(signum));
 
-    const std::string thread_name = thread_sp->GetName();
+    const std::string thread_name = thread->GetName();
     if (!thread_name.empty())
       thread_obj_sp->SetObject("name",
                                std::make_shared<JSONString>(thread_name));
@@ -604,14 +604,14 @@
            m_debugged_process_up->GetID(), tid);
 
   // Ensure we can get info on the given thread.
-  NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadByID(tid));
-  if (!thread_sp)
+  NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid);
+  if (!thread)
     return SendErrorResponse(51);
 
   // Grab the reason this thread stopped.
   struct ThreadStopInfo tid_stop_info;
   std::string description;
-  if (!thread_sp->GetStopReason(tid_stop_info, description))
+  if (!thread->GetStopReason(tid_stop_info, description))
     return SendErrorResponse(52);
 
   // FIXME implement register handling for exec'd inferiors.
@@ -638,7 +638,7 @@
   response.Printf("thread:%" PRIx64 ";", tid);
 
   // Include the thread name if there is one.
-  const std::string thread_name = thread_sp->GetName();
+  const std::string thread_name = thread->GetName();
   if (!thread_name.empty()) {
     size_t thread_name_len = thread_name.length();
 
@@ -665,15 +665,13 @@
     response.PutCString("threads:");
 
     uint32_t thread_index = 0;
-    NativeThreadProtocolSP listed_thread_sp;
-    for (listed_thread_sp =
-             m_debugged_process_up->GetThreadAtIndex(thread_index);
-         listed_thread_sp; ++thread_index,
-        listed_thread_sp = m_debugged_process_up->GetThreadAtIndex(
-            thread_index)) {
+    NativeThreadProtocol *listed_thread;
+    for (listed_thread = m_debugged_process_up->GetThreadAtIndex(thread_index);
+         listed_thread; ++thread_index,
+        listed_thread = m_debugged_process_up->GetThreadAtIndex(thread_index)) {
       if (thread_index > 0)
         response.PutChar(',');
-      response.Printf("%" PRIx64, listed_thread_sp->GetID());
+      response.Printf("%" PRIx64, listed_thread->GetID());
     }
     response.PutChar(';');
 
@@ -701,10 +699,10 @@
     uint32_t i = 0;
     response.PutCString("thread-pcs");
     char delimiter = ':';
-    for (NativeThreadProtocolSP thread_sp;
-         (thread_sp = m_debugged_process_up->GetThreadAtIndex(i)) != nullptr;
+    for (NativeThreadProtocol *thread;
+         (thread = m_debugged_process_up->GetThreadAtIndex(i)) != nullptr;
          ++i) {
-      NativeRegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
+      NativeRegisterContextSP reg_ctx_sp = thread->GetRegisterContext();
       if (!reg_ctx_sp)
         continue;
 
@@ -739,7 +737,7 @@
   //
 
   // Grab the register context.
-  NativeRegisterContextSP reg_ctx_sp = thread_sp->GetRegisterContext();
+  NativeRegisterContextSP reg_ctx_sp = thread->GetRegisterContext();
   if (reg_ctx_sp) {
     // Expedite all registers in the first register set (i.e. should be GPRs)
     // that are not contained in other registers.
@@ -1316,12 +1314,12 @@
   lldb::tid_t tid = m_debugged_process_up->GetCurrentThreadID();
   SetCurrentThreadID(tid);
 
-  NativeThreadProtocolSP thread_sp = m_debugged_process_up->GetCurrentThread();
-  if (!thread_sp)
+  NativeThreadProtocol *thread = m_debugged_process_up->GetCurrentThread();
+  if (!thread)
     return SendErrorResponse(69);
 
   StreamString response;
-  response.Printf("QC%" PRIx64, thread_sp->GetID());
+  response.Printf("QC%" PRIx64, thread->GetID());
 
   return SendPacketNoLock(response.GetString());
 }
@@ -1692,12 +1690,12 @@
     return SendErrorResponse(68);
 
   // Ensure we have a thread.
-  NativeThreadProtocolSP thread_sp(m_debugged_process_up->GetThreadAtIndex(0));
-  if (!thread_sp)
+  NativeThreadProtocol *thread = m_debugged_process_up->GetThreadAtIndex(0);
+  if (!thread)
     return SendErrorResponse(69);
 
   // Get the register context for the first thread.
-  NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
+  NativeRegisterContextSP reg_context_sp(thread->GetRegisterContext());
   if (!reg_context_sp)
     return SendErrorResponse(69);
 
@@ -1908,18 +1906,17 @@
   response.PutChar('m');
 
   LLDB_LOG(log, "starting thread iteration");
-  NativeThreadProtocolSP thread_sp;
+  NativeThreadProtocol *thread;
   uint32_t thread_index;
   for (thread_index = 0,
-      thread_sp = m_debugged_process_up->GetThreadAtIndex(thread_index);
-       thread_sp; ++thread_index,
-      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);
+      thread = m_debugged_process_up->GetThreadAtIndex(thread_index);
+       thread; ++thread_index,
+      thread = m_debugged_process_up->GetThreadAtIndex(thread_index)) {
+    LLDB_LOG(log, "iterated thread {0}(tid={2})", thread_index,
+             thread->GetID());
     if (thread_index > 0)
       response.PutChar(',');
-    response.Printf("%" PRIx64, thread_sp->GetID());
+    response.Printf("%" PRIx64, thread->GetID());
   }
 
   LLDB_LOG(log, "finished thread iteration");
@@ -1951,22 +1948,19 @@
   }
 
   // Get the thread to use.
-  NativeThreadProtocolSP thread_sp = GetThreadFromSuffix(packet);
-  if (!thread_sp) {
-    if (log)
-      log->Printf(
-          "GDBRemoteCommunicationServerLLGS::%s failed, no thread available",
-          __FUNCTION__);
+  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
+  if (!thread) {
+    LLDB_LOG(log, "failed, no thread available");
     return SendErrorResponse(0x15);
   }
 
   // Get the thread's register context.
-  NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
+  NativeRegisterContextSP reg_context_sp(thread->GetRegisterContext());
   if (!reg_context_sp) {
     LLDB_LOG(
         log,
         "pid {0} tid {1} failed, no register context available for the thread",
-        m_debugged_process_up->GetID(), thread_sp->GetID());
+        m_debugged_process_up->GetID(), thread->GetID());
     return SendErrorResponse(0x15);
   }
 
@@ -2063,23 +2057,23 @@
   size_t reg_size = packet.GetHexBytesAvail(reg_bytes);
 
   // Get the thread to use.
-  NativeThreadProtocolSP thread_sp = GetThreadFromSuffix(packet);
-  if (!thread_sp) {
+  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
+  if (!thread) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, no thread "
                   "available (thread index 0)",
                   __FUNCTION__);
     return SendErrorResponse(0x28);
   }
 
   // Get the thread's register context.
-  NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
+  NativeRegisterContextSP reg_context_sp(thread->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_up->GetID(), thread_sp->GetID());
+          __FUNCTION__, m_debugged_process_up->GetID(), thread->GetID());
     return SendErrorResponse(0x15);
   }
 
@@ -2177,8 +2171,8 @@
   // 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_up->GetThreadByID(tid));
-    if (!thread_sp) {
+    NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid);
+    if (!thread) {
       if (log)
         log->Printf("GDBRemoteCommunicationServerLLGS::%s failed, tid %" PRIu64
                     " not found",
@@ -2739,8 +2733,8 @@
 
   // 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_up->GetThreadByID(tid);
-  if (!thread_sp || thread_sp->GetID() != tid)
+  NativeThreadProtocol *thread = m_debugged_process_up->GetThreadByID(tid);
+  if (!thread)
     return SendErrorResponse(0x33);
 
   // Create the step action for the given thread.
@@ -2865,8 +2859,8 @@
   packet.SetFilePos(strlen("QSaveRegisterState"));
 
   // Get the thread to use.
-  NativeThreadProtocolSP thread_sp = GetThreadFromSuffix(packet);
-  if (!thread_sp) {
+  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
+  if (!thread) {
     if (m_thread_suffix_supported)
       return SendIllFormedResponse(
           packet, "No thread specified in QSaveRegisterState packet");
@@ -2876,12 +2870,12 @@
   }
 
   // Grab the register context for the thread.
-  NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
+  NativeRegisterContextSP reg_context_sp(thread->GetRegisterContext());
   if (!reg_context_sp) {
     LLDB_LOG(
         log,
         "pid {0} tid {1} failed, no register context available for the thread",
-        m_debugged_process_up->GetID(), thread_sp->GetID());
+        m_debugged_process_up->GetID(), thread->GetID());
     return SendErrorResponse(0x15);
   }
 
@@ -2930,8 +2924,8 @@
   }
 
   // Get the thread to use.
-  NativeThreadProtocolSP thread_sp = GetThreadFromSuffix(packet);
-  if (!thread_sp) {
+  NativeThreadProtocol *thread = GetThreadFromSuffix(packet);
+  if (!thread) {
     if (m_thread_suffix_supported)
       return SendIllFormedResponse(
           packet, "No thread specified in QRestoreRegisterState packet");
@@ -2941,12 +2935,12 @@
   }
 
   // Grab the register context for the thread.
-  NativeRegisterContextSP reg_context_sp(thread_sp->GetRegisterContext());
+  NativeRegisterContextSP reg_context_sp(thread->GetRegisterContext());
   if (!reg_context_sp) {
     LLDB_LOG(
         log,
         "pid {0} tid {1} failed, no register context available for the thread",
-        m_debugged_process_up->GetID(), thread_sp->GetID());
+        m_debugged_process_up->GetID(), thread->GetID());
     return SendErrorResponse(0x15);
   }
 
@@ -3219,22 +3213,20 @@
   }
 }
 
-NativeThreadProtocolSP GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
+NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
     StringExtractorGDBRemote &packet) {
-  NativeThreadProtocolSP thread_sp;
-
   // We have no thread if we don't have a process.
   if (!m_debugged_process_up ||
       m_debugged_process_up->GetID() == LLDB_INVALID_PROCESS_ID)
-    return thread_sp;
+    return nullptr;
 
   // If the client hasn't asked for thread suffix support, there will not be a
   // thread suffix.
   // Use the current thread in that case.
   if (!m_thread_suffix_supported) {
     const lldb::tid_t current_tid = GetCurrentThreadID();
     if (current_tid == LLDB_INVALID_THREAD_ID)
-      return thread_sp;
+      return nullptr;
     else if (current_tid == 0) {
       // Pick a thread.
       return m_debugged_process_up->GetThreadAtIndex(0);
@@ -3251,27 +3243,27 @@
                   "error: expected ';' prior to start of thread suffix: packet "
                   "contents = '%s'",
                   __FUNCTION__, packet.GetStringRef().c_str());
-    return thread_sp;
+    return nullptr;
   }
 
   if (!packet.GetBytesLeft())
-    return thread_sp;
+    return nullptr;
 
   // Parse out thread: portion.
   if (strncmp(packet.Peek(), "thread:", strlen("thread:")) != 0) {
     if (log)
       log->Printf("GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
                   "error: expected 'thread:' but not found, packet contents = "
                   "'%s'",
                   __FUNCTION__, packet.GetStringRef().c_str());
-    return thread_sp;
+    return nullptr;
   }
   packet.SetFilePos(packet.GetFilePos() + strlen("thread:"));
   const lldb::tid_t tid = packet.GetHexMaxU64(false, 0);
   if (tid != 0)
     return m_debugged_process_up->GetThreadByID(tid);
 
-  return thread_sp;
+  return nullptr;
 }
 
 lldb::tid_t GDBRemoteCommunicationServerLLGS::GetCurrentThreadID() const {
Index: lldb/trunk/source/Host/common/NativeProcessProtocol.cpp
===================================================================
--- lldb/trunk/source/Host/common/NativeProcessProtocol.cpp
+++ lldb/trunk/source/Host/common/NativeProcessProtocol.cpp
@@ -90,23 +90,23 @@
   return true;
 }
 
-NativeThreadProtocolSP NativeProcessProtocol::GetThreadAtIndex(uint32_t idx) {
+NativeThreadProtocol *NativeProcessProtocol::GetThreadAtIndex(uint32_t idx) {
   std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
   if (idx < m_threads.size())
-    return m_threads[idx];
-  return NativeThreadProtocolSP();
+    return m_threads[idx].get();
+  return nullptr;
 }
 
-NativeThreadProtocolSP
+NativeThreadProtocol *
 NativeProcessProtocol::GetThreadByIDUnlocked(lldb::tid_t tid) {
-  for (auto thread_sp : m_threads) {
-    if (thread_sp->GetID() == tid)
-      return thread_sp;
+  for (const auto &thread : m_threads) {
+    if (thread->GetID() == tid)
+      return thread.get();
   }
-  return NativeThreadProtocolSP();
+  return nullptr;
 }
 
-NativeThreadProtocolSP NativeProcessProtocol::GetThreadByID(lldb::tid_t tid) {
+NativeThreadProtocol *NativeProcessProtocol::GetThreadByID(lldb::tid_t tid) {
   std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
   return GetThreadByIDUnlocked(tid);
 }
@@ -134,22 +134,18 @@
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
 
   // get any thread
-  NativeThreadProtocolSP thread_sp(
+  NativeThreadProtocol *thread(
       const_cast<NativeProcessProtocol *>(this)->GetThreadAtIndex(0));
-  if (!thread_sp) {
-    if (log)
-      log->Warning("NativeProcessProtocol::%s (): failed to find a thread to "
-                   "grab a NativeRegisterContext!",
-                   __FUNCTION__);
+  if (!thread) {
+    LLDB_LOG(log, "failed to find a thread to grab a NativeRegisterContext!");
     return llvm::None;
   }
 
-  NativeRegisterContextSP reg_ctx_sp(thread_sp->GetRegisterContext());
+  NativeRegisterContextSP reg_ctx_sp(thread->GetRegisterContext());
   if (!reg_ctx_sp) {
-    if (log)
-      log->Warning("NativeProcessProtocol::%s (): failed to get a "
-                   "RegisterContextNativeProcess from the first thread!",
-                   __FUNCTION__);
+    LLDB_LOG(
+        log,
+        "failed to get a RegisterContextNativeProcess from the first thread!");
     return llvm::None;
   }
 
@@ -175,49 +171,42 @@
   // for.  If one of the thread watchpoint setting operations fails,
   // back off and remove the watchpoint for all the threads that
   // were successfully set so we get back to a consistent state.
-  std::vector<NativeThreadProtocolSP> watchpoint_established_threads;
+  std::vector<NativeThreadProtocol *> watchpoint_established_threads;
 
   // Tell each thread to set a watchpoint.  In the event that
   // hardware watchpoints are requested but the SetWatchpoint fails,
   // try to set a software watchpoint as a fallback.  It's
   // conceivable that if there are more threads than hardware
   // watchpoints available, some of the threads will fail to set
   // hardware watchpoints while software ones may be available.
   std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
-  for (auto thread_sp : m_threads) {
-    assert(thread_sp && "thread list should not have a NULL thread!");
-    if (!thread_sp)
-      continue;
+  for (const auto &thread : m_threads) {
+    assert(thread && "thread list should not have a NULL thread!");
 
     Status thread_error =
-        thread_sp->SetWatchpoint(addr, size, watch_flags, hardware);
+        thread->SetWatchpoint(addr, size, watch_flags, hardware);
     if (thread_error.Fail() && hardware) {
       // Try software watchpoints since we failed on hardware watchpoint setting
       // and we may have just run out of hardware watchpoints.
-      thread_error = thread_sp->SetWatchpoint(addr, size, watch_flags, false);
-      if (thread_error.Success()) {
-        if (log)
-          log->Warning(
-              "hardware watchpoint requested but software watchpoint set");
-      }
+      thread_error = thread->SetWatchpoint(addr, size, watch_flags, false);
+      if (thread_error.Success())
+        LLDB_LOG(log,
+                 "hardware watchpoint requested but software watchpoint set");
     }
 
     if (thread_error.Success()) {
       // Remember that we set this watchpoint successfully in
       // case we need to clear it later.
-      watchpoint_established_threads.push_back(thread_sp);
+      watchpoint_established_threads.push_back(thread.get());
     } else {
       // Unset the watchpoint for each thread we successfully
       // set so that we get back to a consistent state of "not
       // set" for the watchpoint.
       for (auto unwatch_thread_sp : watchpoint_established_threads) {
         Status remove_error = unwatch_thread_sp->RemoveWatchpoint(addr);
-        if (remove_error.Fail() && log) {
-          log->Warning("NativeProcessProtocol::%s (): RemoveWatchpoint failed "
-                       "for pid=%" PRIu64 ", tid=%" PRIu64 ": %s",
-                       __FUNCTION__, GetID(), unwatch_thread_sp->GetID(),
-                       remove_error.AsCString());
-        }
+        if (remove_error.Fail())
+          LLDB_LOG(log, "RemoveWatchpoint failed for pid={0}, tid={1}: {2}",
+                   GetID(), unwatch_thread_sp->GetID(), remove_error);
       }
 
       return thread_error;
@@ -233,12 +222,10 @@
   Status overall_error;
 
   std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
-  for (auto thread_sp : m_threads) {
-    assert(thread_sp && "thread list should not have a NULL thread!");
-    if (!thread_sp)
-      continue;
+  for (const auto &thread : m_threads) {
+    assert(thread && "thread list should not have a NULL thread!");
 
-    const Status thread_error = thread_sp->RemoveWatchpoint(addr);
+    const Status thread_error = thread->RemoveWatchpoint(addr);
     if (thread_error.Fail()) {
       // Keep track of the first thread error if any threads
       // fail. We want to try to remove the watchpoint from
@@ -277,33 +264,29 @@
   // set this hardware breakpoint. If any of the current process threads fails
   // to set this hardware breakpoint then roll back and remove this breakpoint
   // for all the threads that had already set it successfully.
-  std::vector<NativeThreadProtocolSP> breakpoint_established_threads;
+  std::vector<NativeThreadProtocol *> breakpoint_established_threads;
 
   // Request to set a hardware breakpoint for each of current process threads.
   std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
-  for (auto thread_sp : m_threads) {
-    assert(thread_sp && "thread list should not have a NULL thread!");
-    if (!thread_sp)
-      continue;
+  for (const auto &thread : m_threads) {
+    assert(thread && "thread list should not have a NULL thread!");
 
-    Status thread_error = thread_sp->SetHardwareBreakpoint(addr, size);
+    Status thread_error = thread->SetHardwareBreakpoint(addr, size);
     if (thread_error.Success()) {
       // Remember that we set this breakpoint successfully in
       // case we need to clear it later.
-      breakpoint_established_threads.push_back(thread_sp);
+      breakpoint_established_threads.push_back(thread.get());
     } else {
       // Unset the breakpoint for each thread we successfully
       // set so that we get back to a consistent state of "not
       // set" for this hardware breakpoint.
       for (auto rollback_thread_sp : breakpoint_established_threads) {
         Status remove_error =
             rollback_thread_sp->RemoveHardwareBreakpoint(addr);
-        if (remove_error.Fail() && log) {
-          log->Warning("NativeProcessProtocol::%s (): RemoveHardwareBreakpoint"
-                       " failed for pid=%" PRIu64 ", tid=%" PRIu64 ": %s",
-                       __FUNCTION__, GetID(), rollback_thread_sp->GetID(),
-                       remove_error.AsCString());
-        }
+        if (remove_error.Fail())
+          LLDB_LOG(log,
+                   "RemoveHardwareBreakpoint failed for pid={0}, tid={1}: {2}",
+                   GetID(), rollback_thread_sp->GetID(), remove_error);
       }
 
       return thread_error;
@@ -324,12 +307,9 @@
   Status error;
 
   std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
-  for (auto thread_sp : m_threads) {
-    assert(thread_sp && "thread list should not have a NULL thread!");
-    if (!thread_sp)
-      continue;
-
-    error = thread_sp->RemoveHardwareBreakpoint(addr);
+  for (const auto &thread : m_threads) {
+    assert(thread && "thread list should not have a NULL thread!");
+    error = thread->RemoveHardwareBreakpoint(addr);
   }
 
   // Also remove from hardware breakpoint map of current process.
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
@@ -20,8 +20,7 @@
 //------------------------------------------------------------------
 // NativeThreadProtocol
 //------------------------------------------------------------------
-class NativeThreadProtocol
-    : public std::enable_shared_from_this<NativeThreadProtocol> {
+class NativeThreadProtocol {
 public:
   NativeThreadProtocol(NativeProcessProtocol &process, lldb::tid_t tid);
 
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
@@ -10,6 +10,9 @@
 #ifndef liblldb_NativeProcessProtocol_h_
 #define liblldb_NativeProcessProtocol_h_
 
+#include "NativeBreakpointList.h"
+#include "NativeThreadProtocol.h"
+#include "NativeWatchpointList.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/MainLoop.h"
 #include "lldb/Utility/Status.h"
@@ -23,9 +26,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include <vector>
 
-#include "NativeBreakpointList.h"
-#include "NativeWatchpointList.h"
-
 namespace lldb_private {
 class MemoryRegionInfo;
 class ResumeActionList;
@@ -166,15 +166,15 @@
   //----------------------------------------------------------------------
   // Access to threads
   //----------------------------------------------------------------------
-  NativeThreadProtocolSP GetThreadAtIndex(uint32_t idx);
+  NativeThreadProtocol *GetThreadAtIndex(uint32_t idx);
 
-  NativeThreadProtocolSP GetThreadByID(lldb::tid_t tid);
+  NativeThreadProtocol *GetThreadByID(lldb::tid_t tid);
 
   void SetCurrentThreadID(lldb::tid_t tid) { m_current_thread_id = tid; }
 
   lldb::tid_t GetCurrentThreadID() { return m_current_thread_id; }
 
-  NativeThreadProtocolSP GetCurrentThread() {
+  NativeThreadProtocol *GetCurrentThread() {
     return GetThreadByID(m_current_thread_id);
   }
 
@@ -401,7 +401,7 @@
 protected:
   lldb::pid_t m_pid;
 
-  std::vector<NativeThreadProtocolSP> m_threads;
+  std::vector<std::unique_ptr<NativeThreadProtocol>> m_threads;
   lldb::tid_t m_current_thread_id = LLDB_INVALID_THREAD_ID;
   mutable std::recursive_mutex m_threads_mutex;
 
@@ -461,7 +461,7 @@
   // -----------------------------------------------------------
   void NotifyDidExec();
 
-  NativeThreadProtocolSP GetThreadByIDUnlocked(lldb::tid_t tid);
+  NativeThreadProtocol *GetThreadByIDUnlocked(lldb::tid_t tid);
 
   // -----------------------------------------------------------
   // Static helper methods for derived classes.
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
@@ -32,8 +32,6 @@
 typedef std::shared_ptr<NativeBreakpoint> NativeBreakpointSP;
 typedef std::shared_ptr<lldb_private::NativeRegisterContext>
     NativeRegisterContextSP;
-typedef std::shared_ptr<lldb_private::NativeThreadProtocol>
-    NativeThreadProtocolSP;
 }
 
 #endif // #if defined(__cplusplus)
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to