LLDB mainline
SBThread.cpp
Go to the documentation of this file.
1//===-- SBThread.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
9#include "lldb/API/SBThread.h"
10#include "Utils.h"
11#include "lldb/API/SBAddress.h"
12#include "lldb/API/SBDebugger.h"
13#include "lldb/API/SBEvent.h"
14#include "lldb/API/SBFileSpec.h"
15#include "lldb/API/SBFormat.h"
16#include "lldb/API/SBFrame.h"
18#include "lldb/API/SBProcess.h"
19#include "lldb/API/SBStream.h"
24#include "lldb/API/SBValue.h"
26#include "lldb/Core/Debugger.h"
31#include "lldb/Target/Process.h"
32#include "lldb/Target/Queue.h"
35#include "lldb/Target/Target.h"
36#include "lldb/Target/Thread.h"
43#include "lldb/Utility/State.h"
44#include "lldb/Utility/Stream.h"
49
50#include <memory>
51
52using namespace lldb;
53using namespace lldb_private;
54
61
62// Constructors
66
67SBThread::SBThread(const ThreadSP &lldb_object_sp)
68 : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {
69 LLDB_INSTRUMENT_VA(this, lldb_object_sp);
70}
71
73 LLDB_INSTRUMENT_VA(this, rhs);
74
76}
77
78// Assignment operator
79
81 LLDB_INSTRUMENT_VA(this, rhs);
82
83 if (this != &rhs)
85 return *this;
86}
87
88// Destructor
89SBThread::~SBThread() = default;
90
93
94 SBQueue sb_queue;
95 QueueSP queue_sp;
96 llvm::Expected<StoppedExecutionContext> exe_ctx =
98 if (!exe_ctx) {
99 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
100 return SBQueue();
101 }
102
103 if (exe_ctx->HasThreadScope()) {
104 queue_sp = exe_ctx->GetThreadPtr()->GetQueue();
105 if (queue_sp) {
106 sb_queue.SetQueue(queue_sp);
107 }
108 }
109
110 return sb_queue;
111}
112
113bool SBThread::IsValid() const {
114 LLDB_INSTRUMENT_VA(this);
115 return this->operator bool();
116}
117SBThread::operator bool() const {
118 LLDB_INSTRUMENT_VA(this);
119 if (!m_opaque_sp)
120 return false;
121
122 llvm::Expected<StoppedExecutionContext> exe_ctx =
124 if (!exe_ctx) {
125 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
126 return false;
127 }
128
129 return m_opaque_sp->GetThreadSP().get() != nullptr;
130}
131
133 LLDB_INSTRUMENT_VA(this);
134
135 m_opaque_sp->Clear();
136}
137
139 LLDB_INSTRUMENT_VA(this);
140
142 llvm::Expected<StoppedExecutionContext> exe_ctx =
144 if (!exe_ctx) {
145 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
146 return reason;
147 }
148
149 if (exe_ctx->HasThreadScope())
150 return exe_ctx->GetThreadPtr()->GetStopReason();
151
152 return reason;
153}
154
156 LLDB_INSTRUMENT_VA(this);
157
158 llvm::Expected<StoppedExecutionContext> exe_ctx =
160 if (exe_ctx) {
161 if (exe_ctx->HasThreadScope()) {
162 StopInfoSP stop_info_sp = exe_ctx->GetThreadPtr()->GetStopInfo();
163 if (stop_info_sp)
164 return stop_info_sp->GetStopReasonDataCount();
165 }
166 } else {
167 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
168 return 0;
169 }
170 return 0;
171}
172
174 LLDB_INSTRUMENT_VA(this, idx);
175
176 llvm::Expected<StoppedExecutionContext> exe_ctx =
178 if (exe_ctx) {
179 if (exe_ctx->HasThreadScope()) {
180 Thread *thread = exe_ctx->GetThreadPtr();
181 StopInfoSP stop_info_sp = thread->GetStopInfo();
182 if (stop_info_sp)
183 return stop_info_sp->GetStopReasonDataAtIndex(idx);
184 }
185 } else {
186 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
187 return 0;
188 }
189 return 0;
190}
191
193 LLDB_INSTRUMENT_VA(this, stream);
194
195 Stream &strm = stream.ref();
196
197 llvm::Expected<StoppedExecutionContext> exe_ctx =
199 if (!exe_ctx) {
200 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
201 return false;
202 }
203
204 if (!exe_ctx->HasThreadScope())
205 return false;
206
207 StopInfoSP stop_info = exe_ctx->GetThreadPtr()->GetStopInfo();
208 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
209 if (!info)
210 return false;
211
212 info->Dump(strm);
213
214 return true;
215}
216
219 LLDB_INSTRUMENT_VA(this, type);
220
221 SBThreadCollection threads;
222
223 llvm::Expected<StoppedExecutionContext> exe_ctx =
225 if (!exe_ctx) {
226 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
227 return SBThreadCollection();
228 }
229
230 if (!exe_ctx->HasThreadScope())
231 return SBThreadCollection();
232
233 ProcessSP process_sp = exe_ctx->GetProcessSP();
234
235 StopInfoSP stop_info = exe_ctx->GetThreadPtr()->GetStopInfo();
236 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
237 if (!info)
238 return threads;
239
240 threads = process_sp->GetInstrumentationRuntime(type)
241 ->GetBacktracesFromExtendedStopInfo(info);
242 return threads;
243}
244
246 LLDB_INSTRUMENT_VA(this, stream);
247
248 if (!m_opaque_sp)
249 return false;
250
251 llvm::Expected<StoppedExecutionContext> exe_ctx =
253 if (!exe_ctx) {
254 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
255 return false;
256 }
257
258 if (!exe_ctx->HasThreadScope())
259 return false;
260
261 Stream &strm = stream.ref();
262 const std::string stop_desc = exe_ctx->GetThreadPtr()->GetStopDescription();
263 strm.PutCString(stop_desc);
264
265 return true;
266}
267
268size_t SBThread::GetStopDescription(char *dst_or_null, size_t dst_len) {
269 LLDB_INSTRUMENT_VA(this, dst_or_null, dst_len);
270
271 if (dst_or_null)
272 *dst_or_null = 0;
273
274 llvm::Expected<StoppedExecutionContext> exe_ctx =
276 if (!exe_ctx) {
277 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
278 return 0;
279 }
280
281 if (!exe_ctx->HasThreadScope())
282 return 0;
283
284 std::string thread_stop_desc = exe_ctx->GetThreadPtr()->GetStopDescription();
285 if (thread_stop_desc.empty())
286 return 0;
287
288 if (dst_or_null)
289 return ::snprintf(dst_or_null, dst_len, "%s", thread_stop_desc.c_str()) + 1;
290
291 // NULL dst passed in, return the length needed to contain the
292 // description.
293 return thread_stop_desc.size() + 1; // Include the NULL byte for size
294}
295
296/// Get what the function the thread stepped out of returned or threw.
299 llvm::Expected<StoppedExecutionContext> exe_ctx =
300 GetStoppedExecutionContext(exe_ctx_ref_sp);
301 if (!exe_ctx) {
302 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
303 return {};
304 }
305
306 if (!exe_ctx->HasThreadScope())
307 return {};
308 StopInfoSP stop_info_sp = exe_ctx->GetThreadPtr()->GetStopInfo();
309 if (!stop_info_sp)
310 return {};
311 return StopInfo::GetReturnValue(stop_info_sp);
312}
313
315 LLDB_INSTRUMENT_VA(this);
316
318 if (auto *returned = std::get_if<ReturnedValue>(&return_value))
319 return SBValue(returned->valobj_sp);
320 return SBValue();
321}
322
324 LLDB_INSTRUMENT_VA(this);
325
327 if (auto *thrown = std::get_if<ThrownError>(&return_value))
328 return SBValue(thrown->valobj_sp);
329 return SBValue();
330}
331
332void SBThread::SetThread(const ThreadSP &lldb_object_sp) {
333 m_opaque_sp->SetThreadSP(lldb_object_sp);
334}
335
337 LLDB_INSTRUMENT_VA(this);
338
339 llvm::Expected<StoppedExecutionContext> exe_ctx =
341 if (!exe_ctx) {
342 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
344 }
345
346 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
347 if (thread_sp)
348 return thread_sp->GetID();
350}
351
352uint32_t SBThread::GetIndexID() const {
353 LLDB_INSTRUMENT_VA(this);
354
355 llvm::Expected<StoppedExecutionContext> exe_ctx =
357 if (!exe_ctx) {
358 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
360 }
361
362 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
363 if (thread_sp)
364 return thread_sp->GetIndexID();
366}
367
368const char *SBThread::GetName() const {
369 LLDB_INSTRUMENT_VA(this);
370
371 llvm::Expected<StoppedExecutionContext> exe_ctx =
373 if (!exe_ctx) {
374 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
375 return nullptr;
376 }
377
378 if (!exe_ctx->HasThreadScope())
379 return nullptr;
380
381 return GetDebuggerStringPool(exe_ctx->GetTargetRef())
382 .Intern(exe_ctx->GetThreadPtr()->GetName());
383}
384
385const char *SBThread::GetQueueName() const {
386 LLDB_INSTRUMENT_VA(this);
387
388 llvm::Expected<StoppedExecutionContext> exe_ctx =
390 if (!exe_ctx) {
391 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
392 return nullptr;
393 }
394
395 if (!exe_ctx->HasThreadScope())
396 return nullptr;
397
398 return GetDebuggerStringPool(exe_ctx->GetTargetRef())
399 .Intern(exe_ctx->GetThreadPtr()->GetQueueName());
400}
401
403 LLDB_INSTRUMENT_VA(this);
404
406 llvm::Expected<StoppedExecutionContext> exe_ctx =
408 if (!exe_ctx) {
409 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
410 return id;
411 }
412
413 if (exe_ctx->HasThreadScope()) {
414 id = exe_ctx->GetThreadPtr()->GetQueueID();
415 }
416
417 return id;
418}
419
420bool SBThread::GetInfoItemByPathAsString(const char *path, SBStream &strm) {
421 LLDB_INSTRUMENT_VA(this, path, strm);
422
423 bool success = false;
424 llvm::Expected<StoppedExecutionContext> exe_ctx =
426 if (exe_ctx) {
427 if (exe_ctx->HasThreadScope()) {
428 Thread *thread = exe_ctx->GetThreadPtr();
429 StructuredData::ObjectSP info_root_sp = thread->GetExtendedInfo();
430 if (info_root_sp) {
432 info_root_sp->GetObjectForDotSeparatedPath(path);
433 if (node) {
434 if (node->GetType() == eStructuredDataTypeString) {
435 strm.ref() << node->GetAsString()->GetValue();
436 success = true;
437 }
438 if (node->GetType() == eStructuredDataTypeInteger) {
439 strm.Printf("0x%" PRIx64, node->GetUnsignedIntegerValue());
440 success = true;
441 }
442 if (node->GetType() == eStructuredDataTypeFloat) {
443 strm.Printf("0x%f", node->GetAsFloat()->GetValue());
444 success = true;
445 }
446 if (node->GetType() == eStructuredDataTypeBoolean) {
447 if (node->GetAsBoolean()->GetValue())
448 strm.Printf("true");
449 else
450 strm.Printf("false");
451 success = true;
452 }
453 if (node->GetType() == eStructuredDataTypeNull) {
454 strm.Printf("null");
455 success = true;
456 }
457 }
458 }
459 }
460 } else {
461 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
462 return success;
463 }
464
465 return success;
466}
467
469 ThreadPlan *new_plan) {
470 Thread *thread = exe_ctx.GetThreadPtr();
471 if (!thread)
472 return Status::FromErrorString("No thread in SBThread::ResumeNewPlan");
473
474 // User level plans should be Controlling Plans so they can be interrupted,
475 // other plans executed, and then a "continue" will resume the plan.
476 if (new_plan != nullptr) {
477 new_plan->SetIsControllingPlan(true);
478 new_plan->SetOkayToDiscard(false);
479 }
480
481 // Why do we need to set the current thread by ID here???
482 Process *process = exe_ctx.GetProcessPtr();
483 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
484
485 // Release the run lock but keep the API lock.
486 TargetAPIMutex api_mutex = exe_ctx.AllowResume();
487 std::unique_lock<TargetAPIMutex> guard(api_mutex, std::adopt_lock);
488 if (process->GetTarget().GetDebugger().GetAsyncExecution())
489 return process->Resume();
490 return process->ResumeSynchronous(nullptr);
491}
492
493void SBThread::StepOver(lldb::RunMode stop_other_threads) {
494 LLDB_INSTRUMENT_VA(this, stop_other_threads);
495
496 SBError error; // Ignored
497 StepOver(stop_other_threads, error);
498}
499
500void SBThread::StepOver(lldb::RunMode stop_other_threads, SBError &error) {
501 LLDB_INSTRUMENT_VA(this, stop_other_threads, error);
502
503 llvm::Expected<StoppedExecutionContext> exe_ctx =
505 if (!exe_ctx) {
506 error = Status::FromError(exe_ctx.takeError());
507 return;
508 }
509
510 if (!exe_ctx->HasThreadScope()) {
511 error = Status::FromErrorString("this SBThread object is invalid");
512 return;
513 }
514
515 Thread *thread = exe_ctx->GetThreadPtr();
516 bool abort_other_plans = false;
517 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
518 if (!frame_sp) {
519 error.SetErrorString("No frame to step over");
520 return;
521 }
522
523 ThreadPlanSP new_plan_sp;
524 lldb::StepType step_type =
525 frame_sp->HasDebugInformation() || frame_sp->IsSynthetic()
528
529 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
530 frame_sp->GetThreadPlanForStepType(step_type);
531 if (auto llvm_err = frame_plan_result.takeError()) {
532 error.SetErrorStringWithFormat("scripted frame provider got an error "
533 "while constructing step plan: \"%s\"",
534 llvm::toString(std::move(llvm_err)).c_str());
535 return;
536 }
537 new_plan_sp = *frame_plan_result;
538
539 if (new_plan_sp) {
540 thread->QueueThreadPlan(new_plan_sp, false);
541 } else {
542 Status new_plan_status;
543 if (step_type == eStepTypeOver) {
544 const LazyBool avoid_no_debug = eLazyBoolCalculate;
545 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
546 new_plan_sp = thread->QueueThreadPlanForStepOverRange(
547 abort_other_plans, sc.line_entry, sc, stop_other_threads,
548 new_plan_status, avoid_no_debug);
549 } else {
550 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
551 true, abort_other_plans, stop_other_threads, new_plan_status);
552 }
553 }
554 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
555}
556
557void SBThread::StepInto(lldb::RunMode stop_other_threads) {
558 LLDB_INSTRUMENT_VA(this, stop_other_threads);
559
560 StepInto(nullptr, stop_other_threads);
561}
562
563void SBThread::StepInto(const char *target_name,
564 lldb::RunMode stop_other_threads) {
565 LLDB_INSTRUMENT_VA(this, target_name, stop_other_threads);
566
567 SBError error; // Ignored
568 StepInto(target_name, LLDB_INVALID_LINE_NUMBER, error, stop_other_threads);
569}
570
571void SBThread::StepInto(const char *target_name, uint32_t end_line,
572 SBError &error, lldb::RunMode stop_other_threads) {
573 LLDB_INSTRUMENT_VA(this, target_name, end_line, error, stop_other_threads);
574
575 llvm::Expected<StoppedExecutionContext> exe_ctx =
577 if (!exe_ctx) {
578 error = Status::FromError(exe_ctx.takeError());
579 return;
580 }
581
582 if (!exe_ctx->HasThreadScope()) {
583 error = Status::FromErrorString("this SBThread object is invalid");
584 return;
585 }
586
587 bool abort_other_plans = false;
588
589 Thread *thread = exe_ctx->GetThreadPtr();
590 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
591 ThreadPlanSP new_plan_sp;
592 Status new_plan_status;
593 lldb::StepType step_type;
594
595 if (frame_sp && (frame_sp->HasDebugInformation() || frame_sp->IsSynthetic()))
596 step_type = eStepTypeInto;
597 else
598 step_type = eStepTypeTrace;
599
600 // First see if the Frame has some special way to do this step:
601 if (frame_sp) {
602 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
603 frame_sp->GetThreadPlanForStepType(step_type);
604 if (auto llvm_err = frame_plan_result.takeError()) {
605 error.SetErrorStringWithFormat(
606 "scripted frame provider got an error "
607 "while constructing step plan: \"%s\"",
608 llvm::toString(std::move(llvm_err)).c_str());
609 return;
610 }
611 new_plan_sp = *frame_plan_result;
612 }
613
614 if (new_plan_sp) {
615 thread->QueueThreadPlan(new_plan_sp, false);
616 } else {
617 if (step_type == eStepTypeInto) {
618 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
619 AddressRange range;
620 if (end_line == LLDB_INVALID_LINE_NUMBER)
621 range = sc.line_entry.range;
622 else {
623 llvm::Error err = sc.GetAddressRangeFromHereToEndLine(end_line, range);
624 if (err) {
625 error =
626 Status::FromErrorString(llvm::toString(std::move(err)).c_str());
627 return;
628 }
629 }
630
631 const LazyBool step_out_avoids_code_without_debug_info =
633 const LazyBool step_in_avoids_code_without_debug_info =
635 new_plan_sp = thread->QueueThreadPlanForStepInRange(
636 abort_other_plans, range, sc, target_name, stop_other_threads,
637 new_plan_status, step_in_avoids_code_without_debug_info,
638 step_out_avoids_code_without_debug_info);
639 } else {
640 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
641 false, abort_other_plans, stop_other_threads, new_plan_status);
642 }
643 }
644
645 if (new_plan_status.Success())
646 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
647 else
648 error = Status::FromErrorString(new_plan_status.AsCString());
649}
650
652 LLDB_INSTRUMENT_VA(this);
653
654 SBError error; // Ignored
655 StepOut(error);
656}
657
660
661 llvm::Expected<StoppedExecutionContext> exe_ctx =
663 if (!exe_ctx) {
664 error = Status::FromError(exe_ctx.takeError());
665 return;
666 }
667
668 if (!exe_ctx->HasThreadScope()) {
669 error = Status::FromErrorString("this SBThread object is invalid");
670 return;
671 }
672
673 bool abort_other_plans = false;
674 bool stop_other_threads = false;
675
676 ThreadPlanSP new_plan_sp;
677
678 Thread *thread = exe_ctx->GetThreadPtr();
679 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
680 if (frame_sp) {
681 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
682 frame_sp->GetThreadPlanForStepType(eStepTypeOut);
683 if (auto llvm_err = frame_plan_result.takeError()) {
684 error.SetErrorStringWithFormat(
685 "scripted frame provider got an error "
686 "while constructing step plan: \"%s\"",
687 llvm::toString(std::move(llvm_err)).c_str());
688 return;
689 }
690 new_plan_sp = *frame_plan_result;
691 }
692
693 Status new_plan_status;
694 if (new_plan_sp) {
695 // FIXME: Carry over stop_other_threads, and avoid_no_debug to
696 // the new plan?
697 thread->QueueThreadPlan(new_plan_sp, false);
698 } else {
699 const LazyBool avoid_no_debug = eLazyBoolCalculate;
700 new_plan_sp = thread->QueueThreadPlanForStepOut(
701 abort_other_plans, nullptr, false, stop_other_threads, eVoteYes,
702 eVoteNoOpinion, 0, new_plan_status, avoid_no_debug);
703 }
704
705 if (new_plan_status.Success())
706 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
707 else
708 error = Status::FromErrorString(new_plan_status.AsCString());
709}
710
712 LLDB_INSTRUMENT_VA(this, sb_frame);
713
714 SBError error; // Ignored
715 StepOutOfFrame(sb_frame, error);
716}
717
719 LLDB_INSTRUMENT_VA(this, sb_frame, error);
720
721 llvm::Expected<StoppedExecutionContext> exe_ctx =
723 if (!exe_ctx) {
724 error = Status::FromError(exe_ctx.takeError());
725 return;
726 }
727
728 if (!sb_frame.IsValid()) {
729 error = Status::FromErrorString("passed invalid SBFrame object");
730 return;
731 }
732
733 StackFrameSP frame_sp(sb_frame.GetFrameSP());
734
735 if (!exe_ctx->HasThreadScope()) {
736 error = Status::FromErrorString("this SBThread object is invalid");
737 return;
738 }
739
740 bool abort_other_plans = false;
741 bool stop_other_threads = false;
742 Thread *thread = exe_ctx->GetThreadPtr();
743 if (sb_frame.GetThread().GetThreadID() != thread->GetID()) {
744 error = Status::FromErrorString("passed a frame from another thread");
745 return;
746 }
747
748 Status new_plan_status;
749 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut(
750 abort_other_plans, nullptr, false, stop_other_threads, eVoteYes,
751 eVoteNoOpinion, frame_sp->GetFrameIndex(), new_plan_status));
752
753 if (new_plan_status.Success())
754 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
755 else
756 error = Status::FromErrorString(new_plan_status.AsCString());
757}
758
759void SBThread::StepInstruction(bool step_over) {
760 LLDB_INSTRUMENT_VA(this, step_over);
761
762 SBError error; // Ignored
763 StepInstruction(step_over, error);
764}
765
767 LLDB_INSTRUMENT_VA(this, step_over, error);
768
769 llvm::Expected<StoppedExecutionContext> exe_ctx =
771 if (!exe_ctx) {
772 error = Status::FromError(exe_ctx.takeError());
773 return;
774 }
775
776 if (!exe_ctx->HasThreadScope()) {
777 error = Status::FromErrorString("this SBThread object is invalid");
778 return;
779 }
780
781 Thread *thread = exe_ctx->GetThreadPtr();
782 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
783 lldb::StepType step_type = step_over ? eStepTypeTraceOver : eStepTypeTrace;
784
785 ThreadPlanSP new_plan_sp;
786
787 if (frame_sp) {
788 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
789 frame_sp->GetThreadPlanForStepType(step_type);
790 if (auto llvm_err = frame_plan_result.takeError()) {
791 error.SetErrorStringWithFormat(
792 "scripted frame provider got an error "
793 "while constructing step plan: \"%s\"",
794 llvm::toString(std::move(llvm_err)).c_str());
795 return;
796 }
797 new_plan_sp = *frame_plan_result;
798 }
799
800 Status new_plan_status;
801 if (!new_plan_sp)
802 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
803 step_over, false, true, new_plan_status);
804
805 if (new_plan_status.Success())
806 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
807 else
808 error = Status::FromErrorString(new_plan_status.AsCString());
809}
810
812 LLDB_INSTRUMENT_VA(this, addr);
813
814 SBError error; // Ignored
815 RunToAddress(addr, error);
816}
817
819 LLDB_INSTRUMENT_VA(this, addr, error);
820
821 llvm::Expected<StoppedExecutionContext> exe_ctx =
823 if (!exe_ctx) {
824 error = Status::FromError(exe_ctx.takeError());
825 return;
826 }
827
828 if (!exe_ctx->HasThreadScope()) {
829 error = Status::FromErrorString("this SBThread object is invalid");
830 return;
831 }
832
833 bool abort_other_plans = false;
834 bool stop_other_threads = true;
835
836 Address target_addr(addr);
837
838 Thread *thread = exe_ctx->GetThreadPtr();
839
840 Status new_plan_status;
841 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress(
842 abort_other_plans, target_addr, stop_other_threads, new_plan_status));
843
844 if (new_plan_status.Success())
845 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
846 else
847 error = Status::FromErrorString(new_plan_status.AsCString());
848}
849
851 lldb::SBFileSpec &sb_file_spec, uint32_t line) {
852 LLDB_INSTRUMENT_VA(this, sb_frame, sb_file_spec, line);
853
854 SBError sb_error;
855
856 llvm::Expected<StoppedExecutionContext> exe_ctx =
858 if (!exe_ctx)
859 return Status::FromError(exe_ctx.takeError());
860
861 StackFrameSP frame_sp(sb_frame.GetFrameSP());
862
863 if (exe_ctx->HasThreadScope()) {
864 Thread *thread = exe_ctx->GetThreadPtr();
865
866 if (line == 0) {
867 sb_error = Status::FromErrorString("invalid line argument");
868 return sb_error;
869 }
870
871 if (!frame_sp) {
872 // We don't want to run SelectMostRelevantFrame here, for instance if
873 // you called a sequence of StepOverUntil's you wouldn't want the
874 // frame changed out from under you because you stepped into a
875 // recognized frame.
876 frame_sp = thread->GetSelectedFrame(DoNoSelectMostRelevantFrame);
877 if (!frame_sp)
878 frame_sp = thread->GetStackFrameAtIndex(0);
879 }
880
881 SymbolContext frame_sc;
882 if (!frame_sp) {
883 sb_error = Status::FromErrorString("no valid frames in thread to step");
884 return sb_error;
885 }
886
887 // If we have a frame, get its line
888 frame_sc = frame_sp->GetSymbolContext(
889 eSymbolContextCompUnit | eSymbolContextFunction |
890 eSymbolContextLineEntry | eSymbolContextSymbol);
891
892 if (frame_sc.comp_unit == nullptr) {
894 "frame %u doesn't have debug information", frame_sp->GetFrameIndex());
895 return sb_error;
896 }
897
898 FileSpec step_file_spec;
899 if (sb_file_spec.IsValid()) {
900 // The file spec passed in was valid, so use it
901 step_file_spec = sb_file_spec.ref();
902 } else {
903 if (frame_sc.line_entry.IsValid())
904 step_file_spec = frame_sc.line_entry.GetFile();
905 else {
906 sb_error = Status::FromErrorString(
907 "invalid file argument or no file for frame");
908 return sb_error;
909 }
910 }
911
912 const bool abort_other_plans = false;
913 const bool stop_other_threads = false;
914 llvm::Expected<std::vector<addr_t>> step_over_until_addrs =
915 GetStepUntilAddresses(*frame_sp, step_file_spec, {line}, {});
916 if (!step_over_until_addrs)
917 return Status::FromError(step_over_until_addrs.takeError());
918
919 Status new_plan_status;
920 ThreadPlanSP new_plan_sp = thread->QueueThreadPlanForStepUntil(
921 abort_other_plans, *step_over_until_addrs, stop_other_threads,
922 frame_sp->GetFrameIndex(), new_plan_status);
923
924 if (new_plan_status.Success())
925 sb_error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
926 else
927 sb_error = Status::FromErrorString(new_plan_status.AsCString());
928 } else {
929 sb_error = Status::FromErrorString("this SBThread object is invalid");
930 }
931 return sb_error;
932}
933
934SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name) {
935 LLDB_INSTRUMENT_VA(this, script_class_name);
936
937 return StepUsingScriptedThreadPlan(script_class_name, true);
938}
939
940SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name,
941 bool resume_immediately) {
942 LLDB_INSTRUMENT_VA(this, script_class_name, resume_immediately);
943
945 return StepUsingScriptedThreadPlan(script_class_name, no_data,
946 resume_immediately);
947}
948
949SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name,
950 SBStructuredData &args_data,
951 bool resume_immediately) {
952 LLDB_INSTRUMENT_VA(this, script_class_name, args_data, resume_immediately);
953
955
956 llvm::Expected<StoppedExecutionContext> exe_ctx =
958 if (!exe_ctx)
959 return Status::FromError(exe_ctx.takeError());
960
961 if (!exe_ctx->HasThreadScope()) {
962 error = Status::FromErrorString("this SBThread object is invalid");
963 return error;
964 }
965
966 Thread *thread = exe_ctx->GetThreadPtr();
967 Status new_plan_status;
968 StructuredData::ObjectSP obj_sp = args_data.m_impl_up->GetObjectSP();
969
970 StructuredData::DictionarySP args_dict_sp;
971 if (obj_sp && obj_sp->GetType() == lldb::eStructuredDataTypeDictionary)
972 args_dict_sp = std::static_pointer_cast<StructuredData::Dictionary>(obj_sp);
973
974 ScriptedMetadata scripted_metadata(script_class_name, args_dict_sp);
975 ThreadPlanSP new_plan_sp = thread->QueueThreadPlanForStepScripted(
976 false, scripted_metadata, false, new_plan_status);
977
978 if (new_plan_status.Fail()) {
979 error = Status::FromErrorString(new_plan_status.AsCString());
980 return error;
981 }
982
983 if (!resume_immediately)
984 return error;
985
986 if (new_plan_status.Success())
987 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
988 else
989 error = Status::FromErrorString(new_plan_status.AsCString());
990
991 return error;
992}
993
995 LLDB_INSTRUMENT_VA(this, file_spec, line);
996
997 SBError sb_error;
998
999 llvm::Expected<StoppedExecutionContext> exe_ctx =
1001 if (!exe_ctx)
1002 return Status::FromError(exe_ctx.takeError());
1003
1004 if (!exe_ctx->HasThreadScope()) {
1005 sb_error = Status::FromErrorString("this SBThread object is invalid");
1006 return sb_error;
1007 }
1008
1009 Thread *thread = exe_ctx->GetThreadPtr();
1010
1011 Status err = thread->JumpToLine(file_spec.ref(), line, true);
1012 sb_error.SetError(std::move(err));
1013 return sb_error;
1014}
1015
1017 LLDB_INSTRUMENT_VA(this, frame, return_value);
1018
1019 SBError sb_error;
1020
1021 llvm::Expected<StoppedExecutionContext> exe_ctx =
1023 if (!exe_ctx)
1024 return Status::FromError(exe_ctx.takeError());
1025
1026 if (exe_ctx->HasThreadScope()) {
1027 Thread *thread = exe_ctx->GetThreadPtr();
1028 sb_error.SetError(
1029 thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
1030 }
1031
1032 return sb_error;
1033}
1034
1036 LLDB_INSTRUMENT_VA(this);
1037
1038 SBError sb_error;
1039
1040 llvm::Expected<StoppedExecutionContext> exe_ctx =
1042 if (!exe_ctx)
1043 return Status::FromError(exe_ctx.takeError());
1044
1045 if (exe_ctx->HasThreadScope()) {
1046 Thread *thread = exe_ctx->GetThreadPtr();
1047 sb_error.SetError(thread->UnwindInnermostExpression());
1048 if (sb_error.Success())
1049 thread->SetSelectedFrameByIndex(0, false);
1050 }
1051
1052 return sb_error;
1053}
1054
1056 LLDB_INSTRUMENT_VA(this);
1057
1058 SBError error; // Ignored
1059 return Suspend(error);
1060}
1061
1064
1065 llvm::Expected<StoppedExecutionContext> exe_ctx =
1067 if (!exe_ctx) {
1068 error = Status::FromError(exe_ctx.takeError());
1069 return false;
1070 }
1071
1072 bool result = false;
1073 if (exe_ctx->HasThreadScope()) {
1074 exe_ctx->GetThreadPtr()->SetResumeState(eStateSuspended);
1075 result = true;
1076 } else
1077 error = Status::FromErrorString("this SBThread object is invalid");
1078 return result;
1079}
1080
1082 LLDB_INSTRUMENT_VA(this);
1083
1084 SBError error; // Ignored
1085 return Resume(error);
1086}
1087
1090
1091 llvm::Expected<StoppedExecutionContext> exe_ctx =
1093 if (!exe_ctx) {
1094 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1095 error = Status::FromErrorString("process is running");
1096 return false;
1097 }
1098
1099 bool result = false;
1100 if (exe_ctx->HasThreadScope()) {
1101 const bool override_suspend = true;
1102 exe_ctx->GetThreadPtr()->SetResumeState(eStateRunning, override_suspend);
1103 result = true;
1104 } else
1105 error = Status::FromErrorString("this SBThread object is invalid");
1106 return result;
1107}
1108
1110 LLDB_INSTRUMENT_VA(this);
1111
1112 llvm::Expected<StoppedExecutionContext> exe_ctx =
1114 if (!exe_ctx) {
1115 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1116 return false;
1117 }
1118
1119 if (exe_ctx->HasThreadScope())
1120 return exe_ctx->GetThreadPtr()->GetResumeState() == eStateSuspended;
1121 return false;
1122}
1123
1125 LLDB_INSTRUMENT_VA(this);
1126
1127 llvm::Expected<StoppedExecutionContext> exe_ctx =
1129 if (!exe_ctx) {
1130 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1131 return false;
1132 }
1133
1134 if (exe_ctx->HasThreadScope())
1135 return StateIsStoppedState(exe_ctx->GetThreadPtr()->GetState(), true);
1136 return false;
1137}
1138
1140 LLDB_INSTRUMENT_VA(this);
1141
1142 SBProcess sb_process;
1143 llvm::Expected<StoppedExecutionContext> exe_ctx =
1145 if (!exe_ctx) {
1146 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1147 return SBProcess();
1148 }
1149
1150 if (exe_ctx->HasThreadScope()) {
1151 // Have to go up to the target so we can get a shared pointer to our
1152 // process...
1153 sb_process.SetSP(exe_ctx->GetProcessSP());
1154 }
1155
1156 return sb_process;
1157}
1158
1160 LLDB_INSTRUMENT_VA(this);
1161
1162 llvm::Expected<StoppedExecutionContext> exe_ctx =
1164 if (!exe_ctx) {
1165 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1166 return 0;
1167 }
1168
1169 if (exe_ctx->HasThreadScope())
1170 return exe_ctx->GetThreadPtr()->GetStackFrameCount();
1171
1172 return 0;
1173}
1174
1176 LLDB_INSTRUMENT_VA(this, idx);
1177
1178 SBFrame sb_frame;
1179 llvm::Expected<StoppedExecutionContext> exe_ctx =
1181 if (!exe_ctx) {
1182 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1183 return SBFrame();
1184 }
1185
1186 if (exe_ctx->HasThreadScope()) {
1187 StackFrameSP frame_sp = exe_ctx->GetThreadPtr()->GetStackFrameAtIndex(idx);
1188 sb_frame.SetFrameSP(frame_sp);
1189 }
1190
1191 return sb_frame;
1192}
1193
1195 LLDB_INSTRUMENT_VA(this);
1196
1197 SBFrameList sb_frame_list;
1198 llvm::Expected<StoppedExecutionContext> exe_ctx =
1200 if (!exe_ctx) {
1201 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1202 return SBFrameList();
1203 }
1204
1205 if (exe_ctx->HasThreadScope()) {
1206 StackFrameListSP frame_list_sp =
1207 exe_ctx->GetThreadPtr()->GetStackFrameList();
1208 sb_frame_list.SetFrameList(frame_list_sp);
1209 }
1210
1211 return sb_frame_list;
1212}
1213
1215 LLDB_INSTRUMENT_VA(this);
1216
1217 SBFrame sb_frame;
1218 llvm::Expected<StoppedExecutionContext> exe_ctx =
1220 if (!exe_ctx) {
1221 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1222 return SBFrame();
1223 }
1224
1225 if (exe_ctx->HasThreadScope()) {
1226 StackFrameSP frame_sp =
1227 exe_ctx->GetThreadPtr()->GetSelectedFrame(SelectMostRelevantFrame);
1228 sb_frame.SetFrameSP(frame_sp);
1229 }
1230
1231 return sb_frame;
1232}
1233
1235 LLDB_INSTRUMENT_VA(this, idx);
1236
1237 SBFrame sb_frame;
1238 StackFrameSP frame_sp;
1239 llvm::Expected<StoppedExecutionContext> exe_ctx =
1241 if (!exe_ctx) {
1242 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1243 return SBFrame();
1244 }
1245
1246 if (exe_ctx->HasThreadScope()) {
1247 Thread *thread = exe_ctx->GetThreadPtr();
1248 frame_sp = thread->GetStackFrameAtIndex(idx);
1249 if (frame_sp) {
1250 thread->SetSelectedFrame(frame_sp.get());
1251 sb_frame.SetFrameSP(frame_sp);
1252 }
1253 }
1254
1255 return sb_frame;
1256}
1257
1259 LLDB_INSTRUMENT_VA(event);
1260
1261 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != nullptr;
1262}
1263
1269
1275
1276bool SBThread::operator==(const SBThread &rhs) const {
1277 LLDB_INSTRUMENT_VA(this, rhs);
1278
1279 return m_opaque_sp->GetThreadSP().get() ==
1280 rhs.m_opaque_sp->GetThreadSP().get();
1281}
1282
1283bool SBThread::operator!=(const SBThread &rhs) const {
1284 LLDB_INSTRUMENT_VA(this, rhs);
1285
1286 return m_opaque_sp->GetThreadSP().get() !=
1287 rhs.m_opaque_sp->GetThreadSP().get();
1288}
1289
1290bool SBThread::GetStatus(SBStream &status) const {
1291 LLDB_INSTRUMENT_VA(this, status);
1292
1293 Stream &strm = status.ref();
1294
1295 llvm::Expected<StoppedExecutionContext> exe_ctx =
1297 if (!exe_ctx) {
1298 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1299 return false;
1300 }
1301
1302 if (exe_ctx->HasThreadScope()) {
1303 exe_ctx->GetThreadPtr()->GetStatus(strm, 0, 1, 1, true,
1304 /*show_hidden=*/true);
1305 } else
1306 strm.PutCString("No status");
1307
1308 return true;
1309}
1310
1311bool SBThread::GetDescription(SBStream &description) const {
1312 LLDB_INSTRUMENT_VA(this, description);
1313
1314 return GetDescription(description, false);
1315}
1316
1317bool SBThread::GetDescription(SBStream &description, bool stop_format) const {
1318 LLDB_INSTRUMENT_VA(this, description, stop_format);
1319
1320 Stream &strm = description.ref();
1321
1322 llvm::Expected<StoppedExecutionContext> exe_ctx =
1324 if (!exe_ctx) {
1325 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1326 return false;
1327 }
1328
1329 if (exe_ctx->HasThreadScope()) {
1330 exe_ctx->GetThreadPtr()->DumpUsingSettingsFormat(
1331 strm, LLDB_INVALID_THREAD_ID, stop_format);
1332 } else
1333 strm.PutCString("No value");
1334
1335 return true;
1336}
1337
1339 SBStream &output) {
1340 Stream &strm = output.ref();
1341
1342 SBError error;
1343 if (!format) {
1344 error = Status::FromErrorString("The provided SBFormat object is invalid");
1345 return error;
1346 }
1347
1348 llvm::Expected<StoppedExecutionContext> exe_ctx =
1350 if (!exe_ctx) {
1351 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1352 return error;
1353 }
1354
1355 if (exe_ctx->HasThreadScope()) {
1356 if (exe_ctx->GetThreadPtr()->DumpUsingFormat(
1357 strm, LLDB_INVALID_THREAD_ID, format.GetFormatEntrySP().get())) {
1358 return error;
1359 }
1360 }
1361
1363 "It was not possible to generate a thread description with the given "
1364 "format string '%s'",
1365 format.GetFormatEntrySP()->string.c_str());
1366 return error;
1367}
1368
1370 LLDB_INSTRUMENT_VA(this, type);
1371
1372 llvm::Expected<StoppedExecutionContext> exe_ctx =
1374 SBThread sb_origin_thread;
1375 if (exe_ctx) {
1376 if (exe_ctx->HasThreadScope()) {
1377 ThreadSP real_thread(exe_ctx->GetThreadSP());
1378 if (real_thread) {
1379 ConstString type_const(type);
1380 Process *process = exe_ctx->GetProcessPtr();
1381 if (process) {
1382 SystemRuntime *runtime = process->GetSystemRuntime();
1383 if (runtime) {
1384 ThreadSP new_thread_sp(
1385 runtime->GetExtendedBacktraceThread(real_thread, type_const));
1386 if (new_thread_sp) {
1387 // Save this in the Process' ExtendedThreadList so a strong
1388 // pointer retains the object.
1389 process->GetExtendedThreadList().AddThread(new_thread_sp);
1390 sb_origin_thread.SetThread(new_thread_sp);
1391 }
1392 }
1393 }
1394 }
1395 }
1396 } else {
1397 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1398 }
1399
1400 return sb_origin_thread;
1401}
1402
1404 LLDB_INSTRUMENT_VA(this);
1405
1406 llvm::Expected<StoppedExecutionContext> exe_ctx =
1408 if (!exe_ctx) {
1409 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1410 return LLDB_INVALID_INDEX32;
1411 }
1412
1413 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1414 if (thread_sp)
1415 return thread_sp->GetExtendedBacktraceOriginatingIndexID();
1416 return LLDB_INVALID_INDEX32;
1417}
1418
1420 LLDB_INSTRUMENT_VA(this);
1421
1422 llvm::Expected<StoppedExecutionContext> exe_ctx =
1424 if (!exe_ctx) {
1425 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1426 return SBValue();
1427 }
1428
1429 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1430 if (!thread_sp)
1431 return SBValue();
1432
1433 return SBValue(thread_sp->GetCurrentException());
1434}
1435
1437 LLDB_INSTRUMENT_VA(this);
1438
1439 llvm::Expected<StoppedExecutionContext> exe_ctx =
1441 if (!exe_ctx) {
1442 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1443 return SBThread();
1444 }
1445
1446 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1447 if (!thread_sp)
1448 return SBThread();
1449
1450 return SBThread(thread_sp->GetCurrentExceptionBacktrace());
1451}
1452
1454 LLDB_INSTRUMENT_VA(this);
1455
1456 llvm::Expected<StoppedExecutionContext> exe_ctx =
1458 if (!exe_ctx) {
1459 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1460 return false;
1461 }
1462
1463 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1464 if (thread_sp)
1465 return thread_sp->SafeToCallFunctions();
1466 return true;
1467}
1468
1469lldb::ThreadSP SBThread::GetSP() const { return m_opaque_sp->GetThreadSP(); }
1470
1474
1476 return m_opaque_sp->GetThreadSP().get();
1477}
1478
1480 LLDB_INSTRUMENT_VA(this);
1481
1482 llvm::Expected<StoppedExecutionContext> exe_ctx =
1484 if (!exe_ctx) {
1485 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1486 return SBValue();
1487 }
1488
1489 ThreadSP thread_sp = m_opaque_sp->GetThreadSP();
1490 if (!thread_sp)
1491 return SBValue();
1492 return thread_sp->GetSiginfoValue();
1493}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
static Status ResumeNewPlan(StoppedExecutionContext exe_ctx, ThreadPlan *new_plan)
Definition SBThread.cpp:468
static ThreadPlanReturnValue GetStopReturnValueImpl(const lldb::ExecutionContextRefSP &exe_ctx_ref_sp)
Get what the function the thread stepped out of returned or threw.
Definition SBThread.cpp:298
bool Success() const
Definition SBError.cpp:81
void SetError(uint32_t err, lldb::ErrorType type)
Definition SBError.cpp:124
lldb_private::Event * get() const
Definition SBEvent.cpp:136
bool IsValid() const
const lldb_private::FileSpec & ref() const
Class that represents a format string that can be used to generate descriptions of objects like frame...
Definition SBFormat.h:28
lldb::FormatEntrySP GetFormatEntrySP() const
Definition SBFormat.cpp:44
Represents a list of SBFrame objects.
Definition SBFrameList.h:31
void SetFrameList(const lldb::StackFrameListSP &frame_list_sp)
bool IsValid() const
Definition SBFrame.cpp:96
void SetFrameSP(const lldb::StackFrameSP &lldb_object_sp)
Definition SBFrame.cpp:92
lldb::SBThread GetThread() const
Definition SBFrame.cpp:661
lldb::StackFrameSP GetFrameSP() const
Definition SBFrame.cpp:88
void SetSP(const lldb::ProcessSP &process_sp)
void SetQueue(const lldb::QueueSP &queue_sp)
Definition SBQueue.cpp:260
lldb_private::Stream & ref()
Definition SBStream.cpp:179
StructuredDataImplUP m_impl_up
static const char * GetBroadcasterClassName()
Definition SBThread.cpp:55
void StepInto(lldb::RunMode stop_other_threads=lldb::eOnlyDuringStepping)
Definition SBThread.cpp:557
bool Suspend()
LLDB currently supports process centric debugging which means when any thread in a process stops,...
const char * GetName() const
Definition SBThread.cpp:368
bool GetStopDescription(lldb::SBStream &stream) const
Gets a human-readable description of why the thread stopped.
Definition SBThread.cpp:245
const lldb::SBThread & operator=(const lldb::SBThread &rhs)
Definition SBThread.cpp:80
lldb::SBFrame SetSelectedFrame(uint32_t frame_idx)
SBError UnwindInnermostExpression()
friend class SBThreadCollection
Definition SBThread.h:264
bool IsValid() const
Definition SBThread.cpp:113
uint32_t GetNumFrames()
friend class SBProcess
Definition SBThread.h:259
const char * GetQueueName() const
Definition SBThread.cpp:385
SBValue GetSiginfo()
uint32_t GetIndexID() const
Definition SBThread.cpp:352
bool GetDescription(lldb::SBStream &description) const
static bool EventIsThreadEvent(const SBEvent &event)
lldb_private::Thread * operator->()
lldb_private::Thread * get()
void StepOutOfFrame(SBFrame &frame)
Definition SBThread.cpp:711
bool GetStatus(lldb::SBStream &status) const
friend class SBValue
Definition SBThread.h:261
static SBFrame GetStackFrameFromEvent(const SBEvent &event)
lldb::queue_id_t GetQueueID() const
Definition SBThread.cpp:402
lldb::SBFrameList GetFrames() const
bool GetInfoItemByPathAsString(const char *path, SBStream &strm)
Definition SBThread.cpp:420
lldb::SBFrame GetSelectedFrame()
friend class SBFrameList
Definition SBThread.h:258
bool operator!=(const lldb::SBThread &rhs) const
SBError StepUsingScriptedThreadPlan(const char *script_class_name)
Definition SBThread.cpp:934
lldb::tid_t GetThreadID() const
Definition SBThread.cpp:336
lldb::SBFrame GetFrameAtIndex(uint32_t idx)
uint32_t GetExtendedBacktraceOriginatingIndexID()
lldb::SBQueue GetQueue() const
Definition SBThread.cpp:91
bool SafeToCallFunctions()
lldb::SBProcess GetProcess()
size_t GetStopReasonDataCount()
Get the number of words associated with the stop reason.
Definition SBThread.cpp:155
void StepInstruction(bool step_over)
Definition SBThread.cpp:759
SBThread GetCurrentExceptionBacktrace()
friend class SBFrame
Definition SBThread.h:257
static SBThread GetThreadFromEvent(const SBEvent &event)
bool GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream)
Definition SBThread.cpp:192
lldb::StopReason GetStopReason()
Definition SBThread.cpp:138
SBValue GetStopReturnValue()
Get the value the function returned, if the thread stopped because it stepped out of a function.
Definition SBThread.cpp:314
void StepOver(lldb::RunMode stop_other_threads=lldb::eOnlyDuringStepping)
Definition SBThread.cpp:493
SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line)
Definition SBThread.cpp:994
SBError GetDescriptionWithFormat(const SBFormat &format, SBStream &output)
Similar to GetDescription() but the format of the description can be configured via the format parame...
SBThreadCollection GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type)
Definition SBThread.cpp:218
SBValue GetCurrentException()
void SetThread(const lldb::ThreadSP &lldb_object_sp)
Definition SBThread.cpp:332
lldb::ThreadSP GetSP() const
SBThread GetExtendedBacktraceThread(const char *type)
lldb::ExecutionContextRefSP m_opaque_sp
Definition SBThread.h:277
void RunToAddress(lldb::addr_t addr)
Definition SBThread.cpp:811
SBValue GetStopErrorValue()
Get the error the function threw, if the thread stopped because it stepped out of a function that thr...
Definition SBThread.cpp:323
uint64_t GetStopReasonDataAtIndex(uint32_t idx)
Get information associated with a stop reason.
Definition SBThread.cpp:173
SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value)
bool operator==(const lldb::SBThread &rhs) const
SBError StepOverUntil(lldb::SBFrame &frame, lldb::SBFileSpec &file_spec, uint32_t line)
Definition SBThread.cpp:850
lldb::ValueObjectSP GetSP() const
Same as the protected version of GetSP that takes a locker, except that we make the locker locally in...
Definition SBValue.cpp:1084
A section + offset based address range class.
A section + offset based address class.
Definition Address.h:62
A uniqued constant string class.
Definition ConstString.h:40
Execution context objects refer to objects in the execution of the program that is being debugged.
Process * GetProcessPtr() const
Returns a pointer to the process object.
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
A file utility class.
Definition FileSpec.h:56
A plug-in interface definition class for debugging a process.
Definition Process.h:370
ThreadList & GetThreadList()
Definition Process.h:2398
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition Process.cpp:1379
virtual SystemRuntime * GetSystemRuntime()
Get the system runtime plug-in for this process.
Definition Process.cpp:3267
ThreadList & GetExtendedThreadList()
Definition Process.h:2409
Status ResumeSynchronous(Stream *stream)
Resume a process, and wait for it to stop.
Definition Process.cpp:1396
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1271
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
bool Fail() const
Test for error condition.
Definition Status.cpp:293
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition Status.cpp:194
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 ThreadPlanReturnValue GetReturnValue(lldb::StopInfoSP &stop_info_sp)
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
const char * InternNonEmpty(llvm::StringRef str) const
Like Intern, but an empty string yields nullptr.
Definition StringPool.h:81
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
llvm::Error GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range)
CompileUnit * comp_unit
The CompileUnit for a given query.
LineEntry line_entry
The LineEntry for a given query.
A plug-in interface definition class for system runtimes.
virtual lldb::ThreadSP GetExtendedBacktraceThread(lldb::ThreadSP thread, ConstString type)
Return a Thread which shows the origin of this thread's creation.
A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public...
Debugger & GetDebugger() const
Definition Target.h:1378
void AddThread(const lldb::ThreadSP &thread_sp)
bool SetSelectedThreadByID(lldb::tid_t tid, bool notify=false)
void SetOkayToDiscard(bool value)
Definition ThreadPlan.h:431
bool SetIsControllingPlan(bool value)
Definition ThreadPlan.h:423
static const ThreadEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Thread.cpp:179
static lldb::ThreadSP GetThreadFromEvent(const Event *event_ptr)
Definition Thread.cpp:189
static lldb::StackFrameSP GetStackFrameFromEvent(const Event *event_ptr)
Definition Thread.cpp:206
static llvm::StringRef GetStaticBroadcasterClass()
Definition Thread.cpp:221
#define LLDB_INVALID_QUEUE_ID
#define LLDB_INVALID_LINE_NUMBER
#define LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_INDEX32
@ DoNoSelectMostRelevantFrame
@ SelectMostRelevantFrame
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:338
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
llvm::Expected< std::vector< lldb::addr_t > > GetStepUntilAddresses(StackFrame &frame, const FileSpec &file, llvm::ArrayRef< uint32_t > lines, llvm::ArrayRef< lldb::addr_t > requested_addresses)
Returns the load addresses of the line table entries for lines in file, and of addresses,...
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition Utils.h:25
std::variant< std::monostate, ReturnedValue, ThrownError > ThreadPlanReturnValue
What a completed thread plan computed for the function it stepped out of or called: nothing,...
Definition Thread.h:82
StringPoolRef GetDebuggerStringPool(const Target &target)
Strings interned here live as long as target's debugger.
Definition Utils.h:21
llvm::Expected< StoppedExecutionContext > GetStoppedExecutionContext(const ExecutionContextRef *exe_ctx_ref_ptr)
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::Queue > QueueSP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::Thread > ThreadSP
@ 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.
std::shared_ptr< lldb_private::Process > ProcessSP
InstrumentationRuntimeType
@ eStepTypeInto
Single step into a specified context.
@ eStepTypeTraceOver
Single step one instruction, stepping over.
@ eStepTypeTrace
Single step one instruction.
@ eStepTypeOut
Single step out a specified context.
@ eStepTypeOver
Single step over a specified context.
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
uint64_t addr_t
Definition lldb-types.h:80
StopReason
Thread stop reasons.
@ eStructuredDataTypeFloat
@ eStructuredDataTypeDictionary
@ eStructuredDataTypeInteger
@ eStructuredDataTypeNull
@ eStructuredDataTypeBoolean
@ eStructuredDataTypeString
class LLDB_API SBQueue
Definition SBDefines.h:104
RunMode
Thread Run Modes.
uint64_t tid_t
Definition lldb-types.h:85
uint64_t queue_id_t
Definition lldb-types.h:92
std::shared_ptr< lldb_private::StackFrameList > StackFrameListSP
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP
bool IsValid() const
Check if a line entry object is valid.
Definition LineEntry.cpp:35
AddressRange range
The section offset address range for this line entry.
Definition LineEntry.h:137
const FileSpec & GetFile() const
Helper to access the file.
Definition LineEntry.h:134
A wrapper class representing an execution context with non-null Target and Process pointers,...
TargetAPIMutex AllowResume()
Clears this context, unlocking the ProcessRunLock and returning the locked API lock,...