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