ExecutionContext.h revision f4124deeb9532044a38c0774ced872f2709347da
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 41namespace lldb_private { 42 43//---------------------------------------------------------------------- 44/// @class ExecutionContextRef ExecutionContext.h "lldb/Target/ExecutionContext.h" 45/// @brief A class that holds a weak reference to an execution context. 46/// 47/// ExecutionContextRef objects are designed to hold onto an execution 48/// context that might change over time. For example, if an object wants 49/// to refer to a stack frame, it should hold onto an ExecutionContextRef 50/// to a frame object. The backing object that represents the stack frame 51/// might change over time and instaces of this object can track the logical 52/// 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 332protected: 333 //------------------------------------------------------------------ 334 // Member variables 335 //------------------------------------------------------------------ 336 lldb::TargetWP m_target_wp; ///< A weak reference to a target 337 lldb::ProcessWP m_process_wp; ///< A weak reference to a process 338 mutable lldb::ThreadWP m_thread_wp; ///< A weak reference to a thread 339 mutable lldb::StackFrameWP m_frame_wp; ///< A weak reference to a frame 340 lldb::tid_t m_tid; ///< The thread ID that this object refers to in case the backing object changes 341 StackID m_stack_id; ///< The stack ID that this object refers to in case the backing object changes 342}; 343 344//---------------------------------------------------------------------- 345/// @class ExecutionContext ExecutionContext.h "lldb/Target/ExecutionContext.h" 346/// @brief A class that contains an execution context. 347/// 348/// This baton object can be passed into any function that requires 349/// a context that specifies a target, process, thread and frame. 350/// These objects are designed to be used for short term execution 351/// context object storage while a function might be trying to evaluate 352/// something that requires a thread or frame. ExecutionContextRef 353/// objects can be used to initialize one of these objects to turn 354/// the weak execution context object references to the target, process, 355/// thread and frame into strong references (shared pointers) so that 356/// functions can guarantee that these objects won't go away in the 357/// middle of a function. 358/// 359/// ExecutionContext objects should be used as short lived objects 360/// (typically on the stack) in order to lock down an execution context 361/// for local use and for passing down to other functions that also 362/// require specific contexts. They should NOT be used for long term 363/// storage, for long term storage use ExecutionContextRef objects. 364//---------------------------------------------------------------------- 365class ExecutionContext 366{ 367public: 368 //------------------------------------------------------------------ 369 /// Default Constructor. 370 //------------------------------------------------------------------ 371 ExecutionContext(); 372 373 //------------------------------------------------------------------ 374 // Copy constructor 375 //------------------------------------------------------------------ 376 ExecutionContext (const ExecutionContext &rhs); 377 378 //------------------------------------------------------------------ 379 // Adopt the target and optionally its current context. 380 //------------------------------------------------------------------ 381 ExecutionContext (Target* t, bool fill_current_process_thread_frame = true); 382 383 //------------------------------------------------------------------ 384 // Create execution contexts from shared pointers 385 //------------------------------------------------------------------ 386 ExecutionContext (const lldb::TargetSP &target_sp, bool get_process); 387 ExecutionContext (const lldb::ProcessSP &process_sp); 388 ExecutionContext (const lldb::ThreadSP &thread_sp); 389 ExecutionContext (const lldb::StackFrameSP &frame_sp); 390 //------------------------------------------------------------------ 391 // Create execution contexts from weak pointers 392 //------------------------------------------------------------------ 393 ExecutionContext (const lldb::TargetWP &target_wp, bool get_process); 394 ExecutionContext (const lldb::ProcessWP &process_wp); 395 ExecutionContext (const lldb::ThreadWP &thread_wp); 396 ExecutionContext (const lldb::StackFrameWP &frame_wp); 397 ExecutionContext (const ExecutionContextRef &exe_ctx_ref); 398 ExecutionContext (const ExecutionContextRef *exe_ctx_ref); 399 //------------------------------------------------------------------ 400 // Create execution contexts from execution context scopes 401 //------------------------------------------------------------------ 402 ExecutionContext (ExecutionContextScope *exe_scope); 403 ExecutionContext (ExecutionContextScope &exe_scope); 404 405 406 ExecutionContext & 407 operator =(const ExecutionContext &rhs); 408 409 bool 410 operator ==(const ExecutionContext &rhs) const; 411 412 bool 413 operator !=(const ExecutionContext &rhs) const; 414 415 //------------------------------------------------------------------ 416 /// Construct with process, thread, and frame index. 417 /// 418 /// Initialize with process \a p, thread \a t, and frame index \a f. 419 /// 420 /// @param[in] process 421 /// The process for this execution context. 422 /// 423 /// @param[in] thread 424 /// The thread for this execution context. 425 /// 426 /// @param[in] frame 427 /// The frame index for this execution context. 428 //------------------------------------------------------------------ 429 ExecutionContext (Process* process, 430 Thread *thread = NULL, 431 StackFrame * frame = NULL); 432 433 434 ~ExecutionContext(); 435 //------------------------------------------------------------------ 436 /// Clear the object's state. 437 /// 438 /// Sets the process and thread to NULL, and the frame index to an 439 /// invalid value. 440 //------------------------------------------------------------------ 441 void 442 Clear (); 443 444 RegisterContext * 445 GetRegisterContext () const; 446 447 ExecutionContextScope * 448 GetBestExecutionContextScope () const; 449 450 uint32_t 451 GetAddressByteSize() const; 452 453 //------------------------------------------------------------------ 454 /// Returns a pointer to the target object. 455 /// 456 /// The returned pointer might be NULL. Calling HasTargetScope(), 457 /// HasProcessScope(), HasThreadScope(), or HasFrameScope() 458 /// can help to pre-validate this pointer so that this accessor can 459 /// freely be used without having to check for NULL each time. 460 /// 461 /// @see ExecutionContext::HasTargetScope() const 462 /// @see ExecutionContext::HasProcessScope() const 463 /// @see ExecutionContext::HasThreadScope() const 464 /// @see ExecutionContext::HasFrameScope() const 465 //------------------------------------------------------------------ 466 Target * 467 GetTargetPtr () const; 468 469 //------------------------------------------------------------------ 470 /// Returns a pointer to the process object. 471 /// 472 /// The returned pointer might be NULL. Calling HasProcessScope(), 473 /// HasThreadScope(), or HasFrameScope() can help to pre-validate 474 /// this pointer so that this accessor can freely be used without 475 /// having to check for NULL each time. 476 /// 477 /// @see ExecutionContext::HasProcessScope() const 478 /// @see ExecutionContext::HasThreadScope() const 479 /// @see ExecutionContext::HasFrameScope() const 480 //------------------------------------------------------------------ 481 Process * 482 GetProcessPtr () const; 483 484 //------------------------------------------------------------------ 485 /// Returns a pointer to the thread object. 486 /// 487 /// The returned pointer might be NULL. Calling HasThreadScope() or 488 /// HasFrameScope() can help to pre-validate this pointer so that 489 /// this accessor can freely be used without having to check for 490 /// NULL each time. 491 /// 492 /// @see ExecutionContext::HasThreadScope() const 493 /// @see ExecutionContext::HasFrameScope() const 494 //------------------------------------------------------------------ 495 Thread * 496 GetThreadPtr () const 497 { 498 return m_thread_sp.get(); 499 } 500 501 //------------------------------------------------------------------ 502 /// Returns a pointer to the frame object. 503 /// 504 /// The returned pointer might be NULL. Calling HasFrameScope(), 505 /// can help to pre-validate this pointer so that this accessor can 506 /// freely be used without having to check for NULL each time. 507 /// 508 /// @see ExecutionContext::HasFrameScope() const 509 //------------------------------------------------------------------ 510 StackFrame * 511 GetFramePtr () const 512 { 513 return m_frame_sp.get(); 514 } 515 516 //------------------------------------------------------------------ 517 /// Returns a reference to the target object. 518 /// 519 /// Clients should call HasTargetScope(), HasProcessScope(), 520 /// HasThreadScope(), or HasFrameScope() prior to calling this 521 /// function to ensure that this ExecutionContext object contains 522 /// a valid target. 523 /// 524 /// @see ExecutionContext::HasTargetScope() const 525 /// @see ExecutionContext::HasProcessScope() const 526 /// @see ExecutionContext::HasThreadScope() const 527 /// @see ExecutionContext::HasFrameScope() const 528 //------------------------------------------------------------------ 529 Target & 530 GetTargetRef () const; 531 532 //------------------------------------------------------------------ 533 /// Returns a reference to the process object. 534 /// 535 /// Clients should call HasProcessScope(), HasThreadScope(), or 536 /// HasFrameScope() prior to calling this function to ensure that 537 /// this ExecutionContext object contains a valid target. 538 /// 539 /// @see ExecutionContext::HasProcessScope() const 540 /// @see ExecutionContext::HasThreadScope() const 541 /// @see ExecutionContext::HasFrameScope() const 542 //------------------------------------------------------------------ 543 Process & 544 GetProcessRef () const; 545 546 //------------------------------------------------------------------ 547 /// Returns a reference to the thread object. 548 /// 549 /// Clients should call HasThreadScope(), or HasFrameScope() prior 550 /// to calling this function to ensure that this ExecutionContext 551 /// object contains a valid target. 552 /// 553 /// @see ExecutionContext::HasThreadScope() const 554 /// @see ExecutionContext::HasFrameScope() const 555 //------------------------------------------------------------------ 556 Thread & 557 GetThreadRef () const; 558 559 //------------------------------------------------------------------ 560 /// Returns a reference to the thread object. 561 /// 562 /// Clients should call HasFrameScope() prior to calling this 563 /// function to ensure that this ExecutionContext object contains 564 /// a valid target. 565 /// 566 /// @see ExecutionContext::HasFrameScope() const 567 //------------------------------------------------------------------ 568 StackFrame & 569 GetFrameRef () const; 570 571 //------------------------------------------------------------------ 572 /// Get accessor to get the target shared pointer. 573 /// 574 /// The returned shared pointer is not guaranteed to be valid. 575 //------------------------------------------------------------------ 576 const lldb::TargetSP & 577 GetTargetSP () const 578 { 579 return m_target_sp; 580 } 581 582 //------------------------------------------------------------------ 583 /// Get accessor to get the process shared pointer. 584 /// 585 /// The returned shared pointer is not guaranteed to be valid. 586 //------------------------------------------------------------------ 587 const lldb::ProcessSP & 588 GetProcessSP () const 589 { 590 return m_process_sp; 591 } 592 593 //------------------------------------------------------------------ 594 /// Get accessor to get the thread shared pointer. 595 /// 596 /// The returned shared pointer is not guaranteed to be valid. 597 //------------------------------------------------------------------ 598 const lldb::ThreadSP & 599 GetThreadSP () const 600 { 601 return m_thread_sp; 602 } 603 604 //------------------------------------------------------------------ 605 /// Get accessor to get the frame shared pointer. 606 /// 607 /// The returned shared pointer is not guaranteed to be valid. 608 //------------------------------------------------------------------ 609 const lldb::StackFrameSP & 610 GetFrameSP () const 611 { 612 return m_frame_sp; 613 } 614 615 //------------------------------------------------------------------ 616 /// Set accessor to set only the target shared pointer. 617 //------------------------------------------------------------------ 618 void 619 SetTargetSP (const lldb::TargetSP &target_sp); 620 621 //------------------------------------------------------------------ 622 /// Set accessor to set only the process shared pointer. 623 //------------------------------------------------------------------ 624 void 625 SetProcessSP (const lldb::ProcessSP &process_sp); 626 627 //------------------------------------------------------------------ 628 /// Set accessor to set only the thread shared pointer. 629 //------------------------------------------------------------------ 630 void 631 SetThreadSP (const lldb::ThreadSP &thread_sp); 632 633 //------------------------------------------------------------------ 634 /// Set accessor to set only the frame shared pointer. 635 //------------------------------------------------------------------ 636 void 637 SetFrameSP (const lldb::StackFrameSP &frame_sp); 638 639 //------------------------------------------------------------------ 640 /// Set accessor to set only the target shared pointer from a target 641 /// pointer. 642 //------------------------------------------------------------------ 643 void 644 SetTargetPtr (Target* target); 645 646 //------------------------------------------------------------------ 647 /// Set accessor to set only the process shared pointer from a 648 /// process pointer. 649 //------------------------------------------------------------------ 650 void 651 SetProcessPtr (Process *process); 652 653 //------------------------------------------------------------------ 654 /// Set accessor to set only the thread shared pointer from a thread 655 /// pointer. 656 //------------------------------------------------------------------ 657 void 658 SetThreadPtr (Thread *thread); 659 660 //------------------------------------------------------------------ 661 /// Set accessor to set only the frame shared pointer from a frame 662 /// pointer. 663 //------------------------------------------------------------------ 664 void 665 SetFramePtr (StackFrame *frame); 666 667 //------------------------------------------------------------------ 668 // Set the execution context using a target shared pointer. 669 // 670 // If "target_sp" is valid, sets the target context to match and 671 // if "get_process" is true, sets the process shared pointer if 672 // the target currently has a process. 673 //------------------------------------------------------------------ 674 void 675 SetContext (const lldb::TargetSP &target_sp, bool get_process); 676 677 //------------------------------------------------------------------ 678 // Set the execution context using a process shared pointer. 679 // 680 // If "process_sp" is valid, then set the process and target in this 681 // context. Thread and frame contexts will be cleared. 682 // If "process_sp" is not valid, all shared pointers are reset. 683 //------------------------------------------------------------------ 684 void 685 SetContext (const lldb::ProcessSP &process_sp); 686 687 //------------------------------------------------------------------ 688 // Set the execution context using a thread shared pointer. 689 // 690 // If "thread_sp" is valid, then set the thread, process and target 691 // in this context. The frame context will be cleared. 692 // If "thread_sp" is not valid, all shared pointers are reset. 693 //------------------------------------------------------------------ 694 void 695 SetContext (const lldb::ThreadSP &thread_sp); 696 697 //------------------------------------------------------------------ 698 // Set the execution context using a frame shared pointer. 699 // 700 // If "frame_sp" is valid, then set the frame, thread, process and 701 // target in this context 702 // If "frame_sp" is not valid, all shared pointers are reset. 703 //------------------------------------------------------------------ 704 void 705 SetContext (const lldb::StackFrameSP &frame_sp); 706 707 //------------------------------------------------------------------ 708 /// Returns true the ExecutionContext object contains a valid 709 /// target. 710 /// 711 /// This function can be called after initializing an ExecutionContext 712 /// object, and if it returns true, calls to GetTargetPtr() and 713 /// GetTargetRef() do not need to be checked for validity. 714 //------------------------------------------------------------------ 715 bool 716 HasTargetScope () const 717 { 718 return m_target_sp; 719 } 720 721 //------------------------------------------------------------------ 722 /// Returns true the ExecutionContext object contains a valid 723 /// target and process. 724 /// 725 /// This function can be called after initializing an ExecutionContext 726 /// object, and if it returns true, calls to GetTargetPtr() and 727 /// GetTargetRef(), GetProcessPtr(), and GetProcessRef(), do not 728 /// need to be checked for validity. 729 //------------------------------------------------------------------ 730 bool 731 HasProcessScope () const 732 { 733 return m_target_sp && m_process_sp; 734 } 735 736 //------------------------------------------------------------------ 737 /// Returns true the ExecutionContext object contains a valid 738 /// target, process, and thread. 739 /// 740 /// This function can be called after initializing an ExecutionContext 741 /// object, and if it returns true, calls to GetTargetPtr(), 742 /// GetTargetRef(), GetProcessPtr(), GetProcessRef(), GetThreadPtr(), 743 /// and GetThreadRef() do not need to be checked for validity. 744 //------------------------------------------------------------------ 745 bool 746 HasThreadScope () const 747 { 748 return m_target_sp && m_process_sp && m_thread_sp; 749 } 750 751 //------------------------------------------------------------------ 752 /// Returns true the ExecutionContext object contains a valid 753 /// target, process, thread and frame. 754 /// 755 /// This function can be called after initializing an ExecutionContext 756 /// object, and if it returns true, calls to GetTargetPtr(), 757 /// GetTargetRef(), GetProcessPtr(), GetProcessRef(), GetThreadPtr(), 758 /// GetThreadRef(), GetFramePtr(), and GetFrameRef() do not need 759 /// to be checked for validity. 760 //------------------------------------------------------------------ 761 bool 762 HasFrameScope () const 763 { 764 return m_target_sp && m_process_sp && m_thread_sp && m_frame_sp; 765 } 766 767protected: 768 //------------------------------------------------------------------ 769 // Member variables 770 //------------------------------------------------------------------ 771 lldb::TargetSP m_target_sp; ///< The target that owns the process/thread/frame 772 lldb::ProcessSP m_process_sp; ///< The process that owns the thread/frame 773 lldb::ThreadSP m_thread_sp; ///< The thread that owns the frame 774 lldb::StackFrameSP m_frame_sp; ///< The stack frame in thread. 775}; 776} // namespace lldb_private 777 778#endif // liblldb_ExecutionContext_h_ 779