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 case 'p': {
96 // Parse provider range using same format as breakpoint IDs.
97 // Supports: "N", "N-M", "N to M", "*", "all".
98 llvm::StringRef trimmed = option_arg.trim();
99 if (trimmed == "*" || trimmed.equals_insensitive("all")) {
102 break;
103 }
104
105 std::string option_lower = option_arg.lower();
106 static constexpr llvm::StringLiteral range_specifiers[] = {"-", "to"};
107
108 llvm::StringRef range_from;
109 llvm::StringRef range_to;
110 bool is_range = false;
111
112 // Try to find a range specifier.
113 for (auto specifier : range_specifiers) {
114 size_t idx = option_lower.find(specifier);
115 if (idx == std::string::npos)
116 continue;
117
118 range_from = llvm::StringRef(option_lower).take_front(idx).trim();
119 range_to = llvm::StringRef(option_lower)
120 .drop_front(idx + specifier.size())
121 .trim();
122
123 if (!range_from.empty() && !range_to.empty()) {
124 is_range = true;
125 break;
126 }
127 }
128
129 if (is_range) {
130 // Parse both start and end IDs.
131 if (range_from.getAsInteger(0, m_provider_start_id)) {
133 "invalid start provider ID for option '%c': %s", short_option,
134 range_from.data());
135 break;
136 }
137 if (range_to.getAsInteger(0, m_provider_end_id)) {
139 "invalid end provider ID for option '%c': %s", short_option,
140 range_to.data());
141 break;
142 }
143
144 // Validate range.
147 "invalid provider range for option '%c': start ID %u > end "
148 "ID %u",
150 break;
151 }
152 } else {
153 // Single provider ID.
154 if (option_arg.getAsInteger(0, m_provider_start_id)) {
156 "invalid provider ID for option '%c': %s", short_option,
157 option_arg.data());
158 break;
159 }
161 }
162
164 } break;
165 default:
166 llvm_unreachable("Unimplemented option");
167 }
168 return error;
169 }
170
171 void OptionParsingStarting(ExecutionContext *execution_context) override {
173 m_start = 0;
174 m_extended_backtrace = false;
179 m_show_all_providers = false;
180 }
181
182 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
183 return g_thread_backtrace_options;
184 }
185
186 // Instance variables to hold the values for command options.
187 uint32_t m_count;
188 uint32_t m_start;
195 };
196
199 interpreter, "thread backtrace",
200 "Show backtraces of thread call stacks. Defaults to the current "
201 "thread, thread indexes can be specified as arguments.\n"
202 "Use the thread-index \"all\" to see all threads.\n"
203 "Use the thread-index \"unique\" to see threads grouped by unique "
204 "call stacks.\n"
205 "Use '--provider <id>' or '--provider <start>-<end>' to view "
206 "synthetic frame providers (0=base unwinder, 1+=synthetic). "
207 "Range specifiers '-', 'to', 'To', 'TO' are supported.\n"
208 "Use 'settings set frame-format' to customize the printing of "
209 "frames in the backtrace and 'settings set thread-format' to "
210 "customize the thread header.\n"
211 "Customizable frame recognizers may filter out less interesting "
212 "frames, which results in gaps in the numbering. "
213 "Use '-u' to see all frames.",
214 nullptr,
215 eCommandRequiresProcess | eCommandRequiresThread |
216 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
217 eCommandProcessMustBePaused) {}
218
219 ~CommandObjectThreadBacktrace() override = default;
220
221 Options *GetOptions() override { return &m_options; }
222
223 std::optional<std::string> GetRepeatCommand(Args &current_args,
224 uint32_t index) override {
225 llvm::StringRef count_opt("--count");
226 llvm::StringRef start_opt("--start");
227
228 // If no "count" was provided, we are dumping the entire backtrace, so
229 // there isn't a repeat command. So we search for the count option in
230 // the args, and if we find it, we make a copy and insert or modify the
231 // start option's value to start count indices greater.
232
233 Args copy_args(current_args);
234 size_t num_entries = copy_args.GetArgumentCount();
235 // These two point at the index of the option value if found.
236 size_t count_idx = 0;
237 size_t start_idx = 0;
238 size_t count_val = 0;
239 size_t start_val = 0;
240
241 for (size_t idx = 0; idx < num_entries; idx++) {
242 llvm::StringRef arg_string = copy_args[idx].ref();
243 if (arg_string == "-c" || count_opt.starts_with(arg_string)) {
244 idx++;
245 if (idx == num_entries)
246 return std::nullopt;
247 count_idx = idx;
248 if (copy_args[idx].ref().getAsInteger(0, count_val))
249 return std::nullopt;
250 } else if (arg_string == "-s" || start_opt.starts_with(arg_string)) {
251 idx++;
252 if (idx == num_entries)
253 return std::nullopt;
254 start_idx = idx;
255 if (copy_args[idx].ref().getAsInteger(0, start_val))
256 return std::nullopt;
257 }
258 }
259 if (count_idx == 0)
260 return std::nullopt;
261
262 std::string new_start_val = llvm::formatv("{0}", start_val + count_val);
263 if (start_idx == 0) {
264 copy_args.AppendArgument(start_opt);
265 copy_args.AppendArgument(new_start_val);
266 } else {
267 copy_args.ReplaceArgumentAtIndex(start_idx, new_start_val);
268 }
269 std::string repeat_command;
270 if (!copy_args.GetQuotedCommandString(repeat_command))
271 return std::nullopt;
272 return repeat_command;
273 }
274
275protected:
277 SystemRuntime *runtime = thread->GetProcess()->GetSystemRuntime();
278 if (runtime) {
279 Stream &strm = result.GetOutputStream();
280 const std::vector<ConstString> &types =
281 runtime->GetExtendedBacktraceTypes();
282 for (auto type : types) {
283 ThreadSP ext_thread_sp = runtime->GetExtendedBacktraceThread(
284 thread->shared_from_this(), type);
285 if (ext_thread_sp && ext_thread_sp->IsValid()) {
286 const uint32_t num_frames_with_source = 0;
287 const bool stop_format = false;
288 strm.PutChar('\n');
289 if (ext_thread_sp->GetStatus(strm, m_options.m_start,
290 m_options.m_count,
291 num_frames_with_source, stop_format,
292 !m_options.m_filtered_backtrace)) {
293 DoExtendedBacktrace(ext_thread_sp.get(), result);
294 }
295 }
296 }
297 }
298 }
299
300 bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
301 ThreadSP thread_sp =
302 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
303 if (!thread_sp) {
305 "thread disappeared while computing backtraces: 0x%" PRIx64, tid);
306 return false;
307 }
308
309 Thread *thread = thread_sp.get();
310 Stream &strm = result.GetOutputStream();
311
312 // Check if provider filtering is requested.
313 if (m_options.m_provider_specific_backtrace) {
314 // Disallow 'bt --provider' from within a scripted frame provider.
315 // A provider's get_frame_at_index running 'bt --provider' would
316 // try to evaluate the very provider that is mid-construction,
317 // leading to infinite recursion.
318 if (thread->IsAnyProviderActive()) {
320 "cannot use '--provider' option while a scripted frame provider is "
321 "being constructed on this thread");
322 return false;
323 }
324
325 // Print thread status header, like regular bt. This also ensures the
326 // frame list is initialized and any providers are loaded.
327 thread->GetStatus(strm, /*start_frame=*/0, /*num_frames=*/0,
328 /*num_frames_with_source=*/0, /*stop_format=*/true,
329 /*show_hidden=*/false, /*only_stacks=*/false);
330
331 if (m_options.m_show_all_providers) {
332 // Show all providers: unwinder (0) through the last in the chain.
333 m_options.m_provider_start_id = 0;
334 const auto &chain = thread->GetProviderChainIds();
335 m_options.m_provider_end_id = chain.empty() ? 0 : chain.back().second;
336 }
337
338 // Provider filter mode: show sequential views for each provider in range.
339 bool first_provider = true;
340 for (lldb::frame_list_id_t provider_id = m_options.m_provider_start_id;
341 provider_id <= m_options.m_provider_end_id; ++provider_id) {
342
343 // Get the frame list for this provider.
344 lldb::StackFrameListSP frame_list_sp =
345 thread->GetFrameListByIdentifier(provider_id);
346
347 if (!frame_list_sp) {
348 // Provider doesn't exist - skip silently.
349 continue;
350 }
351
352 // Add blank line between providers for readability.
353 if (!first_provider)
354 strm.PutChar('\n');
355 first_provider = false;
356
357 // Print provider header.
358 strm.Printf("=== Provider %u", provider_id);
359
360 // Get provider metadata for header.
361 if (provider_id == 0) {
362 strm.PutCString(": Base Unwinder ===\n");
363 } else {
364 // Find the descriptor in the provider chain.
365 const auto &provider_chain = thread->GetProviderChainIds();
366 std::string provider_name = "Unknown";
367 std::string provider_desc;
368 std::optional<uint32_t> provider_priority;
369
370 for (const auto &[descriptor, id] : provider_chain) {
371 if (id == provider_id) {
372 provider_name = descriptor.GetName().str();
373 provider_desc = descriptor.GetDescription();
374 provider_priority = descriptor.GetPriority();
375 break;
376 }
377 }
378
379 strm.Printf(": %s", provider_name.c_str());
380 if (provider_priority.has_value()) {
381 strm.Printf(" (priority: %u)", *provider_priority);
382 }
383 strm.PutCString(" ===\n");
384
385 if (!provider_desc.empty()) {
386 strm.Printf("Description: %s\n", provider_desc.c_str());
387 }
388 }
389
390 // Print the backtrace for this provider.
391 const uint32_t num_frames_with_source = 0;
392 const StackFrameSP selected_frame_sp =
393 thread->GetSelectedFrame(DoNoSelectMostRelevantFrame);
394 const char *selected_frame_marker = selected_frame_sp ? "->" : nullptr;
395
396 size_t num_frames = frame_list_sp->GetStatus(
397 strm, m_options.m_start, m_options.m_count,
398 /*show_frame_info=*/true, num_frames_with_source,
399 /*show_unique=*/false,
400 /*show_hidden=*/!m_options.m_filtered_backtrace,
401 selected_frame_marker);
402
403 if (num_frames == 0) {
404 strm.PutCString("(No frames available)\n");
405 }
406 }
407
408 if (first_provider) {
409 result.AppendErrorWithFormat("no provider found in range %u-%u",
410 m_options.m_provider_start_id,
411 m_options.m_provider_end_id);
412 return false;
413 }
414 return true;
415 }
416
417 // Original behavior: show default backtrace.
418 const bool only_stacks = m_unique_stacks;
419 const uint32_t num_frames_with_source = 0;
420 const bool stop_format = true;
421 if (!thread->GetStatus(strm, m_options.m_start, m_options.m_count,
422 num_frames_with_source, stop_format,
423 !m_options.m_filtered_backtrace, only_stacks)) {
425 "error displaying backtrace for thread: \"0x%4.4x\"",
426 thread->GetIndexID());
427 return false;
428 }
429 if (m_options.m_extended_backtrace) {
431 "Interrupt skipped extended backtrace")) {
432 DoExtendedBacktrace(thread, result);
433 }
434 }
435
436 return true;
437 }
438
440};
441
442#define LLDB_OPTIONS_thread_step_scope
443#include "CommandOptions.inc"
444
446public:
448 // Keep default values of all options in one place: OptionParsingStarting
449 // ()
450 OptionParsingStarting(nullptr);
451 }
452
453 ~ThreadStepScopeOptionGroup() override = default;
454
455 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
456 return llvm::ArrayRef(g_thread_step_scope_options);
457 }
458
459 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
460 ExecutionContext *execution_context) override {
462 const int short_option =
463 g_thread_step_scope_options[option_idx].short_option;
464
465 switch (short_option) {
466 case 'a': {
467 bool success;
468 bool avoid_no_debug =
469 OptionArgParser::ToBoolean(option_arg, true, &success);
470 if (!success)
472 "invalid boolean value for option '%c': %s", short_option,
473 option_arg.data());
474 else {
476 }
477 } break;
478
479 case 'A': {
480 bool success;
481 bool avoid_no_debug =
482 OptionArgParser::ToBoolean(option_arg, true, &success);
483 if (!success)
485 "invalid boolean value for option '%c': %s", short_option,
486 option_arg.data());
487 else {
489 }
490 } break;
491
492 case 'c':
493 if (option_arg.getAsInteger(0, m_step_count))
495 "invalid integer value for option '%c': %s", short_option,
496 option_arg.data());
497 break;
498
499 case 'm': {
500 auto enum_values = GetDefinitions()[option_idx].enum_values;
502 option_arg, enum_values, eOnlyDuringStepping, error);
503 } break;
504
505 case 'e':
506 if (option_arg == "block") {
508 break;
509 }
510 if (option_arg.getAsInteger(0, m_end_line))
512 "invalid end line number '%s'", option_arg.str().c_str());
513 break;
514
515 case 'r':
516 m_avoid_regexp.clear();
517 m_avoid_regexp.assign(std::string(option_arg));
518 break;
519
520 case 't':
521 m_step_in_target.clear();
522 m_step_in_target.assign(std::string(option_arg));
523 break;
524
525 default:
526 llvm_unreachable("Unimplemented option");
527 }
528 return error;
529 }
530
531 void OptionParsingStarting(ExecutionContext *execution_context) override {
535
536 // Check if we are in Non-Stop mode
537 TargetSP target_sp =
538 execution_context ? execution_context->GetTargetSP() : TargetSP();
539 ProcessSP process_sp =
540 execution_context ? execution_context->GetProcessSP() : ProcessSP();
541 if (process_sp && process_sp->GetSteppingRunsAllThreads())
543
544 m_avoid_regexp.clear();
545 m_step_in_target.clear();
546 m_step_count = 1;
549 }
550
551 // Instance variables to hold the values for command options.
555 std::string m_avoid_regexp;
556 std::string m_step_in_target;
557 uint32_t m_step_count;
558 uint32_t m_end_line;
560};
561
563public:
565 const char *name, const char *help,
566 const char *syntax,
567 StepType step_type)
568 : CommandObjectParsed(interpreter, name, help, syntax,
569 eCommandRequiresProcess | eCommandRequiresThread |
570 eCommandTryTargetAPILock |
571 eCommandProcessMustBeLaunched |
572 eCommandProcessMustBePaused),
573 m_step_type(step_type), m_class_options("scripted step") {
575
576 if (step_type == eStepTypeScripted) {
579 }
580 m_all_options.Append(&m_options);
581 m_all_options.Finalize();
582 }
583
585
586 void
588 OptionElementVector &opt_element_vector) override {
589 if (request.GetCursorIndex())
590 return;
591 CommandObject::HandleArgumentCompletion(request, opt_element_vector);
592 }
593
594 Options *GetOptions() override { return &m_all_options; }
595
596protected:
597 void DoExecute(Args &command, CommandReturnObject &result) override {
598 Process *process = m_exe_ctx.GetProcessPtr();
599 bool synchronous_execution = m_interpreter.GetSynchronous();
600
601 const uint32_t num_threads = process->GetThreadList().GetSize();
602 Thread *thread = nullptr;
603
604 if (command.GetArgumentCount() == 0) {
605 thread = GetDefaultThread();
606
607 if (thread == nullptr) {
608 result.AppendError("no selected thread in process");
609 return;
610 }
611 } else {
612 const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
613 uint32_t step_thread_idx;
614
615 if (!llvm::to_integer(thread_idx_cstr, step_thread_idx)) {
616 result.AppendErrorWithFormat("invalid thread index '%s'",
617 thread_idx_cstr);
618 return;
619 }
620 thread =
621 process->GetThreadList().FindThreadByIndexID(step_thread_idx).get();
622 if (thread == nullptr) {
624 "Thread index %u is out of range (valid values are 0 - %u)",
625 step_thread_idx, num_threads);
626 return;
627 }
628 }
629
631 if (m_class_options.GetName().empty()) {
632 result.AppendErrorWithFormat("empty class name for scripted step");
633 return;
634 } else if (!GetDebugger().GetScriptInterpreter()->CheckObjectExists(
635 m_class_options.GetName().c_str())) {
637 "class for scripted step: \"%s\" does not exist",
638 m_class_options.GetName().c_str());
639 return;
640 }
641 }
642
643 if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER &&
646 "end line option is only valid for step into");
647 return;
648 }
649
650 const bool abort_other_plans = false;
651 const lldb::RunMode stop_other_threads = m_options.m_run_mode;
652
653 // This is a bit unfortunate, but not all the commands in this command
654 // object support only while stepping, so I use the bool for them.
655 bool bool_stop_other_threads;
656 if (m_options.m_run_mode == eAllThreads)
657 bool_stop_other_threads = false;
658 else if (m_options.m_run_mode == eOnlyDuringStepping)
659 bool_stop_other_threads = (m_step_type != eStepTypeOut);
660 else
661 bool_stop_other_threads = true;
662
663 ThreadPlanSP new_plan_sp;
664 Status new_plan_status;
665
666 StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
667 assert(frame != nullptr);
668
669 // First see if the frame has a custom step plan for us:
670 if (frame) {
671 llvm::Expected<lldb::ThreadPlanSP> frame_plan_result =
673 if (auto llvm_err = frame_plan_result.takeError()) {
675 "scripted frame provider got an error "
676 "while constructing step plan: \"%s\"",
677 llvm::toString(std::move(llvm_err)).c_str());
678 return;
679 }
680 new_plan_sp = *frame_plan_result;
681 }
682
683 if (new_plan_sp) {
684 thread->QueueThreadPlan(new_plan_sp, abort_other_plans);
685 new_plan_sp->SetStopOthers(bool_stop_other_threads);
686 } else {
687 if (m_step_type == eStepTypeInto) {
688 if (frame->HasDebugInformation()) {
689 AddressRange range;
690 SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
691 if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER) {
692 llvm::Error err = sc.GetAddressRangeFromHereToEndLine(
693 m_options.m_end_line, range);
694 if (err) {
695 result.AppendErrorWithFormatv("invalid end-line option: {0}.",
696 llvm::toString(std::move(err)));
697 return;
698 }
699 } else if (m_options.m_end_line_is_block_end) {
701 Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
702 if (!block) {
703 result.AppendErrorWithFormat("Could not find the current block");
704 return;
705 }
706
707 AddressRange block_range;
708 Address pc_address = frame->GetFrameCodeAddress();
709 block->GetRangeContainingAddress(pc_address, block_range);
710 if (!block_range.GetBaseAddress().IsValid()) {
712 "Could not find the current block address");
713 return;
714 }
715 lldb::addr_t pc_offset_in_block =
716 pc_address.GetFileAddress() -
717 block_range.GetBaseAddress().GetFileAddress();
718 lldb::addr_t range_length =
719 block_range.GetByteSize() - pc_offset_in_block;
720 range = AddressRange(pc_address, range_length);
721 } else {
722 range = sc.line_entry.range;
723 }
724
725 new_plan_sp = thread->QueueThreadPlanForStepInRange(
726 abort_other_plans, range,
727 frame->GetSymbolContext(eSymbolContextEverything),
728 m_options.m_step_in_target, stop_other_threads, new_plan_status,
729 m_options.m_step_in_avoid_no_debug,
730 m_options.m_step_out_avoid_no_debug);
731
732 if (new_plan_sp && !m_options.m_avoid_regexp.empty()) {
733 ThreadPlanStepInRange *step_in_range_plan =
734 static_cast<ThreadPlanStepInRange *>(new_plan_sp.get());
735 step_in_range_plan->SetAvoidRegexp(
736 m_options.m_avoid_regexp.c_str());
737 }
738 } else
739 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
740 false, abort_other_plans, bool_stop_other_threads,
741 new_plan_status);
742 } else if (m_step_type == eStepTypeOver) {
743
744 if (frame->HasDebugInformation())
745 new_plan_sp = thread->QueueThreadPlanForStepOverRange(
746 abort_other_plans,
747 frame->GetSymbolContext(eSymbolContextEverything).line_entry,
748 frame->GetSymbolContext(eSymbolContextEverything),
749 stop_other_threads, new_plan_status,
750 m_options.m_step_out_avoid_no_debug);
751 else
752 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
753 true, abort_other_plans, bool_stop_other_threads,
754 new_plan_status);
755 } else if (m_step_type == eStepTypeTrace) {
756 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
757 false, abort_other_plans, bool_stop_other_threads, new_plan_status);
758 } else if (m_step_type == eStepTypeTraceOver) {
759 new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
760 true, abort_other_plans, bool_stop_other_threads, new_plan_status);
761 } else if (m_step_type == eStepTypeOut) {
762 new_plan_sp = thread->QueueThreadPlanForStepOut(
763 abort_other_plans, nullptr, false, bool_stop_other_threads,
765 thread->GetSelectedFrameIndex(DoNoSelectMostRelevantFrame),
766 new_plan_status, m_options.m_step_out_avoid_no_debug);
767 } else if (m_step_type == eStepTypeScripted) {
768 ScriptedMetadata scripted_metadata(m_class_options.GetName(),
769 m_class_options.GetStructuredData());
770 new_plan_sp = thread->QueueThreadPlanForStepScripted(
771 abort_other_plans, scripted_metadata, bool_stop_other_threads,
772 new_plan_status);
773 } else {
774 result.AppendError("step type is not supported");
775 return;
776 }
777 }
778
779 // If we got a new plan, then set it to be a controlling plan (User level
780 // Plans should be controlling plans so that they can be interruptible).
781 // Then resume the process.
782
783 if (new_plan_sp) {
784 new_plan_sp->SetIsControllingPlan(true);
785 new_plan_sp->SetOkayToDiscard(false);
786
787 if (m_options.m_step_count > 1) {
788 if (!new_plan_sp->SetIterationCount(m_options.m_step_count)) {
789 result.AppendWarning(
790 "step operation does not support iteration count");
791 }
792 }
793
794 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
795
796 const uint32_t iohandler_id = process->GetIOHandlerID();
797
798 StreamString stream;
800 if (synchronous_execution)
801 error = process->ResumeSynchronous(&stream);
802 else
803 error = process->Resume();
804
805 if (!error.Success()) {
806 result.AppendMessage(error.AsCString());
808 return;
809 }
810
811 // There is a race condition where this thread will return up the call
812 // stack to the main command handler and show an (lldb) prompt before
813 // HandlePrivateEvent (from PrivateStateThread) has a chance to call
814 // PushProcessIOHandler().
815 process->SyncIOHandler(iohandler_id, std::chrono::seconds(2));
816
817 if (synchronous_execution) {
818 // If any state changed events had anything to say, add that to the
819 // result
820 if (stream.GetSize() > 0)
821 result.AppendMessage(stream.GetString());
822
823 process->GetThreadList().SetSelectedThreadByID(thread->GetID());
824 result.SetDidChangeProcessState(true);
826 } else {
828 }
829 } else {
830 result.SetError(std::move(new_plan_status));
831 }
832 }
833
838};
839
840// CommandObjectThreadContinue
841
843public:
846 interpreter, "thread continue",
847 "Continue execution of the current target process. One "
848 "or more threads may be specified, by default all "
849 "threads continue.",
850 nullptr,
851 eCommandRequiresThread | eCommandTryTargetAPILock |
852 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
854 }
855
856 ~CommandObjectThreadContinue() override = default;
857
858 void DoExecute(Args &command, CommandReturnObject &result) override {
859 bool synchronous_execution = m_interpreter.GetSynchronous();
860
861 Process *process = m_exe_ctx.GetProcessPtr();
862 if (process == nullptr) {
863 result.AppendError("no process exists. Cannot continue");
864 return;
865 }
866
867 StateType state = process->GetState();
868 if ((state == eStateCrashed) || (state == eStateStopped) ||
869 (state == eStateSuspended)) {
870 const size_t argc = command.GetArgumentCount();
871 if (argc > 0) {
872 // These two lines appear at the beginning of both blocks in this
873 // if..else, but that is because we need to release the lock before
874 // calling process->Resume below.
875 std::lock_guard<std::recursive_mutex> guard(
876 process->GetThreadList().GetMutex());
877 const uint32_t num_threads = process->GetThreadList().GetSize();
878 std::vector<Thread *> resume_threads;
879 for (auto &entry : command.entries()) {
880 uint32_t thread_idx;
881 if (entry.ref().getAsInteger(0, thread_idx)) {
883 "invalid thread index argument: \"%s\"", entry.c_str());
884 return;
885 }
886 Thread *thread =
887 process->GetThreadList().FindThreadByIndexID(thread_idx).get();
888
889 if (thread) {
890 resume_threads.push_back(thread);
891 } else {
892 result.AppendErrorWithFormat("invalid thread index %u", thread_idx);
893 return;
894 }
895 }
896
897 if (resume_threads.empty()) {
898 result.AppendError("no valid thread indexes were specified");
899 return;
900 } else {
901 Stream &strm = result.GetOutputStream();
902 if (resume_threads.size() == 1)
903 strm << "Resuming thread: ";
904 else
905 strm << "Resuming threads: ";
906
907 for (uint32_t idx = 0; idx < num_threads; ++idx) {
908 Thread *thread =
909 process->GetThreadList().GetThreadAtIndex(idx).get();
910 std::vector<Thread *>::iterator this_thread_pos =
911 find(resume_threads.begin(), resume_threads.end(), thread);
912
913 if (this_thread_pos != resume_threads.end()) {
914 resume_threads.erase(this_thread_pos);
915 if (!resume_threads.empty())
916 strm << llvm::formatv("{0}, ", thread->GetIndexID());
917 else
918 strm << llvm::formatv("{0} ", thread->GetIndexID());
919
920 const bool override_suspend = true;
921 thread->SetResumeState(eStateRunning, override_suspend);
922 } else {
923 thread->SetResumeState(eStateSuspended);
924 }
925 }
926 result.AppendMessageWithFormatv("in process {0}", process->GetID());
927 }
928 } else {
929 // These two lines appear at the beginning of both blocks in this
930 // if..else, but that is because we need to release the lock before
931 // calling process->Resume below.
932 std::lock_guard<std::recursive_mutex> guard(
933 process->GetThreadList().GetMutex());
934 const uint32_t num_threads = process->GetThreadList().GetSize();
935 Thread *current_thread = GetDefaultThread();
936 if (current_thread == nullptr) {
937 result.AppendError("the process doesn't have a current thread");
938 return;
939 }
940 // Set the actions that the threads should each take when resuming
941 for (uint32_t idx = 0; idx < num_threads; ++idx) {
942 Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
943 if (thread == current_thread) {
945 "Resuming thread {0:x4} in process {1}", thread->GetID(),
946 process->GetID());
947 const bool override_suspend = true;
948 thread->SetResumeState(eStateRunning, override_suspend);
949 } else {
950 thread->SetResumeState(eStateSuspended);
951 }
952 }
953 }
954
955 StreamString stream;
957 if (synchronous_execution)
958 error = process->ResumeSynchronous(&stream);
959 else
960 error = process->Resume();
961
962 // We should not be holding the thread list lock when we do this.
963 if (error.Success()) {
964 result.AppendMessageWithFormatv("Process {0} resuming",
965 process->GetID());
966 if (synchronous_execution) {
967 // If any state changed events had anything to say, add that to the
968 // result
969 if (stream.GetSize() > 0)
970 result.AppendMessage(stream.GetString());
971
972 result.SetDidChangeProcessState(true);
974 } else {
976 }
977 } else {
978 result.AppendErrorWithFormat("Failed to resume process: %s",
979 error.AsCString());
980 }
981 } else {
983 "Process cannot be continued from its current state (%s)",
984 StateAsCString(state));
985 }
986 }
987};
988
989// CommandObjectThreadUntil
990
991#define LLDB_OPTIONS_thread_until
992#include "CommandOptions.inc"
993
995public:
996 class CommandOptions : public Options {
997 public:
1000
1002 // Keep default values of all options in one place: OptionParsingStarting
1003 // ()
1004 OptionParsingStarting(nullptr);
1005 }
1006
1007 ~CommandOptions() override = default;
1008
1009 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1010 ExecutionContext *execution_context) override {
1011 Status error;
1012 const int short_option = m_getopt_table[option_idx].val;
1013
1014 switch (short_option) {
1015 case 'a': {
1017 execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
1018 if (error.Success())
1019 m_until_addrs.push_back(tmp_addr);
1020 } break;
1021 case 't':
1022 if (option_arg.getAsInteger(0, m_thread_idx)) {
1024 error = Status::FromErrorStringWithFormat("invalid thread index '%s'",
1025 option_arg.str().c_str());
1026 }
1027 break;
1028 case 'f':
1029 if (option_arg.getAsInteger(0, m_frame_idx)) {
1031 error = Status::FromErrorStringWithFormat("invalid frame index '%s'",
1032 option_arg.str().c_str());
1033 }
1034 break;
1035 case 'm': {
1036 auto enum_values = GetDefinitions()[option_idx].enum_values;
1038 option_arg, enum_values, eOnlyDuringStepping, error);
1039
1040 if (error.Success()) {
1041 if (run_mode == eAllThreads)
1042 m_stop_others = false;
1043 else
1044 m_stop_others = true;
1045 }
1046 } break;
1047 default:
1048 llvm_unreachable("Unimplemented option");
1049 }
1050 return error;
1051 }
1052
1053 void OptionParsingStarting(ExecutionContext *execution_context) override {
1055 m_frame_idx = 0;
1056 m_stop_others = false;
1057 m_until_addrs.clear();
1058 }
1059
1060 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1061 return llvm::ArrayRef(g_thread_until_options);
1062 }
1063
1064 bool m_stop_others = false;
1065 std::vector<lldb::addr_t> m_until_addrs;
1066
1067 // Instance variables to hold the values for command options.
1068 };
1069
1072 interpreter, "thread until",
1073 "Continue until a line number or address is reached by the "
1074 "current or specified thread. Stops when returning from "
1075 "the current function as a safety measure. "
1076 "The target line number(s) are given as arguments, and if more "
1077 "than one"
1078 " is provided, stepping will stop when the first one is hit.",
1079 nullptr,
1080 eCommandRequiresThread | eCommandTryTargetAPILock |
1081 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
1083 }
1084
1085 ~CommandObjectThreadUntil() override = default;
1086
1087 Options *GetOptions() override { return &m_options; }
1088
1089protected:
1090 void DoExecute(Args &command, CommandReturnObject &result) override {
1091 bool synchronous_execution = m_interpreter.GetSynchronous();
1092
1093 Process *process = m_exe_ctx.GetProcessPtr();
1094 if (process == nullptr) {
1095 result.AppendError("need a valid process to step");
1096 } else {
1097 Thread *thread = nullptr;
1098 std::vector<uint32_t> line_numbers;
1099
1100 if (command.GetArgumentCount() >= 1) {
1101 size_t num_args = command.GetArgumentCount();
1102 for (size_t i = 0; i < num_args; i++) {
1103 uint32_t line_number;
1104 if (!llvm::to_integer(command.GetArgumentAtIndex(i), line_number)) {
1105 result.AppendErrorWithFormat("invalid line number: '%s'",
1106 command.GetArgumentAtIndex(i));
1107 return;
1108 } else
1109 line_numbers.push_back(line_number);
1110 }
1111 } else if (m_options.m_until_addrs.empty()) {
1112 result.AppendErrorWithFormat("No line number or address provided:\n%s",
1113 GetSyntax().str().c_str());
1114 return;
1115 }
1116
1117 if (m_options.m_thread_idx == LLDB_INVALID_THREAD_ID) {
1118 thread = GetDefaultThread();
1119 } else {
1120 thread = process->GetThreadList()
1121 .FindThreadByIndexID(m_options.m_thread_idx)
1122 .get();
1123 }
1124
1125 if (thread == nullptr) {
1126 const uint32_t num_threads = process->GetThreadList().GetSize();
1127 result.AppendErrorWithFormat(
1128 "Thread index %u is out of range (valid values are 0 - %u)",
1129 m_options.m_thread_idx, num_threads);
1130 return;
1131 }
1132
1133 const bool abort_other_plans = false;
1134
1135 StackFrame *frame =
1136 thread->GetStackFrameAtIndex(m_options.m_frame_idx).get();
1137 if (frame == nullptr) {
1138 result.AppendErrorWithFormat(
1139 "Frame index %u is out of range for thread id %" PRIu64,
1140 m_options.m_frame_idx, thread->GetID());
1141 return;
1142 }
1143
1144 ThreadPlanSP new_plan_sp;
1145 Status new_plan_status;
1146
1147 if (frame->HasDebugInformation()) {
1148 // Finally we got here... Translate the given line number to a bunch
1149 // of addresses:
1150 SymbolContext sc(frame->GetSymbolContext(eSymbolContextCompUnit));
1151 LineTable *line_table = nullptr;
1152 if (sc.comp_unit)
1153 line_table = sc.comp_unit->GetLineTable();
1154
1155 if (line_table == nullptr) {
1156 result.AppendErrorWithFormat("Failed to resolve the line table for "
1157 "frame %u of thread id %" PRIu64,
1158 m_options.m_frame_idx, thread->GetID());
1159 return;
1160 }
1161
1162 // Find the beginning & end index of the function, but first make
1163 // sure it is valid:
1164 if (!sc.function) {
1165 result.AppendErrorWithFormat("Have debug information but no "
1166 "function info - can't get until range");
1167 return;
1168 }
1169
1170 llvm::Expected<std::vector<addr_t>> address_list =
1172 line_numbers, m_options.m_until_addrs);
1173 if (!address_list) {
1174 result.AppendError(llvm::toString(address_list.takeError()));
1175 return;
1176 }
1177
1178 new_plan_sp = thread->QueueThreadPlanForStepUntil(
1179 abort_other_plans, *address_list, m_options.m_stop_others,
1180 m_options.m_frame_idx, new_plan_status);
1181 if (new_plan_sp) {
1182 // User level plans should be controlling plans so they can be
1183 // interrupted
1184 // (e.g. by hitting a breakpoint) and other plans executed by the
1185 // user (stepping around the breakpoint) and then a "continue" will
1186 // resume the original plan.
1187 new_plan_sp->SetIsControllingPlan(true);
1188 new_plan_sp->SetOkayToDiscard(false);
1189 } else {
1190 result.SetError(std::move(new_plan_status));
1191 return;
1192 }
1193 } else {
1194 result.AppendErrorWithFormat("Frame index %u of thread id %" PRIu64
1195 " has no debug information",
1196 m_options.m_frame_idx, thread->GetID());
1197 return;
1198 }
1199
1200 if (!process->GetThreadList().SetSelectedThreadByID(thread->GetID())) {
1201 result.AppendErrorWithFormat(
1202 "Failed to set the selected thread to thread id %" PRIu64,
1203 thread->GetID());
1204 return;
1205 }
1206
1207 StreamString stream;
1208 Status error;
1209 if (synchronous_execution)
1210 error = process->ResumeSynchronous(&stream);
1211 else
1212 error = process->Resume();
1213
1214 if (error.Success()) {
1215 result.AppendMessageWithFormatv("Process {0} resuming",
1216 process->GetID());
1217 if (synchronous_execution) {
1218 // If any state changed events had anything to say, add that to the
1219 // result
1220 if (stream.GetSize() > 0)
1221 result.AppendMessage(stream.GetString());
1222
1223 result.SetDidChangeProcessState(true);
1225 } else {
1227 }
1228 } else {
1229 result.AppendErrorWithFormat("Failed to resume process: %s",
1230 error.AsCString());
1231 }
1232 }
1233 }
1234
1236};
1237
1238// CommandObjectThreadSelect
1239
1240#define LLDB_OPTIONS_thread_select
1241#include "CommandOptions.inc"
1242
1244public:
1246 public:
1248
1249 ~OptionGroupThreadSelect() override = default;
1250
1251 void OptionParsingStarting(ExecutionContext *execution_context) override {
1253 }
1254
1255 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1256 ExecutionContext *execution_context) override {
1257 const int short_option = g_thread_select_options[option_idx].short_option;
1258 switch (short_option) {
1259 case 't': {
1260 if (option_arg.getAsInteger(0, m_thread_id)) {
1262 return Status::FromErrorStringWithFormat("Invalid thread ID: '%s'.",
1263 option_arg.str().c_str());
1264 }
1265 break;
1266 }
1267
1268 default:
1269 llvm_unreachable("Unimplemented option");
1270 }
1271
1272 return {};
1273 }
1274
1275 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1276 return llvm::ArrayRef(g_thread_select_options);
1277 }
1278
1280 };
1281
1283 : CommandObjectParsed(interpreter, "thread select",
1284 "Change the currently selected thread.",
1285 "thread select <thread-index> (or -t <thread-id>)",
1286 eCommandRequiresProcess | eCommandTryTargetAPILock |
1287 eCommandProcessMustBeLaunched |
1288 eCommandProcessMustBePaused) {
1290 CommandArgumentData thread_idx_arg;
1291
1292 // Define the first (and only) variant of this arg.
1293 thread_idx_arg.arg_type = eArgTypeThreadIndex;
1294 thread_idx_arg.arg_repetition = eArgRepeatPlain;
1295 thread_idx_arg.arg_opt_set_association = LLDB_OPT_SET_1;
1296
1297 // There is only one variant this argument could be; put it into the
1298 // argument entry.
1299 arg.push_back(thread_idx_arg);
1300
1301 // Push the data for the first argument into the m_arguments vector.
1302 m_arguments.push_back(arg);
1303
1305 m_option_group.Finalize();
1306 }
1307
1308 ~CommandObjectThreadSelect() override = default;
1309
1310 void
1312 OptionElementVector &opt_element_vector) override {
1313 if (request.GetCursorIndex())
1314 return;
1315
1318 nullptr);
1319 }
1320
1321 Options *GetOptions() override { return &m_option_group; }
1322
1323protected:
1324 void DoExecute(Args &command, CommandReturnObject &result) override {
1325 Process *process = m_exe_ctx.GetProcessPtr();
1326 if (process == nullptr) {
1327 result.AppendError("no process");
1328 return;
1329 } else if (m_options.m_thread_id == LLDB_INVALID_THREAD_ID &&
1330 command.GetArgumentCount() != 1) {
1331 result.AppendErrorWithFormat(
1332 "'%s' takes exactly one thread index argument, or a thread ID "
1333 "option:\nUsage: %s",
1334 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1335 return;
1336 } else if (m_options.m_thread_id != LLDB_INVALID_THREAD_ID &&
1337 command.GetArgumentCount() != 0) {
1338 result.AppendErrorWithFormat("'%s' cannot take both a thread ID option "
1339 "and a thread index argument:\nUsage: %s",
1340 m_cmd_name.c_str(), m_cmd_syntax.c_str());
1341 return;
1342 }
1343
1344 Thread *new_thread = nullptr;
1345 if (command.GetArgumentCount() == 1) {
1346 uint32_t index_id;
1347 if (!llvm::to_integer(command.GetArgumentAtIndex(0), index_id)) {
1348 result.AppendErrorWithFormat("Invalid thread index '%s'",
1349 command.GetArgumentAtIndex(0));
1350 return;
1351 }
1352 new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get();
1353 if (new_thread == nullptr) {
1354 result.AppendErrorWithFormat("Invalid thread index #%s",
1355 command.GetArgumentAtIndex(0));
1356 return;
1357 }
1358 } else {
1359 new_thread =
1360 process->GetThreadList().FindThreadByID(m_options.m_thread_id).get();
1361 if (new_thread == nullptr) {
1362 result.AppendErrorWithFormat("Invalid thread ID %" PRIu64,
1363 m_options.m_thread_id);
1364 return;
1365 }
1366 }
1367
1368 process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true);
1370 }
1371
1374};
1375
1376// CommandObjectThreadList
1377
1379public:
1382 interpreter, "thread list",
1383 "Show a summary of each thread in the current target process. "
1384 "Use 'settings set thread-format' to customize the individual "
1385 "thread listings.",
1386 "thread list",
1387 eCommandRequiresProcess | eCommandTryTargetAPILock |
1388 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1389
1390 ~CommandObjectThreadList() override = default;
1391
1392protected:
1393 void DoExecute(Args &command, CommandReturnObject &result) override {
1394 Stream &strm = result.GetOutputStream();
1396 Process *process = m_exe_ctx.GetProcessPtr();
1397 const bool only_threads_with_stop_reason = false;
1398 const uint32_t start_frame = 0;
1399 const uint32_t num_frames = 0;
1400 const uint32_t num_frames_with_source = 0;
1401 process->GetStatus(strm);
1402 process->GetThreadStatus(strm, only_threads_with_stop_reason, start_frame,
1403 num_frames, num_frames_with_source, false);
1404 }
1405};
1406
1407// CommandObjectThreadInfo
1408#define LLDB_OPTIONS_thread_info
1409#include "CommandOptions.inc"
1410
1412public:
1413 class CommandOptions : public Options {
1414 public:
1416
1417 ~CommandOptions() override = default;
1418
1419 void OptionParsingStarting(ExecutionContext *execution_context) override {
1420 m_json_thread = false;
1421 m_json_stopinfo = false;
1422 m_backing_thread = false;
1423 }
1424
1425 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1426 ExecutionContext *execution_context) override {
1427 const int short_option = m_getopt_table[option_idx].val;
1428 Status error;
1429
1430 switch (short_option) {
1431 case 'j':
1432 m_json_thread = true;
1433 break;
1434
1435 case 's':
1436 m_json_stopinfo = true;
1437 break;
1438
1439 case 'b':
1440 m_backing_thread = true;
1441 break;
1442
1443 default:
1444 llvm_unreachable("Unimplemented option");
1445 }
1446 return error;
1447 }
1448
1449 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1450 return llvm::ArrayRef(g_thread_info_options);
1451 }
1452
1456 };
1457
1460 interpreter, "thread info",
1461 "Show an extended summary of one or "
1462 "more threads. Defaults to the "
1463 "current thread.",
1464 "thread info",
1465 eCommandRequiresProcess | eCommandTryTargetAPILock |
1466 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
1467 m_add_return = false;
1468 }
1469
1470 ~CommandObjectThreadInfo() override = default;
1471
1472 void
1479
1480 Options *GetOptions() override { return &m_options; }
1481
1483 ThreadSP thread_sp =
1484 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1485 if (!thread_sp) {
1486 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64, tid);
1487 return false;
1488 }
1489
1490 Thread *thread = thread_sp.get();
1491 if (m_options.m_backing_thread && thread->GetBackingThread())
1492 thread = thread->GetBackingThread().get();
1493
1494 Stream &strm = result.GetOutputStream();
1495 if (!thread->GetDescription(strm, eDescriptionLevelFull,
1496 m_options.m_json_thread,
1497 m_options.m_json_stopinfo)) {
1498 result.AppendErrorWithFormat("error displaying info for thread: \"%d\"",
1499 thread->GetIndexID());
1500 return false;
1501 }
1502 return true;
1503 }
1504
1506};
1507
1508// CommandObjectThreadException
1509
1511public:
1514 interpreter, "thread exception",
1515 "Display the current exception object for a thread. Defaults to "
1516 "the current thread.",
1517 "thread exception",
1518 eCommandRequiresProcess | eCommandTryTargetAPILock |
1519 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1520
1521 ~CommandObjectThreadException() override = default;
1522
1523 void
1530
1532 ThreadSP thread_sp =
1533 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1534 if (!thread_sp) {
1535 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64, tid);
1536 return false;
1537 }
1538
1539 Stream &strm = result.GetOutputStream();
1540 ValueObjectSP exception_object_sp = thread_sp->GetCurrentException();
1541 if (exception_object_sp) {
1542 if (llvm::Error error = exception_object_sp->Dump(strm)) {
1543 result.AppendError(toString(std::move(error)));
1544 return false;
1545 }
1546 }
1547
1548 ThreadSP exception_thread_sp = thread_sp->GetCurrentExceptionBacktrace();
1549 if (exception_thread_sp && exception_thread_sp->IsValid()) {
1550 const uint32_t num_frames_with_source = 0;
1551 const bool stop_format = false;
1552 exception_thread_sp->GetStatus(strm, 0, UINT32_MAX,
1553 num_frames_with_source, stop_format,
1554 /*filtered*/ false);
1555 }
1556
1557 return true;
1558 }
1559};
1560
1562public:
1565 interpreter, "thread siginfo",
1566 "Display the current siginfo object for a thread. Defaults to "
1567 "the current thread.",
1568 "thread siginfo",
1569 eCommandRequiresProcess | eCommandTryTargetAPILock |
1570 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1571
1572 ~CommandObjectThreadSiginfo() override = default;
1573
1574 void
1581
1583 ThreadSP thread_sp =
1584 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1585 if (!thread_sp) {
1586 result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64, tid);
1587 return false;
1588 }
1589
1590 Stream &strm = result.GetOutputStream();
1591 if (!thread_sp->GetDescription(strm, eDescriptionLevelFull, false, false)) {
1592 result.AppendErrorWithFormat("error displaying info for thread: \"%d\"",
1593 thread_sp->GetIndexID());
1594 return false;
1595 }
1596 ValueObjectSP exception_object_sp = thread_sp->GetSiginfoValue();
1597 if (exception_object_sp) {
1598 if (llvm::Error error = exception_object_sp->Dump(strm)) {
1599 result.AppendError(toString(std::move(error)));
1600 return false;
1601 }
1602 } else
1603 strm.PutCString("(no siginfo)\n");
1604 strm.PutChar('\n');
1605
1606 return true;
1607 }
1608};
1609
1610// CommandObjectThreadReturn
1611#define LLDB_OPTIONS_thread_return
1612#include "CommandOptions.inc"
1613
1615public:
1616 class CommandOptions : public Options {
1617 public:
1619 // Keep default values of all options in one place: OptionParsingStarting
1620 // ()
1621 OptionParsingStarting(nullptr);
1622 }
1623
1624 ~CommandOptions() override = default;
1625
1626 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1627 ExecutionContext *execution_context) override {
1628 Status error;
1629 const int short_option = m_getopt_table[option_idx].val;
1630
1631 switch (short_option) {
1632 case 'x': {
1633 bool success;
1634 bool tmp_value =
1635 OptionArgParser::ToBoolean(option_arg, false, &success);
1636 if (success)
1637 m_from_expression = tmp_value;
1638 else {
1640 "invalid boolean value '%s' for 'x' option",
1641 option_arg.str().c_str());
1642 }
1643 } break;
1644 default:
1645 llvm_unreachable("Unimplemented option");
1646 }
1647 return error;
1648 }
1649
1650 void OptionParsingStarting(ExecutionContext *execution_context) override {
1651 m_from_expression = false;
1652 }
1653
1654 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1655 return llvm::ArrayRef(g_thread_return_options);
1656 }
1657
1658 bool m_from_expression = false;
1659
1660 // Instance variables to hold the values for command options.
1661 };
1662
1664 : CommandObjectRaw(interpreter, "thread return",
1665 "Prematurely return from a stack frame, "
1666 "short-circuiting execution of newer frames "
1667 "and optionally yielding a specified value. Defaults "
1668 "to the exiting the current stack "
1669 "frame.",
1670 "thread return",
1671 eCommandRequiresFrame | eCommandTryTargetAPILock |
1672 eCommandProcessMustBeLaunched |
1673 eCommandProcessMustBePaused) {
1675 }
1676
1677 ~CommandObjectThreadReturn() override = default;
1678
1679 Options *GetOptions() override { return &m_options; }
1680
1681protected:
1682 void DoExecute(llvm::StringRef command,
1683 CommandReturnObject &result) override {
1684 // I am going to handle this by hand, because I don't want you to have to
1685 // say:
1686 // "thread return -- -5".
1687 if (command.starts_with("-x")) {
1688 if (command.size() != 2U)
1689 result.AppendWarning("return values ignored when returning from user "
1690 "called expressions");
1691
1692 Thread *thread = m_exe_ctx.GetThreadPtr();
1693 Status error;
1694 error = thread->UnwindInnermostExpression();
1695 if (!error.Success()) {
1696 result.AppendErrorWithFormat("Unwinding expression failed - %s",
1697 error.AsCString());
1698 } else {
1699 bool success =
1700 thread->SetSelectedFrameByIndexNoisily(0, result.GetOutputStream());
1701 if (success) {
1702 m_exe_ctx.SetFrameSP(
1703 thread->GetSelectedFrame(DoNoSelectMostRelevantFrame));
1705 } else {
1706 result.AppendErrorWithFormat(
1707 "Could not select 0th frame after unwinding expression");
1708 }
1709 }
1710 return;
1711 }
1712
1713 ValueObjectSP return_valobj_sp;
1714
1715 StackFrameSP frame_sp = m_exe_ctx.GetFrameSP();
1716 uint32_t frame_idx = frame_sp->GetFrameIndex();
1717
1718 if (frame_sp->IsInlined()) {
1719 result.AppendError("don't know how to return from inlined frames");
1720 return;
1721 }
1722
1723 if (!command.empty()) {
1724 Target *target = m_exe_ctx.GetTargetPtr();
1726
1727 options.SetUnwindOnError(true);
1729
1731 exe_results = target->EvaluateExpression(command, frame_sp.get(),
1732 return_valobj_sp, options);
1733 if (exe_results != eExpressionCompleted) {
1734 if (return_valobj_sp)
1735 result.AppendErrorWithFormat(
1736 "Error evaluating result expression: %s",
1737 return_valobj_sp->GetError().AsCString());
1738 else
1739 result.AppendErrorWithFormat(
1740 "Unknown error evaluating result expression");
1741 return;
1742 }
1743 }
1744
1745 Status error;
1746 ThreadSP thread_sp = m_exe_ctx.GetThreadSP();
1747 const bool broadcast = true;
1748 error = thread_sp->ReturnFromFrame(frame_sp, return_valobj_sp, broadcast);
1749 if (!error.Success()) {
1750 result.AppendErrorWithFormat(
1751 "Error returning from frame %d of thread %d: %s", frame_idx,
1752 thread_sp->GetIndexID(), error.AsCString());
1753 return;
1754 }
1755
1757 }
1758
1760};
1761
1762// CommandObjectThreadJump
1763#define LLDB_OPTIONS_thread_jump
1764#include "CommandOptions.inc"
1765
1767public:
1768 class CommandOptions : public Options {
1769 public:
1771
1772 ~CommandOptions() override = default;
1773
1774 void OptionParsingStarting(ExecutionContext *execution_context) override {
1775 m_filenames.Clear();
1776 m_line_num = 0;
1777 m_line_offset = 0;
1779 m_force = false;
1780 }
1781
1782 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1783 ExecutionContext *execution_context) override {
1784 const int short_option = m_getopt_table[option_idx].val;
1785 Status error;
1786
1787 switch (short_option) {
1788 case 'f':
1789 m_filenames.AppendIfUnique(FileSpec(option_arg));
1790 if (m_filenames.GetSize() > 1)
1791 return Status::FromErrorString("only one source file expected.");
1792 break;
1793 case 'l':
1794 if (option_arg.getAsInteger(0, m_line_num))
1795 return Status::FromErrorStringWithFormat("invalid line number: '%s'.",
1796 option_arg.str().c_str());
1797 break;
1798 case 'b': {
1799 option_arg.consume_front("+");
1800
1801 if (option_arg.getAsInteger(0, m_line_offset))
1802 return Status::FromErrorStringWithFormat("invalid line offset: '%s'.",
1803 option_arg.str().c_str());
1804 break;
1805 }
1806 case 'a':
1807 m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg,
1809 break;
1810 case 'r':
1811 m_force = true;
1812 break;
1813 default:
1814 llvm_unreachable("Unimplemented option");
1815 }
1816 return error;
1817 }
1818
1819 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1820 return llvm::ArrayRef(g_thread_jump_options);
1821 }
1822
1824 uint32_t m_line_num;
1828 };
1829
1832 interpreter, "thread jump",
1833 "Sets the program counter to a new address.", "thread jump",
1834 eCommandRequiresFrame | eCommandTryTargetAPILock |
1835 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1836
1837 ~CommandObjectThreadJump() override = default;
1838
1839 Options *GetOptions() override { return &m_options; }
1840
1841protected:
1842 void DoExecute(Args &args, CommandReturnObject &result) override {
1843 RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext();
1844 StackFrame *frame = m_exe_ctx.GetFramePtr();
1845 Thread *thread = m_exe_ctx.GetThreadPtr();
1846 Target *target = m_exe_ctx.GetTargetPtr();
1847 const SymbolContext &sym_ctx =
1848 frame->GetSymbolContext(eSymbolContextLineEntry);
1849
1850 if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) {
1851 // Use this address directly.
1852 Address dest = Address(m_options.m_load_addr);
1853
1854 lldb::addr_t callAddr = dest.GetCallableLoadAddress(target);
1855 if (callAddr == LLDB_INVALID_ADDRESS) {
1856 result.AppendErrorWithFormat("Invalid destination address");
1857 return;
1858 }
1859
1860 if (!reg_ctx->SetPC(callAddr)) {
1861 result.AppendErrorWithFormat("Error changing PC value for thread %d",
1862 thread->GetIndexID());
1863 return;
1864 }
1865 } else {
1866 // Pick either the absolute line, or work out a relative one.
1867 int32_t line = (int32_t)m_options.m_line_num;
1868 if (line == 0)
1869 line = sym_ctx.line_entry.line + m_options.m_line_offset;
1870
1871 // Try the current file, but override if asked.
1872 FileSpec file = sym_ctx.line_entry.GetFile();
1873 if (m_options.m_filenames.GetSize() == 1)
1874 file = m_options.m_filenames.GetFileSpecAtIndex(0);
1875
1876 if (!file) {
1877 result.AppendErrorWithFormat(
1878 "no source file available for the current location");
1879 return;
1880 }
1881
1882 std::string warnings;
1883 Status err = thread->JumpToLine(file, line, m_options.m_force, &warnings);
1884
1885 if (err.Fail()) {
1886 result.SetError(std::move(err));
1887 return;
1888 }
1889
1890 if (!warnings.empty())
1891 result.AppendWarning(warnings.c_str());
1892 }
1893
1895 }
1896
1898};
1899
1900// Next are the subcommands of CommandObjectMultiwordThreadPlan
1901
1902// CommandObjectThreadPlanList
1903#define LLDB_OPTIONS_thread_plan_list
1904#include "CommandOptions.inc"
1905
1907public:
1908 class CommandOptions : public Options {
1909 public:
1911 // Keep default values of all options in one place: OptionParsingStarting
1912 // ()
1913 OptionParsingStarting(nullptr);
1914 }
1915
1916 ~CommandOptions() override = default;
1917
1918 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1919 ExecutionContext *execution_context) override {
1920 const int short_option = m_getopt_table[option_idx].val;
1921
1922 switch (short_option) {
1923 case 'i':
1924 m_internal = true;
1925 break;
1926 case 't':
1927 lldb::tid_t tid;
1928 if (option_arg.getAsInteger(0, tid))
1929 return Status::FromErrorStringWithFormat("invalid tid: '%s'.",
1930 option_arg.str().c_str());
1931 m_tids.push_back(tid);
1932 break;
1933 case 'u':
1934 m_unreported = false;
1935 break;
1936 case 'v':
1937 m_verbose = true;
1938 break;
1939 default:
1940 llvm_unreachable("Unimplemented option");
1941 }
1942 return {};
1943 }
1944
1945 void OptionParsingStarting(ExecutionContext *execution_context) override {
1946 m_verbose = false;
1947 m_internal = false;
1948 m_unreported = true; // The variable is "skip unreported" and we want to
1949 // skip unreported by default.
1950 m_tids.clear();
1951 }
1952
1953 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1954 return llvm::ArrayRef(g_thread_plan_list_options);
1955 }
1956
1957 // Instance variables to hold the values for command options.
1961 std::vector<lldb::tid_t> m_tids;
1962 };
1963
1966 interpreter, "thread plan list",
1967 "Show thread plans for one or more threads. If no threads are "
1968 "specified, show the "
1969 "current thread. Use the thread-index \"all\" to see all threads.",
1970 nullptr,
1971 eCommandRequiresProcess | eCommandRequiresThread |
1972 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
1973 eCommandProcessMustBePaused) {}
1974
1975 ~CommandObjectThreadPlanList() override = default;
1976
1977 Options *GetOptions() override { return &m_options; }
1978
1979 void DoExecute(Args &command, CommandReturnObject &result) override {
1980 // If we are reporting all threads, dispatch to the Process to do that:
1981 if (command.GetArgumentCount() == 0 && m_options.m_tids.empty()) {
1982 Stream &strm = result.GetOutputStream();
1983 DescriptionLevel desc_level = m_options.m_verbose
1986 m_exe_ctx.GetProcessPtr()->DumpThreadPlans(
1987 strm, desc_level, m_options.m_internal, true, m_options.m_unreported);
1989 return;
1990 } else {
1991 // Do any TID's that the user may have specified as TID, then do any
1992 // Thread Indexes...
1993 if (!m_options.m_tids.empty()) {
1994 Process *process = m_exe_ctx.GetProcessPtr();
1995 StreamString tmp_strm;
1996 for (lldb::tid_t tid : m_options.m_tids) {
1997 bool success = process->DumpThreadPlansForTID(
1998 tmp_strm, tid, eDescriptionLevelFull, m_options.m_internal,
1999 true /* condense_trivial */, m_options.m_unreported);
2000 // If we didn't find a TID, stop here and return an error.
2001 if (!success) {
2002 result.AppendError("Error dumping plans:");
2003 result.AppendError(tmp_strm.GetString());
2004 return;
2005 }
2006 // Otherwise, add our data to the output:
2007 result.GetOutputStream() << tmp_strm.GetString();
2008 }
2009 }
2010 return CommandObjectIterateOverThreads::DoExecute(command, result);
2011 }
2012 }
2013
2014protected:
2016 // If we have already handled this from a -t option, skip it here.
2017 if (llvm::is_contained(m_options.m_tids, tid))
2018 return true;
2019
2020 Process *process = m_exe_ctx.GetProcessPtr();
2021
2022 Stream &strm = result.GetOutputStream();
2024 if (m_options.m_verbose)
2025 desc_level = eDescriptionLevelVerbose;
2026
2027 process->DumpThreadPlansForTID(strm, tid, desc_level, m_options.m_internal,
2028 true /* condense_trivial */,
2029 m_options.m_unreported);
2030 return true;
2031 }
2032
2034};
2035
2037public:
2039 : CommandObjectParsed(interpreter, "thread plan discard",
2040 "Discards thread plans up to and including the "
2041 "specified index (see 'thread plan list'.) "
2042 "Only user visible plans can be discarded.",
2043 nullptr,
2044 eCommandRequiresProcess | eCommandRequiresThread |
2045 eCommandTryTargetAPILock |
2046 eCommandProcessMustBeLaunched |
2047 eCommandProcessMustBePaused) {
2049 }
2050
2052
2053 void
2055 OptionElementVector &opt_element_vector) override {
2056 if (!m_exe_ctx.HasThreadScope() || request.GetCursorIndex())
2057 return;
2058
2059 m_exe_ctx.GetThreadPtr()->AutoCompleteThreadPlans(request);
2060 }
2061
2062 void DoExecute(Args &args, CommandReturnObject &result) override {
2063 Thread *thread = m_exe_ctx.GetThreadPtr();
2064 if (args.GetArgumentCount() != 1) {
2065 result.AppendErrorWithFormat("Too many arguments, expected one - the "
2066 "thread plan index - but got %zu",
2067 args.GetArgumentCount());
2068 return;
2069 }
2070
2071 uint32_t thread_plan_idx;
2072 if (!llvm::to_integer(args.GetArgumentAtIndex(0), thread_plan_idx)) {
2073 result.AppendErrorWithFormat(
2074 "Invalid thread index: \"%s\" - should be unsigned int",
2075 args.GetArgumentAtIndex(0));
2076 return;
2077 }
2078
2079 if (thread_plan_idx == 0) {
2080 result.AppendErrorWithFormat(
2081 "You wouldn't really want me to discard the base thread plan");
2082 return;
2083 }
2084
2085 if (thread->DiscardUserThreadPlansUpToIndex(thread_plan_idx)) {
2087 } else {
2088 result.AppendErrorWithFormat(
2089 "Could not find User thread plan with index %s",
2090 args.GetArgumentAtIndex(0));
2091 }
2092 }
2093};
2094
2096public:
2098 : CommandObjectParsed(interpreter, "thread plan prune",
2099 "Removes any thread plans associated with "
2100 "currently unreported threads. "
2101 "Specify one or more TID's to remove, or if no "
2102 "TID's are provides, remove threads for all "
2103 "unreported threads",
2104 nullptr,
2105 eCommandRequiresProcess |
2106 eCommandTryTargetAPILock |
2107 eCommandProcessMustBeLaunched |
2108 eCommandProcessMustBePaused) {
2110 }
2111
2112 ~CommandObjectThreadPlanPrune() override = default;
2113
2114 void DoExecute(Args &args, CommandReturnObject &result) override {
2115 Process *process = m_exe_ctx.GetProcessPtr();
2116
2117 if (args.GetArgumentCount() == 0) {
2118 process->PruneThreadPlans();
2120 return;
2121 }
2122
2123 const size_t num_args = args.GetArgumentCount();
2124
2125 std::lock_guard<std::recursive_mutex> guard(
2126 process->GetThreadList().GetMutex());
2127
2128 for (size_t i = 0; i < num_args; i++) {
2129 lldb::tid_t tid;
2130 if (!llvm::to_integer(args.GetArgumentAtIndex(i), tid)) {
2131 result.AppendErrorWithFormat("invalid thread specification: \"%s\"",
2132 args.GetArgumentAtIndex(i));
2133 return;
2134 }
2135 if (!process->PruneThreadPlansForTID(tid)) {
2136 result.AppendErrorWithFormat("Could not find unreported tid: \"%s\"",
2137 args.GetArgumentAtIndex(i));
2138 return;
2139 }
2140 }
2142 }
2143};
2144
2145// CommandObjectMultiwordThreadPlan
2146
2148public:
2151 interpreter, "plan",
2152 "Commands for managing thread plans that control execution.",
2153 "thread plan <subcommand> [<subcommand objects]") {
2155 "list", CommandObjectSP(new CommandObjectThreadPlanList(interpreter)));
2157 "discard",
2160 "prune",
2162 }
2163
2165};
2166
2167// Next are the subcommands of CommandObjectMultiwordTrace
2168
2169// CommandObjectTraceExport
2170
2172public:
2175 interpreter, "trace thread export",
2176 "Commands for exporting traces of the threads in the current "
2177 "process to different formats.",
2178 "thread trace export <export-plugin> [<subcommand objects>]") {
2179
2180 for (auto &cbs : PluginManager::GetTraceExporterCallbacks()) {
2181 if (cbs.create_thread_trace_export_command)
2182 LoadSubCommand(cbs.name,
2183 cbs.create_thread_trace_export_command(interpreter));
2184 }
2185 }
2186};
2187
2188// CommandObjectTraceStart
2189
2191public:
2194 /*live_debug_session_only=*/true, interpreter, "thread trace start",
2195 "Start tracing threads with the corresponding trace "
2196 "plug-in for the current process.",
2197 "thread trace start [<trace-options>]") {}
2198
2199protected:
2203};
2204
2205// CommandObjectTraceStop
2206
2208public:
2211 interpreter, "thread trace stop",
2212 "Stop tracing threads, including the ones traced with the "
2213 "\"process trace start\" command."
2214 "Defaults to the current thread. Thread indices can be "
2215 "specified as arguments.\n Use the thread-index \"all\" to stop "
2216 "tracing "
2217 "for all existing threads.",
2218 "thread trace stop [<thread-index> <thread-index> ...]",
2219 eCommandRequiresProcess | eCommandTryTargetAPILock |
2220 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
2221 eCommandProcessMustBeTraced) {}
2222
2223 ~CommandObjectTraceStop() override = default;
2224
2226 llvm::ArrayRef<lldb::tid_t> tids) override {
2227 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
2228
2229 TraceSP trace_sp = process_sp->GetTarget().GetTrace();
2230
2231 if (llvm::Error err = trace_sp->Stop(tids))
2232 result.AppendError(toString(std::move(err)));
2233 else
2235
2236 return result.Succeeded();
2237 }
2238};
2239
2241 CommandReturnObject &result) {
2242 if (args.GetArgumentCount() == 0)
2243 return exe_ctx.GetThreadSP();
2244
2245 const char *arg = args.GetArgumentAtIndex(0);
2246 uint32_t thread_idx;
2247
2248 if (!llvm::to_integer(arg, thread_idx)) {
2249 result.AppendErrorWithFormat("invalid thread specification: \"%s\"", arg);
2250 return nullptr;
2251 }
2252 ThreadSP thread_sp =
2253 exe_ctx.GetProcessRef().GetThreadList().FindThreadByIndexID(thread_idx);
2254 if (!thread_sp)
2255 result.AppendErrorWithFormat("no thread with index: \"%s\"", arg);
2256 return thread_sp;
2257}
2258
2259// CommandObjectTraceDumpFunctionCalls
2260#define LLDB_OPTIONS_thread_trace_dump_function_calls
2261#include "CommandOptions.inc"
2262
2264public:
2265 class CommandOptions : public Options {
2266 public:
2268
2269 ~CommandOptions() override = default;
2270
2271 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2272 ExecutionContext *execution_context) override {
2273 Status error;
2274 const int short_option = m_getopt_table[option_idx].val;
2275
2276 switch (short_option) {
2277 case 'j': {
2278 m_dumper_options.json = true;
2279 break;
2280 }
2281 case 'J': {
2282 m_dumper_options.json = true;
2283 m_dumper_options.pretty_print_json = true;
2284 break;
2285 }
2286 case 'F': {
2287 m_output_file.emplace(option_arg);
2288 break;
2289 }
2290 default:
2291 llvm_unreachable("Unimplemented option");
2292 }
2293 return error;
2294 }
2295
2296 void OptionParsingStarting(ExecutionContext *execution_context) override {
2297 m_dumper_options = {};
2298 m_output_file = std::nullopt;
2299 }
2300
2301 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2302 return llvm::ArrayRef(g_thread_trace_dump_function_calls_options);
2303 }
2304
2305 static const size_t kDefaultCount = 20;
2306
2307 // Instance variables to hold the values for command options.
2309 std::optional<FileSpec> m_output_file;
2310 };
2311
2314 interpreter, "thread trace dump function-calls",
2315 "Dump the traced function-calls for one thread. If no "
2316 "thread is specified, the current thread is used.",
2317 nullptr,
2318 eCommandRequiresProcess | eCommandRequiresThread |
2319 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
2320 eCommandProcessMustBePaused | eCommandProcessMustBeTraced) {
2322 }
2323
2325
2326 Options *GetOptions() override { return &m_options; }
2327
2328protected:
2329 void DoExecute(Args &args, CommandReturnObject &result) override {
2330 ThreadSP thread_sp = GetSingleThreadFromArgs(m_exe_ctx, args, result);
2331 if (!thread_sp) {
2332 result.AppendError("invalid thread\n");
2333 return;
2334 }
2335
2336 llvm::Expected<TraceCursorSP> cursor_or_error =
2337 m_exe_ctx.GetTargetSP()->GetTrace()->CreateNewCursor(*thread_sp);
2338
2339 if (!cursor_or_error) {
2340 result.AppendError(llvm::toString(cursor_or_error.takeError()));
2341 return;
2342 }
2343 TraceCursorSP &cursor_sp = *cursor_or_error;
2344
2345 std::optional<StreamFile> out_file;
2346 if (m_options.m_output_file) {
2347 out_file.emplace(m_options.m_output_file->GetPath().c_str(),
2350 }
2351
2352 m_options.m_dumper_options.forwards = true;
2353
2354 TraceDumper dumper(std::move(cursor_sp),
2355 out_file ? *out_file : result.GetOutputStream(),
2356 m_options.m_dumper_options);
2357
2358 dumper.DumpFunctionCalls();
2359 }
2360
2362};
2363
2364// CommandObjectTraceDumpInstructions
2365#define LLDB_OPTIONS_thread_trace_dump_instructions
2366#include "CommandOptions.inc"
2367
2369public:
2370 class CommandOptions : public Options {
2371 public:
2373
2374 ~CommandOptions() override = default;
2375
2376 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2377 ExecutionContext *execution_context) override {
2378 Status error;
2379 const int short_option = m_getopt_table[option_idx].val;
2380
2381 switch (short_option) {
2382 case 'c': {
2383 int32_t count;
2384 if (option_arg.empty() || option_arg.getAsInteger(0, count) ||
2385 count < 0)
2387 "invalid integer value for option '%s'",
2388 option_arg.str().c_str());
2389 else
2390 m_count = count;
2391 break;
2392 }
2393 case 'a': {
2394 m_count = std::numeric_limits<decltype(m_count)>::max();
2395 break;
2396 }
2397 case 's': {
2398 int32_t skip;
2399 if (option_arg.empty() || option_arg.getAsInteger(0, skip) || skip < 0)
2401 "invalid integer value for option '%s'",
2402 option_arg.str().c_str());
2403 else
2404 m_dumper_options.skip = skip;
2405 break;
2406 }
2407 case 'i': {
2408 uint64_t id;
2409 if (option_arg.empty() || option_arg.getAsInteger(0, id))
2411 "invalid integer value for option '%s'",
2412 option_arg.str().c_str());
2413 else
2414 m_dumper_options.id = id;
2415 break;
2416 }
2417 case 'F': {
2418 m_output_file.emplace(option_arg);
2419 break;
2420 }
2421 case 'r': {
2422 m_dumper_options.raw = true;
2423 break;
2424 }
2425 case 'f': {
2426 m_dumper_options.forwards = true;
2427 break;
2428 }
2429 case 'k': {
2430 m_dumper_options.show_control_flow_kind = true;
2431 break;
2432 }
2433 case 't': {
2434 m_dumper_options.show_timestamps = true;
2435 break;
2436 }
2437 case 'e': {
2438 m_dumper_options.show_events = true;
2439 break;
2440 }
2441 case 'j': {
2442 m_dumper_options.json = true;
2443 break;
2444 }
2445 case 'J': {
2446 m_dumper_options.pretty_print_json = true;
2447 m_dumper_options.json = true;
2448 break;
2449 }
2450 case 'E': {
2451 m_dumper_options.only_events = true;
2452 m_dumper_options.show_events = true;
2453 break;
2454 }
2455 case 'C': {
2456 m_continue = true;
2457 break;
2458 }
2459 default:
2460 llvm_unreachable("Unimplemented option");
2461 }
2462 return error;
2463 }
2464
2465 void OptionParsingStarting(ExecutionContext *execution_context) override {
2467 m_continue = false;
2468 m_output_file = std::nullopt;
2469 m_dumper_options = {};
2470 }
2471
2472 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2473 return llvm::ArrayRef(g_thread_trace_dump_instructions_options);
2474 }
2475
2476 static const size_t kDefaultCount = 20;
2477
2478 // Instance variables to hold the values for command options.
2479 size_t m_count;
2481 std::optional<FileSpec> m_output_file;
2483 };
2484
2487 interpreter, "thread trace dump instructions",
2488 "Dump the traced instructions for one thread. If no "
2489 "thread is specified, show the current thread.",
2490 nullptr,
2491 eCommandRequiresProcess | eCommandRequiresThread |
2492 eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
2493 eCommandProcessMustBePaused | eCommandProcessMustBeTraced) {
2495 }
2496
2498
2499 Options *GetOptions() override { return &m_options; }
2500
2501 std::optional<std::string> GetRepeatCommand(Args &current_command_args,
2502 uint32_t index) override {
2503 std::string cmd;
2504 current_command_args.GetCommandString(cmd);
2505 if (cmd.find(" --continue") == std::string::npos)
2506 cmd += " --continue";
2507 return cmd;
2508 }
2509
2510protected:
2511 void DoExecute(Args &args, CommandReturnObject &result) override {
2512 ThreadSP thread_sp = GetSingleThreadFromArgs(m_exe_ctx, args, result);
2513 if (!thread_sp) {
2514 result.AppendError("invalid thread\n");
2515 return;
2516 }
2517
2518 if (m_options.m_continue && m_last_id) {
2519 // We set up the options to continue one instruction past where
2520 // the previous iteration stopped.
2521 m_options.m_dumper_options.skip = 1;
2522 m_options.m_dumper_options.id = m_last_id;
2523 }
2524
2525 llvm::Expected<TraceCursorSP> cursor_or_error =
2526 m_exe_ctx.GetTargetSP()->GetTrace()->CreateNewCursor(*thread_sp);
2527
2528 if (!cursor_or_error) {
2529 result.AppendError(llvm::toString(cursor_or_error.takeError()));
2530 return;
2531 }
2532 TraceCursorSP &cursor_sp = *cursor_or_error;
2533
2534 if (m_options.m_dumper_options.id &&
2535 !cursor_sp->HasId(*m_options.m_dumper_options.id)) {
2536 result.AppendError("invalid instruction id\n");
2537 return;
2538 }
2539
2540 std::optional<StreamFile> out_file;
2541 if (m_options.m_output_file) {
2542 out_file.emplace(m_options.m_output_file->GetPath().c_str(),
2545 }
2546
2547 if (m_options.m_continue && !m_last_id) {
2548 // We need to stop processing data when we already ran out of instructions
2549 // in a previous command. We can fake this by setting the cursor past the
2550 // end of the trace.
2551 cursor_sp->Seek(1, lldb::eTraceCursorSeekTypeEnd);
2552 }
2553
2554 TraceDumper dumper(std::move(cursor_sp),
2555 out_file ? *out_file : result.GetOutputStream(),
2556 m_options.m_dumper_options);
2557
2558 m_last_id = dumper.DumpInstructions(m_options.m_count);
2559 }
2560
2562 // Last traversed id used to continue a repeat command. std::nullopt means
2563 // that all the trace has been consumed.
2564 std::optional<lldb::user_id_t> m_last_id;
2565};
2566
2567// CommandObjectTraceDumpInfo
2568#define LLDB_OPTIONS_thread_trace_dump_info
2569#include "CommandOptions.inc"
2570
2572public:
2573 class CommandOptions : public Options {
2574 public:
2576
2577 ~CommandOptions() override = default;
2578
2579 Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
2580 ExecutionContext *execution_context) override {
2581 Status error;
2582 const int short_option = m_getopt_table[option_idx].val;
2583
2584 switch (short_option) {
2585 case 'v': {
2586 m_verbose = true;
2587 break;
2588 }
2589 case 'j': {
2590 m_json = true;
2591 break;
2592 }
2593 default:
2594 llvm_unreachable("Unimplemented option");
2595 }
2596 return error;
2597 }
2598
2599 void OptionParsingStarting(ExecutionContext *execution_context) override {
2600 m_verbose = false;
2601 m_json = false;
2602 }
2603
2604 llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
2605 return llvm::ArrayRef(g_thread_trace_dump_info_options);
2606 }
2607
2608 // Instance variables to hold the values for command options.
2611 };
2612
2615 interpreter, "thread trace dump info",
2616 "Dump the traced information for one or more threads. If no "
2617 "threads are specified, show the current thread. Use the "
2618 "thread-index \"all\" to see all threads.",
2619 nullptr,
2620 eCommandRequiresProcess | eCommandTryTargetAPILock |
2621 eCommandProcessMustBeLaunched | eCommandProcessMustBePaused |
2622 eCommandProcessMustBeTraced) {}
2623
2624 ~CommandObjectTraceDumpInfo() override = default;
2625
2626 Options *GetOptions() override { return &m_options; }
2627
2628protected:
2630 const TraceSP &trace_sp = m_exe_ctx.GetTargetSP()->GetTrace();
2631 ThreadSP thread_sp =
2632 m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
2633 trace_sp->DumpTraceInfo(*thread_sp, result.GetOutputStream(),
2634 m_options.m_verbose, m_options.m_json);
2635 return true;
2636 }
2637
2639};
2640
2641// CommandObjectMultiwordTraceDump
2643public:
2646 interpreter, "dump",
2647 "Commands for displaying trace information of the threads "
2648 "in the current process.",
2649 "thread trace dump <subcommand> [<subcommand objects>]") {
2651 "instructions",
2654 "function-calls",
2657 "info", CommandObjectSP(new CommandObjectTraceDumpInfo(interpreter)));
2658 }
2660};
2661
2662// CommandObjectMultiwordTrace
2664public:
2667 interpreter, "trace",
2668 "Commands for operating on traces of the threads in the current "
2669 "process.",
2670 "thread trace <subcommand> [<subcommand objects>]") {
2672 interpreter)));
2673 LoadSubCommand("start",
2674 CommandObjectSP(new CommandObjectTraceStart(interpreter)));
2675 LoadSubCommand("stop",
2676 CommandObjectSP(new CommandObjectTraceStop(interpreter)));
2677 LoadSubCommand("export",
2678 CommandObjectSP(new CommandObjectTraceExport(interpreter)));
2679 }
2680
2681 ~CommandObjectMultiwordTrace() override = default;
2682};
2683
2684// CommandObjectMultiwordThread
2685
2687 CommandInterpreter &interpreter)
2688 : CommandObjectMultiword(interpreter, "thread",
2689 "Commands for operating on "
2690 "one or more threads in "
2691 "the current process.",
2692 "thread <subcommand> [<subcommand-options>]") {
2694 interpreter)));
2695 LoadSubCommand("continue",
2697 LoadSubCommand("list",
2698 CommandObjectSP(new CommandObjectThreadList(interpreter)));
2699 LoadSubCommand("return",
2700 CommandObjectSP(new CommandObjectThreadReturn(interpreter)));
2701 LoadSubCommand("jump",
2702 CommandObjectSP(new CommandObjectThreadJump(interpreter)));
2703 LoadSubCommand("select",
2704 CommandObjectSP(new CommandObjectThreadSelect(interpreter)));
2705 LoadSubCommand("until",
2706 CommandObjectSP(new CommandObjectThreadUntil(interpreter)));
2707 LoadSubCommand("info",
2708 CommandObjectSP(new CommandObjectThreadInfo(interpreter)));
2710 interpreter)));
2711 LoadSubCommand("siginfo",
2713 LoadSubCommand("step-in",
2715 interpreter, "thread step-in",
2716 "Source level single step, stepping into calls. Defaults "
2717 "to current thread unless specified.",
2718 nullptr, eStepTypeInto)));
2719
2720 LoadSubCommand("step-out",
2722 interpreter, "thread step-out",
2723 "Finish executing the current stack frame and stop after "
2724 "returning. Defaults to current thread unless specified.",
2725 nullptr, eStepTypeOut)));
2726
2727 LoadSubCommand("step-over",
2729 interpreter, "thread step-over",
2730 "Source level single step, stepping over calls. Defaults "
2731 "to current thread unless specified.",
2732 nullptr, eStepTypeOver)));
2733
2734 LoadSubCommand("step-inst",
2736 interpreter, "thread step-inst",
2737 "Instruction level single step, stepping into calls. "
2738 "Defaults to current thread unless specified.",
2739 nullptr, eStepTypeTrace)));
2740
2741 LoadSubCommand("step-inst-over",
2743 interpreter, "thread step-inst-over",
2744 "Instruction level single step, stepping over calls. "
2745 "Defaults to current thread unless specified.",
2746 nullptr, eStepTypeTraceOver)));
2747
2749 "step-scripted",
2751 interpreter, "thread step-scripted",
2752 "Step as instructed by the script class passed in the -C option. "
2753 "You can also specify a dictionary of key (-k) and value (-v) pairs "
2754 "that will be used to populate an SBStructuredData Dictionary, which "
2755 "will be passed to the constructor of the class implementing the "
2756 "scripted step. See the Python Reference for more details.",
2757 nullptr, eStepTypeScripted)));
2758
2760 interpreter)));
2761 LoadSubCommand("trace",
2763}
2764
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:514
static void skip(TSLexer *lexer)
~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
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.
Address & GetBaseAddress()
Get accessor for the base address of the range.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetCallableLoadAddress(Target *target, bool is_indirect=false) const
Get the load address as a callable code load address.
Definition Address.cpp:328
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
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:248
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
CommandObjectIterateOverThreads(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, uint32_t flags)
void DoExecute(Args &command, CommandReturnObject &result) override
CommandObjectMultipleThreads(CommandInterpreter &interpreter, const char *name, const char *help, const char *syntax, uint32_t flags)
CommandObjectMultiwordThread(CommandInterpreter &interpreter)
bool LoadSubCommand(llvm::StringRef cmd_name, const lldb::CommandObjectSP &command_obj) override
CommandObjectMultiword(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
CommandObjectParsed(CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
CommandObjectRaw(CommandInterpreter &interpreter, llvm::StringRef name, llvm::StringRef help="", llvm::StringRef syntax="", uint32_t flags=0)
CommandObjectTraceProxy(bool live_debug_session_only, CommandInterpreter &interpreter, const char *name, const char *help=nullptr, const char *syntax=nullptr, uint32_t flags=0)
std::vector< CommandArgumentData > CommandArgumentEntry
void AddSimpleArgumentList(lldb::CommandArgumentType arg_type, ArgumentRepetitionType repetition_type=eArgRepeatPlain)
std::vector< CommandArgumentEntry > m_arguments
CommandInterpreter & GetCommandInterpreter()
CommandInterpreter & m_interpreter
virtual void HandleArgumentCompletion(CompletionRequest &request, OptionElementVector &opt_element_vector)
The default version handles argument definitions that have only one argument type,...
virtual llvm::StringRef GetSyntax()
void AppendMessage(llvm::StringRef in_string)
void AppendError(llvm::StringRef in_string)
void SetStatus(lldb::ReturnStatus status)
void AppendErrorWithFormat(const char *format,...) __attribute__((format(printf
void void AppendMessageWithFormatv(const char *format, Args &&...args)
void AppendWarning(llvm::StringRef in_string)
void AppendErrorWithFormatv(const char *format, Args &&...args)
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
LineTable * GetLineTable()
Get the line table for the compile unit.
"lldb/Utility/ArgCompletionRequest.h"
void SetUnwindOnError(bool unwind=false)
Definition Target.h:407
void SetUseDynamic(lldb::DynamicValueType dynamic=lldb::eDynamicCanRunTarget)
Definition Target.h:422
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
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.
Process & GetProcessRef() const
Returns a reference to the process object.
const lldb::ThreadSP & GetThreadSP() const
Get accessor to get the thread shared pointer.
A file collection class.
A file utility class.
Definition FileSpec.h:56
A line table class.
Definition LineTable.h:25
A command line option parsing protocol class.
Definition Options.h:58
std::vector< Option > m_getopt_table
Definition Options.h:198
static llvm::SmallVector< TraceExporterCallbacks > GetTraceExporterCallbacks()
A plug-in interface definition class for debugging a process.
Definition Process.h:368
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:552
ThreadList & GetThreadList()
Definition Process.h:2367
Status Resume()
Resumes all of a process's threads as configured using the Thread run control functions.
Definition Process.cpp:1374
void PruneThreadPlans()
Prune ThreadPlanStacks for all unreported threads.
Definition Process.cpp:1258
bool PruneThreadPlansForTID(lldb::tid_t tid)
Prune ThreadPlanStacks for unreported threads.
Definition Process.cpp:1254
virtual SystemRuntime * GetSystemRuntime()
Get the system runtime plug-in for this process.
Definition Process.cpp:3145
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:1263
Status ResumeSynchronous(Stream *stream)
Resume a process, and wait for it to stop.
Definition Process.cpp:1391
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:6116
lldb::StateType GetState()
Get accessor for the current process state.
Definition Process.cpp:1315
uint32_t GetIOHandlerID() const
Definition Process.h:2429
void GetStatus(Stream &ostrm, bool is_verbose=false)
Definition Process.cpp:6093
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:703
Process * GetProcess()
Definition Runtime.h:22
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual llvm::Expected< lldb::ThreadPlanSP > GetThreadPlanForStepType(lldb::StepType step_type)
Definition StackFrame.h:576
virtual bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
virtual const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
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 PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
size_t PutChar(char ch)
Definition Stream.cpp:131
Defines a symbol context baton that can be handed other debug core functions.
llvm::Error GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range)
Function * function
The Function for a given query.
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.
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:2971
uint32_t GetSize(bool can_update=true)
bool SetSelectedThreadByID(lldb::tid_t tid, bool notify=false)
lldb::ThreadSP FindThreadByIndexID(uint32_t index_id, bool can_update=true)
lldb::ThreadSP GetThreadAtIndex(uint32_t idx, bool can_update=true)
std::recursive_mutex & GetMutex() const override
lldb::ThreadSP FindThreadByID(lldb::tid_t tid, bool can_update=true)
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
#define LLDB_OPT_SET_2
#define LLDB_INVALID_LINE_NUMBER
#define LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_INDEX32
#define LLDB_OPT_SET_ALL
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
#define LLDB_INVALID_FRAME_ID
@ DoNoSelectMostRelevantFrame
A class that represents a running process on the host machine.
std::vector< OptionArgElement > OptionElementVector
Definition Options.h:43
llvm::Expected< std::vector< lldb::addr_t > > GetStepUntilAddresses(StackFrame &frame, const FileSpec &file, llvm::ArrayRef< uint32_t > lines, llvm::ArrayRef< lldb::addr_t > requested_addresses)
Returns the load addresses of the line table entries for lines in file, and of addresses,...
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition State.cpp:14
std::string toString(FormatterBytecode::OpCodes op)
@ eThreadIndexCompletion
std::shared_ptr< lldb_private::Trace > TraceSP
std::shared_ptr< lldb_private::ThreadPlan > ThreadPlanSP
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelFull
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::Thread > ThreadSP
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
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
@ eReturnStatusFailed
@ eReturnStatusSuccessContinuingNoResult
@ eReturnStatusSuccessFinishResult
@ eReturnStatusSuccessFinishNoResult
@ eArgTypeThreadIndex
@ eArgTypeUnsignedInteger
@ eTraceCursorSeekTypeEnd
The end of the trace, i.e the most recent item.
std::shared_ptr< lldb_private::TraceCursor > TraceCursorSP
@ eStepTypeInto
Single step into a specified context.
@ eStepTypeTraceOver
Single step one instruction, stepping over.
@ eStepTypeTrace
Single step one instruction.
@ eStepTypeOut
Single step out a specified context.
@ eStepTypeScripted
A step type implemented by the script interpreter.
@ eStepTypeOver
Single step over a specified context.
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
RunMode
Thread Run Modes.
@ eOnlyDuringStepping
uint64_t tid_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::StackFrameList > StackFrameListSP
uint32_t frame_list_id_t
Definition lldb-types.h:87
Used to build individual command argument lists.
uint32_t arg_opt_set_association
This arg might be associated only with some particular option set(s).
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:151
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
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47