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