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