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,
28 llvm::StringRef name, llvm::StringRef queue,
29 lldb::addr_t register_data_addr)
30 : Thread(process, tid), m_backing_thread_sp(), m_thread_info_valobj_sp(),
31 m_name(name), m_queue(queue), m_register_data_addr(register_data_addr) {}
33 ThreadMemory::~ThreadMemory() { DestroyThread(); }
35 void ThreadMemory::WillResume(StateType resume_state) {
36 if (m_backing_thread_sp)
37 m_backing_thread_sp->WillResume(resume_state);
40 void ThreadMemory::ClearStackFrames() {
41 if (m_backing_thread_sp)
42 m_backing_thread_sp->ClearStackFrames();
43 Thread::ClearStackFrames();
46 RegisterContextSP ThreadMemory::GetRegisterContext() {
47 if (!m_reg_context_sp)
48 m_reg_context_sp.reset(
49 new RegisterContextThreadMemory(*this, m_register_data_addr));
50 return m_reg_context_sp;
54 ThreadMemory::CreateRegisterContextForFrame(StackFrame *frame) {
55 RegisterContextSP reg_ctx_sp;
56 uint32_t concrete_frame_idx = 0;
59 concrete_frame_idx = frame->GetConcreteFrameIndex();
61 if (concrete_frame_idx == 0) {
62 reg_ctx_sp = GetRegisterContext();
64 Unwind *unwinder = GetUnwinder();
65 if (unwinder != nullptr)
66 reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
71 bool ThreadMemory::CalculateStopInfo() {
72 if (m_backing_thread_sp) {
73 lldb::StopInfoSP backing_stop_info_sp(
74 m_backing_thread_sp->GetPrivateStopInfo());
75 if (backing_stop_info_sp &&
76 backing_stop_info_sp->IsValidForOperatingSystemThread(*this)) {
77 backing_stop_info_sp->SetThread(shared_from_this());
78 SetStopInfo(backing_stop_info_sp);
82 ProcessSP process_sp(GetProcess());
85 OperatingSystem *os = process_sp->GetOperatingSystem();
87 SetStopInfo(os->CreateThreadStopReason(this));
95 void ThreadMemory::RefreshStateAfterStop() {
96 if (m_backing_thread_sp)
97 return m_backing_thread_sp->RefreshStateAfterStop();
100 m_reg_context_sp->InvalidateAllRegisters();