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