2011-08-22 10:49:39 +08:00
|
|
|
//===-- ThreadMemory.cpp ----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Plugins/Process/Utility/ThreadMemory.h"
|
|
|
|
#include "lldb/Target/OperatingSystem.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/StopInfo.h"
|
|
|
|
#include "lldb/Target/Unwind.h"
|
2013-05-02 05:54:04 +08:00
|
|
|
#include "Plugins/Process/Utility/RegisterContextThreadMemory.h"
|
2011-08-22 10:49:39 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
ThreadMemory::ThreadMemory (Process &process,
|
2012-10-26 01:56:31 +08:00
|
|
|
tid_t tid,
|
|
|
|
const ValueObjectSP &thread_info_valobj_sp) :
|
2012-10-11 02:32:14 +08:00
|
|
|
Thread (process, tid),
|
2013-04-13 04:07:46 +08:00
|
|
|
m_backing_thread_sp (),
|
2012-08-24 13:45:15 +08:00
|
|
|
m_thread_info_valobj_sp (thread_info_valobj_sp),
|
|
|
|
m_name(),
|
|
|
|
m_queue()
|
2011-08-22 10:49:39 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
ThreadMemory::ThreadMemory (Process &process,
|
2012-08-24 13:45:15 +08:00
|
|
|
lldb::tid_t tid,
|
|
|
|
const char *name,
|
2012-10-26 01:56:31 +08:00
|
|
|
const char *queue,
|
|
|
|
lldb::addr_t register_data_addr) :
|
2012-10-11 02:32:14 +08:00
|
|
|
Thread (process, tid),
|
2013-04-13 04:07:46 +08:00
|
|
|
m_backing_thread_sp (),
|
2012-08-24 13:45:15 +08:00
|
|
|
m_thread_info_valobj_sp (),
|
|
|
|
m_name(),
|
2012-10-26 01:56:31 +08:00
|
|
|
m_queue(),
|
|
|
|
m_register_data_addr (register_data_addr)
|
2012-08-24 13:45:15 +08:00
|
|
|
{
|
|
|
|
if (name)
|
|
|
|
m_name = name;
|
|
|
|
if (queue)
|
|
|
|
m_queue = queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-22 10:49:39 +08:00
|
|
|
ThreadMemory::~ThreadMemory()
|
|
|
|
{
|
|
|
|
DestroyThread();
|
|
|
|
}
|
|
|
|
|
2013-05-02 05:54:04 +08:00
|
|
|
void
|
2011-08-22 10:49:39 +08:00
|
|
|
ThreadMemory::WillResume (StateType resume_state)
|
|
|
|
{
|
2013-05-02 05:54:04 +08:00
|
|
|
if (m_backing_thread_sp)
|
|
|
|
m_backing_thread_sp->WillResume(resume_state);
|
|
|
|
}
|
2013-04-20 08:27:58 +08:00
|
|
|
|
2013-05-02 05:54:04 +08:00
|
|
|
void
|
|
|
|
ThreadMemory::ClearStackFrames ()
|
|
|
|
{
|
2013-04-20 08:27:58 +08:00
|
|
|
if (m_backing_thread_sp)
|
2013-05-02 05:54:04 +08:00
|
|
|
m_backing_thread_sp->ClearStackFrames();
|
|
|
|
Thread::ClearStackFrames();
|
2011-08-22 10:49:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RegisterContextSP
|
|
|
|
ThreadMemory::GetRegisterContext ()
|
|
|
|
{
|
|
|
|
if (!m_reg_context_sp)
|
2013-05-02 05:54:04 +08:00
|
|
|
m_reg_context_sp.reset (new RegisterContextThreadMemory (*this, m_register_data_addr));
|
2011-08-22 10:49:39 +08:00
|
|
|
return m_reg_context_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegisterContextSP
|
2013-11-04 17:33:30 +08:00
|
|
|
ThreadMemory::CreateRegisterContextForFrame (StackFrame *frame)
|
2011-08-22 10:49:39 +08:00
|
|
|
{
|
|
|
|
RegisterContextSP reg_ctx_sp;
|
|
|
|
uint32_t concrete_frame_idx = 0;
|
|
|
|
|
|
|
|
if (frame)
|
|
|
|
concrete_frame_idx = frame->GetConcreteFrameIndex ();
|
|
|
|
|
|
|
|
if (concrete_frame_idx == 0)
|
|
|
|
{
|
|
|
|
reg_ctx_sp = GetRegisterContext ();
|
|
|
|
}
|
2013-04-13 04:07:46 +08:00
|
|
|
else
|
2011-08-22 10:49:39 +08:00
|
|
|
{
|
2013-04-13 04:07:46 +08:00
|
|
|
Unwind *unwinder = GetUnwinder ();
|
|
|
|
if (unwinder)
|
|
|
|
reg_ctx_sp = unwinder->CreateRegisterContextForFrame (frame);
|
2011-08-22 10:49:39 +08:00
|
|
|
}
|
|
|
|
return reg_ctx_sp;
|
|
|
|
}
|
|
|
|
|
2013-05-09 09:55:29 +08:00
|
|
|
bool
|
|
|
|
ThreadMemory::CalculateStopInfo ()
|
2011-08-22 10:49:39 +08:00
|
|
|
{
|
2013-04-13 04:07:46 +08:00
|
|
|
if (m_backing_thread_sp)
|
2013-05-02 05:54:04 +08:00
|
|
|
{
|
2013-05-09 09:55:29 +08:00
|
|
|
lldb::StopInfoSP backing_stop_info_sp (m_backing_thread_sp->GetPrivateStopInfo());
|
2015-04-08 06:17:41 +08:00
|
|
|
if (backing_stop_info_sp && backing_stop_info_sp->IsValidForOperatingSystemThread(*this))
|
2013-05-02 05:54:04 +08:00
|
|
|
{
|
2013-05-09 09:55:29 +08:00
|
|
|
backing_stop_info_sp->SetThread (shared_from_this());
|
|
|
|
SetStopInfo (backing_stop_info_sp);
|
|
|
|
return true;
|
2013-05-02 05:54:04 +08:00
|
|
|
}
|
|
|
|
}
|
2013-05-09 09:55:29 +08:00
|
|
|
else
|
2011-08-22 10:49:39 +08:00
|
|
|
{
|
2013-05-09 09:55:29 +08:00
|
|
|
ProcessSP process_sp (GetProcess());
|
2012-10-16 08:09:33 +08:00
|
|
|
|
2013-05-09 09:55:29 +08:00
|
|
|
if (process_sp)
|
|
|
|
{
|
2012-02-21 08:09:25 +08:00
|
|
|
OperatingSystem *os = process_sp->GetOperatingSystem ();
|
|
|
|
if (os)
|
2013-05-09 09:55:29 +08:00
|
|
|
{
|
|
|
|
SetStopInfo (os->CreateThreadStopReason (this));
|
|
|
|
return true;
|
|
|
|
}
|
2012-02-21 08:09:25 +08:00
|
|
|
}
|
2011-08-22 10:49:39 +08:00
|
|
|
}
|
2013-05-09 09:55:29 +08:00
|
|
|
return false;
|
2011-08-22 10:49:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThreadMemory::RefreshStateAfterStop()
|
|
|
|
{
|
2013-04-13 04:07:46 +08:00
|
|
|
if (m_backing_thread_sp)
|
|
|
|
return m_backing_thread_sp->RefreshStateAfterStop();
|
2013-05-09 09:55:29 +08:00
|
|
|
|
|
|
|
if (m_reg_context_sp)
|
|
|
|
m_reg_context_sp->InvalidateAllRegisters();
|
2011-08-22 10:49:39 +08:00
|
|
|
}
|