]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/Utility/ThreadMemory.cpp
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / lldb / source / Plugins / Process / Utility / ThreadMemory.cpp
1 //===-- ThreadMemory.cpp ----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "Plugins/Process/Utility/ThreadMemory.h"
11 #include "lldb/Target/OperatingSystem.h"
12 #include "lldb/Target/RegisterContext.h"
13 #include "lldb/Target/Process.h"
14 #include "lldb/Target/StopInfo.h"
15 #include "lldb/Target/Unwind.h"
16 #include "Plugins/Process/Utility/RegisterContextThreadMemory.h"
17
18 using namespace lldb;
19 using namespace lldb_private;
20
21 ThreadMemory::ThreadMemory (Process &process,
22                             tid_t tid,
23                             const ValueObjectSP &thread_info_valobj_sp) :
24     Thread (process, tid),
25     m_backing_thread_sp (),
26     m_thread_info_valobj_sp (thread_info_valobj_sp),
27     m_name(),
28     m_queue()
29 {
30 }
31
32
33 ThreadMemory::ThreadMemory (Process &process,
34                             lldb::tid_t tid,
35                             const char *name,
36                             const char *queue,
37                             lldb::addr_t register_data_addr) :
38     Thread (process, tid),
39     m_backing_thread_sp (),
40     m_thread_info_valobj_sp (),
41     m_name(),
42     m_queue(),
43     m_register_data_addr (register_data_addr)
44 {
45     if (name)
46         m_name = name;
47     if (queue)
48         m_queue = queue;
49 }
50
51
52 ThreadMemory::~ThreadMemory()
53 {
54     DestroyThread();
55 }
56
57 void
58 ThreadMemory::WillResume (StateType resume_state)
59 {
60     if (m_backing_thread_sp)
61         m_backing_thread_sp->WillResume(resume_state);
62 }
63
64 void
65 ThreadMemory::ClearStackFrames ()
66 {
67     if (m_backing_thread_sp)
68         m_backing_thread_sp->ClearStackFrames();
69     Thread::ClearStackFrames();
70 }
71
72 RegisterContextSP
73 ThreadMemory::GetRegisterContext ()
74 {
75     if (!m_reg_context_sp)
76         m_reg_context_sp.reset (new RegisterContextThreadMemory (*this, m_register_data_addr));
77     return m_reg_context_sp;
78 }
79
80 RegisterContextSP
81 ThreadMemory::CreateRegisterContextForFrame (StackFrame *frame)
82 {
83     RegisterContextSP reg_ctx_sp;
84     uint32_t concrete_frame_idx = 0;
85     
86     if (frame)
87         concrete_frame_idx = frame->GetConcreteFrameIndex ();
88     
89     if (concrete_frame_idx == 0)
90     {
91         reg_ctx_sp = GetRegisterContext ();
92     }
93     else
94     {
95         Unwind *unwinder = GetUnwinder ();
96         if (unwinder)
97             reg_ctx_sp = unwinder->CreateRegisterContextForFrame (frame);
98     }
99     return reg_ctx_sp;
100 }
101
102 bool
103 ThreadMemory::CalculateStopInfo ()
104 {
105     if (m_backing_thread_sp)
106     {
107         lldb::StopInfoSP backing_stop_info_sp (m_backing_thread_sp->GetPrivateStopInfo());
108         if (backing_stop_info_sp)
109         {
110             backing_stop_info_sp->SetThread (shared_from_this());
111             SetStopInfo (backing_stop_info_sp);
112             return true;
113         }
114     }
115     else
116     {
117         ProcessSP process_sp (GetProcess());
118
119         if (process_sp)
120         {
121             OperatingSystem *os = process_sp->GetOperatingSystem ();
122             if (os)
123             {
124                 SetStopInfo (os->CreateThreadStopReason (this));
125                 return true;
126             }
127         }
128     }
129     return false;
130 }
131
132 void
133 ThreadMemory::RefreshStateAfterStop()
134 {
135     if (m_backing_thread_sp)
136         return m_backing_thread_sp->RefreshStateAfterStop();
137     
138     if (m_reg_context_sp)
139         m_reg_context_sp->InvalidateAllRegisters();
140 }