Chris Lattner | 30fdc8d | 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 | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 9 | |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
| 13 | // Project includes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Target/ExecutionContext.h" |
Greg Clayton | 9b5450f | 2012-07-30 22:05:39 +0000 | [diff] [blame] | 15 | #include "lldb/Core/State.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Target/ExecutionContextScope.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 17 | #include "lldb/Target/StackFrame.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Target/Process.h" |
| 19 | #include "lldb/Target/Target.h" |
| 20 | #include "lldb/Target/Thread.h" |
| 21 | |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | ExecutionContext::ExecutionContext() : |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 25 | m_target_sp (), |
| 26 | m_process_sp (), |
| 27 | m_thread_sp (), |
| 28 | m_frame_sp () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 32 | ExecutionContext::ExecutionContext (const ExecutionContext &rhs) : |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 33 | m_target_sp(rhs.m_target_sp), |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 34 | m_process_sp(rhs.m_process_sp), |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 35 | m_thread_sp(rhs.m_thread_sp), |
| 36 | m_frame_sp(rhs.m_frame_sp) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 37 | { |
| 38 | } |
| 39 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 40 | ExecutionContext::ExecutionContext (const lldb::TargetSP &target_sp, bool get_process) : |
| 41 | m_target_sp (), |
| 42 | m_process_sp (), |
| 43 | m_thread_sp (), |
| 44 | m_frame_sp () |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 45 | { |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 46 | if (target_sp) |
| 47 | SetContext (target_sp, get_process); |
| 48 | } |
| 49 | |
| 50 | ExecutionContext::ExecutionContext (const lldb::ProcessSP &process_sp) : |
| 51 | m_target_sp (), |
| 52 | m_process_sp (), |
| 53 | m_thread_sp (), |
| 54 | m_frame_sp () |
| 55 | { |
| 56 | if (process_sp) |
| 57 | SetContext (process_sp); |
| 58 | } |
| 59 | |
| 60 | ExecutionContext::ExecutionContext (const lldb::ThreadSP &thread_sp) : |
| 61 | m_target_sp (), |
| 62 | m_process_sp (), |
| 63 | m_thread_sp (), |
| 64 | m_frame_sp () |
| 65 | { |
| 66 | if (thread_sp) |
| 67 | SetContext (thread_sp); |
| 68 | } |
| 69 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 70 | ExecutionContext::ExecutionContext (const lldb::StackFrameSP &frame_sp) : |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 71 | m_target_sp (), |
| 72 | m_process_sp (), |
| 73 | m_thread_sp (), |
| 74 | m_frame_sp () |
| 75 | { |
| 76 | if (frame_sp) |
| 77 | SetContext (frame_sp); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 80 | ExecutionContext::ExecutionContext (const lldb::TargetWP &target_wp, bool get_process) : |
| 81 | m_target_sp (), |
| 82 | m_process_sp (), |
| 83 | m_thread_sp (), |
| 84 | m_frame_sp () |
| 85 | { |
| 86 | lldb::TargetSP target_sp(target_wp.lock()); |
| 87 | if (target_sp) |
| 88 | SetContext (target_sp, get_process); |
| 89 | } |
| 90 | |
| 91 | ExecutionContext::ExecutionContext (const lldb::ProcessWP &process_wp) : |
| 92 | m_target_sp (), |
| 93 | m_process_sp (), |
| 94 | m_thread_sp (), |
| 95 | m_frame_sp () |
| 96 | { |
| 97 | lldb::ProcessSP process_sp(process_wp.lock()); |
| 98 | if (process_sp) |
| 99 | SetContext (process_sp); |
| 100 | } |
| 101 | |
| 102 | ExecutionContext::ExecutionContext (const lldb::ThreadWP &thread_wp) : |
| 103 | m_target_sp (), |
| 104 | m_process_sp (), |
| 105 | m_thread_sp (), |
| 106 | m_frame_sp () |
| 107 | { |
| 108 | lldb::ThreadSP thread_sp(thread_wp.lock()); |
| 109 | if (thread_sp) |
| 110 | SetContext (thread_sp); |
| 111 | } |
| 112 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 113 | ExecutionContext::ExecutionContext (const lldb::StackFrameWP &frame_wp) : |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 114 | m_target_sp (), |
| 115 | m_process_sp (), |
| 116 | m_thread_sp (), |
| 117 | m_frame_sp () |
| 118 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 119 | lldb::StackFrameSP frame_sp(frame_wp.lock()); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 120 | if (frame_sp) |
| 121 | SetContext (frame_sp); |
| 122 | } |
| 123 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) : |
Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 125 | m_target_sp (), |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 126 | m_process_sp (), |
| 127 | m_thread_sp (), |
| 128 | m_frame_sp () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | { |
Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 130 | if (t) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | { |
Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 132 | m_target_sp = t->shared_from_this(); |
| 133 | if (fill_current_process_thread_frame) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | { |
Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 135 | m_process_sp = t->GetProcessSP(); |
| 136 | if (m_process_sp) |
| 137 | { |
| 138 | m_thread_sp = m_process_sp->GetThreadList().GetSelectedThread(); |
| 139 | if (m_thread_sp) |
| 140 | m_frame_sp = m_thread_sp->GetSelectedFrame(); |
| 141 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 146 | ExecutionContext::ExecutionContext(Process* process, Thread *thread, StackFrame *frame) : |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 147 | m_target_sp (), |
Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 148 | m_process_sp (), |
| 149 | m_thread_sp (), |
| 150 | m_frame_sp () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 152 | if (process) |
Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 153 | { |
| 154 | m_process_sp = process->shared_from_this(); |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 155 | m_target_sp = process->GetTarget().shared_from_this(); |
Greg Clayton | 526ae04 | 2015-02-12 00:34:25 +0000 | [diff] [blame] | 156 | } |
| 157 | if (thread) |
| 158 | m_thread_sp = thread->shared_from_this(); |
| 159 | if (frame) |
| 160 | m_frame_sp = frame->shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 163 | ExecutionContext::ExecutionContext (const ExecutionContextRef &exe_ctx_ref) : |
| 164 | m_target_sp (exe_ctx_ref.GetTargetSP()), |
| 165 | m_process_sp (exe_ctx_ref.GetProcessSP()), |
| 166 | m_thread_sp (exe_ctx_ref.GetThreadSP()), |
| 167 | m_frame_sp (exe_ctx_ref.GetFrameSP()) |
| 168 | { |
| 169 | } |
| 170 | |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 171 | ExecutionContext::ExecutionContext (const ExecutionContextRef *exe_ctx_ref_ptr, bool thread_and_frame_only_if_stopped) : |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 172 | m_target_sp (), |
| 173 | m_process_sp (), |
| 174 | m_thread_sp (), |
| 175 | m_frame_sp () |
| 176 | { |
| 177 | if (exe_ctx_ref_ptr) |
| 178 | { |
| 179 | m_target_sp = exe_ctx_ref_ptr->GetTargetSP(); |
| 180 | m_process_sp = exe_ctx_ref_ptr->GetProcessSP(); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 181 | if (!thread_and_frame_only_if_stopped || (m_process_sp && StateIsStoppedState(m_process_sp->GetState(), true))) |
| 182 | { |
| 183 | m_thread_sp = exe_ctx_ref_ptr->GetThreadSP(); |
| 184 | m_frame_sp = exe_ctx_ref_ptr->GetFrameSP(); |
| 185 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 189 | ExecutionContext::ExecutionContext (const ExecutionContextRef *exe_ctx_ref_ptr, Mutex::Locker &locker) : |
| 190 | m_target_sp (), |
| 191 | m_process_sp (), |
| 192 | m_thread_sp (), |
| 193 | m_frame_sp () |
| 194 | { |
| 195 | if (exe_ctx_ref_ptr) |
| 196 | { |
| 197 | m_target_sp = exe_ctx_ref_ptr->GetTargetSP(); |
| 198 | if (m_target_sp) |
| 199 | { |
| 200 | locker.Lock(m_target_sp->GetAPIMutex()); |
| 201 | m_process_sp = exe_ctx_ref_ptr->GetProcessSP(); |
| 202 | m_thread_sp = exe_ctx_ref_ptr->GetThreadSP(); |
| 203 | m_frame_sp = exe_ctx_ref_ptr->GetFrameSP(); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | ExecutionContext::ExecutionContext (const ExecutionContextRef &exe_ctx_ref, Mutex::Locker &locker) : |
| 209 | m_target_sp (exe_ctx_ref.GetTargetSP()), |
| 210 | m_process_sp (), |
| 211 | m_thread_sp (), |
| 212 | m_frame_sp () |
| 213 | { |
| 214 | if (m_target_sp) |
| 215 | { |
| 216 | locker.Lock(m_target_sp->GetAPIMutex()); |
| 217 | m_process_sp = exe_ctx_ref.GetProcessSP(); |
| 218 | m_thread_sp = exe_ctx_ref.GetThreadSP(); |
| 219 | m_frame_sp = exe_ctx_ref.GetFrameSP(); |
| 220 | } |
| 221 | } |
| 222 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 223 | ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr) : |
| 224 | m_target_sp (), |
| 225 | m_process_sp (), |
| 226 | m_thread_sp (), |
| 227 | m_frame_sp () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 228 | { |
| 229 | if (exe_scope_ptr) |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 230 | exe_scope_ptr->CalculateExecutionContext (*this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref) |
| 234 | { |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 235 | exe_scope_ref.CalculateExecutionContext (*this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | void |
| 239 | ExecutionContext::Clear() |
| 240 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 241 | m_target_sp.reset(); |
| 242 | m_process_sp.reset(); |
| 243 | m_thread_sp.reset(); |
| 244 | m_frame_sp.reset(); |
| 245 | } |
| 246 | |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 247 | ExecutionContext::~ExecutionContext() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 248 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 249 | uint32_t |
| 250 | ExecutionContext::GetAddressByteSize() const |
| 251 | { |
| 252 | if (m_target_sp && m_target_sp->GetArchitecture().IsValid()) |
Hafiz Abid Qadeer | ed69e30 | 2015-02-25 16:01:12 +0000 | [diff] [blame] | 253 | return m_target_sp->GetArchitecture().GetAddressByteSize(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 254 | if (m_process_sp) |
Hafiz Abid Qadeer | ed69e30 | 2015-02-25 16:01:12 +0000 | [diff] [blame] | 255 | return m_process_sp->GetAddressByteSize(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 256 | return sizeof(void *); |
| 257 | } |
| 258 | |
Enrico Granata | 347c2aa | 2013-10-08 21:49:02 +0000 | [diff] [blame] | 259 | lldb::ByteOrder |
| 260 | ExecutionContext::GetByteOrder() const |
| 261 | { |
| 262 | if (m_target_sp && m_target_sp->GetArchitecture().IsValid()) |
| 263 | m_target_sp->GetArchitecture().GetByteOrder(); |
| 264 | if (m_process_sp) |
| 265 | m_process_sp->GetByteOrder(); |
Bruce Mitchener | 9ccb970 | 2015-11-07 04:40:13 +0000 | [diff] [blame] | 266 | return endian::InlHostByteOrder(); |
Enrico Granata | 347c2aa | 2013-10-08 21:49:02 +0000 | [diff] [blame] | 267 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 268 | |
| 269 | RegisterContext * |
| 270 | ExecutionContext::GetRegisterContext () const |
| 271 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 272 | if (m_frame_sp) |
| 273 | return m_frame_sp->GetRegisterContext().get(); |
| 274 | else if (m_thread_sp) |
| 275 | return m_thread_sp->GetRegisterContext().get(); |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 276 | return nullptr; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | Target * |
| 280 | ExecutionContext::GetTargetPtr () const |
| 281 | { |
| 282 | if (m_target_sp) |
| 283 | return m_target_sp.get(); |
| 284 | if (m_process_sp) |
| 285 | return &m_process_sp->GetTarget(); |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 286 | return nullptr; |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | Process * |
| 290 | ExecutionContext::GetProcessPtr () const |
| 291 | { |
| 292 | if (m_process_sp) |
| 293 | return m_process_sp.get(); |
| 294 | if (m_target_sp) |
| 295 | return m_target_sp->GetProcessSP().get(); |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 296 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | ExecutionContextScope * |
| 300 | ExecutionContext::GetBestExecutionContextScope () const |
| 301 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 302 | if (m_frame_sp) |
| 303 | return m_frame_sp.get(); |
| 304 | if (m_thread_sp) |
| 305 | return m_thread_sp.get(); |
| 306 | if (m_process_sp) |
| 307 | return m_process_sp.get(); |
| 308 | return m_target_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 309 | } |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 310 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 311 | Target & |
| 312 | ExecutionContext::GetTargetRef () const |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 313 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 314 | #if defined (LLDB_CONFIGURATION_DEBUG) || defined (LLDB_CONFIGURATION_RELEASE) |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 315 | assert (m_target_sp); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 316 | #endif |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 317 | return *m_target_sp; |
Greg Clayton | 644247c | 2011-07-07 01:59:51 +0000 | [diff] [blame] | 318 | } |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 319 | |
| 320 | Process & |
| 321 | ExecutionContext::GetProcessRef () const |
| 322 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 323 | #if defined (LLDB_CONFIGURATION_DEBUG) || defined (LLDB_CONFIGURATION_RELEASE) |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 324 | assert (m_process_sp); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 325 | #endif |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 326 | return *m_process_sp; |
| 327 | } |
| 328 | |
| 329 | Thread & |
| 330 | ExecutionContext::GetThreadRef () const |
| 331 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 332 | #if defined (LLDB_CONFIGURATION_DEBUG) || defined (LLDB_CONFIGURATION_RELEASE) |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 333 | assert (m_thread_sp); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 334 | #endif |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 335 | return *m_thread_sp; |
| 336 | } |
| 337 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 338 | StackFrame & |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 339 | ExecutionContext::GetFrameRef () const |
| 340 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 341 | #if defined (LLDB_CONFIGURATION_DEBUG) || defined (LLDB_CONFIGURATION_RELEASE) |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 342 | assert (m_frame_sp); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 343 | #endif |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 344 | return *m_frame_sp; |
| 345 | } |
| 346 | |
| 347 | void |
| 348 | ExecutionContext::SetTargetSP (const lldb::TargetSP &target_sp) |
| 349 | { |
| 350 | m_target_sp = target_sp; |
| 351 | } |
| 352 | |
| 353 | void |
| 354 | ExecutionContext::SetProcessSP (const lldb::ProcessSP &process_sp) |
| 355 | { |
| 356 | m_process_sp = process_sp; |
| 357 | } |
| 358 | |
| 359 | void |
| 360 | ExecutionContext::SetThreadSP (const lldb::ThreadSP &thread_sp) |
| 361 | { |
| 362 | m_thread_sp = thread_sp; |
| 363 | } |
| 364 | |
| 365 | void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 366 | ExecutionContext::SetFrameSP (const lldb::StackFrameSP &frame_sp) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 367 | { |
| 368 | m_frame_sp = frame_sp; |
| 369 | } |
| 370 | |
| 371 | void |
| 372 | ExecutionContext::SetTargetPtr (Target* target) |
| 373 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 374 | if (target) |
| 375 | m_target_sp = target->shared_from_this(); |
| 376 | else |
| 377 | m_target_sp.reset(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | void |
| 381 | ExecutionContext::SetProcessPtr (Process *process) |
| 382 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 383 | if (process) |
| 384 | m_process_sp = process->shared_from_this(); |
| 385 | else |
| 386 | m_process_sp.reset(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | void |
| 390 | ExecutionContext::SetThreadPtr (Thread *thread) |
| 391 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 392 | if (thread) |
| 393 | m_thread_sp = thread->shared_from_this(); |
| 394 | else |
| 395 | m_thread_sp.reset(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 399 | ExecutionContext::SetFramePtr (StackFrame *frame) |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 400 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 401 | if (frame) |
| 402 | m_frame_sp = frame->shared_from_this(); |
| 403 | else |
| 404 | m_frame_sp.reset(); |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 407 | void |
| 408 | ExecutionContext::SetContext (const lldb::TargetSP &target_sp, bool get_process) |
| 409 | { |
| 410 | m_target_sp = target_sp; |
| 411 | if (get_process && target_sp) |
| 412 | m_process_sp = target_sp->GetProcessSP(); |
| 413 | else |
| 414 | m_process_sp.reset(); |
| 415 | m_thread_sp.reset(); |
| 416 | m_frame_sp.reset(); |
| 417 | } |
| 418 | |
| 419 | void |
| 420 | ExecutionContext::SetContext (const lldb::ProcessSP &process_sp) |
| 421 | { |
| 422 | m_process_sp = process_sp; |
| 423 | if (process_sp) |
| 424 | m_target_sp = process_sp->GetTarget().shared_from_this(); |
| 425 | else |
| 426 | m_target_sp.reset(); |
| 427 | m_thread_sp.reset(); |
| 428 | m_frame_sp.reset(); |
| 429 | } |
| 430 | |
| 431 | void |
| 432 | ExecutionContext::SetContext (const lldb::ThreadSP &thread_sp) |
| 433 | { |
| 434 | m_frame_sp.reset(); |
| 435 | m_thread_sp = thread_sp; |
| 436 | if (thread_sp) |
| 437 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 438 | m_process_sp = thread_sp->GetProcess(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 439 | if (m_process_sp) |
| 440 | m_target_sp = m_process_sp->GetTarget().shared_from_this(); |
| 441 | else |
| 442 | m_target_sp.reset(); |
| 443 | } |
| 444 | else |
| 445 | { |
| 446 | m_target_sp.reset(); |
| 447 | m_process_sp.reset(); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 452 | ExecutionContext::SetContext (const lldb::StackFrameSP &frame_sp) |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 453 | { |
| 454 | m_frame_sp = frame_sp; |
| 455 | if (frame_sp) |
| 456 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 457 | m_thread_sp = frame_sp->CalculateThread(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 458 | if (m_thread_sp) |
| 459 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 460 | m_process_sp = m_thread_sp->GetProcess(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 461 | if (m_process_sp) |
| 462 | m_target_sp = m_process_sp->GetTarget().shared_from_this(); |
| 463 | else |
| 464 | m_target_sp.reset(); |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | m_target_sp.reset(); |
| 469 | m_process_sp.reset(); |
| 470 | } |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | m_target_sp.reset(); |
| 475 | m_process_sp.reset(); |
| 476 | m_thread_sp.reset(); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | ExecutionContext & |
| 481 | ExecutionContext::operator =(const ExecutionContext &rhs) |
| 482 | { |
| 483 | if (this != &rhs) |
| 484 | { |
| 485 | m_target_sp = rhs.m_target_sp; |
| 486 | m_process_sp = rhs.m_process_sp; |
| 487 | m_thread_sp = rhs.m_thread_sp; |
| 488 | m_frame_sp = rhs.m_frame_sp; |
| 489 | } |
| 490 | return *this; |
| 491 | } |
| 492 | |
| 493 | bool |
| 494 | ExecutionContext::operator ==(const ExecutionContext &rhs) const |
| 495 | { |
| 496 | // Check that the frame shared pointers match, or both are valid and their stack |
| 497 | // IDs match since sometimes we get new objects that represent the same |
| 498 | // frame within a thread. |
| 499 | if ((m_frame_sp == rhs.m_frame_sp) || (m_frame_sp && rhs.m_frame_sp && m_frame_sp->GetStackID() == rhs.m_frame_sp->GetStackID())) |
| 500 | { |
| 501 | // Check that the thread shared pointers match, or both are valid and |
| 502 | // their thread IDs match since sometimes we get new objects that |
| 503 | // represent the same thread within a process. |
| 504 | if ((m_thread_sp == rhs.m_thread_sp) || (m_thread_sp && rhs.m_thread_sp && m_thread_sp->GetID() == rhs.m_thread_sp->GetID())) |
| 505 | { |
| 506 | // Processes and targets don't change much |
| 507 | return m_process_sp == rhs.m_process_sp && m_target_sp == rhs.m_target_sp; |
| 508 | } |
| 509 | } |
| 510 | return false; |
| 511 | } |
| 512 | |
| 513 | bool |
| 514 | ExecutionContext::operator !=(const ExecutionContext &rhs) const |
| 515 | { |
| 516 | return !(*this == rhs); |
| 517 | } |
| 518 | |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 519 | bool |
| 520 | ExecutionContext::HasTargetScope () const |
| 521 | { |
| 522 | return ((bool) m_target_sp |
| 523 | && m_target_sp->IsValid()); |
| 524 | } |
| 525 | |
| 526 | bool |
| 527 | ExecutionContext::HasProcessScope () const |
| 528 | { |
| 529 | return (HasTargetScope() |
| 530 | && ((bool) m_process_sp && m_process_sp->IsValid())); |
| 531 | } |
| 532 | |
| 533 | bool |
| 534 | ExecutionContext::HasThreadScope () const |
| 535 | { |
| 536 | return (HasProcessScope() |
| 537 | && ((bool) m_thread_sp && m_thread_sp->IsValid())); |
| 538 | } |
| 539 | |
| 540 | bool |
| 541 | ExecutionContext::HasFrameScope () const |
| 542 | { |
| 543 | return HasThreadScope() && m_frame_sp; |
| 544 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 545 | |
| 546 | ExecutionContextRef::ExecutionContextRef() : |
| 547 | m_target_wp (), |
| 548 | m_process_wp (), |
| 549 | m_thread_wp (), |
Greg Clayton | 6482d23 | 2013-03-15 23:54:07 +0000 | [diff] [blame] | 550 | m_tid(LLDB_INVALID_THREAD_ID), |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 551 | m_stack_id () |
| 552 | { |
| 553 | } |
| 554 | |
| 555 | ExecutionContextRef::ExecutionContextRef (const ExecutionContext *exe_ctx) : |
| 556 | m_target_wp (), |
| 557 | m_process_wp (), |
| 558 | m_thread_wp (), |
Greg Clayton | 6482d23 | 2013-03-15 23:54:07 +0000 | [diff] [blame] | 559 | m_tid(LLDB_INVALID_THREAD_ID), |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 560 | m_stack_id () |
| 561 | { |
| 562 | if (exe_ctx) |
| 563 | *this = *exe_ctx; |
| 564 | } |
| 565 | |
| 566 | ExecutionContextRef::ExecutionContextRef (const ExecutionContext &exe_ctx) : |
| 567 | m_target_wp (), |
| 568 | m_process_wp (), |
| 569 | m_thread_wp (), |
Greg Clayton | 6482d23 | 2013-03-15 23:54:07 +0000 | [diff] [blame] | 570 | m_tid(LLDB_INVALID_THREAD_ID), |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 571 | m_stack_id () |
| 572 | { |
| 573 | *this = exe_ctx; |
| 574 | } |
| 575 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 576 | ExecutionContextRef::ExecutionContextRef (Target *target, bool adopt_selected) : |
| 577 | m_target_wp(), |
| 578 | m_process_wp(), |
| 579 | m_thread_wp(), |
Greg Clayton | 6482d23 | 2013-03-15 23:54:07 +0000 | [diff] [blame] | 580 | m_tid(LLDB_INVALID_THREAD_ID), |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 581 | m_stack_id () |
| 582 | { |
| 583 | SetTargetPtr (target, adopt_selected); |
| 584 | } |
| 585 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 586 | ExecutionContextRef::ExecutionContextRef (const ExecutionContextRef &rhs) : |
| 587 | m_target_wp (rhs.m_target_wp), |
| 588 | m_process_wp(rhs.m_process_wp), |
| 589 | m_thread_wp (rhs.m_thread_wp), |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 590 | m_tid (rhs.m_tid), |
| 591 | m_stack_id (rhs.m_stack_id) |
| 592 | { |
| 593 | } |
| 594 | |
| 595 | ExecutionContextRef & |
| 596 | ExecutionContextRef::operator =(const ExecutionContextRef &rhs) |
| 597 | { |
| 598 | if (this != &rhs) |
| 599 | { |
| 600 | m_target_wp = rhs.m_target_wp; |
| 601 | m_process_wp = rhs.m_process_wp; |
| 602 | m_thread_wp = rhs.m_thread_wp; |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 603 | m_tid = rhs.m_tid; |
| 604 | m_stack_id = rhs.m_stack_id; |
| 605 | } |
| 606 | return *this; |
| 607 | } |
| 608 | |
| 609 | ExecutionContextRef & |
| 610 | ExecutionContextRef::operator =(const ExecutionContext &exe_ctx) |
| 611 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 612 | m_target_wp = exe_ctx.GetTargetSP(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 613 | m_process_wp = exe_ctx.GetProcessSP(); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 614 | lldb::ThreadSP thread_sp (exe_ctx.GetThreadSP()); |
| 615 | m_thread_wp = thread_sp; |
| 616 | if (thread_sp) |
| 617 | m_tid = thread_sp->GetID(); |
| 618 | else |
| 619 | m_tid = LLDB_INVALID_THREAD_ID; |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 620 | lldb::StackFrameSP frame_sp (exe_ctx.GetFrameSP()); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 621 | if (frame_sp) |
| 622 | m_stack_id = frame_sp->GetStackID(); |
| 623 | else |
| 624 | m_stack_id.Clear(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 625 | return *this; |
| 626 | } |
| 627 | |
| 628 | void |
| 629 | ExecutionContextRef::Clear() |
| 630 | { |
| 631 | m_target_wp.reset(); |
| 632 | m_process_wp.reset(); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 633 | ClearThread(); |
| 634 | ClearFrame(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 637 | ExecutionContextRef::~ExecutionContextRef() = default; |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 638 | |
| 639 | void |
| 640 | ExecutionContextRef::SetTargetSP (const lldb::TargetSP &target_sp) |
| 641 | { |
| 642 | m_target_wp = target_sp; |
| 643 | } |
| 644 | |
| 645 | void |
| 646 | ExecutionContextRef::SetProcessSP (const lldb::ProcessSP &process_sp) |
| 647 | { |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 648 | if (process_sp) |
| 649 | { |
| 650 | m_process_wp = process_sp; |
| 651 | SetTargetSP (process_sp->GetTarget().shared_from_this()); |
| 652 | } |
| 653 | else |
| 654 | { |
| 655 | m_process_wp.reset(); |
| 656 | m_target_wp.reset(); |
| 657 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | void |
| 661 | ExecutionContextRef::SetThreadSP (const lldb::ThreadSP &thread_sp) |
| 662 | { |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 663 | if (thread_sp) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 664 | { |
| 665 | m_thread_wp = thread_sp; |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 666 | m_tid = thread_sp->GetID(); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 667 | SetProcessSP (thread_sp->GetProcess()); |
| 668 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 669 | else |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 670 | { |
| 671 | ClearThread(); |
| 672 | m_process_wp.reset(); |
| 673 | m_target_wp.reset(); |
| 674 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 678 | ExecutionContextRef::SetFrameSP (const lldb::StackFrameSP &frame_sp) |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 679 | { |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 680 | if (frame_sp) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 681 | { |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 682 | m_stack_id = frame_sp->GetStackID(); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 683 | SetThreadSP (frame_sp->GetThread()); |
| 684 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 685 | else |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 686 | { |
| 687 | ClearFrame(); |
| 688 | ClearThread(); |
| 689 | m_process_wp.reset(); |
| 690 | m_target_wp.reset(); |
| 691 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | void |
| 695 | ExecutionContextRef::SetTargetPtr (Target* target, bool adopt_selected) |
| 696 | { |
| 697 | Clear(); |
| 698 | if (target) |
| 699 | { |
| 700 | lldb::TargetSP target_sp (target->shared_from_this()); |
| 701 | if (target_sp) |
| 702 | { |
| 703 | m_target_wp = target_sp; |
| 704 | if (adopt_selected) |
| 705 | { |
| 706 | lldb::ProcessSP process_sp (target_sp->GetProcessSP()); |
| 707 | if (process_sp) |
| 708 | { |
| 709 | m_process_wp = process_sp; |
| 710 | if (process_sp) |
| 711 | { |
Greg Clayton | 9b5450f | 2012-07-30 22:05:39 +0000 | [diff] [blame] | 712 | // Only fill in the thread and frame if our process is stopped |
Jim Ingham | d5ac1ab | 2015-01-19 23:51:51 +0000 | [diff] [blame] | 713 | // Don't just check the state, since we might be in the middle of |
| 714 | // resuming. |
| 715 | Process::StopLocker stop_locker; |
| 716 | |
| 717 | if (stop_locker.TryLock(&process_sp->GetRunLock()) && StateIsStoppedState (process_sp->GetState(), true)) |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 718 | { |
Greg Clayton | 9b5450f | 2012-07-30 22:05:39 +0000 | [diff] [blame] | 719 | lldb::ThreadSP thread_sp (process_sp->GetThreadList().GetSelectedThread()); |
| 720 | if (!thread_sp) |
| 721 | thread_sp = process_sp->GetThreadList().GetThreadAtIndex(0); |
| 722 | |
| 723 | if (thread_sp) |
| 724 | { |
| 725 | SetThreadSP (thread_sp); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 726 | lldb::StackFrameSP frame_sp (thread_sp->GetSelectedFrame()); |
Greg Clayton | 9b5450f | 2012-07-30 22:05:39 +0000 | [diff] [blame] | 727 | if (!frame_sp) |
| 728 | frame_sp = thread_sp->GetStackFrameAtIndex(0); |
| 729 | if (frame_sp) |
| 730 | SetFrameSP (frame_sp); |
| 731 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | void |
| 741 | ExecutionContextRef::SetProcessPtr (Process *process) |
| 742 | { |
| 743 | if (process) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 744 | { |
| 745 | SetProcessSP(process->shared_from_this()); |
| 746 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 747 | else |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 748 | { |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 749 | m_process_wp.reset(); |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 750 | m_target_wp.reset(); |
| 751 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | void |
| 755 | ExecutionContextRef::SetThreadPtr (Thread *thread) |
| 756 | { |
| 757 | if (thread) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 758 | { |
| 759 | SetThreadSP (thread->shared_from_this()); |
| 760 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 761 | else |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 762 | { |
| 763 | ClearThread(); |
| 764 | m_process_wp.reset(); |
| 765 | m_target_wp.reset(); |
| 766 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 770 | ExecutionContextRef::SetFramePtr (StackFrame *frame) |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 771 | { |
| 772 | if (frame) |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 773 | SetFrameSP (frame->shared_from_this()); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 774 | else |
Greg Clayton | 7fdf9ef | 2012-04-05 16:12:35 +0000 | [diff] [blame] | 775 | Clear(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 778 | lldb::TargetSP |
| 779 | ExecutionContextRef::GetTargetSP () const |
| 780 | { |
| 781 | lldb::TargetSP target_sp(m_target_wp.lock()); |
| 782 | if (target_sp && !target_sp->IsValid()) |
| 783 | target_sp.reset(); |
| 784 | return target_sp; |
| 785 | } |
| 786 | |
| 787 | lldb::ProcessSP |
| 788 | ExecutionContextRef::GetProcessSP () const |
| 789 | { |
| 790 | lldb::ProcessSP process_sp(m_process_wp.lock()); |
| 791 | if (process_sp && !process_sp->IsValid()) |
| 792 | process_sp.reset(); |
| 793 | return process_sp; |
| 794 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 795 | |
| 796 | lldb::ThreadSP |
| 797 | ExecutionContextRef::GetThreadSP () const |
| 798 | { |
| 799 | lldb::ThreadSP thread_sp (m_thread_wp.lock()); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 800 | |
Greg Clayton | 0b88d81 | 2012-04-04 20:43:47 +0000 | [diff] [blame] | 801 | if (m_tid != LLDB_INVALID_THREAD_ID) |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 802 | { |
Greg Clayton | 0b88d81 | 2012-04-04 20:43:47 +0000 | [diff] [blame] | 803 | // We check if the thread has been destroyed in cases where clients |
| 804 | // might still have shared pointer to a thread, but the thread is |
| 805 | // not valid anymore (not part of the process) |
| 806 | if (!thread_sp || !thread_sp->IsValid()) |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 807 | { |
Greg Clayton | 0b88d81 | 2012-04-04 20:43:47 +0000 | [diff] [blame] | 808 | lldb::ProcessSP process_sp(GetProcessSP()); |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 809 | if (process_sp && process_sp->IsValid()) |
Greg Clayton | 0b88d81 | 2012-04-04 20:43:47 +0000 | [diff] [blame] | 810 | { |
| 811 | thread_sp = process_sp->GetThreadList().FindThreadByID(m_tid); |
| 812 | m_thread_wp = thread_sp; |
| 813 | } |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 814 | } |
| 815 | } |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 816 | |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 817 | // Check that we aren't about to return an invalid thread sp. We might return a nullptr thread_sp, |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 818 | // but don't return an invalid one. |
| 819 | |
| 820 | if (thread_sp && !thread_sp->IsValid()) |
| 821 | thread_sp.reset(); |
| 822 | |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 823 | return thread_sp; |
| 824 | } |
| 825 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 826 | lldb::StackFrameSP |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 827 | ExecutionContextRef::GetFrameSP () const |
| 828 | { |
Greg Clayton | 7bcb93d | 2013-05-24 00:58:29 +0000 | [diff] [blame] | 829 | if (m_stack_id.IsValid()) |
| 830 | { |
| 831 | lldb::ThreadSP thread_sp (GetThreadSP()); |
| 832 | if (thread_sp) |
| 833 | return thread_sp->GetFrameWithStackID (m_stack_id); |
| 834 | } |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 835 | return lldb::StackFrameSP(); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | ExecutionContext |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 839 | ExecutionContextRef::Lock (bool thread_and_frame_only_if_stopped) const |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 840 | { |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 841 | return ExecutionContext(this, thread_and_frame_only_if_stopped); |
Greg Clayton | cc4d014 | 2012-02-17 07:49:44 +0000 | [diff] [blame] | 842 | } |