Remove shared pointer from NativeProcessProtocol
Summary:
The usage of shared_from_this forces us to separate construction and
initialization phases, because shared_from_this() is not available in
the constructor (or destructor). The shared semantics are not necessary,
as we always have a clear owner of the native process class
(GDBRemoteCommunicationServerLLDB object). Even if we need shared
semantics in the future (which I think we should strongly avoid),
reverting this will not be necessary -- the owners can still easily
store the native process object in a shared pointer if they really want
to -- this just prevents the knowledge of that from leaking into the
class implementation.
After this a NativeThread object will hold a reference to the parent
process (instead of a weak_ptr) -- having a process instance always
available allows us to simplify some logic in this class (some of it was
already simplified because we were asserting that the process is
available, but this makes it obvious).
Reviewers: krytarowski, eugene, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D35123
llvm-svn: 308282
diff --git a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
index b1d1366..5cd4094 100644
--- a/lldb/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ b/lldb/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);
}