ExecutionContext.h revision 567e7f3ba16eb48cb9fd6a2f26f2f7269eb6983c
1//===-- ExecutionContext.h --------------------------------------*- 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#ifndef liblldb_ExecutionContext_h_
12#define liblldb_ExecutionContext_h_
13
14#include "lldb/lldb-private.h"
15
16namespace lldb_private {
17
18//----------------------------------------------------------------------
19/// @class ExecutionContext ExecutionContext.h "lldb/Target/ExecutionContext.h"
20/// @brief A class that contains an execution context.
21///
22/// This baton object can be passed into any function that requires
23/// a context that specifies a process, thread and frame.
24///
25/// Many lldb functions can evaluate or act upon a specific
26/// execution context. An expression could be evaluated for a specific
27/// process, thread, and frame. The thread object contains frames and
28/// can return StackFrame objects given a valid frame index using:
29/// StackFrame * Thread::GetFrameAtIndex (uint32_t idx).
30//----------------------------------------------------------------------
31class ExecutionContext
32{
33public:
34    //------------------------------------------------------------------
35    /// Default Constructor.
36    ///
37    /// Initialize with NULL process and thread, and invalid frame
38    /// index.
39    //------------------------------------------------------------------
40    ExecutionContext();
41
42    ExecutionContext (const ExecutionContext &rhs);
43
44    ExecutionContext &
45    operator =(const ExecutionContext &rhs);
46
47    ExecutionContext (Target* t, bool fill_current_process_thread_frame = true);
48    //------------------------------------------------------------------
49    /// Construct with process, thread, and frame index.
50    ///
51    /// Initialize with process \a p, thread \a t, and frame index \a f.
52    ///
53    /// @param[in] process
54    ///     The process for this execution context.
55    ///
56    /// @param[in] thread
57    ///     The thread for this execution context.
58    ///
59    /// @param[in] frame
60    ///     The frame index for this execution context.
61    //------------------------------------------------------------------
62    ExecutionContext (Process* process,
63                      Thread *thread = NULL,
64                      StackFrame * frame = NULL);
65
66
67    ExecutionContext (ExecutionContextScope *exe_scope);
68
69    ExecutionContext (ExecutionContextScope &exe_scope);
70
71    ~ExecutionContext();
72    //------------------------------------------------------------------
73    /// Clear the object's state.
74    ///
75    /// Sets the process and thread to NULL, and the frame index to an
76    /// invalid value.
77    //------------------------------------------------------------------
78    void
79    Clear ();
80
81    RegisterContext *
82    GetRegisterContext () const;
83
84    ExecutionContextScope *
85    GetBestExecutionContextScope () const;
86
87    Target *
88    GetTargetPtr () const;
89
90    Process *
91    GetProcessPtr () const;
92
93    Thread *
94    GetThreadPtr () const
95    {
96        return m_thread_sp.get();
97    }
98
99    StackFrame *
100    GetFramePtr () const
101    {
102        return m_frame_sp.get();
103    }
104
105    Target &
106    GetTargetRef () const;
107
108    Process &
109    GetProcessRef () const;
110
111    Thread &
112    GetThreadRef () const;
113
114    StackFrame &
115    GetFrameRef () const;
116
117    const lldb::TargetSP &
118    GetTargetSP ()
119    {
120        return m_target_sp;
121    }
122
123    const lldb::ProcessSP &
124    GetProcessSP ()
125    {
126        return m_process_sp;
127    }
128
129    const lldb::ThreadSP &
130    GetThreadSP ()
131    {
132        return m_thread_sp;
133    }
134
135    const lldb::StackFrameSP &
136    GetFrameSP ()
137    {
138        return m_frame_sp;
139    }
140
141    void
142    SetTargetSP (const lldb::TargetSP &target_sp);
143
144    void
145    SetProcessSP (const lldb::ProcessSP &process_sp);
146
147    void
148    SetThreadSP (const lldb::ThreadSP &thread_sp);
149
150    void
151    SetFrameSP (const lldb::StackFrameSP &frame_sp);
152
153    void
154    SetTargetPtr (Target* target);
155
156    void
157    SetProcessPtr (Process *process);
158
159    void
160    SetThreadPtr (Thread *thread);
161
162    void
163    SetFramePtr (StackFrame *frame);
164
165protected:
166    //------------------------------------------------------------------
167    // Member variables
168    //------------------------------------------------------------------
169    lldb::TargetSP m_target_sp;     ///< The target that owns the process/thread/frame
170    lldb::ProcessSP m_process_sp;   ///< The process that owns the thread/frame
171    lldb::ThreadSP m_thread_sp;     ///< The thread that owns the frame
172    lldb::StackFrameSP m_frame_sp;  ///< The stack frame in thread.
173};
174
175} // namespace lldb_private
176
177#endif  // liblldb_ExecutionContext_h_
178