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