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"
29#include "lldb/Target/Process.h"
32#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
36#include "lldb/Target/Trace.h"
38#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)) {
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))
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)
89 "invalid boolean value for option '%c': %s", short_option,
90 option_arg.data());
91 } break;
92 case 'u':
94 break;
95 default:
96 llvm_unreachable("Unimplemented option");
97 }
98 return error;
99 }
100
101 void OptionParsingStarting(ExecutionContext *execution_context) override {
103 m_start = 0;
104 m_extended_backtrace = false;
106 }
107
108 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
109 return llvm::ArrayRef(g_thread_backtrace_options);
110 }
111
112 // Instance variables to hold the values for command options.
113 uint32_t m_count;
114 uint32_t m_start;
117 };
118
121 interpreter, "thread backtrace",
122 "Show backtraces of thread call stacks. Defaults to the current "
123 "thread, thread indexes can be specified as arguments.\n"
124 "Use the thread-index \"all\" to see all threads.\n"
125 "Use the thread-index \"unique\" to see threads grouped by unique "
126 "call stacks.\n"
127 "Use 'settings set frame-format' to customize the printing of "
128 "frames in the backtrace and 'settings set thread-format' to "
129 "customize the thread header.\n"
130 "Customizable frame recognizers may filter out less interesting "
131 "frames, which results in gaps in the numbering. "
132 "Use '-u' to see all frames.",
133 nullptr,
134 eCommandRequiresProcess | eCommandRequiresThread |
135 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
136 eCommandProcessMustBePaused) {}
137
138 ~CommandObjectThreadBacktrace() override = default;
139
140 Options *GetOptions() override { return &m_options; }
141
142 std::optional<std::string> GetRepeatCommand(Args &current_args,
143 uint32_t index) override {
144 llvm::StringRef count_opt("--count");
145 llvm::StringRef start_opt("--start");
146
147 // If no "count" was provided, we are dumping the entire backtrace, so
148 // there isn't a repeat command. So we search for the count option in
149 // the args, and if we find it, we make a copy and insert or modify the
150 // start option's value to start count indices greater.
151
152 Args copy_args(current_args);
153 size_t num_entries = copy_args.GetArgumentCount();
154 // These two point at the index of the option value if found.
155 size_t count_idx = 0;
156 size_t start_idx = 0;
157 size_t count_val = 0;
158 size_t start_val = 0;
159
160 for (size_t idx = 0; idx < num_entries; idx++) {
161 llvm::StringRef arg_string = copy_args[idx].ref();
162 if (arg_string == "-c" || count_opt.starts_with(arg_string)) {
163 idx++;
164 if (idx == num_entries)
165 return std::nullopt;
166 count_idx = idx;
167 if (copy_args[idx].ref().getAsInteger(0, count_val))
168 return std::nullopt;
169 } else if (arg_string == "-s" || start_opt.starts_with(arg_string)) {
170 idx++;
171 if (idx == num_entries)
172 return std::nullopt;
173 start_idx = idx;
174 if (copy_args[idx].ref().getAsInteger(0, start_val))
175 return std::nullopt;
176 }
177 }
178 if (count_idx == 0)
179 return std::nullopt;
180
181 std::string new_start_val = llvm::formatv("{0}", start_val + count_val);
182 if (start_idx == 0) {
183 copy_args.AppendArgument(start_opt);
184 copy_args.AppendArgument(new_start_val);
185 } else {
186 copy_args.ReplaceArgumentAtIndex(start_idx, new_start_val);
187 }
188 std::string repeat_command;
189 if (!copy_args.GetQuotedCommandString(repeat_command))
190 return std::nullopt;
191 return repeat_command;
192 }
193
194protected:
196 SystemRuntime *runtime = thread->GetProcess()->GetSystemRuntime();
197 if (runtime) {
198 Stream &strm = result.GetOutputStream();
199 const std::vector<ConstString> &types =
200 runtime->GetExtendedBacktraceTypes();
201 for (auto type : types) {
202 ThreadSP ext_thread_sp = runtime->GetExtendedBacktraceThread(
203 thread->shared_from_this(), type);
204 if (ext_thread_sp && ext_thread_sp->IsValid()) {
205 const uint32_t num_frames_with_source = 0;
206 const bool stop_format = false;
207 strm.PutChar('\n');
208 if (ext_thread_sp->GetStatus(strm, m_options.m_start,
210 num_frames_with_source, stop_format,
212 DoExtendedBacktrace(ext_thread_sp.get(), result);
213 }
214 }
215 }
216 }
217 }
218
219 bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
220 ThreadSP thread_sp =
222 if (!thread_sp) {
224 "thread disappeared while computing backtraces: 0x%" PRIx64 "\n",
225 tid);
226 return false;
227 }
228
229 Thread *thread = thread_sp.get();
230
231 Stream &strm = result.GetOutputStream();
232
233 // Only dump stack info if we processing unique stacks.
234 const bool only_stacks = m_unique_stacks;
235
236 // Don't show source context when doing backtraces.
237 const uint32_t num_frames_with_source = 0;
238 const bool stop_format = true;
239 if (!thread->GetStatus(strm, m_options.m_start, m_options.m_count,
240 num_frames_with_source, stop_format,
241 !m_options.m_filtered_backtrace, only_stacks)) {
243 "error displaying backtrace for thread: \"0x%4.4x\"\n",
244 thread->GetIndexID());
245 return false;
246 }
249 "Interrupt skipped extended backtrace")) {
250 DoExtendedBacktrace(thread, result);
251 }
252 }
253
254 return true;
255 }
256
258};
259
260#define LLDB_OPTIONS_thread_step_scope
261#include "CommandOptions.inc"
262
264public:
266 // Keep default values of all options in one place: OptionParsingStarting
267 // ()
268 OptionParsingStarting(nullptr);
269 }
270
271 ~ThreadStepScopeOptionGroup() override = default;
272
273 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
274 return llvm::ArrayRef(g_thread_step_scope_options);
275 }
276
277 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
278 ExecutionContext *execution_context) override {
280 const int short_option =
281 g_thread_step_scope_options[option_idx].short_option;
282
283 switch (short_option) {
284 case 'a': {
285 bool success;
286 bool avoid_no_debug =
287 OptionArgParser::ToBoolean(option_arg, true, &success);
288 if (!success)
290 "invalid boolean value for option '%c': %s", short_option,
291 option_arg.data());
292 else {
294 }
295 } break;
296
297 case 'A': {
298 bool success;
299 bool avoid_no_debug =
300 OptionArgParser::ToBoolean(option_arg, true, &success);
301 if (!success)
303 "invalid boolean value for option '%c': %s", short_option,
304 option_arg.data());
305 else {
307 }
308 } break;
309
310 case 'c':
311 if (option_arg.getAsInteger(0, m_step_count))
313 "invalid integer value for option '%c': %s", short_option,
314 option_arg.data());
315 break;
316
317 case 'm': {
318 auto enum_values = GetDefinitions()[option_idx].enum_values;
320 option_arg, enum_values, eOnlyDuringStepping, error);
321 } break;
322
323 case 'e':
324 if (option_arg == "block") {
326 break;
327 }
328 if (option_arg.getAsInteger(0, m_end_line))
330 "invalid end line number '%s'", option_arg.str().c_str());
331 break;
332
333 case 'r':
334 m_avoid_regexp.clear();
335 m_avoid_regexp.assign(std::string(option_arg));
336 break;
337
338 case 't':
339 m_step_in_target.clear();
340 m_step_in_target.assign(std::string(option_arg));
341 break;
342
343 default:
344 llvm_unreachable("Unimplemented option");
345 }
346 return error;
347 }
348
349 void OptionParsingStarting(ExecutionContext *execution_context) override {
353
354 // Check if we are in Non-Stop mode
355 TargetSP target_sp =
356 execution_context ? execution_context->GetTargetSP() : TargetSP();
357 ProcessSP process_sp =
358 execution_context ? execution_context->GetProcessSP() : ProcessSP();
359 if (process_sp && process_sp->GetSteppingRunsAllThreads())
361
362 m_avoid_regexp.clear();
363 m_step_in_target.clear();
364 m_step_count = 1;
367 }
368
369 // Instance variables to hold the values for command options.
373 std::string m_avoid_regexp;
374 std::string m_step_in_target;
375 uint32_t m_step_count;
376 uint32_t m_end_line;
378};
379
381public:
383 const char *name, const char *help,
384 const char *syntax,
385 StepType step_type)
386 : CommandObjectParsed(interpreter, name, help, syntax,
387 eCommandRequiresProcess | eCommandRequiresThread |
388 eCommandTryTargetAPILock |
389 eCommandProcessMustBeLaunched |
390 eCommandProcessMustBePaused),
391 m_step_type(step_type), m_class_options("scripted step") {
393
394 if (step_type == eStepTypeScripted) {
397 }
400 }
401
403
404 void
406 OptionElementVector &opt_element_vector) override {
407 if (request.GetCursorIndex())
408 return;
409 CommandObject::HandleArgumentCompletion(request, opt_element_vector);
410 }
411
412 Options *GetOptions() override { return &m_all_options; }
413
414protected:
415 void DoExecute(Args &command, CommandReturnObject &result) override {
416 Process *process = m_exe_ctx.GetProcessPtr();
417 bool synchronous_execution = m_interpreter.GetSynchronous();
418
419 const uint32_t num_threads = process->GetThreadList().GetSize();
420 Thread *thread = nullptr;
421
422 if (command.GetArgumentCount() == 0) {
423 thread = GetDefaultThread();
424
425 if (thread == nullptr) {
426 result.AppendError("no selected thread in process");
427 return;
428 }
429 } else {
430 const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
431 uint32_t step_thread_idx;
432
433 if (!llvm::to_integer(thread_idx_cstr, step_thread_idx)) {
434 result.AppendErrorWithFormat("invalid thread index '%s'.\n",
435 thread_idx_cstr);
436 return;
437 }
438 thread =
439 process->GetThreadList().FindThreadByIndexID(step_thread_idx).get();
440 if (thread == nullptr) {
442 "Thread index %u is out of range (valid values are 0 - %u).\n",
443 step_thread_idx, num_threads);
444 return;
445 }
446 }
447
449 if (m_class_options.GetName().empty()) {
450 result.AppendErrorWithFormat("empty class name for scripted step.");
451 return;
452 } else if (!GetDebugger().GetScriptInterpreter()->CheckObjectExists(
453 m_class_options.GetName().c_str())) {
455 "class for scripted step: \"%s\" does not exist.",
456 m_class_options.GetName().c_str());
457 return;
458 }
459 }
460
464 "end line option is only valid for step into");
465 return;
466 }
467
468 const bool abort_other_plans = false;
469 const lldb::RunMode stop_other_threads = m_options.m_run_mode;
470
471 // This is a bit unfortunate, but not all the commands in this command
472 // object support only while stepping, so I use the bool for them.
473 bool bool_stop_other_threads;
475 bool_stop_other_threads = false;
477 bool_stop_other_threads = (m_step_type != eStepTypeOut);
478 else
479 bool_stop_other_threads = true;
480
481 ThreadPlanSP new_plan_sp;
482 Status new_plan_status;
483
484 if (m_step_type == eStepTypeInto) {
485 StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
486 assert(frame != nullptr);
487
488 if (frame->HasDebugInformation()) {
489 AddressRange range;
490 SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
492 llvm::Error err =
494 if (err) {
495 result.AppendErrorWithFormatv("invalid end-line option: {0}.",
496 llvm::toString(std::move(err)));
497 return;
498 }
501 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
502 if (!block) {
503 result.AppendErrorWithFormat("Could not find the current block.");
504 return;
505 }
506
507 AddressRange block_range;
508 Address pc_address = frame->GetFrameCodeAddress();
509 block->GetRangeContainingAddress(pc_address, block_range);
510 if (!block_range.GetBaseAddress().IsValid()) {
512 "Could not find the current block address.");
513 return;
514 }
515 lldb::addr_t pc_offset_in_block =
516 pc_address.GetFileAddress() -
517 block_range.GetBaseAddress().GetFileAddress();
518 lldb::addr_t range_length =
519 block_range.GetByteSize() - pc_offset_in_block;
520 range = AddressRange(pc_address, range_length);
521 } else {
522 range = sc.line_entry.range;
523 }
524
525 new_plan_sp = thread->QueueThreadPlanForStepInRange(
526 abort_other_plans, range,
527 frame->GetSymbolContext(eSymbolContextEverything),
528 m_options.m_step_in_target.c_str(), stop_other_threads,
529 new_plan_status, m_options.m_step_in_avoid_no_debug,
531
532 if (new_plan_sp && !m_options.m_avoid_regexp.empty()) {
533 ThreadPlanStepInRange *step_in_range_plan =
534 static_cast<ThreadPlanStepInRange *>(new_plan_sp.get());
535 step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str());
536 }
537 } else
538 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
539 false, abort_other_plans, bool_stop_other_threads, new_plan_status);
540 } else if (m_step_type == eStepTypeOver) {
541 StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
542
543 if (frame->HasDebugInformation())
544 new_plan_sp = thread->QueueThreadPlanForStepOverRange(
545 abort_other_plans,
546 frame->GetSymbolContext(eSymbolContextEverything).line_entry,
547 frame->GetSymbolContext(eSymbolContextEverything),
548 stop_other_threads, new_plan_status,
550 else
551 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
552 true, abort_other_plans, bool_stop_other_threads, new_plan_status);
553 } else if (m_step_type == eStepTypeTrace) {
554 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
555 false, abort_other_plans, bool_stop_other_threads, new_plan_status);
556 } else if (m_step_type == eStepTypeTraceOver) {
557 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
558 true, abort_other_plans, bool_stop_other_threads, new_plan_status);
559 } else if (m_step_type == eStepTypeOut) {
560 new_plan_sp = thread->QueueThreadPlanForStepOut(
561 abort_other_plans, nullptr, false, bool_stop_other_threads, eVoteYes,
564 new_plan_status, m_options.m_step_out_avoid_no_debug);
565 } else if (m_step_type == eStepTypeScripted) {
566 new_plan_sp = thread->QueueThreadPlanForStepScripted(
567 abort_other_plans, m_class_options.GetName().c_str(),
568 m_class_options.GetStructuredData(), bool_stop_other_threads,
569 new_plan_status);
570 } else {
571 result.AppendError("step type is not supported");
572 return;
573 }
574
575 // If we got a new plan, then set it to be a controlling plan (User level
576 // Plans should be controlling plans so that they can be interruptible).
577 // Then resume the process.
578
579 if (new_plan_sp) {
580 new_plan_sp->SetIsControllingPlan(true);
581 new_plan_sp->SetOkayToDiscard(false);
582
583 if (m_options.m_step_count > 1) {
584 if (!new_plan_sp->SetIterationCount(m_options.m_step_count)) {
585 result.AppendWarning(
586 "step operation does not support iteration count.");
587 }
588 }
589
590 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
591
592 const uint32_t iohandler_id = process->GetIOHandlerID();
593
594 StreamString stream;
596 if (synchronous_execution)
597 error = process->ResumeSynchronous(&stream);
598 else
599 error = process->Resume();
600
601 if (!error.Success()) {
602 result.AppendMessage(error.AsCString());
603 return;
604 }
605
606 // There is a race condition where this thread will return up the call
607 // stack to the main command handler and show an (lldb) prompt before
608 // HandlePrivateEvent (from PrivateStateThread) has a chance to call
609 // PushProcessIOHandler().
610 process->SyncIOHandler(iohandler_id, std::chrono::seconds(2));
611
612 if (synchronous_execution) {
613 // If any state changed events had anything to say, add that to the
614 // result
615 if (stream.GetSize() > 0)
616 result.AppendMessage(stream.GetString());
617
618 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
619 result.SetDidChangeProcessState(true);
621 } else {
623 }
624 } else {
625 result.SetError(std::move(new_plan_status));
626 }
627 }
628
633};
634
635// CommandObjectThreadContinue
636
638public:
641 interpreter, "thread continue",
642 "Continue execution of the current target process. One "
643 "or more threads may be specified, by default all "
644 "threads continue.",
645 nullptr,
646 eCommandRequiresThread | eCommandTryTargetAPILock |
647 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
649 }
650
651 ~CommandObjectThreadContinue() override = default;
652
653 void DoExecute(Args &command, CommandReturnObject &result) override {
654 bool synchronous_execution = m_interpreter.GetSynchronous();
655
656 Process *process = m_exe_ctx.GetProcessPtr();
657 if (process == nullptr) {
658 result.AppendError("no process exists. Cannot continue");
659 return;
660 }
661
662 StateType state = process->GetState();
663 if ((state == eStateCrashed) || (state == eStateStopped) ||
664 (state == eStateSuspended)) {
665 const size_t argc = command.GetArgumentCount();
666 if (argc > 0) {
667 // These two lines appear at the beginning of both blocks in this
668 // if..else, but that is because we need to release the lock before
669 // calling process->Resume below.
670 std::lock_guard<std::recursive_mutex> guard(
671 process->GetThreadList().GetMutex());
672 const uint32_t num_threads = process->GetThreadList().GetSize();
673 std::vector<Thread *> resume_threads;
674 for (auto &entry : command.entries()) {
675 uint32_t thread_idx;
676 if (entry.ref().getAsInteger(0, thread_idx)) {
678 "invalid thread index argument: \"%s\".\n", entry.c_str());
679 return;
680 }
681 Thread *thread =
682 process->GetThreadList().FindThreadByIndexID(thread_idx).get();
683
684 if (thread) {
685 resume_threads.push_back(thread);
686 } else {
687 result.AppendErrorWithFormat("invalid thread index %u.\n",
688 thread_idx);
689 return;
690 }
691 }
692
693 if (resume_threads.empty()) {
694 result.AppendError("no valid thread indexes were specified");
695 return;
696 } else {
697 if (resume_threads.size() == 1)
698 result.AppendMessageWithFormat("Resuming thread: ");
699 else
700 result.AppendMessageWithFormat("Resuming threads: ");
701
702 for (uint32_t idx = 0; idx < num_threads; ++idx) {
703 Thread *thread =
704 process->GetThreadList().GetThreadAtIndex(idx).get();
705 std::vector<Thread *>::iterator this_thread_pos =
706 find(resume_threads.begin(), resume_threads.end(), thread);
707
708 if (this_thread_pos != resume_threads.end()) {
709 resume_threads.erase(this_thread_pos);
710 if (!resume_threads.empty())
711 result.AppendMessageWithFormat("%u, ", thread->GetIndexID());
712 else
713 result.AppendMessageWithFormat("%u ", thread->GetIndexID());
714
715 const bool override_suspend = true;
716 thread->SetResumeState(eStateRunning, override_suspend);
717 } else {
719 }
720 }
721 result.AppendMessageWithFormat("in process %" PRIu64 "\n",
722 process->GetID());
723 }
724 } else {
725 // These two lines appear at the beginning of both blocks in this
726 // if..else, but that is because we need to release the lock before
727 // calling process->Resume below.
728 std::lock_guard<std::recursive_mutex> guard(
729 process->GetThreadList().GetMutex());
730 const uint32_t num_threads = process->GetThreadList().GetSize();
731 Thread *current_thread = GetDefaultThread();
732 if (current_thread == nullptr) {
733 result.AppendError("the process doesn't have a current thread");
734 return;
735 }
736 // Set the actions that the threads should each take when resuming
737 for (uint32_t idx = 0; idx < num_threads; ++idx) {
738 Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
739 if (thread == current_thread) {
740 result.AppendMessageWithFormat("Resuming thread 0x%4.4" PRIx64
741 " in process %" PRIu64 "\n",
742 thread->GetID(), process->GetID());
743 const bool override_suspend = true;
744 thread->SetResumeState(eStateRunning, override_suspend);
745 } else {
747 }
748 }
749 }
750
751 StreamString stream;
753 if (synchronous_execution)
754 error = process->ResumeSynchronous(&stream);
755 else
756 error = process->Resume();
757
758 // We should not be holding the thread list lock when we do this.
759 if (error.Success()) {
760 result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
761 process->GetID());
762 if (synchronous_execution) {
763 // If any state changed events had anything to say, add that to the
764 // result
765 if (stream.GetSize() > 0)
766 result.AppendMessage(stream.GetString());
767
768 result.SetDidChangeProcessState(true);
770 } else {
772 }
773 } else {
774 result.AppendErrorWithFormat("Failed to resume process: %s\n",
775 error.AsCString());
776 }
777 } else {
779 "Process cannot be continued from its current state (%s).\n",
780 StateAsCString(state));
781 }
782 }
783};
784
785// CommandObjectThreadUntil
786
787#define LLDB_OPTIONS_thread_until
788#include "CommandOptions.inc"
789
791public:
792 class CommandOptions : public Options {
793 public:
796
798 // Keep default values of all options in one place: OptionParsingStarting
799 // ()
800 OptionParsingStarting(nullptr);
801 }
802
803 ~CommandOptions() override = default;
804
805 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
806 ExecutionContext *execution_context) override {
808 const int short_option = m_getopt_table[option_idx].val;
809
810 switch (short_option) {
811 case 'a': {
813 execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
814 if (error.Success())
815 m_until_addrs.push_back(tmp_addr);
816 } break;
817 case 't':
818 if (option_arg.getAsInteger(0, m_thread_idx)) {
820 error = Status::FromErrorStringWithFormat("invalid thread index '%s'",
821 option_arg.str().c_str());
822 }
823 break;
824 case 'f':
825 if (option_arg.getAsInteger(0, m_frame_idx)) {
827 error = Status::FromErrorStringWithFormat("invalid frame index '%s'",
828 option_arg.str().c_str());
829 }
830 break;
831 case 'm': {
832 auto enum_values = GetDefinitions()[option_idx].enum_values;
834 option_arg, enum_values, eOnlyDuringStepping, error);
835
836 if (error.Success()) {
837 if (run_mode == eAllThreads)
838 m_stop_others = false;
839 else
840 m_stop_others = true;
841 }
842 } break;
843 default:
844 llvm_unreachable("Unimplemented option");
845 }
846 return error;
847 }
848
849 void OptionParsingStarting(ExecutionContext *execution_context) override {
851 m_frame_idx = 0;
852 m_stop_others = false;
853 m_until_addrs.clear();
854 }
855
856 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
857 return llvm::ArrayRef(g_thread_until_options);
858 }
859
861 bool m_stop_others = false;
862 std::vector<lldb::addr_t> m_until_addrs;
863
864 // Instance variables to hold the values for command options.
865 };
866
869 interpreter, "thread until",
870 "Continue until a line number or address is reached by the "
871 "current or specified thread. Stops when returning from "
872 "the current function as a safety measure. "
873 "The target line number(s) are given as arguments, and if more "
874 "than one"
875 " is provided, stepping will stop when the first one is hit.",
876 nullptr,
877 eCommandRequiresThread | eCommandTryTargetAPILock |
878 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
880 }
881
882 ~CommandObjectThreadUntil() override = default;
883
884 Options *GetOptions() override { return &m_options; }
885
886protected:
887 void DoExecute(Args &command, CommandReturnObject &result) override {
888 bool synchronous_execution = m_interpreter.GetSynchronous();
889
890 Target *target = &GetTarget();
891
892 Process *process = m_exe_ctx.GetProcessPtr();
893 if (process == nullptr) {
894 result.AppendError("need a valid process to step");
895 } else {
896 Thread *thread = nullptr;
897 std::vector<uint32_t> line_numbers;
898
899 if (command.GetArgumentCount() >= 1) {
900 size_t num_args = command.GetArgumentCount();
901 for (size_t i = 0; i < num_args; i++) {
902 uint32_t line_number;
903 if (!llvm::to_integer(command.GetArgumentAtIndex(i), line_number)) {
904 result.AppendErrorWithFormat("invalid line number: '%s'.\n",
905 command.GetArgumentAtIndex(i));
906 return;
907 } else
908 line_numbers.push_back(line_number);
909 }
910 } else if (m_options.m_until_addrs.empty()) {
911 result.AppendErrorWithFormat("No line number or address provided:\n%s",
912 GetSyntax().str().c_str());
913 return;
914 }
915
917 thread = GetDefaultThread();
918 } else {
919 thread = process->GetThreadList()
921 .get();
922 }
923
924 if (thread == nullptr) {
925 const uint32_t num_threads = process->GetThreadList().GetSize();
927 "Thread index %u is out of range (valid values are 0 - %u).\n",
928 m_options.m_thread_idx, num_threads);
929 return;
930 }
931
932 const bool abort_other_plans = false;
933
934 StackFrame *frame =
936 if (frame == nullptr) {
938 "Frame index %u is out of range for thread id %" PRIu64 ".\n",
939 m_options.m_frame_idx, thread->GetID());
940 return;
941 }
942
943 ThreadPlanSP new_plan_sp;
944 Status new_plan_status;
945
946 if (frame->HasDebugInformation()) {
947 // Finally we got here... Translate the given line number to a bunch
948 // of addresses:
949 SymbolContext sc(frame->GetSymbolContext(eSymbolContextCompUnit));
950 LineTable *line_table = nullptr;
951 if (sc.comp_unit)
952 line_table = sc.comp_unit->GetLineTable();
953
954 if (line_table == nullptr) {
955 result.AppendErrorWithFormat("Failed to resolve the line table for "
956 "frame %u of thread id %" PRIu64 ".\n",
957 m_options.m_frame_idx, thread->GetID());
958 return;
959 }
960
961 LineEntry function_start;
962 uint32_t index_ptr = 0, end_ptr = UINT32_MAX;
963 std::vector<addr_t> address_list;
964
965 // Find the beginning & end index of the function, but first make
966 // sure it is valid:
967 if (!sc.function) {
968 result.AppendErrorWithFormat("Have debug information but no "
969 "function info - can't get until range.");
970 return;
971 }
972
973 AddressRange fun_addr_range = sc.function->GetAddressRange();
974 Address fun_start_addr = fun_addr_range.GetBaseAddress();
975 line_table->FindLineEntryByAddress(fun_start_addr, function_start,
976 &index_ptr);
977
978 Address fun_end_addr(fun_start_addr.GetSection(),
979 fun_start_addr.GetOffset() +
980 fun_addr_range.GetByteSize());
981
982 bool all_in_function = true;
983
984 line_table->FindLineEntryByAddress(fun_end_addr, function_start,
985 &end_ptr);
986
987 // Since not all source lines will contribute code, check if we are
988 // setting the breakpoint on the exact line number or the nearest
989 // subsequent line number and set breakpoints at all the line table
990 // entries of the chosen line number (exact or nearest subsequent).
991 for (uint32_t line_number : line_numbers) {
992 LineEntry line_entry;
993 bool exact = false;
994 uint32_t start_idx_ptr = index_ptr;
995 start_idx_ptr = sc.comp_unit->FindLineEntry(
996 index_ptr, line_number, nullptr, exact, &line_entry);
997 if (start_idx_ptr != UINT32_MAX)
998 line_number = line_entry.line;
999 exact = true;
1000 start_idx_ptr = index_ptr;
1001 while (start_idx_ptr <= end_ptr) {
1002 start_idx_ptr = sc.comp_unit->FindLineEntry(
1003 start_idx_ptr, line_number, nullptr, exact, &line_entry);
1004 if (start_idx_ptr == UINT32_MAX)
1005 break;
1006
1007 addr_t address =
1008 line_entry.range.GetBaseAddress().GetLoadAddress(target);
1009 if (address != LLDB_INVALID_ADDRESS) {
1010 if (fun_addr_range.ContainsLoadAddress(address, target))
1011 address_list.push_back(address);
1012 else
1013 all_in_function = false;
1014 }
1015 start_idx_ptr++;
1016 }
1017 }
1018
1019 for (lldb::addr_t address : m_options.m_until_addrs) {
1020 if (fun_addr_range.ContainsLoadAddress(address, target))
1021 address_list.push_back(address);
1022 else
1023 all_in_function = false;
1024 }
1025
1026 if (address_list.empty()) {
1027 if (all_in_function)
1028 result.AppendErrorWithFormat(
1029 "No line entries matching until target.\n");
1030 else
1031 result.AppendErrorWithFormat(
1032 "Until target outside of the current function.\n");
1033
1034 return;
1035 }
1036
1037 new_plan_sp = thread->QueueThreadPlanForStepUntil(
1038 abort_other_plans, &address_list.front(), address_list.size(),
1039 m_options.m_stop_others, m_options.m_frame_idx, new_plan_status);
1040 if (new_plan_sp) {
1041 // User level plans should be controlling plans so they can be
1042 // interrupted
1043 // (e.g. by hitting a breakpoint) and other plans executed by the
1044 // user (stepping around the breakpoint) and then a "continue" will
1045 // resume the original plan.
1046 new_plan_sp->SetIsControllingPlan(true);
1047 new_plan_sp->SetOkayToDiscard(false);
1048 } else {
1049 result.SetError(std::move(new_plan_status));
1050 return;
1051 }
1052 } else {
1053 result.AppendErrorWithFormat("Frame index %u of thread id %" PRIu64
1054 " has no debug information.\n",
1055 m_options.m_frame_idx, thread->GetID());
1056 return;
1057 }
1058
1059 if (!process->GetThreadList().SetSelectedThreadByID(thread->GetID())) {
1060 result.AppendErrorWithFormat(
1061 "Failed to set the selected thread to thread id %" PRIu64 ".\n",
1062 thread->GetID());
1063 return;
1064 }
1065
1066 StreamString stream;
1067 Status error;
1068 if (synchronous_execution)
1069 error = process->ResumeSynchronous(&stream);
1070 else
1071 error = process->Resume();
1072
1073 if (error.Success()) {
1074 result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
1075 process->GetID());
1076 if (synchronous_execution) {
1077 // If any state changed events had anything to say, add that to the
1078 // result
1079 if (stream.GetSize() > 0)
1080 result.AppendMessage(stream.GetString());
1081
1082 result.SetDidChangeProcessState(true);
1084 } else {
1086 }
1087 } else {
1088 result.AppendErrorWithFormat("Failed to resume process: %s.\n",
1089 error.AsCString());
1090 }
1091 }
1092 }
1093
1095};
1096
1097// CommandObjectThreadSelect
1098
1099#define LLDB_OPTIONS_thread_select
1100#include "CommandOptions.inc"
1101
1103public:
1105 public:
1107
1108 ~OptionGroupThreadSelect() override = default;
1109
1110 void OptionParsingStarting(ExecutionContext *execution_context) override {
1112 }
1113
1114 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1115 ExecutionContext *execution_context) override {
1116 const int short_option = g_thread_select_options[option_idx].short_option;
1117 switch (short_option) {
1118 case 't': {
1119 if (option_arg.getAsInteger(0, m_thread_id)) {
1121 return Status::FromErrorStringWithFormat("Invalid thread ID: '%s'.",
1122 option_arg.str().c_str());
1123 }
1124 break;
1125 }
1126
1127 default:
1128 llvm_unreachable("Unimplemented option");
1129 }
1130
1131 return {};
1132 }
1133
1134 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1135 return llvm::ArrayRef(g_thread_select_options);
1136 }
1137
1139 };
1140
1142 : CommandObjectParsed(interpreter, "thread select",
1143 "Change the currently selected thread.",
1144 "thread select <thread-index> (or -t <thread-id>)",
1145 eCommandRequiresProcess | eCommandTryTargetAPILock |
1146 eCommandProcessMustBeLaunched |
1147 eCommandProcessMustBePaused) {
1149 CommandArgumentData thread_idx_arg;
1150
1151 // Define the first (and only) variant of this arg.
1152 thread_idx_arg.arg_type = eArgTypeThreadIndex;
1153 thread_idx_arg.arg_repetition = eArgRepeatPlain;
1154 thread_idx_arg.arg_opt_set_association = LLDB_OPT_SET_1;
1155
1156 // There is only one variant this argument could be; put it into the
1157 // argument entry.
1158 arg.push_back(thread_idx_arg);
1159
1160 // Push the data for the first argument into the m_arguments vector.
1161 m_arguments.push_back(arg);
1162
1165 }
1166
1167 ~CommandObjectThreadSelect() override = default;
1168
1169 void
1171 OptionElementVector &opt_element_vector) override {
1172 if (request.GetCursorIndex())
1173 return;
1174
1177 nullptr);
1178 }
1179
1180 Options *GetOptions() override { return &m_option_group; }
1181
1182protected:
1183 void DoExecute(Args &command, CommandReturnObject &result) override {
1184 Process *process = m_exe_ctx.GetProcessPtr();
1185 if (process == nullptr) {
1186 result.AppendError("no process");
1187 return;
1189 command.GetArgumentCount() != 1) {
1190 result.AppendErrorWithFormat(
1191 "'%s' takes exactly one thread index argument, or a thread ID "
1192 "option:\nUsage: %s\n",
1193 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1194 return;
1196 command.GetArgumentCount() != 0) {
1197 result.AppendErrorWithFormat("'%s' cannot take both a thread ID option "
1198 "and a thread index argument:\nUsage: %s\n",
1199 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1200 return;
1201 }
1202
1203 Thread *new_thread = nullptr;
1204 if (command.GetArgumentCount() == 1) {
1205 uint32_t index_id;
1206 if (!llvm::to_integer(command.GetArgumentAtIndex(0), index_id)) {
1207 result.AppendErrorWithFormat("Invalid thread index '%s'",
1208 command.GetArgumentAtIndex(0));
1209 return;
1210 }
1211 new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get();
1212 if (new_thread == nullptr) {
1213 result.AppendErrorWithFormat("Invalid thread index #%s.\n",
1214 command.GetArgumentAtIndex(0));
1215 return;
1216 }
1217 } else {
1218 new_thread =
1220 if (new_thread == nullptr) {
1221 result.AppendErrorWithFormat("Invalid thread ID %" PRIu64 ".\n",
1223 return;
1224 }
1225 }
1226
1227 process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true);
1229 }
1230
1233};
1234
1235// CommandObjectThreadList
1236
1238public:
1241 interpreter, "thread list",
1242 "Show a summary of each thread in the current target process. "
1243 "Use 'settings set thread-format' to customize the individual "
1244 "thread listings.",
1245 "thread list",
1246 eCommandRequiresProcess | eCommandTryTargetAPILock |
1247 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1248
1249 ~CommandObjectThreadList() override = default;
1250
1251protected:
1252 void DoExecute(Args &command, CommandReturnObject &result) override {
1253 Stream &strm = result.GetOutputStream();
1255 Process *process = m_exe_ctx.GetProcessPtr();
1256 const bool only_threads_with_stop_reason = false;
1257 const uint32_t start_frame = 0;
1258 const uint32_t num_frames = 0;
1259 const uint32_t num_frames_with_source = 0;
1260 process->GetStatus(strm);
1261 process->GetThreadStatus(strm, only_threads_with_stop_reason, start_frame,
1262 num_frames, num_frames_with_source, false);
1263 }
1264};
1265
1266// CommandObjectThreadInfo
1267#define LLDB_OPTIONS_thread_info
1268#include "CommandOptions.inc"
1269
1271public:
1272 class CommandOptions : public Options {
1273 public:
1275
1276 ~CommandOptions() override = default;
1277
1278 void OptionParsingStarting(ExecutionContext *execution_context) override {
1279 m_json_thread = false;
1280 m_json_stopinfo = false;
1281 }
1282
1283 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1284 ExecutionContext *execution_context) override {
1285 const int short_option = m_getopt_table[option_idx].val;
1286 Status error;
1287
1288 switch (short_option) {
1289 case 'j':
1290 m_json_thread = true;
1291 break;
1292
1293 case 's':
1294 m_json_stopinfo = true;
1295 break;
1296
1297 default:
1298 llvm_unreachable("Unimplemented option");
1299 }
1300 return error;
1301 }
1302
1303 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1304 return llvm::ArrayRef(g_thread_info_options);
1305 }
1306
1309 };
1310
1313 interpreter, "thread info",
1314 "Show an extended summary of one or "
1315 "more threads. Defaults to the "
1316 "current thread.",
1317 "thread info",
1318 eCommandRequiresProcess | eCommandTryTargetAPILock |
1319 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
1320 m_add_return = false;
1321 }
1322
1323 ~CommandObjectThreadInfo() override = default;
1324
1325 void
1327 OptionElementVector &opt_element_vector) override {
1330 nullptr);
1331 }
1332
1333 Options *GetOptions() override { return &m_options; }
1334
1336 ThreadSP thread_sp =
1338 if (!thread_sp) {
1339 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1340 tid);
1341 return false;
1342 }
1343
1344 Thread *thread = thread_sp.get();
1345
1346 Stream &strm = result.GetOutputStream();
1347 if (!thread->GetDescription(strm, eDescriptionLevelFull,
1350 result.AppendErrorWithFormat("error displaying info for thread: \"%d\"\n",
1351 thread->GetIndexID());
1352 return false;
1353 }
1354 return true;
1355 }
1356
1358};
1359
1360// CommandObjectThreadException
1361
1363public:
1366 interpreter, "thread exception",
1367 "Display the current exception object for a thread. Defaults to "
1368 "the current thread.",
1369 "thread exception",
1370 eCommandRequiresProcess | eCommandTryTargetAPILock |
1371 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1372
1373 ~CommandObjectThreadException() override = default;
1374
1375 void
1377 OptionElementVector &opt_element_vector) override {
1380 nullptr);
1381 }
1382
1384 ThreadSP thread_sp =
1386 if (!thread_sp) {
1387 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1388 tid);
1389 return false;
1390 }
1391
1392 Stream &strm = result.GetOutputStream();
1393 ValueObjectSP exception_object_sp = thread_sp->GetCurrentException();
1394 if (exception_object_sp) {
1395 if (llvm::Error error = exception_object_sp->Dump(strm)) {
1396 result.AppendError(toString(std::move(error)));
1397 return false;
1398 }
1399 }
1400
1401 ThreadSP exception_thread_sp = thread_sp->GetCurrentExceptionBacktrace();
1402 if (exception_thread_sp && exception_thread_sp->IsValid()) {
1403 const uint32_t num_frames_with_source = 0;
1404 const bool stop_format = false;
1405 exception_thread_sp->GetStatus(strm, 0, UINT32_MAX,
1406 num_frames_with_source, stop_format,
1407 /*filtered*/ false);
1408 }
1409
1410 return true;
1411 }
1412};
1413
1415public:
1418 interpreter, "thread siginfo",
1419 "Display the current siginfo object for a thread. Defaults to "
1420 "the current thread.",
1421 "thread siginfo",
1422 eCommandRequiresProcess | eCommandTryTargetAPILock |
1423 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1424
1425 ~CommandObjectThreadSiginfo() override = default;
1426
1427 void
1429 OptionElementVector &opt_element_vector) override {
1432 nullptr);
1433 }
1434
1436 ThreadSP thread_sp =
1438 if (!thread_sp) {
1439 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1440 tid);
1441 return false;
1442 }
1443
1444 Stream &strm = result.GetOutputStream();
1445 if (!thread_sp->GetDescription(strm, eDescriptionLevelFull, false, false)) {
1446 result.AppendErrorWithFormat("error displaying info for thread: \"%d\"\n",
1447 thread_sp->GetIndexID());
1448 return false;
1449 }
1450 ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
1451 if (exception_object_sp) {
1452 if (llvm::Error error = exception_object_sp->Dump(strm)) {
1453 result.AppendError(toString(std::move(error)));
1454 return false;
1455 }
1456 } else
1457 strm.Printf("(no siginfo)\n");
1458 strm.PutChar('\n');
1459
1460 return true;
1461 }
1462};
1463
1464// CommandObjectThreadReturn
1465#define LLDB_OPTIONS_thread_return
1466#include "CommandOptions.inc"
1467
1469public:
1470 class CommandOptions : public Options {
1471 public:
1473 // Keep default values of all options in one place: OptionParsingStarting
1474 // ()
1475 OptionParsingStarting(nullptr);
1476 }
1477
1478 ~CommandOptions() override = default;
1479
1480 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1481 ExecutionContext *execution_context) override {
1482 Status error;
1483 const int short_option = m_getopt_table[option_idx].val;
1484
1485 switch (short_option) {
1486 case 'x': {
1487 bool success;
1488 bool tmp_value =
1489 OptionArgParser::ToBoolean(option_arg, false, &success);
1490 if (success)
1491 m_from_expression = tmp_value;
1492 else {
1494 "invalid boolean value '%s' for 'x' option",
1495 option_arg.str().c_str());
1496 }
1497 } break;
1498 default:
1499 llvm_unreachable("Unimplemented option");
1500 }
1501 return error;
1502 }
1503
1504 void OptionParsingStarting(ExecutionContext *execution_context) override {
1505 m_from_expression = false;
1506 }
1507
1508 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1509 return llvm::ArrayRef(g_thread_return_options);
1510 }
1511
1512 bool m_from_expression = false;
1513
1514 // Instance variables to hold the values for command options.
1515 };
1516
1518 : CommandObjectRaw(interpreter, "thread return",
1519 "Prematurely return from a stack frame, "
1520 "short-circuiting execution of newer frames "
1521 "and optionally yielding a specified value. Defaults "
1522 "to the exiting the current stack "
1523 "frame.",
1524 "thread return",
1525 eCommandRequiresFrame | eCommandTryTargetAPILock |
1526 eCommandProcessMustBeLaunched |
1527 eCommandProcessMustBePaused) {
1529 }
1530
1531 ~CommandObjectThreadReturn() override = default;
1532
1533 Options *GetOptions() override { return &m_options; }
1534
1535protected:
1536 void DoExecute(llvm::StringRef command,
1537 CommandReturnObject &result) override {
1538 // I am going to handle this by hand, because I don't want you to have to
1539 // say:
1540 // "thread return -- -5".
1541 if (command.starts_with("-x")) {
1542 if (command.size() != 2U)
1543 result.AppendWarning("Return values ignored when returning from user "
1544 "called expressions");
1545
1546 Thread *thread = m_exe_ctx.GetThreadPtr();
1547 Status error;
1548 error = thread->UnwindInnermostExpression();
1549 if (!error.Success()) {
1550 result.AppendErrorWithFormat("Unwinding expression failed - %s.",
1551 error.AsCString());
1552 } else {
1553 bool success =
1555 if (success) {
1559 } else {
1560 result.AppendErrorWithFormat(
1561 "Could not select 0th frame after unwinding expression.");
1562 }
1563 }
1564 return;
1565 }
1566
1567 ValueObjectSP return_valobj_sp;
1568
1569 StackFrameSP frame_sp = m_exe_ctx.GetFrameSP();
1570 uint32_t frame_idx = frame_sp->GetFrameIndex();
1571
1572 if (frame_sp->IsInlined()) {
1573 result.AppendError("Don't know how to return from inlined frames.");
1574 return;
1575 }
1576
1577 if (!command.empty()) {
1578 Target *target = m_exe_ctx.GetTargetPtr();
1580
1581 options.SetUnwindOnError(true);
1583
1585 exe_results = target->EvaluateExpression(command, frame_sp.get(),
1586 return_valobj_sp, options);
1587 if (exe_results != eExpressionCompleted) {
1588 if (return_valobj_sp)
1589 result.AppendErrorWithFormat(
1590 "Error evaluating result expression: %s",
1591 return_valobj_sp->GetError().AsCString());
1592 else
1593 result.AppendErrorWithFormat(
1594 "Unknown error evaluating result expression.");
1595 return;
1596 }
1597 }
1598
1599 Status error;
1600 ThreadSP thread_sp = m_exe_ctx.GetThreadSP();
1601 const bool broadcast = true;
1602 error = thread_sp->ReturnFromFrame(frame_sp, return_valobj_sp, broadcast);
1603 if (!error.Success()) {
1604 result.AppendErrorWithFormat(
1605 "Error returning from frame %d of thread %d: %s.", frame_idx,
1606 thread_sp->GetIndexID(), error.AsCString());
1607 return;
1608 }
1609
1611 }
1612
1614};
1615
1616// CommandObjectThreadJump
1617#define LLDB_OPTIONS_thread_jump
1618#include "CommandOptions.inc"
1619
1621public:
1622 class CommandOptions : public Options {
1623 public:
1625
1626 ~CommandOptions() override = default;
1627
1628 void OptionParsingStarting(ExecutionContext *execution_context) override {
1630 m_line_num = 0;
1631 m_line_offset = 0;
1633 m_force = false;
1634 }
1635
1636 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1637 ExecutionContext *execution_context) override {
1638 const int short_option = m_getopt_table[option_idx].val;
1639 Status error;
1640
1641 switch (short_option) {
1642 case 'f':
1643 m_filenames.AppendIfUnique(FileSpec(option_arg));
1644 if (m_filenames.GetSize() > 1)
1645 return Status::FromErrorString("only one source file expected.");
1646 break;
1647 case 'l':
1648 if (option_arg.getAsInteger(0, m_line_num))
1649 return Status::FromErrorStringWithFormat("invalid line number: '%s'.",
1650 option_arg.str().c_str());
1651 break;
1652 case 'b':
1653 if (option_arg.getAsInteger(0, m_line_offset))
1654 return Status::FromErrorStringWithFormat("invalid line offset: '%s'.",
1655 option_arg.str().c_str());
1656 break;
1657 case 'a':
1658 m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg,
1660 break;
1661 case 'r':
1662 m_force = true;
1663 break;
1664 default:
1665 llvm_unreachable("Unimplemented option");
1666 }
1667 return error;
1668 }
1669
1670 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1671 return llvm::ArrayRef(g_thread_jump_options);
1672 }
1673
1675 uint32_t m_line_num;
1679 };
1680
1683 interpreter, "thread jump",
1684 "Sets the program counter to a new address.", "thread jump",
1685 eCommandRequiresFrame | eCommandTryTargetAPILock |
1686 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1687
1688 ~CommandObjectThreadJump() override = default;
1689
1690 Options *GetOptions() override { return &m_options; }
1691
1692protected:
1693 void DoExecute(Args &args, CommandReturnObject &result) override {
1695 StackFrame *frame = m_exe_ctx.GetFramePtr();
1696 Thread *thread = m_exe_ctx.GetThreadPtr();
1697 Target *target = m_exe_ctx.GetTargetPtr();
1698 const SymbolContext &sym_ctx =
1699 frame->GetSymbolContext(eSymbolContextLineEntry);
1700
1702 // Use this address directly.
1704
1705 lldb::addr_t callAddr = dest.GetCallableLoadAddress(target);
1706 if (callAddr == LLDB_INVALID_ADDRESS) {
1707 result.AppendErrorWithFormat("Invalid destination address.");
1708 return;
1709 }
1710
1711 if (!reg_ctx->SetPC(callAddr)) {
1712 result.AppendErrorWithFormat("Error changing PC value for thread %d.",
1713 thread->GetIndexID());
1714 return;
1715 }
1716 } else {
1717 // Pick either the absolute line, or work out a relative one.
1718 int32_t line = (int32_t)m_options.m_line_num;
1719 if (line == 0)
1720 line = sym_ctx.line_entry.line + m_options.m_line_offset;
1721
1722 // Try the current file, but override if asked.
1723 FileSpec file = sym_ctx.line_entry.GetFile();
1724 if (m_options.m_filenames.GetSize() == 1)
1726
1727 if (!file) {
1728 result.AppendErrorWithFormat(
1729 "No source file available for the current location.");
1730 return;
1731 }
1732
1733 std::string warnings;
1734 Status err = thread->JumpToLine(file, line, m_options.m_force, &warnings);
1735
1736 if (err.Fail()) {
1737 result.SetError(std::move(err));
1738 return;
1739 }
1740
1741 if (!warnings.empty())
1742 result.AppendWarning(warnings.c_str());
1743 }
1744
1746 }
1747
1749};
1750
1751// Next are the subcommands of CommandObjectMultiwordThreadPlan
1752
1753// CommandObjectThreadPlanList
1754#define LLDB_OPTIONS_thread_plan_list
1755#include "CommandOptions.inc"
1756
1758public:
1759 class CommandOptions : public Options {
1760 public:
1762 // Keep default values of all options in one place: OptionParsingStarting
1763 // ()
1764 OptionParsingStarting(nullptr);
1765 }
1766
1767 ~CommandOptions() override = default;
1768
1769 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1770 ExecutionContext *execution_context) override {
1771 const int short_option = m_getopt_table[option_idx].val;
1772
1773 switch (short_option) {
1774 case 'i':
1775 m_internal = true;
1776 break;
1777 case 't':
1778 lldb::tid_t tid;
1779 if (option_arg.getAsInteger(0, tid))
1780 return Status::FromErrorStringWithFormat("invalid tid: '%s'.",
1781 option_arg.str().c_str());
1782 m_tids.push_back(tid);
1783 break;
1784 case 'u':
1785 m_unreported = false;
1786 break;
1787 case 'v':
1788 m_verbose = true;
1789 break;
1790 default:
1791 llvm_unreachable("Unimplemented option");
1792 }
1793 return {};
1794 }
1795
1796 void OptionParsingStarting(ExecutionContext *execution_context) override {
1797 m_verbose = false;
1798 m_internal = false;
1799 m_unreported = true; // The variable is "skip unreported" and we want to
1800 // skip unreported by default.
1801 m_tids.clear();
1802 }
1803
1804 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1805 return llvm::ArrayRef(g_thread_plan_list_options);
1806 }
1807
1808 // Instance variables to hold the values for command options.
1812 std::vector<lldb::tid_t> m_tids;
1813 };
1814
1817 interpreter, "thread plan list",
1818 "Show thread plans for one or more threads. If no threads are "
1819 "specified, show the "
1820 "current thread. Use the thread-index \"all\" to see all threads.",
1821 nullptr,
1822 eCommandRequiresProcess | eCommandRequiresThread |
1823 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
1824 eCommandProcessMustBePaused) {}
1825
1826 ~CommandObjectThreadPlanList() override = default;
1827
1828 Options *GetOptions() override { return &m_options; }
1829
1830 void DoExecute(Args &command, CommandReturnObject &result) override {
1831 // If we are reporting all threads, dispatch to the Process to do that:
1832 if (command.GetArgumentCount() == 0 && m_options.m_tids.empty()) {
1833 Stream &strm = result.GetOutputStream();
1838 strm, desc_level, m_options.m_internal, true, m_options.m_unreported);
1840 return;
1841 } else {
1842 // Do any TID's that the user may have specified as TID, then do any
1843 // Thread Indexes...
1844 if (!m_options.m_tids.empty()) {
1845 Process *process = m_exe_ctx.GetProcessPtr();
1846 StreamString tmp_strm;
1847 for (lldb::tid_t tid : m_options.m_tids) {
1848 bool success = process->DumpThreadPlansForTID(
1850 true /* condense_trivial */, m_options.m_unreported);
1851 // If we didn't find a TID, stop here and return an error.
1852 if (!success) {
1853 result.AppendError("Error dumping plans:");
1854 result.AppendError(tmp_strm.GetString());
1855 return;
1856 }
1857 // Otherwise, add our data to the output:
1858 result.GetOutputStream() << tmp_strm.GetString();
1859 }
1860 }
1861 return CommandObjectIterateOverThreads::DoExecute(command, result);
1862 }
1863 }
1864
1865protected:
1867 // If we have already handled this from a -t option, skip it here.
1868 if (llvm::is_contained(m_options.m_tids, tid))
1869 return true;
1870
1871 Process *process = m_exe_ctx.GetProcessPtr();
1872
1873 Stream &strm = result.GetOutputStream();
1875 if (m_options.m_verbose)
1876 desc_level = eDescriptionLevelVerbose;
1877
1878 process->DumpThreadPlansForTID(strm, tid, desc_level, m_options.m_internal,
1879 true /* condense_trivial */,
1881 return true;
1882 }
1883
1885};
1886
1888public:
1890 : CommandObjectParsed(interpreter, "thread plan discard",
1891 "Discards thread plans up to and including the "
1892 "specified index (see 'thread plan list'.) "
1893 "Only user visible plans can be discarded.",
1894 nullptr,
1895 eCommandRequiresProcess | eCommandRequiresThread |
1896 eCommandTryTargetAPILock |
1897 eCommandProcessMustBeLaunched |
1898 eCommandProcessMustBePaused) {
1900 }
1901
1903
1904 void
1906 OptionElementVector &opt_element_vector) override {
1907 if (!m_exe_ctx.HasThreadScope() || request.GetCursorIndex())
1908 return;
1909
1911 }
1912
1913 void DoExecute(Args &args, CommandReturnObject &result) override {
1914 Thread *thread = m_exe_ctx.GetThreadPtr();
1915 if (args.GetArgumentCount() != 1) {
1916 result.AppendErrorWithFormat("Too many arguments, expected one - the "
1917 "thread plan index - but got %zu.",
1918 args.GetArgumentCount());
1919 return;
1920 }
1921
1922 uint32_t thread_plan_idx;
1923 if (!llvm::to_integer(args.GetArgumentAtIndex(0), thread_plan_idx)) {
1924 result.AppendErrorWithFormat(
1925 "Invalid thread index: \"%s\" - should be unsigned int.",
1926 args.GetArgumentAtIndex(0));
1927 return;
1928 }
1929
1930 if (thread_plan_idx == 0) {
1931 result.AppendErrorWithFormat(
1932 "You wouldn't really want me to discard the base thread plan.");
1933 return;
1934 }
1935
1936 if (thread->DiscardUserThreadPlansUpToIndex(thread_plan_idx)) {
1938 } else {
1939 result.AppendErrorWithFormat(
1940 "Could not find User thread plan with index %s.",
1941 args.GetArgumentAtIndex(0));
1942 }
1943 }
1944};
1945
1947public:
1949 : CommandObjectParsed(interpreter, "thread plan prune",
1950 "Removes any thread plans associated with "
1951 "currently unreported threads. "
1952 "Specify one or more TID's to remove, or if no "
1953 "TID's are provides, remove threads for all "
1954 "unreported threads",
1955 nullptr,
1956 eCommandRequiresProcess |
1957 eCommandTryTargetAPILock |
1958 eCommandProcessMustBeLaunched |
1959 eCommandProcessMustBePaused) {
1961 }
1962
1963 ~CommandObjectThreadPlanPrune() override = default;
1964
1965 void DoExecute(Args &args, CommandReturnObject &result) override {
1966 Process *process = m_exe_ctx.GetProcessPtr();
1967
1968 if (args.GetArgumentCount() == 0) {
1969 process->PruneThreadPlans();
1971 return;
1972 }
1973
1974 const size_t num_args = args.GetArgumentCount();
1975
1976 std::lock_guard<std::recursive_mutex> guard(
1977 process->GetThreadList().GetMutex());
1978
1979 for (size_t i = 0; i < num_args; i++) {
1980 lldb::tid_t tid;
1981 if (!llvm::to_integer(args.GetArgumentAtIndex(i), tid)) {
1982 result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n",
1983 args.GetArgumentAtIndex(i));
1984 return;
1985 }
1986 if (!process->PruneThreadPlansForTID(tid)) {
1987 result.AppendErrorWithFormat("Could not find unreported tid: \"%s\"\n",
1988 args.GetArgumentAtIndex(i));
1989 return;
1990 }
1991 }
1993 }
1994};
1995
1996// CommandObjectMultiwordThreadPlan
1997
1999public:
2002 interpreter, "plan",
2003 "Commands for managing thread plans that control execution.",
2004 "thread plan <subcommand> [<subcommand objects]") {
2006 "list", CommandObjectSP(new CommandObjectThreadPlanList(interpreter)));
2008 "discard",
2011 "prune",
2013 }
2014
2016};
2017
2018// Next are the subcommands of CommandObjectMultiwordTrace
2019
2020// CommandObjectTraceExport
2021
2023public:
2026 interpreter, "trace thread export",
2027 "Commands for exporting traces of the threads in the current "
2028 "process to different formats.",
2029 "thread trace export <export-plugin> [<subcommand objects>]") {
2030
2031 unsigned i = 0;
2032 for (llvm::StringRef plugin_name =
2034 !plugin_name.empty();
2036 if (ThreadTraceExportCommandCreator command_creator =
2038 LoadSubCommand(plugin_name, command_creator(interpreter));
2039 }
2040 }
2041 }
2042};
2043
2044// CommandObjectTraceStart
2045
2047public:
2050 /*live_debug_session_only=*/true, interpreter, "thread trace start",
2051 "Start tracing threads with the corresponding trace "
2052 "plug-in for the current process.",
2053 "thread trace start [<trace-options>]") {}
2054
2055protected:
2058 }
2059};
2060
2061// CommandObjectTraceStop
2062
2064public:
2067 interpreter, "thread trace stop",
2068 "Stop tracing threads, including the ones traced with the "
2069 "\"process trace start\" command."
2070 "Defaults to the current thread. Thread indices can be "
2071 "specified as arguments.\n Use the thread-index \"all\" to stop "
2072 "tracing "
2073 "for all existing threads.",
2074 "thread trace stop [<thread-index> <thread-index> ...]",
2075 eCommandRequiresProcess | eCommandTryTargetAPILock |
2076 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
2077 eCommandProcessMustBeTraced) {}
2078
2079 ~CommandObjectTraceStop() override = default;
2080
2082 llvm::ArrayRef<lldb::tid_t> tids) override {
2083 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
2084
2085 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
2086
2087 if (llvm::Error err = trace_sp->Stop(tids))
2088 result.AppendError(toString(std::move(err)));
2089 else
2091
2092 return result.Succeeded();
2093 }
2094};
2095
2097 CommandReturnObject &result) {
2098 if (args.GetArgumentCount() == 0)
2099 return exe_ctx.GetThreadSP();
2100
2101 const char *arg = args.GetArgumentAtIndex(0);
2102 uint32_t thread_idx;
2103
2104 if (!llvm::to_integer(arg, thread_idx)) {
2105 result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n", arg);
2106 return nullptr;
2107 }
2108 ThreadSP thread_sp =
2109 exe_ctx.GetProcessRef().GetThreadList().FindThreadByIndexID(thread_idx);
2110 if (!thread_sp)
2111 result.AppendErrorWithFormat("no thread with index: \"%s\"\n", arg);
2112 return thread_sp;
2113}
2114
2115// CommandObjectTraceDumpFunctionCalls
2116#define LLDB_OPTIONS_thread_trace_dump_function_calls
2117#include "CommandOptions.inc"
2118
2120public:
2121 class CommandOptions : public Options {
2122 public:
2124
2125 ~CommandOptions() override = default;
2126
2127 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2128 ExecutionContext *execution_context) override {
2129 Status error;
2130 const int short_option = m_getopt_table[option_idx].val;
2131
2132 switch (short_option) {
2133 case 'j': {
2134 m_dumper_options.json = true;
2135 break;
2136 }
2137 case 'J': {
2138 m_dumper_options.json = true;
2140 break;
2141 }
2142 case 'F': {
2143 m_output_file.emplace(option_arg);
2144 break;
2145 }
2146 default:
2147 llvm_unreachable("Unimplemented option");
2148 }
2149 return error;
2150 }
2151
2152 void OptionParsingStarting(ExecutionContext *execution_context) override {
2153 m_dumper_options = {};
2154 m_output_file = std::nullopt;
2155 }
2156
2157 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2158 return llvm::ArrayRef(g_thread_trace_dump_function_calls_options);
2159 }
2160
2161 static const size_t kDefaultCount = 20;
2162
2163 // Instance variables to hold the values for command options.
2165 std::optional<FileSpec> m_output_file;
2166 };
2167
2170 interpreter, "thread trace dump function-calls",
2171 "Dump the traced function-calls for one thread. If no "
2172 "thread is specified, the current thread is used.",
2173 nullptr,
2174 eCommandRequiresProcess | eCommandRequiresThread |
2175 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
2176 eCommandProcessMustBePaused | eCommandProcessMustBeTraced) {
2178 }
2179
2181
2182 Options *GetOptions() override { return &m_options; }
2183
2184protected:
2185 void DoExecute(Args &args, CommandReturnObject &result) override {
2186 ThreadSP thread_sp = GetSingleThreadFromArgs(m_exe_ctx, args, result);
2187 if (!thread_sp) {
2188 result.AppendError("invalid thread\n");
2189 return;
2190 }
2191
2192 llvm::Expected<TraceCursorSP> cursor_or_error =
2193 m_exe_ctx.GetTargetSP()->GetTrace()->CreateNewCursor(*thread_sp);
2194
2195 if (!cursor_or_error) {
2196 result.AppendError(llvm::toString(cursor_or_error.takeError()));
2197 return;
2198 }
2199 TraceCursorSP &cursor_sp = *cursor_or_error;
2200
2201 std::optional<StreamFile> out_file;
2203 out_file.emplace(m_options.m_output_file->GetPath().c_str(),
2206 }
2207
2209
2210 TraceDumper dumper(std::move(cursor_sp),
2211 out_file ? *out_file : result.GetOutputStream(),
2213
2214 dumper.DumpFunctionCalls();
2215 }
2216
2218};
2219
2220// CommandObjectTraceDumpInstructions
2221#define LLDB_OPTIONS_thread_trace_dump_instructions
2222#include "CommandOptions.inc"
2223
2225public:
2226 class CommandOptions : public Options {
2227 public:
2229
2230 ~CommandOptions() override = default;
2231
2232 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2233 ExecutionContext *execution_context) override {
2234 Status error;
2235 const int short_option = m_getopt_table[option_idx].val;
2236
2237 switch (short_option) {
2238 case 'c': {
2239 int32_t count;
2240 if (option_arg.empty() || option_arg.getAsInteger(0, count) ||
2241 count < 0)
2243 "invalid integer value for option '%s'",
2244 option_arg.str().c_str());
2245 else
2246 m_count = count;
2247 break;
2248 }
2249 case 'a': {
2250 m_count = std::numeric_limits<decltype(m_count)>::max();
2251 break;
2252 }
2253 case 's': {
2254 int32_t skip;
2255 if (option_arg.empty() || option_arg.getAsInteger(0, skip) || skip < 0)
2257 "invalid integer value for option '%s'",
2258 option_arg.str().c_str());
2259 else
2260 m_dumper_options.skip = skip;
2261 break;
2262 }
2263 case 'i': {
2264 uint64_t id;
2265 if (option_arg.empty() || option_arg.getAsInteger(0, id))
2267 "invalid integer value for option '%s'",
2268 option_arg.str().c_str());
2269 else
2271 break;
2272 }
2273 case 'F': {
2274 m_output_file.emplace(option_arg);
2275 break;
2276 }
2277 case 'r': {
2278 m_dumper_options.raw = true;
2279 break;
2280 }
2281 case 'f': {
2283 break;
2284 }
2285 case 'k': {
2287 break;
2288 }
2289 case 't': {
2291 break;
2292 }
2293 case 'e': {
2295 break;
2296 }
2297 case 'j': {
2298 m_dumper_options.json = true;
2299 break;
2300 }
2301 case 'J': {
2303 m_dumper_options.json = true;
2304 break;
2305 }
2306 case 'E': {
2309 break;
2310 }
2311 case 'C': {
2312 m_continue = true;
2313 break;
2314 }
2315 default:
2316 llvm_unreachable("Unimplemented option");
2317 }
2318 return error;
2319 }
2320
2321 void OptionParsingStarting(ExecutionContext *execution_context) override {
2323 m_continue = false;
2324 m_output_file = std::nullopt;
2325 m_dumper_options = {};
2326 }
2327
2328 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2329 return llvm::ArrayRef(g_thread_trace_dump_instructions_options);
2330 }
2331
2332 static const size_t kDefaultCount = 20;
2333
2334 // Instance variables to hold the values for command options.
2335 size_t m_count;
2337 std::optional<FileSpec> m_output_file;
2339 };
2340
2343 interpreter, "thread trace dump instructions",
2344 "Dump the traced instructions for one thread. If no "
2345 "thread is specified, show the current thread.",
2346 nullptr,
2347 eCommandRequiresProcess | eCommandRequiresThread |
2348 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
2349 eCommandProcessMustBePaused | eCommandProcessMustBeTraced) {
2351 }
2352
2354
2355 Options *GetOptions() override { return &m_options; }
2356
2357 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
2358 uint32_t index) override {
2359 std::string cmd;
2360 current_command_args.GetCommandString(cmd);
2361 if (cmd.find(" --continue") == std::string::npos)
2362 cmd += " --continue";
2363 return cmd;
2364 }
2365
2366protected:
2367 void DoExecute(Args &args, CommandReturnObject &result) override {
2368 ThreadSP thread_sp = GetSingleThreadFromArgs(m_exe_ctx, args, result);
2369 if (!thread_sp) {
2370 result.AppendError("invalid thread\n");
2371 return;
2372 }
2373
2375 // We set up the options to continue one instruction past where
2376 // the previous iteration stopped.
2379 }
2380
2381 llvm::Expected<TraceCursorSP> cursor_or_error =
2382 m_exe_ctx.GetTargetSP()->GetTrace()->CreateNewCursor(*thread_sp);
2383
2384 if (!cursor_or_error) {
2385 result.AppendError(llvm::toString(cursor_or_error.takeError()));
2386 return;
2387 }
2388 TraceCursorSP &cursor_sp = *cursor_or_error;
2389
2391 !cursor_sp->HasId(*m_options.m_dumper_options.id)) {
2392 result.AppendError("invalid instruction id\n");
2393 return;
2394 }
2395
2396 std::optional<StreamFile> out_file;
2398 out_file.emplace(m_options.m_output_file->GetPath().c_str(),
2401 }
2402
2403 if (m_options.m_continue && !m_last_id) {
2404 // We need to stop processing data when we already ran out of instructions
2405 // in a previous command. We can fake this by setting the cursor past the
2406 // end of the trace.
2407 cursor_sp->Seek(1, lldb::eTraceCursorSeekTypeEnd);
2408 }
2409
2410 TraceDumper dumper(std::move(cursor_sp),
2411 out_file ? *out_file : result.GetOutputStream(),
2413
2415 }
2416
2418 // Last traversed id used to continue a repeat command. std::nullopt means
2419 // that all the trace has been consumed.
2420 std::optional<lldb::user_id_t> m_last_id;
2421};
2422
2423// CommandObjectTraceDumpInfo
2424#define LLDB_OPTIONS_thread_trace_dump_info
2425#include "CommandOptions.inc"
2426
2428public:
2429 class CommandOptions : public Options {
2430 public:
2432
2433 ~CommandOptions() override = default;
2434
2435 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2436 ExecutionContext *execution_context) override {
2437 Status error;
2438 const int short_option = m_getopt_table[option_idx].val;
2439
2440 switch (short_option) {
2441 case 'v': {
2442 m_verbose = true;
2443 break;
2444 }
2445 case 'j': {
2446 m_json = true;
2447 break;
2448 }
2449 default:
2450 llvm_unreachable("Unimplemented option");
2451 }
2452 return error;
2453 }
2454
2455 void OptionParsingStarting(ExecutionContext *execution_context) override {
2456 m_verbose = false;
2457 m_json = false;
2458 }
2459
2460 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2461 return llvm::ArrayRef(g_thread_trace_dump_info_options);
2462 }
2463
2464 // Instance variables to hold the values for command options.
2467 };
2468
2471 interpreter, "thread trace dump info",
2472 "Dump the traced information for one or more threads. If no "
2473 "threads are specified, show the current thread. Use the "
2474 "thread-index \"all\" to see all threads.",
2475 nullptr,
2476 eCommandRequiresProcess | eCommandTryTargetAPILock |
2477 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
2478 eCommandProcessMustBeTraced) {}
2479
2480 ~CommandObjectTraceDumpInfo() override = default;
2481
2482 Options *GetOptions() override { return &m_options; }
2483
2484protected:
2486 const TraceSP &trace_sp = m_exe_ctx.GetTargetSP()->GetTrace();
2487 ThreadSP thread_sp =
2489 trace_sp->DumpTraceInfo(*thread_sp, result.GetOutputStream(),
2491 return true;
2492 }
2493
2495};
2496
2497// CommandObjectMultiwordTraceDump
2499public:
2502 interpreter, "dump",
2503 "Commands for displaying trace information of the threads "
2504 "in the current process.",
2505 "thread trace dump <subcommand> [<subcommand objects>]") {
2507 "instructions",
2510 "function-calls",
2513 "info", CommandObjectSP(new CommandObjectTraceDumpInfo(interpreter)));
2514 }
2516};
2517
2518// CommandObjectMultiwordTrace
2520public:
2523 interpreter, "trace",
2524 "Commands for operating on traces of the threads in the current "
2525 "process.",
2526 "thread trace <subcommand> [<subcommand objects>]") {
2528 interpreter)));
2529 LoadSubCommand("start",
2530 CommandObjectSP(new CommandObjectTraceStart(interpreter)));
2531 LoadSubCommand("stop",
2532 CommandObjectSP(new CommandObjectTraceStop(interpreter)));
2533 LoadSubCommand("export",
2534 CommandObjectSP(new CommandObjectTraceExport(interpreter)));
2535 }
2536
2537 ~CommandObjectMultiwordTrace() override = default;
2538};
2539
2540// CommandObjectMultiwordThread
2541
2543 CommandInterpreter &interpreter)
2544 : CommandObjectMultiword(interpreter, "thread",
2545 "Commands for operating on "
2546 "one or more threads in "
2547 "the current process.",
2548 "thread <subcommand> [<subcommand-options>]") {
2550 interpreter)));
2551 LoadSubCommand("continue",
2553 LoadSubCommand("list",
2554 CommandObjectSP(new CommandObjectThreadList(interpreter)));
2555 LoadSubCommand("return",
2556 CommandObjectSP(new CommandObjectThreadReturn(interpreter)));
2557 LoadSubCommand("jump",
2558 CommandObjectSP(new CommandObjectThreadJump(interpreter)));
2559 LoadSubCommand("select",
2560 CommandObjectSP(new CommandObjectThreadSelect(interpreter)));
2561 LoadSubCommand("until",
2562 CommandObjectSP(new CommandObjectThreadUntil(interpreter)));
2563 LoadSubCommand("info",
2564 CommandObjectSP(new CommandObjectThreadInfo(interpreter)));
2566 interpreter)));
2567 LoadSubCommand("siginfo",
2569 LoadSubCommand("step-in",
2571 interpreter, "thread step-in",
2572 "Source level single step, stepping into calls. Defaults "
2573 "to current thread unless specified.",
2574 nullptr, eStepTypeInto)));
2575
2576 LoadSubCommand("step-out",
2578 interpreter, "thread step-out",
2579 "Finish executing the current stack frame and stop after "
2580 "returning. Defaults to current thread unless specified.",
2581 nullptr, eStepTypeOut)));
2582
2583 LoadSubCommand("step-over",
2585 interpreter, "thread step-over",
2586 "Source level single step, stepping over calls. Defaults "
2587 "to current thread unless specified.",
2588 nullptr, eStepTypeOver)));
2589
2590 LoadSubCommand("step-inst",
2592 interpreter, "thread step-inst",
2593 "Instruction level single step, stepping into calls. "
2594 "Defaults to current thread unless specified.",
2595 nullptr, eStepTypeTrace)));
2596
2597 LoadSubCommand("step-inst-over",
2599 interpreter, "thread step-inst-over",
2600 "Instruction level single step, stepping over calls. "
2601 "Defaults to current thread unless specified.",
2602 nullptr, eStepTypeTraceOver)));
2603
2605 "step-scripted",
2607 interpreter, "thread step-scripted",
2608 "Step as instructed by the script class passed in the -C option. "
2609 "You can also specify a dictionary of key (-k) and value (-v) pairs "
2610 "that will be used to populate an SBStructuredData Dictionary, which "
2611 "will be passed to the constructor of the class implementing the "
2612 "scripted step. See the Python Reference for more details.",
2613 nullptr, eStepTypeScripted)));
2614
2616 interpreter)));
2617 LoadSubCommand("trace",
2619}
2620
static ThreadSP GetSingleThreadFromArgs(ExecutionContext &exe_ctx, Args &args, CommandReturnObject &result)
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:454
~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
void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector) override
The default version handles argument definitions that have only one argument type,...
CommandObjectThreadStepWithTypeAndScope(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, StepType step_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:120
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:347
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:332
llvm::ArrayRef< ArgEntry > entries() const
Definition: Args.h:132
const char * GetArgumentAtIndex(size_t idx) const
Gets the NULL terminated C string argument pointer for the argument at index idx.
Definition: Args.cpp:273
bool GetCommandString(std::string &command) const
Definition: Args.cpp:215
bool GetQuotedCommandString(std::string &command) const
Definition: Args.cpp:232
A class that describes a single lexical block.
Definition: Block.h:41
bool GetRangeContainingAddress(const Address &addr, AddressRange &range)
Definition: Block.cpp:243
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 AppendErrorWithFormatv(const char *format, Args &&... args)
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)
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:359
void SetUseDynamic(lldb::DynamicValueType dynamic=lldb::eDynamicCanRunTarget)
Definition: Target.h:374
"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:91
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()
DEPRECATED: Use GetAddressRanges instead.
Definition: Function.h:448
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:788
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:343
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:542
ThreadList & GetThreadList()
Definition: Process.h:2182
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition: Process.cpp:1355
void PruneThreadPlans()
Prune ThreadPlanStacks for all unreported threads.
Definition: Process.cpp:1247
bool PruneThreadPlansForTID(lldb::tid_t tid)
Prune ThreadPlanStacks for unreported threads.
Definition: Process.cpp:1243
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:1251
Status ResumeSynchronous(Stream *stream)
Resume a process, and wait for it to stop.
Definition: Process.cpp:1372
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:5767
lldb::StateType GetState()
Get accessor for the current process state.
Definition: Process.cpp:1308
void GetStatus(Stream &ostrm)
Definition: Process.cpp:5747
uint32_t GetIOHandlerID() const
Definition: Process.h:2244
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:1258
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:636
This base class provides an interface to stack frames.
Definition: StackFrame.h:44
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:301
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:191
An error handling class.
Definition: Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:141
bool Fail() const
Test for error condition.
Definition: Status.cpp:294
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
llvm::Error GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range)
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.
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:2790
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:1328
Status UnwindInnermostExpression()
Unwinds the thread stack for the innermost expression plan currently on the thread plan stack.
Definition: Thread.cpp:1244
virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx)
Definition: Thread.h:408
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:1384
void AutoCompleteThreadPlans(CompletionRequest &request) const
Format the thread plan information for auto completion.
Definition: Thread.cpp:1127
uint32_t GetIndexID() const
Definition: Thread.cpp:1406
bool GetDescription(Stream &s, lldb::DescriptionLevel level, bool print_json_thread, bool print_json_stopinfo)
Definition: Thread.cpp:1818
void SetResumeState(lldb::StateType state, bool override_suspend=false)
Sets the USER resume state for this thread.
Definition: Thread.h:187
lldb::StackFrameSP GetSelectedFrame(SelectMostRelevant select_most_relevant)
Definition: Thread.cpp:271
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:1203
uint32_t GetSelectedFrameIndex(SelectMostRelevant select_most_relevant)
Definition: Thread.h:444
lldb::ProcessSP GetProcess() const
Definition: Thread.h:157
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:1298
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:1394
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:1262
Status JumpToLine(const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings=nullptr)
Definition: Thread.cpp:1571
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:1271
bool SetSelectedFrameByIndexNoisily(uint32_t frame_idx, Stream &output_stream)
Definition: Thread.cpp:300
size_t GetStatus(Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source, bool stop_format, bool show_hidden, bool only_stacks=false)
Definition: Thread.cpp:1761
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:458
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
Definition: lldb-forward.h:453
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:424
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelFull
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:450
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:333
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
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:389
@ 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:460
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:448
@ 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:95
uint32_t arg_opt_set_association
This arg might be associated only with some particular option set(s).
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