Change ProcessEventData over to use a std::weak_ptr to a process intead of a std::shared_ptr. Anyone consuming events for a process should have the process around long enough to grab the event and anyone that holds onto an event for too long won't keep the process around.

llvm-svn: 238541
This commit is contained in:
Greg Clayton 2015-05-29 03:20:37 +00:00
parent 27a6cfd823
commit aeb3b8b1c0
2 changed files with 25 additions and 13 deletions

View File

@ -818,11 +818,12 @@ public:
virtual const ConstString &
GetFlavor () const;
const lldb::ProcessSP &
lldb::ProcessSP
GetProcessSP() const
{
return m_process_sp;
return m_process_wp.lock();
}
lldb::StateType
GetState() const
{
@ -917,7 +918,7 @@ public:
m_restarted_reasons.push_back(reason);
}
lldb::ProcessSP m_process_sp;
lldb::ProcessWP m_process_wp;
lldb::StateType m_state;
std::vector<std::string> m_restarted_reasons;
bool m_restarted; // For "eStateStopped" events, this is true if the target was automatically restarted.

View File

@ -4646,7 +4646,7 @@ Process::RunPrivateStateThread ()
Process::ProcessEventData::ProcessEventData () :
EventData (),
m_process_sp (),
m_process_wp (),
m_state (eStateInvalid),
m_restarted (false),
m_update_state (0),
@ -4656,12 +4656,14 @@ Process::ProcessEventData::ProcessEventData () :
Process::ProcessEventData::ProcessEventData (const ProcessSP &process_sp, StateType state) :
EventData (),
m_process_sp (process_sp),
m_process_wp (),
m_state (state),
m_restarted (false),
m_update_state (0),
m_interrupted (false)
{
if (process_sp)
m_process_wp = process_sp;
}
Process::ProcessEventData::~ProcessEventData()
@ -4684,6 +4686,11 @@ Process::ProcessEventData::GetFlavor () const
void
Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
{
ProcessSP process_sp(m_process_wp.lock());
if (!process_sp)
return;
// This function gets called twice for each event, once when the event gets pulled
// off of the private process event queue, and then any number of times, first when it gets pulled off of
// the public event queue, then other times when we're pretending that this is where we stopped at the
@ -4693,7 +4700,7 @@ Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
if (m_update_state != 1)
return;
m_process_sp->SetPublicState (m_state, Process::ProcessEventData::GetRestartedFromEvent(event_ptr));
process_sp->SetPublicState (m_state, Process::ProcessEventData::GetRestartedFromEvent(event_ptr));
// If this is a halt event, even if the halt stopped with some reason other than a plain interrupt (e.g. we had
// already stopped for a breakpoint when the halt request came through) don't do the StopInfo actions, as they may
@ -4704,7 +4711,7 @@ Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
// If we're stopped and haven't restarted, then do the StopInfo actions here:
if (m_state == eStateStopped && ! m_restarted)
{
ThreadList &curr_thread_list = m_process_sp->GetThreadList();
ThreadList &curr_thread_list = process_sp->GetThreadList();
uint32_t num_threads = curr_thread_list.GetSize();
uint32_t idx;
@ -4734,7 +4741,7 @@ Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
for (idx = 0; idx < num_threads; ++idx)
{
curr_thread_list = m_process_sp->GetThreadList();
curr_thread_list = process_sp->GetThreadList();
if (curr_thread_list.GetSize() != num_threads)
{
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_STEP | LIBLLDB_LOG_PROCESS));
@ -4797,14 +4804,14 @@ Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
SetRestarted(true);
// Use the public resume method here, since this is just
// extending a public resume.
m_process_sp->PrivateResume();
process_sp->PrivateResume();
}
else
{
// If we didn't restart, run the Stop Hooks here:
// They might also restart the target, so watch for that.
m_process_sp->GetTarget().RunStopHooks();
if (m_process_sp->GetPrivateState() == eStateRunning)
process_sp->GetTarget().RunStopHooks();
if (process_sp->GetPrivateState() == eStateRunning)
SetRestarted(true);
}
}
@ -4814,9 +4821,13 @@ Process::ProcessEventData::DoOnRemoval (Event *event_ptr)
void
Process::ProcessEventData::Dump (Stream *s) const
{
if (m_process_sp)
ProcessSP process_sp(m_process_wp.lock());
if (process_sp)
s->Printf(" process = %p (pid = %" PRIu64 "), ",
static_cast<void*>(m_process_sp.get()), m_process_sp->GetID());
static_cast<void*>(process_sp.get()), process_sp->GetID());
else
s->PutCString(" process = NULL, ");
s->Printf("state = %s", StateAsCString(GetState()));
}