LLDB mainline
CommandObjectThread.cpp
Go to the documentation of this file.
1//===-- CommandObjectThread.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
10
11#include <memory>
12#include <optional>
13#include <sstream>
14
16#include "CommandObjectTrace.h"
30#include "lldb/Target/Process.h"
33#include "lldb/Target/Target.h"
34#include "lldb/Target/Thread.h"
37#include "lldb/Target/Trace.h"
39#include "lldb/Utility/State.h"
40
41using namespace lldb;
42using namespace lldb_private;
43
44// CommandObjectThreadBacktrace
45#define LLDB_OPTIONS_thread_backtrace
46#include "CommandOptions.inc"
47
49public:
50 class CommandOptions : public Options {
51 public:
53 // Keep default values of all options in one place: OptionParsingStarting
54 // ()
55 OptionParsingStarting(nullptr);
56 }
57
58 ~CommandOptions() override = default;
59
60 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
61 ExecutionContext *execution_context) override {
63 const int short_option = m_getopt_table[option_idx].val;
64
65 switch (short_option) {
66 case 'c':
67 if (option_arg.getAsInteger(0, m_count)) {
69 error.SetErrorStringWithFormat(
70 "invalid integer value for option '%c': %s", short_option,
71 option_arg.data());
72 }
73 // A count of 0 means all frames.
74 if (m_count == 0)
76 break;
77 case 's':
78 if (option_arg.getAsInteger(0, m_start))
79 error.SetErrorStringWithFormat(
80 "invalid integer value for option '%c': %s", short_option,
81 option_arg.data());
82 break;
83 case 'e': {
84 bool success;
86 OptionArgParser::ToBoolean(option_arg, false, &success);
87 if (!success)
88 error.SetErrorStringWithFormat(
89 "invalid boolean value for option '%c': %s", short_option,
90 option_arg.data());
91 } break;
92 default:
93 llvm_unreachable("Unimplemented option");
94 }
95 return error;
96 }
97
98 void OptionParsingStarting(ExecutionContext *execution_context) override {
100 m_start = 0;
101 m_extended_backtrace = false;
102 }
103
104 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
105 return llvm::ArrayRef(g_thread_backtrace_options);
106 }
107
108 // Instance variables to hold the values for command options.
109 uint32_t m_count;
110 uint32_t m_start;
112 };
113
116 interpreter, "thread backtrace",
117 "Show backtraces of thread call stacks. Defaults to the current "
118 "thread, thread indexes can be specified as arguments.\n"
119 "Use the thread-index \"all\" to see all threads.\n"
120 "Use the thread-index \"unique\" to see threads grouped by unique "
121 "call stacks.\n"
122 "Use 'settings set frame-format' to customize the printing of "
123 "frames in the backtrace and 'settings set thread-format' to "
124 "customize the thread header.",
125 nullptr,
126 eCommandRequiresProcess | eCommandRequiresThread |
127 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
128 eCommandProcessMustBePaused) {}
129
130 ~CommandObjectThreadBacktrace() override = default;
131
132 Options *GetOptions() override { return &m_options; }
133
134 std::optional<std::string> GetRepeatCommand(Args &current_args,
135 uint32_t index) override {
136 llvm::StringRef count_opt("--count");
137 llvm::StringRef start_opt("--start");
138
139 // If no "count" was provided, we are dumping the entire backtrace, so
140 // there isn't a repeat command. So we search for the count option in
141 // the args, and if we find it, we make a copy and insert or modify the
142 // start option's value to start count indices greater.
143
144 Args copy_args(current_args);
145 size_t num_entries = copy_args.GetArgumentCount();
146 // These two point at the index of the option value if found.
147 size_t count_idx = 0;
148 size_t start_idx = 0;
149 size_t count_val = 0;
150 size_t start_val = 0;
151
152 for (size_t idx = 0; idx < num_entries; idx++) {
153 llvm::StringRef arg_string = copy_args[idx].ref();
154 if (arg_string == "-c" || count_opt.starts_with(arg_string)) {
155 idx++;
156 if (idx == num_entries)
157 return std::nullopt;
158 count_idx = idx;
159 if (copy_args[idx].ref().getAsInteger(0, count_val))
160 return std::nullopt;
161 } else if (arg_string == "-s" || start_opt.starts_with(arg_string)) {
162 idx++;
163 if (idx == num_entries)
164 return std::nullopt;
165 start_idx = idx;
166 if (copy_args[idx].ref().getAsInteger(0, start_val))
167 return std::nullopt;
168 }
169 }
170 if (count_idx == 0)
171 return std::nullopt;
172
173 std::string new_start_val = llvm::formatv("{0}", start_val + count_val);
174 if (start_idx == 0) {
175 copy_args.AppendArgument(start_opt);
176 copy_args.AppendArgument(new_start_val);
177 } else {
178 copy_args.ReplaceArgumentAtIndex(start_idx, new_start_val);
179 }
180 std::string repeat_command;
181 if (!copy_args.GetQuotedCommandString(repeat_command))
182 return std::nullopt;
183 return repeat_command;
184 }
185
186protected:
188 SystemRuntime *runtime = thread->GetProcess()->GetSystemRuntime();
189 if (runtime) {
190 Stream &strm = result.GetOutputStream();
191 const std::vector<ConstString> &types =
192 runtime->GetExtendedBacktraceTypes();
193 for (auto type : types) {
194 ThreadSP ext_thread_sp = runtime->GetExtendedBacktraceThread(
195 thread->shared_from_this(), type);
196 if (ext_thread_sp && ext_thread_sp->IsValid()) {
197 const uint32_t num_frames_with_source = 0;
198 const bool stop_format = false;
199 strm.PutChar('\n');
200 if (ext_thread_sp->GetStatus(strm, m_options.m_start,
202 num_frames_with_source, stop_format)) {
203 DoExtendedBacktrace(ext_thread_sp.get(), result);
204 }
205 }
206 }
207 }
208 }
209
210 bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
211 ThreadSP thread_sp =
213 if (!thread_sp) {
215 "thread disappeared while computing backtraces: 0x%" PRIx64 "\n",
216 tid);
217 return false;
218 }
219
220 Thread *thread = thread_sp.get();
221
222 Stream &strm = result.GetOutputStream();
223
224 // Only dump stack info if we processing unique stacks.
225 const bool only_stacks = m_unique_stacks;
226
227 // Don't show source context when doing backtraces.
228 const uint32_t num_frames_with_source = 0;
229 const bool stop_format = true;
230 if (!thread->GetStatus(strm, m_options.m_start, m_options.m_count,
231 num_frames_with_source, stop_format, only_stacks)) {
233 "error displaying backtrace for thread: \"0x%4.4x\"\n",
234 thread->GetIndexID());
235 return false;
236 }
239 "Interrupt skipped extended backtrace")) {
240 DoExtendedBacktrace(thread, result);
241 }
242 }
243
244 return true;
245 }
246
248};
249
251
252#define LLDB_OPTIONS_thread_step_scope
253#include "CommandOptions.inc"
254
256public:
258 // Keep default values of all options in one place: OptionParsingStarting
259 // ()
260 OptionParsingStarting(nullptr);
261 }
262
263 ~ThreadStepScopeOptionGroup() override = default;
264
265 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
266 return llvm::ArrayRef(g_thread_step_scope_options);
267 }
268
269 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
270 ExecutionContext *execution_context) override {
272 const int short_option =
273 g_thread_step_scope_options[option_idx].short_option;
274
275 switch (short_option) {
276 case 'a': {
277 bool success;
278 bool avoid_no_debug =
279 OptionArgParser::ToBoolean(option_arg, true, &success);
280 if (!success)
281 error.SetErrorStringWithFormat(
282 "invalid boolean value for option '%c': %s", short_option,
283 option_arg.data());
284 else {
286 }
287 } break;
288
289 case 'A': {
290 bool success;
291 bool avoid_no_debug =
292 OptionArgParser::ToBoolean(option_arg, true, &success);
293 if (!success)
294 error.SetErrorStringWithFormat(
295 "invalid boolean value for option '%c': %s", short_option,
296 option_arg.data());
297 else {
299 }
300 } break;
301
302 case 'c':
303 if (option_arg.getAsInteger(0, m_step_count))
304 error.SetErrorStringWithFormat(
305 "invalid integer value for option '%c': %s", short_option,
306 option_arg.data());
307 break;
308
309 case 'm': {
310 auto enum_values = GetDefinitions()[option_idx].enum_values;
312 option_arg, enum_values, eOnlyDuringStepping, error);
313 } break;
314
315 case 'e':
316 if (option_arg == "block") {
318 break;
319 }
320 if (option_arg.getAsInteger(0, m_end_line))
321 error.SetErrorStringWithFormat("invalid end line number '%s'",
322 option_arg.str().c_str());
323 break;
324
325 case 'r':
326 m_avoid_regexp.clear();
327 m_avoid_regexp.assign(std::string(option_arg));
328 break;
329
330 case 't':
331 m_step_in_target.clear();
332 m_step_in_target.assign(std::string(option_arg));
333 break;
334
335 default:
336 llvm_unreachable("Unimplemented option");
337 }
338 return error;
339 }
340
341 void OptionParsingStarting(ExecutionContext *execution_context) override {
345
346 // Check if we are in Non-Stop mode
347 TargetSP target_sp =
348 execution_context ? execution_context->GetTargetSP() : TargetSP();
349 ProcessSP process_sp =
350 execution_context ? execution_context->GetProcessSP() : ProcessSP();
351 if (process_sp && process_sp->GetSteppingRunsAllThreads())
353
354 m_avoid_regexp.clear();
355 m_step_in_target.clear();
356 m_step_count = 1;
359 }
360
361 // Instance variables to hold the values for command options.
365 std::string m_avoid_regexp;
366 std::string m_step_in_target;
367 uint32_t m_step_count;
368 uint32_t m_end_line;
370};
371
373public:
375 const char *name, const char *help,
376 const char *syntax,
377 StepType step_type,
378 StepScope step_scope)
379 : CommandObjectParsed(interpreter, name, help, syntax,
380 eCommandRequiresProcess | eCommandRequiresThread |
381 eCommandTryTargetAPILock |
382 eCommandProcessMustBeLaunched |
383 eCommandProcessMustBePaused),
384 m_step_type(step_type), m_step_scope(step_scope),
385 m_class_options("scripted step") {
387
388 if (step_type == eStepTypeScripted) {
391 }
394 }
395
397
398 void
400 OptionElementVector &opt_element_vector) override {
401 if (request.GetCursorIndex())
402 return;
403 CommandObject::HandleArgumentCompletion(request, opt_element_vector);
404 }
405
406 Options *GetOptions() override { return &m_all_options; }
407
408protected:
409 void DoExecute(Args &command, CommandReturnObject &result) override {
410 Process *process = m_exe_ctx.GetProcessPtr();
411 bool synchronous_execution = m_interpreter.GetSynchronous();
412
413 const uint32_t num_threads = process->GetThreadList().GetSize();
414 Thread *thread = nullptr;
415
416 if (command.GetArgumentCount() == 0) {
417 thread = GetDefaultThread();
418
419 if (thread == nullptr) {
420 result.AppendError("no selected thread in process");
421 return;
422 }
423 } else {
424 const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
425 uint32_t step_thread_idx;
426
427 if (!llvm::to_integer(thread_idx_cstr, step_thread_idx)) {
428 result.AppendErrorWithFormat("invalid thread index '%s'.\n",
429 thread_idx_cstr);
430 return;
431 }
432 thread =
433 process->GetThreadList().FindThreadByIndexID(step_thread_idx).get();
434 if (thread == nullptr) {
436 "Thread index %u is out of range (valid values are 0 - %u).\n",
437 step_thread_idx, num_threads);
438 return;
439 }
440 }
441
443 if (m_class_options.GetName().empty()) {
444 result.AppendErrorWithFormat("empty class name for scripted step.");
445 return;
446 } else if (!GetDebugger().GetScriptInterpreter()->CheckObjectExists(
447 m_class_options.GetName().c_str())) {
449 "class for scripted step: \"%s\" does not exist.",
450 m_class_options.GetName().c_str());
451 return;
452 }
453 }
454
458 "end line option is only valid for step into");
459 return;
460 }
461
462 const bool abort_other_plans = false;
463 const lldb::RunMode stop_other_threads = m_options.m_run_mode;
464
465 // This is a bit unfortunate, but not all the commands in this command
466 // object support only while stepping, so I use the bool for them.
467 bool bool_stop_other_threads;
469 bool_stop_other_threads = false;
471 bool_stop_other_threads = (m_step_type != eStepTypeOut);
472 else
473 bool_stop_other_threads = true;
474
475 ThreadPlanSP new_plan_sp;
476 Status new_plan_status;
477
478 if (m_step_type == eStepTypeInto) {
479 StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
480 assert(frame != nullptr);
481
482 if (frame->HasDebugInformation()) {
483 AddressRange range;
484 SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
488 error)) {
489 result.AppendErrorWithFormat("invalid end-line option: %s.",
490 error.AsCString());
491 return;
492 }
495 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
496 if (!block) {
497 result.AppendErrorWithFormat("Could not find the current block.");
498 return;
499 }
500
501 AddressRange block_range;
502 Address pc_address = frame->GetFrameCodeAddress();
503 block->GetRangeContainingAddress(pc_address, block_range);
504 if (!block_range.GetBaseAddress().IsValid()) {
506 "Could not find the current block address.");
507 return;
508 }
509 lldb::addr_t pc_offset_in_block =
510 pc_address.GetFileAddress() -
511 block_range.GetBaseAddress().GetFileAddress();
512 lldb::addr_t range_length =
513 block_range.GetByteSize() - pc_offset_in_block;
514 range = AddressRange(pc_address, range_length);
515 } else {
516 range = sc.line_entry.range;
517 }
518
519 new_plan_sp = thread->QueueThreadPlanForStepInRange(
520 abort_other_plans, range,
521 frame->GetSymbolContext(eSymbolContextEverything),
522 m_options.m_step_in_target.c_str(), stop_other_threads,
523 new_plan_status, m_options.m_step_in_avoid_no_debug,
525
526 if (new_plan_sp && !m_options.m_avoid_regexp.empty()) {
527 ThreadPlanStepInRange *step_in_range_plan =
528 static_cast<ThreadPlanStepInRange *>(new_plan_sp.get());
529 step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str());
530 }
531 } else
532 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
533 false, abort_other_plans, bool_stop_other_threads, new_plan_status);
534 } else if (m_step_type == eStepTypeOver) {
535 StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
536
537 if (frame->HasDebugInformation())
538 new_plan_sp = thread->QueueThreadPlanForStepOverRange(
539 abort_other_plans,
540 frame->GetSymbolContext(eSymbolContextEverything).line_entry,
541 frame->GetSymbolContext(eSymbolContextEverything),
542 stop_other_threads, new_plan_status,
544 else
545 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
546 true, abort_other_plans, bool_stop_other_threads, new_plan_status);
547 } else if (m_step_type == eStepTypeTrace) {
548 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
549 false, abort_other_plans, bool_stop_other_threads, new_plan_status);
550 } else if (m_step_type == eStepTypeTraceOver) {
551 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
552 true, abort_other_plans, bool_stop_other_threads, new_plan_status);
553 } else if (m_step_type == eStepTypeOut) {
554 new_plan_sp = thread->QueueThreadPlanForStepOut(
555 abort_other_plans, nullptr, false, bool_stop_other_threads, eVoteYes,
558 new_plan_status, m_options.m_step_out_avoid_no_debug);
559 } else if (m_step_type == eStepTypeScripted) {
560 new_plan_sp = thread->QueueThreadPlanForStepScripted(
561 abort_other_plans, m_class_options.GetName().c_str(),
562 m_class_options.GetStructuredData(), bool_stop_other_threads,
563 new_plan_status);
564 } else {
565 result.AppendError("step type is not supported");
566 return;
567 }
568
569 // If we got a new plan, then set it to be a controlling plan (User level
570 // Plans should be controlling plans so that they can be interruptible).
571 // Then resume the process.
572
573 if (new_plan_sp) {
574 new_plan_sp->SetIsControllingPlan(true);
575 new_plan_sp->SetOkayToDiscard(false);
576
577 if (m_options.m_step_count > 1) {
578 if (!new_plan_sp->SetIterationCount(m_options.m_step_count)) {
579 result.AppendWarning(
580 "step operation does not support iteration count.");
581 }
582 }
583
584 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
585
586 const uint32_t iohandler_id = process->GetIOHandlerID();
587
588 StreamString stream;
590 if (synchronous_execution)
591 error = process->ResumeSynchronous(&stream);
592 else
593 error = process->Resume();
594
595 if (!error.Success()) {
596 result.AppendMessage(error.AsCString());
597 return;
598 }
599
600 // There is a race condition where this thread will return up the call
601 // stack to the main command handler and show an (lldb) prompt before
602 // HandlePrivateEvent (from PrivateStateThread) has a chance to call
603 // PushProcessIOHandler().
604 process->SyncIOHandler(iohandler_id, std::chrono::seconds(2));
605
606 if (synchronous_execution) {
607 // If any state changed events had anything to say, add that to the
608 // result
609 if (stream.GetSize() > 0)
610 result.AppendMessage(stream.GetString());
611
612 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
613 result.SetDidChangeProcessState(true);
615 } else {
617 }
618 } else {
619 result.SetError(new_plan_status);
620 }
621 }
622
628};
629
630// CommandObjectThreadContinue
631
633public:
636 interpreter, "thread continue",
637 "Continue execution of the current target process. One "
638 "or more threads may be specified, by default all "
639 "threads continue.",
640 nullptr,
641 eCommandRequiresThread | eCommandTryTargetAPILock |
642 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
644 }
645
646 ~CommandObjectThreadContinue() override = default;
647
648 void DoExecute(Args &command, CommandReturnObject &result) override {
649 bool synchronous_execution = m_interpreter.GetSynchronous();
650
651 Process *process = m_exe_ctx.GetProcessPtr();
652 if (process == nullptr) {
653 result.AppendError("no process exists. Cannot continue");
654 return;
655 }
656
657 StateType state = process->GetState();
658 if ((state == eStateCrashed) || (state == eStateStopped) ||
659 (state == eStateSuspended)) {
660 const size_t argc = command.GetArgumentCount();
661 if (argc > 0) {
662 // These two lines appear at the beginning of both blocks in this
663 // if..else, but that is because we need to release the lock before
664 // calling process->Resume below.
665 std::lock_guard<std::recursive_mutex> guard(
666 process->GetThreadList().GetMutex());
667 const uint32_t num_threads = process->GetThreadList().GetSize();
668 std::vector<Thread *> resume_threads;
669 for (auto &entry : command.entries()) {
670 uint32_t thread_idx;
671 if (entry.ref().getAsInteger(0, thread_idx)) {
673 "invalid thread index argument: \"%s\".\n", entry.c_str());
674 return;
675 }
676 Thread *thread =
677 process->GetThreadList().FindThreadByIndexID(thread_idx).get();
678
679 if (thread) {
680 resume_threads.push_back(thread);
681 } else {
682 result.AppendErrorWithFormat("invalid thread index %u.\n",
683 thread_idx);
684 return;
685 }
686 }
687
688 if (resume_threads.empty()) {
689 result.AppendError("no valid thread indexes were specified");
690 return;
691 } else {
692 if (resume_threads.size() == 1)
693 result.AppendMessageWithFormat("Resuming thread: ");
694 else
695 result.AppendMessageWithFormat("Resuming threads: ");
696
697 for (uint32_t idx = 0; idx < num_threads; ++idx) {
698 Thread *thread =
699 process->GetThreadList().GetThreadAtIndex(idx).get();
700 std::vector<Thread *>::iterator this_thread_pos =
701 find(resume_threads.begin(), resume_threads.end(), thread);
702
703 if (this_thread_pos != resume_threads.end()) {
704 resume_threads.erase(this_thread_pos);
705 if (!resume_threads.empty())
706 result.AppendMessageWithFormat("%u, ", thread->GetIndexID());
707 else
708 result.AppendMessageWithFormat("%u ", thread->GetIndexID());
709
710 const bool override_suspend = true;
711 thread->SetResumeState(eStateRunning, override_suspend);
712 } else {
714 }
715 }
716 result.AppendMessageWithFormat("in process %" PRIu64 "\n",
717 process->GetID());
718 }
719 } else {
720 // These two lines appear at the beginning of both blocks in this
721 // if..else, but that is because we need to release the lock before
722 // calling process->Resume below.
723 std::lock_guard<std::recursive_mutex> guard(
724 process->GetThreadList().GetMutex());
725 const uint32_t num_threads = process->GetThreadList().GetSize();
726 Thread *current_thread = GetDefaultThread();
727 if (current_thread == nullptr) {
728 result.AppendError("the process doesn't have a current thread");
729 return;
730 }
731 // Set the actions that the threads should each take when resuming
732 for (uint32_t idx = 0; idx < num_threads; ++idx) {
733 Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
734 if (thread == current_thread) {
735 result.AppendMessageWithFormat("Resuming thread 0x%4.4" PRIx64
736 " in process %" PRIu64 "\n",
737 thread->GetID(), process->GetID());
738 const bool override_suspend = true;
739 thread->SetResumeState(eStateRunning, override_suspend);
740 } else {
742 }
743 }
744 }
745
746 StreamString stream;
748 if (synchronous_execution)
749 error = process->ResumeSynchronous(&stream);
750 else
751 error = process->Resume();
752
753 // We should not be holding the thread list lock when we do this.
754 if (error.Success()) {
755 result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
756 process->GetID());
757 if (synchronous_execution) {
758 // If any state changed events had anything to say, add that to the
759 // result
760 if (stream.GetSize() > 0)
761 result.AppendMessage(stream.GetString());
762
763 result.SetDidChangeProcessState(true);
765 } else {
767 }
768 } else {
769 result.AppendErrorWithFormat("Failed to resume process: %s\n",
770 error.AsCString());
771 }
772 } else {
774 "Process cannot be continued from its current state (%s).\n",
775 StateAsCString(state));
776 }
777 }
778};
779
780// CommandObjectThreadUntil
781
782#define LLDB_OPTIONS_thread_until
783#include "CommandOptions.inc"
784
786public:
787 class CommandOptions : public Options {
788 public:
791
793 // Keep default values of all options in one place: OptionParsingStarting
794 // ()
795 OptionParsingStarting(nullptr);
796 }
797
798 ~CommandOptions() override = default;
799
800 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
801 ExecutionContext *execution_context) override {
803 const int short_option = m_getopt_table[option_idx].val;
804
805 switch (short_option) {
806 case 'a': {
808 execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
809 if (error.Success())
810 m_until_addrs.push_back(tmp_addr);
811 } break;
812 case 't':
813 if (option_arg.getAsInteger(0, m_thread_idx)) {
815 error.SetErrorStringWithFormat("invalid thread index '%s'",
816 option_arg.str().c_str());
817 }
818 break;
819 case 'f':
820 if (option_arg.getAsInteger(0, m_frame_idx)) {
822 error.SetErrorStringWithFormat("invalid frame index '%s'",
823 option_arg.str().c_str());
824 }
825 break;
826 case 'm': {
827 auto enum_values = GetDefinitions()[option_idx].enum_values;
829 option_arg, enum_values, eOnlyDuringStepping, error);
830
831 if (error.Success()) {
832 if (run_mode == eAllThreads)
833 m_stop_others = false;
834 else
835 m_stop_others = true;
836 }
837 } break;
838 default:
839 llvm_unreachable("Unimplemented option");
840 }
841 return error;
842 }
843
844 void OptionParsingStarting(ExecutionContext *execution_context) override {
846 m_frame_idx = 0;
847 m_stop_others = false;
848 m_until_addrs.clear();
849 }
850
851 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
852 return llvm::ArrayRef(g_thread_until_options);
853 }
854
856 bool m_stop_others = false;
857 std::vector<lldb::addr_t> m_until_addrs;
858
859 // Instance variables to hold the values for command options.
860 };
861
864 interpreter, "thread until",
865 "Continue until a line number or address is reached by the "
866 "current or specified thread. Stops when returning from "
867 "the current function as a safety measure. "
868 "The target line number(s) are given as arguments, and if more "
869 "than one"
870 " is provided, stepping will stop when the first one is hit.",
871 nullptr,
872 eCommandRequiresThread | eCommandTryTargetAPILock |
873 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
875 }
876
877 ~CommandObjectThreadUntil() override = default;
878
879 Options *GetOptions() override { return &m_options; }
880
881protected:
882 void DoExecute(Args &command, CommandReturnObject &result) override {
883 bool synchronous_execution = m_interpreter.GetSynchronous();
884
885 Target *target = &GetSelectedTarget();
886
887 Process *process = m_exe_ctx.GetProcessPtr();
888 if (process == nullptr) {
889 result.AppendError("need a valid process to step");
890 } else {
891 Thread *thread = nullptr;
892 std::vector<uint32_t> line_numbers;
893
894 if (command.GetArgumentCount() >= 1) {
895 size_t num_args = command.GetArgumentCount();
896 for (size_t i = 0; i < num_args; i++) {
897 uint32_t line_number;
898 if (!llvm::to_integer(command.GetArgumentAtIndex(i), line_number)) {
899 result.AppendErrorWithFormat("invalid line number: '%s'.\n",
900 command.GetArgumentAtIndex(i));
901 return;
902 } else
903 line_numbers.push_back(line_number);
904 }
905 } else if (m_options.m_until_addrs.empty()) {
906 result.AppendErrorWithFormat("No line number or address provided:\n%s",
907 GetSyntax().str().c_str());
908 return;
909 }
910
912 thread = GetDefaultThread();
913 } else {
914 thread = process->GetThreadList()
916 .get();
917 }
918
919 if (thread == nullptr) {
920 const uint32_t num_threads = process->GetThreadList().GetSize();
922 "Thread index %u is out of range (valid values are 0 - %u).\n",
923 m_options.m_thread_idx, num_threads);
924 return;
925 }
926
927 const bool abort_other_plans = false;
928
929 StackFrame *frame =
931 if (frame == nullptr) {
933 "Frame index %u is out of range for thread id %" PRIu64 ".\n",
934 m_options.m_frame_idx, thread->GetID());
935 return;
936 }
937
938 ThreadPlanSP new_plan_sp;
939 Status new_plan_status;
940
941 if (frame->HasDebugInformation()) {
942 // Finally we got here... Translate the given line number to a bunch
943 // of addresses:
944 SymbolContext sc(frame->GetSymbolContext(eSymbolContextCompUnit));
945 LineTable *line_table = nullptr;
946 if (sc.comp_unit)
947 line_table = sc.comp_unit->GetLineTable();
948
949 if (line_table == nullptr) {
950 result.AppendErrorWithFormat("Failed to resolve the line table for "
951 "frame %u of thread id %" PRIu64 ".\n",
952 m_options.m_frame_idx, thread->GetID());
953 return;
954 }
955
956 LineEntry function_start;
957 uint32_t index_ptr = 0, end_ptr = UINT32_MAX;
958 std::vector<addr_t> address_list;
959
960 // Find the beginning & end index of the function, but first make
961 // sure it is valid:
962 if (!sc.function) {
963 result.AppendErrorWithFormat("Have debug information but no "
964 "function info - can't get until range.");
965 return;
966 }
967
968 AddressRange fun_addr_range = sc.function->GetAddressRange();
969 Address fun_start_addr = fun_addr_range.GetBaseAddress();
970 line_table->FindLineEntryByAddress(fun_start_addr, function_start,
971 &index_ptr);
972
973 Address fun_end_addr(fun_start_addr.GetSection(),
974 fun_start_addr.GetOffset() +
975 fun_addr_range.GetByteSize());
976
977 bool all_in_function = true;
978
979 line_table->FindLineEntryByAddress(fun_end_addr, function_start,
980 &end_ptr);
981
982 // Since not all source lines will contribute code, check if we are
983 // setting the breakpoint on the exact line number or the nearest
984 // subsequent line number and set breakpoints at all the line table
985 // entries of the chosen line number (exact or nearest subsequent).
986 for (uint32_t line_number : line_numbers) {
987 LineEntry line_entry;
988 bool exact = false;
989 uint32_t start_idx_ptr = index_ptr;
990 start_idx_ptr = sc.comp_unit->FindLineEntry(
991 index_ptr, line_number, nullptr, exact, &line_entry);
992 if (start_idx_ptr != UINT32_MAX)
993 line_number = line_entry.line;
994 exact = true;
995 start_idx_ptr = index_ptr;
996 while (start_idx_ptr <= end_ptr) {
997 start_idx_ptr = sc.comp_unit->FindLineEntry(
998 start_idx_ptr, line_number, nullptr, exact, &line_entry);
999 if (start_idx_ptr == UINT32_MAX)
1000 break;
1001
1002 addr_t address =
1003 line_entry.range.GetBaseAddress().GetLoadAddress(target);
1004 if (address != LLDB_INVALID_ADDRESS) {
1005 if (fun_addr_range.ContainsLoadAddress(address, target))
1006 address_list.push_back(address);
1007 else
1008 all_in_function = false;
1009 }
1010 start_idx_ptr++;
1011 }
1012 }
1013
1014 for (lldb::addr_t address : m_options.m_until_addrs) {
1015 if (fun_addr_range.ContainsLoadAddress(address, target))
1016 address_list.push_back(address);
1017 else
1018 all_in_function = false;
1019 }
1020
1021 if (address_list.empty()) {
1022 if (all_in_function)
1023 result.AppendErrorWithFormat(
1024 "No line entries matching until target.\n");
1025 else
1026 result.AppendErrorWithFormat(
1027 "Until target outside of the current function.\n");
1028
1029 return;
1030 }
1031
1032 new_plan_sp = thread->QueueThreadPlanForStepUntil(
1033 abort_other_plans, &address_list.front(), address_list.size(),
1034 m_options.m_stop_others, m_options.m_frame_idx, new_plan_status);
1035 if (new_plan_sp) {
1036 // User level plans should be controlling plans so they can be
1037 // interrupted
1038 // (e.g. by hitting a breakpoint) and other plans executed by the
1039 // user (stepping around the breakpoint) and then a "continue" will
1040 // resume the original plan.
1041 new_plan_sp->SetIsControllingPlan(true);
1042 new_plan_sp->SetOkayToDiscard(false);
1043 } else {
1044 result.SetError(new_plan_status);
1045 return;
1046 }
1047 } else {
1048 result.AppendErrorWithFormat("Frame index %u of thread id %" PRIu64
1049 " has no debug information.\n",
1050 m_options.m_frame_idx, thread->GetID());
1051 return;
1052 }
1053
1054 if (!process->GetThreadList().SetSelectedThreadByID(thread->GetID())) {
1055 result.AppendErrorWithFormat(
1056 "Failed to set the selected thread to thread id %" PRIu64 ".\n",
1057 thread->GetID());
1058 return;
1059 }
1060
1061 StreamString stream;
1062 Status error;
1063 if (synchronous_execution)
1064 error = process->ResumeSynchronous(&stream);
1065 else
1066 error = process->Resume();
1067
1068 if (error.Success()) {
1069 result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
1070 process->GetID());
1071 if (synchronous_execution) {
1072 // If any state changed events had anything to say, add that to the
1073 // result
1074 if (stream.GetSize() > 0)
1075 result.AppendMessage(stream.GetString());
1076
1077 result.SetDidChangeProcessState(true);
1079 } else {
1081 }
1082 } else {
1083 result.AppendErrorWithFormat("Failed to resume process: %s.\n",
1084 error.AsCString());
1085 }
1086 }
1087 }
1088
1090};
1091
1092// CommandObjectThreadSelect
1093
1094#define LLDB_OPTIONS_thread_select
1095#include "CommandOptions.inc"
1096
1098public:
1100 public:
1102
1103 ~OptionGroupThreadSelect() override = default;
1104
1105 void OptionParsingStarting(ExecutionContext *execution_context) override {
1107 }
1108
1109 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1110 ExecutionContext *execution_context) override {
1111 const int short_option = g_thread_select_options[option_idx].short_option;
1112 switch (short_option) {
1113 case 't': {
1114 if (option_arg.getAsInteger(0, m_thread_id)) {
1116 return Status("Invalid thread ID: '%s'.", option_arg.str().c_str());
1117 }
1118 break;
1119 }
1120
1121 default:
1122 llvm_unreachable("Unimplemented option");
1123 }
1124
1125 return {};
1126 }
1127
1128 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1129 return llvm::ArrayRef(g_thread_select_options);
1130 }
1131
1133 };
1134
1136 : CommandObjectParsed(interpreter, "thread select",
1137 "Change the currently selected thread.",
1138 "thread select <thread-index> (or -t <thread-id>)",
1139 eCommandRequiresProcess | eCommandTryTargetAPILock |
1140 eCommandProcessMustBeLaunched |
1141 eCommandProcessMustBePaused) {
1143 CommandArgumentData thread_idx_arg;
1144
1145 // Define the first (and only) variant of this arg.
1146 thread_idx_arg.arg_type = eArgTypeThreadIndex;
1147 thread_idx_arg.arg_repetition = eArgRepeatPlain;
1148 thread_idx_arg.arg_opt_set_association = LLDB_OPT_SET_1;
1149
1150 // There is only one variant this argument could be; put it into the
1151 // argument entry.
1152 arg.push_back(thread_idx_arg);
1153
1154 // Push the data for the first argument into the m_arguments vector.
1155 m_arguments.push_back(arg);
1156
1159 }
1160
1161 ~CommandObjectThreadSelect() override = default;
1162
1163 void
1165 OptionElementVector &opt_element_vector) override {
1166 if (request.GetCursorIndex())
1167 return;
1168
1171 nullptr);
1172 }
1173
1174 Options *GetOptions() override { return &m_option_group; }
1175
1176protected:
1177 void DoExecute(Args &command, CommandReturnObject &result) override {
1178 Process *process = m_exe_ctx.GetProcessPtr();
1179 if (process == nullptr) {
1180 result.AppendError("no process");
1181 return;
1183 command.GetArgumentCount() != 1) {
1184 result.AppendErrorWithFormat(
1185 "'%s' takes exactly one thread index argument, or a thread ID "
1186 "option:\nUsage: %s\n",
1187 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1188 return;
1190 command.GetArgumentCount() != 0) {
1191 result.AppendErrorWithFormat("'%s' cannot take both a thread ID option "
1192 "and a thread index argument:\nUsage: %s\n",
1193 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1194 return;
1195 }
1196
1197 Thread *new_thread = nullptr;
1198 if (command.GetArgumentCount() == 1) {
1199 uint32_t index_id;
1200 if (!llvm::to_integer(command.GetArgumentAtIndex(0), index_id)) {
1201 result.AppendErrorWithFormat("Invalid thread index '%s'",
1202 command.GetArgumentAtIndex(0));
1203 return;
1204 }
1205 new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get();
1206 if (new_thread == nullptr) {
1207 result.AppendErrorWithFormat("Invalid thread index #%s.\n",
1208 command.GetArgumentAtIndex(0));
1209 return;
1210 }
1211 } else {
1212 new_thread =
1214 if (new_thread == nullptr) {
1215 result.AppendErrorWithFormat("Invalid thread ID %" PRIu64 ".\n",
1217 return;
1218 }
1219 }
1220
1221 process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true);
1223 }
1224
1227};
1228
1229// CommandObjectThreadList
1230
1232public:
1235 interpreter, "thread list",
1236 "Show a summary of each thread in the current target process. "
1237 "Use 'settings set thread-format' to customize the individual "
1238 "thread listings.",
1239 "thread list",
1240 eCommandRequiresProcess | eCommandTryTargetAPILock |
1241 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1242
1243 ~CommandObjectThreadList() override = default;
1244
1245protected:
1246 void DoExecute(Args &command, CommandReturnObject &result) override {
1247 Stream &strm = result.GetOutputStream();
1249 Process *process = m_exe_ctx.GetProcessPtr();
1250 const bool only_threads_with_stop_reason = false;
1251 const uint32_t start_frame = 0;
1252 const uint32_t num_frames = 0;
1253 const uint32_t num_frames_with_source = 0;
1254 process->GetStatus(strm);
1255 process->GetThreadStatus(strm, only_threads_with_stop_reason, start_frame,
1256 num_frames, num_frames_with_source, false);
1257 }
1258};
1259
1260// CommandObjectThreadInfo
1261#define LLDB_OPTIONS_thread_info
1262#include "CommandOptions.inc"
1263
1265public:
1266 class CommandOptions : public Options {
1267 public:
1269
1270 ~CommandOptions() override = default;
1271
1272 void OptionParsingStarting(ExecutionContext *execution_context) override {
1273 m_json_thread = false;
1274 m_json_stopinfo = false;
1275 }
1276
1277 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1278 ExecutionContext *execution_context) override {
1279 const int short_option = m_getopt_table[option_idx].val;
1280 Status error;
1281
1282 switch (short_option) {
1283 case 'j':
1284 m_json_thread = true;
1285 break;
1286
1287 case 's':
1288 m_json_stopinfo = true;
1289 break;
1290
1291 default:
1292 llvm_unreachable("Unimplemented option");
1293 }
1294 return error;
1295 }
1296
1297 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1298 return llvm::ArrayRef(g_thread_info_options);
1299 }
1300
1303 };
1304
1307 interpreter, "thread info",
1308 "Show an extended summary of one or "
1309 "more threads. Defaults to the "
1310 "current thread.",
1311 "thread info",
1312 eCommandRequiresProcess | eCommandTryTargetAPILock |
1313 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
1314 m_add_return = false;
1315 }
1316
1317 ~CommandObjectThreadInfo() override = default;
1318
1319 void
1321 OptionElementVector &opt_element_vector) override {
1324 nullptr);
1325 }
1326
1327 Options *GetOptions() override { return &m_options; }
1328
1330 ThreadSP thread_sp =
1332 if (!thread_sp) {
1333 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1334 tid);
1335 return false;
1336 }
1337
1338 Thread *thread = thread_sp.get();
1339
1340 Stream &strm = result.GetOutputStream();
1341 if (!thread->GetDescription(strm, eDescriptionLevelFull,
1344 result.AppendErrorWithFormat("error displaying info for thread: \"%d\"\n",
1345 thread->GetIndexID());
1346 return false;
1347 }
1348 return true;
1349 }
1350
1352};
1353
1354// CommandObjectThreadException
1355
1357public:
1360 interpreter, "thread exception",
1361 "Display the current exception object for a thread. Defaults to "
1362 "the current thread.",
1363 "thread exception",
1364 eCommandRequiresProcess | eCommandTryTargetAPILock |
1365 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1366
1367 ~CommandObjectThreadException() override = default;
1368
1369 void
1371 OptionElementVector &opt_element_vector) override {
1374 nullptr);
1375 }
1376
1378 ThreadSP thread_sp =
1380 if (!thread_sp) {
1381 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1382 tid);
1383 return false;
1384 }
1385
1386 Stream &strm = result.GetOutputStream();
1387 ValueObjectSP exception_object_sp = thread_sp->GetCurrentException();
1388 if (exception_object_sp) {
1389 if (llvm::Error error = exception_object_sp->Dump(strm)) {
1390 result.AppendError(toString(std::move(error)));
1391 return false;
1392 }
1393 }
1394
1395 ThreadSP exception_thread_sp = thread_sp->GetCurrentExceptionBacktrace();
1396 if (exception_thread_sp && exception_thread_sp->IsValid()) {
1397 const uint32_t num_frames_with_source = 0;
1398 const bool stop_format = false;
1399 exception_thread_sp->GetStatus(strm, 0, UINT32_MAX,
1400 num_frames_with_source, stop_format);
1401 }
1402
1403 return true;
1404 }
1405};
1406
1408public:
1411 interpreter, "thread siginfo",
1412 "Display the current siginfo object for a thread. Defaults to "
1413 "the current thread.",
1414 "thread siginfo",
1415 eCommandRequiresProcess | eCommandTryTargetAPILock |
1416 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1417
1418 ~CommandObjectThreadSiginfo() override = default;
1419
1420 void
1422 OptionElementVector &opt_element_vector) override {
1425 nullptr);
1426 }
1427
1429 ThreadSP thread_sp =
1431 if (!thread_sp) {
1432 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1433 tid);
1434 return false;
1435 }
1436
1437 Stream &strm = result.GetOutputStream();
1438 if (!thread_sp->GetDescription(strm, eDescriptionLevelFull, false, false)) {
1439 result.AppendErrorWithFormat("error displaying info for thread: \"%d\"\n",
1440 thread_sp->GetIndexID());
1441 return false;
1442 }
1443 ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
1444 if (exception_object_sp) {
1445 if (llvm::Error error = exception_object_sp->Dump(strm)) {
1446 result.AppendError(toString(std::move(error)));
1447 return false;
1448 }
1449 } else
1450 strm.Printf("(no siginfo)\n");
1451 strm.PutChar('\n');
1452
1453 return true;
1454 }
1455};
1456
1457// CommandObjectThreadReturn
1458#define LLDB_OPTIONS_thread_return
1459#include "CommandOptions.inc"
1460
1462public:
1463 class CommandOptions : public Options {
1464 public:
1466 // Keep default values of all options in one place: OptionParsingStarting
1467 // ()
1468 OptionParsingStarting(nullptr);
1469 }
1470
1471 ~CommandOptions() override = default;
1472
1473 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1474 ExecutionContext *execution_context) override {
1475 Status error;
1476 const int short_option = m_getopt_table[option_idx].val;
1477
1478 switch (short_option) {
1479 case 'x': {
1480 bool success;
1481 bool tmp_value =
1482 OptionArgParser::ToBoolean(option_arg, false, &success);
1483 if (success)
1484 m_from_expression = tmp_value;
1485 else {
1486 error.SetErrorStringWithFormat(
1487 "invalid boolean value '%s' for 'x' option",
1488 option_arg.str().c_str());
1489 }
1490 } break;
1491 default:
1492 llvm_unreachable("Unimplemented option");
1493 }
1494 return error;
1495 }
1496
1497 void OptionParsingStarting(ExecutionContext *execution_context) override {
1498 m_from_expression = false;
1499 }
1500
1501 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1502 return llvm::ArrayRef(g_thread_return_options);
1503 }
1504
1505 bool m_from_expression = false;
1506
1507 // Instance variables to hold the values for command options.
1508 };
1509
1511 : CommandObjectRaw(interpreter, "thread return",
1512 "Prematurely return from a stack frame, "
1513 "short-circuiting execution of newer frames "
1514 "and optionally yielding a specified value. Defaults "
1515 "to the exiting the current stack "
1516 "frame.",
1517 "thread return",
1518 eCommandRequiresFrame | eCommandTryTargetAPILock |
1519 eCommandProcessMustBeLaunched |
1520 eCommandProcessMustBePaused) {
1522 }
1523
1524 ~CommandObjectThreadReturn() override = default;
1525
1526 Options *GetOptions() override { return &m_options; }
1527
1528protected:
1529 void DoExecute(llvm::StringRef command,
1530 CommandReturnObject &result) override {
1531 // I am going to handle this by hand, because I don't want you to have to
1532 // say:
1533 // "thread return -- -5".
1534 if (command.starts_with("-x")) {
1535 if (command.size() != 2U)
1536 result.AppendWarning("Return values ignored when returning from user "
1537 "called expressions");
1538
1539 Thread *thread = m_exe_ctx.GetThreadPtr();
1540 Status error;
1541 error = thread->UnwindInnermostExpression();
1542 if (!error.Success()) {
1543 result.AppendErrorWithFormat("Unwinding expression failed - %s.",
1544 error.AsCString());
1545 } else {
1546 bool success =
1548 if (success) {
1552 } else {
1553 result.AppendErrorWithFormat(
1554 "Could not select 0th frame after unwinding expression.");
1555 }
1556 }
1557 return;
1558 }
1559
1560 ValueObjectSP return_valobj_sp;
1561
1562 StackFrameSP frame_sp = m_exe_ctx.GetFrameSP();
1563 uint32_t frame_idx = frame_sp->GetFrameIndex();
1564
1565 if (frame_sp->IsInlined()) {
1566 result.AppendError("Don't know how to return from inlined frames.");
1567 return;
1568 }
1569
1570 if (!command.empty()) {
1571 Target *target = m_exe_ctx.GetTargetPtr();
1573
1574 options.SetUnwindOnError(true);
1576
1578 exe_results = target->EvaluateExpression(command, frame_sp.get(),
1579 return_valobj_sp, options);
1580 if (exe_results != eExpressionCompleted) {
1581 if (return_valobj_sp)
1582 result.AppendErrorWithFormat(
1583 "Error evaluating result expression: %s",
1584 return_valobj_sp->GetError().AsCString());
1585 else
1586 result.AppendErrorWithFormat(
1587 "Unknown error evaluating result expression.");
1588 return;
1589 }
1590 }
1591
1592 Status error;
1593 ThreadSP thread_sp = m_exe_ctx.GetThreadSP();
1594 const bool broadcast = true;
1595 error = thread_sp->ReturnFromFrame(frame_sp, return_valobj_sp, broadcast);
1596 if (!error.Success()) {
1597 result.AppendErrorWithFormat(
1598 "Error returning from frame %d of thread %d: %s.", frame_idx,
1599 thread_sp->GetIndexID(), error.AsCString());
1600 return;
1601 }
1602
1604 }
1605
1607};
1608
1609// CommandObjectThreadJump
1610#define LLDB_OPTIONS_thread_jump
1611#include "CommandOptions.inc"
1612
1614public:
1615 class CommandOptions : public Options {
1616 public:
1618
1619 ~CommandOptions() override = default;
1620
1621 void OptionParsingStarting(ExecutionContext *execution_context) override {
1623 m_line_num = 0;
1624 m_line_offset = 0;
1626 m_force = false;
1627 }
1628
1629 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1630 ExecutionContext *execution_context) override {
1631 const int short_option = m_getopt_table[option_idx].val;
1632 Status error;
1633
1634 switch (short_option) {
1635 case 'f':
1636 m_filenames.AppendIfUnique(FileSpec(option_arg));
1637 if (m_filenames.GetSize() > 1)
1638 return Status("only one source file expected.");
1639 break;
1640 case 'l':
1641 if (option_arg.getAsInteger(0, m_line_num))
1642 return Status("invalid line number: '%s'.", option_arg.str().c_str());
1643 break;
1644 case 'b':
1645 if (option_arg.getAsInteger(0, m_line_offset))
1646 return Status("invalid line offset: '%s'.", option_arg.str().c_str());
1647 break;
1648 case 'a':
1649 m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg,
1651 break;
1652 case 'r':
1653 m_force = true;
1654 break;
1655 default:
1656 llvm_unreachable("Unimplemented option");
1657 }
1658 return error;
1659 }
1660
1661 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1662 return llvm::ArrayRef(g_thread_jump_options);
1663 }
1664
1666 uint32_t m_line_num;
1670 };
1671
1674 interpreter, "thread jump",
1675 "Sets the program counter to a new address.", "thread jump",
1676 eCommandRequiresFrame | eCommandTryTargetAPILock |
1677 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1678
1679 ~CommandObjectThreadJump() override = default;
1680
1681 Options *GetOptions() override { return &m_options; }
1682
1683protected:
1684 void DoExecute(Args &args, CommandReturnObject &result) override {
1686 StackFrame *frame = m_exe_ctx.GetFramePtr();
1687 Thread *thread = m_exe_ctx.GetThreadPtr();
1688 Target *target = m_exe_ctx.GetTargetPtr();
1689 const SymbolContext &sym_ctx =
1690 frame->GetSymbolContext(eSymbolContextLineEntry);
1691
1693 // Use this address directly.
1695
1696 lldb::addr_t callAddr = dest.GetCallableLoadAddress(target);
1697 if (callAddr == LLDB_INVALID_ADDRESS) {
1698 result.AppendErrorWithFormat("Invalid destination address.");
1699 return;
1700 }
1701
1702 if (!reg_ctx->SetPC(callAddr)) {
1703 result.AppendErrorWithFormat("Error changing PC value for thread %d.",
1704 thread->GetIndexID());
1705 return;
1706 }
1707 } else {
1708 // Pick either the absolute line, or work out a relative one.
1709 int32_t line = (int32_t)m_options.m_line_num;
1710 if (line == 0)
1711 line = sym_ctx.line_entry.line + m_options.m_line_offset;
1712
1713 // Try the current file, but override if asked.
1714 FileSpec file = sym_ctx.line_entry.GetFile();
1715 if (m_options.m_filenames.GetSize() == 1)
1717
1718 if (!file) {
1719 result.AppendErrorWithFormat(
1720 "No source file available for the current location.");
1721 return;
1722 }
1723
1724 std::string warnings;
1725 Status err = thread->JumpToLine(file, line, m_options.m_force, &warnings);
1726
1727 if (err.Fail()) {
1728 result.SetError(err);
1729 return;
1730 }
1731
1732 if (!warnings.empty())
1733 result.AppendWarning(warnings.c_str());
1734 }
1735
1737 }
1738
1740};
1741
1742// Next are the subcommands of CommandObjectMultiwordThreadPlan
1743
1744// CommandObjectThreadPlanList
1745#define LLDB_OPTIONS_thread_plan_list
1746#include "CommandOptions.inc"
1747
1749public:
1750 class CommandOptions : public Options {
1751 public:
1753 // Keep default values of all options in one place: OptionParsingStarting
1754 // ()
1755 OptionParsingStarting(nullptr);
1756 }
1757
1758 ~CommandOptions() override = default;
1759
1760 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1761 ExecutionContext *execution_context) override {
1762 const int short_option = m_getopt_table[option_idx].val;
1763
1764 switch (short_option) {
1765 case 'i':
1766 m_internal = true;
1767 break;
1768 case 't':
1769 lldb::tid_t tid;
1770 if (option_arg.getAsInteger(0, tid))
1771 return Status("invalid tid: '%s'.", option_arg.str().c_str());
1772 m_tids.push_back(tid);
1773 break;
1774 case 'u':
1775 m_unreported = false;
1776 break;
1777 case 'v':
1778 m_verbose = true;
1779 break;
1780 default:
1781 llvm_unreachable("Unimplemented option");
1782 }
1783 return {};
1784 }
1785
1786 void OptionParsingStarting(ExecutionContext *execution_context) override {
1787 m_verbose = false;
1788 m_internal = false;
1789 m_unreported = true; // The variable is "skip unreported" and we want to
1790 // skip unreported by default.
1791 m_tids.clear();
1792 }
1793
1794 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1795 return llvm::ArrayRef(g_thread_plan_list_options);
1796 }
1797
1798 // Instance variables to hold the values for command options.
1802 std::vector<lldb::tid_t> m_tids;
1803 };
1804
1807 interpreter, "thread plan list",
1808 "Show thread plans for one or more threads. If no threads are "
1809 "specified, show the "
1810 "current thread. Use the thread-index \"all\" to see all threads.",
1811 nullptr,
1812 eCommandRequiresProcess | eCommandRequiresThread |
1813 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
1814 eCommandProcessMustBePaused) {}
1815
1816 ~CommandObjectThreadPlanList() override = default;
1817
1818 Options *GetOptions() override { return &m_options; }
1819
1820 void DoExecute(Args &command, CommandReturnObject &result) override {
1821 // If we are reporting all threads, dispatch to the Process to do that:
1822 if (command.GetArgumentCount() == 0 && m_options.m_tids.empty()) {
1823 Stream &strm = result.GetOutputStream();
1828 strm, desc_level, m_options.m_internal, true, m_options.m_unreported);
1830 return;
1831 } else {
1832 // Do any TID's that the user may have specified as TID, then do any
1833 // Thread Indexes...
1834 if (!m_options.m_tids.empty()) {
1835 Process *process = m_exe_ctx.GetProcessPtr();
1836 StreamString tmp_strm;
1837 for (lldb::tid_t tid : m_options.m_tids) {
1838 bool success = process->DumpThreadPlansForTID(
1840 true /* condense_trivial */, m_options.m_unreported);
1841 // If we didn't find a TID, stop here and return an error.
1842 if (!success) {
1843 result.AppendError("Error dumping plans:");
1844 result.AppendError(tmp_strm.GetString());
1845 return;
1846 }
1847 // Otherwise, add our data to the output:
1848 result.GetOutputStream() << tmp_strm.GetString();
1849 }
1850 }
1851 return CommandObjectIterateOverThreads::DoExecute(command, result);
1852 }
1853 }
1854
1855protected:
1857 // If we have already handled this from a -t option, skip it here.
1858 if (llvm::is_contained(m_options.m_tids, tid))
1859 return true;
1860
1861 Process *process = m_exe_ctx.GetProcessPtr();
1862
1863 Stream &strm = result.GetOutputStream();
1865 if (m_options.m_verbose)
1866 desc_level = eDescriptionLevelVerbose;
1867
1868 process->DumpThreadPlansForTID(strm, tid, desc_level, m_options.m_internal,
1869 true /* condense_trivial */,
1871 return true;
1872 }
1873
1875};
1876
1878public:
1880 : CommandObjectParsed(interpreter, "thread plan discard",
1881 "Discards thread plans up to and including the "
1882 "specified index (see 'thread plan list'.) "
1883 "Only user visible plans can be discarded.",
1884 nullptr,
1885 eCommandRequiresProcess | eCommandRequiresThread |
1886 eCommandTryTargetAPILock |
1887 eCommandProcessMustBeLaunched |
1888 eCommandProcessMustBePaused) {
1890 }
1891
1893
1894 void
1896 OptionElementVector &opt_element_vector) override {
1897 if (!m_exe_ctx.HasThreadScope() || request.GetCursorIndex())
1898 return;
1899
1901 }
1902
1903 void DoExecute(Args &args, CommandReturnObject &result) override {
1904 Thread *thread = m_exe_ctx.GetThreadPtr();
1905 if (args.GetArgumentCount() != 1) {
1906 result.AppendErrorWithFormat("Too many arguments, expected one - the "
1907 "thread plan index - but got %zu.",
1908 args.GetArgumentCount());
1909 return;
1910 }
1911
1912 uint32_t thread_plan_idx;
1913 if (!llvm::to_integer(args.GetArgumentAtIndex(0), thread_plan_idx)) {
1914 result.AppendErrorWithFormat(
1915 "Invalid thread index: \"%s\" - should be unsigned int.",
1916 args.GetArgumentAtIndex(0));
1917 return;
1918 }
1919
1920 if (thread_plan_idx == 0) {
1921 result.AppendErrorWithFormat(
1922 "You wouldn't really want me to discard the base thread plan.");
1923 return;
1924 }
1925
1926 if (thread->DiscardUserThreadPlansUpToIndex(thread_plan_idx)) {
1928 } else {
1929 result.AppendErrorWithFormat(
1930 "Could not find User thread plan with index %s.",
1931 args.GetArgumentAtIndex(0));
1932 }
1933 }
1934};
1935
1937public:
1939 : CommandObjectParsed(interpreter, "thread plan prune",
1940 "Removes any thread plans associated with "
1941 "currently unreported threads. "
1942 "Specify one or more TID's to remove, or if no "
1943 "TID's are provides, remove threads for all "
1944 "unreported threads",
1945 nullptr,
1946 eCommandRequiresProcess |
1947 eCommandTryTargetAPILock |
1948 eCommandProcessMustBeLaunched |
1949 eCommandProcessMustBePaused) {
1951 }
1952
1953 ~CommandObjectThreadPlanPrune() override = default;
1954
1955 void DoExecute(Args &args, CommandReturnObject &result) override {
1956 Process *process = m_exe_ctx.GetProcessPtr();
1957
1958 if (args.GetArgumentCount() == 0) {
1959 process->PruneThreadPlans();
1961 return;
1962 }
1963
1964 const size_t num_args = args.GetArgumentCount();
1965
1966 std::lock_guard<std::recursive_mutex> guard(
1967 process->GetThreadList().GetMutex());
1968
1969 for (size_t i = 0; i < num_args; i++) {
1970 lldb::tid_t tid;
1971 if (!llvm::to_integer(args.GetArgumentAtIndex(i), tid)) {
1972 result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n",
1973 args.GetArgumentAtIndex(i));
1974 return;
1975 }
1976 if (!process->PruneThreadPlansForTID(tid)) {
1977 result.AppendErrorWithFormat("Could not find unreported tid: \"%s\"\n",
1978 args.GetArgumentAtIndex(i));
1979 return;
1980 }
1981 }
1983 }
1984};
1985
1986// CommandObjectMultiwordThreadPlan
1987
1989public:
1992 interpreter, "plan",
1993 "Commands for managing thread plans that control execution.",
1994 "thread plan <subcommand> [<subcommand objects]") {
1996 "list", CommandObjectSP(new CommandObjectThreadPlanList(interpreter)));
1998 "discard",
2001 "prune",
2003 }
2004
2006};
2007
2008// Next are the subcommands of CommandObjectMultiwordTrace
2009
2010// CommandObjectTraceExport
2011
2013public:
2016 interpreter, "trace thread export",
2017 "Commands for exporting traces of the threads in the current "
2018 "process to different formats.",
2019 "thread trace export <export-plugin> [<subcommand objects>]") {
2020
2021 unsigned i = 0;
2022 for (llvm::StringRef plugin_name =
2024 !plugin_name.empty();
2026 if (ThreadTraceExportCommandCreator command_creator =
2028 LoadSubCommand(plugin_name, command_creator(interpreter));
2029 }
2030 }
2031 }
2032};
2033
2034// CommandObjectTraceStart
2035
2037public:
2040 /*live_debug_session_only=*/true, interpreter, "thread trace start",
2041 "Start tracing threads with the corresponding trace "
2042 "plug-in for the current process.",
2043 "thread trace start [<trace-options>]") {}
2044
2045protected:
2048 }
2049};
2050
2051// CommandObjectTraceStop
2052
2054public:
2057 interpreter, "thread trace stop",
2058 "Stop tracing threads, including the ones traced with the "
2059 "\"process trace start\" command."
2060 "Defaults to the current thread. Thread indices can be "
2061 "specified as arguments.\n Use the thread-index \"all\" to stop "
2062 "tracing "
2063 "for all existing threads.",
2064 "thread trace stop [<thread-index> <thread-index> ...]",
2065 eCommandRequiresProcess | eCommandTryTargetAPILock |
2066 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
2067 eCommandProcessMustBeTraced) {}
2068
2069 ~CommandObjectTraceStop() override = default;
2070
2072 llvm::ArrayRef<lldb::tid_t> tids) override {
2073 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
2074
2075 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
2076
2077 if (llvm::Error err = trace_sp->Stop(tids))
2078 result.AppendError(toString(std::move(err)));
2079 else
2081
2082 return result.Succeeded();
2083 }
2084};
2085
2087 CommandReturnObject &result) {
2088 if (args.GetArgumentCount() == 0)
2089 return exe_ctx.GetThreadSP();
2090
2091 const char *arg = args.GetArgumentAtIndex(0);
2092 uint32_t thread_idx;
2093
2094 if (!llvm::to_integer(arg, thread_idx)) {
2095 result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n", arg);
2096 return nullptr;
2097 }
2098 ThreadSP thread_sp =
2099 exe_ctx.GetProcessRef().GetThreadList().FindThreadByIndexID(thread_idx);
2100 if (!thread_sp)
2101 result.AppendErrorWithFormat("no thread with index: \"%s\"\n", arg);
2102 return thread_sp;
2103}
2104
2105// CommandObjectTraceDumpFunctionCalls
2106#define LLDB_OPTIONS_thread_trace_dump_function_calls
2107#include "CommandOptions.inc"
2108
2110public:
2111 class CommandOptions : public Options {
2112 public:
2114
2115 ~CommandOptions() override = default;
2116
2117 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2118 ExecutionContext *execution_context) override {
2119 Status error;
2120 const int short_option = m_getopt_table[option_idx].val;
2121
2122 switch (short_option) {
2123 case 'j': {
2124 m_dumper_options.json = true;
2125 break;
2126 }
2127 case 'J': {
2128 m_dumper_options.json = true;
2130 break;
2131 }
2132 case 'F': {
2133 m_output_file.emplace(option_arg);
2134 break;
2135 }
2136 default:
2137 llvm_unreachable("Unimplemented option");
2138 }
2139 return error;
2140 }
2141
2142 void OptionParsingStarting(ExecutionContext *execution_context) override {
2143 m_dumper_options = {};
2144 m_output_file = std::nullopt;
2145 }
2146
2147 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2148 return llvm::ArrayRef(g_thread_trace_dump_function_calls_options);
2149 }
2150
2151 static const size_t kDefaultCount = 20;
2152
2153 // Instance variables to hold the values for command options.
2155 std::optional<FileSpec> m_output_file;
2156 };
2157
2160 interpreter, "thread trace dump function-calls",
2161 "Dump the traced function-calls for one thread. If no "
2162 "thread is specified, the current thread is used.",
2163 nullptr,
2164 eCommandRequiresProcess | eCommandRequiresThread |
2165 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
2166 eCommandProcessMustBePaused | eCommandProcessMustBeTraced) {
2168 }
2169
2171
2172 Options *GetOptions() override { return &m_options; }
2173
2174protected:
2175 void DoExecute(Args &args, CommandReturnObject &result) override {
2176 ThreadSP thread_sp = GetSingleThreadFromArgs(m_exe_ctx, args, result);
2177 if (!thread_sp) {
2178 result.AppendError("invalid thread\n");
2179 return;
2180 }
2181
2182 llvm::Expected<TraceCursorSP> cursor_or_error =
2183 m_exe_ctx.GetTargetSP()->GetTrace()->CreateNewCursor(*thread_sp);
2184
2185 if (!cursor_or_error) {
2186 result.AppendError(llvm::toString(cursor_or_error.takeError()));
2187 return;
2188 }
2189 TraceCursorSP &cursor_sp = *cursor_or_error;
2190
2191 std::optional<StreamFile> out_file;
2193 out_file.emplace(m_options.m_output_file->GetPath().c_str(),
2196 }
2197
2199
2200 TraceDumper dumper(std::move(cursor_sp),
2201 out_file ? *out_file : result.GetOutputStream(),
2203
2204 dumper.DumpFunctionCalls();
2205 }
2206
2208};
2209
2210// CommandObjectTraceDumpInstructions
2211#define LLDB_OPTIONS_thread_trace_dump_instructions
2212#include "CommandOptions.inc"
2213
2215public:
2216 class CommandOptions : public Options {
2217 public:
2219
2220 ~CommandOptions() override = default;
2221
2222 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2223 ExecutionContext *execution_context) override {
2224 Status error;
2225 const int short_option = m_getopt_table[option_idx].val;
2226
2227 switch (short_option) {
2228 case 'c': {
2229 int32_t count;
2230 if (option_arg.empty() || option_arg.getAsInteger(0, count) ||
2231 count < 0)
2232 error.SetErrorStringWithFormat(
2233 "invalid integer value for option '%s'",
2234 option_arg.str().c_str());
2235 else
2236 m_count = count;
2237 break;
2238 }
2239 case 'a': {
2240 m_count = std::numeric_limits<decltype(m_count)>::max();
2241 break;
2242 }
2243 case 's': {
2244 int32_t skip;
2245 if (option_arg.empty() || option_arg.getAsInteger(0, skip) || skip < 0)
2246 error.SetErrorStringWithFormat(
2247 "invalid integer value for option '%s'",
2248 option_arg.str().c_str());
2249 else
2250 m_dumper_options.skip = skip;
2251 break;
2252 }
2253 case 'i': {
2254 uint64_t id;
2255 if (option_arg.empty() || option_arg.getAsInteger(0, id))
2256 error.SetErrorStringWithFormat(
2257 "invalid integer value for option '%s'",
2258 option_arg.str().c_str());
2259 else
2261 break;
2262 }
2263 case 'F': {
2264 m_output_file.emplace(option_arg);
2265 break;
2266 }
2267 case 'r': {
2268 m_dumper_options.raw = true;
2269 break;
2270 }
2271 case 'f': {
2273 break;
2274 }
2275 case 'k': {
2277 break;
2278 }
2279 case 't': {
2281 break;
2282 }
2283 case 'e': {
2285 break;
2286 }
2287 case 'j': {
2288 m_dumper_options.json = true;
2289 break;
2290 }
2291 case 'J': {
2293 m_dumper_options.json = true;
2294 break;
2295 }
2296 case 'E': {
2299 break;
2300 }
2301 case 'C': {
2302 m_continue = true;
2303 break;
2304 }
2305 default:
2306 llvm_unreachable("Unimplemented option");
2307 }
2308 return error;
2309 }
2310
2311 void OptionParsingStarting(ExecutionContext *execution_context) override {
2313 m_continue = false;
2314 m_output_file = std::nullopt;
2315 m_dumper_options = {};
2316 }
2317
2318 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2319 return llvm::ArrayRef(g_thread_trace_dump_instructions_options);
2320 }
2321
2322 static const size_t kDefaultCount = 20;
2323
2324 // Instance variables to hold the values for command options.
2325 size_t m_count;
2327 std::optional<FileSpec> m_output_file;
2329 };
2330
2333 interpreter, "thread trace dump instructions",
2334 "Dump the traced instructions for one thread. If no "
2335 "thread is specified, show the current thread.",
2336 nullptr,
2337 eCommandRequiresProcess | eCommandRequiresThread |
2338 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
2339 eCommandProcessMustBePaused | eCommandProcessMustBeTraced) {
2341 }
2342
2344
2345 Options *GetOptions() override { return &m_options; }
2346
2347 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
2348 uint32_t index) override {
2349 std::string cmd;
2350 current_command_args.GetCommandString(cmd);
2351 if (cmd.find(" --continue") == std::string::npos)
2352 cmd += " --continue";
2353 return cmd;
2354 }
2355
2356protected:
2357 void DoExecute(Args &args, CommandReturnObject &result) override {
2358 ThreadSP thread_sp = GetSingleThreadFromArgs(m_exe_ctx, args, result);
2359 if (!thread_sp) {
2360 result.AppendError("invalid thread\n");
2361 return;
2362 }
2363
2365 // We set up the options to continue one instruction past where
2366 // the previous iteration stopped.
2369 }
2370
2371 llvm::Expected<TraceCursorSP> cursor_or_error =
2372 m_exe_ctx.GetTargetSP()->GetTrace()->CreateNewCursor(*thread_sp);
2373
2374 if (!cursor_or_error) {
2375 result.AppendError(llvm::toString(cursor_or_error.takeError()));
2376 return;
2377 }
2378 TraceCursorSP &cursor_sp = *cursor_or_error;
2379
2381 !cursor_sp->HasId(*m_options.m_dumper_options.id)) {
2382 result.AppendError("invalid instruction id\n");
2383 return;
2384 }
2385
2386 std::optional<StreamFile> out_file;
2388 out_file.emplace(m_options.m_output_file->GetPath().c_str(),
2391 }
2392
2393 if (m_options.m_continue && !m_last_id) {
2394 // We need to stop processing data when we already ran out of instructions
2395 // in a previous command. We can fake this by setting the cursor past the
2396 // end of the trace.
2397 cursor_sp->Seek(1, lldb::eTraceCursorSeekTypeEnd);
2398 }
2399
2400 TraceDumper dumper(std::move(cursor_sp),
2401 out_file ? *out_file : result.GetOutputStream(),
2403
2405 }
2406
2408 // Last traversed id used to continue a repeat command. std::nullopt means
2409 // that all the trace has been consumed.
2410 std::optional<lldb::user_id_t> m_last_id;
2411};
2412
2413// CommandObjectTraceDumpInfo
2414#define LLDB_OPTIONS_thread_trace_dump_info
2415#include "CommandOptions.inc"
2416
2418public:
2419 class CommandOptions : public Options {
2420 public:
2422
2423 ~CommandOptions() override = default;
2424
2425 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2426 ExecutionContext *execution_context) override {
2427 Status error;
2428 const int short_option = m_getopt_table[option_idx].val;
2429
2430 switch (short_option) {
2431 case 'v': {
2432 m_verbose = true;
2433 break;
2434 }
2435 case 'j': {
2436 m_json = true;
2437 break;
2438 }
2439 default:
2440 llvm_unreachable("Unimplemented option");
2441 }
2442 return error;
2443 }
2444
2445 void OptionParsingStarting(ExecutionContext *execution_context) override {
2446 m_verbose = false;
2447 m_json = false;
2448 }
2449
2450 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2451 return llvm::ArrayRef(g_thread_trace_dump_info_options);
2452 }
2453
2454 // Instance variables to hold the values for command options.
2457 };
2458
2461 interpreter, "thread trace dump info",
2462 "Dump the traced information for one or more threads. If no "
2463 "threads are specified, show the current thread. Use the "
2464 "thread-index \"all\" to see all threads.",
2465 nullptr,
2466 eCommandRequiresProcess | eCommandTryTargetAPILock |
2467 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
2468 eCommandProcessMustBeTraced) {}
2469
2470 ~CommandObjectTraceDumpInfo() override = default;
2471
2472 Options *GetOptions() override { return &m_options; }
2473
2474protected:
2476 const TraceSP &trace_sp = m_exe_ctx.GetTargetSP()->GetTrace();
2477 ThreadSP thread_sp =
2479 trace_sp->DumpTraceInfo(*thread_sp, result.GetOutputStream(),
2481 return true;
2482 }
2483
2485};
2486
2487// CommandObjectMultiwordTraceDump
2489public:
2492 interpreter, "dump",
2493 "Commands for displaying trace information of the threads "
2494 "in the current process.",
2495 "thread trace dump <subcommand> [<subcommand objects>]") {
2497 "instructions",
2500 "function-calls",
2503 "info", CommandObjectSP(new CommandObjectTraceDumpInfo(interpreter)));
2504 }
2506};
2507
2508// CommandObjectMultiwordTrace
2510public:
2513 interpreter, "trace",
2514 "Commands for operating on traces of the threads in the current "
2515 "process.",
2516 "thread trace <subcommand> [<subcommand objects>]") {
2518 interpreter)));
2519 LoadSubCommand("start",
2520 CommandObjectSP(new CommandObjectTraceStart(interpreter)));
2521 LoadSubCommand("stop",
2522 CommandObjectSP(new CommandObjectTraceStop(interpreter)));
2523 LoadSubCommand("export",
2524 CommandObjectSP(new CommandObjectTraceExport(interpreter)));
2525 }
2526
2527 ~CommandObjectMultiwordTrace() override = default;
2528};
2529
2530// CommandObjectMultiwordThread
2531
2533 CommandInterpreter &interpreter)
2534 : CommandObjectMultiword(interpreter, "thread",
2535 "Commands for operating on "
2536 "one or more threads in "
2537 "the current process.",
2538 "thread <subcommand> [<subcommand-options>]") {
2540 interpreter)));
2541 LoadSubCommand("continue",
2543 LoadSubCommand("list",
2544 CommandObjectSP(new CommandObjectThreadList(interpreter)));
2545 LoadSubCommand("return",
2546 CommandObjectSP(new CommandObjectThreadReturn(interpreter)));
2547 LoadSubCommand("jump",
2548 CommandObjectSP(new CommandObjectThreadJump(interpreter)));
2549 LoadSubCommand("select",
2550 CommandObjectSP(new CommandObjectThreadSelect(interpreter)));
2551 LoadSubCommand("until",
2552 CommandObjectSP(new CommandObjectThreadUntil(interpreter)));
2553 LoadSubCommand("info",
2554 CommandObjectSP(new CommandObjectThreadInfo(interpreter)));
2556 interpreter)));
2557 LoadSubCommand("siginfo",
2559 LoadSubCommand("step-in",
2561 interpreter, "thread step-in",
2562 "Source level single step, stepping into calls. Defaults "
2563 "to current thread unless specified.",
2564 nullptr, eStepTypeInto, eStepScopeSource)));
2565
2566 LoadSubCommand("step-out",
2568 interpreter, "thread step-out",
2569 "Finish executing the current stack frame and stop after "
2570 "returning. Defaults to current thread unless specified.",
2571 nullptr, eStepTypeOut, eStepScopeSource)));
2572
2573 LoadSubCommand("step-over",
2575 interpreter, "thread step-over",
2576 "Source level single step, stepping over calls. Defaults "
2577 "to current thread unless specified.",
2578 nullptr, eStepTypeOver, eStepScopeSource)));
2579
2580 LoadSubCommand("step-inst",
2582 interpreter, "thread step-inst",
2583 "Instruction level single step, stepping into calls. "
2584 "Defaults to current thread unless specified.",
2586
2587 LoadSubCommand("step-inst-over",
2589 interpreter, "thread step-inst-over",
2590 "Instruction level single step, stepping over calls. "
2591 "Defaults to current thread unless specified.",
2593
2595 "step-scripted",
2597 interpreter, "thread step-scripted",
2598 "Step as instructed by the script class passed in the -C option. "
2599 "You can also specify a dictionary of key (-k) and value (-v) pairs "
2600 "that will be used to populate an SBStructuredData Dictionary, which "
2601 "will be passed to the constructor of the class implementing the "
2602 "scripted step. See the Python Reference for more details.",
2604
2606 interpreter)));
2607 LoadSubCommand("trace",
2609}
2610
static ThreadSP GetSingleThreadFromArgs(ExecutionContext &exe_ctx, Args &args, CommandReturnObject &result)
@ eStepScopeInstruction
@ eStepScopeSource
static llvm::raw_ostream & error(Stream &strm)
#define INTERRUPT_REQUESTED(debugger,...)
This handy define will keep you from having to generate a report for the interruption by hand.
Definition: Debugger.h:446
~CommandObjectMultiwordThreadPlan() override=default
CommandObjectMultiwordThreadPlan(CommandInterpreter &interpreter)
~CommandObjectMultiwordTraceDump() override=default
CommandObjectMultiwordTraceDump(CommandInterpreter &interpreter)
CommandObjectMultiwordTrace(CommandInterpreter &interpreter)
~CommandObjectMultiwordTrace() override=default
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
CommandObjectThreadBacktrace(CommandInterpreter &interpreter)
std::optional< std::string > GetRepeatCommand(Args &current_args, uint32_t index) override
Get the command that appropriate for a "repeat" of the current command.
void DoExtendedBacktrace(Thread *thread, CommandReturnObject &result)
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override
~CommandObjectThreadBacktrace() override=default
~CommandObjectThreadContinue() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectThreadContinue(CommandInterpreter &interpreter)
CommandObjectThreadException(CommandInterpreter &interpreter)
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override
~CommandObjectThreadException() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
CommandObjectThreadInfo(CommandInterpreter &interpreter)
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override
~CommandObjectThreadInfo() override=default
Options * GetOptions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
CommandObjectThreadJump(CommandInterpreter &interpreter)
void DoExecute(Args &args, CommandReturnObject &result) override
~CommandObjectThreadJump() override=default
Options * GetOptions() override
void DoExecute(Args &command, CommandReturnObject &result) override
~CommandObjectThreadList() override=default
CommandObjectThreadList(CommandInterpreter &interpreter)
void DoExecute(Args &args, CommandReturnObject &result) override
CommandObjectThreadPlanDiscard(CommandInterpreter &interpreter)
~CommandObjectThreadPlanDiscard() override=default
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
CommandObjectThreadPlanList(CommandInterpreter &interpreter)
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override
~CommandObjectThreadPlanList() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectThreadPlanPrune(CommandInterpreter &interpreter)
~CommandObjectThreadPlanPrune() override=default
void DoExecute(Args &args, CommandReturnObject &result) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
CommandObjectThreadReturn(CommandInterpreter &interpreter)
void DoExecute(llvm::StringRef command, CommandReturnObject &result) override
~CommandObjectThreadReturn() override=default
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void DoExecute(Args &command, CommandReturnObject &result) override
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
CommandObjectThreadSelect(CommandInterpreter &interpreter)
~CommandObjectThreadSelect() override=default
OptionGroupThreadSelect m_options
~CommandObjectThreadSiginfo() override=default
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override
CommandObjectThreadSiginfo(CommandInterpreter &interpreter)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
OptionGroupPythonClassWithDict m_class_options
~CommandObjectThreadStepWithTypeAndScope() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectThreadStepWithTypeAndScope(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, StepType step_type, StepScope step_scope)
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
Options * GetOptions() override
CommandObjectThreadUntil(CommandInterpreter &interpreter)
~CommandObjectThreadUntil() override=default
void DoExecute(Args &command, CommandReturnObject &result) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
void OptionParsingStarting(ExecutionContext *execution_context) override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void DoExecute(Args &args, CommandReturnObject &result) override
CommandObjectTraceDumpFunctionCalls(CommandInterpreter &interpreter)
~CommandObjectTraceDumpFunctionCalls() override=default
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
~CommandObjectTraceDumpInfo() override=default
bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override
CommandObjectTraceDumpInfo(CommandInterpreter &interpreter)
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
Set the value of an option.
void OptionParsingStarting(ExecutionContext *execution_context) override
CommandObjectTraceDumpInstructions(CommandInterpreter &interpreter)
~CommandObjectTraceDumpInstructions() override=default
std::optional< std::string > GetRepeatCommand(Args &current_command_args, uint32_t index) override
Get the command that appropriate for a "repeat" of the current command.
void DoExecute(Args &args, CommandReturnObject &result) override
std::optional< lldb::user_id_t > m_last_id
CommandObjectTraceExport(CommandInterpreter &interpreter)
lldb::CommandObjectSP GetDelegateCommand(Trace &trace) override
CommandObjectTraceStart(CommandInterpreter &interpreter)
~CommandObjectTraceStop() override=default
bool DoExecuteOnThreads(Args &command, CommandReturnObject &result, llvm::ArrayRef< lldb::tid_t > tids) override
CommandObjectTraceStop(CommandInterpreter &interpreter)
void OptionParsingStarting(ExecutionContext *execution_context) override
~ThreadStepScopeOptionGroup() override=default
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, ExecutionContext *execution_context) override
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
bool ContainsLoadAddress(const Address &so_addr, Target *target) const
Check if a section offset so_addr when represented as a load address is contained within this object'...
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:223
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:313
lldb::addr_t GetCallableLoadAddress(Target *target, bool is_indirect=false) const
Get the load address as a callable code load address.
Definition: Address.cpp:338
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:439
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:329
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
A command line argument class.
Definition: Args.h:33
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Definition: Args.h:116
void ReplaceArgumentAtIndex(size_t idx, llvm::StringRef arg_str, char quote_char='\0')
Replaces the argument value at index idx to arg_str if idx is a valid argument index.
Definition: Args.cpp:337
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
Definition: Args.cpp:322
llvm::ArrayRef< ArgEntry > entries() const
Definition: Args.h:128
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:263
bool GetCommandString(std::string &command) const
Definition: Args.cpp:211
bool GetQuotedCommandString(std::string &command) const
Definition: Args.cpp:228
A class that describes a single lexical block.
Definition: Block.h:41
bool GetRangeContainingAddress(const Address &addr, AddressRange &range)
Definition: Block.cpp:250
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
void DoExecute(Args &command, CommandReturnObject &result) override
Class similar to CommandObjectIterateOverThreads, but which performs an action on multiple threads at...
CommandObjectMultiwordThread(CommandInterpreter &interpreter)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
This class works by delegating the logic to the actual trace plug-in that can support the current pro...
std::vector< CommandArgumentData > CommandArgumentEntry
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
ExecutionContext m_exe_ctx
std::vector< CommandArgumentEntry > m_arguments
CommandInterpreter & GetCommandInterpreter()
CommandInterpreter & m_interpreter
virtual void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector)
The default version handles argument definitions that have only one argument type,...
virtual llvm::StringRef GetSyntax()
void AppendMessage(llvm::StringRef in_string)
void void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void AppendMessageWithFormat(const char *format,...) __attribute__((format(printf
void void AppendWarning(llvm::StringRef in_string)
void SetError(const Status &error, const char *fallback_error_cstr=nullptr)
uint32_t FindLineEntry(uint32_t start_idx, uint32_t line, const FileSpec *file_spec_ptr, bool exact, LineEntry *line_entry)
Find the line entry by line and optional inlined file spec.
LineTable * GetLineTable()
Get the line table for the compile unit.
"lldb/Utility/ArgCompletionRequest.h"
void SetUnwindOnError(bool unwind=false)
Definition: Target.h:343
void SetUseDynamic(lldb::DynamicValueType dynamic=lldb::eDynamicCanRunTarget)
Definition: Target.h:358
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void SetFrameSP(const lldb::StackFrameSP &frame_sp)
Set accessor to set only the frame shared pointer.
bool HasThreadScope() const
Returns true the ExecutionContext object contains a valid target, process, and thread.
const lldb::TargetSP & GetTargetSP() const
Get accessor to get the target shared pointer.
const lldb::ProcessSP & GetProcessSP() const
Get accessor to get the process shared pointer.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
const lldb::StackFrameSP & GetFrameSP() const
Get accessor to get the frame shared pointer.
Process & GetProcessRef() const
Returns a reference to the process object.
Target * GetTargetPtr() const
Returns a pointer to the target object.
const lldb::ThreadSP & GetThreadSP() const
Get accessor to get the thread shared pointer.
Process * GetProcessPtr() const
Returns a pointer to the process object.
RegisterContext * GetRegisterContext() const
Thread * GetThreadPtr() const
Returns a pointer to the thread object.
A file collection class.
Definition: FileSpecList.h:85
const FileSpec & GetFileSpecAtIndex(size_t idx) const
Get file at index.
void Clear()
Clears the file list.
size_t GetSize() const
Get the number of files in the file list.
bool AppendIfUnique(const FileSpec &file)
Append a FileSpec object if unique.
A file utility class.
Definition: FileSpec.h:56
@ eOpenOptionWriteOnly
Definition: File.h:52
@ eOpenOptionCanCreate
Definition: File.h:56
@ eOpenOptionTruncate
Definition: File.h:57
const AddressRange & GetAddressRange()
Definition: Function.h:447
A line table class.
Definition: LineTable.h:40
bool FindLineEntryByAddress(const Address &so_addr, LineEntry &line_entry, uint32_t *index_ptr=nullptr)
Find a line entry that contains the section offset address so_addr.
Definition: LineTable.cpp:188
void Append(OptionGroup *group)
Append options from a OptionGroup class.
Definition: Options.cpp:755
const StructuredData::DictionarySP GetStructuredData()
A command line option parsing protocol class.
Definition: Options.h:58
std::vector< Option > m_getopt_table
Definition: Options.h:198
static llvm::StringRef GetTraceExporterPluginNameAtIndex(uint32_t index)
static ThreadTraceExportCommandCreator GetThreadTraceExportCommandCreatorAtIndex(uint32_t index)
Return the callback used to create the CommandObject that will be listed under "thread trace export".
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition: Process.h:540
ThreadList & GetThreadList()
Definition: Process.h:2215
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition: Process.cpp:1379
void PruneThreadPlans()
Prune ThreadPlanStacks for all unreported threads.
Definition: Process.cpp:1271
bool PruneThreadPlansForTID(lldb::tid_t tid)
Prune ThreadPlanStacks for unreported threads.
Definition: Process.cpp:1267
bool DumpThreadPlansForTID(Stream &strm, lldb::tid_t tid, lldb::DescriptionLevel desc_level, bool internal, bool condense_trivial, bool skip_unreported_plans)
Dump the thread plans associated with thread with tid.
Definition: Process.cpp:1275
Status ResumeSynchronous(Stream *stream)
Resume a process, and wait for it to stop.
Definition: Process.cpp:1396
size_t GetThreadStatus(Stream &ostrm, bool only_threads_with_stop_reason, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source, bool stop_format)
Definition: Process.cpp:5772
lldb::StateType GetState()
Get accessor for the current process state.
Definition: Process.cpp:1332
void GetStatus(Stream &ostrm)
Definition: Process.cpp:5752
uint32_t GetIOHandlerID() const
Definition: Process.h:2277
void DumpThreadPlans(Stream &strm, lldb::DescriptionLevel desc_level, bool internal, bool condense_trivial, bool skip_unreported_plans)
Dump all the thread plans for this process.
Definition: Process.cpp:1282
void SyncIOHandler(uint32_t iohandler_id, const Timeout< std::micro > &timeout)
Waits for the process state to be running within a given msec timeout.
Definition: Process.cpp:661
This base class provides an interface to stack frames.
Definition: StackFrame.h:43
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:300
bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
Definition: StackFrame.cpp:190
An error handling class.
Definition: Status.h:44
bool Fail() const
Test for error condition.
Definition: Status.cpp:180
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutChar(char ch)
Definition: Stream.cpp:131
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
Block * block
The Block for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
LineEntry line_entry
The LineEntry for a given query.
bool GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range, Status &error)
A plug-in interface definition class for system runtimes.
Definition: SystemRuntime.h:43
virtual lldb::ThreadSP GetExtendedBacktraceThread(lldb::ThreadSP thread, ConstString type)
Return a Thread which shows the origin of this thread's creation.
virtual const std::vector< ConstString > & GetExtendedBacktraceTypes()
Return a list of thread origin extended backtraces that may be available.
lldb::ExpressionResults EvaluateExpression(llvm::StringRef expression, ExecutionContextScope *exe_scope, lldb::ValueObjectSP &result_valobj_sp, const EvaluateExpressionOptions &options=EvaluateExpressionOptions(), std::string *fixed_expression=nullptr, ValueObject *ctx_obj=nullptr)
Definition: Target.cpp:2650
uint32_t GetSize(bool can_update=true)
Definition: ThreadList.cpp:82
bool SetSelectedThreadByID(lldb::tid_t tid, bool notify=false)
Definition: ThreadList.cpp:695
lldb::ThreadSP FindThreadByIndexID(uint32_t index_id, bool can_update=true)
Definition: ThreadList.cpp:208
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
Definition: ThreadList.cpp:90
std::recursive_mutex & GetMutex() const override
Definition: ThreadList.cpp:787
lldb::ThreadSP FindThreadByID(lldb::tid_t tid, bool can_update=true)
Definition: ThreadList.cpp:102
virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut(bool abort_other_plans, SymbolContext *addr_context, bool first_insn, bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote, uint32_t frame_idx, Status &status, LazyBool step_out_avoids_code_without_debug_info=eLazyBoolCalculate)
Queue the plan used to step out of the function at the current PC of thread.
Definition: Thread.cpp:1310
Status UnwindInnermostExpression()
Unwinds the thread stack for the innermost expression plan currently on the thread plan stack.
Definition: Thread.cpp:1227
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:406
virtual lldb::ThreadPlanSP QueueThreadPlanForStepUntil(bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses, bool stop_others, uint32_t frame_idx, Status &status)
Definition: Thread.cpp:1366
void AutoCompleteThreadPlans(CompletionRequest &request) const
Format the thread plan information for auto completion.
Definition: Thread.cpp:1108
uint32_t GetIndexID() const
Definition: Thread.cpp:1388
bool GetDescription(Stream &s, lldb::DescriptionLevel level, bool print_json_thread, bool print_json_stopinfo)
Definition: Thread.cpp:1793
void SetResumeState(lldb::StateType state, bool override_suspend=false)
Sets the USER resume state for this thread.
Definition: Thread.h:185
lldb::StackFrameSP GetSelectedFrame(SelectMostRelevant select_most_relevant)
Definition: Thread.cpp:265
bool DiscardUserThreadPlansUpToIndex(uint32_t thread_index)
Discards the plans queued on the plan stack of the current thread up to and including the plan in tha...
Definition: Thread.cpp:1186
uint32_t GetSelectedFrameIndex(SelectMostRelevant select_most_relevant)
Definition: Thread.h:442
lldb::ProcessSP GetProcess() const
Definition: Thread.h:155
virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange(bool abort_other_plans, const AddressRange &range, const SymbolContext &addr_context, const char *step_in_target, lldb::RunMode stop_other_threads, Status &status, LazyBool step_in_avoids_code_without_debug_info=eLazyBoolCalculate, LazyBool step_out_avoids_code_without_debug_info=eLazyBoolCalculate)
Queues the plan used to step through an address range, stepping into functions.
Definition: Thread.cpp:1280
virtual lldb::ThreadPlanSP QueueThreadPlanForStepScripted(bool abort_other_plans, const char *class_name, StructuredData::ObjectSP extra_args_sp, bool stop_other_threads, Status &status)
Definition: Thread.cpp:1376
virtual lldb::ThreadPlanSP QueueThreadPlanForStepSingleInstruction(bool step_over, bool abort_other_plans, bool stop_other_threads, Status &status)
Queues the plan used to step one instruction from the current PC of thread.
Definition: Thread.cpp:1244
Status JumpToLine(const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings=nullptr)
Definition: Thread.cpp:1551
virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange(bool abort_other_plans, const AddressRange &range, const SymbolContext &addr_context, lldb::RunMode stop_other_threads, Status &status, LazyBool step_out_avoids_code_without_debug_info=eLazyBoolCalculate)
Queues the plan used to step through an address range, stepping over function calls.
Definition: Thread.cpp:1253
size_t GetStatus(Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source, bool stop_format, bool only_stacks=false)
Definition: Thread.cpp:1736
bool SetSelectedFrameByIndexNoisily(uint32_t frame_idx, Stream &output_stream)
Definition: Thread.cpp:294
Class used to dump the instructions of a TraceCursor using its current state and granularity.
Definition: TraceDumper.h:51
std::optional< lldb::user_id_t > DumpInstructions(size_t count)
Dump count instructions of the thread trace starting at the current cursor position.
void DumpFunctionCalls()
Dump all function calls forwards chronologically and hierarchically.
A plug-in interface definition class for trace information.
Definition: Trace.h:48
virtual lldb::CommandObjectSP GetThreadTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "thread trace start" command.
#define LLDB_OPT_SET_1
Definition: lldb-defines.h:111
#define LLDB_OPT_SET_2
Definition: lldb-defines.h:112
#define LLDB_INVALID_LINE_NUMBER
Definition: lldb-defines.h:94
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:90
#define LLDB_INVALID_INDEX32
Definition: lldb-defines.h:83
#define LLDB_OPT_SET_ALL
Definition: lldb-defines.h:110
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
#define LLDB_INVALID_FRAME_ID
Definition: lldb-defines.h:91
@ DoNoSelectMostRelevantFrame
A class that represents a running process on the host machine.
std::vector< OptionArgElement > OptionElementVector
Definition: Options.h:43
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
const char * toString(AppleArm64ExceptionClass EC)
lldb::CommandObjectSP(* ThreadTraceExportCommandCreator)(CommandInterpreter &interpreter)
@ eStepTypeTraceOver
Single step one instruction, stepping over.
@ eStepTypeOut
Single step out a specified context.
@ eStepTypeScripted
A step type implemented by the script interpreter.
@ eStepTypeInto
Single step into a specified context.
@ eStepTypeOver
Single step over a specified context.
@ eStepTypeTrace
Single step one instruction.
Definition: SBAddress.h:15
@ eThreadIndexCompletion
std::shared_ptr< lldb_private::Trace > TraceSP
Definition: lldb-forward.h:453
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
Definition: lldb-forward.h:448
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:419
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelFull
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:445
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:330
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:479
StateType
Process and Thread States.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eStateSuspended
Process or thread is in a suspended state as far as the debugger is concerned while other processes o...
@ eStateRunning
Process or thread is running and can't be examined.
@ eStateCrashed
Process or thread has crashed and can be examined.
ExpressionResults
The results of expression evaluation.
@ eExpressionCompleted
@ eExpressionSetupError
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:386
@ eReturnStatusSuccessContinuingNoResult
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
@ eArgTypeThreadID
@ eArgTypeThreadIndex
@ eArgTypeExpression
@ eArgTypeUnsignedInteger
@ eTraceCursorSeekTypeEnd
The end of the trace, i.e the most recent item.
std::shared_ptr< lldb_private::TraceCursor > TraceCursorSP
Definition: lldb-forward.h:455
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:443
@ eNoDynamicValues
RunMode
Thread Run Modes.
@ eOnlyDuringStepping
uint64_t tid_t
Definition: lldb-types.h:84
Used to build individual command argument lists.
Definition: CommandObject.h:93
uint32_t arg_opt_set_association
This arg might be associated only with some particular option set(s).
Definition: CommandObject.h:98
A line table entry class.
Definition: LineEntry.h:21
AddressRange range
The section offset address range for this line entry.
Definition: LineEntry.h:137
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition: LineEntry.h:147
const FileSpec & GetFile() const
Helper to access the file.
Definition: LineEntry.h:134
static int64_t ToOptionEnum(llvm::StringRef s, const OptionEnumValues &enum_values, int32_t fail_value, Status &error)
static lldb::addr_t ToAddress(const ExecutionContext *exe_ctx, llvm::StringRef s, lldb::addr_t fail_value, Status *error_ptr)
Try to parse an address.
static bool ToBoolean(llvm::StringRef s, bool fail_value, bool *success_ptr)
Class that holds the configuration used by TraceDumper for traversing and dumping instructions.
Definition: TraceDumper.h:21
bool show_control_flow_kind
For each instruction, print the instruction kind.
Definition: TraceDumper.h:41
bool only_events
Dump events and none of the instructions.
Definition: TraceDumper.h:39
bool show_timestamps
For each trace item, print the corresponding timestamp in nanoseconds if available.
Definition: TraceDumper.h:35
std::optional< uint64_t > id
Optional custom id to start traversing from.
Definition: TraceDumper.h:43
bool pretty_print_json
When dumping in JSON format, pretty print the output.
Definition: TraceDumper.h:32
std::optional< size_t > skip
Optional number of instructions to skip from the starting position of the cursor.
Definition: TraceDumper.h:46
bool json
Dump in json format.
Definition: TraceDumper.h:30
bool show_events
Dump the events that happened between instructions.
Definition: TraceDumper.h:37
bool raw
Dump only instruction addresses without disassembly nor symbol information.
Definition: TraceDumper.h:28
bool forwards
If true, the cursor will be iterated forwards starting from the oldest instruction.
Definition: TraceDumper.h:25
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47