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() : |
| 20 | target (NULL), |
| 21 | process (NULL), |
| 22 | thread (NULL), |
| 23 | frame (NULL) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) : |
| 28 | target (t), |
| 29 | process (NULL), |
| 30 | thread (NULL), |
| 31 | frame (NULL) |
| 32 | { |
| 33 | if (t && fill_current_process_thread_frame) |
| 34 | { |
| 35 | process = t->GetProcessSP().get(); |
| 36 | if (process) |
| 37 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 38 | thread = process->GetThreadList().GetSelectedThread().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | if (thread) |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 40 | frame = thread->GetSelectedFrame().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | ExecutionContext::ExecutionContext(Process* p, Thread *t, StackFrame *f) : |
| 46 | target (p ? &p->GetTarget() : NULL), |
| 47 | process (p), |
| 48 | thread (t), |
| 49 | frame (f) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr) |
| 54 | { |
| 55 | if (exe_scope_ptr) |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 56 | exe_scope_ptr->CalculateExecutionContext (*this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | else |
| 58 | { |
| 59 | target = NULL; |
| 60 | process = NULL; |
| 61 | thread = NULL; |
| 62 | frame = NULL; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref) |
| 67 | { |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 68 | exe_scope_ref.CalculateExecutionContext (*this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void |
| 72 | ExecutionContext::Clear() |
| 73 | { |
| 74 | target = NULL; |
| 75 | process = NULL; |
| 76 | thread = NULL; |
| 77 | frame = NULL; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | RegisterContext * |
| 82 | ExecutionContext::GetRegisterContext () const |
| 83 | { |
| 84 | if (frame) |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 85 | return frame->GetRegisterContext().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | else if (thread) |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 87 | return thread->GetRegisterContext().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | return NULL; |
| 89 | } |
| 90 | |
| 91 | ExecutionContextScope * |
| 92 | ExecutionContext::GetBestExecutionContextScope () const |
| 93 | { |
| 94 | if (frame) |
| 95 | return frame; |
| 96 | if (thread) |
| 97 | return thread; |
| 98 | if (process) |
| 99 | return process; |
| 100 | return target; |
| 101 | } |
Greg Clayton | 801417e | 2011-07-07 01:59:51 +0000 | [diff] [blame^] | 102 | |
| 103 | Process * |
| 104 | ExecutionContext::GetProcess () const |
| 105 | { |
| 106 | if (process) |
| 107 | return process; |
| 108 | if (target) |
| 109 | return target->GetProcessSP().get(); |
| 110 | return NULL; |
| 111 | } |