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