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 //===----------------------------------------------------------------------===// 9 // 10 // 11 12 // 13 //===----------------------------------------------------------------------===// 14 15 16 #include "lldb/Target/ExecutionContext.h" 17 #include "lldb/Target/ExecutionContextScope.h" 18 #include "lldb/Target/StackFrame.h" 19 #include "lldb/Target/Process.h" 20 #include "lldb/Target/Target.h" 21 #include "lldb/Target/Thread.h" 22 23 using namespace lldb_private; 24 25 ExecutionContext::ExecutionContext() : 26 target (NULL), 27 process (NULL), 28 thread (NULL), 29 frame (NULL) 30 { 31 } 32 33 ExecutionContext::ExecutionContext (Target* t, bool fill_current_process_thread_frame) : 34 target (t), 35 process (NULL), 36 thread (NULL), 37 frame (NULL) 38 { 39 if (t && fill_current_process_thread_frame) 40 { 41 process = t->GetProcessSP().get(); 42 if (process) 43 { 44 thread = process->GetThreadList().GetCurrentThread().get(); 45 if (thread) 46 frame = thread->GetCurrentFrame().get(); 47 } 48 } 49 } 50 51 ExecutionContext::ExecutionContext(Process* p, Thread *t, StackFrame *f) : 52 target (p ? &p->GetTarget() : NULL), 53 process (p), 54 thread (t), 55 frame (f) 56 { 57 } 58 59 ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr) 60 { 61 if (exe_scope_ptr) 62 exe_scope_ptr->Calculate (*this); 63 else 64 { 65 target = NULL; 66 process = NULL; 67 thread = NULL; 68 frame = NULL; 69 } 70 } 71 72 ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref) 73 { 74 exe_scope_ref.Calculate (*this); 75 } 76 77 void 78 ExecutionContext::Clear() 79 { 80 target = NULL; 81 process = NULL; 82 thread = NULL; 83 frame = NULL; 84 } 85 86 87 RegisterContext * 88 ExecutionContext::GetRegisterContext () const 89 { 90 if (frame) 91 return frame->GetRegisterContext(); 92 else if (thread) 93 return thread->GetRegisterContext(); 94 return NULL; 95 } 96 97 ExecutionContextScope * 98 ExecutionContext::GetBestExecutionContextScope () const 99 { 100 if (frame) 101 return frame; 102 if (thread) 103 return thread; 104 if (process) 105 return process; 106 return target; 107 } 108