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 
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 
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 
108     lldb::ThreadSP GetThread() const { return m_thread_sp; }
109 
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 
153   lldb::ProcessSP GetProcess() const { return m_process_wp.lock(); }
154 
155   int GetResumeSignal() const { return m_resume_signal; }
156 
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.
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.
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 
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).
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 
279   virtual const char *GetName() { return nullptr; }
280 
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.
299   virtual lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() {
300     return eLazyBoolNo;
301   }
302 
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.
319   virtual lldb::queue_id_t GetQueueID() { return LLDB_INVALID_QUEUE_ID; }
320 
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.
331   virtual const char *GetQueueName() { return nullptr; }
332 
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.
345   virtual lldb::QueueKind GetQueueKind() { return lldb::eQueueKindUnknown; }
346 
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.
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.
373   virtual lldb::addr_t GetQueueLibdispatchQueueAddress() {
374     return LLDB_INVALID_ADDRESS;
375   }
376 
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.
391   virtual bool ThreadHasQueueInformation() const { return false; }
392 
393   virtual uint32_t GetStackFrameCount() {
394     return GetStackFrameList()->GetNumFrames();
395   }
396 
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 
404   bool DecrementCurrentInlinedDepth() {
405     return GetStackFrameList()->DecrementCurrentInlinedDepth();
406   }
407 
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 
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.
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 
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 
459   virtual bool SetBackingThread(const lldb::ThreadSP &thread_sp) {
460     return false;
461   }
462 
463   virtual lldb::ThreadSP GetBackingThread() const { return lldb::ThreadSP(); }
464 
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   // If stop_format is true, this will be the form used when we print stop
494   // info. If false, it will be the form we use for thread list and co.
495   void DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
496                                bool stop_format);
497 
498   bool GetDescription(Stream &s, lldb::DescriptionLevel level,
499                       bool print_json_thread, bool print_json_stopinfo);
500 
501   /// Default implementation for stepping into.
502   ///
503   /// This function is designed to be used by commands where the
504   /// process is publicly stopped.
505   ///
506   /// \param[in] source_step
507   ///     If true and the frame has debug info, then do a source level
508   ///     step in, else do a single instruction step in.
509   ///
510   /// \param[in] step_in_avoids_code_without_debug_info
511   ///     If \a true, then avoid stepping into code that doesn't have
512   ///     debug info, else step into any code regardless of whether it
513   ///     has debug info.
514   ///
515   /// \param[in] step_out_avoids_code_without_debug_info
516   ///     If \a true, then if you step out to code with no debug info, keep
517   ///     stepping out till you get to code with debug info.
518   ///
519   /// \return
520   ///     An error that describes anything that went wrong
521   virtual Status
522   StepIn(bool source_step,
523          LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate,
524          LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
525 
526   /// Default implementation for stepping over.
527   ///
528   /// This function is designed to be used by commands where the
529   /// process is publicly stopped.
530   ///
531   /// \param[in] source_step
532   ///     If true and the frame has debug info, then do a source level
533   ///     step over, else do a single instruction step over.
534   ///
535   /// \return
536   ///     An error that describes anything that went wrong
537   virtual Status StepOver(
538       bool source_step,
539       LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
540 
541   /// Default implementation for stepping out.
542   ///
543   /// This function is designed to be used by commands where the
544   /// process is publicly stopped.
545   ///
546   /// \param[in] frame_idx
547   ///     The frame index to step out of.
548   ///
549   /// \return
550   ///     An error that describes anything that went wrong
551   virtual Status StepOut(uint32_t frame_idx = 0);
552 
553   /// Retrieves the per-thread data area.
554   /// Most OSs maintain a per-thread pointer (e.g. the FS register on
555   /// x64), which we return the value of here.
556   ///
557   /// \return
558   ///     LLDB_INVALID_ADDRESS if not supported, otherwise the thread
559   ///     pointer value.
560   virtual lldb::addr_t GetThreadPointer();
561 
562   /// Retrieves the per-module TLS block for a thread.
563   ///
564   /// \param[in] module
565   ///     The module to query TLS data for.
566   ///
567   /// \param[in] tls_file_addr
568   ///     The thread local address in module
569   /// \return
570   ///     If the thread has TLS data allocated for the
571   ///     module, the address of the TLS block. Otherwise
572   ///     LLDB_INVALID_ADDRESS is returned.
573   virtual lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
574                                           lldb::addr_t tls_file_addr);
575 
576   /// Check whether this thread is safe to run functions
577   ///
578   /// The SystemRuntime may know of certain thread states (functions in
579   /// process of execution, for instance) which can make it unsafe for
580   /// functions to be called.
581   ///
582   /// \return
583   ///     True if it is safe to call functions on this thread.
584   ///     False if function calls should be avoided on this thread.
585   virtual bool SafeToCallFunctions();
586 
587   // Thread Plan Providers:
588   // This section provides the basic thread plans that the Process control
589   // machinery uses to run the target.  ThreadPlan.h provides more details on
590   // how this mechanism works. The thread provides accessors to a set of plans
591   // that perform basic operations. The idea is that particular Platform
592   // plugins can override these methods to provide the implementation of these
593   // basic operations appropriate to their environment.
594   //
595   // NB: All the QueueThreadPlanXXX providers return Shared Pointers to
596   // Thread plans.  This is useful so that you can modify the plans after
597   // creation in ways specific to that plan type.  Also, it is often necessary
598   // for ThreadPlans that utilize other ThreadPlans to implement their task to
599   // keep a shared pointer to the sub-plan. But besides that, the shared
600   // pointers should only be held onto by entities who live no longer than the
601   // thread containing the ThreadPlan.
602   // FIXME: If this becomes a problem, we can make a version that just returns a
603   // pointer,
604   // which it is clearly unsafe to hold onto, and a shared pointer version, and
605   // only allow ThreadPlan and Co. to use the latter.  That is made more
606   // annoying to do because there's no elegant way to friend a method to all
607   // sub-classes of a given class.
608   //
609 
610   /// Queues the base plan for a thread.
611   /// The version returned by Process does some things that are useful,
612   /// like handle breakpoints and signals, so if you return a plugin specific
613   /// one you probably want to call through to the Process one for anything
614   /// your plugin doesn't explicitly handle.
615   ///
616   /// \param[in] abort_other_plans
617   ///    \b true if we discard the currently queued plans and replace them with
618   ///    this one.
619   ///    Otherwise this plan will go on the end of the plan stack.
620   ///
621   /// \return
622   ///     A shared pointer to the newly queued thread plan, or nullptr if the
623   ///     plan could not be queued.
624   lldb::ThreadPlanSP QueueBasePlan(bool abort_other_plans);
625 
626   /// Queues the plan used to step one instruction from the current PC of \a
627   /// thread.
628   ///
629   /// \param[in] step_over
630   ///    \b true if we step over calls to functions, false if we step in.
631   ///
632   /// \param[in] abort_other_plans
633   ///    \b true if we discard the currently queued plans and replace them with
634   ///    this one.
635   ///    Otherwise this plan will go on the end of the plan stack.
636   ///
637   /// \param[in] stop_other_threads
638   ///    \b true if we will stop other threads while we single step this one.
639   ///
640   /// \param[out] status
641   ///     A status with an error if queuing failed.
642   ///
643   /// \return
644   ///     A shared pointer to the newly queued thread plan, or nullptr if the
645   ///     plan could not be queued.
646   virtual lldb::ThreadPlanSP QueueThreadPlanForStepSingleInstruction(
647       bool step_over, bool abort_other_plans, bool stop_other_threads,
648       Status &status);
649 
650   /// Queues the plan used to step through an address range, stepping  over
651   /// function calls.
652   ///
653   /// \param[in] abort_other_plans
654   ///    \b true if we discard the currently queued plans and replace them with
655   ///    this one.
656   ///    Otherwise this plan will go on the end of the plan stack.
657   ///
658   /// \param[in] type
659   ///    Type of step to do, only eStepTypeInto and eStepTypeOver are supported
660   ///    by this plan.
661   ///
662   /// \param[in] range
663   ///    The address range to step through.
664   ///
665   /// \param[in] addr_context
666   ///    When dealing with stepping through inlined functions the current PC is
667   ///    not enough information to know
668   ///    what "step" means.  For instance a series of nested inline functions
669   ///    might start at the same address.
670   //     The \a addr_context provides the current symbol context the step
671   ///    is supposed to be out of.
672   //   FIXME: Currently unused.
673   ///
674   /// \param[in] stop_other_threads
675   ///    \b true if we will stop other threads while we single step this one.
676   ///
677   /// \param[out] status
678   ///     A status with an error if queuing failed.
679   ///
680   /// \param[in] step_out_avoids_code_without_debug_info
681   ///    If eLazyBoolYes, if the step over steps out it will continue to step
682   ///    out till it comes to a frame with debug info.
683   ///    If eLazyBoolCalculate, we will consult the default set in the thread.
684   ///
685   /// \return
686   ///     A shared pointer to the newly queued thread plan, or nullptr if the
687   ///     plan could not be queued.
688   virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange(
689       bool abort_other_plans, const AddressRange &range,
690       const SymbolContext &addr_context, lldb::RunMode stop_other_threads,
691       Status &status,
692       LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
693 
694   // Helper function that takes a LineEntry to step, insted of an AddressRange.
695   // This may combine multiple LineEntries of the same source line number to
696   // step over a longer address range in a single operation.
697   virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange(
698       bool abort_other_plans, const LineEntry &line_entry,
699       const SymbolContext &addr_context, lldb::RunMode stop_other_threads,
700       Status &status,
701       LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
702 
703   /// Queues the plan used to step through an address range, stepping into
704   /// functions.
705   ///
706   /// \param[in] abort_other_plans
707   ///    \b true if we discard the currently queued plans and replace them with
708   ///    this one.
709   ///    Otherwise this plan will go on the end of the plan stack.
710   ///
711   /// \param[in] type
712   ///    Type of step to do, only eStepTypeInto and eStepTypeOver are supported
713   ///    by this plan.
714   ///
715   /// \param[in] range
716   ///    The address range to step through.
717   ///
718   /// \param[in] addr_context
719   ///    When dealing with stepping through inlined functions the current PC is
720   ///    not enough information to know
721   ///    what "step" means.  For instance a series of nested inline functions
722   ///    might start at the same address.
723   //     The \a addr_context provides the current symbol context the step
724   ///    is supposed to be out of.
725   //   FIXME: Currently unused.
726   ///
727   /// \param[in] step_in_target
728   ///    Name if function we are trying to step into.  We will step out if we
729   ///    don't land in that function.
730   ///
731   /// \param[in] stop_other_threads
732   ///    \b true if we will stop other threads while we single step this one.
733   ///
734   /// \param[out] status
735   ///     A status with an error if queuing failed.
736   ///
737   /// \param[in] step_in_avoids_code_without_debug_info
738   ///    If eLazyBoolYes we will step out if we step into code with no debug
739   ///    info.
740   ///    If eLazyBoolCalculate we will consult the default set in the thread.
741   ///
742   /// \param[in] step_out_avoids_code_without_debug_info
743   ///    If eLazyBoolYes, if the step over steps out it will continue to step
744   ///    out till it comes to a frame with debug info.
745   ///    If eLazyBoolCalculate, it will consult the default set in the thread.
746   ///
747   /// \return
748   ///     A shared pointer to the newly queued thread plan, or nullptr if the
749   ///     plan could not be queued.
750   virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange(
751       bool abort_other_plans, const AddressRange &range,
752       const SymbolContext &addr_context, const char *step_in_target,
753       lldb::RunMode stop_other_threads, Status &status,
754       LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate,
755       LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
756 
757   // Helper function that takes a LineEntry to step, insted of an AddressRange.
758   // This may combine multiple LineEntries of the same source line number to
759   // step over a longer address range in a single operation.
760   virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange(
761       bool abort_other_plans, const LineEntry &line_entry,
762       const SymbolContext &addr_context, const char *step_in_target,
763       lldb::RunMode stop_other_threads, Status &status,
764       LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate,
765       LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
766 
767   /// Queue the plan used to step out of the function at the current PC of
768   /// \a thread.
769   ///
770   /// \param[in] abort_other_plans
771   ///    \b true if we discard the currently queued plans and replace them with
772   ///    this one.
773   ///    Otherwise this plan will go on the end of the plan stack.
774   ///
775   /// \param[in] addr_context
776   ///    When dealing with stepping through inlined functions the current PC is
777   ///    not enough information to know
778   ///    what "step" means.  For instance a series of nested inline functions
779   ///    might start at the same address.
780   //     The \a addr_context provides the current symbol context the step
781   ///    is supposed to be out of.
782   //   FIXME: Currently unused.
783   ///
784   /// \param[in] first_insn
785   ///     \b true if this is the first instruction of a function.
786   ///
787   /// \param[in] stop_other_threads
788   ///    \b true if we will stop other threads while we single step this one.
789   ///
790   /// \param[in] report_stop_vote
791   ///    See standard meanings for the stop & run votes in ThreadPlan.h.
792   ///
793   /// \param[in] report_run_vote
794   ///    See standard meanings for the stop & run votes in ThreadPlan.h.
795   ///
796   /// \param[out] status
797   ///     A status with an error if queuing failed.
798   ///
799   /// \param[in] step_out_avoids_code_without_debug_info
800   ///    If eLazyBoolYes, if the step over steps out it will continue to step
801   ///    out till it comes to a frame with debug info.
802   ///    If eLazyBoolCalculate, it will consult the default set in the thread.
803   ///
804   /// \return
805   ///     A shared pointer to the newly queued thread plan, or nullptr if the
806   ///     plan could not be queued.
807   virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut(
808       bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
809       bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
810       uint32_t frame_idx, Status &status,
811       LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
812 
813   /// Queue the plan used to step out of the function at the current PC of
814   /// a thread.  This version does not consult the should stop here callback,
815   /// and should only
816   /// be used by other thread plans when they need to retain control of the step
817   /// out.
818   ///
819   /// \param[in] abort_other_plans
820   ///    \b true if we discard the currently queued plans and replace them with
821   ///    this one.
822   ///    Otherwise this plan will go on the end of the plan stack.
823   ///
824   /// \param[in] addr_context
825   ///    When dealing with stepping through inlined functions the current PC is
826   ///    not enough information to know
827   ///    what "step" means.  For instance a series of nested inline functions
828   ///    might start at the same address.
829   //     The \a addr_context provides the current symbol context the step
830   ///    is supposed to be out of.
831   //   FIXME: Currently unused.
832   ///
833   /// \param[in] first_insn
834   ///     \b true if this is the first instruction of a function.
835   ///
836   /// \param[in] stop_other_threads
837   ///    \b true if we will stop other threads while we single step this one.
838   ///
839   /// \param[in] report_stop_vote
840   ///    See standard meanings for the stop & run votes in ThreadPlan.h.
841   ///
842   /// \param[in] report_run_vote
843   ///    See standard meanings for the stop & run votes in ThreadPlan.h.
844   ///
845   /// \param[in] frame_idx
846   ///     The frame index.
847   ///
848   /// \param[out] status
849   ///     A status with an error if queuing failed.
850   ///
851   /// \param[in] continue_to_next_branch
852   ///    Normally this will enqueue a plan that will put a breakpoint on the
853   ///    return address and continue
854   ///    to there.  If continue_to_next_branch is true, this is an operation not
855   ///    involving the user --
856   ///    e.g. stepping "next" in a source line and we instruction stepped into
857   ///    another function --
858   ///    so instead of putting a breakpoint on the return address, advance the
859   ///    breakpoint to the
860   ///    end of the source line that is doing the call, or until the next flow
861   ///    control instruction.
862   ///    If the return value from the function call is to be retrieved /
863   ///    displayed to the user, you must stop
864   ///    on the return address.  The return value may be stored in volatile
865   ///    registers which are overwritten
866   ///    before the next branch instruction.
867   ///
868   /// \return
869   ///     A shared pointer to the newly queued thread plan, or nullptr if the
870   ///     plan could not be queued.
871   virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop(
872       bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
873       bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
874       uint32_t frame_idx, Status &status, bool continue_to_next_branch = false);
875 
876   /// Gets the plan used to step through the code that steps from a function
877   /// call site at the current PC into the actual function call.
878   ///
879   /// \param[in] return_stack_id
880   ///    The stack id that we will return to (by setting backstop breakpoints on
881   ///    the return
882   ///    address to that frame) if we fail to step through.
883   ///
884   /// \param[in] abort_other_plans
885   ///    \b true if we discard the currently queued plans and replace them with
886   ///    this one.
887   ///    Otherwise this plan will go on the end of the plan stack.
888   ///
889   /// \param[in] stop_other_threads
890   ///    \b true if we will stop other threads while we single step this one.
891   ///
892   /// \param[out] status
893   ///     A status with an error if queuing failed.
894   ///
895   /// \return
896   ///     A shared pointer to the newly queued thread plan, or nullptr if the
897   ///     plan could not be queued.
898   virtual lldb::ThreadPlanSP
899   QueueThreadPlanForStepThrough(StackID &return_stack_id,
900                                 bool abort_other_plans, bool stop_other_threads,
901                                 Status &status);
902 
903   /// Gets the plan used to continue from the current PC.
904   /// This is a simple plan, mostly useful as a backstop when you are continuing
905   /// for some particular purpose.
906   ///
907   /// \param[in] abort_other_plans
908   ///    \b true if we discard the currently queued plans and replace them with
909   ///    this one.
910   ///    Otherwise this plan will go on the end of the plan stack.
911   ///
912   /// \param[in] target_addr
913   ///    The address to which we're running.
914   ///
915   /// \param[in] stop_other_threads
916   ///    \b true if we will stop other threads while we single step this one.
917   ///
918   /// \param[out] status
919   ///     A status with an error if queuing failed.
920   ///
921   /// \return
922   ///     A shared pointer to the newly queued thread plan, or nullptr if the
923   ///     plan could not be queued.
924   virtual lldb::ThreadPlanSP
925   QueueThreadPlanForRunToAddress(bool abort_other_plans, Address &target_addr,
926                                  bool stop_other_threads, Status &status);
927 
928   virtual lldb::ThreadPlanSP QueueThreadPlanForStepUntil(
929       bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses,
930       bool stop_others, uint32_t frame_idx, Status &status);
931 
932   virtual lldb::ThreadPlanSP
933   QueueThreadPlanForStepScripted(bool abort_other_plans, const char *class_name,
934                                  StructuredData::ObjectSP extra_args_sp,
935                                  bool stop_other_threads, Status &status);
936 
937   // Thread Plan accessors:
938 
939   /// Format the thread plan information for auto completion.
940   ///
941   /// \param[in] request
942   ///     The reference to the completion handler.
943   void AutoCompleteThreadPlans(CompletionRequest &request) const;
944 
945   /// Gets the plan which will execute next on the plan stack.
946   ///
947   /// \return
948   ///     A pointer to the next executed plan.
949   ThreadPlan *GetCurrentPlan() const;
950 
951   /// Unwinds the thread stack for the innermost expression plan currently
952   /// on the thread plan stack.
953   ///
954   /// \return
955   ///     An error if the thread plan could not be unwound.
956 
957   Status UnwindInnermostExpression();
958 
959   /// Gets the outer-most plan that was popped off the plan stack in the
960   /// most recent stop.  Useful for printing the stop reason accurately.
961   ///
962   /// \return
963   ///     A pointer to the last completed plan.
964   lldb::ThreadPlanSP GetCompletedPlan() const;
965 
966   /// Gets the outer-most return value from the completed plans
967   ///
968   /// \return
969   ///     A ValueObjectSP, either empty if there is no return value,
970   ///     or containing the return value.
971   lldb::ValueObjectSP GetReturnValueObject() const;
972 
973   /// Gets the outer-most expression variable from the completed plans
974   ///
975   /// \return
976   ///     A ExpressionVariableSP, either empty if there is no
977   ///     plan completed an expression during the current stop
978   ///     or the expression variable that was made for the completed expression.
979   lldb::ExpressionVariableSP GetExpressionVariable() const;
980 
981   ///  Checks whether the given plan is in the completed plans for this
982   ///  stop.
983   ///
984   /// \param[in] plan
985   ///     Pointer to the plan you're checking.
986   ///
987   /// \return
988   ///     Returns true if the input plan is in the completed plan stack,
989   ///     false otherwise.
990   bool IsThreadPlanDone(ThreadPlan *plan) const;
991 
992   ///  Checks whether the given plan is in the discarded plans for this
993   ///  stop.
994   ///
995   /// \param[in] plan
996   ///     Pointer to the plan you're checking.
997   ///
998   /// \return
999   ///     Returns true if the input plan is in the discarded plan stack,
1000   ///     false otherwise.
1001   bool WasThreadPlanDiscarded(ThreadPlan *plan) const;
1002 
1003   /// Check if we have completed plan to override breakpoint stop reason
1004   ///
1005   /// \return
1006   ///     Returns true if completed plan stack is not empty
1007   ///     false otherwise.
1008   bool CompletedPlanOverridesBreakpoint() const;
1009 
1010   /// Queues a generic thread plan.
1011   ///
1012   /// \param[in] plan_sp
1013   ///    The plan to queue.
1014   ///
1015   /// \param[in] abort_other_plans
1016   ///    \b true if we discard the currently queued plans and replace them with
1017   ///    this one.
1018   ///    Otherwise this plan will go on the end of the plan stack.
1019   ///
1020   /// \return
1021   ///     A pointer to the last completed plan.
1022   Status QueueThreadPlan(lldb::ThreadPlanSP &plan_sp, bool abort_other_plans);
1023 
1024   /// Discards the plans queued on the plan stack of the current thread.  This
1025   /// is
1026   /// arbitrated by the "Controlling" ThreadPlans, using the "OkayToDiscard"
1027   /// call.
1028   //  But if \a force is true, all thread plans are discarded.
1029   void DiscardThreadPlans(bool force);
1030 
1031   /// Discards the plans queued on the plan stack of the current thread up to
1032   /// and
1033   /// including up_to_plan_sp.
1034   //
1035   // \param[in] up_to_plan_sp
1036   //   Discard all plans up to and including this one.
1037   void DiscardThreadPlansUpToPlan(lldb::ThreadPlanSP &up_to_plan_sp);
1038 
1039   void DiscardThreadPlansUpToPlan(ThreadPlan *up_to_plan_ptr);
1040 
1041   /// Discards the plans queued on the plan stack of the current thread up to
1042   /// and
1043   /// including the plan in that matches \a thread_index counting only
1044   /// the non-Private plans.
1045   ///
1046   /// \param[in] thread_index
1047   ///   Discard all plans up to and including this user plan given by this
1048   ///   index.
1049   ///
1050   /// \return
1051   ///    \b true if there was a thread plan with that user index, \b false
1052   ///    otherwise.
1053   bool DiscardUserThreadPlansUpToIndex(uint32_t thread_index);
1054 
1055   virtual bool CheckpointThreadState(ThreadStateCheckpoint &saved_state);
1056 
1057   virtual bool
1058   RestoreRegisterStateFromCheckpoint(ThreadStateCheckpoint &saved_state);
1059 
1060   void RestoreThreadStateFromCheckpoint(ThreadStateCheckpoint &saved_state);
1061 
1062   // Get the thread index ID. The index ID that is guaranteed to not be re-used
1063   // by a process. They start at 1 and increase with each new thread. This
1064   // allows easy command line access by a unique ID that is easier to type than
1065   // the actual system thread ID.
1066   uint32_t GetIndexID() const;
1067 
1068   // Get the originating thread's index ID.
1069   // In the case of an "extended" thread -- a thread which represents the stack
1070   // that enqueued/spawned work that is currently executing -- we need to
1071   // provide the IndexID of the thread that actually did this work.  We don't
1072   // want to just masquerade as that thread's IndexID by using it in our own
1073   // IndexID because that way leads to madness - but the driver program which
1074   // is iterating over extended threads may ask for the OriginatingThreadID to
1075   // display that information to the user.
1076   // Normal threads will return the same thing as GetIndexID();
1077   virtual uint32_t GetExtendedBacktraceOriginatingIndexID() {
1078     return GetIndexID();
1079   }
1080 
1081   // The API ID is often the same as the Thread::GetID(), but not in all cases.
1082   // Thread::GetID() is the user visible thread ID that clients would want to
1083   // see. The API thread ID is the thread ID that is used when sending data
1084   // to/from the debugging protocol.
1085   virtual lldb::user_id_t GetProtocolID() const { return GetID(); }
1086 
1087   // lldb::ExecutionContextScope pure virtual functions
1088   lldb::TargetSP CalculateTarget() override;
1089 
1090   lldb::ProcessSP CalculateProcess() override;
1091 
1092   lldb::ThreadSP CalculateThread() override;
1093 
1094   lldb::StackFrameSP CalculateStackFrame() override;
1095 
1096   void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
1097 
1098   lldb::StackFrameSP
1099   GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr);
1100 
1101   size_t GetStatus(Stream &strm, uint32_t start_frame, uint32_t num_frames,
1102                    uint32_t num_frames_with_source, bool stop_format,
1103                    bool only_stacks = false);
1104 
1105   size_t GetStackFrameStatus(Stream &strm, uint32_t first_frame,
1106                              uint32_t num_frames, bool show_frame_info,
1107                              uint32_t num_frames_with_source);
1108 
1109   // We need a way to verify that even though we have a thread in a shared
1110   // pointer that the object itself is still valid. Currently this won't be the
1111   // case if DestroyThread() was called. DestroyThread is called when a thread
1112   // has been removed from the Process' thread list.
1113   bool IsValid() const { return !m_destroy_called; }
1114 
1115   // Sets and returns a valid stop info based on the process stop ID and the
1116   // current thread plan. If the thread stop ID does not match the process'
1117   // stop ID, the private stop reason is not set and an invalid StopInfoSP may
1118   // be returned.
1119   //
1120   // NOTE: This function must be called before the current thread plan is
1121   // moved to the completed plan stack (in Thread::ShouldStop()).
1122   //
1123   // NOTE: If subclasses override this function, ensure they do not overwrite
1124   // the m_actual_stop_info if it is valid.  The stop info may be a
1125   // "checkpointed and restored" stop info, so if it is still around it is
1126   // right even if you have not calculated this yourself, or if it disagrees
1127   // with what you might have calculated.
1128   virtual lldb::StopInfoSP GetPrivateStopInfo(bool calculate = true);
1129 
1130   // Calculate the stop info that will be shown to lldb clients.  For instance,
1131   // a "step out" is implemented by running to a breakpoint on the function
1132   // return PC, so the process plugin initially sets the stop info to a
1133   // StopInfoBreakpoint. But once we've run the ShouldStop machinery, we
1134   // discover that there's a completed ThreadPlanStepOut, and that's really
1135   // the StopInfo we want to show.  That will happen naturally the next
1136   // time GetStopInfo is called, but if you want to force the replacement,
1137   // you can call this.
1138 
1139   void CalculatePublicStopInfo();
1140 
1141   // Ask the thread subclass to set its stop info.
1142   //
1143   // Thread subclasses should call Thread::SetStopInfo(...) with the reason the
1144   // thread stopped.
1145   //
1146   // \return
1147   //      True if Thread::SetStopInfo(...) was called, false otherwise.
1148   virtual bool CalculateStopInfo() = 0;
1149 
1150   // Gets the temporary resume state for a thread.
1151   //
1152   // This value gets set in each thread by complex debugger logic in
1153   // Thread::ShouldResume() and an appropriate thread resume state will get set
1154   // in each thread every time the process is resumed prior to calling
1155   // Process::DoResume(). The lldb_private::Process subclass should adhere to
1156   // the thread resume state request which will be one of:
1157   //
1158   //  eStateRunning   - thread will resume when process is resumed
1159   //  eStateStepping  - thread should step 1 instruction and stop when process
1160   //                    is resumed
1161   //  eStateSuspended - thread should not execute any instructions when
1162   //                    process is resumed
1163   lldb::StateType GetTemporaryResumeState() const {
1164     return m_temporary_resume_state;
1165   }
1166 
1167   void SetStopInfo(const lldb::StopInfoSP &stop_info_sp);
1168 
1169   void ResetStopInfo();
1170 
1171   void SetShouldReportStop(Vote vote);
1172 
1173   void SetShouldRunBeforePublicStop(bool newval) {
1174       m_should_run_before_public_stop = newval;
1175   }
1176 
1177   bool ShouldRunBeforePublicStop() {
1178       return m_should_run_before_public_stop;
1179   }
1180 
1181   /// Sets the extended backtrace token for this thread
1182   ///
1183   /// Some Thread subclasses may maintain a token to help with providing
1184   /// an extended backtrace.  The SystemRuntime plugin will set/request this.
1185   ///
1186   /// \param [in] token The extended backtrace token.
1187   virtual void SetExtendedBacktraceToken(uint64_t token) {}
1188 
1189   /// Gets the extended backtrace token for this thread
1190   ///
1191   /// Some Thread subclasses may maintain a token to help with providing
1192   /// an extended backtrace.  The SystemRuntime plugin will set/request this.
1193   ///
1194   /// \return
1195   ///     The token needed by the SystemRuntime to create an extended backtrace.
1196   ///     LLDB_INVALID_ADDRESS is returned if no token is available.
1197   virtual uint64_t GetExtendedBacktraceToken() { return LLDB_INVALID_ADDRESS; }
1198 
1199   lldb::ValueObjectSP GetCurrentException();
1200 
1201   lldb::ThreadSP GetCurrentExceptionBacktrace();
1202 
1203   lldb::ValueObjectSP GetSiginfoValue();
1204 
1205 protected:
1206   friend class ThreadPlan;
1207   friend class ThreadList;
1208   friend class ThreadEventData;
1209   friend class StackFrameList;
1210   friend class StackFrame;
1211   friend class OperatingSystem;
1212 
1213   // This is necessary to make sure thread assets get destroyed while the
1214   // thread is still in good shape to call virtual thread methods.  This must
1215   // be called by classes that derive from Thread in their destructor.
1216   virtual void DestroyThread();
1217 
1218   ThreadPlanStack &GetPlans() const;
1219 
1220   void PushPlan(lldb::ThreadPlanSP plan_sp);
1221 
1222   void PopPlan();
1223 
1224   void DiscardPlan();
1225 
1226   ThreadPlan *GetPreviousPlan(ThreadPlan *plan) const;
1227 
1228   virtual Unwind &GetUnwinder();
1229 
1230   // Check to see whether the thread is still at the last breakpoint hit that
1231   // stopped it.
1232   virtual bool IsStillAtLastBreakpointHit();
1233 
1234   // Some threads are threads that are made up by OperatingSystem plugins that
1235   // are threads that exist and are context switched out into memory. The
1236   // OperatingSystem plug-in need a ways to know if a thread is "real" or made
1237   // up.
1238   virtual bool IsOperatingSystemPluginThread() const { return false; }
1239 
1240   // Subclasses that have a way to get an extended info dictionary for this
1241   // thread should fill
1242   virtual lldb_private::StructuredData::ObjectSP FetchThreadExtendedInfo() {
1243     return StructuredData::ObjectSP();
1244   }
1245 
1246   lldb::StackFrameListSP GetStackFrameList();
1247 
1248   void SetTemporaryResumeState(lldb::StateType new_state) {
1249     m_temporary_resume_state = new_state;
1250   }
1251 
1252   void FrameSelectedCallback(lldb_private::StackFrame *frame);
1253 
1254   virtual llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
1255   GetSiginfo(size_t max_size) const {
1256     return llvm::make_error<UnimplementedError>();
1257   }
1258 
1259   // Classes that inherit from Process can see and modify these
1260   lldb::ProcessWP m_process_wp;    ///< The process that owns this thread.
1261   lldb::StopInfoSP m_stop_info_sp; ///< The private stop reason for this thread
1262   uint32_t m_stop_info_stop_id; // This is the stop id for which the StopInfo is
1263                                 // valid.  Can use this so you know that
1264   // the thread's m_stop_info_sp is current and you don't have to fetch it
1265   // again
1266   uint32_t m_stop_info_override_stop_id; // The stop ID containing the last time
1267                                          // the stop info was checked against
1268                                          // the stop info override
1269   bool m_should_run_before_public_stop;  // If this thread has "stop others"
1270                                          // private work to do, then it will
1271                                          // set this.
1272   const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread
1273                              /// for easy UI/command line access.
1274   lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this
1275                                             ///thread's current register state.
1276   lldb::StateType m_state;                  ///< The state of our process.
1277   mutable std::recursive_mutex
1278       m_state_mutex;       ///< Multithreaded protection for m_state.
1279   mutable std::recursive_mutex
1280       m_frame_mutex; ///< Multithreaded protection for m_state.
1281   lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily
1282                                            ///populated after a thread stops.
1283   lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from
1284                                            ///the last time this thread stopped.
1285   int m_resume_signal; ///< The signal that should be used when continuing this
1286                        ///thread.
1287   lldb::StateType m_resume_state; ///< This state is used to force a thread to
1288                                   ///be suspended from outside the ThreadPlan
1289                                   ///logic.
1290   lldb::StateType m_temporary_resume_state; ///< This state records what the
1291                                             ///thread was told to do by the
1292                                             ///thread plan logic for the current
1293                                             ///resume.
1294   /// It gets set in Thread::ShouldResume.
1295   std::unique_ptr<lldb_private::Unwind> m_unwinder_up;
1296   bool m_destroy_called; // This is used internally to make sure derived Thread
1297                          // classes call DestroyThread.
1298   LazyBool m_override_should_notify;
1299   mutable std::unique_ptr<ThreadPlanStack> m_null_plan_stack_up;
1300 
1301 private:
1302   bool m_extended_info_fetched; // Have we tried to retrieve the m_extended_info
1303                                 // for this thread?
1304   StructuredData::ObjectSP m_extended_info; // The extended info for this thread
1305 
1306   void BroadcastSelectedFrameChange(StackID &new_frame_id);
1307 
1308   Thread(const Thread &) = delete;
1309   const Thread &operator=(const Thread &) = delete;
1310 };
1311 
1312 } // namespace lldb_private
1313 
1314 #endif // LLDB_TARGET_THREAD_H
1315