1 //===-- ThreadMemory.cpp ----------------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #include "Plugins/Process/Utility/ThreadMemory.h"
12 #include "Plugins/Process/Utility/RegisterContextThreadMemory.h"
13 #include "lldb/Target/OperatingSystem.h"
14 #include "lldb/Target/Process.h"
15 #include "lldb/Target/RegisterContext.h"
16 #include "lldb/Target/StopInfo.h"
17 #include "lldb/Target/Unwind.h"
20 using namespace lldb_private;
22 ThreadMemory::ThreadMemory(Process &process, tid_t tid,
23 const ValueObjectSP &thread_info_valobj_sp)
24 : Thread(process, tid), m_backing_thread_sp(),
25 m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue() {}
27 ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid, const char *name,
28 const char *queue, lldb::addr_t register_data_addr)
29 : Thread(process, tid), m_backing_thread_sp(), m_thread_info_valobj_sp(),
30 m_name(), m_queue(), m_register_data_addr(register_data_addr) {
37 ThreadMemory::~ThreadMemory() { DestroyThread(); }
39 void ThreadMemory::WillResume(StateType resume_state) {
40 if (m_backing_thread_sp)
41 m_backing_thread_sp->WillResume(resume_state);
44 void ThreadMemory::ClearStackFrames() {
45 if (m_backing_thread_sp)
46 m_backing_thread_sp->ClearStackFrames();
47 Thread::ClearStackFrames();
50 RegisterContextSP ThreadMemory::GetRegisterContext() {
51 if (!m_reg_context_sp)
52 m_reg_context_sp.reset(
53 new RegisterContextThreadMemory(*this, m_register_data_addr));
54 return m_reg_context_sp;
58 ThreadMemory::CreateRegisterContextForFrame(StackFrame *frame) {
59 RegisterContextSP reg_ctx_sp;
60 uint32_t concrete_frame_idx = 0;
63 concrete_frame_idx = frame->GetConcreteFrameIndex();
65 if (concrete_frame_idx == 0) {
66 reg_ctx_sp = GetRegisterContext();
68 Unwind *unwinder = GetUnwinder();
70 reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
75 bool ThreadMemory::CalculateStopInfo() {
76 if (m_backing_thread_sp) {
77 lldb::StopInfoSP backing_stop_info_sp(
78 m_backing_thread_sp->GetPrivateStopInfo());
79 if (backing_stop_info_sp &&
80 backing_stop_info_sp->IsValidForOperatingSystemThread(*this)) {
81 backing_stop_info_sp->SetThread(shared_from_this());
82 SetStopInfo(backing_stop_info_sp);
86 ProcessSP process_sp(GetProcess());
89 OperatingSystem *os = process_sp->GetOperatingSystem();
91 SetStopInfo(os->CreateThreadStopReason(this));
99 void ThreadMemory::RefreshStateAfterStop() {
100 if (m_backing_thread_sp)
101 return m_backing_thread_sp->RefreshStateAfterStop();
103 if (m_reg_context_sp)
104 m_reg_context_sp->InvalidateAllRegisters();