43 #define LLDB_OPTIONS_thread_backtrace
44 #include "CommandOptions.inc"
53 OptionParsingStarting(
nullptr);
61 const int short_option = m_getopt_table[option_idx].val;
63 switch (short_option) {
65 int32_t input_count = 0;
66 if (option_arg.getAsInteger(0, m_count)) {
68 error.SetErrorStringWithFormat(
69 "invalid integer value for option '%c'", short_option);
70 }
else if (input_count < 0)
74 if (option_arg.getAsInteger(0, m_start))
75 error.SetErrorStringWithFormat(
76 "invalid integer value for option '%c'", short_option);
80 m_extended_backtrace =
81 OptionArgParser::ToBoolean(option_arg,
false, &success);
83 error.SetErrorStringWithFormat(
84 "invalid boolean value for option '%c'", short_option);
87 llvm_unreachable(
"Unimplemented option");
95 m_extended_backtrace =
false;
99 return llvm::makeArrayRef(g_thread_backtrace_options);
110 interpreter,
"thread backtrace",
111 "Show thread call stacks. Defaults to the current thread, thread "
112 "indexes can be specified as arguments.\n"
113 "Use the thread-index \"all\" to see all threads.\n"
114 "Use the thread-index \"unique\" to see threads grouped by unique "
116 "Use 'settings set frame-format' to customize the printing of "
117 "frames in the backtrace and 'settings set thread-format' to "
118 "customize the thread header.",
120 eCommandRequiresProcess | eCommandRequiresThread |
121 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
122 eCommandProcessMustBePaused) {}
130 llvm::StringRef count_opt(
"--count");
131 llvm::StringRef start_opt(
"--start");
138 Args copy_args(current_args);
141 size_t count_idx = 0;
142 size_t start_idx = 0;
143 size_t count_val = 0;
144 size_t start_val = 0;
146 for (
size_t idx = 0; idx < num_entries; idx++) {
147 llvm::StringRef arg_string = copy_args[idx].ref();
148 if (arg_string.equals(
"-c") || count_opt.startswith(arg_string)) {
150 if (idx == num_entries)
153 if (copy_args[idx].ref().getAsInteger(0, count_val))
155 }
else if (arg_string.equals(
"-s") || start_opt.startswith(arg_string)) {
157 if (idx == num_entries)
160 if (copy_args[idx].ref().getAsInteger(0, start_val))
167 std::string new_start_val = llvm::formatv(
"{0}", start_val + count_val);
168 if (start_idx == 0) {
177 return repeat_command;
185 const std::vector<ConstString> &types =
187 for (
auto type : types) {
189 thread->shared_from_this(), type);
190 if (ext_thread_sp && ext_thread_sp->IsValid()) {
191 const uint32_t num_frames_with_source = 0;
192 const bool stop_format =
false;
193 if (ext_thread_sp->GetStatus(strm, m_options.m_start,
195 num_frames_with_source, stop_format)) {
196 DoExtendedBacktrace(ext_thread_sp.get(), result);
205 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
208 "thread disappeared while computing backtraces: 0x%" PRIx64
"\n",
213 Thread *thread = thread_sp.get();
218 const bool only_stacks = m_unique_stacks;
221 const uint32_t num_frames_with_source = 0;
222 const bool stop_format =
true;
223 if (!thread->
GetStatus(strm, m_options.m_start, m_options.m_count,
224 num_frames_with_source, stop_format, only_stacks)) {
226 "error displaying backtrace for thread: \"0x%4.4x\"\n",
230 if (m_options.m_extended_backtrace) {
231 DoExtendedBacktrace(thread, result);
246 "Run only this thread while stepping"}};
252 #define LLDB_OPTIONS_thread_step_scope
253 #include "CommandOptions.inc"
260 OptionParsingStarting(
nullptr);
266 return llvm::makeArrayRef(g_thread_step_scope_options);
272 const int short_option =
273 g_thread_step_scope_options[option_idx].short_option;
275 switch (short_option) {
278 bool avoid_no_debug =
279 OptionArgParser::ToBoolean(option_arg,
true, &success);
281 error.SetErrorStringWithFormat(
"invalid boolean value for option '%c'",
290 bool avoid_no_debug =
291 OptionArgParser::ToBoolean(option_arg,
true, &success);
293 error.SetErrorStringWithFormat(
"invalid boolean value for option '%c'",
301 if (option_arg.getAsInteger(0, m_step_count))
302 error.SetErrorStringWithFormat(
"invalid step count '%s'",
303 option_arg.str().c_str());
307 auto enum_values = GetDefinitions()[option_idx].enum_values;
313 if (option_arg ==
"block") {
314 m_end_line_is_block_end =
true;
317 if (option_arg.getAsInteger(0, m_end_line))
318 error.SetErrorStringWithFormat(
"invalid end line number '%s'",
319 option_arg.str().c_str());
323 m_avoid_regexp.clear();
328 m_step_in_target.clear();
333 llvm_unreachable(
"Unimplemented option");
345 execution_context ? execution_context->
GetTargetSP() : TargetSP();
346 ProcessSP process_sp =
347 execution_context ? execution_context->
GetProcessSP() : ProcessSP();
348 if (process_sp && process_sp->GetSteppingRunsAllThreads())
351 m_avoid_regexp.clear();
352 m_step_in_target.clear();
355 m_end_line_is_block_end =
false;
372 const char *name,
const char *help,
377 eCommandRequiresProcess | eCommandRequiresThread |
378 eCommandTryTargetAPILock |
379 eCommandProcessMustBeLaunched |
380 eCommandProcessMustBePaused),
381 m_step_type(step_type), m_step_scope(step_scope),
382 m_class_options(
"scripted step") {
392 arg.push_back(thread_id_arg);
395 m_arguments.push_back(arg);
401 m_all_options.Append(&m_options);
402 m_all_options.Finalize();
413 CommandCompletions::InvokeCommonCompletionCallbacks(
414 GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
422 Process *process = m_exe_ctx.GetProcessPtr();
423 bool synchronous_execution = m_interpreter.GetSynchronous();
429 thread = GetDefaultThread();
431 if (thread ==
nullptr) {
432 result.
AppendError(
"no selected thread in process");
439 if (!llvm::to_integer(thread_idx_cstr, step_thread_idx)) {
446 if (thread ==
nullptr) {
448 "Thread index %u is out of range (valid values are 0 - %u).\n",
449 step_thread_idx, num_threads);
455 if (m_class_options.GetName().empty()) {
458 }
else if (!GetDebugger().GetScriptInterpreter()->CheckObjectExists(
459 m_class_options.GetName().c_str())) {
461 "class for scripted step: \"%s\" does not exist.",
462 m_class_options.GetName().c_str());
470 "end line option is only valid for step into");
474 const bool abort_other_plans =
false;
475 const lldb::RunMode stop_other_threads = m_options.m_run_mode;
479 bool bool_stop_other_threads;
481 bool_stop_other_threads =
false;
483 bool_stop_other_threads = (m_step_type !=
eStepTypeOut);
485 bool_stop_other_threads =
true;
487 ThreadPlanSP new_plan_sp;
492 assert(frame !=
nullptr);
505 }
else if (m_options.m_end_line_is_block_end) {
518 "Could not find the current block address.");
532 abort_other_plans, range,
534 m_options.m_step_in_target.c_str(), stop_other_threads,
535 new_plan_status, m_options.m_step_in_avoid_no_debug,
536 m_options.m_step_out_avoid_no_debug);
538 if (new_plan_sp && !m_options.m_avoid_regexp.empty()) {
541 step_in_range_plan->
SetAvoidRegexp(m_options.m_avoid_regexp.c_str());
545 false, abort_other_plans, bool_stop_other_threads, new_plan_status);
554 stop_other_threads, new_plan_status,
555 m_options.m_step_out_avoid_no_debug);
558 true, abort_other_plans, bool_stop_other_threads, new_plan_status);
561 false, abort_other_plans, bool_stop_other_threads, new_plan_status);
564 true, abort_other_plans, bool_stop_other_threads, new_plan_status);
567 abort_other_plans,
nullptr,
false, bool_stop_other_threads,
eVoteYes,
569 m_options.m_step_out_avoid_no_debug);
572 abort_other_plans, m_class_options.GetName().c_str(),
573 m_class_options.GetStructuredData(), bool_stop_other_threads,
585 new_plan_sp->SetIsControllingPlan(
true);
586 new_plan_sp->SetOkayToDiscard(
false);
588 if (m_options.m_step_count > 1) {
589 if (!new_plan_sp->SetIterationCount(m_options.m_step_count)) {
591 "step operation does not support iteration count.");
601 if (synchronous_execution)
606 if (!
error.Success()) {
615 process->
SyncIOHandler(iohandler_id, std::chrono::seconds(2));
617 if (synchronous_execution) {
648 interpreter,
"thread continue",
649 "Continue execution of the current target process. One "
650 "or more threads may be specified, by default all "
653 eCommandRequiresThread | eCommandTryTargetAPILock |
654 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
664 arg.push_back(thread_idx_arg);
667 m_arguments.push_back(arg);
675 CommandCompletions::InvokeCommonCompletionCallbacks(
676 GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
681 bool synchronous_execution = m_interpreter.GetSynchronous();
683 Process *process = m_exe_ctx.GetProcessPtr();
684 if (process ==
nullptr) {
685 result.
AppendError(
"no process exists. Cannot continue");
697 std::lock_guard<std::recursive_mutex> guard(
700 std::vector<Thread *> resume_threads;
701 for (
auto &entry : command.
entries()) {
703 if (entry.ref().getAsInteger(0, thread_idx)) {
705 "invalid thread index argument: \"%s\".\n", entry.c_str());
712 resume_threads.push_back(thread);
720 if (resume_threads.empty()) {
721 result.
AppendError(
"no valid thread indexes were specified");
724 if (resume_threads.size() == 1)
729 for (
uint32_t idx = 0; idx < num_threads; ++idx) {
732 std::vector<Thread *>::iterator this_thread_pos =
733 find(resume_threads.begin(), resume_threads.end(), thread);
735 if (this_thread_pos != resume_threads.end()) {
736 resume_threads.erase(this_thread_pos);
737 if (!resume_threads.empty())
742 const bool override_suspend =
true;
755 std::lock_guard<std::recursive_mutex> guard(
758 Thread *current_thread = GetDefaultThread();
759 if (current_thread ==
nullptr) {
760 result.
AppendError(
"the process doesn't have a current thread");
764 for (
uint32_t idx = 0; idx < num_threads; ++idx) {
766 if (thread == current_thread) {
768 " in process %" PRIu64
"\n",
770 const bool override_suspend =
true;
780 if (synchronous_execution)
786 if (
error.Success()) {
789 if (synchronous_execution) {
806 "Process cannot be continued from its current state (%s).\n",
824 #define LLDB_OPTIONS_thread_until
825 #include "CommandOptions.inc"
837 OptionParsingStarting(
nullptr);
845 const int short_option = m_getopt_table[option_idx].val;
847 switch (short_option) {
852 m_until_addrs.push_back(tmp_addr);
855 if (option_arg.getAsInteger(0, m_thread_idx)) {
857 error.SetErrorStringWithFormat(
"invalid thread index '%s'",
858 option_arg.str().c_str());
862 if (option_arg.getAsInteger(0, m_frame_idx)) {
864 error.SetErrorStringWithFormat(
"invalid frame index '%s'",
865 option_arg.str().c_str());
869 auto enum_values = GetDefinitions()[option_idx].enum_values;
873 if (
error.Success()) {
875 m_stop_others =
false;
877 m_stop_others =
true;
881 llvm_unreachable(
"Unimplemented option");
889 m_stop_others =
false;
890 m_until_addrs.clear();
894 return llvm::makeArrayRef(g_thread_until_options);
906 interpreter,
"thread until",
907 "Continue until a line number or address is reached by the "
908 "current or specified thread. Stops when returning from "
909 "the current function as a safety measure. "
910 "The target line number(s) are given as arguments, and if more "
912 " is provided, stepping will stop when the first one is hit.",
914 eCommandRequiresThread | eCommandTryTargetAPILock |
915 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
925 arg.push_back(line_num_arg);
928 m_arguments.push_back(arg);
937 bool synchronous_execution = m_interpreter.GetSynchronous();
939 Target *target = &GetSelectedTarget();
941 Process *process = m_exe_ctx.GetProcessPtr();
942 if (process ==
nullptr) {
943 result.
AppendError(
"need a valid process to step");
946 std::vector<uint32_t> line_numbers;
950 for (
size_t i = 0; i < num_args; i++) {
957 line_numbers.push_back(line_number);
959 }
else if (m_options.m_until_addrs.empty()) {
961 GetSyntax().str().c_str());
966 thread = GetDefaultThread();
973 if (thread ==
nullptr) {
976 "Thread index %u is out of range (valid values are 0 - %u).\n",
977 m_options.m_thread_idx, num_threads);
981 const bool abort_other_plans =
false;
985 if (frame ==
nullptr) {
987 "Frame index %u is out of range for thread id %" PRIu64
".\n",
988 m_options.m_frame_idx, thread->
GetID());
992 ThreadPlanSP new_plan_sp;
1003 if (line_table ==
nullptr) {
1005 "frame %u of thread id %" PRIu64
".\n",
1006 m_options.m_frame_idx, thread->
GetID());
1012 std::vector<addr_t> address_list;
1018 "function info - can't get until range.");
1031 bool all_in_function =
true;
1036 for (
uint32_t line_number : line_numbers) {
1037 uint32_t start_idx_ptr = index_ptr;
1038 while (start_idx_ptr <= end_ptr) {
1040 const bool exact =
false;
1042 start_idx_ptr, line_number,
nullptr, exact, &line_entry);
1050 address_list.push_back(address);
1052 all_in_function =
false;
1060 address_list.push_back(address);
1062 all_in_function =
false;
1065 if (address_list.empty()) {
1066 if (all_in_function)
1068 "No line entries matching until target.\n");
1071 "Until target outside of the current function.\n");
1077 abort_other_plans, &address_list.front(), address_list.size(),
1078 m_options.m_stop_others, m_options.m_frame_idx, new_plan_status);
1085 new_plan_sp->SetIsControllingPlan(
true);
1086 new_plan_sp->SetOkayToDiscard(
false);
1093 " has no debug information.\n",
1094 m_options.m_frame_idx, thread->
GetID());
1100 "Failed to set the selected thread to thread id %" PRIu64
".\n",
1107 if (synchronous_execution)
1112 if (
error.Success()) {
1115 if (synchronous_execution) {
1143 "Change the currently selected thread.", nullptr,
1144 eCommandRequiresProcess | eCommandTryTargetAPILock |
1145 eCommandProcessMustBeLaunched |
1146 eCommandProcessMustBePaused) {
1156 arg.push_back(thread_idx_arg);
1159 m_arguments.push_back(arg);
1170 CommandCompletions::InvokeCommonCompletionCallbacks(
1171 GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
1177 Process *process = m_exe_ctx.GetProcessPtr();
1178 if (process ==
nullptr) {
1183 "'%s' takes exactly one thread index argument:\nUsage: %s\n",
1184 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1197 if (new_thread ==
nullptr) {
1216 interpreter,
"thread list",
1217 "Show a summary of each thread in the current target process. "
1218 "Use 'settings set thread-format' to customize the individual "
1221 eCommandRequiresProcess | eCommandTryTargetAPILock |
1222 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1230 Process *process = m_exe_ctx.GetProcessPtr();
1231 const bool only_threads_with_stop_reason =
false;
1234 const uint32_t num_frames_with_source = 0;
1236 process->
GetThreadStatus(strm, only_threads_with_stop_reason, start_frame,
1237 num_frames, num_frames_with_source,
false);
1243 #define LLDB_OPTIONS_thread_info
1244 #include "CommandOptions.inc"
1255 m_json_thread =
false;
1256 m_json_stopinfo =
false;
1261 const int short_option = m_getopt_table[option_idx].val;
1264 switch (short_option) {
1266 m_json_thread =
true;
1270 m_json_stopinfo =
true;
1274 llvm_unreachable(
"Unimplemented option");
1280 return llvm::makeArrayRef(g_thread_info_options);
1289 interpreter,
"thread info",
1290 "Show an extended summary of one or "
1291 "more threads. Defaults to the "
1294 eCommandRequiresProcess | eCommandTryTargetAPILock |
1295 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
1296 m_add_return =
false;
1304 CommandCompletions::InvokeCommonCompletionCallbacks(
1305 GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
1312 ThreadSP thread_sp =
1313 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1320 Thread *thread = thread_sp.get();
1324 m_options.m_json_thread,
1325 m_options.m_json_stopinfo)) {
1342 interpreter,
"thread exception",
1343 "Display the current exception object for a thread. Defaults to "
1344 "the current thread.",
1346 eCommandRequiresProcess | eCommandTryTargetAPILock |
1347 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1354 CommandCompletions::InvokeCommonCompletionCallbacks(
1355 GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
1360 ThreadSP thread_sp =
1361 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1369 ValueObjectSP exception_object_sp = thread_sp->GetCurrentException();
1370 if (exception_object_sp) {
1371 exception_object_sp->Dump(strm);
1374 ThreadSP exception_thread_sp = thread_sp->GetCurrentExceptionBacktrace();
1375 if (exception_thread_sp && exception_thread_sp->IsValid()) {
1376 const uint32_t num_frames_with_source = 0;
1377 const bool stop_format =
false;
1378 exception_thread_sp->GetStatus(strm, 0,
UINT32_MAX,
1379 num_frames_with_source, stop_format);
1390 interpreter,
"thread siginfo",
1391 "Display the current siginfo object for a thread. Defaults to "
1392 "the current thread.",
1394 eCommandRequiresProcess | eCommandTryTargetAPILock |
1395 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1402 CommandCompletions::InvokeCommonCompletionCallbacks(
1403 GetCommandInterpreter(), CommandCompletions::eThreadIndexCompletion,
1408 ThreadSP thread_sp =
1409 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1419 thread_sp->GetIndexID());
1422 ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
1423 if (exception_object_sp)
1424 exception_object_sp->Dump(strm);
1426 strm.
Printf(
"(no siginfo)\n");
1434 #define LLDB_OPTIONS_thread_return
1435 #include "CommandOptions.inc"
1444 OptionParsingStarting(
nullptr);
1452 const int short_option = m_getopt_table[option_idx].val;
1454 switch (short_option) {
1458 OptionArgParser::ToBoolean(option_arg,
false, &success);
1460 m_from_expression = tmp_value;
1462 error.SetErrorStringWithFormat(
1463 "invalid boolean value '%s' for 'x' option",
1464 option_arg.str().c_str());
1468 llvm_unreachable(
"Unimplemented option");
1474 m_from_expression =
false;
1478 return llvm::makeArrayRef(g_thread_return_options);
1481 bool m_from_expression =
false;
1488 "Prematurely return from a stack frame, "
1489 "short-circuiting execution of newer frames "
1490 "and optionally yielding a specified value. Defaults "
1491 "to the exiting the current stack "
1494 eCommandRequiresFrame | eCommandTryTargetAPILock |
1495 eCommandProcessMustBeLaunched |
1496 eCommandProcessMustBePaused) {
1506 arg.push_back(expression_arg);
1509 m_arguments.push_back(arg);
1522 if (command.startswith(
"-x")) {
1523 if (command.size() != 2U)
1524 result.
AppendWarning(
"Return values ignored when returning from user "
1525 "called expressions");
1527 Thread *thread = m_exe_ctx.GetThreadPtr();
1530 if (!
error.Success()) {
1541 "Could not select 0th frame after unwinding expression.");
1547 ValueObjectSP return_valobj_sp;
1549 StackFrameSP frame_sp = m_exe_ctx.GetFrameSP();
1550 uint32_t frame_idx = frame_sp->GetFrameIndex();
1552 if (frame_sp->IsInlined()) {
1553 result.
AppendError(
"Don't know how to return from inlined frames.");
1557 if (!command.empty()) {
1558 Target *target = m_exe_ctx.GetTargetPtr();
1566 return_valobj_sp, options);
1568 if (return_valobj_sp)
1570 "Error evaluating result expression: %s",
1571 return_valobj_sp->GetError().AsCString());
1574 "Unknown error evaluating result expression.");
1580 ThreadSP thread_sp = m_exe_ctx.GetThreadSP();
1581 const bool broadcast =
true;
1582 error = thread_sp->ReturnFromFrame(frame_sp, return_valobj_sp, broadcast);
1583 if (!
error.Success()) {
1585 "Error returning from frame %d of thread %d: %s.", frame_idx,
1586 thread_sp->GetIndexID(),
error.AsCString());
1598 #define LLDB_OPTIONS_thread_jump
1599 #include "CommandOptions.inc"
1610 m_filenames.Clear();
1619 const int short_option = m_getopt_table[option_idx].val;
1622 switch (short_option) {
1624 m_filenames.AppendIfUnique(
FileSpec(option_arg));
1625 if (m_filenames.GetSize() > 1)
1626 return Status(
"only one source file expected.");
1629 if (option_arg.getAsInteger(0, m_line_num))
1630 return Status(
"invalid line number: '%s'.", option_arg.str().c_str());
1633 if (option_arg.getAsInteger(0, m_line_offset))
1634 return Status(
"invalid line offset: '%s'.", option_arg.str().c_str());
1637 m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg,
1644 llvm_unreachable(
"Unimplemented option");
1650 return llvm::makeArrayRef(g_thread_jump_options);
1662 interpreter,
"thread jump",
1663 "Sets the program counter to a new address.",
"thread jump",
1664 eCommandRequiresFrame | eCommandTryTargetAPILock |
1665 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1675 Thread *thread = m_exe_ctx.GetThreadPtr();
1676 Target *target = m_exe_ctx.GetTargetPtr();
1690 if (!reg_ctx->
SetPC(callAddr)) {
1697 int32_t line = (int32_t)m_options.m_line_num;
1703 if (m_options.m_filenames.GetSize() == 1)
1704 file = m_options.m_filenames.GetFileSpecAtIndex(0);
1708 "No source file available for the current location.");
1720 if (!warnings.empty())
1734 #define LLDB_OPTIONS_thread_plan_list
1735 #include "CommandOptions.inc"
1744 OptionParsingStarting(
nullptr);
1751 const int short_option = m_getopt_table[option_idx].val;
1753 switch (short_option) {
1759 if (option_arg.getAsInteger(0, tid))
1760 return Status(
"invalid tid: '%s'.", option_arg.str().c_str());
1761 m_tids.push_back(tid);
1764 m_unreported =
false;
1770 llvm_unreachable(
"Unimplemented option");
1778 m_unreported =
true;
1784 return llvm::makeArrayRef(g_thread_plan_list_options);
1796 interpreter,
"thread plan list",
1797 "Show thread plans for one or more threads. If no threads are "
1798 "specified, show the "
1799 "current thread. Use the thread-index \"all\" to see all threads.",
1801 eCommandRequiresProcess | eCommandRequiresThread |
1802 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
1803 eCommandProcessMustBePaused) {}
1816 m_exe_ctx.GetProcessPtr()->DumpThreadPlans(
1817 strm, desc_level, m_options.m_internal,
true, m_options.m_unreported);
1823 if (!m_options.m_tids.empty()) {
1824 Process *process = m_exe_ctx.GetProcessPtr();
1829 true , m_options.m_unreported);
1840 return CommandObjectIterateOverThreads::DoExecute(command, result);
1847 if (llvm::is_contained(m_options.m_tids, tid))
1850 Process *process = m_exe_ctx.GetProcessPtr();
1854 if (m_options.m_verbose)
1859 m_options.m_unreported);
1870 "Discards thread plans up to and including the "
1871 "specified index (see 'thread plan list'.) "
1872 "Only user visible plans can be discarded.",
1874 eCommandRequiresProcess | eCommandRequiresThread |
1875 eCommandTryTargetAPILock |
1876 eCommandProcessMustBeLaunched |
1877 eCommandProcessMustBePaused) {
1887 arg.push_back(plan_index_arg);
1890 m_arguments.push_back(arg);
1901 m_exe_ctx.GetThreadPtr()->AutoCompleteThreadPlans(request);
1905 Thread *thread = m_exe_ctx.GetThreadPtr();
1908 "thread plan index - but got %zu.",
1916 "Invalid thread index: \"%s\" - should be unsigned int.",
1921 if (thread_plan_idx == 0) {
1923 "You wouldn't really want me to discard the base thread plan.");
1932 "Could not find User thread plan with index %s.",
1943 "Removes any thread plans associated with "
1944 "currently unreported threads. "
1945 "Specify one or more TID's to remove, or if no "
1946 "TID's are provides, remove threads for all "
1947 "unreported threads",
1949 eCommandRequiresProcess |
1950 eCommandTryTargetAPILock |
1951 eCommandProcessMustBeLaunched |
1952 eCommandProcessMustBePaused) {
1962 arg.push_back(tid_arg);
1965 m_arguments.push_back(arg);
1971 Process *process = m_exe_ctx.GetProcessPtr();
1981 std::lock_guard<std::recursive_mutex> guard(
1984 for (
size_t i = 0; i < num_args; i++) {
2008 interpreter,
"plan",
2009 "Commands for managing thread plans that control execution.",
2010 "thread plan <subcommand> [<subcommand objects]") {
2032 interpreter,
"trace thread export",
2033 "Commands for exporting traces of the threads in the current "
2034 "process to different formats.",
2035 "thread trace export <export-plugin> [<subcommand objects>]") {
2038 for (llvm::StringRef plugin_name =
2039 PluginManager::GetTraceExporterPluginNameAtIndex(i);
2040 !plugin_name.empty();
2041 plugin_name = PluginManager::GetTraceExporterPluginNameAtIndex(i++)) {
2042 if (ThreadTraceExportCommandCreator command_creator =
2043 PluginManager::GetThreadTraceExportCommandCreatorAtIndex(i)) {
2044 LoadSubCommand(plugin_name, command_creator(interpreter));
2056 true, interpreter,
"thread trace start",
2057 "Start tracing threads with the corresponding trace "
2058 "plug-in for the current process.",
2059 "thread trace start [<trace-options>]") {}
2073 interpreter,
"thread trace stop",
2074 "Stop tracing threads, including the ones traced with the "
2075 "\"process trace start\" command."
2076 "Defaults to the current thread. Thread indices can be "
2077 "specified as arguments.\n Use the thread-index \"all\" to stop "
2079 "for all existing threads.",
2080 "thread trace stop [<thread-index> <thread-index> ...]",
2081 eCommandRequiresProcess | eCommandTryTargetAPILock |
2082 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
2083 eCommandProcessMustBeTraced) {}
2088 llvm::ArrayRef<lldb::tid_t> tids)
override {
2089 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
2091 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
2103 #define LLDB_OPTIONS_thread_trace_dump_instructions
2104 #include "CommandOptions.inc"
2117 const int short_option = m_getopt_table[option_idx].val;
2119 switch (short_option) {
2122 if (option_arg.empty() || option_arg.getAsInteger(0, count) ||
2124 error.SetErrorStringWithFormat(
2125 "invalid integer value for option '%s'",
2126 option_arg.str().c_str());
2132 m_count = std::numeric_limits<decltype(m_count)>::max();
2137 if (option_arg.empty() || option_arg.getAsInteger(0, skip) || skip < 0)
2138 error.SetErrorStringWithFormat(
2139 "invalid integer value for option '%s'",
2140 option_arg.str().c_str());
2142 m_dumper_options.skip = skip;
2147 if (option_arg.empty() || option_arg.getAsInteger(0,
id))
2148 error.SetErrorStringWithFormat(
2149 "invalid integer value for option '%s'",
2150 option_arg.str().c_str());
2152 m_dumper_options.id =
id;
2156 m_output_file.emplace(option_arg);
2160 m_dumper_options.raw =
true;
2164 m_dumper_options.forwards =
true;
2168 m_dumper_options.show_tsc =
true;
2172 m_dumper_options.show_events =
true;
2176 m_dumper_options.json =
true;
2180 m_dumper_options.pretty_print_json =
true;
2181 m_dumper_options.json =
true;
2189 llvm_unreachable(
"Unimplemented option");
2195 m_count = kDefaultCount;
2197 m_output_file = llvm::None;
2198 m_dumper_options = {};
2202 return llvm::makeArrayRef(g_thread_trace_dump_instructions_options);
2205 static const size_t kDefaultCount = 20;
2216 interpreter,
"thread trace dump instructions",
2217 "Dump the traced instructions for one thread. If no "
2218 "thread is specified, show the current thread.",
2220 eCommandRequiresProcess | eCommandRequiresThread |
2221 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
2222 eCommandProcessMustBePaused | eCommandProcessMustBeTraced) {
2224 m_arguments.push_back({thread_arg});
2235 if (cmd.find(
" --continue") == std::string::npos)
2236 cmd +=
" --continue";
2243 return m_exe_ctx.GetThreadSP();
2248 if (!llvm::to_integer(arg, thread_idx)) {
2253 ThreadSP thread_sp =
2254 m_exe_ctx.GetProcessRef().GetThreadList().FindThreadByIndexID(
2262 ThreadSP thread_sp = GetThread(args, result);
2268 if (m_options.m_continue && m_last_id) {
2271 m_options.m_dumper_options.skip = 1;
2272 m_options.m_dumper_options.id = m_last_id;
2275 llvm::Expected<TraceCursorUP> cursor_or_error =
2276 m_exe_ctx.GetTargetSP()->GetTrace()->CreateNewCursor(*thread_sp);
2278 if (!cursor_or_error) {
2282 TraceCursorUP &cursor_up = *cursor_or_error;
2284 if (m_options.m_dumper_options.id &&
2285 !cursor_up->HasId(*m_options.m_dumper_options.id)) {
2290 llvm::Optional<StreamFile> out_file;
2291 if (m_options.m_output_file) {
2292 out_file.emplace(m_options.m_output_file->GetPath().c_str(),
2293 File::eOpenOptionWriteOnly | File::eOpenOptionCanCreate,
2294 lldb::eFilePermissionsFileDefault);
2297 if (m_options.m_continue && !m_last_id) {
2301 cursor_up->Seek(1, TraceCursor::SeekType::End);
2306 m_options.m_dumper_options);
2319 #define LLDB_OPTIONS_thread_trace_dump_info
2320 #include "CommandOptions.inc"
2333 const int short_option = m_getopt_table[option_idx].val;
2335 switch (short_option) {
2341 llvm_unreachable(
"Unimplemented option");
2351 return llvm::makeArrayRef(g_thread_trace_dump_info_options);
2359 Target &target = m_exe_ctx.GetTargetRef();
2361 target.
GetTrace()->GetPluginName());
2362 return CommandObjectIterateOverThreads::DoExecute(command, result);
2367 interpreter,
"thread trace dump info",
2368 "Dump the traced information for one or more threads. If no "
2369 "threads are specified, show the current thread. Use the "
2370 "thread-index \"all\" to see all threads.",
2372 eCommandRequiresProcess | eCommandTryTargetAPILock |
2373 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
2374 eCommandProcessMustBeTraced) {}
2382 const TraceSP &trace_sp = m_exe_ctx.GetTargetSP()->GetTrace();
2383 ThreadSP thread_sp =
2384 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
2386 m_options.m_verbose);
2398 interpreter,
"dump",
2399 "Commands for displaying trace information of the threads "
2400 "in the current process.",
2401 "thread trace dump <subcommand> [<subcommand objects>]") {
2416 interpreter,
"trace",
2417 "Commands for operating on traces of the threads in the current "
2419 "thread trace <subcommand> [<subcommand objects>]") {
2422 LoadSubCommand(
"start",
2424 LoadSubCommand(
"stop",
2426 LoadSubCommand(
"export",
2435 CommandObjectMultiwordThread::CommandObjectMultiwordThread(
2438 "Commands for operating on "
2439 "one or more threads in "
2440 "the current process.",
2441 "thread <subcommand> [<subcommand-options>]") {
2464 interpreter,
"thread step-in",
2465 "Source level single step, stepping into calls. Defaults "
2466 "to current thread unless specified.",
2471 interpreter,
"thread step-out",
2472 "Finish executing the current stack frame and stop after "
2473 "returning. Defaults to current thread unless specified.",
2478 interpreter,
"thread step-over",
2479 "Source level single step, stepping over calls. Defaults "
2480 "to current thread unless specified.",
2485 interpreter,
"thread step-inst",
2486 "Instruction level single step, stepping into calls. "
2487 "Defaults to current thread unless specified.",
2492 interpreter,
"thread step-inst-over",
2493 "Instruction level single step, stepping over calls. "
2494 "Defaults to current thread unless specified.",
2500 interpreter,
"thread step-scripted",
2501 "Step as instructed by the script class passed in the -C option. "
2502 "You can also specify a dictionary of key (-k) and value (-v) pairs "
2503 "that will be used to populate an SBStructuredData Dictionary, which "
2504 "will be passed to the constructor of the class implementing the "
2505 "scripted step. See the Python Reference for more details.",