|
|
|||
File indexing completed on 2026-05-10 08:42:55
0001 //===-- Thread.h ------------------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLDB_TARGET_THREAD_H 0010 #define LLDB_TARGET_THREAD_H 0011 0012 #include <memory> 0013 #include <mutex> 0014 #include <optional> 0015 #include <string> 0016 #include <vector> 0017 0018 #include "lldb/Core/UserSettingsController.h" 0019 #include "lldb/Target/ExecutionContextScope.h" 0020 #include "lldb/Target/RegisterCheckpoint.h" 0021 #include "lldb/Target/StackFrameList.h" 0022 #include "lldb/Utility/Broadcaster.h" 0023 #include "lldb/Utility/CompletionRequest.h" 0024 #include "lldb/Utility/Event.h" 0025 #include "lldb/Utility/StructuredData.h" 0026 #include "lldb/Utility/UnimplementedError.h" 0027 #include "lldb/Utility/UserID.h" 0028 #include "lldb/lldb-private.h" 0029 #include "llvm/Support/MemoryBuffer.h" 0030 0031 #define LLDB_THREAD_MAX_STOP_EXC_DATA 8 0032 0033 namespace lldb_private { 0034 0035 class ThreadPlanStack; 0036 0037 class ThreadProperties : public Properties { 0038 public: 0039 ThreadProperties(bool is_global); 0040 0041 ~ThreadProperties() override; 0042 0043 /// The regular expression returned determines symbols that this 0044 /// thread won't stop in during "step-in" operations. 0045 /// 0046 /// \return 0047 /// A pointer to a regular expression to compare against symbols, 0048 /// or nullptr if all symbols are allowed. 0049 /// 0050 const RegularExpression *GetSymbolsToAvoidRegexp(); 0051 0052 FileSpecList GetLibrariesToAvoid() const; 0053 0054 bool GetTraceEnabledState() const; 0055 0056 bool GetStepInAvoidsNoDebug() const; 0057 0058 bool GetStepOutAvoidsNoDebug() const; 0059 0060 uint64_t GetMaxBacktraceDepth() const; 0061 0062 uint64_t GetSingleThreadPlanTimeout() const; 0063 }; 0064 0065 class Thread : public std::enable_shared_from_this<Thread>, 0066 public ThreadProperties, 0067 public UserID, 0068 public ExecutionContextScope, 0069 public Broadcaster { 0070 public: 0071 /// Broadcaster event bits definitions. 0072 enum { 0073 eBroadcastBitStackChanged = (1 << 0), 0074 eBroadcastBitThreadSuspended = (1 << 1), 0075 eBroadcastBitThreadResumed = (1 << 2), 0076 eBroadcastBitSelectedFrameChanged = (1 << 3), 0077 eBroadcastBitThreadSelected = (1 << 4) 0078 }; 0079 0080 static llvm::StringRef GetStaticBroadcasterClass(); 0081 0082 llvm::StringRef GetBroadcasterClass() const override { 0083 return GetStaticBroadcasterClass(); 0084 } 0085 0086 class ThreadEventData : public EventData { 0087 public: 0088 ThreadEventData(const lldb::ThreadSP thread_sp); 0089 0090 ThreadEventData(const lldb::ThreadSP thread_sp, const StackID &stack_id); 0091 0092 ThreadEventData(); 0093 0094 ~ThreadEventData() override; 0095 0096 static llvm::StringRef GetFlavorString(); 0097 0098 llvm::StringRef GetFlavor() const override { 0099 return ThreadEventData::GetFlavorString(); 0100 } 0101 0102 void Dump(Stream *s) const override; 0103 0104 static const ThreadEventData *GetEventDataFromEvent(const Event *event_ptr); 0105 0106 static lldb::ThreadSP GetThreadFromEvent(const Event *event_ptr); 0107 0108 static StackID GetStackIDFromEvent(const Event *event_ptr); 0109 0110 static lldb::StackFrameSP GetStackFrameFromEvent(const Event *event_ptr); 0111 0112 lldb::ThreadSP GetThread() const { return m_thread_sp; } 0113 0114 StackID GetStackID() const { return m_stack_id; } 0115 0116 private: 0117 lldb::ThreadSP m_thread_sp; 0118 StackID m_stack_id; 0119 0120 ThreadEventData(const ThreadEventData &) = delete; 0121 const ThreadEventData &operator=(const ThreadEventData &) = delete; 0122 }; 0123 0124 struct ThreadStateCheckpoint { 0125 uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting 0126 // bit of data. 0127 lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you 0128 // might continue with the wrong signals. 0129 size_t m_completed_plan_checkpoint; 0130 lldb::RegisterCheckpointSP 0131 register_backup_sp; // You need to restore the registers, of course... 0132 uint32_t current_inlined_depth; 0133 lldb::addr_t current_inlined_pc; 0134 }; 0135 0136 /// Constructor 0137 /// 0138 /// \param [in] use_invalid_index_id 0139 /// Optional parameter, defaults to false. The only subclass that 0140 /// is likely to set use_invalid_index_id == true is the HistoryThread 0141 /// class. In that case, the Thread we are constructing represents 0142 /// a thread from earlier in the program execution. We may have the 0143 /// tid of the original thread that they represent but we don't want 0144 /// to reuse the IndexID of that thread, or create a new one. If a 0145 /// client wants to know the original thread's IndexID, they should use 0146 /// Thread::GetExtendedBacktraceOriginatingIndexID(). 0147 Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id = false); 0148 0149 ~Thread() override; 0150 0151 static void SettingsInitialize(); 0152 0153 static void SettingsTerminate(); 0154 0155 static ThreadProperties &GetGlobalProperties(); 0156 0157 lldb::ProcessSP GetProcess() const { return m_process_wp.lock(); } 0158 0159 int GetResumeSignal() const { return m_resume_signal; } 0160 0161 void SetResumeSignal(int signal) { m_resume_signal = signal; } 0162 0163 lldb::StateType GetState() const; 0164 0165 void SetState(lldb::StateType state); 0166 0167 /// Sets the USER resume state for this thread. If you set a thread to 0168 /// suspended with 0169 /// this API, it won't take part in any of the arbitration for ShouldResume, 0170 /// and will stay 0171 /// suspended even when other threads do get to run. 0172 /// 0173 /// N.B. This is not the state that is used internally by thread plans to 0174 /// implement 0175 /// staying on one thread while stepping over a breakpoint, etc. The is the 0176 /// TemporaryResume state, and if you are implementing some bit of strategy in 0177 /// the stepping 0178 /// machinery you should be using that state and not the user resume state. 0179 /// 0180 /// If you are just preparing all threads to run, you should not override the 0181 /// threads that are 0182 /// marked as suspended by the debugger. In that case, pass override_suspend 0183 /// = false. If you want 0184 /// to force the thread to run (e.g. the "thread continue" command, or are 0185 /// resetting the state 0186 /// (e.g. in SBThread::Resume()), then pass true to override_suspend. 0187 void SetResumeState(lldb::StateType state, bool override_suspend = false) { 0188 if (m_resume_state == lldb::eStateSuspended && !override_suspend) 0189 return; 0190 m_resume_state = state; 0191 } 0192 0193 /// Gets the USER resume state for this thread. This is not the same as what 0194 /// this thread is going to do for any particular step, however if this thread 0195 /// returns eStateSuspended, then the process control logic will never allow 0196 /// this 0197 /// thread to run. 0198 /// 0199 /// \return 0200 /// The User resume state for this thread. 0201 lldb::StateType GetResumeState() const { return m_resume_state; } 0202 0203 /// This function is called on all the threads before "ShouldResume" and 0204 /// "WillResume" in case a thread needs to change its state before the 0205 /// ThreadList polls all the threads to figure out which ones actually will 0206 /// get to run and how. 0207 /// 0208 /// \return 0209 /// True if we pushed a ThreadPlanStepOverBreakpoint 0210 bool SetupForResume(); 0211 0212 // Do not override this function, it is for thread plan logic only 0213 bool ShouldResume(lldb::StateType resume_state); 0214 0215 // Override this to do platform specific tasks before resume. 0216 virtual void WillResume(lldb::StateType resume_state) {} 0217 0218 // This clears generic thread state after a resume. If you subclass this, be 0219 // sure to call it. 0220 virtual void DidResume(); 0221 0222 // This notifies the thread when a private stop occurs. 0223 virtual void DidStop(); 0224 0225 virtual void RefreshStateAfterStop() = 0; 0226 0227 std::string GetStopDescription(); 0228 0229 std::string GetStopDescriptionRaw(); 0230 0231 void WillStop(); 0232 0233 bool ShouldStop(Event *event_ptr); 0234 0235 Vote ShouldReportStop(Event *event_ptr); 0236 0237 Vote ShouldReportRun(Event *event_ptr); 0238 0239 void Flush(); 0240 0241 // Return whether this thread matches the specification in ThreadSpec. This 0242 // is a virtual method because at some point we may extend the thread spec 0243 // with a platform specific dictionary of attributes, which then only the 0244 // platform specific Thread implementation would know how to match. For now, 0245 // this just calls through to the ThreadSpec's ThreadPassesBasicTests method. 0246 virtual bool MatchesSpec(const ThreadSpec *spec); 0247 0248 // Get the current public stop info, calculating it if necessary. 0249 lldb::StopInfoSP GetStopInfo(); 0250 0251 lldb::StopReason GetStopReason(); 0252 0253 bool StopInfoIsUpToDate() const; 0254 0255 // This sets the stop reason to a "blank" stop reason, so you can call 0256 // functions on the thread without having the called function run with 0257 // whatever stop reason you stopped with. 0258 void SetStopInfoToNothing(); 0259 0260 bool ThreadStoppedForAReason(); 0261 0262 static std::string RunModeAsString(lldb::RunMode mode); 0263 0264 static std::string StopReasonAsString(lldb::StopReason reason); 0265 0266 virtual const char *GetInfo() { return nullptr; } 0267 0268 /// Retrieve a dictionary of information about this thread 0269 /// 0270 /// On Mac OS X systems there may be voucher information. 0271 /// The top level dictionary returned will have an "activity" key and the 0272 /// value of the activity is a dictionary. Keys in that dictionary will 0273 /// be "name" and "id", among others. 0274 /// There may also be "trace_messages" (an array) with each entry in that 0275 /// array 0276 /// being a dictionary (keys include "message" with the text of the trace 0277 /// message). 0278 StructuredData::ObjectSP GetExtendedInfo() { 0279 if (!m_extended_info_fetched) { 0280 m_extended_info = FetchThreadExtendedInfo(); 0281 m_extended_info_fetched = true; 0282 } 0283 return m_extended_info; 0284 } 0285 0286 virtual const char *GetName() { return nullptr; } 0287 0288 virtual void SetName(const char *name) {} 0289 0290 /// Whether this thread can be associated with a libdispatch queue 0291 /// 0292 /// The Thread may know if it is associated with a libdispatch queue, 0293 /// it may know definitively that it is NOT associated with a libdispatch 0294 /// queue, or it may be unknown whether it is associated with a libdispatch 0295 /// queue. 0296 /// 0297 /// \return 0298 /// eLazyBoolNo if this thread is definitely not associated with a 0299 /// libdispatch queue (e.g. on a non-Darwin system where GCD aka 0300 /// libdispatch is not available). 0301 /// 0302 /// eLazyBoolYes this thread is associated with a libdispatch queue. 0303 /// 0304 /// eLazyBoolCalculate this thread may be associated with a libdispatch 0305 /// queue but the thread doesn't know one way or the other. 0306 virtual lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() { 0307 return eLazyBoolNo; 0308 } 0309 0310 virtual void SetAssociatedWithLibdispatchQueue( 0311 lldb_private::LazyBool associated_with_libdispatch_queue) {} 0312 0313 /// Retrieve the Queue ID for the queue currently using this Thread 0314 /// 0315 /// If this Thread is doing work on behalf of a libdispatch/GCD queue, 0316 /// retrieve the QueueID. 0317 /// 0318 /// This is a unique identifier for the libdispatch/GCD queue in a 0319 /// process. Often starting at 1 for the initial system-created 0320 /// queues and incrementing, a QueueID will not be reused for a 0321 /// different queue during the lifetime of a process. 0322 /// 0323 /// \return 0324 /// A QueueID if the Thread subclass implements this, else 0325 /// LLDB_INVALID_QUEUE_ID. 0326 virtual lldb::queue_id_t GetQueueID() { return LLDB_INVALID_QUEUE_ID; } 0327 0328 virtual void SetQueueID(lldb::queue_id_t new_val) {} 0329 0330 /// Retrieve the Queue name for the queue currently using this Thread 0331 /// 0332 /// If this Thread is doing work on behalf of a libdispatch/GCD queue, 0333 /// retrieve the Queue name. 0334 /// 0335 /// \return 0336 /// The Queue name, if the Thread subclass implements this, else 0337 /// nullptr. 0338 virtual const char *GetQueueName() { return nullptr; } 0339 0340 virtual void SetQueueName(const char *name) {} 0341 0342 /// Retrieve the Queue kind for the queue currently using this Thread 0343 /// 0344 /// If this Thread is doing work on behalf of a libdispatch/GCD queue, 0345 /// retrieve the Queue kind - either eQueueKindSerial or 0346 /// eQueueKindConcurrent, indicating that this queue processes work 0347 /// items serially or concurrently. 0348 /// 0349 /// \return 0350 /// The Queue kind, if the Thread subclass implements this, else 0351 /// eQueueKindUnknown. 0352 virtual lldb::QueueKind GetQueueKind() { return lldb::eQueueKindUnknown; } 0353 0354 virtual void SetQueueKind(lldb::QueueKind kind) {} 0355 0356 /// Retrieve the Queue for this thread, if any. 0357 /// 0358 /// \return 0359 /// A QueueSP for the queue that is currently associated with this 0360 /// thread. 0361 /// An empty shared pointer indicates that this thread is not 0362 /// associated with a queue, or libdispatch queues are not 0363 /// supported on this target. 0364 virtual lldb::QueueSP GetQueue() { return lldb::QueueSP(); } 0365 0366 /// Retrieve the address of the libdispatch_queue_t struct for queue 0367 /// currently using this Thread 0368 /// 0369 /// If this Thread is doing work on behalf of a libdispatch/GCD queue, 0370 /// retrieve the address of the libdispatch_queue_t structure describing 0371 /// the queue. 0372 /// 0373 /// This address may be reused for different queues later in the Process 0374 /// lifetime and should not be used to identify a queue uniquely. Use 0375 /// the GetQueueID() call for that. 0376 /// 0377 /// \return 0378 /// The Queue's libdispatch_queue_t address if the Thread subclass 0379 /// implements this, else LLDB_INVALID_ADDRESS. 0380 virtual lldb::addr_t GetQueueLibdispatchQueueAddress() { 0381 return LLDB_INVALID_ADDRESS; 0382 } 0383 0384 virtual void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) {} 0385 0386 /// Whether this Thread already has all the Queue information cached or not 0387 /// 0388 /// A Thread may be associated with a libdispatch work Queue at a given 0389 /// public stop event. If so, the thread can satisify requests like 0390 /// GetQueueLibdispatchQueueAddress, GetQueueKind, GetQueueName, and 0391 /// GetQueueID 0392 /// either from information from the remote debug stub when it is initially 0393 /// created, or it can query the SystemRuntime for that information. 0394 /// 0395 /// This method allows the SystemRuntime to discover if a thread has this 0396 /// information already, instead of calling the thread to get the information 0397 /// and having the thread call the SystemRuntime again. 0398 virtual bool ThreadHasQueueInformation() const { return false; } 0399 0400 /// GetStackFrameCount can be expensive. Stacks can get very deep, and they 0401 /// require memory reads for each frame. So only use GetStackFrameCount when 0402 /// you need to know the depth of the stack. When iterating over frames, its 0403 /// better to generate the frames one by one with GetFrameAtIndex, and when 0404 /// that returns NULL, you are at the end of the stack. That way your loop 0405 /// will only do the work it needs to, without forcing lldb to realize 0406 /// StackFrames you weren't going to look at. 0407 virtual uint32_t GetStackFrameCount() { 0408 return GetStackFrameList()->GetNumFrames(); 0409 } 0410 0411 virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx) { 0412 return GetStackFrameList()->GetFrameAtIndex(idx); 0413 } 0414 0415 virtual lldb::StackFrameSP 0416 GetFrameWithConcreteFrameIndex(uint32_t unwind_idx); 0417 0418 bool DecrementCurrentInlinedDepth() { 0419 return GetStackFrameList()->DecrementCurrentInlinedDepth(); 0420 } 0421 0422 uint32_t GetCurrentInlinedDepth() { 0423 return GetStackFrameList()->GetCurrentInlinedDepth(); 0424 } 0425 0426 Status ReturnFromFrameWithIndex(uint32_t frame_idx, 0427 lldb::ValueObjectSP return_value_sp, 0428 bool broadcast = false); 0429 0430 Status ReturnFromFrame(lldb::StackFrameSP frame_sp, 0431 lldb::ValueObjectSP return_value_sp, 0432 bool broadcast = false); 0433 0434 Status JumpToLine(const FileSpec &file, uint32_t line, 0435 bool can_leave_function, std::string *warnings = nullptr); 0436 0437 virtual lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id) { 0438 if (stack_id.IsValid()) 0439 return GetStackFrameList()->GetFrameWithStackID(stack_id); 0440 return lldb::StackFrameSP(); 0441 } 0442 0443 // Only pass true to select_most_relevant if you are fulfilling an explicit 0444 // user request for GetSelectedFrameIndex. The most relevant frame is only 0445 // for showing to the user, and can do arbitrary work, so we don't want to 0446 // call it internally. 0447 uint32_t GetSelectedFrameIndex(SelectMostRelevant select_most_relevant) { 0448 return GetStackFrameList()->GetSelectedFrameIndex(select_most_relevant); 0449 } 0450 0451 lldb::StackFrameSP 0452 GetSelectedFrame(SelectMostRelevant select_most_relevant); 0453 0454 uint32_t SetSelectedFrame(lldb_private::StackFrame *frame, 0455 bool broadcast = false); 0456 0457 bool SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast = false); 0458 0459 bool SetSelectedFrameByIndexNoisily(uint32_t frame_idx, 0460 Stream &output_stream); 0461 0462 void SetDefaultFileAndLineToSelectedFrame() { 0463 GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame(); 0464 } 0465 0466 virtual lldb::RegisterContextSP GetRegisterContext() = 0; 0467 0468 virtual lldb::RegisterContextSP 0469 CreateRegisterContextForFrame(StackFrame *frame) = 0; 0470 0471 virtual void ClearStackFrames(); 0472 0473 virtual bool SetBackingThread(const lldb::ThreadSP &thread_sp) { 0474 return false; 0475 } 0476 0477 virtual lldb::ThreadSP GetBackingThread() const { return lldb::ThreadSP(); } 0478 0479 virtual void ClearBackingThread() { 0480 // Subclasses can use this function if a thread is actually backed by 0481 // another thread. This is currently used for the OperatingSystem plug-ins 0482 // where they might have a thread that is in memory, yet its registers are 0483 // available through the lldb_private::Thread subclass for the current 0484 // lldb_private::Process class. Since each time the process stops the 0485 // backing threads for memory threads can change, we need a way to clear 0486 // the backing thread for all memory threads each time we stop. 0487 } 0488 0489 /// Dump \a count instructions of the thread's \a Trace starting at the \a 0490 /// start_position position in reverse order. 0491 /// 0492 /// The instructions are indexed in reverse order, which means that the \a 0493 /// start_position 0 represents the last instruction of the trace 0494 /// chronologically. 0495 /// 0496 /// \param[in] s 0497 /// The stream object where the instructions are printed. 0498 /// 0499 /// \param[in] count 0500 /// The number of instructions to print. 0501 /// 0502 /// \param[in] start_position 0503 /// The position of the first instruction to print. 0504 void DumpTraceInstructions(Stream &s, size_t count, 0505 size_t start_position = 0) const; 0506 0507 /// Print a description of this thread using the provided thread format. 0508 /// 0509 /// \param[out] strm 0510 /// The Stream to print the description to. 0511 /// 0512 /// \param[in] frame_idx 0513 /// If not \b LLDB_INVALID_FRAME_ID, then use this frame index as context to 0514 /// generate the description. 0515 /// 0516 /// \param[in] format 0517 /// The input format. 0518 /// 0519 /// \return 0520 /// \b true if and only if dumping with the given \p format worked. 0521 bool DumpUsingFormat(Stream &strm, uint32_t frame_idx, 0522 const FormatEntity::Entry *format); 0523 0524 // If stop_format is true, this will be the form used when we print stop 0525 // info. If false, it will be the form we use for thread list and co. 0526 void DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx, 0527 bool stop_format); 0528 0529 bool GetDescription(Stream &s, lldb::DescriptionLevel level, 0530 bool print_json_thread, bool print_json_stopinfo); 0531 0532 /// Default implementation for stepping into. 0533 /// 0534 /// This function is designed to be used by commands where the 0535 /// process is publicly stopped. 0536 /// 0537 /// \param[in] source_step 0538 /// If true and the frame has debug info, then do a source level 0539 /// step in, else do a single instruction step in. 0540 /// 0541 /// \param[in] step_in_avoids_code_without_debug_info 0542 /// If \a true, then avoid stepping into code that doesn't have 0543 /// debug info, else step into any code regardless of whether it 0544 /// has debug info. 0545 /// 0546 /// \param[in] step_out_avoids_code_without_debug_info 0547 /// If \a true, then if you step out to code with no debug info, keep 0548 /// stepping out till you get to code with debug info. 0549 /// 0550 /// \return 0551 /// An error that describes anything that went wrong 0552 virtual Status 0553 StepIn(bool source_step, 0554 LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, 0555 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 0556 0557 /// Default implementation for stepping over. 0558 /// 0559 /// This function is designed to be used by commands where the 0560 /// process is publicly stopped. 0561 /// 0562 /// \param[in] source_step 0563 /// If true and the frame has debug info, then do a source level 0564 /// step over, else do a single instruction step over. 0565 /// 0566 /// \return 0567 /// An error that describes anything that went wrong 0568 virtual Status StepOver( 0569 bool source_step, 0570 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 0571 0572 /// Default implementation for stepping out. 0573 /// 0574 /// This function is designed to be used by commands where the 0575 /// process is publicly stopped. 0576 /// 0577 /// \param[in] frame_idx 0578 /// The frame index to step out of. 0579 /// 0580 /// \return 0581 /// An error that describes anything that went wrong 0582 virtual Status StepOut(uint32_t frame_idx = 0); 0583 0584 /// Retrieves the per-thread data area. 0585 /// Most OSs maintain a per-thread pointer (e.g. the FS register on 0586 /// x64), which we return the value of here. 0587 /// 0588 /// \return 0589 /// LLDB_INVALID_ADDRESS if not supported, otherwise the thread 0590 /// pointer value. 0591 virtual lldb::addr_t GetThreadPointer(); 0592 0593 /// Retrieves the per-module TLS block for a thread. 0594 /// 0595 /// \param[in] module 0596 /// The module to query TLS data for. 0597 /// 0598 /// \param[in] tls_file_addr 0599 /// The thread local address in module 0600 /// \return 0601 /// If the thread has TLS data allocated for the 0602 /// module, the address of the TLS block. Otherwise 0603 /// LLDB_INVALID_ADDRESS is returned. 0604 virtual lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, 0605 lldb::addr_t tls_file_addr); 0606 0607 /// Check whether this thread is safe to run functions 0608 /// 0609 /// The SystemRuntime may know of certain thread states (functions in 0610 /// process of execution, for instance) which can make it unsafe for 0611 /// functions to be called. 0612 /// 0613 /// \return 0614 /// True if it is safe to call functions on this thread. 0615 /// False if function calls should be avoided on this thread. 0616 virtual bool SafeToCallFunctions(); 0617 0618 // Thread Plan Providers: 0619 // This section provides the basic thread plans that the Process control 0620 // machinery uses to run the target. ThreadPlan.h provides more details on 0621 // how this mechanism works. The thread provides accessors to a set of plans 0622 // that perform basic operations. The idea is that particular Platform 0623 // plugins can override these methods to provide the implementation of these 0624 // basic operations appropriate to their environment. 0625 // 0626 // NB: All the QueueThreadPlanXXX providers return Shared Pointers to 0627 // Thread plans. This is useful so that you can modify the plans after 0628 // creation in ways specific to that plan type. Also, it is often necessary 0629 // for ThreadPlans that utilize other ThreadPlans to implement their task to 0630 // keep a shared pointer to the sub-plan. But besides that, the shared 0631 // pointers should only be held onto by entities who live no longer than the 0632 // thread containing the ThreadPlan. 0633 // FIXME: If this becomes a problem, we can make a version that just returns a 0634 // pointer, 0635 // which it is clearly unsafe to hold onto, and a shared pointer version, and 0636 // only allow ThreadPlan and Co. to use the latter. That is made more 0637 // annoying to do because there's no elegant way to friend a method to all 0638 // sub-classes of a given class. 0639 // 0640 0641 /// Queues the base plan for a thread. 0642 /// The version returned by Process does some things that are useful, 0643 /// like handle breakpoints and signals, so if you return a plugin specific 0644 /// one you probably want to call through to the Process one for anything 0645 /// your plugin doesn't explicitly handle. 0646 /// 0647 /// \param[in] abort_other_plans 0648 /// \b true if we discard the currently queued plans and replace them with 0649 /// this one. 0650 /// Otherwise this plan will go on the end of the plan stack. 0651 /// 0652 /// \return 0653 /// A shared pointer to the newly queued thread plan, or nullptr if the 0654 /// plan could not be queued. 0655 lldb::ThreadPlanSP QueueBasePlan(bool abort_other_plans); 0656 0657 /// Queues the plan used to step one instruction from the current PC of \a 0658 /// thread. 0659 /// 0660 /// \param[in] step_over 0661 /// \b true if we step over calls to functions, false if we step in. 0662 /// 0663 /// \param[in] abort_other_plans 0664 /// \b true if we discard the currently queued plans and replace them with 0665 /// this one. 0666 /// Otherwise this plan will go on the end of the plan stack. 0667 /// 0668 /// \param[in] stop_other_threads 0669 /// \b true if we will stop other threads while we single step this one. 0670 /// 0671 /// \param[out] status 0672 /// A status with an error if queuing failed. 0673 /// 0674 /// \return 0675 /// A shared pointer to the newly queued thread plan, or nullptr if the 0676 /// plan could not be queued. 0677 virtual lldb::ThreadPlanSP QueueThreadPlanForStepSingleInstruction( 0678 bool step_over, bool abort_other_plans, bool stop_other_threads, 0679 Status &status); 0680 0681 /// Queues the plan used to step through an address range, stepping over 0682 /// function calls. 0683 /// 0684 /// \param[in] abort_other_plans 0685 /// \b true if we discard the currently queued plans and replace them with 0686 /// this one. 0687 /// Otherwise this plan will go on the end of the plan stack. 0688 /// 0689 /// \param[in] type 0690 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported 0691 /// by this plan. 0692 /// 0693 /// \param[in] range 0694 /// The address range to step through. 0695 /// 0696 /// \param[in] addr_context 0697 /// When dealing with stepping through inlined functions the current PC is 0698 /// not enough information to know 0699 /// what "step" means. For instance a series of nested inline functions 0700 /// might start at the same address. 0701 // The \a addr_context provides the current symbol context the step 0702 /// is supposed to be out of. 0703 // FIXME: Currently unused. 0704 /// 0705 /// \param[in] stop_other_threads 0706 /// \b true if we will stop other threads while we single step this one. 0707 /// 0708 /// \param[out] status 0709 /// A status with an error if queuing failed. 0710 /// 0711 /// \param[in] step_out_avoids_code_without_debug_info 0712 /// If eLazyBoolYes, if the step over steps out it will continue to step 0713 /// out till it comes to a frame with debug info. 0714 /// If eLazyBoolCalculate, we will consult the default set in the thread. 0715 /// 0716 /// \return 0717 /// A shared pointer to the newly queued thread plan, or nullptr if the 0718 /// plan could not be queued. 0719 virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange( 0720 bool abort_other_plans, const AddressRange &range, 0721 const SymbolContext &addr_context, lldb::RunMode stop_other_threads, 0722 Status &status, 0723 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 0724 0725 // Helper function that takes a LineEntry to step, insted of an AddressRange. 0726 // This may combine multiple LineEntries of the same source line number to 0727 // step over a longer address range in a single operation. 0728 virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange( 0729 bool abort_other_plans, const LineEntry &line_entry, 0730 const SymbolContext &addr_context, lldb::RunMode stop_other_threads, 0731 Status &status, 0732 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 0733 0734 /// Queues the plan used to step through an address range, stepping into 0735 /// functions. 0736 /// 0737 /// \param[in] abort_other_plans 0738 /// \b true if we discard the currently queued plans and replace them with 0739 /// this one. 0740 /// Otherwise this plan will go on the end of the plan stack. 0741 /// 0742 /// \param[in] type 0743 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported 0744 /// by this plan. 0745 /// 0746 /// \param[in] range 0747 /// The address range to step through. 0748 /// 0749 /// \param[in] addr_context 0750 /// When dealing with stepping through inlined functions the current PC is 0751 /// not enough information to know 0752 /// what "step" means. For instance a series of nested inline functions 0753 /// might start at the same address. 0754 // The \a addr_context provides the current symbol context the step 0755 /// is supposed to be out of. 0756 // FIXME: Currently unused. 0757 /// 0758 /// \param[in] step_in_target 0759 /// Name if function we are trying to step into. We will step out if we 0760 /// don't land in that function. 0761 /// 0762 /// \param[in] stop_other_threads 0763 /// \b true if we will stop other threads while we single step this one. 0764 /// 0765 /// \param[out] status 0766 /// A status with an error if queuing failed. 0767 /// 0768 /// \param[in] step_in_avoids_code_without_debug_info 0769 /// If eLazyBoolYes we will step out if we step into code with no debug 0770 /// info. 0771 /// If eLazyBoolCalculate we will consult the default set in the thread. 0772 /// 0773 /// \param[in] step_out_avoids_code_without_debug_info 0774 /// If eLazyBoolYes, if the step over steps out it will continue to step 0775 /// out till it comes to a frame with debug info. 0776 /// If eLazyBoolCalculate, it will consult the default set in the thread. 0777 /// 0778 /// \return 0779 /// A shared pointer to the newly queued thread plan, or nullptr if the 0780 /// plan could not be queued. 0781 virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange( 0782 bool abort_other_plans, const AddressRange &range, 0783 const SymbolContext &addr_context, const char *step_in_target, 0784 lldb::RunMode stop_other_threads, Status &status, 0785 LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, 0786 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 0787 0788 // Helper function that takes a LineEntry to step, insted of an AddressRange. 0789 // This may combine multiple LineEntries of the same source line number to 0790 // step over a longer address range in a single operation. 0791 virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange( 0792 bool abort_other_plans, const LineEntry &line_entry, 0793 const SymbolContext &addr_context, const char *step_in_target, 0794 lldb::RunMode stop_other_threads, Status &status, 0795 LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, 0796 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 0797 0798 /// Queue the plan used to step out of the function at the current PC of 0799 /// \a thread. 0800 /// 0801 /// \param[in] abort_other_plans 0802 /// \b true if we discard the currently queued plans and replace them with 0803 /// this one. 0804 /// Otherwise this plan will go on the end of the plan stack. 0805 /// 0806 /// \param[in] addr_context 0807 /// When dealing with stepping through inlined functions the current PC is 0808 /// not enough information to know 0809 /// what "step" means. For instance a series of nested inline functions 0810 /// might start at the same address. 0811 // The \a addr_context provides the current symbol context the step 0812 /// is supposed to be out of. 0813 // FIXME: Currently unused. 0814 /// 0815 /// \param[in] first_insn 0816 /// \b true if this is the first instruction of a function. 0817 /// 0818 /// \param[in] stop_other_threads 0819 /// \b true if we will stop other threads while we single step this one. 0820 /// 0821 /// \param[in] report_stop_vote 0822 /// See standard meanings for the stop & run votes in ThreadPlan.h. 0823 /// 0824 /// \param[in] report_run_vote 0825 /// See standard meanings for the stop & run votes in ThreadPlan.h. 0826 /// 0827 /// \param[out] status 0828 /// A status with an error if queuing failed. 0829 /// 0830 /// \param[in] step_out_avoids_code_without_debug_info 0831 /// If eLazyBoolYes, if the step over steps out it will continue to step 0832 /// out till it comes to a frame with debug info. 0833 /// If eLazyBoolCalculate, it will consult the default set in the thread. 0834 /// 0835 /// \return 0836 /// A shared pointer to the newly queued thread plan, or nullptr if the 0837 /// plan could not be queued. 0838 virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut( 0839 bool abort_other_plans, SymbolContext *addr_context, bool first_insn, 0840 bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote, 0841 uint32_t frame_idx, Status &status, 0842 LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); 0843 0844 /// Queue the plan used to step out of the function at the current PC of 0845 /// a thread. This version does not consult the should stop here callback, 0846 /// and should only 0847 /// be used by other thread plans when they need to retain control of the step 0848 /// out. 0849 /// 0850 /// \param[in] abort_other_plans 0851 /// \b true if we discard the currently queued plans and replace them with 0852 /// this one. 0853 /// Otherwise this plan will go on the end of the plan stack. 0854 /// 0855 /// \param[in] addr_context 0856 /// When dealing with stepping through inlined functions the current PC is 0857 /// not enough information to know 0858 /// what "step" means. For instance a series of nested inline functions 0859 /// might start at the same address. 0860 // The \a addr_context provides the current symbol context the step 0861 /// is supposed to be out of. 0862 // FIXME: Currently unused. 0863 /// 0864 /// \param[in] first_insn 0865 /// \b true if this is the first instruction of a function. 0866 /// 0867 /// \param[in] stop_other_threads 0868 /// \b true if we will stop other threads while we single step this one. 0869 /// 0870 /// \param[in] report_stop_vote 0871 /// See standard meanings for the stop & run votes in ThreadPlan.h. 0872 /// 0873 /// \param[in] report_run_vote 0874 /// See standard meanings for the stop & run votes in ThreadPlan.h. 0875 /// 0876 /// \param[in] frame_idx 0877 /// The frame index. 0878 /// 0879 /// \param[out] status 0880 /// A status with an error if queuing failed. 0881 /// 0882 /// \param[in] continue_to_next_branch 0883 /// Normally this will enqueue a plan that will put a breakpoint on the 0884 /// return address and continue 0885 /// to there. If continue_to_next_branch is true, this is an operation not 0886 /// involving the user -- 0887 /// e.g. stepping "next" in a source line and we instruction stepped into 0888 /// another function -- 0889 /// so instead of putting a breakpoint on the return address, advance the 0890 /// breakpoint to the 0891 /// end of the source line that is doing the call, or until the next flow 0892 /// control instruction. 0893 /// If the return value from the function call is to be retrieved / 0894 /// displayed to the user, you must stop 0895 /// on the return address. The return value may be stored in volatile 0896 /// registers which are overwritten 0897 /// before the next branch instruction. 0898 /// 0899 /// \return 0900 /// A shared pointer to the newly queued thread plan, or nullptr if the 0901 /// plan could not be queued. 0902 virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop( 0903 bool abort_other_plans, SymbolContext *addr_context, bool first_insn, 0904 bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote, 0905 uint32_t frame_idx, Status &status, bool continue_to_next_branch = false); 0906 0907 /// Gets the plan used to step through the code that steps from a function 0908 /// call site at the current PC into the actual function call. 0909 /// 0910 /// \param[in] return_stack_id 0911 /// The stack id that we will return to (by setting backstop breakpoints on 0912 /// the return 0913 /// address to that frame) if we fail to step through. 0914 /// 0915 /// \param[in] abort_other_plans 0916 /// \b true if we discard the currently queued plans and replace them with 0917 /// this one. 0918 /// Otherwise this plan will go on the end of the plan stack. 0919 /// 0920 /// \param[in] stop_other_threads 0921 /// \b true if we will stop other threads while we single step this one. 0922 /// 0923 /// \param[out] status 0924 /// A status with an error if queuing failed. 0925 /// 0926 /// \return 0927 /// A shared pointer to the newly queued thread plan, or nullptr if the 0928 /// plan could not be queued. 0929 virtual lldb::ThreadPlanSP 0930 QueueThreadPlanForStepThrough(StackID &return_stack_id, 0931 bool abort_other_plans, bool stop_other_threads, 0932 Status &status); 0933 0934 /// Gets the plan used to continue from the current PC. 0935 /// This is a simple plan, mostly useful as a backstop when you are continuing 0936 /// for some particular purpose. 0937 /// 0938 /// \param[in] abort_other_plans 0939 /// \b true if we discard the currently queued plans and replace them with 0940 /// this one. 0941 /// Otherwise this plan will go on the end of the plan stack. 0942 /// 0943 /// \param[in] target_addr 0944 /// The address to which we're running. 0945 /// 0946 /// \param[in] stop_other_threads 0947 /// \b true if we will stop other threads while we single step this one. 0948 /// 0949 /// \param[out] status 0950 /// A status with an error if queuing failed. 0951 /// 0952 /// \return 0953 /// A shared pointer to the newly queued thread plan, or nullptr if the 0954 /// plan could not be queued. 0955 virtual lldb::ThreadPlanSP 0956 QueueThreadPlanForRunToAddress(bool abort_other_plans, Address &target_addr, 0957 bool stop_other_threads, Status &status); 0958 0959 virtual lldb::ThreadPlanSP QueueThreadPlanForStepUntil( 0960 bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses, 0961 bool stop_others, uint32_t frame_idx, Status &status); 0962 0963 virtual lldb::ThreadPlanSP 0964 QueueThreadPlanForStepScripted(bool abort_other_plans, const char *class_name, 0965 StructuredData::ObjectSP extra_args_sp, 0966 bool stop_other_threads, Status &status); 0967 0968 // Thread Plan accessors: 0969 0970 /// Format the thread plan information for auto completion. 0971 /// 0972 /// \param[in] request 0973 /// The reference to the completion handler. 0974 void AutoCompleteThreadPlans(CompletionRequest &request) const; 0975 0976 /// Gets the plan which will execute next on the plan stack. 0977 /// 0978 /// \return 0979 /// A pointer to the next executed plan. 0980 ThreadPlan *GetCurrentPlan() const; 0981 0982 /// Unwinds the thread stack for the innermost expression plan currently 0983 /// on the thread plan stack. 0984 /// 0985 /// \return 0986 /// An error if the thread plan could not be unwound. 0987 0988 Status UnwindInnermostExpression(); 0989 0990 /// Gets the outer-most plan that was popped off the plan stack in the 0991 /// most recent stop. Useful for printing the stop reason accurately. 0992 /// 0993 /// \return 0994 /// A pointer to the last completed plan. 0995 lldb::ThreadPlanSP GetCompletedPlan() const; 0996 0997 /// Gets the outer-most return value from the completed plans 0998 /// 0999 /// \return 1000 /// A ValueObjectSP, either empty if there is no return value, 1001 /// or containing the return value. 1002 lldb::ValueObjectSP GetReturnValueObject() const; 1003 1004 /// Gets the outer-most expression variable from the completed plans 1005 /// 1006 /// \return 1007 /// A ExpressionVariableSP, either empty if there is no 1008 /// plan completed an expression during the current stop 1009 /// or the expression variable that was made for the completed expression. 1010 lldb::ExpressionVariableSP GetExpressionVariable() const; 1011 1012 /// Checks whether the given plan is in the completed plans for this 1013 /// stop. 1014 /// 1015 /// \param[in] plan 1016 /// Pointer to the plan you're checking. 1017 /// 1018 /// \return 1019 /// Returns true if the input plan is in the completed plan stack, 1020 /// false otherwise. 1021 bool IsThreadPlanDone(ThreadPlan *plan) const; 1022 1023 /// Checks whether the given plan is in the discarded plans for this 1024 /// stop. 1025 /// 1026 /// \param[in] plan 1027 /// Pointer to the plan you're checking. 1028 /// 1029 /// \return 1030 /// Returns true if the input plan is in the discarded plan stack, 1031 /// false otherwise. 1032 bool WasThreadPlanDiscarded(ThreadPlan *plan) const; 1033 1034 /// Check if we have completed plan to override breakpoint stop reason 1035 /// 1036 /// \return 1037 /// Returns true if completed plan stack is not empty 1038 /// false otherwise. 1039 bool CompletedPlanOverridesBreakpoint() const; 1040 1041 /// Queues a generic thread plan. 1042 /// 1043 /// \param[in] plan_sp 1044 /// The plan to queue. 1045 /// 1046 /// \param[in] abort_other_plans 1047 /// \b true if we discard the currently queued plans and replace them with 1048 /// this one. 1049 /// Otherwise this plan will go on the end of the plan stack. 1050 /// 1051 /// \return 1052 /// A pointer to the last completed plan. 1053 Status QueueThreadPlan(lldb::ThreadPlanSP &plan_sp, bool abort_other_plans); 1054 1055 /// Discards the plans queued on the plan stack of the current thread. This 1056 /// is 1057 /// arbitrated by the "Controlling" ThreadPlans, using the "OkayToDiscard" 1058 /// call. 1059 // But if \a force is true, all thread plans are discarded. 1060 void DiscardThreadPlans(bool force); 1061 1062 /// Discards the plans queued on the plan stack of the current thread up to 1063 /// and 1064 /// including up_to_plan_sp. 1065 // 1066 // \param[in] up_to_plan_sp 1067 // Discard all plans up to and including this one. 1068 void DiscardThreadPlansUpToPlan(lldb::ThreadPlanSP &up_to_plan_sp); 1069 1070 void DiscardThreadPlansUpToPlan(ThreadPlan *up_to_plan_ptr); 1071 1072 /// Discards the plans queued on the plan stack of the current thread up to 1073 /// and 1074 /// including the plan in that matches \a thread_index counting only 1075 /// the non-Private plans. 1076 /// 1077 /// \param[in] thread_index 1078 /// Discard all plans up to and including this user plan given by this 1079 /// index. 1080 /// 1081 /// \return 1082 /// \b true if there was a thread plan with that user index, \b false 1083 /// otherwise. 1084 bool DiscardUserThreadPlansUpToIndex(uint32_t thread_index); 1085 1086 virtual bool CheckpointThreadState(ThreadStateCheckpoint &saved_state); 1087 1088 virtual bool 1089 RestoreRegisterStateFromCheckpoint(ThreadStateCheckpoint &saved_state); 1090 1091 void RestoreThreadStateFromCheckpoint(ThreadStateCheckpoint &saved_state); 1092 1093 // Get the thread index ID. The index ID that is guaranteed to not be re-used 1094 // by a process. They start at 1 and increase with each new thread. This 1095 // allows easy command line access by a unique ID that is easier to type than 1096 // the actual system thread ID. 1097 uint32_t GetIndexID() const; 1098 1099 // Get the originating thread's index ID. 1100 // In the case of an "extended" thread -- a thread which represents the stack 1101 // that enqueued/spawned work that is currently executing -- we need to 1102 // provide the IndexID of the thread that actually did this work. We don't 1103 // want to just masquerade as that thread's IndexID by using it in our own 1104 // IndexID because that way leads to madness - but the driver program which 1105 // is iterating over extended threads may ask for the OriginatingThreadID to 1106 // display that information to the user. 1107 // Normal threads will return the same thing as GetIndexID(); 1108 virtual uint32_t GetExtendedBacktraceOriginatingIndexID() { 1109 return GetIndexID(); 1110 } 1111 1112 // The API ID is often the same as the Thread::GetID(), but not in all cases. 1113 // Thread::GetID() is the user visible thread ID that clients would want to 1114 // see. The API thread ID is the thread ID that is used when sending data 1115 // to/from the debugging protocol. 1116 virtual lldb::user_id_t GetProtocolID() const { return GetID(); } 1117 1118 // lldb::ExecutionContextScope pure virtual functions 1119 lldb::TargetSP CalculateTarget() override; 1120 1121 lldb::ProcessSP CalculateProcess() override; 1122 1123 lldb::ThreadSP CalculateThread() override; 1124 1125 lldb::StackFrameSP CalculateStackFrame() override; 1126 1127 void CalculateExecutionContext(ExecutionContext &exe_ctx) override; 1128 1129 lldb::StackFrameSP 1130 GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr); 1131 1132 size_t GetStatus(Stream &strm, uint32_t start_frame, uint32_t num_frames, 1133 uint32_t num_frames_with_source, bool stop_format, 1134 bool show_hidden, bool only_stacks = false); 1135 1136 size_t GetStackFrameStatus(Stream &strm, uint32_t first_frame, 1137 uint32_t num_frames, bool show_frame_info, 1138 uint32_t num_frames_with_source, bool show_hidden); 1139 1140 // We need a way to verify that even though we have a thread in a shared 1141 // pointer that the object itself is still valid. Currently this won't be the 1142 // case if DestroyThread() was called. DestroyThread is called when a thread 1143 // has been removed from the Process' thread list. 1144 bool IsValid() const { return !m_destroy_called; } 1145 1146 // Sets and returns a valid stop info based on the process stop ID and the 1147 // current thread plan. If the thread stop ID does not match the process' 1148 // stop ID, the private stop reason is not set and an invalid StopInfoSP may 1149 // be returned. 1150 // 1151 // NOTE: This function must be called before the current thread plan is 1152 // moved to the completed plan stack (in Thread::ShouldStop()). 1153 // 1154 // NOTE: If subclasses override this function, ensure they do not overwrite 1155 // the m_actual_stop_info if it is valid. The stop info may be a 1156 // "checkpointed and restored" stop info, so if it is still around it is 1157 // right even if you have not calculated this yourself, or if it disagrees 1158 // with what you might have calculated. 1159 virtual lldb::StopInfoSP GetPrivateStopInfo(bool calculate = true); 1160 1161 // Calculate the stop info that will be shown to lldb clients. For instance, 1162 // a "step out" is implemented by running to a breakpoint on the function 1163 // return PC, so the process plugin initially sets the stop info to a 1164 // StopInfoBreakpoint. But once we've run the ShouldStop machinery, we 1165 // discover that there's a completed ThreadPlanStepOut, and that's really 1166 // the StopInfo we want to show. That will happen naturally the next 1167 // time GetStopInfo is called, but if you want to force the replacement, 1168 // you can call this. 1169 1170 void CalculatePublicStopInfo(); 1171 1172 /// Ask the thread subclass to set its stop info. 1173 /// 1174 /// Thread subclasses should call Thread::SetStopInfo(...) with the reason the 1175 /// thread stopped. 1176 /// 1177 /// A thread that is sitting at a breakpoint site, but has not yet executed 1178 /// the breakpoint instruction, should have a breakpoint-hit StopInfo set. 1179 /// When execution is resumed, any thread sitting at a breakpoint site will 1180 /// instruction-step over the breakpoint instruction silently, and we will 1181 /// never record this breakpoint as being hit, updating the hit count, 1182 /// possibly executing breakpoint commands or conditions. 1183 /// 1184 /// \return 1185 /// True if Thread::SetStopInfo(...) was called, false otherwise. 1186 virtual bool CalculateStopInfo() = 0; 1187 1188 // Gets the temporary resume state for a thread. 1189 // 1190 // This value gets set in each thread by complex debugger logic in 1191 // Thread::ShouldResume() and an appropriate thread resume state will get set 1192 // in each thread every time the process is resumed prior to calling 1193 // Process::DoResume(). The lldb_private::Process subclass should adhere to 1194 // the thread resume state request which will be one of: 1195 // 1196 // eStateRunning - thread will resume when process is resumed 1197 // eStateStepping - thread should step 1 instruction and stop when process 1198 // is resumed 1199 // eStateSuspended - thread should not execute any instructions when 1200 // process is resumed 1201 lldb::StateType GetTemporaryResumeState() const { 1202 return m_temporary_resume_state; 1203 } 1204 1205 void SetStopInfo(const lldb::StopInfoSP &stop_info_sp); 1206 1207 void ResetStopInfo(); 1208 1209 void SetShouldReportStop(Vote vote); 1210 1211 void SetShouldRunBeforePublicStop(bool newval) { 1212 m_should_run_before_public_stop = newval; 1213 } 1214 1215 bool ShouldRunBeforePublicStop() { 1216 return m_should_run_before_public_stop; 1217 } 1218 1219 /// Sets the extended backtrace token for this thread 1220 /// 1221 /// Some Thread subclasses may maintain a token to help with providing 1222 /// an extended backtrace. The SystemRuntime plugin will set/request this. 1223 /// 1224 /// \param [in] token The extended backtrace token. 1225 virtual void SetExtendedBacktraceToken(uint64_t token) {} 1226 1227 /// Gets the extended backtrace token for this thread 1228 /// 1229 /// Some Thread subclasses may maintain a token to help with providing 1230 /// an extended backtrace. The SystemRuntime plugin will set/request this. 1231 /// 1232 /// \return 1233 /// The token needed by the SystemRuntime to create an extended backtrace. 1234 /// LLDB_INVALID_ADDRESS is returned if no token is available. 1235 virtual uint64_t GetExtendedBacktraceToken() { return LLDB_INVALID_ADDRESS; } 1236 1237 lldb::ValueObjectSP GetCurrentException(); 1238 1239 lldb::ThreadSP GetCurrentExceptionBacktrace(); 1240 1241 lldb::ValueObjectSP GetSiginfoValue(); 1242 1243 /// Request the pc value the thread had when previously stopped. 1244 /// 1245 /// When the thread performs execution, it copies the current RegisterContext 1246 /// GetPC() value. This method returns that value, if it is available. 1247 /// 1248 /// \return 1249 /// The PC value before execution was resumed. May not be available; 1250 /// an empty std::optional is returned in that case. 1251 std::optional<lldb::addr_t> GetPreviousFrameZeroPC(); 1252 1253 protected: 1254 friend class ThreadPlan; 1255 friend class ThreadList; 1256 friend class ThreadEventData; 1257 friend class StackFrameList; 1258 friend class StackFrame; 1259 friend class OperatingSystem; 1260 1261 // This is necessary to make sure thread assets get destroyed while the 1262 // thread is still in good shape to call virtual thread methods. This must 1263 // be called by classes that derive from Thread in their destructor. 1264 virtual void DestroyThread(); 1265 1266 ThreadPlanStack &GetPlans() const; 1267 1268 void PushPlan(lldb::ThreadPlanSP plan_sp); 1269 1270 void PopPlan(); 1271 1272 void DiscardPlan(); 1273 1274 ThreadPlan *GetPreviousPlan(ThreadPlan *plan) const; 1275 1276 virtual Unwind &GetUnwinder(); 1277 1278 // Check to see whether the thread is still at the last breakpoint hit that 1279 // stopped it. 1280 virtual bool IsStillAtLastBreakpointHit(); 1281 1282 // Some threads are threads that are made up by OperatingSystem plugins that 1283 // are threads that exist and are context switched out into memory. The 1284 // OperatingSystem plug-in need a ways to know if a thread is "real" or made 1285 // up. 1286 virtual bool IsOperatingSystemPluginThread() const { return false; } 1287 1288 // Subclasses that have a way to get an extended info dictionary for this 1289 // thread should fill 1290 virtual lldb_private::StructuredData::ObjectSP FetchThreadExtendedInfo() { 1291 return StructuredData::ObjectSP(); 1292 } 1293 1294 lldb::StackFrameListSP GetStackFrameList(); 1295 1296 void SetTemporaryResumeState(lldb::StateType new_state) { 1297 m_temporary_resume_state = new_state; 1298 } 1299 1300 void FrameSelectedCallback(lldb_private::StackFrame *frame); 1301 1302 virtual llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> 1303 GetSiginfo(size_t max_size) const { 1304 return llvm::make_error<UnimplementedError>(); 1305 } 1306 1307 // Classes that inherit from Process can see and modify these 1308 lldb::ProcessWP m_process_wp; ///< The process that owns this thread. 1309 lldb::StopInfoSP m_stop_info_sp; ///< The private stop reason for this thread 1310 uint32_t m_stop_info_stop_id; // This is the stop id for which the StopInfo is 1311 // valid. Can use this so you know that 1312 // the thread's m_stop_info_sp is current and you don't have to fetch it 1313 // again 1314 uint32_t m_stop_info_override_stop_id; // The stop ID containing the last time 1315 // the stop info was checked against 1316 // the stop info override 1317 bool m_should_run_before_public_stop; // If this thread has "stop others" 1318 // private work to do, then it will 1319 // set this. 1320 const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread 1321 /// for easy UI/command line access. 1322 lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this 1323 ///thread's current register state. 1324 lldb::StateType m_state; ///< The state of our process. 1325 mutable std::recursive_mutex 1326 m_state_mutex; ///< Multithreaded protection for m_state. 1327 mutable std::recursive_mutex 1328 m_frame_mutex; ///< Multithreaded protection for m_state. 1329 lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily 1330 ///populated after a thread stops. 1331 lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from 1332 ///the last time this thread stopped. 1333 std::optional<lldb::addr_t> 1334 m_prev_framezero_pc; ///< Frame 0's PC the last 1335 /// time this thread was stopped. 1336 int m_resume_signal; ///< The signal that should be used when continuing this 1337 ///thread. 1338 lldb::StateType m_resume_state; ///< This state is used to force a thread to 1339 ///be suspended from outside the ThreadPlan 1340 ///logic. 1341 lldb::StateType m_temporary_resume_state; ///< This state records what the 1342 ///thread was told to do by the 1343 ///thread plan logic for the current 1344 ///resume. 1345 /// It gets set in Thread::ShouldResume. 1346 std::unique_ptr<lldb_private::Unwind> m_unwinder_up; 1347 bool m_destroy_called; // This is used internally to make sure derived Thread 1348 // classes call DestroyThread. 1349 LazyBool m_override_should_notify; 1350 mutable std::unique_ptr<ThreadPlanStack> m_null_plan_stack_up; 1351 1352 private: 1353 bool m_extended_info_fetched; // Have we tried to retrieve the m_extended_info 1354 // for this thread? 1355 StructuredData::ObjectSP m_extended_info; // The extended info for this thread 1356 1357 void BroadcastSelectedFrameChange(StackID &new_frame_id); 1358 1359 Thread(const Thread &) = delete; 1360 const Thread &operator=(const Thread &) = delete; 1361 }; 1362 1363 } // namespace lldb_private 1364 1365 #endif // LLDB_TARGET_THREAD_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|