blob: 41cf04d0dbe28fb948904596cb2b50cda797314b [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 Clayton567e7f32011-09-22 04:58:26 +000049 m_target_sp (t),
50 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)
61 m_frame_sp = m_thread_sp->GetSelectedFrame().get();
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) :
67 m_target_sp (process ? &process->GetTarget() : NULL),
68 m_process_sp (process),
69 m_thread_sp (thread),
70 m_frame_sp (frame)
Chris Lattner24943d22010-06-08 16:52:24 +000071{
72}
73
74ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr)
75{
76 if (exe_scope_ptr)
Greg Claytona830adb2010-10-04 01:05:56 +000077 exe_scope_ptr->CalculateExecutionContext (*this);
Chris Lattner24943d22010-06-08 16:52:24 +000078 else
79 {
Greg Clayton567e7f32011-09-22 04:58:26 +000080 m_target_sp.reset();
81 m_process_sp.reset();
82 m_thread_sp.reset();
83 m_frame_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +000084 }
85}
86
87ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref)
88{
Greg Claytona830adb2010-10-04 01:05:56 +000089 exe_scope_ref.CalculateExecutionContext (*this);
Chris Lattner24943d22010-06-08 16:52:24 +000090}
91
92void
93ExecutionContext::Clear()
94{
Greg Clayton567e7f32011-09-22 04:58:26 +000095 m_target_sp.reset();
96 m_process_sp.reset();
97 m_thread_sp.reset();
98 m_frame_sp.reset();
99}
100
101ExecutionContext::~ExecutionContext()
102{
Chris Lattner24943d22010-06-08 16:52:24 +0000103}
104
105
106RegisterContext *
107ExecutionContext::GetRegisterContext () const
108{
Greg Clayton567e7f32011-09-22 04:58:26 +0000109 if (m_frame_sp)
110 return m_frame_sp->GetRegisterContext().get();
111 else if (m_thread_sp)
112 return m_thread_sp->GetRegisterContext().get();
113 return NULL;
114}
115
116Target *
117ExecutionContext::GetTargetPtr () const
118{
119 if (m_target_sp)
120 return m_target_sp.get();
121 if (m_process_sp)
122 return &m_process_sp->GetTarget();
123 return NULL;
124}
125
126Process *
127ExecutionContext::GetProcessPtr () const
128{
129 if (m_process_sp)
130 return m_process_sp.get();
131 if (m_target_sp)
132 return m_target_sp->GetProcessSP().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000133 return NULL;
134}
135
136ExecutionContextScope *
137ExecutionContext::GetBestExecutionContextScope () const
138{
Greg Clayton567e7f32011-09-22 04:58:26 +0000139 if (m_frame_sp)
140 return m_frame_sp.get();
141 if (m_thread_sp)
142 return m_thread_sp.get();
143 if (m_process_sp)
144 return m_process_sp.get();
145 return m_target_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000146}
Greg Clayton801417e2011-07-07 01:59:51 +0000147
Greg Clayton567e7f32011-09-22 04:58:26 +0000148Target &
149ExecutionContext::GetTargetRef () const
Greg Clayton801417e2011-07-07 01:59:51 +0000150{
Greg Clayton567e7f32011-09-22 04:58:26 +0000151 assert (m_target_sp.get());
152 return *m_target_sp;
Greg Clayton801417e2011-07-07 01:59:51 +0000153}
Greg Clayton567e7f32011-09-22 04:58:26 +0000154
155Process &
156ExecutionContext::GetProcessRef () const
157{
158 assert (m_process_sp.get());
159 return *m_process_sp;
160}
161
162Thread &
163ExecutionContext::GetThreadRef () const
164{
165 assert (m_thread_sp.get());
166 return *m_thread_sp;
167}
168
169StackFrame &
170ExecutionContext::GetFrameRef () const
171{
172 assert (m_frame_sp.get());
173 return *m_frame_sp;
174}
175
176void
177ExecutionContext::SetTargetSP (const lldb::TargetSP &target_sp)
178{
179 m_target_sp = target_sp;
180}
181
182void
183ExecutionContext::SetProcessSP (const lldb::ProcessSP &process_sp)
184{
185 m_process_sp = process_sp;
186}
187
188void
189ExecutionContext::SetThreadSP (const lldb::ThreadSP &thread_sp)
190{
191 m_thread_sp = thread_sp;
192}
193
194void
195ExecutionContext::SetFrameSP (const lldb::StackFrameSP &frame_sp)
196{
197 m_frame_sp = frame_sp;
198}
199
200void
201ExecutionContext::SetTargetPtr (Target* target)
202{
203 m_target_sp = target;
204}
205
206void
207ExecutionContext::SetProcessPtr (Process *process)
208{
209 m_process_sp = process;
210}
211
212void
213ExecutionContext::SetThreadPtr (Thread *thread)
214{
215 m_thread_sp = thread;
216}
217
218void
219ExecutionContext::SetFramePtr (StackFrame *frame)
220{
221 m_frame_sp = frame;
222}
223