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