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"
48
49#include <memory>
50
51using namespace lldb;
52using namespace lldb_private;
53
59
60// Constructors
64
65SBThread::SBThread(const ThreadSP &lldb_object_sp)
66 : m_opaque_sp(new ExecutionContextRef(lldb_object_sp)) {
67 LLDB_INSTRUMENT_VA(this, lldb_object_sp);
68}
69
71 LLDB_INSTRUMENT_VA(this, rhs);
72
74}
75
76// Assignment operator
77
79 LLDB_INSTRUMENT_VA(this, rhs);
80
81 if (this != &rhs)
83 return *this;
84}
85
86// Destructor
87SBThread::~SBThread() = default;
88
91
92 SBQueue sb_queue;
93 QueueSP queue_sp;
94 llvm::Expected<StoppedExecutionContext> exe_ctx =
96 if (!exe_ctx) {
97 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
98 return SBQueue();
99 }
100
101 if (exe_ctx->HasThreadScope()) {
102 queue_sp = exe_ctx->GetThreadPtr()->GetQueue();
103 if (queue_sp) {
104 sb_queue.SetQueue(queue_sp);
105 }
106 }
107
108 return sb_queue;
109}
110
111bool SBThread::IsValid() const {
112 LLDB_INSTRUMENT_VA(this);
113 return this->operator bool();
114}
115SBThread::operator bool() const {
116 LLDB_INSTRUMENT_VA(this);
117 if (!m_opaque_sp)
118 return false;
119
120 llvm::Expected<StoppedExecutionContext> exe_ctx =
122 if (!exe_ctx) {
123 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
124 return false;
125 }
126
127 return m_opaque_sp->GetThreadSP().get() != nullptr;
128}
129
131 LLDB_INSTRUMENT_VA(this);
132
133 m_opaque_sp->Clear();
134}
135
137 LLDB_INSTRUMENT_VA(this);
138
140 llvm::Expected<StoppedExecutionContext> exe_ctx =
142 if (!exe_ctx) {
143 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
144 return reason;
145 }
146
147 if (exe_ctx->HasThreadScope())
148 return exe_ctx->GetThreadPtr()->GetStopReason();
149
150 return reason;
151}
152
154 LLDB_INSTRUMENT_VA(this);
155
156 llvm::Expected<StoppedExecutionContext> exe_ctx =
158 if (exe_ctx) {
159 if (exe_ctx->HasThreadScope()) {
160 StopInfoSP stop_info_sp = exe_ctx->GetThreadPtr()->GetStopInfo();
161 if (stop_info_sp)
162 return stop_info_sp->GetStopReasonDataCount();
163 }
164 } else {
165 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
166 return 0;
167 }
168 return 0;
169}
170
172 LLDB_INSTRUMENT_VA(this, idx);
173
174 llvm::Expected<StoppedExecutionContext> exe_ctx =
176 if (exe_ctx) {
177 if (exe_ctx->HasThreadScope()) {
178 Thread *thread = exe_ctx->GetThreadPtr();
179 StopInfoSP stop_info_sp = thread->GetStopInfo();
180 if (stop_info_sp)
181 return stop_info_sp->GetStopReasonDataAtIndex(idx);
182 }
183 } else {
184 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
185 return 0;
186 }
187 return 0;
188}
189
191 LLDB_INSTRUMENT_VA(this, stream);
192
193 Stream &strm = stream.ref();
194
195 llvm::Expected<StoppedExecutionContext> exe_ctx =
197 if (!exe_ctx) {
198 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
199 return false;
200 }
201
202 if (!exe_ctx->HasThreadScope())
203 return false;
204
205 StopInfoSP stop_info = exe_ctx->GetThreadPtr()->GetStopInfo();
206 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
207 if (!info)
208 return false;
209
210 info->Dump(strm);
211
212 return true;
213}
214
217 LLDB_INSTRUMENT_VA(this, type);
218
219 SBThreadCollection threads;
220
221 llvm::Expected<StoppedExecutionContext> exe_ctx =
223 if (!exe_ctx) {
224 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
225 return SBThreadCollection();
226 }
227
228 if (!exe_ctx->HasThreadScope())
229 return SBThreadCollection();
230
231 ProcessSP process_sp = exe_ctx->GetProcessSP();
232
233 StopInfoSP stop_info = exe_ctx->GetThreadPtr()->GetStopInfo();
234 StructuredData::ObjectSP info = stop_info->GetExtendedInfo();
235 if (!info)
236 return threads;
237
238 threads = process_sp->GetInstrumentationRuntime(type)
239 ->GetBacktracesFromExtendedStopInfo(info);
240 return threads;
241}
242
244 LLDB_INSTRUMENT_VA(this, stream);
245
246 if (!m_opaque_sp)
247 return false;
248
249 llvm::Expected<StoppedExecutionContext> exe_ctx =
251 if (!exe_ctx) {
252 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
253 return false;
254 }
255
256 if (!exe_ctx->HasThreadScope())
257 return false;
258
259 Stream &strm = stream.ref();
260 const std::string stop_desc = exe_ctx->GetThreadPtr()->GetStopDescription();
261 strm.PutCString(stop_desc);
262
263 return true;
264}
265
266size_t SBThread::GetStopDescription(char *dst_or_null, size_t dst_len) {
267 LLDB_INSTRUMENT_VA(this, dst_or_null, dst_len);
268
269 if (dst_or_null)
270 *dst_or_null = 0;
271
272 llvm::Expected<StoppedExecutionContext> exe_ctx =
274 if (!exe_ctx) {
275 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
276 return 0;
277 }
278
279 if (!exe_ctx->HasThreadScope())
280 return 0;
281
282 std::string thread_stop_desc = exe_ctx->GetThreadPtr()->GetStopDescription();
283 if (thread_stop_desc.empty())
284 return 0;
285
286 if (dst_or_null)
287 return ::snprintf(dst_or_null, dst_len, "%s", thread_stop_desc.c_str()) + 1;
288
289 // NULL dst passed in, return the length needed to contain the
290 // description.
291 return thread_stop_desc.size() + 1; // Include the NULL byte for size
292}
293
295 LLDB_INSTRUMENT_VA(this);
296
297 ValueObjectSP return_valobj_sp;
298 llvm::Expected<StoppedExecutionContext> exe_ctx =
300 if (!exe_ctx) {
301 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
302 return SBValue();
303 }
304
305 if (exe_ctx->HasThreadScope()) {
306 StopInfoSP stop_info_sp = exe_ctx->GetThreadPtr()->GetStopInfo();
307 if (stop_info_sp) {
308 return_valobj_sp = StopInfo::GetReturnValueObject(stop_info_sp);
309 }
310 }
311
312 return SBValue(return_valobj_sp);
313}
314
315void SBThread::SetThread(const ThreadSP &lldb_object_sp) {
316 m_opaque_sp->SetThreadSP(lldb_object_sp);
317}
318
320 LLDB_INSTRUMENT_VA(this);
321
322 llvm::Expected<StoppedExecutionContext> exe_ctx =
324 if (!exe_ctx) {
325 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
327 }
328
329 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
330 if (thread_sp)
331 return thread_sp->GetID();
333}
334
335uint32_t SBThread::GetIndexID() const {
336 LLDB_INSTRUMENT_VA(this);
337
338 llvm::Expected<StoppedExecutionContext> exe_ctx =
340 if (!exe_ctx) {
341 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
343 }
344
345 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
346 if (thread_sp)
347 return thread_sp->GetIndexID();
349}
350
351const char *SBThread::GetName() const {
352 LLDB_INSTRUMENT_VA(this);
353
354 llvm::Expected<StoppedExecutionContext> exe_ctx =
356 if (!exe_ctx) {
357 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
358 return nullptr;
359 }
360
361 if (!exe_ctx->HasThreadScope())
362 return nullptr;
363
364 return ConstString(exe_ctx->GetThreadPtr()->GetName()).GetCString();
365}
366
367const char *SBThread::GetQueueName() const {
368 LLDB_INSTRUMENT_VA(this);
369
370 llvm::Expected<StoppedExecutionContext> exe_ctx =
372 if (!exe_ctx) {
373 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
374 return nullptr;
375 }
376
377 if (!exe_ctx->HasThreadScope())
378 return nullptr;
379
380 return ConstString(exe_ctx->GetThreadPtr()->GetQueueName()).GetCString();
381}
382
384 LLDB_INSTRUMENT_VA(this);
385
387 llvm::Expected<StoppedExecutionContext> exe_ctx =
389 if (!exe_ctx) {
390 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
391 return id;
392 }
393
394 if (exe_ctx->HasThreadScope()) {
395 id = exe_ctx->GetThreadPtr()->GetQueueID();
396 }
397
398 return id;
399}
400
401bool SBThread::GetInfoItemByPathAsString(const char *path, SBStream &strm) {
402 LLDB_INSTRUMENT_VA(this, path, strm);
403
404 bool success = false;
405 llvm::Expected<StoppedExecutionContext> exe_ctx =
407 if (exe_ctx) {
408 if (exe_ctx->HasThreadScope()) {
409 Thread *thread = exe_ctx->GetThreadPtr();
410 StructuredData::ObjectSP info_root_sp = thread->GetExtendedInfo();
411 if (info_root_sp) {
413 info_root_sp->GetObjectForDotSeparatedPath(path);
414 if (node) {
415 if (node->GetType() == eStructuredDataTypeString) {
416 strm.ref() << node->GetAsString()->GetValue();
417 success = true;
418 }
419 if (node->GetType() == eStructuredDataTypeInteger) {
420 strm.Printf("0x%" PRIx64, node->GetUnsignedIntegerValue());
421 success = true;
422 }
423 if (node->GetType() == eStructuredDataTypeFloat) {
424 strm.Printf("0x%f", node->GetAsFloat()->GetValue());
425 success = true;
426 }
427 if (node->GetType() == eStructuredDataTypeBoolean) {
428 if (node->GetAsBoolean()->GetValue())
429 strm.Printf("true");
430 else
431 strm.Printf("false");
432 success = true;
433 }
434 if (node->GetType() == eStructuredDataTypeNull) {
435 strm.Printf("null");
436 success = true;
437 }
438 }
439 }
440 }
441 } else {
442 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
443 return success;
444 }
445
446 return success;
447}
448
450 ThreadPlan *new_plan) {
451 Thread *thread = exe_ctx.GetThreadPtr();
452 if (!thread)
453 return Status::FromErrorString("No thread in SBThread::ResumeNewPlan");
454
455 // User level plans should be Controlling Plans so they can be interrupted,
456 // other plans executed, and then a "continue" will resume the plan.
457 if (new_plan != nullptr) {
458 new_plan->SetIsControllingPlan(true);
459 new_plan->SetOkayToDiscard(false);
460 }
461
462 // Why do we need to set the current thread by ID here???
463 Process *process = exe_ctx.GetProcessPtr();
464 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
465
466 // Release the run lock but keep the API lock.
467 TargetAPIMutex api_mutex = exe_ctx.AllowResume();
468 std::unique_lock<TargetAPIMutex> guard(api_mutex, std::adopt_lock);
469 if (process->GetTarget().GetDebugger().GetAsyncExecution())
470 return process->Resume();
471 return process->ResumeSynchronous(nullptr);
472}
473
474void SBThread::StepOver(lldb::RunMode stop_other_threads) {
475 LLDB_INSTRUMENT_VA(this, stop_other_threads);
476
477 SBError error; // Ignored
478 StepOver(stop_other_threads, error);
479}
480
481void SBThread::StepOver(lldb::RunMode stop_other_threads, SBError &error) {
482 LLDB_INSTRUMENT_VA(this, stop_other_threads, error);
483
484 llvm::Expected<StoppedExecutionContext> exe_ctx =
486 if (!exe_ctx) {
487 error = Status::FromError(exe_ctx.takeError());
488 return;
489 }
490
491 if (!exe_ctx->HasThreadScope()) {
492 error = Status::FromErrorString("this SBThread object is invalid");
493 return;
494 }
495
496 Thread *thread = exe_ctx->GetThreadPtr();
497 bool abort_other_plans = false;
498 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
499 if (!frame_sp) {
500 error.SetErrorString("No frame to step over");
501 return;
502 }
503
504 ThreadPlanSP new_plan_sp;
505 lldb::StepType step_type =
506 frame_sp->HasDebugInformation() || frame_sp->IsSynthetic()
509
510 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
511 frame_sp->GetThreadPlanForStepType(step_type);
512 if (auto llvm_err = frame_plan_result.takeError()) {
513 error.SetErrorStringWithFormat("scripted frame provider got an error "
514 "while constructing step plan: \"%s\"",
515 llvm::toString(std::move(llvm_err)).c_str());
516 return;
517 }
518 new_plan_sp = *frame_plan_result;
519
520 if (new_plan_sp) {
521 thread->QueueThreadPlan(new_plan_sp, false);
522 } else {
523 Status new_plan_status;
524 if (step_type == eStepTypeOver) {
525 const LazyBool avoid_no_debug = eLazyBoolCalculate;
526 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
527 new_plan_sp = thread->QueueThreadPlanForStepOverRange(
528 abort_other_plans, sc.line_entry, sc, stop_other_threads,
529 new_plan_status, avoid_no_debug);
530 } else {
531 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
532 true, abort_other_plans, stop_other_threads, new_plan_status);
533 }
534 }
535 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
536}
537
538void SBThread::StepInto(lldb::RunMode stop_other_threads) {
539 LLDB_INSTRUMENT_VA(this, stop_other_threads);
540
541 StepInto(nullptr, stop_other_threads);
542}
543
544void SBThread::StepInto(const char *target_name,
545 lldb::RunMode stop_other_threads) {
546 LLDB_INSTRUMENT_VA(this, target_name, stop_other_threads);
547
548 SBError error; // Ignored
549 StepInto(target_name, LLDB_INVALID_LINE_NUMBER, error, stop_other_threads);
550}
551
552void SBThread::StepInto(const char *target_name, uint32_t end_line,
553 SBError &error, lldb::RunMode stop_other_threads) {
554 LLDB_INSTRUMENT_VA(this, target_name, end_line, error, stop_other_threads);
555
556 llvm::Expected<StoppedExecutionContext> exe_ctx =
558 if (!exe_ctx) {
559 error = Status::FromError(exe_ctx.takeError());
560 return;
561 }
562
563 if (!exe_ctx->HasThreadScope()) {
564 error = Status::FromErrorString("this SBThread object is invalid");
565 return;
566 }
567
568 bool abort_other_plans = false;
569
570 Thread *thread = exe_ctx->GetThreadPtr();
571 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
572 ThreadPlanSP new_plan_sp;
573 Status new_plan_status;
574 lldb::StepType step_type;
575
576 if (frame_sp && (frame_sp->HasDebugInformation() || frame_sp->IsSynthetic()))
577 step_type = eStepTypeInto;
578 else
579 step_type = eStepTypeTrace;
580
581 // First see if the Frame has some special way to do this step:
582 if (frame_sp) {
583 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
584 frame_sp->GetThreadPlanForStepType(step_type);
585 if (auto llvm_err = frame_plan_result.takeError()) {
586 error.SetErrorStringWithFormat(
587 "scripted frame provider got an error "
588 "while constructing step plan: \"%s\"",
589 llvm::toString(std::move(llvm_err)).c_str());
590 return;
591 }
592 new_plan_sp = *frame_plan_result;
593 }
594
595 if (new_plan_sp) {
596 thread->QueueThreadPlan(new_plan_sp, false);
597 } else {
598 if (step_type == eStepTypeInto) {
599 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
600 AddressRange range;
601 if (end_line == LLDB_INVALID_LINE_NUMBER)
602 range = sc.line_entry.range;
603 else {
604 llvm::Error err = sc.GetAddressRangeFromHereToEndLine(end_line, range);
605 if (err) {
606 error =
607 Status::FromErrorString(llvm::toString(std::move(err)).c_str());
608 return;
609 }
610 }
611
612 const LazyBool step_out_avoids_code_without_debug_info =
614 const LazyBool step_in_avoids_code_without_debug_info =
616 new_plan_sp = thread->QueueThreadPlanForStepInRange(
617 abort_other_plans, range, sc, target_name, stop_other_threads,
618 new_plan_status, step_in_avoids_code_without_debug_info,
619 step_out_avoids_code_without_debug_info);
620 } else {
621 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
622 false, abort_other_plans, stop_other_threads, new_plan_status);
623 }
624 }
625
626 if (new_plan_status.Success())
627 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
628 else
629 error = Status::FromErrorString(new_plan_status.AsCString());
630}
631
633 LLDB_INSTRUMENT_VA(this);
634
635 SBError error; // Ignored
636 StepOut(error);
637}
638
641
642 llvm::Expected<StoppedExecutionContext> exe_ctx =
644 if (!exe_ctx) {
645 error = Status::FromError(exe_ctx.takeError());
646 return;
647 }
648
649 if (!exe_ctx->HasThreadScope()) {
650 error = Status::FromErrorString("this SBThread object is invalid");
651 return;
652 }
653
654 bool abort_other_plans = false;
655 bool stop_other_threads = false;
656
657 ThreadPlanSP new_plan_sp;
658
659 Thread *thread = exe_ctx->GetThreadPtr();
660 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
661 if (frame_sp) {
662 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
663 frame_sp->GetThreadPlanForStepType(eStepTypeOut);
664 if (auto llvm_err = frame_plan_result.takeError()) {
665 error.SetErrorStringWithFormat(
666 "scripted frame provider got an error "
667 "while constructing step plan: \"%s\"",
668 llvm::toString(std::move(llvm_err)).c_str());
669 return;
670 }
671 new_plan_sp = *frame_plan_result;
672 }
673
674 Status new_plan_status;
675 if (new_plan_sp) {
676 // FIXME: Carry over stop_other_threads, and avoid_no_debug to
677 // the new plan?
678 thread->QueueThreadPlan(new_plan_sp, false);
679 } else {
680 const LazyBool avoid_no_debug = eLazyBoolCalculate;
681 new_plan_sp = thread->QueueThreadPlanForStepOut(
682 abort_other_plans, nullptr, false, stop_other_threads, eVoteYes,
683 eVoteNoOpinion, 0, new_plan_status, avoid_no_debug);
684 }
685
686 if (new_plan_status.Success())
687 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
688 else
689 error = Status::FromErrorString(new_plan_status.AsCString());
690}
691
693 LLDB_INSTRUMENT_VA(this, sb_frame);
694
695 SBError error; // Ignored
696 StepOutOfFrame(sb_frame, error);
697}
698
700 LLDB_INSTRUMENT_VA(this, sb_frame, error);
701
702 llvm::Expected<StoppedExecutionContext> exe_ctx =
704 if (!exe_ctx) {
705 error = Status::FromError(exe_ctx.takeError());
706 return;
707 }
708
709 if (!sb_frame.IsValid()) {
710 error = Status::FromErrorString("passed invalid SBFrame object");
711 return;
712 }
713
714 StackFrameSP frame_sp(sb_frame.GetFrameSP());
715
716 if (!exe_ctx->HasThreadScope()) {
717 error = Status::FromErrorString("this SBThread object is invalid");
718 return;
719 }
720
721 bool abort_other_plans = false;
722 bool stop_other_threads = false;
723 Thread *thread = exe_ctx->GetThreadPtr();
724 if (sb_frame.GetThread().GetThreadID() != thread->GetID()) {
725 error = Status::FromErrorString("passed a frame from another thread");
726 return;
727 }
728
729 Status new_plan_status;
730 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForStepOut(
731 abort_other_plans, nullptr, false, stop_other_threads, eVoteYes,
732 eVoteNoOpinion, frame_sp->GetFrameIndex(), new_plan_status));
733
734 if (new_plan_status.Success())
735 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
736 else
737 error = Status::FromErrorString(new_plan_status.AsCString());
738}
739
740void SBThread::StepInstruction(bool step_over) {
741 LLDB_INSTRUMENT_VA(this, step_over);
742
743 SBError error; // Ignored
744 StepInstruction(step_over, error);
745}
746
748 LLDB_INSTRUMENT_VA(this, step_over, error);
749
750 llvm::Expected<StoppedExecutionContext> exe_ctx =
752 if (!exe_ctx) {
753 error = Status::FromError(exe_ctx.takeError());
754 return;
755 }
756
757 if (!exe_ctx->HasThreadScope()) {
758 error = Status::FromErrorString("this SBThread object is invalid");
759 return;
760 }
761
762 Thread *thread = exe_ctx->GetThreadPtr();
763 StackFrameSP frame_sp(thread->GetStackFrameAtIndex(0));
764 lldb::StepType step_type = step_over ? eStepTypeTraceOver : eStepTypeTrace;
765
766 ThreadPlanSP new_plan_sp;
767
768 if (frame_sp) {
769 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
770 frame_sp->GetThreadPlanForStepType(step_type);
771 if (auto llvm_err = frame_plan_result.takeError()) {
772 error.SetErrorStringWithFormat(
773 "scripted frame provider got an error "
774 "while constructing step plan: \"%s\"",
775 llvm::toString(std::move(llvm_err)).c_str());
776 return;
777 }
778 new_plan_sp = *frame_plan_result;
779 }
780
781 Status new_plan_status;
782 if (!new_plan_sp)
783 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
784 step_over, false, true, new_plan_status);
785
786 if (new_plan_status.Success())
787 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
788 else
789 error = Status::FromErrorString(new_plan_status.AsCString());
790}
791
793 LLDB_INSTRUMENT_VA(this, addr);
794
795 SBError error; // Ignored
796 RunToAddress(addr, error);
797}
798
800 LLDB_INSTRUMENT_VA(this, addr, error);
801
802 llvm::Expected<StoppedExecutionContext> exe_ctx =
804 if (!exe_ctx) {
805 error = Status::FromError(exe_ctx.takeError());
806 return;
807 }
808
809 if (!exe_ctx->HasThreadScope()) {
810 error = Status::FromErrorString("this SBThread object is invalid");
811 return;
812 }
813
814 bool abort_other_plans = false;
815 bool stop_other_threads = true;
816
817 Address target_addr(addr);
818
819 Thread *thread = exe_ctx->GetThreadPtr();
820
821 Status new_plan_status;
822 ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress(
823 abort_other_plans, target_addr, stop_other_threads, new_plan_status));
824
825 if (new_plan_status.Success())
826 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
827 else
828 error = Status::FromErrorString(new_plan_status.AsCString());
829}
830
832 lldb::SBFileSpec &sb_file_spec, uint32_t line) {
833 LLDB_INSTRUMENT_VA(this, sb_frame, sb_file_spec, line);
834
835 SBError sb_error;
836 char path[PATH_MAX];
837
838 llvm::Expected<StoppedExecutionContext> exe_ctx =
840 if (!exe_ctx)
841 return Status::FromError(exe_ctx.takeError());
842
843 StackFrameSP frame_sp(sb_frame.GetFrameSP());
844
845 if (exe_ctx->HasThreadScope()) {
846 Target *target = exe_ctx->GetTargetPtr();
847 Thread *thread = exe_ctx->GetThreadPtr();
848
849 if (line == 0) {
850 sb_error = Status::FromErrorString("invalid line argument");
851 return sb_error;
852 }
853
854 if (!frame_sp) {
855 // We don't want to run SelectMostRelevantFrame here, for instance if
856 // you called a sequence of StepOverUntil's you wouldn't want the
857 // frame changed out from under you because you stepped into a
858 // recognized frame.
859 frame_sp = thread->GetSelectedFrame(DoNoSelectMostRelevantFrame);
860 if (!frame_sp)
861 frame_sp = thread->GetStackFrameAtIndex(0);
862 }
863
864 SymbolContext frame_sc;
865 if (!frame_sp) {
866 sb_error = Status::FromErrorString("no valid frames in thread to step");
867 return sb_error;
868 }
869
870 // If we have a frame, get its line
871 frame_sc = frame_sp->GetSymbolContext(
872 eSymbolContextCompUnit | eSymbolContextFunction |
873 eSymbolContextLineEntry | eSymbolContextSymbol);
874
875 if (frame_sc.comp_unit == nullptr) {
877 "frame %u doesn't have debug information", frame_sp->GetFrameIndex());
878 return sb_error;
879 }
880
881 FileSpec step_file_spec;
882 if (sb_file_spec.IsValid()) {
883 // The file spec passed in was valid, so use it
884 step_file_spec = sb_file_spec.ref();
885 } else {
886 if (frame_sc.line_entry.IsValid())
887 step_file_spec = frame_sc.line_entry.GetFile();
888 else {
889 sb_error = Status::FromErrorString(
890 "invalid file argument or no file for frame");
891 return sb_error;
892 }
893 }
894
895 // Grab the current function, then we will make sure the "until" address is
896 // within the function. We discard addresses that are out of the current
897 // function, and then if there are no addresses remaining, give an
898 // appropriate error message.
899
900 bool all_in_function = true;
901
902 std::vector<addr_t> step_over_until_addrs;
903 const bool abort_other_plans = false;
904 const bool stop_other_threads = false;
905 // TODO: Handle SourceLocationSpec column information
906 SourceLocationSpec location_spec(
907 step_file_spec, line, /*column=*/std::nullopt, /*check_inlines=*/true,
908 /*exact_match=*/false);
909
910 SymbolContextList sc_list;
911 frame_sc.comp_unit->ResolveSymbolContext(location_spec,
912 eSymbolContextLineEntry, sc_list);
913 for (const SymbolContext &sc : sc_list) {
914 addr_t step_addr =
915 sc.line_entry.range.GetBaseAddress().GetLoadAddress(target);
916 if (step_addr != LLDB_INVALID_ADDRESS) {
917 AddressRange unused_range;
918 if (frame_sc.function->GetRangeContainingLoadAddress(step_addr, *target,
919 unused_range))
920 step_over_until_addrs.push_back(step_addr);
921 else
922 all_in_function = false;
923 }
924 }
925
926 if (step_over_until_addrs.empty()) {
927 if (all_in_function) {
928 step_file_spec.GetPath(path, sizeof(path));
930 "No line entries for %s:%u", path, line);
931 } else
932 sb_error = Status::FromErrorString(
933 "step until target not in current function");
934 } else {
935 Status new_plan_status;
936 ThreadPlanSP new_plan_sp = thread->QueueThreadPlanForStepUntil(
937 abort_other_plans, step_over_until_addrs, stop_other_threads,
938 frame_sp->GetFrameIndex(), new_plan_status);
939
940 if (new_plan_status.Success())
941 sb_error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
942 else
943 sb_error = Status::FromErrorString(new_plan_status.AsCString());
944 }
945 } else {
946 sb_error = Status::FromErrorString("this SBThread object is invalid");
947 }
948 return sb_error;
949}
950
951SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name) {
952 LLDB_INSTRUMENT_VA(this, script_class_name);
953
954 return StepUsingScriptedThreadPlan(script_class_name, true);
955}
956
957SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name,
958 bool resume_immediately) {
959 LLDB_INSTRUMENT_VA(this, script_class_name, resume_immediately);
960
962 return StepUsingScriptedThreadPlan(script_class_name, no_data,
963 resume_immediately);
964}
965
966SBError SBThread::StepUsingScriptedThreadPlan(const char *script_class_name,
967 SBStructuredData &args_data,
968 bool resume_immediately) {
969 LLDB_INSTRUMENT_VA(this, script_class_name, args_data, resume_immediately);
970
972
973 llvm::Expected<StoppedExecutionContext> exe_ctx =
975 if (!exe_ctx)
976 return Status::FromError(exe_ctx.takeError());
977
978 if (!exe_ctx->HasThreadScope()) {
979 error = Status::FromErrorString("this SBThread object is invalid");
980 return error;
981 }
982
983 Thread *thread = exe_ctx->GetThreadPtr();
984 Status new_plan_status;
985 StructuredData::ObjectSP obj_sp = args_data.m_impl_up->GetObjectSP();
986
987 StructuredData::DictionarySP args_dict_sp;
988 if (obj_sp && obj_sp->GetType() == lldb::eStructuredDataTypeDictionary)
989 args_dict_sp = std::static_pointer_cast<StructuredData::Dictionary>(obj_sp);
990
991 ScriptedMetadata scripted_metadata(script_class_name, args_dict_sp);
992 ThreadPlanSP new_plan_sp = thread->QueueThreadPlanForStepScripted(
993 false, scripted_metadata, false, new_plan_status);
994
995 if (new_plan_status.Fail()) {
996 error = Status::FromErrorString(new_plan_status.AsCString());
997 return error;
998 }
999
1000 if (!resume_immediately)
1001 return error;
1002
1003 if (new_plan_status.Success())
1004 error = ResumeNewPlan(std::move(*exe_ctx), new_plan_sp.get());
1005 else
1006 error = Status::FromErrorString(new_plan_status.AsCString());
1007
1008 return error;
1009}
1010
1012 LLDB_INSTRUMENT_VA(this, file_spec, line);
1013
1014 SBError sb_error;
1015
1016 llvm::Expected<StoppedExecutionContext> exe_ctx =
1018 if (!exe_ctx)
1019 return Status::FromError(exe_ctx.takeError());
1020
1021 if (!exe_ctx->HasThreadScope()) {
1022 sb_error = Status::FromErrorString("this SBThread object is invalid");
1023 return sb_error;
1024 }
1025
1026 Thread *thread = exe_ctx->GetThreadPtr();
1027
1028 Status err = thread->JumpToLine(file_spec.ref(), line, true);
1029 sb_error.SetError(std::move(err));
1030 return sb_error;
1031}
1032
1034 LLDB_INSTRUMENT_VA(this, frame, return_value);
1035
1036 SBError sb_error;
1037
1038 llvm::Expected<StoppedExecutionContext> exe_ctx =
1040 if (!exe_ctx)
1041 return Status::FromError(exe_ctx.takeError());
1042
1043 if (exe_ctx->HasThreadScope()) {
1044 Thread *thread = exe_ctx->GetThreadPtr();
1045 sb_error.SetError(
1046 thread->ReturnFromFrame(frame.GetFrameSP(), return_value.GetSP()));
1047 }
1048
1049 return sb_error;
1050}
1051
1053 LLDB_INSTRUMENT_VA(this);
1054
1055 SBError sb_error;
1056
1057 llvm::Expected<StoppedExecutionContext> exe_ctx =
1059 if (!exe_ctx)
1060 return Status::FromError(exe_ctx.takeError());
1061
1062 if (exe_ctx->HasThreadScope()) {
1063 Thread *thread = exe_ctx->GetThreadPtr();
1064 sb_error.SetError(thread->UnwindInnermostExpression());
1065 if (sb_error.Success())
1066 thread->SetSelectedFrameByIndex(0, false);
1067 }
1068
1069 return sb_error;
1070}
1071
1073 LLDB_INSTRUMENT_VA(this);
1074
1075 SBError error; // Ignored
1076 return Suspend(error);
1077}
1078
1081
1082 llvm::Expected<StoppedExecutionContext> exe_ctx =
1084 if (!exe_ctx) {
1085 error = Status::FromError(exe_ctx.takeError());
1086 return false;
1087 }
1088
1089 bool result = false;
1090 if (exe_ctx->HasThreadScope()) {
1091 exe_ctx->GetThreadPtr()->SetResumeState(eStateSuspended);
1092 result = true;
1093 } else
1094 error = Status::FromErrorString("this SBThread object is invalid");
1095 return result;
1096}
1097
1099 LLDB_INSTRUMENT_VA(this);
1100
1101 SBError error; // Ignored
1102 return Resume(error);
1103}
1104
1107
1108 llvm::Expected<StoppedExecutionContext> exe_ctx =
1110 if (!exe_ctx) {
1111 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1112 error = Status::FromErrorString("process is running");
1113 return false;
1114 }
1115
1116 bool result = false;
1117 if (exe_ctx->HasThreadScope()) {
1118 const bool override_suspend = true;
1119 exe_ctx->GetThreadPtr()->SetResumeState(eStateRunning, override_suspend);
1120 result = true;
1121 } else
1122 error = Status::FromErrorString("this SBThread object is invalid");
1123 return result;
1124}
1125
1127 LLDB_INSTRUMENT_VA(this);
1128
1129 llvm::Expected<StoppedExecutionContext> exe_ctx =
1131 if (!exe_ctx) {
1132 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1133 return false;
1134 }
1135
1136 if (exe_ctx->HasThreadScope())
1137 return exe_ctx->GetThreadPtr()->GetResumeState() == eStateSuspended;
1138 return false;
1139}
1140
1142 LLDB_INSTRUMENT_VA(this);
1143
1144 llvm::Expected<StoppedExecutionContext> exe_ctx =
1146 if (!exe_ctx) {
1147 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1148 return false;
1149 }
1150
1151 if (exe_ctx->HasThreadScope())
1152 return StateIsStoppedState(exe_ctx->GetThreadPtr()->GetState(), true);
1153 return false;
1154}
1155
1157 LLDB_INSTRUMENT_VA(this);
1158
1159 SBProcess sb_process;
1160 llvm::Expected<StoppedExecutionContext> exe_ctx =
1162 if (!exe_ctx) {
1163 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1164 return SBProcess();
1165 }
1166
1167 if (exe_ctx->HasThreadScope()) {
1168 // Have to go up to the target so we can get a shared pointer to our
1169 // process...
1170 sb_process.SetSP(exe_ctx->GetProcessSP());
1171 }
1172
1173 return sb_process;
1174}
1175
1177 LLDB_INSTRUMENT_VA(this);
1178
1179 llvm::Expected<StoppedExecutionContext> exe_ctx =
1181 if (!exe_ctx) {
1182 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1183 return 0;
1184 }
1185
1186 if (exe_ctx->HasThreadScope())
1187 return exe_ctx->GetThreadPtr()->GetStackFrameCount();
1188
1189 return 0;
1190}
1191
1193 LLDB_INSTRUMENT_VA(this, idx);
1194
1195 SBFrame sb_frame;
1196 llvm::Expected<StoppedExecutionContext> exe_ctx =
1198 if (!exe_ctx) {
1199 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1200 return SBFrame();
1201 }
1202
1203 if (exe_ctx->HasThreadScope()) {
1204 StackFrameSP frame_sp = exe_ctx->GetThreadPtr()->GetStackFrameAtIndex(idx);
1205 sb_frame.SetFrameSP(frame_sp);
1206 }
1207
1208 return sb_frame;
1209}
1210
1212 LLDB_INSTRUMENT_VA(this);
1213
1214 SBFrameList sb_frame_list;
1215 llvm::Expected<StoppedExecutionContext> exe_ctx =
1217 if (!exe_ctx) {
1218 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1219 return SBFrameList();
1220 }
1221
1222 if (exe_ctx->HasThreadScope()) {
1223 StackFrameListSP frame_list_sp =
1224 exe_ctx->GetThreadPtr()->GetStackFrameList();
1225 sb_frame_list.SetFrameList(frame_list_sp);
1226 }
1227
1228 return sb_frame_list;
1229}
1230
1232 LLDB_INSTRUMENT_VA(this);
1233
1234 SBFrame sb_frame;
1235 llvm::Expected<StoppedExecutionContext> exe_ctx =
1237 if (!exe_ctx) {
1238 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1239 return SBFrame();
1240 }
1241
1242 if (exe_ctx->HasThreadScope()) {
1243 StackFrameSP frame_sp =
1244 exe_ctx->GetThreadPtr()->GetSelectedFrame(SelectMostRelevantFrame);
1245 sb_frame.SetFrameSP(frame_sp);
1246 }
1247
1248 return sb_frame;
1249}
1250
1252 LLDB_INSTRUMENT_VA(this, idx);
1253
1254 SBFrame sb_frame;
1255 StackFrameSP frame_sp;
1256 llvm::Expected<StoppedExecutionContext> exe_ctx =
1258 if (!exe_ctx) {
1259 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1260 return SBFrame();
1261 }
1262
1263 if (exe_ctx->HasThreadScope()) {
1264 Thread *thread = exe_ctx->GetThreadPtr();
1265 frame_sp = thread->GetStackFrameAtIndex(idx);
1266 if (frame_sp) {
1267 thread->SetSelectedFrame(frame_sp.get());
1268 sb_frame.SetFrameSP(frame_sp);
1269 }
1270 }
1271
1272 return sb_frame;
1273}
1274
1276 LLDB_INSTRUMENT_VA(event);
1277
1278 return Thread::ThreadEventData::GetEventDataFromEvent(event.get()) != nullptr;
1279}
1280
1286
1292
1293bool SBThread::operator==(const SBThread &rhs) const {
1294 LLDB_INSTRUMENT_VA(this, rhs);
1295
1296 return m_opaque_sp->GetThreadSP().get() ==
1297 rhs.m_opaque_sp->GetThreadSP().get();
1298}
1299
1300bool SBThread::operator!=(const SBThread &rhs) const {
1301 LLDB_INSTRUMENT_VA(this, rhs);
1302
1303 return m_opaque_sp->GetThreadSP().get() !=
1304 rhs.m_opaque_sp->GetThreadSP().get();
1305}
1306
1307bool SBThread::GetStatus(SBStream &status) const {
1308 LLDB_INSTRUMENT_VA(this, status);
1309
1310 Stream &strm = status.ref();
1311
1312 llvm::Expected<StoppedExecutionContext> exe_ctx =
1314 if (!exe_ctx) {
1315 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1316 return false;
1317 }
1318
1319 if (exe_ctx->HasThreadScope()) {
1320 exe_ctx->GetThreadPtr()->GetStatus(strm, 0, 1, 1, true,
1321 /*show_hidden=*/true);
1322 } else
1323 strm.PutCString("No status");
1324
1325 return true;
1326}
1327
1328bool SBThread::GetDescription(SBStream &description) const {
1329 LLDB_INSTRUMENT_VA(this, description);
1330
1331 return GetDescription(description, false);
1332}
1333
1334bool SBThread::GetDescription(SBStream &description, bool stop_format) const {
1335 LLDB_INSTRUMENT_VA(this, description, stop_format);
1336
1337 Stream &strm = description.ref();
1338
1339 llvm::Expected<StoppedExecutionContext> exe_ctx =
1341 if (!exe_ctx) {
1342 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1343 return false;
1344 }
1345
1346 if (exe_ctx->HasThreadScope()) {
1347 exe_ctx->GetThreadPtr()->DumpUsingSettingsFormat(
1348 strm, LLDB_INVALID_THREAD_ID, stop_format);
1349 } else
1350 strm.PutCString("No value");
1351
1352 return true;
1353}
1354
1356 SBStream &output) {
1357 Stream &strm = output.ref();
1358
1359 SBError error;
1360 if (!format) {
1361 error = Status::FromErrorString("The provided SBFormat object is invalid");
1362 return error;
1363 }
1364
1365 llvm::Expected<StoppedExecutionContext> exe_ctx =
1367 if (!exe_ctx) {
1368 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1369 return error;
1370 }
1371
1372 if (exe_ctx->HasThreadScope()) {
1373 if (exe_ctx->GetThreadPtr()->DumpUsingFormat(
1374 strm, LLDB_INVALID_THREAD_ID, format.GetFormatEntrySP().get())) {
1375 return error;
1376 }
1377 }
1378
1380 "It was not possible to generate a thread description with the given "
1381 "format string '%s'",
1382 format.GetFormatEntrySP()->string.c_str());
1383 return error;
1384}
1385
1387 LLDB_INSTRUMENT_VA(this, type);
1388
1389 llvm::Expected<StoppedExecutionContext> exe_ctx =
1391 SBThread sb_origin_thread;
1392 if (exe_ctx) {
1393 if (exe_ctx->HasThreadScope()) {
1394 ThreadSP real_thread(exe_ctx->GetThreadSP());
1395 if (real_thread) {
1396 ConstString type_const(type);
1397 Process *process = exe_ctx->GetProcessPtr();
1398 if (process) {
1399 SystemRuntime *runtime = process->GetSystemRuntime();
1400 if (runtime) {
1401 ThreadSP new_thread_sp(
1402 runtime->GetExtendedBacktraceThread(real_thread, type_const));
1403 if (new_thread_sp) {
1404 // Save this in the Process' ExtendedThreadList so a strong
1405 // pointer retains the object.
1406 process->GetExtendedThreadList().AddThread(new_thread_sp);
1407 sb_origin_thread.SetThread(new_thread_sp);
1408 }
1409 }
1410 }
1411 }
1412 }
1413 } else {
1414 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1415 }
1416
1417 return sb_origin_thread;
1418}
1419
1421 LLDB_INSTRUMENT_VA(this);
1422
1423 llvm::Expected<StoppedExecutionContext> exe_ctx =
1425 if (!exe_ctx) {
1426 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1427 return LLDB_INVALID_INDEX32;
1428 }
1429
1430 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1431 if (thread_sp)
1432 return thread_sp->GetExtendedBacktraceOriginatingIndexID();
1433 return LLDB_INVALID_INDEX32;
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 SBValue();
1444 }
1445
1446 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1447 if (!thread_sp)
1448 return SBValue();
1449
1450 return SBValue(thread_sp->GetCurrentException());
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 SBThread();
1461 }
1462
1463 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1464 if (!thread_sp)
1465 return SBThread();
1466
1467 return SBThread(thread_sp->GetCurrentExceptionBacktrace());
1468}
1469
1471 LLDB_INSTRUMENT_VA(this);
1472
1473 llvm::Expected<StoppedExecutionContext> exe_ctx =
1475 if (!exe_ctx) {
1476 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1477 return false;
1478 }
1479
1480 ThreadSP thread_sp(m_opaque_sp->GetThreadSP());
1481 if (thread_sp)
1482 return thread_sp->SafeToCallFunctions();
1483 return true;
1484}
1485
1486lldb::ThreadSP SBThread::GetSP() const { return m_opaque_sp->GetThreadSP(); }
1487
1491
1493 return m_opaque_sp->GetThreadSP().get();
1494}
1495
1497 LLDB_INSTRUMENT_VA(this);
1498
1499 llvm::Expected<StoppedExecutionContext> exe_ctx =
1501 if (!exe_ctx) {
1502 LLDB_LOG_ERROR(GetLog(LLDBLog::API), exe_ctx.takeError(), "{0}");
1503 return SBValue();
1504 }
1505
1506 ThreadSP thread_sp = m_opaque_sp->GetThreadSP();
1507 if (!thread_sp)
1508 return SBValue();
1509 return thread_sp->GetSiginfoValue();
1510}
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:449
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:134
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:655
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:254
lldb_private::Stream & ref()
Definition SBStream.cpp:179
StructuredDataImplUP m_impl_up
static const char * GetBroadcasterClassName()
Definition SBThread.cpp:54
void StepInto(lldb::RunMode stop_other_threads=lldb::eOnlyDuringStepping)
Definition SBThread.cpp:538
bool Suspend()
LLDB currently supports process centric debugging which means when any thread in a process stops,...
const char * GetName() const
Definition SBThread.cpp:351
bool GetStopDescription(lldb::SBStream &stream) const
Gets a human-readable description of why the thread stopped.
Definition SBThread.cpp:243
const lldb::SBThread & operator=(const lldb::SBThread &rhs)
Definition SBThread.cpp:78
lldb::SBFrame SetSelectedFrame(uint32_t frame_idx)
SBError UnwindInnermostExpression()
friend class SBThreadCollection
Definition SBThread.h:255
bool IsValid() const
Definition SBThread.cpp:111
uint32_t GetNumFrames()
friend class SBProcess
Definition SBThread.h:250
const char * GetQueueName() const
Definition SBThread.cpp:367
SBValue GetSiginfo()
uint32_t GetIndexID() const
Definition SBThread.cpp:335
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:692
bool GetStatus(lldb::SBStream &status) const
friend class SBValue
Definition SBThread.h:252
static SBFrame GetStackFrameFromEvent(const SBEvent &event)
lldb::queue_id_t GetQueueID() const
Definition SBThread.cpp:383
lldb::SBFrameList GetFrames() const
bool GetInfoItemByPathAsString(const char *path, SBStream &strm)
Definition SBThread.cpp:401
lldb::SBFrame GetSelectedFrame()
friend class SBFrameList
Definition SBThread.h:249
bool operator!=(const lldb::SBThread &rhs) const
SBError StepUsingScriptedThreadPlan(const char *script_class_name)
Definition SBThread.cpp:951
lldb::tid_t GetThreadID() const
Definition SBThread.cpp:319
lldb::SBFrame GetFrameAtIndex(uint32_t idx)
uint32_t GetExtendedBacktraceOriginatingIndexID()
lldb::SBQueue GetQueue() const
Definition SBThread.cpp:89
bool SafeToCallFunctions()
lldb::SBProcess GetProcess()
size_t GetStopReasonDataCount()
Get the number of words associated with the stop reason.
Definition SBThread.cpp:153
void StepInstruction(bool step_over)
Definition SBThread.cpp:740
SBThread GetCurrentExceptionBacktrace()
friend class SBFrame
Definition SBThread.h:248
static SBThread GetThreadFromEvent(const SBEvent &event)
bool GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream)
Definition SBThread.cpp:190
lldb::StopReason GetStopReason()
Definition SBThread.cpp:136
SBValue GetStopReturnValue()
Definition SBThread.cpp:294
void StepOver(lldb::RunMode stop_other_threads=lldb::eOnlyDuringStepping)
Definition SBThread.cpp:474
SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line)
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:216
SBValue GetCurrentException()
void SetThread(const lldb::ThreadSP &lldb_object_sp)
Definition SBThread.cpp:315
lldb::ThreadSP GetSP() const
SBThread GetExtendedBacktraceThread(const char *type)
lldb::ExecutionContextRefSP m_opaque_sp
Definition SBThread.h:268
void RunToAddress(lldb::addr_t addr)
Definition SBThread.cpp:792
uint64_t GetStopReasonDataAtIndex(uint32_t idx)
Get information associated with a stop reason.
Definition SBThread.cpp:171
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:831
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:1058
A section + offset based address range class.
A section + offset based address class.
Definition Address.h:62
void ResolveSymbolContext(const SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, SymbolContextList &sc_list, RealpathPrefixes *realpath_prefixes=nullptr)
Resolve symbol contexts by file and line.
A uniqued constant string class.
Definition ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
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
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:380
bool GetRangeContainingLoadAddress(lldb::addr_t load_addr, Target &target, AddressRange &range)
Definition Function.h:441
A plug-in interface definition class for debugging a process.
Definition Process.h:367
ThreadList & GetThreadList()
Definition Process.h:2408
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition Process.cpp:1355
virtual SystemRuntime * GetSystemRuntime()
Get the system runtime plug-in for this process.
Definition Process.cpp:3178
ThreadList & GetExtendedThreadList()
Definition Process.h:2419
Status ResumeSynchronous(Stream *stream)
Resume a process, and wait for it to stop.
Definition Process.cpp:1372
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1266
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
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 lldb::ValueObjectSP GetReturnValueObject(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
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
Defines a list of symbol context objects.
Defines a symbol context baton that can be handed other debug core functions.
llvm::Error GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range)
Function * function
The Function for a given query.
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:1349
void AddThread(const lldb::ThreadSP &thread_sp)
bool SetSelectedThreadByID(lldb::tid_t tid, bool notify=false)
void SetOkayToDiscard(bool value)
Definition ThreadPlan.h:427
bool SetIsControllingPlan(bool value)
Definition ThreadPlan.h:419
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
#define LLDB_INVALID_ADDRESS
@ 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
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition Utils.h:17
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
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
@ 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:103
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
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,...
#define PATH_MAX