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