blob: 581ba6a9952e1d98476233958abcdb5eea1f4f5e [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() :
20 target (NULL),
21 process (NULL),
22 thread (NULL),
23 frame (NULL)
24{
25}
26
27ExecutionContext::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 Inghamc8332952010-08-26 21:32:51 +000038 thread = process->GetThreadList().GetSelectedThread().get();
Chris Lattner24943d22010-06-08 16:52:24 +000039 if (thread)
Jim Inghamc8332952010-08-26 21:32:51 +000040 frame = thread->GetSelectedFrame().get();
Chris Lattner24943d22010-06-08 16:52:24 +000041 }
42 }
43}
44
45ExecutionContext::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
53ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr)
54{
55 if (exe_scope_ptr)
Greg Claytona830adb2010-10-04 01:05:56 +000056 exe_scope_ptr->CalculateExecutionContext (*this);
Chris Lattner24943d22010-06-08 16:52:24 +000057 else
58 {
59 target = NULL;
60 process = NULL;
61 thread = NULL;
62 frame = NULL;
63 }
64}
65
66ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref)
67{
Greg Claytona830adb2010-10-04 01:05:56 +000068 exe_scope_ref.CalculateExecutionContext (*this);
Chris Lattner24943d22010-06-08 16:52:24 +000069}
70
71void
72ExecutionContext::Clear()
73{
74 target = NULL;
75 process = NULL;
76 thread = NULL;
77 frame = NULL;
78}
79
80
81RegisterContext *
82ExecutionContext::GetRegisterContext () const
83{
84 if (frame)
Greg Clayton08d7d3a2011-01-06 22:15:06 +000085 return frame->GetRegisterContext().get();
Chris Lattner24943d22010-06-08 16:52:24 +000086 else if (thread)
Greg Clayton08d7d3a2011-01-06 22:15:06 +000087 return thread->GetRegisterContext().get();
Chris Lattner24943d22010-06-08 16:52:24 +000088 return NULL;
89}
90
91ExecutionContextScope *
92ExecutionContext::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}