LLDB mainline
Thread.cpp
Go to the documentation of this file.
1//===-- Thread.cpp --------------------------------------------------------===//
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
11#include "lldb/Core/Debugger.h"
13#include "lldb/Core/Module.h"
15#include "lldb/Host/Host.h"
23#include "lldb/Target/ABI.h"
27#include "lldb/Target/Process.h"
34#include "lldb/Target/Target.h"
50#include "lldb/Utility/Log.h"
53#include "lldb/Utility/State.h"
54#include "lldb/Utility/Stream.h"
59
60#include <memory>
61#include <optional>
62
63using namespace lldb;
64using namespace lldb_private;
65
67 // NOTE: intentional leak so we don't crash if global destructor chain gets
68 // called as other threads still use the result of this function
69 static ThreadProperties *g_settings_ptr = new ThreadProperties(true);
70 return *g_settings_ptr;
71}
72
73#define LLDB_PROPERTIES_thread
74#include "TargetProperties.inc"
75
76enum {
77#define LLDB_PROPERTIES_thread
78#include "TargetPropertiesEnum.inc"
79};
80
82 : public Cloneable<ThreadOptionValueProperties, OptionValueProperties> {
83public:
84 ThreadOptionValueProperties(llvm::StringRef name) : Cloneable(name) {}
85
86 const Property *
88 const ExecutionContext *exe_ctx) const override {
89 // When getting the value for a key from the thread options, we will always
90 // try and grab the setting from the current thread if there is one. Else
91 // we just use the one from this instance.
92 if (exe_ctx) {
93 Thread *thread = exe_ctx->GetThreadPtr();
94 if (thread) {
95 ThreadOptionValueProperties *instance_properties =
96 static_cast<ThreadOptionValueProperties *>(
97 thread->GetValueProperties().get());
98 if (this != instance_properties)
99 return instance_properties->ProtectedGetPropertyAtIndex(idx);
100 }
101 }
102 return ProtectedGetPropertyAtIndex(idx);
103 }
104};
105
107 if (is_global) {
108 m_collection_sp = std::make_shared<ThreadOptionValueProperties>("thread");
109 m_collection_sp->Initialize(g_thread_properties);
110 } else
113}
114
116
118 const uint32_t idx = ePropertyStepAvoidRegex;
120}
121
123 const uint32_t idx = ePropertyStepAvoidLibraries;
125}
126
128 const uint32_t idx = ePropertyEnableThreadTrace;
130 idx, g_thread_properties[idx].default_uint_value != 0);
131}
132
134 const uint32_t idx = ePropertyStepInAvoidsNoDebug;
136 idx, g_thread_properties[idx].default_uint_value != 0);
137}
138
140 const uint32_t idx = ePropertyStepOutAvoidsNoDebug;
142 idx, g_thread_properties[idx].default_uint_value != 0);
143}
144
146 const uint32_t idx = ePropertyMaxBacktraceDepth;
148 idx, g_thread_properties[idx].default_uint_value);
149}
150
152 const uint32_t idx = ePropertySingleThreadPlanTimeout;
154 idx, g_thread_properties[idx].default_uint_value);
155}
156
157// Thread Event Data
158
160 return "Thread::ThreadEventData";
161}
162
165
167 const StackID &stack_id)
168 : m_thread_sp(thread_sp), m_stack_id(stack_id) {}
169
171
173
175
178 if (event_ptr) {
179 const EventData *event_data = event_ptr->GetData();
180 if (event_data &&
182 return static_cast<const ThreadEventData *>(event_ptr->GetData());
183 }
184 return nullptr;
185}
186
188 ThreadSP thread_sp;
189 const ThreadEventData *event_data = GetEventDataFromEvent(event_ptr);
190 if (event_data)
191 thread_sp = event_data->GetThread();
192 return thread_sp;
193}
194
196 StackID stack_id;
197 const ThreadEventData *event_data = GetEventDataFromEvent(event_ptr);
198 if (event_data)
199 stack_id = event_data->GetStackID();
200 return stack_id;
201}
202
205 const ThreadEventData *event_data = GetEventDataFromEvent(event_ptr);
206 StackFrameSP frame_sp;
207 if (event_data) {
208 ThreadSP thread_sp = event_data->GetThread();
209 if (thread_sp) {
210 frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID(
211 event_data->GetStackID());
212 }
213 }
214 return frame_sp;
215}
216
217// Thread class
218
220 static constexpr llvm::StringLiteral class_name("lldb.thread");
221 return class_name;
222}
223
224Thread::Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id)
225 : ThreadProperties(false), UserID(tid),
226 Broadcaster(process.GetTarget().GetDebugger().GetBroadcasterManager(),
228 m_process_wp(process.shared_from_this()), m_stop_info_sp(),
232 m_index_id(use_invalid_index_id ? LLDB_INVALID_INDEX32
233 : process.GetNextThreadIndexID(tid)),
241 Log *log = GetLog(LLDBLog::Object);
242 LLDB_LOGF(log, "%p Thread::Thread(tid = 0x%4.4" PRIx64 ")",
243 static_cast<void *>(this), GetID());
244
246}
247
249 Log *log = GetLog(LLDBLog::Object);
250 LLDB_LOGF(log, "%p Thread::~Thread(tid = 0x%4.4" PRIx64 ")",
251 static_cast<void *>(this), GetID());
252 /// If you hit this assert, it means your derived class forgot to call
253 /// DestroyThread in its destructor.
254 assert(m_destroy_called);
255}
256
258 m_destroy_called = true;
259 m_stop_info_sp.reset();
260 m_reg_context_sp.reset();
261 m_unwinder_up.reset();
262 std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
263 m_curr_frames_sp.reset();
264 m_prev_frames_sp.reset();
265 m_frame_provider_sp.reset();
266 m_prev_framezero_pc.reset();
267}
268
271 auto data_sp =
272 std::make_shared<ThreadEventData>(shared_from_this(), new_frame_id);
274 }
275}
276
279 StackFrameListSP stack_frame_list_sp(GetStackFrameList());
280 StackFrameSP frame_sp = stack_frame_list_sp->GetFrameAtIndex(
281 stack_frame_list_sp->GetSelectedFrameIndex(select_most_relevant));
282 FrameSelectedCallback(frame_sp.get());
283 return frame_sp;
284}
285
287 bool broadcast) {
288 uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame);
289 if (broadcast)
292 return ret_value;
293}
294
295bool Thread::SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast) {
296 StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex(frame_idx));
297 if (frame_sp) {
298 GetStackFrameList()->SetSelectedFrame(frame_sp.get());
299 if (broadcast)
300 BroadcastSelectedFrameChange(frame_sp->GetStackID());
301 FrameSelectedCallback(frame_sp.get());
302 return true;
303 } else
304 return false;
305}
306
308 Stream &output_stream) {
309 const bool broadcast = true;
310 bool success = SetSelectedFrameByIndex(frame_idx, broadcast);
311 if (success) {
313 if (frame_sp) {
314 bool already_shown = false;
315 SymbolContext frame_sc(
316 frame_sp->GetSymbolContext(eSymbolContextLineEntry));
317 const Debugger &debugger = GetProcess()->GetTarget().GetDebugger();
318 if (debugger.GetUseExternalEditor() && frame_sc.line_entry.GetFile() &&
319 frame_sc.line_entry.line != 0) {
320 if (llvm::Error e = Host::OpenFileInExternalEditor(
321 debugger.GetExternalEditor(), frame_sc.line_entry.GetFile(),
322 frame_sc.line_entry.line)) {
323 LLDB_LOG_ERROR(GetLog(LLDBLog::Host), std::move(e),
324 "OpenFileInExternalEditor failed: {0}");
325 } else {
326 already_shown = true;
327 }
328 }
329
330 bool show_frame_info = true;
331 bool show_source = !already_shown;
332 FrameSelectedCallback(frame_sp.get());
333 return frame_sp->GetStatus(output_stream, show_frame_info, show_source);
334 }
335 return false;
336 } else
337 return false;
338}
339
341 if (!frame)
342 return;
343
344 if (frame->HasDebugInformation() &&
345 (GetProcess()->GetWarningsOptimization() ||
346 GetProcess()->GetWarningsUnsupportedLanguage())) {
347 SymbolContext sc =
348 frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextModule);
349 GetProcess()->PrintWarningOptimization(sc);
350 GetProcess()->PrintWarningUnsupportedLanguage(sc);
351 }
352}
353
356 return m_stop_info_sp;
357
358 ThreadPlanSP completed_plan_sp(GetCompletedPlan());
359 ProcessSP process_sp(GetProcess());
360 const uint32_t stop_id = process_sp ? process_sp->GetStopID() : UINT32_MAX;
361
362 // Here we select the stop info according to priorirty: - m_stop_info_sp (if
363 // not trace) - preset value - completed plan stop info - new value with plan
364 // from completed plan stack - m_stop_info_sp (trace stop reason is OK now) -
365 // ask GetPrivateStopInfo to set stop info
366
367 bool have_valid_stop_info = m_stop_info_sp &&
368 m_stop_info_sp ->IsValid() &&
369 m_stop_info_stop_id == stop_id;
370 bool have_valid_completed_plan = completed_plan_sp && completed_plan_sp->PlanSucceeded();
371 bool plan_failed = completed_plan_sp && !completed_plan_sp->PlanSucceeded();
372 bool plan_overrides_trace =
373 have_valid_stop_info && have_valid_completed_plan
374 && (m_stop_info_sp->GetStopReason() == eStopReasonTrace);
375
376 if (have_valid_stop_info && !plan_overrides_trace && !plan_failed) {
377 return m_stop_info_sp;
378 } else if (completed_plan_sp) {
380 completed_plan_sp, GetReturnValueObject(), GetExpressionVariable());
381 } else {
383 return m_stop_info_sp;
384 }
385}
386
391
393 if (!calculate)
394 return m_stop_info_sp;
395
397 return m_stop_info_sp;
398
399 ProcessSP process_sp(GetProcess());
400 if (process_sp) {
401 const uint32_t process_stop_id = process_sp->GetStopID();
402 if (m_stop_info_stop_id != process_stop_id) {
403 // We preserve the old stop info for a variety of reasons:
404 // 1) Someone has already updated it by the time we get here
405 // 2) We didn't get to execute the breakpoint instruction we stopped at
406 // 3) This is a virtual step so we didn't actually run
407 // 4) If this thread wasn't allowed to run the last time round.
408 if (m_stop_info_sp) {
409 if (m_stop_info_sp->IsValid() || IsStillAtLastBreakpointHit() ||
410 GetCurrentPlan()->IsVirtualStep()
413 else
414 m_stop_info_sp.reset();
415 }
416
417 if (!m_stop_info_sp) {
418 if (!CalculateStopInfo())
420 }
421 }
422
423 // The stop info can be manually set by calling Thread::SetStopInfo() prior
424 // to this function ever getting called, so we can't rely on
425 // "m_stop_info_stop_id != process_stop_id" as the condition for the if
426 // statement below, we must also check the stop info to see if we need to
427 // override it. See the header documentation in
428 // Architecture::OverrideStopInfo() for more information on the stop
429 // info override callback.
430 if (m_stop_info_override_stop_id != process_stop_id) {
431 m_stop_info_override_stop_id = process_stop_id;
432 if (m_stop_info_sp) {
433 if (const Architecture *arch =
434 process_sp->GetTarget().GetArchitecturePlugin())
435 arch->OverrideStopInfo(*this);
436 }
437 }
438 }
439
440 // If we were resuming the process and it was interrupted,
441 // return no stop reason. This thread would like to resume.
442 if (m_stop_info_sp && m_stop_info_sp->WasContinueInterrupted(*this))
443 return {};
444
445 return m_stop_info_sp;
446}
447
449 lldb::StopInfoSP stop_info_sp(GetStopInfo());
450 if (stop_info_sp)
451 return stop_info_sp->GetStopReason();
452 return eStopReasonNone;
453}
454
456 ProcessSP process_sp(GetProcess());
457 if (process_sp)
458 return m_stop_info_stop_id == process_sp->GetStopID();
459 else
460 return true; // Process is no longer around so stop info is always up to
461 // date...
462}
463
465 if (m_stop_info_sp) {
466 m_stop_info_sp.reset();
467 }
468}
469
470void Thread::SetStopInfo(const lldb::StopInfoSP &stop_info_sp) {
471 m_stop_info_sp = stop_info_sp;
472 if (m_stop_info_sp) {
473 m_stop_info_sp->MakeStopInfoValid();
474 // If we are overriding the ShouldReportStop, do that here:
476 m_stop_info_sp->OverrideShouldNotify(m_override_should_notify ==
478 }
479
480 ProcessSP process_sp(GetProcess());
481 if (process_sp)
482 m_stop_info_stop_id = process_sp->GetStopID();
483 else
485 Log *log = GetLog(LLDBLog::Thread);
486 LLDB_LOGF(log, "%p: tid = 0x%" PRIx64 ": stop info = %s (stop_id = %u)",
487 static_cast<void *>(this), GetID(),
488 stop_info_sp ? stop_info_sp->GetDescription() : "<NULL>",
490}
491
493 if (vote == eVoteNoOpinion)
494 return;
495 else {
497 if (m_stop_info_sp)
498 m_stop_info_sp->OverrideShouldNotify(m_override_should_notify ==
500 }
501}
502
504 // Note, we can't just NULL out the private reason, or the native thread
505 // implementation will try to go calculate it again. For now, just set it to
506 // a Unix Signal with an invalid signal number.
509}
510
512
514 saved_state.register_backup_sp.reset();
516 if (frame_sp) {
517 lldb::RegisterCheckpointSP reg_checkpoint_sp(
519 if (reg_checkpoint_sp) {
520 lldb::RegisterContextSP reg_ctx_sp(frame_sp->GetRegisterContext());
521 if (reg_ctx_sp && reg_ctx_sp->ReadAllRegisterValues(*reg_checkpoint_sp))
522 saved_state.register_backup_sp = reg_checkpoint_sp;
523 }
524 }
525 if (!saved_state.register_backup_sp)
526 return false;
527
528 saved_state.stop_info_sp = GetStopInfo();
529 ProcessSP process_sp(GetProcess());
530 if (process_sp)
531 saved_state.orig_stop_id = process_sp->GetStopID();
533 saved_state.m_completed_plan_checkpoint =
536
537 return true;
538}
539
541 ThreadStateCheckpoint &saved_state) {
542 if (saved_state.register_backup_sp) {
544 if (frame_sp) {
545 lldb::RegisterContextSP reg_ctx_sp(frame_sp->GetRegisterContext());
546 if (reg_ctx_sp) {
547 bool ret =
548 reg_ctx_sp->WriteAllRegisterValues(*saved_state.register_backup_sp);
549
550 // Clear out all stack frames as our world just changed.
552 reg_ctx_sp->InvalidateIfNeeded(true);
553 if (m_unwinder_up)
554 m_unwinder_up->Clear();
555 return ret;
556 }
557 }
558 }
559 return false;
560}
561
563 ThreadStateCheckpoint &saved_state) {
564 if (saved_state.stop_info_sp)
565 saved_state.stop_info_sp->MakeStopInfoValid();
566 SetStopInfo(saved_state.stop_info_sp);
567 GetStackFrameList()->SetCurrentInlinedDepth(
568 saved_state.current_inlined_depth);
570 saved_state.m_completed_plan_checkpoint);
572}
573
575 // If any other threads access this we will need a mutex for it
576 std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
577 return m_state;
578}
579
581 std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
582 m_state = state;
583}
584
587
588 if (!frame_sp)
589 return GetStopDescriptionRaw();
590
591 auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
592
593 if (!recognized_frame_sp)
594 return GetStopDescriptionRaw();
595
596 std::string recognized_stop_description =
597 recognized_frame_sp->GetStopDescription();
598
599 if (!recognized_stop_description.empty())
600 return recognized_stop_description;
601
602 return GetStopDescriptionRaw();
603}
604
606 StopInfoSP stop_info_sp = GetStopInfo();
607 std::string raw_stop_description;
608 if (stop_info_sp && stop_info_sp->IsValid()) {
609 raw_stop_description = stop_info_sp->GetDescription();
610 assert((!raw_stop_description.empty() ||
611 stop_info_sp->GetStopReason() == eStopReasonNone) &&
612 "StopInfo returned an empty description.");
613 }
614 return raw_stop_description;
615}
616
618 ThreadPlan *current_plan = GetCurrentPlan();
619
620 // FIXME: I may decide to disallow threads with no plans. In which
621 // case this should go to an assert.
622
623 if (!current_plan)
624 return;
625
626 current_plan->WillStop();
627}
628
631 // First check whether this thread is going to "actually" resume at all.
632 // For instance, if we're stepping from one level to the next of an
633 // virtual inlined call stack, we just change the inlined call stack index
634 // without actually running this thread. In that case, for this thread we
635 // shouldn't push a step over breakpoint plan or do that work.
636 if (GetCurrentPlan()->IsVirtualStep())
637 return false;
638
639 // If we're at a breakpoint push the step-over breakpoint plan. Do this
640 // before telling the current plan it will resume, since we might change
641 // what the current plan is.
642
644 ProcessSP process_sp(GetProcess());
645 if (reg_ctx_sp && process_sp && direction == eRunForward) {
646 const addr_t thread_pc = reg_ctx_sp->GetPC();
647 BreakpointSiteSP bp_site_sp =
648 process_sp->GetBreakpointSiteList().FindByAddress(thread_pc);
649 // If we're at a BreakpointSite which we have either
650 // 1. already triggered/hit, or
651 // 2. the Breakpoint was added while stopped, or the pc was moved
652 // to this BreakpointSite
653 // Step past the breakpoint before resuming.
654 // If we stopped at a breakpoint instruction/BreakpointSite location
655 // without hitting it, and we're still at that same address on
656 // resuming, then we want to hit the BreakpointSite when we resume.
657 if (bp_site_sp && m_stopped_at_unexecuted_bp != thread_pc) {
658 // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the
659 // target may not require anything special to step over a breakpoint.
660
661 ThreadPlan *cur_plan = GetCurrentPlan();
662
663 bool push_step_over_bp_plan = false;
664 if (cur_plan->GetKind() == ThreadPlan::eKindStepOverBreakpoint) {
667 if (bp_plan->GetBreakpointLoadAddress() != thread_pc)
668 push_step_over_bp_plan = true;
669 } else
670 push_step_over_bp_plan = true;
671
672 if (push_step_over_bp_plan) {
673 ThreadPlanSP step_bp_plan_sp(new ThreadPlanStepOverBreakpoint(*this));
674 if (step_bp_plan_sp) {
675 step_bp_plan_sp->SetPrivate(true);
676
677 if (GetCurrentPlan()->RunState() != eStateStepping) {
678 ThreadPlanStepOverBreakpoint *step_bp_plan =
679 static_cast<ThreadPlanStepOverBreakpoint *>(
680 step_bp_plan_sp.get());
681 step_bp_plan->SetAutoContinue(true);
682 }
683 QueueThreadPlan(step_bp_plan_sp, false);
684 return true;
685 }
686 }
687 }
688 }
689 }
690 return false;
691}
692
693bool Thread::ShouldResume(StateType resume_state) {
694 // At this point clear the completed plan stack.
697
698 StateType prev_resume_state = GetTemporaryResumeState();
699
700 SetTemporaryResumeState(resume_state);
701
702 lldb::ThreadSP backing_thread_sp(GetBackingThread());
703 if (backing_thread_sp)
704 backing_thread_sp->SetTemporaryResumeState(resume_state);
705
706 // Make sure m_stop_info_sp is valid. Don't do this for threads we suspended
707 // in the previous run.
708 if (prev_resume_state != eStateSuspended)
710
711 // This is a little dubious, but we are trying to limit how often we actually
712 // fetch stop info from the target, 'cause that slows down single stepping.
713 // So assume that if we got to the point where we're about to resume, and we
714 // haven't yet had to fetch the stop reason, then it doesn't need to know
715 // about the fact that we are resuming...
716 const uint32_t process_stop_id = GetProcess()->GetStopID();
717 if (m_stop_info_stop_id == process_stop_id &&
718 (m_stop_info_sp && m_stop_info_sp->IsValid())) {
719 if (StopInfoSP stop_info_sp = GetPrivateStopInfo())
720 stop_info_sp->WillResume(resume_state);
721 }
722
723 // Tell all the plans that we are about to resume in case they need to clear
724 // any state. We distinguish between the plan on the top of the stack and the
725 // lower plans in case a plan needs to do any special business before it
726 // runs.
727
728 bool need_to_resume = false;
729 ThreadPlan *plan_ptr = GetCurrentPlan();
730 if (plan_ptr) {
731 need_to_resume = plan_ptr->WillResume(resume_state, true);
732
733 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != nullptr) {
734 plan_ptr->WillResume(resume_state, false);
735 }
736
737 // If the WillResume for the plan says we are faking a resume, then it will
738 // have set an appropriate stop info. In that case, don't reset it here.
739
740 if (need_to_resume && resume_state != eStateSuspended) {
741 m_stop_info_sp.reset();
742 }
743 }
744
745 if (need_to_resume) {
747
748 // Only reset m_stopped_at_unexecuted_bp if the thread is actually being
749 // resumed. Otherwise, the state of a suspended thread may not be restored
750 // correctly at the next stop. For example, this could happen if the thread
751 // is suspended by ThreadPlanStepOverBreakpoint in another thread, which
752 // temporarily disables the breakpoint that the suspended thread has reached
753 // but not yet executed.
754 if (resume_state != eStateSuspended)
756
757 // Let Thread subclasses do any special work they need to prior to resuming
758 WillResume(resume_state);
759 }
760
761 return need_to_resume;
762}
763
766 // This will get recomputed each time when we stop.
768}
769
771
772bool Thread::ShouldStop(Event *event_ptr) {
773 ThreadPlan *current_plan = GetCurrentPlan();
774
775 bool should_stop = true;
776
777 Log *log = GetLog(LLDBLog::Step);
778
780 LLDB_LOGF(log,
781 "Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64
782 ", should_stop = 0 (ignore since thread was suspended)",
783 __FUNCTION__, GetID(), GetProtocolID());
784 return false;
785 }
786
788 LLDB_LOGF(log,
789 "Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64
790 ", should_stop = 0 (ignore since thread was suspended)",
791 __FUNCTION__, GetID(), GetProtocolID());
792 return false;
793 }
794
795 // Based on the current thread plan and process stop info, check if this
796 // thread caused the process to stop. NOTE: this must take place before the
797 // plan is moved from the current plan stack to the completed plan stack.
799 LLDB_LOGF(log,
800 "Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64
801 ", pc = 0x%16.16" PRIx64
802 ", should_stop = 0 (ignore since no stop reason)",
803 __FUNCTION__, GetID(), GetProtocolID(),
806 return false;
807 }
808
809 // Clear the "must run me before stop" if it was set:
811
812 if (log) {
813 LLDB_LOGF(log,
814 "Thread::%s(%p) for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64
815 ", pc = 0x%16.16" PRIx64,
816 __FUNCTION__, static_cast<void *>(this), GetID(), GetProtocolID(),
819 LLDB_LOGF(log, "^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^");
820 StreamString s;
821 s.IndentMore();
822 GetProcess()->DumpThreadPlansForTID(
823 s, GetID(), eDescriptionLevelVerbose, true /* internal */,
824 false /* condense_trivial */, true /* skip_unreported */);
825 LLDB_LOGF(log, "Plan stack initial state:\n%s", s.GetData());
826 }
827
828 // The top most plan always gets to do the trace log...
829 current_plan->DoTraceLog();
830
831 // First query the stop info's ShouldStopSynchronous. This handles
832 // "synchronous" stop reasons, for example the breakpoint command on internal
833 // breakpoints. If a synchronous stop reason says we should not stop, then
834 // we don't have to do any more work on this stop.
835 StopInfoSP private_stop_info(GetPrivateStopInfo());
836 if (private_stop_info &&
837 !private_stop_info->ShouldStopSynchronous(event_ptr)) {
838 LLDB_LOGF(log, "StopInfo::ShouldStop async callback says we should not "
839 "stop, returning ShouldStop of false.");
840 return false;
841 }
842
843 // If we've already been restarted, don't query the plans since the state
844 // they would examine is not current.
846 return false;
847
848 // Before the plans see the state of the world, calculate the current inlined
849 // depth.
850 GetStackFrameList()->CalculateCurrentInlinedDepth();
851
852 // If the base plan doesn't understand why we stopped, then we have to find a
853 // plan that does. If that plan is still working, then we don't need to do
854 // any more work. If the plan that explains the stop is done, then we should
855 // pop all the plans below it, and pop it, and then let the plans above it
856 // decide whether they still need to do more work.
857
858 bool done_processing_current_plan = false;
859 if (!current_plan->PlanExplainsStop(event_ptr)) {
860 if (current_plan->TracerExplainsStop()) {
861 done_processing_current_plan = true;
862 should_stop = false;
863 } else {
864 // Leaf plan that does not explain the stop should be popped.
865 // The plan should be push itself later again before resuming to stay
866 // as leaf.
867 if (current_plan->IsLeafPlan())
868 PopPlan();
869
870 // If the current plan doesn't explain the stop, then find one that does
871 // and let it handle the situation.
872 ThreadPlan *plan_ptr = current_plan;
873 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != nullptr) {
874 if (plan_ptr->PlanExplainsStop(event_ptr)) {
875 LLDB_LOGF(log, "Plan %s explains stop.", plan_ptr->GetName());
876
877 should_stop = plan_ptr->ShouldStop(event_ptr);
878
879 // plan_ptr explains the stop, next check whether plan_ptr is done,
880 // if so, then we should take it and all the plans below it off the
881 // stack.
882
883 if (plan_ptr->MischiefManaged()) {
884 // We're going to pop the plans up to and including the plan that
885 // explains the stop.
886 ThreadPlan *prev_plan_ptr = GetPreviousPlan(plan_ptr);
887
888 do {
889 if (should_stop)
890 current_plan->WillStop();
891 PopPlan();
892 } while ((current_plan = GetCurrentPlan()) != prev_plan_ptr);
893 // Now, if the responsible plan was not "Okay to discard" then
894 // we're done, otherwise we forward this to the next plan in the
895 // stack below.
896 done_processing_current_plan =
897 (plan_ptr->IsControllingPlan() && !plan_ptr->OkayToDiscard());
898 } else {
899 bool should_force_run = plan_ptr->ShouldRunBeforePublicStop();
900 if (should_force_run) {
902 should_stop = false;
903 }
904 done_processing_current_plan = true;
905 }
906 break;
907 }
908 }
909 }
910 }
911
912 if (!done_processing_current_plan) {
913 bool override_stop = false;
914
915 // We're starting from the base plan, so just let it decide;
916 if (current_plan->IsBasePlan()) {
917 should_stop = current_plan->ShouldStop(event_ptr);
918 LLDB_LOGF(log, "Base plan says should stop: %i.", should_stop);
919 } else {
920 // Otherwise, don't let the base plan override what the other plans say
921 // to do, since presumably if there were other plans they would know what
922 // to do...
923 while (true) {
924 if (current_plan->IsBasePlan())
925 break;
926
927 should_stop = current_plan->ShouldStop(event_ptr);
928 LLDB_LOGF(log, "Plan %s should stop: %d.", current_plan->GetName(),
929 should_stop);
930 if (current_plan->MischiefManaged()) {
931 if (should_stop)
932 current_plan->WillStop();
933
934 if (current_plan->ShouldAutoContinue(event_ptr)) {
935 override_stop = true;
936 LLDB_LOGF(log, "Plan %s auto-continue: true.",
937 current_plan->GetName());
938 }
939
940 // If a Controlling Plan wants to stop, we let it. Otherwise, see if
941 // the plan's parent wants to stop.
942
943 PopPlan();
944 if (should_stop && current_plan->IsControllingPlan() &&
945 !current_plan->OkayToDiscard()) {
946 break;
947 }
948
949 current_plan = GetCurrentPlan();
950 if (current_plan == nullptr) {
951 break;
952 }
953 } else {
954 break;
955 }
956 }
957 }
958
959 if (override_stop)
960 should_stop = false;
961 }
962
963 // One other potential problem is that we set up a controlling plan, then stop
964 // in before it is complete - for instance by hitting a breakpoint during a
965 // step-over - then do some step/finish/etc operations that wind up past the
966 // end point condition of the initial plan. We don't want to strand the
967 // original plan on the stack, This code clears stale plans off the stack.
968
969 if (should_stop) {
970 ThreadPlan *plan_ptr = GetCurrentPlan();
971
972 // Discard the stale plans and all plans below them in the stack, plus move
973 // the completed plans to the completed plan stack
974 while (!plan_ptr->IsBasePlan()) {
975 bool stale = plan_ptr->IsPlanStale();
976 ThreadPlan *examined_plan = plan_ptr;
977 plan_ptr = GetPreviousPlan(examined_plan);
978
979 if (stale) {
980 LLDB_LOGF(
981 log,
982 "Plan %s being discarded in cleanup, it says it is already done.",
983 examined_plan->GetName());
984 while (GetCurrentPlan() != examined_plan) {
985 DiscardPlan();
986 }
987 if (examined_plan->IsPlanComplete()) {
988 // plan is complete but does not explain the stop (example: step to a
989 // line with breakpoint), let us move the plan to
990 // completed_plan_stack anyway
991 PopPlan();
992 } else
993 DiscardPlan();
994 }
995 }
996 }
997
998 if (log) {
999 StreamString s;
1000 s.IndentMore();
1001 GetProcess()->DumpThreadPlansForTID(
1002 s, GetID(), eDescriptionLevelVerbose, true /* internal */,
1003 false /* condense_trivial */, true /* skip_unreported */);
1004 LLDB_LOGF(log, "Plan stack final state:\n%s", s.GetData());
1005 LLDB_LOGF(log, "vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv",
1006 should_stop);
1007 }
1008 return should_stop;
1009}
1010
1012 StateType thread_state = GetResumeState();
1013 StateType temp_thread_state = GetTemporaryResumeState();
1014
1015 Log *log = GetLog(LLDBLog::Step);
1016
1017 if (thread_state == eStateSuspended || thread_state == eStateInvalid) {
1018 LLDB_LOGF(log,
1019 "Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
1020 ": returning vote %i (state was suspended or invalid)",
1022 return eVoteNoOpinion;
1023 }
1024
1025 if (temp_thread_state == eStateSuspended ||
1026 temp_thread_state == eStateInvalid) {
1027 LLDB_LOGF(log,
1028 "Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
1029 ": returning vote %i (temporary state was suspended or invalid)",
1031 return eVoteNoOpinion;
1032 }
1033
1034 if (!ThreadStoppedForAReason()) {
1035 LLDB_LOGF(log,
1036 "Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
1037 ": returning vote %i (thread didn't stop for a reason.)",
1039 return eVoteNoOpinion;
1040 }
1041
1042 if (GetPlans().AnyCompletedPlans()) {
1043 // Pass skip_private = false to GetCompletedPlan, since we want to ask
1044 // the last plan, regardless of whether it is private or not.
1045 LLDB_LOGF(log,
1046 "Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
1047 ": returning vote for complete stack's back plan",
1048 GetID());
1049 return GetPlans().GetCompletedPlan(false)->ShouldReportStop(event_ptr);
1050 } else {
1051 Vote thread_vote = eVoteNoOpinion;
1052 ThreadPlan *plan_ptr = GetCurrentPlan();
1053 while (true) {
1054 if (plan_ptr->PlanExplainsStop(event_ptr)) {
1055 thread_vote = plan_ptr->ShouldReportStop(event_ptr);
1056 break;
1057 }
1058 if (plan_ptr->IsBasePlan())
1059 break;
1060 else
1061 plan_ptr = GetPreviousPlan(plan_ptr);
1062 }
1063 LLDB_LOGF(log,
1064 "Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
1065 ": returning vote %i for current plan",
1066 GetID(), thread_vote);
1067
1068 return thread_vote;
1069 }
1070}
1071
1073 StateType thread_state = GetResumeState();
1074
1075 if (thread_state == eStateSuspended || thread_state == eStateInvalid) {
1076 return eVoteNoOpinion;
1077 }
1078
1079 Log *log = GetLog(LLDBLog::Step);
1080 if (GetPlans().AnyCompletedPlans()) {
1081 // Pass skip_private = false to GetCompletedPlan, since we want to ask
1082 // the last plan, regardless of whether it is private or not.
1083 LLDB_LOGF(log,
1084 "Current Plan for thread %d(%p) (0x%4.4" PRIx64
1085 ", %s): %s being asked whether we should report run.",
1086 GetIndexID(), static_cast<void *>(this), GetID(),
1089
1090 return GetPlans().GetCompletedPlan(false)->ShouldReportRun(event_ptr);
1091 } else {
1092 LLDB_LOGF(log,
1093 "Current Plan for thread %d(%p) (0x%4.4" PRIx64
1094 ", %s): %s being asked whether we should report run.",
1095 GetIndexID(), static_cast<void *>(this), GetID(),
1097 GetCurrentPlan()->GetName());
1098
1099 return GetCurrentPlan()->ShouldReportRun(event_ptr);
1100 }
1101}
1102
1104 return (spec == nullptr) ? true : spec->ThreadPassesBasicTests(*this);
1105}
1106
1108 ThreadPlanStack *plans = GetProcess()->FindThreadPlans(GetID());
1109 if (plans)
1110 return *plans;
1111
1112 // History threads don't have a thread plan, but they do ask get asked to
1113 // describe themselves, which usually involves pulling out the stop reason.
1114 // That in turn will check for a completed plan on the ThreadPlanStack.
1115 // Instead of special-casing at that point, we return a Stack with a
1116 // ThreadPlanNull as its base plan. That will give the right answers to the
1117 // queries GetDescription makes, and only assert if you try to run the thread.
1119 m_null_plan_stack_up = std::make_unique<ThreadPlanStack>(*this, true);
1120 return *m_null_plan_stack_up;
1121}
1122
1123void Thread::PushPlan(ThreadPlanSP thread_plan_sp) {
1124 assert(thread_plan_sp && "Don't push an empty thread plan.");
1125
1126 Log *log = GetLog(LLDBLog::Step);
1127 if (log) {
1128 StreamString s;
1129 thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelFull);
1130 LLDB_LOGF(log, "Thread::PushPlan(0x%p): \"%s\", tid = 0x%4.4" PRIx64 ".",
1131 static_cast<void *>(this), s.GetData(),
1132 thread_plan_sp->GetThread().GetID());
1133 }
1134
1135 GetPlans().PushPlan(std::move(thread_plan_sp));
1136}
1137
1139 Log *log = GetLog(LLDBLog::Step);
1140 ThreadPlanSP popped_plan_sp = GetPlans().PopPlan();
1141 if (log) {
1142 LLDB_LOGF(log, "Popping plan: \"%s\", tid = 0x%4.4" PRIx64 ".",
1143 popped_plan_sp->GetName(), popped_plan_sp->GetThread().GetID());
1144 }
1145}
1146
1148 Log *log = GetLog(LLDBLog::Step);
1149 ThreadPlanSP discarded_plan_sp = GetPlans().DiscardPlan();
1150
1151 LLDB_LOGF(log, "Discarding plan: \"%s\", tid = 0x%4.4" PRIx64 ".",
1152 discarded_plan_sp->GetName(),
1153 discarded_plan_sp->GetThread().GetID());
1154}
1155
1157 const ThreadPlanStack &plans = GetPlans();
1158 if (!plans.AnyPlans())
1159 return;
1160
1161 // Iterate from the second plan (index: 1) to skip the base plan.
1162 ThreadPlanSP p;
1163 uint32_t i = 1;
1164 while ((p = plans.GetPlanByIndex(i, false))) {
1165 StreamString strm;
1166 p->GetDescription(&strm, eDescriptionLevelInitial);
1167 request.TryCompleteCurrentArg(std::to_string(i), strm.GetString());
1168 i++;
1169 }
1170}
1171
1173 return GetPlans().GetCurrentPlan().get();
1174}
1175
1179
1183
1187
1189 return GetPlans().IsPlanDone(plan);
1190}
1191
1193 return GetPlans().WasPlanDiscarded(plan);
1194}
1195
1199
1201 return GetPlans().GetPreviousPlan(current_plan);
1202}
1203
1205 bool abort_other_plans) {
1206 Status status;
1207 StreamString s;
1208 if (!thread_plan_sp->ValidatePlan(&s)) {
1209 DiscardThreadPlansUpToPlan(thread_plan_sp);
1210 thread_plan_sp.reset();
1211 return Status(s.GetString().str());
1212 }
1213
1214 if (abort_other_plans)
1215 DiscardThreadPlans(true);
1216
1217 PushPlan(thread_plan_sp);
1218
1219 // This seems a little funny, but I don't want to have to split up the
1220 // constructor and the DidPush in the scripted plan, that seems annoying.
1221 // That means the constructor has to be in DidPush. So I have to validate the
1222 // plan AFTER pushing it, and then take it off again...
1223 if (!thread_plan_sp->ValidatePlan(&s)) {
1224 DiscardThreadPlansUpToPlan(thread_plan_sp);
1225 thread_plan_sp.reset();
1226 return Status(s.GetString().str());
1227 }
1228
1229 return status;
1230}
1231
1233 // Count the user thread plans from the back end to get the number of the one
1234 // we want to discard:
1235
1236 ThreadPlan *up_to_plan_ptr = GetPlans().GetPlanByIndex(plan_index).get();
1237 if (up_to_plan_ptr == nullptr)
1238 return false;
1239
1240 DiscardThreadPlansUpToPlan(up_to_plan_ptr);
1241 return true;
1242}
1243
1245 DiscardThreadPlansUpToPlan(up_to_plan_sp.get());
1246}
1247
1249 Log *log = GetLog(LLDBLog::Step);
1250 LLDB_LOGF(log,
1251 "Discarding thread plans for thread tid = 0x%4.4" PRIx64
1252 ", up to %p",
1253 GetID(), static_cast<void *>(up_to_plan_ptr));
1254 GetPlans().DiscardPlansUpToPlan(up_to_plan_ptr);
1255}
1256
1258 Log *log = GetLog(LLDBLog::Step);
1259 if (log) {
1260 LLDB_LOGF(log,
1261 "Discarding thread plans for thread (tid = 0x%4.4" PRIx64
1262 ", force %d)",
1263 GetID(), force);
1264 }
1265
1266 if (force) {
1268 return;
1269 }
1271}
1272
1274 Status error;
1275 ThreadPlan *innermost_expr_plan = GetPlans().GetInnermostExpression();
1276 if (!innermost_expr_plan) {
1278 "No expressions currently active on this thread");
1279 return error;
1280 }
1281 DiscardThreadPlansUpToPlan(innermost_expr_plan);
1282 return error;
1283}
1284
1285ThreadPlanSP Thread::QueueBasePlan(bool abort_other_plans) {
1286 ThreadPlanSP thread_plan_sp(new ThreadPlanBase(*this));
1287 QueueThreadPlan(thread_plan_sp, abort_other_plans);
1288 return thread_plan_sp;
1289}
1290
1292 bool step_over, bool abort_other_plans, bool stop_other_threads,
1293 Status &status) {
1294 ThreadPlanSP thread_plan_sp(new ThreadPlanStepInstruction(
1295 *this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
1296 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1297 return thread_plan_sp;
1298}
1299
1301 bool abort_other_plans, const AddressRange &range,
1302 const SymbolContext &addr_context, lldb::RunMode stop_other_threads,
1303 Status &status, LazyBool step_out_avoids_code_withoug_debug_info) {
1304 ThreadPlanSP thread_plan_sp;
1305 thread_plan_sp = std::make_shared<ThreadPlanStepOverRange>(
1306 *this, range, addr_context, stop_other_threads,
1307 step_out_avoids_code_withoug_debug_info);
1308
1309 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1310 return thread_plan_sp;
1311}
1312
1313// Call the QueueThreadPlanForStepOverRange method which takes an address
1314// range.
1316 bool abort_other_plans, const LineEntry &line_entry,
1317 const SymbolContext &addr_context, lldb::RunMode stop_other_threads,
1318 Status &status, LazyBool step_out_avoids_code_withoug_debug_info) {
1319 const bool include_inlined_functions = true;
1320 auto address_range =
1321 line_entry.GetSameLineContiguousAddressRange(include_inlined_functions);
1323 abort_other_plans, address_range, addr_context, stop_other_threads,
1324 status, step_out_avoids_code_withoug_debug_info);
1325}
1326
1328 bool abort_other_plans, const AddressRange &range,
1329 const SymbolContext &addr_context, const char *step_in_target,
1330 lldb::RunMode stop_other_threads, Status &status,
1331 LazyBool step_in_avoids_code_without_debug_info,
1332 LazyBool step_out_avoids_code_without_debug_info) {
1333 ThreadPlanSP thread_plan_sp(new ThreadPlanStepInRange(
1334 *this, range, addr_context, step_in_target, stop_other_threads,
1335 step_in_avoids_code_without_debug_info,
1336 step_out_avoids_code_without_debug_info));
1337 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1338 return thread_plan_sp;
1339}
1340
1341// Call the QueueThreadPlanForStepInRange method which takes an address range.
1343 bool abort_other_plans, const LineEntry &line_entry,
1344 const SymbolContext &addr_context, const char *step_in_target,
1345 lldb::RunMode stop_other_threads, Status &status,
1346 LazyBool step_in_avoids_code_without_debug_info,
1347 LazyBool step_out_avoids_code_without_debug_info) {
1348 const bool include_inlined_functions = false;
1350 abort_other_plans,
1351 line_entry.GetSameLineContiguousAddressRange(include_inlined_functions),
1352 addr_context, step_in_target, stop_other_threads, status,
1353 step_in_avoids_code_without_debug_info,
1354 step_out_avoids_code_without_debug_info);
1355}
1356
1358 bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
1359 bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
1360 uint32_t frame_idx, Status &status,
1361 LazyBool step_out_avoids_code_without_debug_info) {
1362 ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
1363 *this, addr_context, first_insn, stop_other_threads, report_stop_vote,
1364 report_run_vote, frame_idx, step_out_avoids_code_without_debug_info));
1365
1366 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1367 return thread_plan_sp;
1368}
1369
1371 bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
1372 bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
1373 uint32_t frame_idx, Status &status, bool continue_to_next_branch) {
1374 const bool calculate_return_value =
1375 false; // No need to calculate the return value here.
1376 ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
1377 *this, stop_other_threads, report_stop_vote, report_run_vote, frame_idx,
1378 continue_to_next_branch, calculate_return_value));
1379
1380 ThreadPlanStepOut *new_plan =
1381 static_cast<ThreadPlanStepOut *>(thread_plan_sp.get());
1382 new_plan->ClearShouldStopHereCallbacks();
1383
1384 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1385 return thread_plan_sp;
1386}
1387
1389 bool abort_other_plans,
1390 bool stop_other_threads,
1391 Status &status) {
1392 ThreadPlanSP thread_plan_sp(
1393 new ThreadPlanStepThrough(*this, return_stack_id, stop_other_threads));
1394 if (!thread_plan_sp || !thread_plan_sp->ValidatePlan(nullptr))
1395 return ThreadPlanSP();
1396
1397 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1398 return thread_plan_sp;
1399}
1400
1402 Address &target_addr,
1403 bool stop_other_threads,
1404 Status &status) {
1405 ThreadPlanSP thread_plan_sp(
1406 new ThreadPlanRunToAddress(*this, target_addr, stop_other_threads));
1407
1408 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1409 return thread_plan_sp;
1410}
1411
1413 bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses,
1414 bool stop_other_threads, uint32_t frame_idx, Status &status) {
1415 ThreadPlanSP thread_plan_sp(new ThreadPlanStepUntil(
1416 *this, address_list, num_addresses, stop_other_threads, frame_idx));
1417
1418 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1419 return thread_plan_sp;
1420}
1421
1423 bool abort_other_plans, const char *class_name,
1424 StructuredData::ObjectSP extra_args_sp, bool stop_other_threads,
1425 Status &status) {
1426
1427 ThreadPlanSP thread_plan_sp(new ScriptedThreadPlan(
1428 *this, class_name, StructuredDataImpl(extra_args_sp)));
1429 thread_plan_sp->SetStopOthers(stop_other_threads);
1430 status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
1431 return thread_plan_sp;
1432}
1433
1434uint32_t Thread::GetIndexID() const { return m_index_id; }
1435
1437 TargetSP target_sp;
1438 ProcessSP process_sp(GetProcess());
1439 if (process_sp)
1440 target_sp = process_sp->CalculateTarget();
1441 return target_sp;
1442}
1443
1445
1446ThreadSP Thread::CalculateThread() { return shared_from_this(); }
1447
1449
1451 exe_ctx.SetContext(shared_from_this());
1452}
1453
1455 std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
1456
1457 if (m_curr_frames_sp)
1458 return m_curr_frames_sp;
1459
1460 // First, try to load a frame provider if we don't have one yet.
1461 if (!m_frame_provider_sp) {
1462 ProcessSP process_sp = GetProcess();
1463 if (process_sp) {
1464 Target &target = process_sp->GetTarget();
1465 const auto &descriptors = target.GetScriptedFrameProviderDescriptors();
1466
1467 // Collect all descriptors that apply to this thread.
1468 std::vector<const ScriptedFrameProviderDescriptor *>
1469 applicable_descriptors;
1470 for (const auto &entry : descriptors) {
1471 const ScriptedFrameProviderDescriptor &descriptor = entry.second;
1472 if (descriptor.IsValid() && descriptor.AppliesToThread(*this))
1473 applicable_descriptors.push_back(&descriptor);
1474 }
1475
1476 // Sort by priority (lower number = higher priority).
1477 llvm::sort(applicable_descriptors,
1480 // nullopt (no priority) sorts last (UINT32_MAX).
1481 uint32_t priority_a = a->GetPriority().value_or(UINT32_MAX);
1482 uint32_t priority_b = b->GetPriority().value_or(UINT32_MAX);
1483 return priority_a < priority_b;
1484 });
1485
1486 // Load the highest priority provider that successfully instantiates.
1487 for (const auto *descriptor : applicable_descriptors) {
1488 if (llvm::Error error = LoadScriptedFrameProvider(*descriptor)) {
1490 "Failed to load scripted frame provider: {0}");
1491 continue; // Try next provider if this one fails.
1492 }
1493 break; // Successfully loaded provider.
1494 }
1495 }
1496 }
1497
1498 // Create the frame list based on whether we have a provider.
1499 if (m_frame_provider_sp) {
1500 // We have a provider - create synthetic frame list.
1501 StackFrameListSP input_frames = m_frame_provider_sp->GetInputFrames();
1502 m_curr_frames_sp = std::make_shared<SyntheticStackFrameList>(
1503 *this, input_frames, m_prev_frames_sp, true);
1504 } else {
1505 // No provider - use normal unwinder frames.
1507 std::make_shared<StackFrameList>(*this, m_prev_frames_sp, true);
1508 }
1509
1510 return m_curr_frames_sp;
1511}
1512
1514 const ScriptedFrameProviderDescriptor &descriptor) {
1515 std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
1516
1517 // Note: We don't create input_frames here - it will be created lazily
1518 // by SyntheticStackFrameList when frames are first fetched.
1519 // Creating them too early can cause crashes during thread initialization.
1520
1521 // Create a temporary StackFrameList just to get the thread reference for the
1522 // provider. The provider won't actually use this - it will get real input
1523 // frames from SyntheticStackFrameList later.
1524 StackFrameListSP temp_frames =
1525 std::make_shared<StackFrameList>(*this, m_prev_frames_sp, true);
1526
1527 auto provider_or_err =
1528 SyntheticFrameProvider::CreateInstance(temp_frames, descriptor);
1529 if (!provider_or_err)
1530 return provider_or_err.takeError();
1531
1533 m_frame_provider_sp = *provider_or_err;
1534 return llvm::Error::success();
1535}
1536
1538 std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
1539 m_frame_provider_sp.reset();
1540 m_curr_frames_sp.reset();
1541 m_prev_frames_sp.reset();
1542}
1543
1544std::optional<addr_t> Thread::GetPreviousFrameZeroPC() {
1545 return m_prev_framezero_pc;
1546}
1547
1549 std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
1550
1551 GetUnwinder().Clear();
1552 m_prev_framezero_pc.reset();
1553 if (RegisterContextSP reg_ctx_sp = GetRegisterContext())
1554 m_prev_framezero_pc = reg_ctx_sp->GetPC();
1555
1556 // Only store away the old "reference" StackFrameList if we got all its
1557 // frames:
1558 // FIXME: At some point we can try to splice in the frames we have fetched
1559 // into the new frame as we make it, but let's not try that now.
1560 if (m_curr_frames_sp && m_curr_frames_sp->WereAllFramesFetched())
1562 m_curr_frames_sp.reset();
1563
1564 m_frame_provider_sp.reset();
1565 m_extended_info.reset();
1567}
1568
1570 return GetStackFrameList()->GetFrameWithConcreteFrameIndex(unwind_idx);
1571}
1572
1574 lldb::ValueObjectSP return_value_sp,
1575 bool broadcast) {
1576 StackFrameSP frame_sp = GetStackFrameAtIndex(frame_idx);
1577 Status return_error;
1578
1579 if (!frame_sp) {
1580 return_error = Status::FromErrorStringWithFormat(
1581 "Could not find frame with index %d in thread 0x%" PRIx64 ".",
1582 frame_idx, GetID());
1583 }
1584
1585 return ReturnFromFrame(frame_sp, return_value_sp, broadcast);
1586}
1587
1589 lldb::ValueObjectSP return_value_sp,
1590 bool broadcast) {
1591 Status return_error;
1592
1593 if (!frame_sp) {
1594 return_error = Status::FromErrorString("Can't return to a null frame.");
1595 return return_error;
1596 }
1597
1598 Thread *thread = frame_sp->GetThread().get();
1599 uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1;
1600 StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx);
1601 if (!older_frame_sp) {
1602 return_error = Status::FromErrorString("No older frame to return to.");
1603 return return_error;
1604 }
1605
1606 if (return_value_sp) {
1607 lldb::ABISP abi = thread->GetProcess()->GetABI();
1608 if (!abi) {
1609 return_error =
1610 Status::FromErrorString("Could not find ABI to set return value.");
1611 return return_error;
1612 }
1613 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction);
1614
1615 // FIXME: ValueObject::Cast doesn't currently work correctly, at least not
1616 // for scalars.
1617 // Turn that back on when that works.
1618 if (/* DISABLES CODE */ (false) && sc.function != nullptr) {
1619 Type *function_type = sc.function->GetType();
1620 if (function_type) {
1621 CompilerType return_type =
1623 if (return_type) {
1624 StreamString s;
1625 return_type.DumpTypeDescription(&s);
1626 ValueObjectSP cast_value_sp = return_value_sp->Cast(return_type);
1627 if (cast_value_sp) {
1628 cast_value_sp->SetFormat(eFormatHex);
1629 return_value_sp = cast_value_sp;
1630 }
1631 }
1632 }
1633 }
1634
1635 return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp);
1636 if (!return_error.Success())
1637 return return_error;
1638 }
1639
1640 // Now write the return registers for the chosen frame: Note, we can't use
1641 // ReadAllRegisterValues->WriteAllRegisterValues, since the read & write cook
1642 // their data
1643
1644 StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0);
1645 if (youngest_frame_sp) {
1646 lldb::RegisterContextSP reg_ctx_sp(youngest_frame_sp->GetRegisterContext());
1647 if (reg_ctx_sp) {
1648 bool copy_success = reg_ctx_sp->CopyFromRegisterContext(
1649 older_frame_sp->GetRegisterContext());
1650 if (copy_success) {
1651 thread->DiscardThreadPlans(true);
1652 thread->ClearStackFrames();
1654 auto data_sp = std::make_shared<ThreadEventData>(shared_from_this());
1656 }
1657 } else {
1658 return_error =
1659 Status::FromErrorString("Could not reset register values.");
1660 }
1661 } else {
1662 return_error = Status::FromErrorString("Frame has no register context.");
1663 }
1664 } else {
1665 return_error = Status::FromErrorString("Returned past top frame.");
1666 }
1667 return return_error;
1668}
1669
1670static void DumpAddressList(Stream &s, const std::vector<Address> &list,
1671 ExecutionContextScope *exe_scope) {
1672 for (size_t n = 0; n < list.size(); n++) {
1673 s << "\t";
1674 list[n].Dump(&s, exe_scope, Address::DumpStyleResolvedDescription,
1676 s << "\n";
1677 }
1678}
1679
1680Status Thread::JumpToLine(const FileSpec &file, uint32_t line,
1681 bool can_leave_function, std::string *warnings) {
1683 Target *target = exe_ctx.GetTargetPtr();
1684 TargetSP target_sp = exe_ctx.GetTargetSP();
1685 RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
1686 StackFrame *frame = exe_ctx.GetFramePtr();
1687 const SymbolContext &sc = frame->GetSymbolContext(eSymbolContextFunction);
1688
1689 // Find candidate locations.
1690 std::vector<Address> candidates, within_function, outside_function;
1691 target->GetImages().FindAddressesForLine(target_sp, file, line, sc.function,
1692 within_function, outside_function);
1693
1694 // If possible, we try and stay within the current function. Within a
1695 // function, we accept multiple locations (optimized code may do this,
1696 // there's no solution here so we do the best we can). However if we're
1697 // trying to leave the function, we don't know how to pick the right
1698 // location, so if there's more than one then we bail.
1699 if (!within_function.empty())
1700 candidates = within_function;
1701 else if (outside_function.size() == 1 && can_leave_function)
1702 candidates = outside_function;
1703
1704 // Check if we got anything.
1705 if (candidates.empty()) {
1706 if (outside_function.empty()) {
1708 "Cannot locate an address for %s:%i.", file.GetFilename().AsCString(),
1709 line);
1710 } else if (outside_function.size() == 1) {
1712 "%s:%i is outside the current function.",
1713 file.GetFilename().AsCString(), line);
1714 } else {
1715 StreamString sstr;
1716 DumpAddressList(sstr, outside_function, target);
1718 "%s:%i has multiple candidate locations:\n%s",
1719 file.GetFilename().AsCString(), line, sstr.GetData());
1720 }
1721 }
1722
1723 // Accept the first location, warn about any others.
1724 Address dest = candidates[0];
1725 if (warnings && candidates.size() > 1) {
1726 StreamString sstr;
1727 sstr.Printf("%s:%i appears multiple times in this function, selecting the "
1728 "first location:\n",
1729 file.GetFilename().AsCString(), line);
1730 DumpAddressList(sstr, candidates, target);
1731 *warnings = std::string(sstr.GetString());
1732 }
1733
1734 if (!reg_ctx->SetPC(dest))
1735 return Status::FromErrorString("Cannot change PC to target address.");
1736
1737 return Status();
1738}
1739
1740bool Thread::DumpUsingFormat(Stream &strm, uint32_t frame_idx,
1741 const FormatEntity::Entry *format) {
1742 ExecutionContext exe_ctx(shared_from_this());
1743 Process *process = exe_ctx.GetProcessPtr();
1744 if (!process || !format)
1745 return false;
1746
1747 StackFrameSP frame_sp;
1748 SymbolContext frame_sc;
1749 if (frame_idx != LLDB_INVALID_FRAME_ID) {
1750 frame_sp = GetStackFrameAtIndex(frame_idx);
1751 if (frame_sp) {
1752 exe_ctx.SetFrameSP(frame_sp);
1753 frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
1754 }
1755 }
1756
1757 return FormatEntity::Formatter(frame_sp ? &frame_sc : nullptr, &exe_ctx,
1758 nullptr, false, false)
1759 .Format(*format, strm);
1760}
1761
1762void Thread::DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
1763 bool stop_format) {
1764 ExecutionContext exe_ctx(shared_from_this());
1765
1766 const FormatEntity::Entry *thread_format;
1767 FormatEntity::Entry format_entry;
1768 if (stop_format) {
1769 format_entry = exe_ctx.GetTargetRef().GetDebugger().GetThreadStopFormat();
1770 thread_format = &format_entry;
1771 } else {
1772 format_entry = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
1773 thread_format = &format_entry;
1774 }
1775
1776 assert(thread_format);
1777
1778 DumpUsingFormat(strm, frame_idx, thread_format);
1779}
1780
1782
1784
1786 if (m_reg_context_sp)
1787 return m_reg_context_sp->GetThreadPointer();
1788 return LLDB_INVALID_ADDRESS;
1789}
1790
1792 lldb::addr_t tls_file_addr) {
1793 // The default implementation is to ask the dynamic loader for it. This can
1794 // be overridden for specific platforms.
1795 DynamicLoader *loader = GetProcess()->GetDynamicLoader();
1796 if (loader)
1797 return loader->GetThreadLocalData(module, shared_from_this(),
1798 tls_file_addr);
1799 else
1800 return LLDB_INVALID_ADDRESS;
1801}
1802
1804 Process *process = GetProcess().get();
1805 if (process) {
1806 DynamicLoader *loader = GetProcess()->GetDynamicLoader();
1807 if (loader && loader->IsFullyInitialized() == false)
1808 return false;
1809
1810 SystemRuntime *runtime = process->GetSystemRuntime();
1811 if (runtime) {
1812 return runtime->SafeToCallFunctionsOnThisThread(shared_from_this());
1813 }
1814 }
1815 return true;
1816}
1817
1820 return GetStackFrameList()->GetStackFrameSPForStackFramePtr(stack_frame_ptr);
1821}
1822
1824 switch (reason) {
1825 case eStopReasonInvalid:
1826 return "invalid";
1827 case eStopReasonNone:
1828 return "none";
1829 case eStopReasonTrace:
1830 return "trace";
1832 return "breakpoint";
1834 return "watchpoint";
1835 case eStopReasonSignal:
1836 return "signal";
1838 return "exception";
1839 case eStopReasonExec:
1840 return "exec";
1841 case eStopReasonFork:
1842 return "fork";
1843 case eStopReasonVFork:
1844 return "vfork";
1846 return "vfork done";
1848 return "plan complete";
1850 return "thread exiting";
1852 return "instrumentation break";
1854 return "processor trace";
1856 return "async interrupt";
1858 return "history boundary";
1859 }
1860
1861 return "StopReason = " + std::to_string(reason);
1862}
1863
1865 switch (mode) {
1866 case eOnlyThisThread:
1867 return "only this thread";
1868 case eAllThreads:
1869 return "all threads";
1871 return "only during stepping";
1872 }
1873
1874 return "RunMode = " + std::to_string(mode);
1875}
1876
1877size_t Thread::GetStatus(Stream &strm, uint32_t start_frame,
1878 uint32_t num_frames, uint32_t num_frames_with_source,
1879 bool stop_format, bool show_hidden, bool only_stacks) {
1880
1881 if (!only_stacks) {
1882 ExecutionContext exe_ctx(shared_from_this());
1883 Target *target = exe_ctx.GetTargetPtr();
1884 Process *process = exe_ctx.GetProcessPtr();
1885 strm.Indent();
1886 bool is_selected = false;
1887 if (process) {
1888 if (process->GetThreadList().GetSelectedThread().get() == this)
1889 is_selected = true;
1890 }
1891 strm.Printf("%c ", is_selected ? '*' : ' ');
1892 if (target && target->GetDebugger().GetUseExternalEditor()) {
1893 StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
1894 if (frame_sp) {
1895 SymbolContext frame_sc(
1896 frame_sp->GetSymbolContext(eSymbolContextLineEntry));
1897 if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.GetFile()) {
1898 if (llvm::Error e = Host::OpenFileInExternalEditor(
1899 target->GetDebugger().GetExternalEditor(),
1900 frame_sc.line_entry.GetFile(), frame_sc.line_entry.line)) {
1901 LLDB_LOG_ERROR(GetLog(LLDBLog::Host), std::move(e),
1902 "OpenFileInExternalEditor failed: {0}");
1903 }
1904 }
1905 }
1906 }
1907
1908 DumpUsingSettingsFormat(strm, start_frame, stop_format);
1909 }
1910
1911 size_t num_frames_shown = 0;
1912 if (num_frames > 0) {
1913 strm.IndentMore();
1914
1915 const bool show_frame_info = true;
1916 const bool show_frame_unique = only_stacks;
1917 const char *selected_frame_marker = nullptr;
1918 if (num_frames == 1 || only_stacks ||
1919 (GetID() != GetProcess()->GetThreadList().GetSelectedThread()->GetID()))
1920 strm.IndentMore();
1921 else
1922 selected_frame_marker = "* ";
1923
1924 num_frames_shown = GetStackFrameList()->GetStatus(
1925 strm, start_frame, num_frames, show_frame_info, num_frames_with_source,
1926 show_frame_unique, show_hidden, selected_frame_marker);
1927 if (num_frames == 1)
1928 strm.IndentLess();
1929 strm.IndentLess();
1930 }
1931 return num_frames_shown;
1932}
1933
1935 bool print_json_thread, bool print_json_stopinfo) {
1936 const bool stop_format = false;
1937 DumpUsingSettingsFormat(strm, 0, stop_format);
1938 strm.Printf("\n");
1939
1941
1942 if (print_json_thread || print_json_stopinfo) {
1943 if (thread_info && print_json_thread) {
1944 thread_info->Dump(strm);
1945 strm.Printf("\n");
1946 }
1947
1948 if (print_json_stopinfo && m_stop_info_sp) {
1949 StructuredData::ObjectSP stop_info = m_stop_info_sp->GetExtendedInfo();
1950 if (stop_info) {
1951 stop_info->Dump(strm);
1952 strm.Printf("\n");
1953 }
1954 }
1955
1956 return true;
1957 }
1958
1959 if (thread_info) {
1960 StructuredData::ObjectSP activity =
1961 thread_info->GetObjectForDotSeparatedPath("activity");
1962 StructuredData::ObjectSP breadcrumb =
1963 thread_info->GetObjectForDotSeparatedPath("breadcrumb");
1964 StructuredData::ObjectSP messages =
1965 thread_info->GetObjectForDotSeparatedPath("trace_messages");
1966
1967 bool printed_activity = false;
1968 if (activity && activity->GetType() == eStructuredDataTypeDictionary) {
1969 StructuredData::Dictionary *activity_dict = activity->GetAsDictionary();
1970 StructuredData::ObjectSP id = activity_dict->GetValueForKey("id");
1971 StructuredData::ObjectSP name = activity_dict->GetValueForKey("name");
1972 if (name && name->GetType() == eStructuredDataTypeString && id &&
1973 id->GetType() == eStructuredDataTypeInteger) {
1974 strm.Format(" Activity '{0}', {1:x}\n",
1975 name->GetAsString()->GetValue(),
1976 id->GetUnsignedIntegerValue());
1977 }
1978 printed_activity = true;
1979 }
1980 bool printed_breadcrumb = false;
1981 if (breadcrumb && breadcrumb->GetType() == eStructuredDataTypeDictionary) {
1982 if (printed_activity)
1983 strm.Printf("\n");
1984 StructuredData::Dictionary *breadcrumb_dict =
1985 breadcrumb->GetAsDictionary();
1986 StructuredData::ObjectSP breadcrumb_text =
1987 breadcrumb_dict->GetValueForKey("name");
1988 if (breadcrumb_text &&
1989 breadcrumb_text->GetType() == eStructuredDataTypeString) {
1990 strm.Format(" Current Breadcrumb: {0}\n",
1991 breadcrumb_text->GetAsString()->GetValue());
1992 }
1993 printed_breadcrumb = true;
1994 }
1995 if (messages && messages->GetType() == eStructuredDataTypeArray) {
1996 if (printed_breadcrumb)
1997 strm.Printf("\n");
1998 StructuredData::Array *messages_array = messages->GetAsArray();
1999 const size_t msg_count = messages_array->GetSize();
2000 if (msg_count > 0) {
2001 strm.Printf(" %zu trace messages:\n", msg_count);
2002 for (size_t i = 0; i < msg_count; i++) {
2003 StructuredData::ObjectSP message = messages_array->GetItemAtIndex(i);
2004 if (message && message->GetType() == eStructuredDataTypeDictionary) {
2005 StructuredData::Dictionary *message_dict =
2006 message->GetAsDictionary();
2007 StructuredData::ObjectSP message_text =
2008 message_dict->GetValueForKey("message");
2009 if (message_text &&
2010 message_text->GetType() == eStructuredDataTypeString) {
2011 strm.Format(" {0}\n", message_text->GetAsString()->GetValue());
2012 }
2013 }
2014 }
2015 }
2016 }
2017 }
2018
2019 return true;
2020}
2021
2022size_t Thread::GetStackFrameStatus(Stream &strm, uint32_t first_frame,
2023 uint32_t num_frames, bool show_frame_info,
2024 uint32_t num_frames_with_source,
2025 bool show_hidden) {
2026 return GetStackFrameList()->GetStatus(strm, first_frame, num_frames,
2027 show_frame_info, num_frames_with_source,
2028 /*show_unique*/ false, show_hidden);
2029}
2030
2032 if (!m_unwinder_up)
2033 m_unwinder_up = std::make_unique<UnwindLLDB>(*this);
2034 return *m_unwinder_up;
2035}
2036
2042
2044 // If we are currently stopped at a breakpoint, always return that stopinfo
2045 // and don't reset it. This allows threads to maintain their breakpoint
2046 // stopinfo, such as when thread-stepping in multithreaded programs.
2047 if (m_stop_info_sp) {
2048 StopReason stop_reason = m_stop_info_sp->GetStopReason();
2049 if (stop_reason == lldb::eStopReasonBreakpoint) {
2050 uint64_t value = m_stop_info_sp->GetValue();
2052 if (reg_ctx_sp) {
2053 lldb::addr_t pc = reg_ctx_sp->GetPC();
2054 BreakpointSiteSP bp_site_sp =
2055 GetProcess()->GetBreakpointSiteList().FindByAddress(pc);
2056 if (bp_site_sp && static_cast<break_id_t>(value) == bp_site_sp->GetID())
2057 return true;
2058 }
2059 }
2060 }
2061 return false;
2062}
2063
2064Status Thread::StepIn(bool source_step,
2065 LazyBool step_in_avoids_code_without_debug_info,
2066 LazyBool step_out_avoids_code_without_debug_info)
2067
2068{
2069 Status error;
2070 Process *process = GetProcess().get();
2071 if (StateIsStoppedState(process->GetState(), true)) {
2072 StackFrameSP frame_sp = GetStackFrameAtIndex(0);
2073 ThreadPlanSP new_plan_sp;
2074 const lldb::RunMode run_mode = eOnlyThisThread;
2075 const bool abort_other_plans = false;
2076
2077 if (source_step && frame_sp && frame_sp->HasDebugInformation()) {
2078 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
2079 new_plan_sp = QueueThreadPlanForStepInRange(
2080 abort_other_plans, sc.line_entry, sc, nullptr, run_mode, error,
2081 step_in_avoids_code_without_debug_info,
2082 step_out_avoids_code_without_debug_info);
2083 } else {
2085 false, abort_other_plans, run_mode, error);
2086 }
2087
2088 new_plan_sp->SetIsControllingPlan(true);
2089 new_plan_sp->SetOkayToDiscard(false);
2090
2091 // Why do we need to set the current thread by ID here???
2093 error = process->Resume();
2094 } else {
2095 error = Status::FromErrorString("process not stopped");
2096 }
2097 return error;
2098}
2099
2100Status Thread::StepOver(bool source_step,
2101 LazyBool step_out_avoids_code_without_debug_info) {
2102 Status error;
2103 Process *process = GetProcess().get();
2104 if (StateIsStoppedState(process->GetState(), true)) {
2105 StackFrameSP frame_sp = GetStackFrameAtIndex(0);
2106 ThreadPlanSP new_plan_sp;
2107
2108 const lldb::RunMode run_mode = eOnlyThisThread;
2109 const bool abort_other_plans = false;
2110
2111 if (source_step && frame_sp && frame_sp->HasDebugInformation()) {
2112 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
2113 new_plan_sp = QueueThreadPlanForStepOverRange(
2114 abort_other_plans, sc.line_entry, sc, run_mode, error,
2115 step_out_avoids_code_without_debug_info);
2116 } else {
2118 true, abort_other_plans, run_mode, error);
2119 }
2120
2121 new_plan_sp->SetIsControllingPlan(true);
2122 new_plan_sp->SetOkayToDiscard(false);
2123
2124 // Why do we need to set the current thread by ID here???
2126 error = process->Resume();
2127 } else {
2128 error = Status::FromErrorString("process not stopped");
2129 }
2130 return error;
2131}
2132
2133Status Thread::StepOut(uint32_t frame_idx) {
2134 Status error;
2135 Process *process = GetProcess().get();
2136 if (StateIsStoppedState(process->GetState(), true)) {
2137 const bool first_instruction = false;
2138 const bool stop_other_threads = false;
2139 const bool abort_other_plans = false;
2140
2142 abort_other_plans, nullptr, first_instruction, stop_other_threads,
2143 eVoteYes, eVoteNoOpinion, frame_idx, error));
2144
2145 new_plan_sp->SetIsControllingPlan(true);
2146 new_plan_sp->SetOkayToDiscard(false);
2147
2148 // Why do we need to set the current thread by ID here???
2150 error = process->Resume();
2151 } else {
2152 error = Status::FromErrorString("process not stopped");
2153 }
2154 return error;
2155}
2156
2158 if (auto frame_sp = GetStackFrameAtIndex(0))
2159 if (auto recognized_frame = frame_sp->GetRecognizedFrame())
2160 if (auto e = recognized_frame->GetExceptionObject())
2161 return e;
2162
2163 // NOTE: Even though this behavior is generalized, only ObjC is actually
2164 // supported at the moment.
2165 for (LanguageRuntime *runtime : GetProcess()->GetLanguageRuntimes()) {
2166 if (auto e = runtime->GetExceptionObjectForThread(shared_from_this()))
2167 return e;
2168 }
2169
2170 return ValueObjectSP();
2171}
2172
2174 ValueObjectSP exception = GetCurrentException();
2175 if (!exception)
2176 return ThreadSP();
2177
2178 // NOTE: Even though this behavior is generalized, only ObjC is actually
2179 // supported at the moment.
2180 for (LanguageRuntime *runtime : GetProcess()->GetLanguageRuntimes()) {
2181 if (auto bt = runtime->GetBacktraceThreadFromException(exception))
2182 return bt;
2183 }
2184
2185 return ThreadSP();
2186}
2187
2189 ProcessSP process_sp = GetProcess();
2190 assert(process_sp);
2191 Target &target = process_sp->GetTarget();
2192 PlatformSP platform_sp = target.GetPlatform();
2193 assert(platform_sp);
2194 ArchSpec arch = target.GetArchitecture();
2195
2196 CompilerType type = platform_sp->GetSiginfoType(arch.GetTriple());
2197 if (!type.IsValid())
2199 &target, Status::FromErrorString("no siginfo_t for the platform"));
2200
2201 auto type_size_or_err = type.GetByteSize(nullptr);
2202 if (!type_size_or_err)
2204 &target, Status::FromError(type_size_or_err.takeError()));
2205
2206 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> data =
2207 GetSiginfo(*type_size_or_err);
2208 if (!data)
2209 return ValueObjectConstResult::Create(&target,
2210 Status::FromError(data.takeError()));
2211
2212 DataExtractor data_extractor{data.get()->getBufferStart(), data.get()->getBufferSize(),
2213 process_sp->GetByteOrder(), arch.GetAddressByteSize()};
2214 return ValueObjectConstResult::Create(&target, type, ConstString("__lldb_siginfo"), data_extractor);
2215}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
static void DumpAddressList(Stream &s, const std::vector< Address > &list, ExecutionContextScope *exe_scope)
Definition Thread.cpp:1670
ThreadOptionValueProperties(llvm::StringRef name)
Definition Thread.cpp:84
const Property * GetPropertyAtIndex(size_t idx, const ExecutionContext *exe_ctx) const override
Definition Thread.cpp:87
A section + offset based address range class.
A section + offset based address class.
Definition Address.h:62
@ DumpStyleSectionNameOffset
Display as the section name + offset.
Definition Address.h:74
@ DumpStyleResolvedDescription
Display the details about what an address resolves to.
Definition Address.h:104
An architecture specification class.
Definition ArchSpec.h:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition ArchSpec.cpp:685
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition ArchSpec.h:468
bool EventTypeHasListeners(uint32_t event_type)
Broadcaster(lldb::BroadcasterManagerSP manager_sp, std::string name)
Construct with a broadcaster with a name.
void BroadcastEvent(lldb::EventSP &event_sp)
Broadcast an event which has no associated data.
A class that implements CRTP-based "virtual constructor" idiom.
Definition Cloneable.h:40
Generic representation of a type in a programming language.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
CompilerType GetFunctionReturnType() const
void DumpTypeDescription(lldb::DescriptionLevel level=lldb::eDescriptionLevelFull) const
Dump to stdout.
"lldb/Utility/ArgCompletionRequest.h"
void TryCompleteCurrentArg(llvm::StringRef completion, llvm::StringRef description="")
Adds a possible completion string if the completion would complete the current argument.
A uniqued constant string class.
Definition ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
An data extractor class.
A class to manage flag bits.
Definition Debugger.h:80
bool GetUseExternalEditor() const
Definition Debugger.cpp:434
FormatEntity::Entry GetThreadStopFormat() const
Definition Debugger.cpp:363
llvm::StringRef GetExternalEditor() const
Definition Debugger.cpp:445
FormatEntity::Entry GetThreadFormat() const
Definition Debugger.cpp:358
A plug-in interface definition class for dynamic loaders.
virtual lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr)
Retrieves the per-module TLS block for a given thread.
virtual bool IsFullyInitialized()
Return whether the dynamic loader is fully initialized and it's safe to call its APIs.
friend class Event
Definition Event.h:36
virtual llvm::StringRef GetFlavor() const =0
EventData * GetData()
Definition Event.h:199
"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.
void SetFrameSP(const lldb::StackFrameSP &frame_sp)
Set accessor to set only the frame shared pointer.
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
void SetContext(const lldb::TargetSP &target_sp, bool get_process)
Target * GetTargetPtr() const
Returns a pointer to the target object.
Target & GetTargetRef() const
Returns a reference to the target object.
Process * GetProcessPtr() const
Returns a pointer to the process object.
RegisterContext * GetRegisterContext() const
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
A file collection class.
A file utility class.
Definition FileSpec.h:57
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:251
bool Format(const Entry &entry, Stream &s, ValueObject *valobj=nullptr)
CompilerType GetCompilerType()
Definition Function.cpp:571
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition Function.cpp:550
static llvm::Error OpenFileInExternalEditor(llvm::StringRef editor, const FileSpec &file_spec, uint32_t line_no)
void FindAddressesForLine(const lldb::TargetSP target_sp, const FileSpec &file, uint32_t line, Function *function, std::vector< Address > &output_local, std::vector< Address > &output_extern)
Find addresses by file/line.
Property * ProtectedGetPropertyAtIndex(size_t idx)
static lldb::OptionValuePropertiesSP CreateLocalCopy(const Properties &global_properties)
static bool GetRestartedFromEvent(const Event *event_ptr)
Definition Process.cpp:4520
A plug-in interface definition class for debugging a process.
Definition Process.h:354
ThreadList & GetThreadList()
Definition Process.h:2275
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition Process.cpp:1332
virtual SystemRuntime * GetSystemRuntime()
Get the system runtime plug-in for this process.
Definition Process.cpp:2947
lldb::StateType GetState()
Get accessor for the current process state.
Definition Process.cpp:1285
lldb::OptionValuePropertiesSP m_collection_sp
T GetPropertyAtIndexAs(uint32_t idx, T default_value, const ExecutionContext *exe_ctx=nullptr) const
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual StackID & GetStackID()
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:137
bool Success() const
Test for success condition.
Definition Status.cpp:304
static lldb::StopInfoSP CreateStopReasonWithPlan(lldb::ThreadPlanSP &plan, lldb::ValueObjectSP return_valobj_sp, lldb::ExpressionVariableSP expression_variable_sp)
static lldb::StopInfoSP CreateStopReasonWithSignal(Thread &thread, int signo, const char *description=nullptr, std::optional< int > code=std::nullopt)
const char * GetData() const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Format(const char *format, Args &&... args)
Definition Stream.h:364
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition Stream.cpp:198
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition Stream.cpp:195
ObjectSP GetItemAtIndex(size_t idx) const
ObjectSP GetValueForKey(llvm::StringRef key) const
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
LineEntry line_entry
The LineEntry for a given query.
static llvm::Expected< lldb::SyntheticFrameProviderSP > CreateInstance(lldb::StackFrameListSP input_frames, const ScriptedFrameProviderDescriptor &descriptor)
Try to create a SyntheticFrameProvider instance for the given input frames and descriptor.
A plug-in interface definition class for system runtimes.
virtual bool SafeToCallFunctionsOnThisThread(lldb::ThreadSP thread_sp)
Determine whether it is safe to run an expression on a given thread.
Debugger & GetDebugger() const
Definition Target.h:1194
const llvm::DenseMap< uint32_t, ScriptedFrameProviderDescriptor > & GetScriptedFrameProviderDescriptors() const
Get all scripted frame provider descriptors for this target.
Definition Target.cpp:3772
lldb::PlatformSP GetPlatform()
Definition Target.h:1648
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition Target.h:1111
const ArchSpec & GetArchitecture() const
Definition Target.h:1153
lldb::ThreadSP GetSelectedThread()
bool SetSelectedThreadByID(lldb::tid_t tid, bool notify=false)
void DiscardPlansUpToPlan(ThreadPlan *up_to_plan_ptr)
lldb::ThreadPlanSP GetCompletedPlan(bool skip_private=true) const
lldb::ExpressionVariableSP GetExpressionVariable() const
bool IsPlanDone(ThreadPlan *plan) const
void RestoreCompletedPlanCheckpoint(size_t checkpoint)
lldb::ThreadPlanSP GetPlanByIndex(uint32_t plan_idx, bool skip_private=true) const
lldb::ValueObjectSP GetReturnValueObject() const
void PushPlan(lldb::ThreadPlanSP new_plan_sp)
bool WasPlanDiscarded(ThreadPlan *plan) const
ThreadPlan * GetInnermostExpression() const
lldb::ThreadPlanSP GetCurrentPlan() const
ThreadPlan * GetPreviousPlan(ThreadPlan *current_plan) const
virtual bool IsLeafPlan()
Definition ThreadPlan.h:417
virtual Vote ShouldReportStop(Event *event_ptr)
virtual bool OkayToDiscard()
virtual bool ShouldAutoContinue(Event *event_ptr)
Returns whether this thread plan overrides the ShouldStop of subsequently processed plans.
Definition ThreadPlan.h:385
Vote ShouldReportRun(Event *event_ptr)
const char * GetName() const
Returns the name of this thread plan.
Definition ThreadPlan.h:324
ThreadPlanKind GetKind() const
Definition ThreadPlan.h:446
virtual bool ShouldRunBeforePublicStop()
Definition ThreadPlan.h:404
bool PlanExplainsStop(Event *event_ptr)
bool WillResume(lldb::StateType resume_state, bool current_plan)
virtual bool MischiefManaged()
virtual bool IsPlanStale()
Definition ThreadPlan.h:452
virtual bool WillStop()=0
virtual bool ShouldStop(Event *event_ptr)=0
virtual bool IsBasePlan()
Definition ThreadPlan.h:456
bool GetStepInAvoidsNoDebug() const
Definition Thread.cpp:133
const RegularExpression * GetSymbolsToAvoidRegexp()
The regular expression returned determines symbols that this thread won't stop in during "step-in" op...
Definition Thread.cpp:117
bool GetTraceEnabledState() const
Definition Thread.cpp:127
ThreadProperties(bool is_global)
Definition Thread.cpp:106
uint64_t GetMaxBacktraceDepth() const
Definition Thread.cpp:145
FileSpecList GetLibrariesToAvoid() const
Definition Thread.cpp:122
bool GetStepOutAvoidsNoDebug() const
Definition Thread.cpp:139
uint64_t GetSingleThreadPlanTimeout() const
Definition Thread.cpp:151
bool ThreadPassesBasicTests(Thread &thread) const
static const ThreadEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Thread.cpp:177
static lldb::ThreadSP GetThreadFromEvent(const Event *event_ptr)
Definition Thread.cpp:187
void Dump(Stream *s) const override
Definition Thread.cpp:174
static lldb::StackFrameSP GetStackFrameFromEvent(const Event *event_ptr)
Definition Thread.cpp:204
static llvm::StringRef GetFlavorString()
Definition Thread.cpp:159
ThreadEventData(const lldb::ThreadSP thread_sp)
Definition Thread.cpp:163
lldb::ThreadSP GetThread() const
Definition Thread.h:112
static StackID GetStackIDFromEvent(const Event *event_ptr)
Definition Thread.cpp:195
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:1357
bool IsThreadPlanDone(ThreadPlan *plan) const
Checks whether the given plan is in the completed plans for this stop.
Definition Thread.cpp:1188
virtual lldb::user_id_t GetProtocolID() const
Definition Thread.h:1161
lldb::ThreadSP GetCurrentExceptionBacktrace()
Definition Thread.cpp:2173
std::optional< lldb::addr_t > GetPreviousFrameZeroPC()
Request the pc value the thread had when previously stopped.
Definition Thread.cpp:1544
void BroadcastSelectedFrameChange(StackID &new_frame_id)
Definition Thread.cpp:269
@ eBroadcastBitSelectedFrameChanged
Definition Thread.h:76
Status UnwindInnermostExpression()
Unwinds the thread stack for the innermost expression plan currently on the thread plan stack.
Definition Thread.cpp:1273
~Thread() override
Definition Thread.cpp:248
const uint32_t m_index_id
A unique 1 based index assigned to each thread for easy UI/command line access.
Definition Thread.h:1377
void SetShouldRunBeforePublicStop(bool newval)
Definition Thread.h:1256
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition Thread.h:431
bool CompletedPlanOverridesBreakpoint() const
Check if we have completed plan to override breakpoint stop reason.
Definition Thread.cpp:1196
lldb::StackFrameListSP m_curr_frames_sp
The stack frames that get lazily populated after a thread stops.
Definition Thread.h:1386
virtual bool SafeToCallFunctions()
Check whether this thread is safe to run functions.
Definition Thread.cpp:1803
void RestoreThreadStateFromCheckpoint(ThreadStateCheckpoint &saved_state)
Definition Thread.cpp:562
Status QueueThreadPlan(lldb::ThreadPlanSP &plan_sp, bool abort_other_plans)
Queues a generic thread plan.
Definition Thread.cpp:1204
bool WasThreadPlanDiscarded(ThreadPlan *plan) const
Checks whether the given plan is in the discarded plans for this stop.
Definition Thread.cpp:1192
virtual lldb::RegisterContextSP GetRegisterContext()=0
virtual lldb::addr_t GetThreadPointer()
Retrieves the per-thread data area.
Definition Thread.cpp:1785
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:1412
virtual void DidStop()
Definition Thread.cpp:770
virtual bool RestoreRegisterStateFromCheckpoint(ThreadStateCheckpoint &saved_state)
Definition Thread.cpp:540
friend class ThreadPlan
Definition Thread.h:1310
bool SetupToStepOverBreakpointIfNeeded(lldb::RunDirection direction)
Definition Thread.cpp:629
uint32_t m_stop_info_stop_id
Definition Thread.h:1364
void AutoCompleteThreadPlans(CompletionRequest &request) const
Format the thread plan information for auto completion.
Definition Thread.cpp:1156
std::recursive_mutex m_frame_mutex
Multithreaded protection for m_state.
Definition Thread.h:1385
static void SettingsInitialize()
Definition Thread.cpp:1781
void SetShouldReportStop(Vote vote)
Definition Thread.cpp:492
virtual lldb::StopInfoSP GetPrivateStopInfo(bool calculate=true)
Definition Thread.cpp:392
uint32_t GetIndexID() const
Definition Thread.cpp:1434
std::optional< lldb::addr_t > m_prev_framezero_pc
Frame 0's PC the last time this thread was stopped.
Definition Thread.h:1391
Status ReturnFromFrame(lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast=false)
Definition Thread.cpp:1588
void CalculateExecutionContext(ExecutionContext &exe_ctx) override
Reconstruct the object's execution context into sc.
Definition Thread.cpp:1450
void DiscardThreadPlans(bool force)
Discards the plans queued on the plan stack of the current thread.
Definition Thread.cpp:1257
void SetStopInfo(const lldb::StopInfoSP &stop_info_sp)
Definition Thread.cpp:470
bool GetDescription(Stream &s, lldb::DescriptionLevel level, bool print_json_thread, bool print_json_stopinfo)
Definition Thread.cpp:1934
static std::string RunModeAsString(lldb::RunMode mode)
Definition Thread.cpp:1864
void SetTemporaryResumeState(lldb::StateType new_state)
Definition Thread.h:1350
virtual bool MatchesSpec(const ThreadSpec *spec)
Definition Thread.cpp:1103
lldb::ProcessSP CalculateProcess() override
Definition Thread.cpp:1444
StructuredData::ObjectSP GetExtendedInfo()
Retrieve a dictionary of information about this thread.
Definition Thread.h:278
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:1791
void SetStopInfoToNothing()
Definition Thread.cpp:503
virtual void DestroyThread()
Definition Thread.cpp:257
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:1401
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:1388
lldb::StackFrameSP GetSelectedFrame(SelectMostRelevant select_most_relevant)
Definition Thread.cpp:278
virtual bool IsStillAtLastBreakpointHit()
Definition Thread.cpp:2043
std::recursive_mutex m_state_mutex
Multithreaded protection for m_state.
Definition Thread.h:1383
ThreadPlan * GetPreviousPlan(ThreadPlan *plan) const
Definition Thread.cpp:1200
virtual const char * GetName()
Definition Thread.h:286
void PushPlan(lldb::ThreadPlanSP plan_sp)
Definition Thread.cpp:1123
lldb::StackFrameListSP m_prev_frames_sp
The previous stack frames from the last time this thread stopped.
Definition Thread.h:1388
virtual void ClearStackFrames()
Definition Thread.cpp:1548
ThreadPlan * GetCurrentPlan() const
Gets the plan which will execute next on the plan stack.
Definition Thread.cpp:1172
virtual Unwind & GetUnwinder()
Definition Thread.cpp:2031
static llvm::StringRef GetStaticBroadcasterClass()
Definition Thread.cpp:219
void SetResumeSignal(int signal)
Definition Thread.h:162
lldb::ValueObjectSP GetReturnValueObject() const
Gets the outer-most return value from the completed plans.
Definition Thread.cpp:1180
virtual lldb::ThreadSP GetBackingThread() const
Definition Thread.h:522
lldb::ExpressionVariableSP GetExpressionVariable() const
Gets the outer-most expression variable from the completed plans.
Definition Thread.cpp:1184
Vote ShouldReportRun(Event *event_ptr)
Definition Thread.cpp:1072
lldb::TargetSP CalculateTarget() override
Definition Thread.cpp:1436
static std::string StopReasonAsString(lldb::StopReason reason)
Definition Thread.cpp:1823
virtual void WillResume(lldb::StateType resume_state)
Definition Thread.h:216
Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id=false)
Constructor.
Definition Thread.cpp:224
lldb::addr_t m_stopped_at_unexecuted_bp
Definition Thread.h:1374
bool ThreadStoppedForAReason()
Definition Thread.cpp:511
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:2022
std::string GetStopDescriptionRaw()
Definition Thread.cpp:605
void ClearScriptedFrameProvider()
Definition Thread.cpp:1537
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:1232
virtual Status StepOver(bool source_step, LazyBool step_out_avoids_code_without_debug_info=eLazyBoolCalculate)
Default implementation for stepping over.
Definition Thread.cpp:2100
bool ShouldResume(lldb::StateType resume_state)
Definition Thread.cpp:693
std::unique_ptr< lldb_private::Unwind > m_unwinder_up
It gets set in Thread::ShouldResume.
Definition Thread.h:1403
std::unique_ptr< ThreadPlanStack > m_null_plan_stack_up
Definition Thread.h:1407
lldb::StateType GetTemporaryResumeState() const
Definition Thread.h:1246
virtual bool CheckpointThreadState(ThreadStateCheckpoint &saved_state)
Definition Thread.cpp:513
void SetState(lldb::StateType state)
Definition Thread.cpp:580
llvm::Error LoadScriptedFrameProvider(const ScriptedFrameProviderDescriptor &descriptor)
Definition Thread.cpp:1513
lldb::ProcessSP GetProcess() const
Definition Thread.h:158
lldb::StackFrameSP CalculateStackFrame() override
Definition Thread.cpp:1448
lldb::StateType GetResumeState() const
Gets the USER resume state for this thread.
Definition Thread.h:202
friend class StackFrame
Definition Thread.h:1314
uint32_t SetSelectedFrame(lldb_private::StackFrame *frame, bool broadcast=false)
Definition Thread.cpp:286
lldb::StopInfoSP m_stop_info_sp
The private stop reason for this thread.
Definition Thread.h:1363
lldb::ProcessWP m_process_wp
The process that owns this thread.
Definition Thread.h:1362
void DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx, bool stop_format)
Definition Thread.cpp:1762
LazyBool m_override_should_notify
Definition Thread.h:1406
lldb::ThreadSP CalculateThread() override
Definition Thread.cpp:1446
Status ReturnFromFrameWithIndex(uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast=false)
Definition Thread.cpp:1573
virtual Status StepOut(uint32_t frame_idx=0)
Default implementation for stepping out.
Definition Thread.cpp:2133
virtual llvm::Expected< std::unique_ptr< llvm::MemoryBuffer > > GetSiginfo(size_t max_size) const
Definition Thread.h:1357
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:1327
lldb::StateType GetState() const
Definition Thread.cpp:574
lldb::StateType m_state
The state of our process.
Definition Thread.h:1381
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:1422
bool m_extended_info_fetched
Definition Thread.h:1416
void CalculatePublicStopInfo()
Definition Thread.cpp:387
static void SettingsTerminate()
Definition Thread.cpp:1783
bool SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast=false)
Definition Thread.cpp:295
lldb::StopReason GetStopReason()
Definition Thread.cpp:448
ThreadPlanStack & GetPlans() const
Definition Thread.cpp:1107
lldb::ValueObjectSP GetSiginfoValue()
Definition Thread.cpp:2188
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:1291
uint32_t m_stop_info_override_stop_id
Definition Thread.h:1368
int m_resume_signal
The signal that should be used when continuing this thread.
Definition Thread.h:1393
virtual void DidResume()
Definition Thread.cpp:764
bool StopInfoIsUpToDate() const
Definition Thread.cpp:455
lldb::StackFrameSP GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr)
Definition Thread.cpp:1819
lldb::ThreadPlanSP GetCompletedPlan() const
Gets the outer-most plan that was popped off the plan stack in the most recent stop.
Definition Thread.cpp:1176
lldb::ValueObjectSP GetCurrentException()
Definition Thread.cpp:2157
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:1370
virtual lldb::StackFrameSP GetFrameWithConcreteFrameIndex(uint32_t unwind_idx)
Definition Thread.cpp:1569
bool ShouldStop(Event *event_ptr)
Definition Thread.cpp:772
Status JumpToLine(const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings=nullptr)
Definition Thread.cpp:1680
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:1740
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:1244
void FrameSelectedCallback(lldb_private::StackFrame *frame)
Definition Thread.cpp:340
lldb::SyntheticFrameProviderSP m_frame_provider_sp
The Scripted Frame Provider, if any.
Definition Thread.h:1413
lldb::ThreadPlanSP QueueBasePlan(bool abort_other_plans)
Queues the base plan for a thread.
Definition Thread.cpp:1285
static ThreadProperties & GetGlobalProperties()
Definition Thread.cpp:66
uint32_t GetCurrentInlinedDepth()
Definition Thread.h:442
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:1300
std::string GetStopDescription()
Definition Thread.cpp:585
StructuredData::ObjectSP m_extended_info
Definition Thread.h:1418
lldb::StopInfoSP GetStopInfo()
Definition Thread.cpp:354
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:1398
lldb::StackFrameListSP GetStackFrameList()
Definition Thread.cpp:1454
bool m_should_run_before_public_stop
Definition Thread.h:1371
Vote ShouldReportStop(Event *event_ptr)
Definition Thread.cpp:1011
bool SetSelectedFrameByIndexNoisily(uint32_t frame_idx, Stream &output_stream)
Definition Thread.cpp:307
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:1395
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:2064
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:1877
lldb::RegisterContextSP m_reg_context_sp
The register context for this thread's current register state.
Definition Thread.h:1379
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size, lldb::addr_t address=LLDB_INVALID_ADDRESS)
#define LLDB_INVALID_SIGNAL_NUMBER
#define LLDB_INVALID_INDEX32
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
#define LLDB_INVALID_FRAME_ID
@ DoNoSelectMostRelevantFrame
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
bool StateIsStoppedState(lldb::StateType state, bool must_exist)
Check if a state represents a state where the process or thread is stopped.
Definition State.cpp:89
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition State.cpp:14
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::BreakpointSite > BreakpointSiteSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelInitial
@ eDescriptionLevelFull
@ eDescriptionLevelVerbose
RunDirection
Execution directions.
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::ExpressionVariable > ExpressionVariableSP
std::shared_ptr< lldb_private::Platform > PlatformSP
StateType
Process and Thread States.
@ eStateUnloaded
Process is object is valid, but not currently loaded.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
int32_t break_id_t
Definition lldb-types.h:86
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
uint64_t addr_t
Definition lldb-types.h:80
StopReason
Thread stop reasons.
@ eStopReasonInstrumentation
@ eStopReasonPlanComplete
@ eStopReasonHistoryBoundary
@ eStopReasonBreakpoint
@ eStopReasonExec
Program was re-exec'ed.
@ eStopReasonVForkDone
@ eStopReasonInterrupt
Thread requested interrupt.
@ eStopReasonProcessorTrace
@ eStopReasonThreadExiting
@ eStopReasonException
@ eStopReasonWatchpoint
std::shared_ptr< lldb_private::Target > TargetSP
@ eStructuredDataTypeDictionary
@ eStructuredDataTypeInteger
@ eStructuredDataTypeArray
@ eStructuredDataTypeString
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
RunMode
Thread Run Modes.
@ eOnlyDuringStepping
uint64_t tid_t
Definition lldb-types.h:84
std::shared_ptr< lldb_private::Module > ModuleSP
std::shared_ptr< lldb_private::RegisterCheckpoint > RegisterCheckpointSP
std::shared_ptr< lldb_private::StackFrameList > StackFrameListSP
A line table entry class.
Definition LineEntry.h:21
AddressRange GetSameLineContiguousAddressRange(bool include_inlined_functions) const
Give the range for this LineEntry + any additional LineEntries for this same source line that are con...
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition LineEntry.h:151
const FileSpec & GetFile() const
Helper to access the file.
Definition LineEntry.h:134
This struct contains the metadata needed to instantiate a frame provider and optional filters to cont...
bool AppliesToThread(Thread &thread) const
Check if this descriptor applies to the given thread.
bool IsValid() const
Check if this descriptor has valid metadata for script-based providers.
std::optional< uint32_t > GetPriority() const
Get the priority of this frame provider.
lldb::RegisterCheckpointSP register_backup_sp
Definition Thread.h:131
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47