1 //===-- Thread.h ------------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_TARGET_THREAD_H 10 #define LLDB_TARGET_THREAD_H 11 12 #include <memory> 13 #include <mutex> 14 #include <string> 15 #include <vector> 16 17 #include "lldb/Core/UserSettingsController.h" 18 #include "lldb/Target/ExecutionContextScope.h" 19 #include "lldb/Target/RegisterCheckpoint.h" 20 #include "lldb/Target/StackFrameList.h" 21 #include "lldb/Utility/Broadcaster.h" 22 #include "lldb/Utility/CompletionRequest.h" 23 #include "lldb/Utility/Event.h" 24 #include "lldb/Utility/StructuredData.h" 25 #include "lldb/Utility/UnimplementedError.h" 26 #include "lldb/Utility/UserID.h" 27 #include "lldb/lldb-private.h" 28 29 #define LLDB_THREAD_MAX_STOP_EXC_DATA 8 30 31 namespace lldb_private { 32 33 class ThreadPlanStack; 34 35 class ThreadProperties : public Properties { 36 public: 37 ThreadProperties(bool is_global); 38 39 ~ThreadProperties() override; 40 41 /// The regular expression returned determines symbols that this 42 /// thread won't stop in during "step-in" operations. 43 /// 44 /// \return 45 /// A pointer to a regular expression to compare against symbols, 46 /// or nullptr if all symbols are allowed. 47 /// 48 const RegularExpression *GetSymbolsToAvoidRegexp(); 49 50 FileSpecList GetLibrariesToAvoid() const; 51 52 bool GetTraceEnabledState() const; 53 54 bool GetStepInAvoidsNoDebug() const; 55 56 bool GetStepOutAvoidsNoDebug() const; 57 58 uint64_t GetMaxBacktraceDepth() const; 59 }; 60 61 class Thread : public std::enable_shared_from_this<Thread>, 62 public ThreadProperties, 63 public UserID, 64 public ExecutionContextScope, 65 public Broadcaster { 66 public: 67 /// Broadcaster event bits definitions. 68 enum { 69 eBroadcastBitStackChanged = (1 << 0), 70 eBroadcastBitThreadSuspended = (1 << 1), 71 eBroadcastBitThreadResumed = (1 << 2), 72 eBroadcastBitSelectedFrameChanged = (1 << 3), 73 eBroadcastBitThreadSelected = (1 << 4) 74 }; 75 76 static ConstString &GetStaticBroadcasterClass(); 77 GetBroadcasterClass()78 ConstString &GetBroadcasterClass() const override { 79 return GetStaticBroadcasterClass(); 80 } 81 82 class ThreadEventData : public EventData { 83 public: 84 ThreadEventData(const lldb::ThreadSP thread_sp); 85 86 ThreadEventData(const lldb::ThreadSP thread_sp, const StackID &stack_id); 87 88 ThreadEventData(); 89 90 ~ThreadEventData() override; 91 92 static llvm::StringRef GetFlavorString(); 93 GetFlavor()94 llvm::StringRef GetFlavor() const override { 95 return ThreadEventData::GetFlavorString(); 96 } 97 98 void Dump(Stream *s) const override; 99 100 static const ThreadEventData *GetEventDataFromEvent(const Event *event_ptr); 101 102 static lldb::ThreadSP GetThreadFromEvent(const Event *event_ptr); 103 104 static StackID GetStackIDFromEvent(const Event *event_ptr); 105 106 static lldb::StackFrameSP GetStackFrameFromEvent(const Event *event_ptr); 107 GetThread()108 lldb::ThreadSP GetThread() const { return m_thread_sp; } 109 GetStackID()110 StackID GetStackID() const { return m_stack_id; } 111 112 private: 113 lldb::ThreadSP m_thread_sp; 114 StackID m_stack_id; 115 116 ThreadEventData(const ThreadEventData &) = delete; 117 const ThreadEventData &operator=(const ThreadEventData &) = delete; 118 }; 119 120 struct ThreadStateCheckpoint { 121 uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting 122 // bit of data. 123 lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you 124 // might continue with the wrong signals. 125 size_t m_completed_plan_checkpoint; 126 lldb::RegisterCheckpointSP 127 register_backup_sp; // You need to restore the registers, of course... 128 uint32_t current_inlined_depth; 129 lldb::addr_t current_inlined_pc; 130 }; 131 132 /// Constructor 133 /// 134 /// \param [in] use_invalid_index_id 135 /// Optional parameter, defaults to false. The only subclass that 136 /// is likely to set use_invalid_index_id == true is the HistoryThread 137 /// class. In that case, the Thread we are constructing represents 138 /// a thread from earlier in the program execution. We may have the 139 /// tid of the original thread that they represent but we don't want 140 /// to reuse the IndexID of that thread, or create a new one. If a 141 /// client wants to know the original thread's IndexID, they should use 142 /// Thread::GetExtendedBacktraceOriginatingIndexID(). 143 Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id = false); 144 145 ~Thread() override; 146 147 static void SettingsInitialize(); 148 149 static void SettingsTerminate(); 150 151 static ThreadProperties &GetGlobalProperties(); 152 GetProcess()153 lldb::ProcessSP GetProcess() const { return m_process_wp.lock(); } 154 GetResumeSignal()155 int GetResumeSignal() const { return m_resume_signal; } 156 SetResumeSignal(int signal)157 void SetResumeSignal(int signal) { m_resume_signal = signal; } 158 159 lldb::StateType GetState() const; 160 161 void SetState(lldb::StateType state); 162 163 /// Sets the USER resume state for this thread. If you set a thread to 164 /// suspended with 165 /// this API, it won't take part in any of the arbitration for ShouldResume, 166 /// and will stay 167 /// suspended even when other threads do get to run. 168 /// 169 /// N.B. This is not the state that is used internally by thread plans to 170 /// implement 171 /// staying on one thread while stepping over a breakpoint, etc. The is the 172 /// TemporaryResume state, and if you are implementing some bit of strategy in 173 /// the stepping 174 /// machinery you should be using that state and not the user resume state. 175 /// 176 /// If you are just preparing all threads to run, you should not override the 177 /// threads that are 178 /// marked as suspended by the debugger. In that case, pass override_suspend 179 /// = false. If you want 180 /// to force the thread to run (e.g. the "thread continue" command, or are 181 /// resetting the state 182 /// (e.g. in SBThread::Resume()), then pass true to override_suspend. 183 void SetResumeState(lldb::StateType state, bool override_suspend = false) { 184 if (m_resume_state == lldb::eStateSuspended && !override_suspend) 185 return; 186 m_resume_state = state; 187 } 188 189 /// Gets the USER resume state for this thread. This is not the same as what 190 /// this thread is going to do for any particular step, however if this thread 191 /// returns eStateSuspended, then the process control logic will never allow 192 /// this 193 /// thread to run. 194 /// 195 /// \return 196 /// The User resume state for this thread. GetResumeState()197 lldb::StateType GetResumeState() const { return m_resume_state; } 198 199 // This function is called on all the threads before "ShouldResume" and 200 // "WillResume" in case a thread needs to change its state before the 201 // ThreadList polls all the threads to figure out which ones actually will 202 // get to run and how. 203 void SetupForResume(); 204 205 // Do not override this function, it is for thread plan logic only 206 bool ShouldResume(lldb::StateType resume_state); 207 208 // Override this to do platform specific tasks before resume. WillResume(lldb::StateType resume_state)209 virtual void WillResume(lldb::StateType resume_state) {} 210 211 // This clears generic thread state after a resume. If you subclass this, be 212 // sure to call it. 213 virtual void DidResume(); 214 215 // This notifies the thread when a private stop occurs. 216 virtual void DidStop(); 217 218 virtual void RefreshStateAfterStop() = 0; 219 220 std::string GetStopDescription(); 221 222 std::string GetStopDescriptionRaw(); 223 224 void WillStop(); 225 226 bool ShouldStop(Event *event_ptr); 227 228 Vote ShouldReportStop(Event *event_ptr); 229 230 Vote ShouldReportRun(Event *event_ptr); 231 232 void Flush(); 233 234 // Return whether this thread matches the specification in ThreadSpec. This 235 // is a virtual method because at some point we may extend the thread spec 236 // with a platform specific dictionary of attributes, which then only the 237 // platform specific Thread implementation would know how to match. For now, 238 // this just calls through to the ThreadSpec's ThreadPassesBasicTests method. 239 virtual bool MatchesSpec(const ThreadSpec *spec); 240 241 // Get the current public stop info, calculating it if necessary. 242 lldb::StopInfoSP GetStopInfo(); 243 244 lldb::StopReason GetStopReason(); 245 246 bool StopInfoIsUpToDate() const; 247 248 // This sets the stop reason to a "blank" stop reason, so you can call 249 // functions on the thread without having the called function run with 250 // whatever stop reason you stopped with. 251 void SetStopInfoToNothing(); 252 253 bool ThreadStoppedForAReason(); 254 255 static std::string RunModeAsString(lldb::RunMode mode); 256 257 static std::string StopReasonAsString(lldb::StopReason reason); 258 GetInfo()259 virtual const char *GetInfo() { return nullptr; } 260 261 /// Retrieve a dictionary of information about this thread 262 /// 263 /// On Mac OS X systems there may be voucher information. 264 /// The top level dictionary returned will have an "activity" key and the 265 /// value of the activity is a dictionary. Keys in that dictionary will 266 /// be "name" and "id", among others. 267 /// There may also be "trace_messages" (an array) with each entry in that 268 /// array 269 /// being a dictionary (keys include "message" with the text of the trace 270 /// message). GetExtendedInfo()271 StructuredData::ObjectSP GetExtendedInfo() { 272 if (!m_extended_info_fetched) { 273 m_extended_info = FetchThreadExtendedInfo(); 274 m_extended_info_fetched = true; 275 } 276 return m_extended_info; 277 } 278 GetName()279 virtual const char *GetName() { return nullptr; } 280 SetName(const char * name)281 virtual void SetName(const char *name) {} 282 283 /// Whether this thread can be associated with a libdispatch queue 284 /// 285 /// The Thread may know if it is associated with a libdispatch queue, 286 /// it may know definitively that it is NOT associated with a libdispatch 287 /// queue, or it may be unknown whether it is associated with a libdispatch 288 /// queue. 289 /// 290 /// \return 291 /// eLazyBoolNo if this thread is definitely not associated with a 292 /// libdispatch queue (e.g. on a non-Darwin system where GCD aka 293 /// libdispatch is not available). 294 /// 295 /// eLazyBoolYes this thread is associated with a libdispatch queue. 296 /// 297 /// eLazyBoolCalculate this thread may be associated with a libdispatch 298 /// queue but the thread doesn't know one way or the other. GetAssociatedWithLibdispatchQueue()299 virtual lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() { 300 return eLazyBoolNo; 301 } 302 SetAssociatedWithLibdispatchQueue(lldb_private::LazyBool associated_with_libdispatch_queue)303 virtual void SetAssociatedWithLibdispatchQueue( 304 lldb_private::LazyBool associated_with_libdispatch_queue) {} 305 306 /// Retrieve the Queue ID for the queue currently using this Thread 307 /// 308 /// If this Thread is doing work on behalf of a libdispatch/GCD queue, 309 /// retrieve the QueueID. 310 /// 311 /// This is a unique identifier for the libdispatch/GCD queue in a 312 /// process. Often starting at 1 for the initial system-created 313 /// queues and incrementing, a QueueID will not be reused for a 314 /// different queue during the lifetime of a process. 315 /// 316 /// \return 317 /// A QueueID if the Thread subclass implements this, else 318 /// LLDB_INVALID_QUEUE_ID. GetQueueID()319 virtual lldb::queue_id_t GetQueueID() { return LLDB_INVALID_QUEUE_ID; } 320 SetQueueID(lldb::queue_id_t new_val)321 virtual void SetQueueID(lldb::queue_id_t new_val) {} 322 323 /// Retrieve the Queue name for the queue currently using this Thread 324 /// 325 /// If this Thread is doing work on behalf of a libdispatch/GCD queue, 326 /// retrieve the Queue name. 327 /// 328 /// \return 329 /// The Queue name, if the Thread subclass implements this, else 330 /// nullptr. GetQueueName()331 virtual const char *GetQueueName() { return nullptr; } 332 SetQueueName(const char * name)333 virtual void SetQueueName(const char *name) {} 334 335 /// Retrieve the Queue kind for the queue currently using this Thread 336 /// 337 /// If this Thread is doing work on behalf of a libdispatch/GCD queue, 338 /// retrieve the Queue kind - either eQueueKindSerial or 339 /// eQueueKindConcurrent, indicating that this queue processes work 340 /// items serially or concurrently. 341 /// 342 /// \return 343 /// The Queue kind, if the Thread subclass implements this, else 344 /// eQueueKindUnknown. GetQueueKind()345 virtual lldb::QueueKind GetQueueKind() { return lldb::eQueueKindUnknown; } 346 SetQueueKind(lldb::QueueKind kind)347 virtual void SetQueueKind(lldb::QueueKind kind) {} 348 349 /// Retrieve the Queue for this thread, if any. 350 /// 351 /// \return 352 /// A QueueSP for the queue that is currently associated with this 353 /// thread. 354 /// An empty shared pointer indicates that this thread is not 355 /// associated with a queue, or libdispatch queues are not 356 /// supported on this target. GetQueue()357 virtual lldb::QueueSP GetQueue() { return lldb::QueueSP(); } 358 359 /// Retrieve the address of the libdispatch_queue_t struct for queue 360 /// currently using this Thread 361 /// 362 /// If this Thread is doing work on behalf of a libdispatch/GCD queue, 363 /// retrieve the address of the libdispatch_queue_t structure describing 364 /// the queue. 365 /// 366 /// This address may be reused for different queues later in the Process 367 /// lifetime and should not be used to identify a queue uniquely. Use 368 /// the GetQueueID() call for that. 369 /// 370 /// \return 371 /// The Queue's libdispatch_queue_t address if the Thread subclass 372 /// implements this, else LLDB_INVALID_ADDRESS. GetQueueLibdispatchQueueAddress()373 virtual lldb::addr_t GetQueueLibdispatchQueueAddress() { 374 return LLDB_INVALID_ADDRESS; 375 } 376 SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t)377 virtual void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) {} 378 379 /// Whether this Thread already has all the Queue information cached or not 380 /// 381 /// A Thread may be associated with a libdispatch work Queue at a given 382 /// public stop event. If so, the thread can satisify requests like 383 /// GetQueueLibdispatchQueueAddress, GetQueueKind, GetQueueName, and 384 /// GetQueueID 385 /// either from information from the remote debug stub when it is initially 386 /// created, or it can query the SystemRuntime for that information. 387 /// 388 /// This method allows the SystemRuntime to discover if a thread has this 389 /// information already, instead of calling the thread to get the information 390 /// and having the thread call the SystemRuntime again. ThreadHasQueueInformation()391 virtual bool ThreadHasQueueInformation() const { return false; } 392 GetStackFrameCount()393 virtual uint32_t GetStackFrameCount() { 394 return GetStackFrameList()->GetNumFrames(); 395 } 396 GetStackFrameAtIndex(uint32_t idx)397 virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx) { 398 return GetStackFrameList()->GetFrameAtIndex(idx); 399 } 400 401 virtual lldb::StackFrameSP 402 GetFrameWithConcreteFrameIndex(uint32_t unwind_idx); 403 DecrementCurrentInlinedDepth()404 bool DecrementCurrentInlinedDepth() { 405 return GetStackFrameList()->DecrementCurrentInlinedDepth(); 406 } 407 GetCurrentInlinedDepth()408 uint32_t GetCurrentInlinedDepth() { 409 return GetStackFrameList()->GetCurrentInlinedDepth(); 410 } 411 412 Status ReturnFromFrameWithIndex(uint32_t frame_idx, 413 lldb::ValueObjectSP return_value_sp, 414 bool broadcast = false); 415 416 Status ReturnFromFrame(lldb::StackFrameSP frame_sp, 417 lldb::ValueObjectSP return_value_sp, 418 bool broadcast = false); 419 420 Status JumpToLine(const FileSpec &file, uint32_t line, 421 bool can_leave_function, std::string *warnings = nullptr); 422 GetFrameWithStackID(const StackID & stack_id)423 virtual lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id) { 424 if (stack_id.IsValid()) 425 return GetStackFrameList()->GetFrameWithStackID(stack_id); 426 return lldb::StackFrameSP(); 427 } 428 429 // Only pass true to select_most_relevant if you are fulfilling an explicit 430 // user request for GetSelectedFrameIndex. The most relevant frame is only 431 // for showing to the user, and can do arbitrary work, so we don't want to 432 // call it internally. GetSelectedFrameIndex(SelectMostRelevant select_most_relevant)433 uint32_t GetSelectedFrameIndex(SelectMostRelevant select_most_relevant) { 434 return GetStackFrameList()->GetSelectedFrameIndex(select_most_relevant); 435 } 436 437 lldb::StackFrameSP 438 GetSelectedFrame(SelectMostRelevant select_most_relevant); 439 440 uint32_t SetSelectedFrame(lldb_private::StackFrame *frame, 441 bool broadcast = false); 442 443 bool SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast = false); 444 445 bool SetSelectedFrameByIndexNoisily(uint32_t frame_idx, 446 Stream &output_stream); 447 SetDefaultFileAndLineToSelectedFrame()448 void SetDefaultFileAndLineToSelectedFrame() { 449 GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame(); 450 } 451 452 virtual lldb::RegisterContextSP GetRegisterContext() = 0; 453 454 virtual lldb::RegisterContextSP 455 CreateRegisterContextForFrame(StackFrame *frame) = 0; 456 457 virtual void ClearStackFrames(); 458 SetBackingThread(const lldb::ThreadSP & thread_sp)459 virtual bool SetBackingThread(const lldb::ThreadSP &thread_sp) { 460 return false; 461 } 462 GetBackingThread()463 virtual lldb::ThreadSP GetBackingThread() const { return lldb::ThreadSP(); } 464 ClearBackingThread()465 virtual void ClearBackingThread() { 466 // Subclasses can use this function if a thread is actually backed by 467 // another thread. This is currently used for the OperatingSystem plug-ins 468 // where they might have a thread that is in memory, yet its registers are 469 // available through the lldb_private::Thread subclass for the current 470 // lldb_private::Process class. Since each time the process stops the 471 // backing threads for memory threads can change, we need a way to clear 472 // the backing thread for all memory threads each time we stop. 473 } 474 475 /// Dump \a count instructions of the thread's \a Trace starting at the \a 476 /// start_position position in reverse order. 477 /// 478 /// The instructions are indexed in reverse order, which means that the \a 479 /// start_position 0 represents the last instruction of the trace 480 /// chronologically. 481 /// 482 /// \param[in] s 483 /// The stream object where the instructions are printed. 484 /// 485 /// \param[in] count 486 /// The number of instructions to print. 487 /// 488 /// \param[in] start_position 489 /// The position of the first instruction to print. 490 void DumpTraceInstructions(Stream &s, size_t count, 491 size_t start_position = 0) const; 492 493 /// Print a description of this thread using the provided thread format. 494 /// 495 /// \param[out] strm 496 /// The Stream to print the description to. 497 /// 498 /// \param[in] frame_idx 499 /// If not \b LLDB_INVALID_FRAME_ID, then use this frame index as context to 500 /// generate the description. 501 /// 502 /// \param[in] format 503 /// The input format. 504 /// 505 /// \return 506 /// \b true if and only if dumping with the given \p format worked. 507 bool DumpUsingFormat(Stream &strm, uint32_t frame_idx, 508 const FormatEntity::Entry *format); 509 510 // If stop_format is true, this will be the form used when we print stop 511 // info. If false, it will be the form we use for thread list and co. 512 void DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx, 513 bool stop_format); 514 515 bool GetDescription(Stream &s, lldb::DescriptionLevel level, 516 bool print_json_thread, bool print_json_stopinfo); 517 518 /// Default implementation for stepping into. 519 /// 520 /// This function is designed to be used by commands where the 521 /// process is publicly stopped. 522 /// 523 /// \param[in] source_step 524 /// If true and the frame has debug info, then do a source level 525 /// step in, else do a single instruction step in. 526 /// 527 /// \param[in] step_in_avoids_code_without_debug_info 528 /// If \a true, then avoid stepping into code that doesn't have 529 /// debug info, else step into any code regardless of whether it 530 /// has debug info. 531 /// 532 /// \param[in] step_out_avoids_code_without_debug_info 533 /// If \a true, then if you step out to code with no debug info, keep 534 /// stepping out till you get to code with debug info. 535 /// 536 /// \return 537 /// An error that describes anything that went wrong 538 virtual Status 539 StepIn(bool source_step, 540 LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, 541 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 542 543 /// Default implementation for stepping over. 544 /// 545 /// This function is designed to be used by commands where the 546 /// process is publicly stopped. 547 /// 548 /// \param[in] source_step 549 /// If true and the frame has debug info, then do a source level 550 /// step over, else do a single instruction step over. 551 /// 552 /// \return 553 /// An error that describes anything that went wrong 554 virtual Status StepOver( 555 bool source_step, 556 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 557 558 /// Default implementation for stepping out. 559 /// 560 /// This function is designed to be used by commands where the 561 /// process is publicly stopped. 562 /// 563 /// \param[in] frame_idx 564 /// The frame index to step out of. 565 /// 566 /// \return 567 /// An error that describes anything that went wrong 568 virtual Status StepOut(uint32_t frame_idx = 0); 569 570 /// Retrieves the per-thread data area. 571 /// Most OSs maintain a per-thread pointer (e.g. the FS register on 572 /// x64), which we return the value of here. 573 /// 574 /// \return 575 /// LLDB_INVALID_ADDRESS if not supported, otherwise the thread 576 /// pointer value. 577 virtual lldb::addr_t GetThreadPointer(); 578 579 /// Retrieves the per-module TLS block for a thread. 580 /// 581 /// \param[in] module 582 /// The module to query TLS data for. 583 /// 584 /// \param[in] tls_file_addr 585 /// The thread local address in module 586 /// \return 587 /// If the thread has TLS data allocated for the 588 /// module, the address of the TLS block. Otherwise 589 /// LLDB_INVALID_ADDRESS is returned. 590 virtual lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, 591 lldb::addr_t tls_file_addr); 592 593 /// Check whether this thread is safe to run functions 594 /// 595 /// The SystemRuntime may know of certain thread states (functions in 596 /// process of execution, for instance) which can make it unsafe for 597 /// functions to be called. 598 /// 599 /// \return 600 /// True if it is safe to call functions on this thread. 601 /// False if function calls should be avoided on this thread. 602 virtual bool SafeToCallFunctions(); 603 604 // Thread Plan Providers: 605 // This section provides the basic thread plans that the Process control 606 // machinery uses to run the target. ThreadPlan.h provides more details on 607 // how this mechanism works. The thread provides accessors to a set of plans 608 // that perform basic operations. The idea is that particular Platform 609 // plugins can override these methods to provide the implementation of these 610 // basic operations appropriate to their environment. 611 // 612 // NB: All the QueueThreadPlanXXX providers return Shared Pointers to 613 // Thread plans. This is useful so that you can modify the plans after 614 // creation in ways specific to that plan type. Also, it is often necessary 615 // for ThreadPlans that utilize other ThreadPlans to implement their task to 616 // keep a shared pointer to the sub-plan. But besides that, the shared 617 // pointers should only be held onto by entities who live no longer than the 618 // thread containing the ThreadPlan. 619 // FIXME: If this becomes a problem, we can make a version that just returns a 620 // pointer, 621 // which it is clearly unsafe to hold onto, and a shared pointer version, and 622 // only allow ThreadPlan and Co. to use the latter. That is made more 623 // annoying to do because there's no elegant way to friend a method to all 624 // sub-classes of a given class. 625 // 626 627 /// Queues the base plan for a thread. 628 /// The version returned by Process does some things that are useful, 629 /// like handle breakpoints and signals, so if you return a plugin specific 630 /// one you probably want to call through to the Process one for anything 631 /// your plugin doesn't explicitly handle. 632 /// 633 /// \param[in] abort_other_plans 634 /// \b true if we discard the currently queued plans and replace them with 635 /// this one. 636 /// Otherwise this plan will go on the end of the plan stack. 637 /// 638 /// \return 639 /// A shared pointer to the newly queued thread plan, or nullptr if the 640 /// plan could not be queued. 641 lldb::ThreadPlanSP QueueBasePlan(bool abort_other_plans); 642 643 /// Queues the plan used to step one instruction from the current PC of \a 644 /// thread. 645 /// 646 /// \param[in] step_over 647 /// \b true if we step over calls to functions, false if we step in. 648 /// 649 /// \param[in] abort_other_plans 650 /// \b true if we discard the currently queued plans and replace them with 651 /// this one. 652 /// Otherwise this plan will go on the end of the plan stack. 653 /// 654 /// \param[in] stop_other_threads 655 /// \b true if we will stop other threads while we single step this one. 656 /// 657 /// \param[out] status 658 /// A status with an error if queuing failed. 659 /// 660 /// \return 661 /// A shared pointer to the newly queued thread plan, or nullptr if the 662 /// plan could not be queued. 663 virtual lldb::ThreadPlanSP QueueThreadPlanForStepSingleInstruction( 664 bool step_over, bool abort_other_plans, bool stop_other_threads, 665 Status &status); 666 667 /// Queues the plan used to step through an address range, stepping over 668 /// function calls. 669 /// 670 /// \param[in] abort_other_plans 671 /// \b true if we discard the currently queued plans and replace them with 672 /// this one. 673 /// Otherwise this plan will go on the end of the plan stack. 674 /// 675 /// \param[in] type 676 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported 677 /// by this plan. 678 /// 679 /// \param[in] range 680 /// The address range to step through. 681 /// 682 /// \param[in] addr_context 683 /// When dealing with stepping through inlined functions the current PC is 684 /// not enough information to know 685 /// what "step" means. For instance a series of nested inline functions 686 /// might start at the same address. 687 // The \a addr_context provides the current symbol context the step 688 /// is supposed to be out of. 689 // FIXME: Currently unused. 690 /// 691 /// \param[in] stop_other_threads 692 /// \b true if we will stop other threads while we single step this one. 693 /// 694 /// \param[out] status 695 /// A status with an error if queuing failed. 696 /// 697 /// \param[in] step_out_avoids_code_without_debug_info 698 /// If eLazyBoolYes, if the step over steps out it will continue to step 699 /// out till it comes to a frame with debug info. 700 /// If eLazyBoolCalculate, we will consult the default set in the thread. 701 /// 702 /// \return 703 /// A shared pointer to the newly queued thread plan, or nullptr if the 704 /// plan could not be queued. 705 virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange( 706 bool abort_other_plans, const AddressRange &range, 707 const SymbolContext &addr_context, lldb::RunMode stop_other_threads, 708 Status &status, 709 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 710 711 // Helper function that takes a LineEntry to step, insted of an AddressRange. 712 // This may combine multiple LineEntries of the same source line number to 713 // step over a longer address range in a single operation. 714 virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange( 715 bool abort_other_plans, const LineEntry &line_entry, 716 const SymbolContext &addr_context, lldb::RunMode stop_other_threads, 717 Status &status, 718 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 719 720 /// Queues the plan used to step through an address range, stepping into 721 /// functions. 722 /// 723 /// \param[in] abort_other_plans 724 /// \b true if we discard the currently queued plans and replace them with 725 /// this one. 726 /// Otherwise this plan will go on the end of the plan stack. 727 /// 728 /// \param[in] type 729 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported 730 /// by this plan. 731 /// 732 /// \param[in] range 733 /// The address range to step through. 734 /// 735 /// \param[in] addr_context 736 /// When dealing with stepping through inlined functions the current PC is 737 /// not enough information to know 738 /// what "step" means. For instance a series of nested inline functions 739 /// might start at the same address. 740 // The \a addr_context provides the current symbol context the step 741 /// is supposed to be out of. 742 // FIXME: Currently unused. 743 /// 744 /// \param[in] step_in_target 745 /// Name if function we are trying to step into. We will step out if we 746 /// don't land in that function. 747 /// 748 /// \param[in] stop_other_threads 749 /// \b true if we will stop other threads while we single step this one. 750 /// 751 /// \param[out] status 752 /// A status with an error if queuing failed. 753 /// 754 /// \param[in] step_in_avoids_code_without_debug_info 755 /// If eLazyBoolYes we will step out if we step into code with no debug 756 /// info. 757 /// If eLazyBoolCalculate we will consult the default set in the thread. 758 /// 759 /// \param[in] step_out_avoids_code_without_debug_info 760 /// If eLazyBoolYes, if the step over steps out it will continue to step 761 /// out till it comes to a frame with debug info. 762 /// If eLazyBoolCalculate, it will consult the default set in the thread. 763 /// 764 /// \return 765 /// A shared pointer to the newly queued thread plan, or nullptr if the 766 /// plan could not be queued. 767 virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange( 768 bool abort_other_plans, const AddressRange &range, 769 const SymbolContext &addr_context, const char *step_in_target, 770 lldb::RunMode stop_other_threads, Status &status, 771 LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, 772 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 773 774 // Helper function that takes a LineEntry to step, insted of an AddressRange. 775 // This may combine multiple LineEntries of the same source line number to 776 // step over a longer address range in a single operation. 777 virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange( 778 bool abort_other_plans, const LineEntry &line_entry, 779 const SymbolContext &addr_context, const char *step_in_target, 780 lldb::RunMode stop_other_threads, Status &status, 781 LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, 782 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 783 784 /// Queue the plan used to step out of the function at the current PC of 785 /// \a thread. 786 /// 787 /// \param[in] abort_other_plans 788 /// \b true if we discard the currently queued plans and replace them with 789 /// this one. 790 /// Otherwise this plan will go on the end of the plan stack. 791 /// 792 /// \param[in] addr_context 793 /// When dealing with stepping through inlined functions the current PC is 794 /// not enough information to know 795 /// what "step" means. For instance a series of nested inline functions 796 /// might start at the same address. 797 // The \a addr_context provides the current symbol context the step 798 /// is supposed to be out of. 799 // FIXME: Currently unused. 800 /// 801 /// \param[in] first_insn 802 /// \b true if this is the first instruction of a function. 803 /// 804 /// \param[in] stop_other_threads 805 /// \b true if we will stop other threads while we single step this one. 806 /// 807 /// \param[in] report_stop_vote 808 /// See standard meanings for the stop & run votes in ThreadPlan.h. 809 /// 810 /// \param[in] report_run_vote 811 /// See standard meanings for the stop & run votes in ThreadPlan.h. 812 /// 813 /// \param[out] status 814 /// A status with an error if queuing failed. 815 /// 816 /// \param[in] step_out_avoids_code_without_debug_info 817 /// If eLazyBoolYes, if the step over steps out it will continue to step 818 /// out till it comes to a frame with debug info. 819 /// If eLazyBoolCalculate, it will consult the default set in the thread. 820 /// 821 /// \return 822 /// A shared pointer to the newly queued thread plan, or nullptr if the 823 /// plan could not be queued. 824 virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut( 825 bool abort_other_plans, SymbolContext *addr_context, bool first_insn, 826 bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote, 827 uint32_t frame_idx, Status &status, 828 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 829 830 /// Queue the plan used to step out of the function at the current PC of 831 /// a thread. This version does not consult the should stop here callback, 832 /// and should only 833 /// be used by other thread plans when they need to retain control of the step 834 /// out. 835 /// 836 /// \param[in] abort_other_plans 837 /// \b true if we discard the currently queued plans and replace them with 838 /// this one. 839 /// Otherwise this plan will go on the end of the plan stack. 840 /// 841 /// \param[in] addr_context 842 /// When dealing with stepping through inlined functions the current PC is 843 /// not enough information to know 844 /// what "step" means. For instance a series of nested inline functions 845 /// might start at the same address. 846 // The \a addr_context provides the current symbol context the step 847 /// is supposed to be out of. 848 // FIXME: Currently unused. 849 /// 850 /// \param[in] first_insn 851 /// \b true if this is the first instruction of a function. 852 /// 853 /// \param[in] stop_other_threads 854 /// \b true if we will stop other threads while we single step this one. 855 /// 856 /// \param[in] report_stop_vote 857 /// See standard meanings for the stop & run votes in ThreadPlan.h. 858 /// 859 /// \param[in] report_run_vote 860 /// See standard meanings for the stop & run votes in ThreadPlan.h. 861 /// 862 /// \param[in] frame_idx 863 /// The frame index. 864 /// 865 /// \param[out] status 866 /// A status with an error if queuing failed. 867 /// 868 /// \param[in] continue_to_next_branch 869 /// Normally this will enqueue a plan that will put a breakpoint on the 870 /// return address and continue 871 /// to there. If continue_to_next_branch is true, this is an operation not 872 /// involving the user -- 873 /// e.g. stepping "next" in a source line and we instruction stepped into 874 /// another function -- 875 /// so instead of putting a breakpoint on the return address, advance the 876 /// breakpoint to the 877 /// end of the source line that is doing the call, or until the next flow 878 /// control instruction. 879 /// If the return value from the function call is to be retrieved / 880 /// displayed to the user, you must stop 881 /// on the return address. The return value may be stored in volatile 882 /// registers which are overwritten 883 /// before the next branch instruction. 884 /// 885 /// \return 886 /// A shared pointer to the newly queued thread plan, or nullptr if the 887 /// plan could not be queued. 888 virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop( 889 bool abort_other_plans, SymbolContext *addr_context, bool first_insn, 890 bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote, 891 uint32_t frame_idx, Status &status, bool continue_to_next_branch = false); 892 893 /// Gets the plan used to step through the code that steps from a function 894 /// call site at the current PC into the actual function call. 895 /// 896 /// \param[in] return_stack_id 897 /// The stack id that we will return to (by setting backstop breakpoints on 898 /// the return 899 /// address to that frame) if we fail to step through. 900 /// 901 /// \param[in] abort_other_plans 902 /// \b true if we discard the currently queued plans and replace them with 903 /// this one. 904 /// Otherwise this plan will go on the end of the plan stack. 905 /// 906 /// \param[in] stop_other_threads 907 /// \b true if we will stop other threads while we single step this one. 908 /// 909 /// \param[out] status 910 /// A status with an error if queuing failed. 911 /// 912 /// \return 913 /// A shared pointer to the newly queued thread plan, or nullptr if the 914 /// plan could not be queued. 915 virtual lldb::ThreadPlanSP 916 QueueThreadPlanForStepThrough(StackID &return_stack_id, 917 bool abort_other_plans, bool stop_other_threads, 918 Status &status); 919 920 /// Gets the plan used to continue from the current PC. 921 /// This is a simple plan, mostly useful as a backstop when you are continuing 922 /// for some particular purpose. 923 /// 924 /// \param[in] abort_other_plans 925 /// \b true if we discard the currently queued plans and replace them with 926 /// this one. 927 /// Otherwise this plan will go on the end of the plan stack. 928 /// 929 /// \param[in] target_addr 930 /// The address to which we're running. 931 /// 932 /// \param[in] stop_other_threads 933 /// \b true if we will stop other threads while we single step this one. 934 /// 935 /// \param[out] status 936 /// A status with an error if queuing failed. 937 /// 938 /// \return 939 /// A shared pointer to the newly queued thread plan, or nullptr if the 940 /// plan could not be queued. 941 virtual lldb::ThreadPlanSP 942 QueueThreadPlanForRunToAddress(bool abort_other_plans, Address &target_addr, 943 bool stop_other_threads, Status &status); 944 945 virtual lldb::ThreadPlanSP QueueThreadPlanForStepUntil( 946 bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses, 947 bool stop_others, uint32_t frame_idx, Status &status); 948 949 virtual lldb::ThreadPlanSP 950 QueueThreadPlanForStepScripted(bool abort_other_plans, const char *class_name, 951 StructuredData::ObjectSP extra_args_sp, 952 bool stop_other_threads, Status &status); 953 954 // Thread Plan accessors: 955 956 /// Format the thread plan information for auto completion. 957 /// 958 /// \param[in] request 959 /// The reference to the completion handler. 960 void AutoCompleteThreadPlans(CompletionRequest &request) const; 961 962 /// Gets the plan which will execute next on the plan stack. 963 /// 964 /// \return 965 /// A pointer to the next executed plan. 966 ThreadPlan *GetCurrentPlan() const; 967 968 /// Unwinds the thread stack for the innermost expression plan currently 969 /// on the thread plan stack. 970 /// 971 /// \return 972 /// An error if the thread plan could not be unwound. 973 974 Status UnwindInnermostExpression(); 975 976 /// Gets the outer-most plan that was popped off the plan stack in the 977 /// most recent stop. Useful for printing the stop reason accurately. 978 /// 979 /// \return 980 /// A pointer to the last completed plan. 981 lldb::ThreadPlanSP GetCompletedPlan() const; 982 983 /// Gets the outer-most return value from the completed plans 984 /// 985 /// \return 986 /// A ValueObjectSP, either empty if there is no return value, 987 /// or containing the return value. 988 lldb::ValueObjectSP GetReturnValueObject() const; 989 990 /// Gets the outer-most expression variable from the completed plans 991 /// 992 /// \return 993 /// A ExpressionVariableSP, either empty if there is no 994 /// plan completed an expression during the current stop 995 /// or the expression variable that was made for the completed expression. 996 lldb::ExpressionVariableSP GetExpressionVariable() const; 997 998 /// Checks whether the given plan is in the completed plans for this 999 /// stop. 1000 /// 1001 /// \param[in] plan 1002 /// Pointer to the plan you're checking. 1003 /// 1004 /// \return 1005 /// Returns true if the input plan is in the completed plan stack, 1006 /// false otherwise. 1007 bool IsThreadPlanDone(ThreadPlan *plan) const; 1008 1009 /// Checks whether the given plan is in the discarded plans for this 1010 /// stop. 1011 /// 1012 /// \param[in] plan 1013 /// Pointer to the plan you're checking. 1014 /// 1015 /// \return 1016 /// Returns true if the input plan is in the discarded plan stack, 1017 /// false otherwise. 1018 bool WasThreadPlanDiscarded(ThreadPlan *plan) const; 1019 1020 /// Check if we have completed plan to override breakpoint stop reason 1021 /// 1022 /// \return 1023 /// Returns true if completed plan stack is not empty 1024 /// false otherwise. 1025 bool CompletedPlanOverridesBreakpoint() const; 1026 1027 /// Queues a generic thread plan. 1028 /// 1029 /// \param[in] plan_sp 1030 /// The plan to queue. 1031 /// 1032 /// \param[in] abort_other_plans 1033 /// \b true if we discard the currently queued plans and replace them with 1034 /// this one. 1035 /// Otherwise this plan will go on the end of the plan stack. 1036 /// 1037 /// \return 1038 /// A pointer to the last completed plan. 1039 Status QueueThreadPlan(lldb::ThreadPlanSP &plan_sp, bool abort_other_plans); 1040 1041 /// Discards the plans queued on the plan stack of the current thread. This 1042 /// is 1043 /// arbitrated by the "Controlling" ThreadPlans, using the "OkayToDiscard" 1044 /// call. 1045 // But if \a force is true, all thread plans are discarded. 1046 void DiscardThreadPlans(bool force); 1047 1048 /// Discards the plans queued on the plan stack of the current thread up to 1049 /// and 1050 /// including up_to_plan_sp. 1051 // 1052 // \param[in] up_to_plan_sp 1053 // Discard all plans up to and including this one. 1054 void DiscardThreadPlansUpToPlan(lldb::ThreadPlanSP &up_to_plan_sp); 1055 1056 void DiscardThreadPlansUpToPlan(ThreadPlan *up_to_plan_ptr); 1057 1058 /// Discards the plans queued on the plan stack of the current thread up to 1059 /// and 1060 /// including the plan in that matches \a thread_index counting only 1061 /// the non-Private plans. 1062 /// 1063 /// \param[in] thread_index 1064 /// Discard all plans up to and including this user plan given by this 1065 /// index. 1066 /// 1067 /// \return 1068 /// \b true if there was a thread plan with that user index, \b false 1069 /// otherwise. 1070 bool DiscardUserThreadPlansUpToIndex(uint32_t thread_index); 1071 1072 virtual bool CheckpointThreadState(ThreadStateCheckpoint &saved_state); 1073 1074 virtual bool 1075 RestoreRegisterStateFromCheckpoint(ThreadStateCheckpoint &saved_state); 1076 1077 void RestoreThreadStateFromCheckpoint(ThreadStateCheckpoint &saved_state); 1078 1079 // Get the thread index ID. The index ID that is guaranteed to not be re-used 1080 // by a process. They start at 1 and increase with each new thread. This 1081 // allows easy command line access by a unique ID that is easier to type than 1082 // the actual system thread ID. 1083 uint32_t GetIndexID() const; 1084 1085 // Get the originating thread's index ID. 1086 // In the case of an "extended" thread -- a thread which represents the stack 1087 // that enqueued/spawned work that is currently executing -- we need to 1088 // provide the IndexID of the thread that actually did this work. We don't 1089 // want to just masquerade as that thread's IndexID by using it in our own 1090 // IndexID because that way leads to madness - but the driver program which 1091 // is iterating over extended threads may ask for the OriginatingThreadID to 1092 // display that information to the user. 1093 // Normal threads will return the same thing as GetIndexID(); GetExtendedBacktraceOriginatingIndexID()1094 virtual uint32_t GetExtendedBacktraceOriginatingIndexID() { 1095 return GetIndexID(); 1096 } 1097 1098 // The API ID is often the same as the Thread::GetID(), but not in all cases. 1099 // Thread::GetID() is the user visible thread ID that clients would want to 1100 // see. The API thread ID is the thread ID that is used when sending data 1101 // to/from the debugging protocol. GetProtocolID()1102 virtual lldb::user_id_t GetProtocolID() const { return GetID(); } 1103 1104 // lldb::ExecutionContextScope pure virtual functions 1105 lldb::TargetSP CalculateTarget() override; 1106 1107 lldb::ProcessSP CalculateProcess() override; 1108 1109 lldb::ThreadSP CalculateThread() override; 1110 1111 lldb::StackFrameSP CalculateStackFrame() override; 1112 1113 void CalculateExecutionContext(ExecutionContext &exe_ctx) override; 1114 1115 lldb::StackFrameSP 1116 GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr); 1117 1118 size_t GetStatus(Stream &strm, uint32_t start_frame, uint32_t num_frames, 1119 uint32_t num_frames_with_source, bool stop_format, 1120 bool only_stacks = false); 1121 1122 size_t GetStackFrameStatus(Stream &strm, uint32_t first_frame, 1123 uint32_t num_frames, bool show_frame_info, 1124 uint32_t num_frames_with_source); 1125 1126 // We need a way to verify that even though we have a thread in a shared 1127 // pointer that the object itself is still valid. Currently this won't be the 1128 // case if DestroyThread() was called. DestroyThread is called when a thread 1129 // has been removed from the Process' thread list. IsValid()1130 bool IsValid() const { return !m_destroy_called; } 1131 1132 // Sets and returns a valid stop info based on the process stop ID and the 1133 // current thread plan. If the thread stop ID does not match the process' 1134 // stop ID, the private stop reason is not set and an invalid StopInfoSP may 1135 // be returned. 1136 // 1137 // NOTE: This function must be called before the current thread plan is 1138 // moved to the completed plan stack (in Thread::ShouldStop()). 1139 // 1140 // NOTE: If subclasses override this function, ensure they do not overwrite 1141 // the m_actual_stop_info if it is valid. The stop info may be a 1142 // "checkpointed and restored" stop info, so if it is still around it is 1143 // right even if you have not calculated this yourself, or if it disagrees 1144 // with what you might have calculated. 1145 virtual lldb::StopInfoSP GetPrivateStopInfo(bool calculate = true); 1146 1147 // Calculate the stop info that will be shown to lldb clients. For instance, 1148 // a "step out" is implemented by running to a breakpoint on the function 1149 // return PC, so the process plugin initially sets the stop info to a 1150 // StopInfoBreakpoint. But once we've run the ShouldStop machinery, we 1151 // discover that there's a completed ThreadPlanStepOut, and that's really 1152 // the StopInfo we want to show. That will happen naturally the next 1153 // time GetStopInfo is called, but if you want to force the replacement, 1154 // you can call this. 1155 1156 void CalculatePublicStopInfo(); 1157 1158 // Ask the thread subclass to set its stop info. 1159 // 1160 // Thread subclasses should call Thread::SetStopInfo(...) with the reason the 1161 // thread stopped. 1162 // 1163 // \return 1164 // True if Thread::SetStopInfo(...) was called, false otherwise. 1165 virtual bool CalculateStopInfo() = 0; 1166 1167 // Gets the temporary resume state for a thread. 1168 // 1169 // This value gets set in each thread by complex debugger logic in 1170 // Thread::ShouldResume() and an appropriate thread resume state will get set 1171 // in each thread every time the process is resumed prior to calling 1172 // Process::DoResume(). The lldb_private::Process subclass should adhere to 1173 // the thread resume state request which will be one of: 1174 // 1175 // eStateRunning - thread will resume when process is resumed 1176 // eStateStepping - thread should step 1 instruction and stop when process 1177 // is resumed 1178 // eStateSuspended - thread should not execute any instructions when 1179 // process is resumed GetTemporaryResumeState()1180 lldb::StateType GetTemporaryResumeState() const { 1181 return m_temporary_resume_state; 1182 } 1183 1184 void SetStopInfo(const lldb::StopInfoSP &stop_info_sp); 1185 1186 void ResetStopInfo(); 1187 1188 void SetShouldReportStop(Vote vote); 1189 SetShouldRunBeforePublicStop(bool newval)1190 void SetShouldRunBeforePublicStop(bool newval) { 1191 m_should_run_before_public_stop = newval; 1192 } 1193 ShouldRunBeforePublicStop()1194 bool ShouldRunBeforePublicStop() { 1195 return m_should_run_before_public_stop; 1196 } 1197 1198 /// Sets the extended backtrace token for this thread 1199 /// 1200 /// Some Thread subclasses may maintain a token to help with providing 1201 /// an extended backtrace. The SystemRuntime plugin will set/request this. 1202 /// 1203 /// \param [in] token The extended backtrace token. SetExtendedBacktraceToken(uint64_t token)1204 virtual void SetExtendedBacktraceToken(uint64_t token) {} 1205 1206 /// Gets the extended backtrace token for this thread 1207 /// 1208 /// Some Thread subclasses may maintain a token to help with providing 1209 /// an extended backtrace. The SystemRuntime plugin will set/request this. 1210 /// 1211 /// \return 1212 /// The token needed by the SystemRuntime to create an extended backtrace. 1213 /// LLDB_INVALID_ADDRESS is returned if no token is available. GetExtendedBacktraceToken()1214 virtual uint64_t GetExtendedBacktraceToken() { return LLDB_INVALID_ADDRESS; } 1215 1216 lldb::ValueObjectSP GetCurrentException(); 1217 1218 lldb::ThreadSP GetCurrentExceptionBacktrace(); 1219 1220 lldb::ValueObjectSP GetSiginfoValue(); 1221 1222 protected: 1223 friend class ThreadPlan; 1224 friend class ThreadList; 1225 friend class ThreadEventData; 1226 friend class StackFrameList; 1227 friend class StackFrame; 1228 friend class OperatingSystem; 1229 1230 // This is necessary to make sure thread assets get destroyed while the 1231 // thread is still in good shape to call virtual thread methods. This must 1232 // be called by classes that derive from Thread in their destructor. 1233 virtual void DestroyThread(); 1234 1235 ThreadPlanStack &GetPlans() const; 1236 1237 void PushPlan(lldb::ThreadPlanSP plan_sp); 1238 1239 void PopPlan(); 1240 1241 void DiscardPlan(); 1242 1243 ThreadPlan *GetPreviousPlan(ThreadPlan *plan) const; 1244 1245 virtual Unwind &GetUnwinder(); 1246 1247 // Check to see whether the thread is still at the last breakpoint hit that 1248 // stopped it. 1249 virtual bool IsStillAtLastBreakpointHit(); 1250 1251 // Some threads are threads that are made up by OperatingSystem plugins that 1252 // are threads that exist and are context switched out into memory. The 1253 // OperatingSystem plug-in need a ways to know if a thread is "real" or made 1254 // up. IsOperatingSystemPluginThread()1255 virtual bool IsOperatingSystemPluginThread() const { return false; } 1256 1257 // Subclasses that have a way to get an extended info dictionary for this 1258 // thread should fill FetchThreadExtendedInfo()1259 virtual lldb_private::StructuredData::ObjectSP FetchThreadExtendedInfo() { 1260 return StructuredData::ObjectSP(); 1261 } 1262 1263 lldb::StackFrameListSP GetStackFrameList(); 1264 SetTemporaryResumeState(lldb::StateType new_state)1265 void SetTemporaryResumeState(lldb::StateType new_state) { 1266 m_temporary_resume_state = new_state; 1267 } 1268 1269 void FrameSelectedCallback(lldb_private::StackFrame *frame); 1270 1271 virtual llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> GetSiginfo(size_t max_size)1272 GetSiginfo(size_t max_size) const { 1273 return llvm::make_error<UnimplementedError>(); 1274 } 1275 1276 // Classes that inherit from Process can see and modify these 1277 lldb::ProcessWP m_process_wp; ///< The process that owns this thread. 1278 lldb::StopInfoSP m_stop_info_sp; ///< The private stop reason for this thread 1279 uint32_t m_stop_info_stop_id; // This is the stop id for which the StopInfo is 1280 // valid. Can use this so you know that 1281 // the thread's m_stop_info_sp is current and you don't have to fetch it 1282 // again 1283 uint32_t m_stop_info_override_stop_id; // The stop ID containing the last time 1284 // the stop info was checked against 1285 // the stop info override 1286 bool m_should_run_before_public_stop; // If this thread has "stop others" 1287 // private work to do, then it will 1288 // set this. 1289 const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread 1290 /// for easy UI/command line access. 1291 lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this 1292 ///thread's current register state. 1293 lldb::StateType m_state; ///< The state of our process. 1294 mutable std::recursive_mutex 1295 m_state_mutex; ///< Multithreaded protection for m_state. 1296 mutable std::recursive_mutex 1297 m_frame_mutex; ///< Multithreaded protection for m_state. 1298 lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily 1299 ///populated after a thread stops. 1300 lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from 1301 ///the last time this thread stopped. 1302 int m_resume_signal; ///< The signal that should be used when continuing this 1303 ///thread. 1304 lldb::StateType m_resume_state; ///< This state is used to force a thread to 1305 ///be suspended from outside the ThreadPlan 1306 ///logic. 1307 lldb::StateType m_temporary_resume_state; ///< This state records what the 1308 ///thread was told to do by the 1309 ///thread plan logic for the current 1310 ///resume. 1311 /// It gets set in Thread::ShouldResume. 1312 std::unique_ptr<lldb_private::Unwind> m_unwinder_up; 1313 bool m_destroy_called; // This is used internally to make sure derived Thread 1314 // classes call DestroyThread. 1315 LazyBool m_override_should_notify; 1316 mutable std::unique_ptr<ThreadPlanStack> m_null_plan_stack_up; 1317 1318 private: 1319 bool m_extended_info_fetched; // Have we tried to retrieve the m_extended_info 1320 // for this thread? 1321 StructuredData::ObjectSP m_extended_info; // The extended info for this thread 1322 1323 void BroadcastSelectedFrameChange(StackID &new_frame_id); 1324 1325 Thread(const Thread &) = delete; 1326 const Thread &operator=(const Thread &) = delete; 1327 }; 1328 1329 } // namespace lldb_private 1330 1331 #endif // LLDB_TARGET_THREAD_H 1332