]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/Process/Utility/ThreadMemory.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / Plugins / Process / Utility / ThreadMemory.cpp
1 //===-- ThreadMemory.cpp ----------------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
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"
18
19 using namespace lldb;
20 using namespace lldb_private;
21
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() {}
26
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) {
31   if (name)
32     m_name = name;
33   if (queue)
34     m_queue = queue;
35 }
36
37 ThreadMemory::~ThreadMemory() { DestroyThread(); }
38
39 void ThreadMemory::WillResume(StateType resume_state) {
40   if (m_backing_thread_sp)
41     m_backing_thread_sp->WillResume(resume_state);
42 }
43
44 void ThreadMemory::ClearStackFrames() {
45   if (m_backing_thread_sp)
46     m_backing_thread_sp->ClearStackFrames();
47   Thread::ClearStackFrames();
48 }
49
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;
55 }
56
57 RegisterContextSP
58 ThreadMemory::CreateRegisterContextForFrame(StackFrame *frame) {
59   RegisterContextSP reg_ctx_sp;
60   uint32_t concrete_frame_idx = 0;
61
62   if (frame)
63     concrete_frame_idx = frame->GetConcreteFrameIndex();
64
65   if (concrete_frame_idx == 0) {
66     reg_ctx_sp = GetRegisterContext();
67   } else {
68     Unwind *unwinder = GetUnwinder();
69     if (unwinder)
70       reg_ctx_sp = unwinder->CreateRegisterContextForFrame(frame);
71   }
72   return reg_ctx_sp;
73 }
74
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);
83       return true;
84     }
85   } else {
86     ProcessSP process_sp(GetProcess());
87
88     if (process_sp) {
89       OperatingSystem *os = process_sp->GetOperatingSystem();
90       if (os) {
91         SetStopInfo(os->CreateThreadStopReason(this));
92         return true;
93       }
94     }
95   }
96   return false;
97 }
98
99 void ThreadMemory::RefreshStateAfterStop() {
100   if (m_backing_thread_sp)
101     return m_backing_thread_sp->RefreshStateAfterStop();
102
103   if (m_reg_context_sp)
104     m_reg_context_sp->InvalidateAllRegisters();
105 }