Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 9 | |
| 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 | |
| 17 | using namespace lldb_private; |
| 18 | |
| 19 | ExecutionContext::ExecutionContext() : |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 20 | m_target_sp (), |
| 21 | m_process_sp (), |
| 22 | m_thread_sp (), |
| 23 | m_frame_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | { |
| 25 | } |
| 26 | |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 27 | ExecutionContext::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 | |
| 35 | ExecutionContext & |
| 36 | ExecutionContext::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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) : |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 49 | m_target_sp (t->shared_from_this()), |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 50 | m_process_sp (), |
| 51 | m_thread_sp (), |
| 52 | m_frame_sp () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | { |
| 54 | if (t && fill_current_process_thread_frame) |
| 55 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 56 | m_process_sp = t->GetProcessSP(); |
| 57 | if (m_process_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 59 | m_thread_sp = m_process_sp->GetThreadList().GetSelectedThread(); |
| 60 | if (m_thread_sp) |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 61 | m_frame_sp = m_thread_sp->GetSelectedFrame(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 66 | ExecutionContext::ExecutionContext(Process* process, Thread *thread, StackFrame *frame) : |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 67 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 72 | if (process) |
| 73 | m_target_sp = process->GetTarget().shared_from_this(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr) |
| 77 | { |
| 78 | if (exe_scope_ptr) |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 79 | exe_scope_ptr->CalculateExecutionContext (*this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | else |
| 81 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 82 | m_target_sp.reset(); |
| 83 | m_process_sp.reset(); |
| 84 | m_thread_sp.reset(); |
| 85 | m_frame_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref) |
| 90 | { |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 91 | exe_scope_ref.CalculateExecutionContext (*this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void |
| 95 | ExecutionContext::Clear() |
| 96 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 97 | m_target_sp.reset(); |
| 98 | m_process_sp.reset(); |
| 99 | m_thread_sp.reset(); |
| 100 | m_frame_sp.reset(); |
| 101 | } |
| 102 | |
| 103 | ExecutionContext::~ExecutionContext() |
| 104 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | |
| 108 | RegisterContext * |
| 109 | ExecutionContext::GetRegisterContext () const |
| 110 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 111 | 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 | |
| 118 | Target * |
| 119 | ExecutionContext::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 | |
| 128 | Process * |
| 129 | ExecutionContext::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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 135 | return NULL; |
| 136 | } |
| 137 | |
| 138 | ExecutionContextScope * |
| 139 | ExecutionContext::GetBestExecutionContextScope () const |
| 140 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 141 | 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | } |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 149 | |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 150 | Target & |
| 151 | ExecutionContext::GetTargetRef () const |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 152 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 153 | assert (m_target_sp.get()); |
| 154 | return *m_target_sp; |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 155 | } |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 156 | |
| 157 | Process & |
| 158 | ExecutionContext::GetProcessRef () const |
| 159 | { |
| 160 | assert (m_process_sp.get()); |
| 161 | return *m_process_sp; |
| 162 | } |
| 163 | |
| 164 | Thread & |
| 165 | ExecutionContext::GetThreadRef () const |
| 166 | { |
| 167 | assert (m_thread_sp.get()); |
| 168 | return *m_thread_sp; |
| 169 | } |
| 170 | |
| 171 | StackFrame & |
| 172 | ExecutionContext::GetFrameRef () const |
| 173 | { |
| 174 | assert (m_frame_sp.get()); |
| 175 | return *m_frame_sp; |
| 176 | } |
| 177 | |
| 178 | void |
| 179 | ExecutionContext::SetTargetSP (const lldb::TargetSP &target_sp) |
| 180 | { |
| 181 | m_target_sp = target_sp; |
| 182 | } |
| 183 | |
| 184 | void |
| 185 | ExecutionContext::SetProcessSP (const lldb::ProcessSP &process_sp) |
| 186 | { |
| 187 | m_process_sp = process_sp; |
| 188 | } |
| 189 | |
| 190 | void |
| 191 | ExecutionContext::SetThreadSP (const lldb::ThreadSP &thread_sp) |
| 192 | { |
| 193 | m_thread_sp = thread_sp; |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | ExecutionContext::SetFrameSP (const lldb::StackFrameSP &frame_sp) |
| 198 | { |
| 199 | m_frame_sp = frame_sp; |
| 200 | } |
| 201 | |
| 202 | void |
| 203 | ExecutionContext::SetTargetPtr (Target* target) |
| 204 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 205 | if (target) |
| 206 | m_target_sp = target->shared_from_this(); |
| 207 | else |
| 208 | m_target_sp.reset(); |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void |
| 212 | ExecutionContext::SetProcessPtr (Process *process) |
| 213 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 214 | if (process) |
| 215 | m_process_sp = process->shared_from_this(); |
| 216 | else |
| 217 | m_process_sp.reset(); |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void |
| 221 | ExecutionContext::SetThreadPtr (Thread *thread) |
| 222 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 223 | if (thread) |
| 224 | m_thread_sp = thread->shared_from_this(); |
| 225 | else |
| 226 | m_thread_sp.reset(); |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void |
| 230 | ExecutionContext::SetFramePtr (StackFrame *frame) |
| 231 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 232 | if (frame) |
| 233 | m_frame_sp = frame->shared_from_this(); |
| 234 | else |
| 235 | m_frame_sp.reset(); |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 236 | } |
| 237 | |