]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Target/ExecutionContext.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Target / ExecutionContext.h
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 #ifndef liblldb_ExecutionContext_h_
11 #define liblldb_ExecutionContext_h_
12
13 #include <mutex>
14
15 #include "lldb/Target/StackID.h"
16 #include "lldb/lldb-private.h"
17
18 namespace lldb_private {
19
20 //===----------------------------------------------------------------------===//
21 /// Execution context objects refer to objects in the execution of the program
22 /// that is being debugged. The consist of one or more of the following
23 /// objects: target, process, thread, and frame. Many objects in the debugger
24 /// need to track different executions contexts. For example, a local function
25 /// variable might have an execution context that refers to a stack frame. A
26 /// global or static variable might refer to a target since a stack frame
27 /// isn't required in order to evaluate a global or static variable (a process
28 /// isn't necessarily needed for a global variable since we might be able to
29 /// read the variable value from a data section in one of the object files in
30 /// a target). There are two types of objects that hold onto execution
31 /// contexts: ExecutionContextRef and ExecutionContext. Both of these objects
32 /// are described below.
33 ///
34 /// Not all objects in an ExecutionContext objects will be valid. If you want
35 /// to refer strongly (ExecutionContext) or weakly (ExecutionContextRef) to a
36 /// process, then only the process and target references will be valid. For
37 /// threads, only the thread, process and target references will be filled in.
38 /// For frames, all of the objects will be filled in.
39 ///
40 /// These classes are designed to be used as baton objects that get passed to
41 /// a wide variety of functions that require execution contexts.
42 //===----------------------------------------------------------------------===//
43
44 //----------------------------------------------------------------------
45 /// @class ExecutionContextRef ExecutionContext.h
46 /// "lldb/Target/ExecutionContext.h"
47 /// A class that holds a weak reference to an execution context.
48 ///
49 /// ExecutionContextRef objects are designed to hold onto an execution context
50 /// that might change over time. For example, if an object wants to refer to a
51 /// stack frame, it should hold onto an ExecutionContextRef to a frame object.
52 /// The backing object that represents the stack frame might change over time
53 /// and instances of this object can track the logical object that refers to a
54 /// frame even if it does change.
55 ///
56 /// These objects also don't keep execution objects around longer than they
57 /// should since they use weak pointers. For example if an object refers to a
58 /// stack frame and a stack frame is no longer in a thread, then a
59 /// ExecutionContextRef object that refers to that frame will not be able to
60 /// get a shared pointer to those objects since they are no longer around.
61 ///
62 /// ExecutionContextRef objects can also be used as objects in classes that
63 /// want to track a "previous execution context". Since the weak references to
64 /// the execution objects (target, process, thread and frame) don't keep these
65 /// objects around, they are safe to keep around.
66 ///
67 /// The general rule of thumb is all long lived objects that want to refer to
68 /// execution contexts should use ExecutionContextRef objects. The
69 /// ExecutionContext class is used to temporarily get shared pointers to any
70 /// execution context objects that are still around so they are guaranteed to
71 /// exist during a function that requires the objects. ExecutionContext
72 /// objects should NOT be used for long term storage since they will keep
73 /// objects alive with extra shared pointer references to these  objects.
74 //----------------------------------------------------------------------
75 class ExecutionContextRef {
76 public:
77   //------------------------------------------------------------------
78   /// Default Constructor.
79   //------------------------------------------------------------------
80   ExecutionContextRef();
81
82   //------------------------------------------------------------------
83   /// Copy Constructor.
84   //------------------------------------------------------------------
85   ExecutionContextRef(const ExecutionContextRef &rhs);
86
87   //------------------------------------------------------------------
88   /// Construct using an ExecutionContext object that might be nullptr.
89   ///
90   /// If \a exe_ctx_ptr is valid, then make weak references to any valid
91   /// objects in the ExecutionContext, otherwise no weak references to any
92   /// execution context objects will be made.
93   //------------------------------------------------------------------
94   ExecutionContextRef(const ExecutionContext *exe_ctx_ptr);
95
96   //------------------------------------------------------------------
97   /// Construct using an ExecutionContext object.
98   ///
99   /// Make weak references to any valid objects in the ExecutionContext.
100   //------------------------------------------------------------------
101   ExecutionContextRef(const ExecutionContext &exe_ctx);
102
103   //------------------------------------------------------------------
104   /// Construct using the target and all the selected items inside of it (the
105   /// process and its selected thread, and the thread's selected frame). If
106   /// there is no selected thread, default to the first thread If there is no
107   /// selected frame, default to the first frame.
108   //------------------------------------------------------------------
109   ExecutionContextRef(Target *target, bool adopt_selected);
110
111   //------------------------------------------------------------------
112   /// Construct using an execution context scope.
113   ///
114   /// If the ExecutionContextScope object is valid and refers to a frame, make
115   /// weak references too the frame, thread, process and target. If the
116   /// ExecutionContextScope object is valid and refers to a thread, make weak
117   /// references too the thread, process and target. If the
118   /// ExecutionContextScope object is valid and refers to a process, make weak
119   /// references too the process and target. If the ExecutionContextScope
120   /// object is valid and refers to a target, make weak references too the
121   /// target.
122   //------------------------------------------------------------------
123   ExecutionContextRef(ExecutionContextScope *exe_scope);
124
125   //------------------------------------------------------------------
126   /// Construct using an execution context scope.
127   ///
128   /// If the ExecutionContextScope object refers to a frame, make weak
129   /// references too the frame, thread, process and target. If the
130   /// ExecutionContextScope object refers to a thread, make weak references
131   /// too the thread, process and target. If the ExecutionContextScope object
132   /// refers to a process, make weak references too the process and target. If
133   /// the ExecutionContextScope object refers to a target, make weak
134   /// references too the target.
135   //------------------------------------------------------------------
136   ExecutionContextRef(ExecutionContextScope &exe_scope);
137
138   ~ExecutionContextRef();
139
140   //------------------------------------------------------------------
141   /// Assignment operator
142   ///
143   /// Copy all weak references in \a rhs.
144   //------------------------------------------------------------------
145   ExecutionContextRef &operator=(const ExecutionContextRef &rhs);
146
147   //------------------------------------------------------------------
148   /// Assignment operator from a ExecutionContext
149   ///
150   /// Make weak references to any strongly referenced objects in \a exe_ctx.
151   //------------------------------------------------------------------
152   ExecutionContextRef &operator=(const ExecutionContext &exe_ctx);
153
154   //------------------------------------------------------------------
155   /// Clear the object's state.
156   ///
157   /// Sets the process and thread to nullptr, and the frame index to an
158   /// invalid value.
159   //------------------------------------------------------------------
160   void Clear();
161
162   //------------------------------------------------------------------
163   /// Set accessor that creates a weak reference to the target referenced in
164   /// \a target_sp.
165   ///
166   /// If \a target_sp is valid this object will create a weak reference to
167   /// that object, otherwise any previous target weak reference contained in
168   /// this object will be reset.
169   ///
170   /// Only the weak reference to the target will be updated, no other weak
171   /// references will be modified. If you want this execution context to make
172   /// a weak reference to the target's process, use the
173   /// ExecutionContextRef::SetContext() functions.
174   ///
175   /// @see ExecutionContextRef::SetContext(const lldb::TargetSP &, bool)
176   //------------------------------------------------------------------
177   void SetTargetSP(const lldb::TargetSP &target_sp);
178
179   //------------------------------------------------------------------
180   /// Set accessor that creates a weak reference to the process referenced in
181   /// \a process_sp.
182   ///
183   /// If \a process_sp is valid this object will create a weak reference to
184   /// that object, otherwise any previous process weak reference contained in
185   /// this object will be reset.
186   ///
187   /// Only the weak reference to the process will be updated, no other weak
188   /// references will be modified. If you want this execution context to make
189   /// a weak reference to the target, use the
190   /// ExecutionContextRef::SetContext() functions.
191   ///
192   /// @see ExecutionContextRef::SetContext(const lldb::ProcessSP &)
193   //------------------------------------------------------------------
194   void SetProcessSP(const lldb::ProcessSP &process_sp);
195
196   //------------------------------------------------------------------
197   /// Set accessor that creates a weak reference to the thread referenced in
198   /// \a thread_sp.
199   ///
200   /// If \a thread_sp is valid this object will create a weak reference to
201   /// that object, otherwise any previous thread weak reference contained in
202   /// this object will be reset.
203   ///
204   /// Only the weak reference to the thread will be updated, no other weak
205   /// references will be modified. If you want this execution context to make
206   /// a weak reference to the thread's process and target, use the
207   /// ExecutionContextRef::SetContext() functions.
208   ///
209   /// @see ExecutionContextRef::SetContext(const lldb::ThreadSP &)
210   //------------------------------------------------------------------
211   void SetThreadSP(const lldb::ThreadSP &thread_sp);
212
213   //------------------------------------------------------------------
214   /// Set accessor that creates a weak reference to the frame referenced in \a
215   /// frame_sp.
216   ///
217   /// If \a frame_sp is valid this object will create a weak reference to that
218   /// object, otherwise any previous frame weak reference contained in this
219   /// object will be reset.
220   ///
221   /// Only the weak reference to the frame will be updated, no other weak
222   /// references will be modified. If you want this execution context to make
223   /// a weak reference to the frame's thread, process and target, use the
224   /// ExecutionContextRef::SetContext() functions.
225   ///
226   /// @see ExecutionContextRef::SetContext(const lldb::StackFrameSP &)
227   //------------------------------------------------------------------
228   void SetFrameSP(const lldb::StackFrameSP &frame_sp);
229
230   void SetTargetPtr(Target *target, bool adopt_selected);
231
232   void SetProcessPtr(Process *process);
233
234   void SetThreadPtr(Thread *thread);
235
236   void SetFramePtr(StackFrame *frame);
237
238   //------------------------------------------------------------------
239   /// Get accessor that creates a strong reference from the weak target
240   /// reference contained in this object.
241   ///
242   /// @returns
243   ///     A shared pointer to a target that is not guaranteed to be valid.
244   //------------------------------------------------------------------
245   lldb::TargetSP GetTargetSP() const;
246
247   //------------------------------------------------------------------
248   /// Get accessor that creates a strong reference from the weak process
249   /// reference contained in this object.
250   ///
251   /// @returns
252   ///     A shared pointer to a process that is not guaranteed to be valid.
253   //------------------------------------------------------------------
254   lldb::ProcessSP GetProcessSP() const;
255
256   //------------------------------------------------------------------
257   /// Get accessor that creates a strong reference from the weak thread
258   /// reference contained in this object.
259   ///
260   /// @returns
261   ///     A shared pointer to a thread that is not guaranteed to be valid.
262   //------------------------------------------------------------------
263   lldb::ThreadSP GetThreadSP() const;
264
265   //------------------------------------------------------------------
266   /// Get accessor that creates a strong reference from the weak frame
267   /// reference contained in this object.
268   ///
269   /// @returns
270   ///     A shared pointer to a frame that is not guaranteed to be valid.
271   //------------------------------------------------------------------
272   lldb::StackFrameSP GetFrameSP() const;
273
274   //------------------------------------------------------------------
275   /// Create an ExecutionContext object from this object.
276   ///
277   /// Create strong references to any execution context objects that are still
278   /// valid. Any of the returned shared pointers in the ExecutionContext
279   /// objects is not guaranteed to be valid. @returns
280   ///     An execution context object that has strong references to
281   ///     any valid weak references in this object.
282   //------------------------------------------------------------------
283   ExecutionContext Lock(bool thread_and_frame_only_if_stopped) const;
284
285   //------------------------------------------------------------------
286   /// Returns true if this object has a weak reference to a thread. The return
287   /// value is only an indication of whether this object has a weak reference
288   /// and does not indicate whether the weak reference is valid or not.
289   //------------------------------------------------------------------
290   bool HasThreadRef() const { return m_tid != LLDB_INVALID_THREAD_ID; }
291
292   //------------------------------------------------------------------
293   /// Returns true if this object has a weak reference to a frame. The return
294   /// value is only an indication of whether this object has a weak reference
295   /// and does not indicate whether the weak reference is valid or not.
296   //------------------------------------------------------------------
297   bool HasFrameRef() const { return m_stack_id.IsValid(); }
298
299   void ClearThread() {
300     m_thread_wp.reset();
301     m_tid = LLDB_INVALID_THREAD_ID;
302   }
303
304   void ClearFrame() { m_stack_id.Clear(); }
305
306 protected:
307   //------------------------------------------------------------------
308   // Member variables
309   //------------------------------------------------------------------
310   lldb::TargetWP m_target_wp;         ///< A weak reference to a target
311   lldb::ProcessWP m_process_wp;       ///< A weak reference to a process
312   mutable lldb::ThreadWP m_thread_wp; ///< A weak reference to a thread
313   lldb::tid_t m_tid;  ///< The thread ID that this object refers to in case the
314                       ///backing object changes
315   StackID m_stack_id; ///< The stack ID that this object refers to in case the
316                       ///backing object changes
317 };
318
319 //----------------------------------------------------------------------
320 /// @class ExecutionContext ExecutionContext.h
321 /// "lldb/Target/ExecutionContext.h"
322 /// A class that contains an execution context.
323 ///
324 /// This baton object can be passed into any function that requires a context
325 /// that specifies a target, process, thread and frame. These objects are
326 /// designed to be used for short term execution context object storage while
327 /// a function might be trying to evaluate something that requires a thread or
328 /// frame. ExecutionContextRef objects can be used to initialize one of these
329 /// objects to turn the weak execution context object references to the
330 /// target, process, thread and frame into strong references (shared pointers)
331 /// so that functions can guarantee that these objects won't go away in the
332 /// middle of a function.
333 ///
334 /// ExecutionContext objects should be used as short lived objects (typically
335 /// on the stack) in order to lock down an execution context for local use and
336 /// for passing down to other functions that also require specific contexts.
337 /// They should NOT be used for long term storage, for long term storage use
338 /// ExecutionContextRef objects.
339 //----------------------------------------------------------------------
340 class ExecutionContext {
341 public:
342   //------------------------------------------------------------------
343   /// Default Constructor.
344   //------------------------------------------------------------------
345   ExecutionContext();
346
347   //------------------------------------------------------------------
348   // Copy constructor
349   //------------------------------------------------------------------
350   ExecutionContext(const ExecutionContext &rhs);
351
352   //------------------------------------------------------------------
353   // Adopt the target and optionally its current context.
354   //------------------------------------------------------------------
355   ExecutionContext(Target *t, bool fill_current_process_thread_frame = true);
356
357   //------------------------------------------------------------------
358   // Create execution contexts from shared pointers
359   //------------------------------------------------------------------
360   ExecutionContext(const lldb::TargetSP &target_sp, bool get_process);
361   ExecutionContext(const lldb::ProcessSP &process_sp);
362   ExecutionContext(const lldb::ThreadSP &thread_sp);
363   ExecutionContext(const lldb::StackFrameSP &frame_sp);
364
365   //------------------------------------------------------------------
366   // Create execution contexts from weak pointers
367   //------------------------------------------------------------------
368   ExecutionContext(const lldb::TargetWP &target_wp, bool get_process);
369   ExecutionContext(const lldb::ProcessWP &process_wp);
370   ExecutionContext(const lldb::ThreadWP &thread_wp);
371   ExecutionContext(const lldb::StackFrameWP &frame_wp);
372   ExecutionContext(const ExecutionContextRef &exe_ctx_ref);
373   ExecutionContext(const ExecutionContextRef *exe_ctx_ref,
374                    bool thread_and_frame_only_if_stopped = false);
375
376   // These two variants take in a locker, and grab the target, lock the API
377   // mutex into locker, then fill in the rest of the shared pointers.
378   ExecutionContext(const ExecutionContextRef &exe_ctx_ref,
379                    std::unique_lock<std::recursive_mutex> &locker);
380   ExecutionContext(const ExecutionContextRef *exe_ctx_ref,
381                    std::unique_lock<std::recursive_mutex> &locker);
382   //------------------------------------------------------------------
383   // Create execution contexts from execution context scopes
384   //------------------------------------------------------------------
385   ExecutionContext(ExecutionContextScope *exe_scope);
386   ExecutionContext(ExecutionContextScope &exe_scope);
387
388   //------------------------------------------------------------------
389   /// Construct with process, thread, and frame index.
390   ///
391   /// Initialize with process \a p, thread \a t, and frame index \a f.
392   ///
393   /// @param[in] process
394   ///     The process for this execution context.
395   ///
396   /// @param[in] thread
397   ///     The thread for this execution context.
398   ///
399   /// @param[in] frame
400   ///     The frame index for this execution context.
401   //------------------------------------------------------------------
402   ExecutionContext(Process *process, Thread *thread = nullptr,
403                    StackFrame *frame = nullptr);
404
405   ~ExecutionContext();
406
407   ExecutionContext &operator=(const ExecutionContext &rhs);
408
409   bool operator==(const ExecutionContext &rhs) const;
410
411   bool operator!=(const ExecutionContext &rhs) const;
412
413   //------------------------------------------------------------------
414   /// Clear the object's state.
415   ///
416   /// Sets the process and thread to nullptr, and the frame index to an
417   /// invalid value.
418   //------------------------------------------------------------------
419   void Clear();
420
421   RegisterContext *GetRegisterContext() const;
422
423   ExecutionContextScope *GetBestExecutionContextScope() const;
424
425   uint32_t GetAddressByteSize() const;
426
427   lldb::ByteOrder GetByteOrder() const;
428
429   //------------------------------------------------------------------
430   /// Returns a pointer to the target object.
431   ///
432   /// The returned pointer might be nullptr. Calling HasTargetScope(),
433   /// HasProcessScope(), HasThreadScope(), or HasFrameScope() can help to pre-
434   /// validate this pointer so that this accessor can freely be used without
435   /// having to check for nullptr each time.
436   ///
437   /// @see ExecutionContext::HasTargetScope() const @see
438   /// ExecutionContext::HasProcessScope() const @see
439   /// ExecutionContext::HasThreadScope() const @see
440   /// ExecutionContext::HasFrameScope() const
441   //------------------------------------------------------------------
442   Target *GetTargetPtr() const;
443
444   //------------------------------------------------------------------
445   /// Returns a pointer to the process object.
446   ///
447   /// The returned pointer might be nullptr. Calling HasProcessScope(),
448   /// HasThreadScope(), or HasFrameScope()  can help to pre-validate this
449   /// pointer so that this accessor can freely be used without having to check
450   /// for nullptr each time.
451   ///
452   /// @see ExecutionContext::HasProcessScope() const @see
453   /// ExecutionContext::HasThreadScope() const @see
454   /// ExecutionContext::HasFrameScope() const
455   //------------------------------------------------------------------
456   Process *GetProcessPtr() const;
457
458   //------------------------------------------------------------------
459   /// Returns a pointer to the thread object.
460   ///
461   /// The returned pointer might be nullptr. Calling HasThreadScope() or
462   /// HasFrameScope() can help to pre-validate this pointer so that this
463   /// accessor can freely be used without having to check for nullptr each
464   /// time.
465   ///
466   /// @see ExecutionContext::HasThreadScope() const @see
467   /// ExecutionContext::HasFrameScope() const
468   //------------------------------------------------------------------
469   Thread *GetThreadPtr() const { return m_thread_sp.get(); }
470
471   //------------------------------------------------------------------
472   /// Returns a pointer to the frame object.
473   ///
474   /// The returned pointer might be nullptr. Calling HasFrameScope(), can help
475   /// to pre-validate this pointer so that this accessor can freely be used
476   /// without having to check for nullptr each time.
477   ///
478   /// @see ExecutionContext::HasFrameScope() const
479   //------------------------------------------------------------------
480   StackFrame *GetFramePtr() const { return m_frame_sp.get(); }
481
482   //------------------------------------------------------------------
483   /// Returns a reference to the target object.
484   ///
485   /// Clients should call HasTargetScope(), HasProcessScope(),
486   /// HasThreadScope(), or HasFrameScope() prior to calling this function to
487   /// ensure that this ExecutionContext object contains a valid target.
488   ///
489   /// @see ExecutionContext::HasTargetScope() const @see
490   /// ExecutionContext::HasProcessScope() const @see
491   /// ExecutionContext::HasThreadScope() const @see
492   /// ExecutionContext::HasFrameScope() const
493   //------------------------------------------------------------------
494   Target &GetTargetRef() const;
495
496   //------------------------------------------------------------------
497   /// Returns a reference to the process object.
498   ///
499   /// Clients should call HasProcessScope(), HasThreadScope(), or
500   /// HasFrameScope() prior to calling this  function to ensure that this
501   /// ExecutionContext object contains a valid target.
502   ///
503   /// @see ExecutionContext::HasProcessScope() const @see
504   /// ExecutionContext::HasThreadScope() const @see
505   /// ExecutionContext::HasFrameScope() const
506   //------------------------------------------------------------------
507   Process &GetProcessRef() const;
508
509   //------------------------------------------------------------------
510   /// Returns a reference to the thread object.
511   ///
512   /// Clients should call HasThreadScope(), or  HasFrameScope() prior to
513   /// calling this  function to ensure that  this ExecutionContext object
514   /// contains a valid target.
515   ///
516   /// @see ExecutionContext::HasThreadScope() const @see
517   /// ExecutionContext::HasFrameScope() const
518   //------------------------------------------------------------------
519   Thread &GetThreadRef() const;
520
521   //------------------------------------------------------------------
522   /// Returns a reference to the thread object.
523   ///
524   /// Clients should call HasFrameScope() prior to calling this function to
525   /// ensure that  this ExecutionContext object contains a valid target.
526   ///
527   /// @see ExecutionContext::HasFrameScope() const
528   //------------------------------------------------------------------
529   StackFrame &GetFrameRef() const;
530
531   //------------------------------------------------------------------
532   /// Get accessor to get the target shared pointer.
533   ///
534   /// The returned shared pointer is not guaranteed to be valid.
535   //------------------------------------------------------------------
536   const lldb::TargetSP &GetTargetSP() const { return m_target_sp; }
537
538   //------------------------------------------------------------------
539   /// Get accessor to get the process shared pointer.
540   ///
541   /// The returned shared pointer is not guaranteed to be valid.
542   //------------------------------------------------------------------
543   const lldb::ProcessSP &GetProcessSP() const { return m_process_sp; }
544
545   //------------------------------------------------------------------
546   /// Get accessor to get the thread shared pointer.
547   ///
548   /// The returned shared pointer is not guaranteed to be valid.
549   //------------------------------------------------------------------
550   const lldb::ThreadSP &GetThreadSP() const { return m_thread_sp; }
551
552   //------------------------------------------------------------------
553   /// Get accessor to get the frame shared pointer.
554   ///
555   /// The returned shared pointer is not guaranteed to be valid.
556   //------------------------------------------------------------------
557   const lldb::StackFrameSP &GetFrameSP() const { return m_frame_sp; }
558
559   //------------------------------------------------------------------
560   /// Set accessor to set only the target shared pointer.
561   //------------------------------------------------------------------
562   void SetTargetSP(const lldb::TargetSP &target_sp);
563
564   //------------------------------------------------------------------
565   /// Set accessor to set only the process shared pointer.
566   //------------------------------------------------------------------
567   void SetProcessSP(const lldb::ProcessSP &process_sp);
568
569   //------------------------------------------------------------------
570   /// Set accessor to set only the thread shared pointer.
571   //------------------------------------------------------------------
572   void SetThreadSP(const lldb::ThreadSP &thread_sp);
573
574   //------------------------------------------------------------------
575   /// Set accessor to set only the frame shared pointer.
576   //------------------------------------------------------------------
577   void SetFrameSP(const lldb::StackFrameSP &frame_sp);
578
579   //------------------------------------------------------------------
580   /// Set accessor to set only the target shared pointer from a target
581   /// pointer.
582   //------------------------------------------------------------------
583   void SetTargetPtr(Target *target);
584
585   //------------------------------------------------------------------
586   /// Set accessor to set only the process shared pointer from a process
587   /// pointer.
588   //------------------------------------------------------------------
589   void SetProcessPtr(Process *process);
590
591   //------------------------------------------------------------------
592   /// Set accessor to set only the thread shared pointer from a thread
593   /// pointer.
594   //------------------------------------------------------------------
595   void SetThreadPtr(Thread *thread);
596
597   //------------------------------------------------------------------
598   /// Set accessor to set only the frame shared pointer from a frame pointer.
599   //------------------------------------------------------------------
600   void SetFramePtr(StackFrame *frame);
601
602   //------------------------------------------------------------------
603   // Set the execution context using a target shared pointer.
604   //
605   // If "target_sp" is valid, sets the target context to match and if
606   // "get_process" is true, sets the process shared pointer if the target
607   // currently has a process.
608   //------------------------------------------------------------------
609   void SetContext(const lldb::TargetSP &target_sp, bool get_process);
610
611   //------------------------------------------------------------------
612   // Set the execution context using a process shared pointer.
613   //
614   // If "process_sp" is valid, then set the process and target in this context.
615   // Thread and frame contexts will be cleared. If "process_sp" is not valid,
616   // all shared pointers are reset.
617   //------------------------------------------------------------------
618   void SetContext(const lldb::ProcessSP &process_sp);
619
620   //------------------------------------------------------------------
621   // Set the execution context using a thread shared pointer.
622   //
623   // If "thread_sp" is valid, then set the thread, process and target in this
624   // context. The frame context will be cleared. If "thread_sp" is not valid,
625   // all shared pointers are reset.
626   //------------------------------------------------------------------
627   void SetContext(const lldb::ThreadSP &thread_sp);
628
629   //------------------------------------------------------------------
630   // Set the execution context using a frame shared pointer.
631   //
632   // If "frame_sp" is valid, then set the frame, thread, process and target in
633   // this context If "frame_sp" is not valid, all shared pointers are reset.
634   //------------------------------------------------------------------
635   void SetContext(const lldb::StackFrameSP &frame_sp);
636
637   //------------------------------------------------------------------
638   /// Returns true the ExecutionContext object contains a valid target.
639   ///
640   /// This function can be called after initializing an ExecutionContext
641   /// object, and if it returns true, calls to GetTargetPtr() and
642   /// GetTargetRef() do not need to be checked for validity.
643   //------------------------------------------------------------------
644   bool HasTargetScope() const;
645
646   //------------------------------------------------------------------
647   /// Returns true the ExecutionContext object contains a valid target and
648   /// process.
649   ///
650   /// This function can be called after initializing an ExecutionContext
651   /// object, and if it returns true, calls to GetTargetPtr() and
652   /// GetTargetRef(), GetProcessPtr(), and GetProcessRef(), do not need to be
653   /// checked for validity.
654   //------------------------------------------------------------------
655   bool HasProcessScope() const;
656
657   //------------------------------------------------------------------
658   /// Returns true the ExecutionContext object contains a valid target,
659   /// process, and thread.
660   ///
661   /// This function can be called after initializing an ExecutionContext
662   /// object, and if it returns true, calls to GetTargetPtr(), GetTargetRef(),
663   /// GetProcessPtr(), GetProcessRef(), GetThreadPtr(), and GetThreadRef() do
664   /// not need to be checked for validity.
665   //------------------------------------------------------------------
666   bool HasThreadScope() const;
667
668   //------------------------------------------------------------------
669   /// Returns true the ExecutionContext object contains a valid target,
670   /// process, thread and frame.
671   ///
672   /// This function can be called after initializing an ExecutionContext
673   /// object, and if it returns true, calls to GetTargetPtr(), GetTargetRef(),
674   /// GetProcessPtr(), GetProcessRef(), GetThreadPtr(), GetThreadRef(),
675   /// GetFramePtr(), and GetFrameRef() do not need to be checked for validity.
676   //------------------------------------------------------------------
677   bool HasFrameScope() const;
678
679 protected:
680   //------------------------------------------------------------------
681   // Member variables
682   //------------------------------------------------------------------
683   lldb::TargetSP m_target_sp; ///< The target that owns the process/thread/frame
684   lldb::ProcessSP m_process_sp;  ///< The process that owns the thread/frame
685   lldb::ThreadSP m_thread_sp;    ///< The thread that owns the frame
686   lldb::StackFrameSP m_frame_sp; ///< The stack frame in thread.
687 };
688
689 } // namespace lldb_private
690
691 #endif // liblldb_ExecutionContext_h_