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