blob: d0bcdac8789989a3822253d6d389ec27c815ec0b [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//===----------------------------------------------------------------------===//
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
23using namespace lldb_private;
24
25ExecutionContext::ExecutionContext() :
26 target (NULL),
27 process (NULL),
28 thread (NULL),
29 frame (NULL)
30{
31}
32
33ExecutionContext::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 {
Jim Inghamc8332952010-08-26 21:32:51 +000044 thread = process->GetThreadList().GetSelectedThread().get();
Chris Lattner24943d22010-06-08 16:52:24 +000045 if (thread)
Jim Inghamc8332952010-08-26 21:32:51 +000046 frame = thread->GetSelectedFrame().get();
Chris Lattner24943d22010-06-08 16:52:24 +000047 }
48 }
49}
50
51ExecutionContext::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
59ExecutionContext::ExecutionContext (ExecutionContextScope *exe_scope_ptr)
60{
61 if (exe_scope_ptr)
Greg Claytona830adb2010-10-04 01:05:56 +000062 exe_scope_ptr->CalculateExecutionContext (*this);
Chris Lattner24943d22010-06-08 16:52:24 +000063 else
64 {
65 target = NULL;
66 process = NULL;
67 thread = NULL;
68 frame = NULL;
69 }
70}
71
72ExecutionContext::ExecutionContext (ExecutionContextScope &exe_scope_ref)
73{
Greg Claytona830adb2010-10-04 01:05:56 +000074 exe_scope_ref.CalculateExecutionContext (*this);
Chris Lattner24943d22010-06-08 16:52:24 +000075}
76
77void
78ExecutionContext::Clear()
79{
80 target = NULL;
81 process = NULL;
82 thread = NULL;
83 frame = NULL;
84}
85
86
87RegisterContext *
88ExecutionContext::GetRegisterContext () const
89{
90 if (frame)
91 return frame->GetRegisterContext();
92 else if (thread)
93 return thread->GetRegisterContext();
94 return NULL;
95}
96
97ExecutionContextScope *
98ExecutionContext::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}