blob: 8360d1addcfa5dd75e2c1b64221f7561432d8d36 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- ExecutionContext.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//===----------------------------------------------------------------------===//
Chris Lattner24943d22010-06-08 16:52:24 +00009
10#include "lldb/Target/ExecutionContext.h"
11#include "lldb/Target/ExecutionContextScope.h"
12#include "lldb/Target/StackFrame.h"
13#include "lldb/Target/Process.h"
14#include "lldb/Target/Target.h"
15#include "lldb/Target/Thread.h"
16
17using namespace lldb_private;
18
19ExecutionContext::ExecutionContext() :
Greg Clayton567e7f32011-09-22 04:58:26 +000020 m_target_sp (),
21 m_process_sp (),
22 m_thread_sp (),
23 m_frame_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000024{
25}
26
Greg Clayton567e7f32011-09-22 04:58:26 +000027ExecutionContext::ExecutionContext (const ExecutionContext &rhs) :
28 m_target_sp (rhs.m_target_sp),
29 m_process_sp(rhs.m_process_sp),
30 m_thread_sp (rhs.m_thread_sp),
31 m_frame_sp (rhs.m_frame_sp)
32{
33}
34
35ExecutionContext &
36ExecutionContext::operator =(const ExecutionContext &rhs)
37{
38 if (this != &rhs)
39 {
40 m_target_sp = rhs.m_target_sp;
41 m_process_sp = rhs.m_process_sp;
42 m_thread_sp = rhs.m_thread_sp;
43 m_frame_sp = rhs.m_frame_sp;
44 }
45 return *this;
46}
47
Chris Lattner24943d22010-06-08 16:52:24 +000048ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) :
Greg Clayton13d24fb2012-01-29 20:56:30 +000049 m_target_sp (t->shared_from_this()),
Greg Clayton567e7f32011-09-22 04:58:26 +000050 m_process_sp (),
51 m_thread_sp (),
52 m_frame_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000053{
54 if (t && fill_current_process_thread_frame)
55 {
Greg Clayton567e7f32011-09-22 04:58:26 +000056 m_process_sp = t->GetProcessSP();
57 if (m_process_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000058 {
Greg Clayton567e7f32011-09-22 04:58:26 +000059 m_thread_sp = m_process_sp->GetThreadList().GetSelectedThread();
60 if (m_thread_sp)
Greg Clayton13d24fb2012-01-29 20:56:30 +000061 m_frame_sp = m_thread_sp->GetSelectedFrame();
Chris Lattner24943d22010-06-08 16:52:24 +000062 }
63 }
64}
65
Greg Clayton567e7f32011-09-22 04:58:26 +000066ExecutionContext::ExecutionContext(Process* process, Thread *thread, StackFrame *frame) :
Greg Clayton13d24fb2012-01-29 20:56:30 +000067 m_target_sp (),
68 m_process_sp (process->shared_from_this()),
69 m_thread_sp (thread->shared_from_this()),
70 m_frame_sp (frame->shared_from_this())
Chris Lattner24943d22010-06-08 16:52:24 +000071{
Greg Clayton13d24fb2012-01-29 20:56:30 +000072 if (process)
73 m_target_sp = process->GetTarget().shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +000074}
75
76ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr)
77{
78 if (exe_scope_ptr)
Greg Claytona830adb2010-10-04 01:05:56 +000079 exe_scope_ptr->CalculateExecutionContext (*this);
Chris Lattner24943d22010-06-08 16:52:24 +000080 else
81 {
Greg Clayton567e7f32011-09-22 04:58:26 +000082 m_target_sp.reset();
83 m_process_sp.reset();
84 m_thread_sp.reset();
85 m_frame_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +000086 }
87}
88
89ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref)
90{
Greg Claytona830adb2010-10-04 01:05:56 +000091 exe_scope_ref.CalculateExecutionContext (*this);
Chris Lattner24943d22010-06-08 16:52:24 +000092}
93
94void
95ExecutionContext::Clear()
96{
Greg Clayton567e7f32011-09-22 04:58:26 +000097 m_target_sp.reset();
98 m_process_sp.reset();
99 m_thread_sp.reset();
100 m_frame_sp.reset();
101}
102
103ExecutionContext::~ExecutionContext()
104{
Chris Lattner24943d22010-06-08 16:52:24 +0000105}
106
107
108RegisterContext *
109ExecutionContext::GetRegisterContext () const
110{
Greg Clayton567e7f32011-09-22 04:58:26 +0000111 if (m_frame_sp)
112 return m_frame_sp->GetRegisterContext().get();
113 else if (m_thread_sp)
114 return m_thread_sp->GetRegisterContext().get();
115 return NULL;
116}
117
118Target *
119ExecutionContext::GetTargetPtr () const
120{
121 if (m_target_sp)
122 return m_target_sp.get();
123 if (m_process_sp)
124 return &m_process_sp->GetTarget();
125 return NULL;
126}
127
128Process *
129ExecutionContext::GetProcessPtr () const
130{
131 if (m_process_sp)
132 return m_process_sp.get();
133 if (m_target_sp)
134 return m_target_sp->GetProcessSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000135 return NULL;
136}
137
138ExecutionContextScope *
139ExecutionContext::GetBestExecutionContextScope () const
140{
Greg Clayton567e7f32011-09-22 04:58:26 +0000141 if (m_frame_sp)
142 return m_frame_sp.get();
143 if (m_thread_sp)
144 return m_thread_sp.get();
145 if (m_process_sp)
146 return m_process_sp.get();
147 return m_target_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000148}
Greg Clayton801417e2011-07-07 01:59:51 +0000149
Greg Clayton567e7f32011-09-22 04:58:26 +0000150Target &
151ExecutionContext::GetTargetRef () const
Greg Clayton801417e2011-07-07 01:59:51 +0000152{
Greg Clayton567e7f32011-09-22 04:58:26 +0000153 assert (m_target_sp.get());
154 return *m_target_sp;
Greg Clayton801417e2011-07-07 01:59:51 +0000155}
Greg Clayton567e7f32011-09-22 04:58:26 +0000156
157Process &
158ExecutionContext::GetProcessRef () const
159{
160 assert (m_process_sp.get());
161 return *m_process_sp;
162}
163
164Thread &
165ExecutionContext::GetThreadRef () const
166{
167 assert (m_thread_sp.get());
168 return *m_thread_sp;
169}
170
171StackFrame &
172ExecutionContext::GetFrameRef () const
173{
174 assert (m_frame_sp.get());
175 return *m_frame_sp;
176}
177
178void
179ExecutionContext::SetTargetSP (const lldb::TargetSP &target_sp)
180{
181 m_target_sp = target_sp;
182}
183
184void
185ExecutionContext::SetProcessSP (const lldb::ProcessSP &process_sp)
186{
187 m_process_sp = process_sp;
188}
189
190void
191ExecutionContext::SetThreadSP (const lldb::ThreadSP &thread_sp)
192{
193 m_thread_sp = thread_sp;
194}
195
196void
197ExecutionContext::SetFrameSP (const lldb::StackFrameSP &frame_sp)
198{
199 m_frame_sp = frame_sp;
200}
201
202void
203ExecutionContext::SetTargetPtr (Target* target)
204{
Greg Clayton13d24fb2012-01-29 20:56:30 +0000205 if (target)
206 m_target_sp = target->shared_from_this();
207 else
208 m_target_sp.reset();
Greg Clayton567e7f32011-09-22 04:58:26 +0000209}
210
211void
212ExecutionContext::SetProcessPtr (Process *process)
213{
Greg Clayton13d24fb2012-01-29 20:56:30 +0000214 if (process)
215 m_process_sp = process->shared_from_this();
216 else
217 m_process_sp.reset();
Greg Clayton567e7f32011-09-22 04:58:26 +0000218}
219
220void
221ExecutionContext::SetThreadPtr (Thread *thread)
222{
Greg Clayton13d24fb2012-01-29 20:56:30 +0000223 if (thread)
224 m_thread_sp = thread->shared_from_this();
225 else
226 m_thread_sp.reset();
Greg Clayton567e7f32011-09-22 04:58:26 +0000227}
228
229void
230ExecutionContext::SetFramePtr (StackFrame *frame)
231{
Greg Clayton13d24fb2012-01-29 20:56:30 +0000232 if (frame)
233 m_frame_sp = frame->shared_from_this();
234 else
235 m_frame_sp.reset();
Greg Clayton567e7f32011-09-22 04:58:26 +0000236}
237