1ac7ddfbfSEd Maste //===-- CommandObjectThread.cpp ---------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "CommandObjectThread.h"
11ac7ddfbfSEd Maste
12ac7ddfbfSEd Maste #include "lldb/Core/SourceManager.h"
131c3bbb01SEd Maste #include "lldb/Core/ValueObject.h"
14ac7ddfbfSEd Maste #include "lldb/Host/Host.h"
15f678e45dSDimitry Andric #include "lldb/Host/OptionParser.h"
161c3bbb01SEd Maste #include "lldb/Host/StringConvert.h"
17ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
18ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandReturnObject.h"
194ba319b5SDimitry Andric #include "lldb/Interpreter/OptionArgParser.h"
20ac7ddfbfSEd Maste #include "lldb/Interpreter/Options.h"
21ac7ddfbfSEd Maste #include "lldb/Symbol/CompileUnit.h"
22ac7ddfbfSEd Maste #include "lldb/Symbol/Function.h"
23ac7ddfbfSEd Maste #include "lldb/Symbol/LineEntry.h"
24435933ddSDimitry Andric #include "lldb/Symbol/LineTable.h"
25ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
26ac7ddfbfSEd Maste #include "lldb/Target/RegisterContext.h"
27b952cd58SEd Maste #include "lldb/Target/SystemRuntime.h"
28ac7ddfbfSEd Maste #include "lldb/Target/Target.h"
29ac7ddfbfSEd Maste #include "lldb/Target/Thread.h"
30ac7ddfbfSEd Maste #include "lldb/Target/ThreadPlan.h"
31435933ddSDimitry Andric #include "lldb/Target/ThreadPlanStepInRange.h"
32ac7ddfbfSEd Maste #include "lldb/Target/ThreadPlanStepInstruction.h"
33ac7ddfbfSEd Maste #include "lldb/Target/ThreadPlanStepOut.h"
34ac7ddfbfSEd Maste #include "lldb/Target/ThreadPlanStepRange.h"
35*b5893f02SDimitry Andric #include "lldb/Utility/State.h"
36435933ddSDimitry Andric #include "lldb/lldb-private.h"
37ac7ddfbfSEd Maste
38ac7ddfbfSEd Maste using namespace lldb;
39ac7ddfbfSEd Maste using namespace lldb_private;
40ac7ddfbfSEd Maste
41ac7ddfbfSEd Maste //-------------------------------------------------------------------------
4224d58133SDimitry Andric // CommandObjectIterateOverThreads
43ac7ddfbfSEd Maste //-------------------------------------------------------------------------
44ac7ddfbfSEd Maste
45435933ddSDimitry Andric class CommandObjectIterateOverThreads : public CommandObjectParsed {
4624d58133SDimitry Andric
4724d58133SDimitry Andric class UniqueStack {
4824d58133SDimitry Andric
4924d58133SDimitry Andric public:
UniqueStack(std::stack<lldb::addr_t> stack_frames,uint32_t thread_index_id)5024d58133SDimitry Andric UniqueStack(std::stack<lldb::addr_t> stack_frames, uint32_t thread_index_id)
5124d58133SDimitry Andric : m_stack_frames(stack_frames) {
5224d58133SDimitry Andric m_thread_index_ids.push_back(thread_index_id);
5324d58133SDimitry Andric }
5424d58133SDimitry Andric
AddThread(uint32_t thread_index_id) const5524d58133SDimitry Andric void AddThread(uint32_t thread_index_id) const {
5624d58133SDimitry Andric m_thread_index_ids.push_back(thread_index_id);
5724d58133SDimitry Andric }
5824d58133SDimitry Andric
GetUniqueThreadIndexIDs() const5924d58133SDimitry Andric const std::vector<uint32_t> &GetUniqueThreadIndexIDs() const {
6024d58133SDimitry Andric return m_thread_index_ids;
6124d58133SDimitry Andric }
6224d58133SDimitry Andric
GetRepresentativeThread() const6324d58133SDimitry Andric lldb::tid_t GetRepresentativeThread() const {
6424d58133SDimitry Andric return m_thread_index_ids.front();
6524d58133SDimitry Andric }
6624d58133SDimitry Andric
operator <(const UniqueStack & lhs,const UniqueStack & rhs)6724d58133SDimitry Andric friend bool inline operator<(const UniqueStack &lhs,
6824d58133SDimitry Andric const UniqueStack &rhs) {
6924d58133SDimitry Andric return lhs.m_stack_frames < rhs.m_stack_frames;
7024d58133SDimitry Andric }
7124d58133SDimitry Andric
7224d58133SDimitry Andric protected:
7324d58133SDimitry Andric // Mark the thread index as mutable, as we don't care about it from a const
7424d58133SDimitry Andric // perspective, we only care about m_stack_frames so we keep our std::set
7524d58133SDimitry Andric // sorted.
7624d58133SDimitry Andric mutable std::vector<uint32_t> m_thread_index_ids;
7724d58133SDimitry Andric std::stack<lldb::addr_t> m_stack_frames;
7824d58133SDimitry Andric };
7924d58133SDimitry Andric
807aa51b79SEd Maste public:
CommandObjectIterateOverThreads(CommandInterpreter & interpreter,const char * name,const char * help,const char * syntax,uint32_t flags)817aa51b79SEd Maste CommandObjectIterateOverThreads(CommandInterpreter &interpreter,
82435933ddSDimitry Andric const char *name, const char *help,
83435933ddSDimitry Andric const char *syntax, uint32_t flags)
84435933ddSDimitry Andric : CommandObjectParsed(interpreter, name, help, syntax, flags) {}
857aa51b79SEd Maste
864bb0738eSEd Maste ~CommandObjectIterateOverThreads() override = default;
879f2f44ceSEd Maste
DoExecute(Args & command,CommandReturnObject & result)88435933ddSDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
897aa51b79SEd Maste result.SetStatus(m_success_return);
907aa51b79SEd Maste
9124d58133SDimitry Andric bool all_threads = false;
92435933ddSDimitry Andric if (command.GetArgumentCount() == 0) {
937aa51b79SEd Maste Thread *thread = m_exe_ctx.GetThreadPtr();
94acac075bSDimitry Andric if (!thread || !HandleOneThread(thread->GetID(), result))
957aa51b79SEd Maste return false;
964bb0738eSEd Maste return result.Succeeded();
9724d58133SDimitry Andric } else if (command.GetArgumentCount() == 1) {
9824d58133SDimitry Andric all_threads = ::strcmp(command.GetArgumentAtIndex(0), "all") == 0;
9924d58133SDimitry Andric m_unique_stacks = ::strcmp(command.GetArgumentAtIndex(0), "unique") == 0;
1007aa51b79SEd Maste }
1014bb0738eSEd Maste
102435933ddSDimitry Andric // Use tids instead of ThreadSPs to prevent deadlocking problems which
1034ba319b5SDimitry Andric // result from JIT-ing code while iterating over the (locked) ThreadSP
1044ba319b5SDimitry Andric // list.
1054bb0738eSEd Maste std::vector<lldb::tid_t> tids;
1064bb0738eSEd Maste
10724d58133SDimitry Andric if (all_threads || m_unique_stacks) {
1087aa51b79SEd Maste Process *process = m_exe_ctx.GetProcessPtr();
1097aa51b79SEd Maste
1104bb0738eSEd Maste for (ThreadSP thread_sp : process->Threads())
1114bb0738eSEd Maste tids.push_back(thread_sp->GetID());
112435933ddSDimitry Andric } else {
1137aa51b79SEd Maste const size_t num_args = command.GetArgumentCount();
1147aa51b79SEd Maste Process *process = m_exe_ctx.GetProcessPtr();
1154bb0738eSEd Maste
116435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
117435933ddSDimitry Andric process->GetThreadList().GetMutex());
1187aa51b79SEd Maste
119435933ddSDimitry Andric for (size_t i = 0; i < num_args; i++) {
1207aa51b79SEd Maste bool success;
1217aa51b79SEd Maste
122435933ddSDimitry Andric uint32_t thread_idx = StringConvert::ToUInt32(
123435933ddSDimitry Andric command.GetArgumentAtIndex(i), 0, 0, &success);
124435933ddSDimitry Andric if (!success) {
125435933ddSDimitry Andric result.AppendErrorWithFormat("invalid thread specification: \"%s\"\n",
126435933ddSDimitry Andric command.GetArgumentAtIndex(i));
1277aa51b79SEd Maste result.SetStatus(eReturnStatusFailed);
1287aa51b79SEd Maste return false;
1297aa51b79SEd Maste }
1307aa51b79SEd Maste
131435933ddSDimitry Andric ThreadSP thread =
132435933ddSDimitry Andric process->GetThreadList().FindThreadByIndexID(thread_idx);
1337aa51b79SEd Maste
134435933ddSDimitry Andric if (!thread) {
135435933ddSDimitry Andric result.AppendErrorWithFormat("no thread with index: \"%s\"\n",
136435933ddSDimitry Andric command.GetArgumentAtIndex(i));
1377aa51b79SEd Maste result.SetStatus(eReturnStatusFailed);
1387aa51b79SEd Maste return false;
1397aa51b79SEd Maste }
1407aa51b79SEd Maste
1414bb0738eSEd Maste tids.push_back(thread->GetID());
1424bb0738eSEd Maste }
1437aa51b79SEd Maste }
1447aa51b79SEd Maste
14524d58133SDimitry Andric if (m_unique_stacks) {
14624d58133SDimitry Andric // Iterate over threads, finding unique stack buckets.
14724d58133SDimitry Andric std::set<UniqueStack> unique_stacks;
14824d58133SDimitry Andric for (const lldb::tid_t &tid : tids) {
14924d58133SDimitry Andric if (!BucketThread(tid, unique_stacks, result)) {
15024d58133SDimitry Andric return false;
15124d58133SDimitry Andric }
15224d58133SDimitry Andric }
15324d58133SDimitry Andric
15424d58133SDimitry Andric // Write the thread id's and unique call stacks to the output stream
15524d58133SDimitry Andric Stream &strm = result.GetOutputStream();
15624d58133SDimitry Andric Process *process = m_exe_ctx.GetProcessPtr();
15724d58133SDimitry Andric for (const UniqueStack &stack : unique_stacks) {
15824d58133SDimitry Andric // List the common thread ID's
15924d58133SDimitry Andric const std::vector<uint32_t> &thread_index_ids =
16024d58133SDimitry Andric stack.GetUniqueThreadIndexIDs();
161c4394386SDimitry Andric strm.Format("{0} thread(s) ", thread_index_ids.size());
16224d58133SDimitry Andric for (const uint32_t &thread_index_id : thread_index_ids) {
163c4394386SDimitry Andric strm.Format("#{0} ", thread_index_id);
16424d58133SDimitry Andric }
16524d58133SDimitry Andric strm.EOL();
16624d58133SDimitry Andric
16724d58133SDimitry Andric // List the shared call stack for this set of threads
16824d58133SDimitry Andric uint32_t representative_thread_id = stack.GetRepresentativeThread();
16924d58133SDimitry Andric ThreadSP thread = process->GetThreadList().FindThreadByIndexID(
17024d58133SDimitry Andric representative_thread_id);
17124d58133SDimitry Andric if (!HandleOneThread(thread->GetID(), result)) {
17224d58133SDimitry Andric return false;
17324d58133SDimitry Andric }
17424d58133SDimitry Andric }
17524d58133SDimitry Andric } else {
1764bb0738eSEd Maste uint32_t idx = 0;
177435933ddSDimitry Andric for (const lldb::tid_t &tid : tids) {
1784bb0738eSEd Maste if (idx != 0 && m_add_return)
1794bb0738eSEd Maste result.AppendMessage("");
1804bb0738eSEd Maste
1814bb0738eSEd Maste if (!HandleOneThread(tid, result))
1827aa51b79SEd Maste return false;
1837aa51b79SEd Maste
1844bb0738eSEd Maste ++idx;
1857aa51b79SEd Maste }
18624d58133SDimitry Andric }
1877aa51b79SEd Maste return result.Succeeded();
1887aa51b79SEd Maste }
1897aa51b79SEd Maste
1907aa51b79SEd Maste protected:
1917aa51b79SEd Maste // Override this to do whatever you need to do for one thread.
1927aa51b79SEd Maste //
1937aa51b79SEd Maste // If you return false, the iteration will stop, otherwise it will proceed.
194435933ddSDimitry Andric // The result is set to m_success_return (defaults to
1954ba319b5SDimitry Andric // eReturnStatusSuccessFinishResult) before the iteration, so you only need
1964ba319b5SDimitry Andric // to set the return status in HandleOneThread if you want to indicate an
1974ba319b5SDimitry Andric // error. If m_add_return is true, a blank line will be inserted between each
1984ba319b5SDimitry Andric // of the listings (except the last one.)
1997aa51b79SEd Maste
200435933ddSDimitry Andric virtual bool HandleOneThread(lldb::tid_t, CommandReturnObject &result) = 0;
2017aa51b79SEd Maste
BucketThread(lldb::tid_t tid,std::set<UniqueStack> & unique_stacks,CommandReturnObject & result)20224d58133SDimitry Andric bool BucketThread(lldb::tid_t tid, std::set<UniqueStack> &unique_stacks,
20324d58133SDimitry Andric CommandReturnObject &result) {
20424d58133SDimitry Andric // Grab the corresponding thread for the given thread id.
20524d58133SDimitry Andric Process *process = m_exe_ctx.GetProcessPtr();
20624d58133SDimitry Andric Thread *thread = process->GetThreadList().FindThreadByID(tid).get();
20724d58133SDimitry Andric if (thread == nullptr) {
208c4394386SDimitry Andric result.AppendErrorWithFormatv("Failed to process thread #{0}.\n", tid);
20924d58133SDimitry Andric result.SetStatus(eReturnStatusFailed);
21024d58133SDimitry Andric return false;
21124d58133SDimitry Andric }
21224d58133SDimitry Andric
21324d58133SDimitry Andric // Collect the each frame's address for this call-stack
21424d58133SDimitry Andric std::stack<lldb::addr_t> stack_frames;
21524d58133SDimitry Andric const uint32_t frame_count = thread->GetStackFrameCount();
21624d58133SDimitry Andric for (uint32_t frame_index = 0; frame_index < frame_count; frame_index++) {
21724d58133SDimitry Andric const lldb::StackFrameSP frame_sp =
21824d58133SDimitry Andric thread->GetStackFrameAtIndex(frame_index);
21924d58133SDimitry Andric const lldb::addr_t pc = frame_sp->GetStackID().GetPC();
22024d58133SDimitry Andric stack_frames.push(pc);
22124d58133SDimitry Andric }
22224d58133SDimitry Andric
22324d58133SDimitry Andric uint32_t thread_index_id = thread->GetIndexID();
22424d58133SDimitry Andric UniqueStack new_unique_stack(stack_frames, thread_index_id);
22524d58133SDimitry Andric
22624d58133SDimitry Andric // Try to match the threads stack to and existing entry.
22724d58133SDimitry Andric std::set<UniqueStack>::iterator matching_stack =
22824d58133SDimitry Andric unique_stacks.find(new_unique_stack);
22924d58133SDimitry Andric if (matching_stack != unique_stacks.end()) {
23024d58133SDimitry Andric matching_stack->AddThread(thread_index_id);
23124d58133SDimitry Andric } else {
23224d58133SDimitry Andric unique_stacks.insert(new_unique_stack);
23324d58133SDimitry Andric }
23424d58133SDimitry Andric return true;
23524d58133SDimitry Andric }
23624d58133SDimitry Andric
2377aa51b79SEd Maste ReturnStatus m_success_return = eReturnStatusSuccessFinishResult;
23824d58133SDimitry Andric bool m_unique_stacks = false;
2397aa51b79SEd Maste bool m_add_return = true;
2407aa51b79SEd Maste };
2417aa51b79SEd Maste
2427aa51b79SEd Maste //-------------------------------------------------------------------------
2437aa51b79SEd Maste // CommandObjectThreadBacktrace
2447aa51b79SEd Maste //-------------------------------------------------------------------------
2457aa51b79SEd Maste
246*b5893f02SDimitry Andric static constexpr OptionDefinition g_thread_backtrace_options[] = {
247435933ddSDimitry Andric // clang-format off
248*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount, "How many frames to display (-1 for all)" },
249*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "start", 's', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeFrameIndex, "Frame in which to start the backtrace" },
250*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "extended", 'e', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "Show the extended backtrace, if available" }
251435933ddSDimitry Andric // clang-format on
252435933ddSDimitry Andric };
253435933ddSDimitry Andric
254435933ddSDimitry Andric class CommandObjectThreadBacktrace : public CommandObjectIterateOverThreads {
255ac7ddfbfSEd Maste public:
256435933ddSDimitry Andric class CommandOptions : public Options {
257ac7ddfbfSEd Maste public:
CommandOptions()258435933ddSDimitry Andric CommandOptions() : Options() {
259435933ddSDimitry Andric // Keep default values of all options in one place: OptionParsingStarting
260435933ddSDimitry Andric // ()
261435933ddSDimitry Andric OptionParsingStarting(nullptr);
262ac7ddfbfSEd Maste }
263ac7ddfbfSEd Maste
2644bb0738eSEd Maste ~CommandOptions() override = default;
265ac7ddfbfSEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)2665517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
267435933ddSDimitry Andric ExecutionContext *execution_context) override {
2685517e702SDimitry Andric Status error;
269ac7ddfbfSEd Maste const int short_option = m_getopt_table[option_idx].val;
270ac7ddfbfSEd Maste
271435933ddSDimitry Andric switch (short_option) {
272435933ddSDimitry Andric case 'c': {
273435933ddSDimitry Andric int32_t input_count = 0;
274435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_count)) {
275ac7ddfbfSEd Maste m_count = UINT32_MAX;
276435933ddSDimitry Andric error.SetErrorStringWithFormat(
277435933ddSDimitry Andric "invalid integer value for option '%c'", short_option);
278435933ddSDimitry Andric } else if (input_count < 0)
279435933ddSDimitry Andric m_count = UINT32_MAX;
280435933ddSDimitry Andric } break;
281ac7ddfbfSEd Maste case 's':
282435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_start))
283435933ddSDimitry Andric error.SetErrorStringWithFormat(
284435933ddSDimitry Andric "invalid integer value for option '%c'", short_option);
2854bb0738eSEd Maste break;
286435933ddSDimitry Andric case 'e': {
287b952cd58SEd Maste bool success;
288435933ddSDimitry Andric m_extended_backtrace =
2894ba319b5SDimitry Andric OptionArgParser::ToBoolean(option_arg, false, &success);
290b952cd58SEd Maste if (!success)
291435933ddSDimitry Andric error.SetErrorStringWithFormat(
292435933ddSDimitry Andric "invalid boolean value for option '%c'", short_option);
293435933ddSDimitry Andric } break;
294ac7ddfbfSEd Maste default:
295435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid short option character '%c'",
296435933ddSDimitry Andric short_option);
297ac7ddfbfSEd Maste break;
298ac7ddfbfSEd Maste }
299ac7ddfbfSEd Maste return error;
300ac7ddfbfSEd Maste }
301ac7ddfbfSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)302435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
303ac7ddfbfSEd Maste m_count = UINT32_MAX;
304ac7ddfbfSEd Maste m_start = 0;
305b952cd58SEd Maste m_extended_backtrace = false;
306ac7ddfbfSEd Maste }
307ac7ddfbfSEd Maste
GetDefinitions()308435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
309435933ddSDimitry Andric return llvm::makeArrayRef(g_thread_backtrace_options);
310ac7ddfbfSEd Maste }
311ac7ddfbfSEd Maste
312ac7ddfbfSEd Maste // Instance variables to hold the values for command options.
313ac7ddfbfSEd Maste uint32_t m_count;
314ac7ddfbfSEd Maste uint32_t m_start;
315b952cd58SEd Maste bool m_extended_backtrace;
316ac7ddfbfSEd Maste };
317ac7ddfbfSEd Maste
CommandObjectThreadBacktrace(CommandInterpreter & interpreter)3184bb0738eSEd Maste CommandObjectThreadBacktrace(CommandInterpreter &interpreter)
3194bb0738eSEd Maste : CommandObjectIterateOverThreads(
320435933ddSDimitry Andric interpreter, "thread backtrace",
321435933ddSDimitry Andric "Show thread call stacks. Defaults to the current thread, thread "
32224d58133SDimitry Andric "indexes can be specified as arguments.\n"
32324d58133SDimitry Andric "Use the thread-index \"all\" to see all threads.\n"
32424d58133SDimitry Andric "Use the thread-index \"unique\" to see threads grouped by unique "
32524d58133SDimitry Andric "call stacks.",
326435933ddSDimitry Andric nullptr,
327435933ddSDimitry Andric eCommandRequiresProcess | eCommandRequiresThread |
328435933ddSDimitry Andric eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
329435933ddSDimitry Andric eCommandProcessMustBePaused),
330435933ddSDimitry Andric m_options() {}
331ac7ddfbfSEd Maste
3324bb0738eSEd Maste ~CommandObjectThreadBacktrace() override = default;
333ac7ddfbfSEd Maste
GetOptions()334435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
335ac7ddfbfSEd Maste
336ac7ddfbfSEd Maste protected:
DoExtendedBacktrace(Thread * thread,CommandReturnObject & result)337435933ddSDimitry Andric void DoExtendedBacktrace(Thread *thread, CommandReturnObject &result) {
338b952cd58SEd Maste SystemRuntime *runtime = thread->GetProcess()->GetSystemRuntime();
339435933ddSDimitry Andric if (runtime) {
340b952cd58SEd Maste Stream &strm = result.GetOutputStream();
341435933ddSDimitry Andric const std::vector<ConstString> &types =
342435933ddSDimitry Andric runtime->GetExtendedBacktraceTypes();
343435933ddSDimitry Andric for (auto type : types) {
344435933ddSDimitry Andric ThreadSP ext_thread_sp = runtime->GetExtendedBacktraceThread(
345435933ddSDimitry Andric thread->shared_from_this(), type);
346435933ddSDimitry Andric if (ext_thread_sp && ext_thread_sp->IsValid()) {
347b952cd58SEd Maste const uint32_t num_frames_with_source = 0;
348435933ddSDimitry Andric const bool stop_format = false;
349435933ddSDimitry Andric if (ext_thread_sp->GetStatus(strm, m_options.m_start,
350b952cd58SEd Maste m_options.m_count,
351435933ddSDimitry Andric num_frames_with_source,
352435933ddSDimitry Andric stop_format)) {
353b952cd58SEd Maste DoExtendedBacktrace(ext_thread_sp.get(), result);
354b952cd58SEd Maste }
355b952cd58SEd Maste }
356b952cd58SEd Maste }
357b952cd58SEd Maste }
358b952cd58SEd Maste }
359b952cd58SEd Maste
HandleOneThread(lldb::tid_t tid,CommandReturnObject & result)360435933ddSDimitry Andric bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
361435933ddSDimitry Andric ThreadSP thread_sp =
362435933ddSDimitry Andric m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
363435933ddSDimitry Andric if (!thread_sp) {
364435933ddSDimitry Andric result.AppendErrorWithFormat(
365435933ddSDimitry Andric "thread disappeared while computing backtraces: 0x%" PRIx64 "\n",
366435933ddSDimitry Andric tid);
3674bb0738eSEd Maste result.SetStatus(eReturnStatusFailed);
3684bb0738eSEd Maste return false;
3694bb0738eSEd Maste }
3704bb0738eSEd Maste
3714bb0738eSEd Maste Thread *thread = thread_sp.get();
3724bb0738eSEd Maste
373ac7ddfbfSEd Maste Stream &strm = result.GetOutputStream();
374ac7ddfbfSEd Maste
37524d58133SDimitry Andric // Only dump stack info if we processing unique stacks.
37624d58133SDimitry Andric const bool only_stacks = m_unique_stacks;
37724d58133SDimitry Andric
378ac7ddfbfSEd Maste // Don't show source context when doing backtraces.
379ac7ddfbfSEd Maste const uint32_t num_frames_with_source = 0;
380435933ddSDimitry Andric const bool stop_format = true;
381435933ddSDimitry Andric if (!thread->GetStatus(strm, m_options.m_start, m_options.m_count,
38224d58133SDimitry Andric num_frames_with_source, stop_format, only_stacks)) {
383435933ddSDimitry Andric result.AppendErrorWithFormat(
384435933ddSDimitry Andric "error displaying backtrace for thread: \"0x%4.4x\"\n",
385435933ddSDimitry Andric thread->GetIndexID());
386ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
387ac7ddfbfSEd Maste return false;
388ac7ddfbfSEd Maste }
389435933ddSDimitry Andric if (m_options.m_extended_backtrace) {
3904bb0738eSEd Maste DoExtendedBacktrace(thread, result);
391b952cd58SEd Maste }
392ac7ddfbfSEd Maste
3937aa51b79SEd Maste return true;
394ac7ddfbfSEd Maste }
395ac7ddfbfSEd Maste
396ac7ddfbfSEd Maste CommandOptions m_options;
397ac7ddfbfSEd Maste };
398ac7ddfbfSEd Maste
399435933ddSDimitry Andric enum StepScope { eStepScopeSource, eStepScopeInstruction };
400435933ddSDimitry Andric
401*b5893f02SDimitry Andric static constexpr OptionEnumValueElement g_tri_running_mode[] = {
402435933ddSDimitry Andric {eOnlyThisThread, "this-thread", "Run only this thread"},
403435933ddSDimitry Andric {eAllThreads, "all-threads", "Run all threads"},
404435933ddSDimitry Andric {eOnlyDuringStepping, "while-stepping",
405*b5893f02SDimitry Andric "Run only this thread while stepping"} };
406435933ddSDimitry Andric
TriRunningModes()407*b5893f02SDimitry Andric static constexpr OptionEnumValues TriRunningModes() {
408*b5893f02SDimitry Andric return OptionEnumValues(g_tri_running_mode);
409*b5893f02SDimitry Andric }
410435933ddSDimitry Andric
411*b5893f02SDimitry Andric static constexpr OptionDefinition g_thread_step_scope_options[] = {
412435933ddSDimitry Andric // clang-format off
413*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "step-in-avoids-no-debug", 'a', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "A boolean value that sets whether stepping into functions will step over functions with no debug information." },
414*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "step-out-avoids-no-debug", 'A', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "A boolean value, if true stepping out of functions will continue to step out till it hits a function with debug information." },
415*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, {}, 1, eArgTypeCount, "How many times to perform the stepping operation - currently only supported for step-inst and next-inst." },
416*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "end-linenumber", 'e', OptionParser::eRequiredArgument, nullptr, {}, 1, eArgTypeLineNum, "The line at which to stop stepping - defaults to the next line and only supported for step-in and step-over. You can also pass the string 'block' to step to the end of the current block. This is particularly useful in conjunction with --step-target to step through a complex calling sequence." },
417*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "run-mode", 'm', OptionParser::eRequiredArgument, nullptr, TriRunningModes(), 0, eArgTypeRunMode, "Determine how to run other threads while stepping the current thread." },
418*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "step-over-regexp", 'r', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeRegularExpression, "A regular expression that defines function names to not to stop at when stepping in." },
419*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "step-in-target", 't', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeFunctionName, "The name of the directly called function step in should stop at when stepping into." },
420*b5893f02SDimitry Andric { LLDB_OPT_SET_2, false, "python-class", 'C', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypePythonClass, "The name of the class that will manage this step - only supported for Scripted Step." }
421435933ddSDimitry Andric // clang-format on
422ac7ddfbfSEd Maste };
423ac7ddfbfSEd Maste
424435933ddSDimitry Andric class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed {
425ac7ddfbfSEd Maste public:
426435933ddSDimitry Andric class CommandOptions : public Options {
427ac7ddfbfSEd Maste public:
CommandOptions()428435933ddSDimitry Andric CommandOptions() : Options() {
429435933ddSDimitry Andric // Keep default values of all options in one place: OptionParsingStarting
430435933ddSDimitry Andric // ()
431435933ddSDimitry Andric OptionParsingStarting(nullptr);
432ac7ddfbfSEd Maste }
433ac7ddfbfSEd Maste
4344bb0738eSEd Maste ~CommandOptions() override = default;
435ac7ddfbfSEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)4365517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
437435933ddSDimitry Andric ExecutionContext *execution_context) override {
4385517e702SDimitry Andric Status error;
439ac7ddfbfSEd Maste const int short_option = m_getopt_table[option_idx].val;
440ac7ddfbfSEd Maste
441435933ddSDimitry Andric switch (short_option) {
442435933ddSDimitry Andric case 'a': {
443ac7ddfbfSEd Maste bool success;
4444ba319b5SDimitry Andric bool avoid_no_debug =
4454ba319b5SDimitry Andric OptionArgParser::ToBoolean(option_arg, true, &success);
446ac7ddfbfSEd Maste if (!success)
447435933ddSDimitry Andric error.SetErrorStringWithFormat(
448435933ddSDimitry Andric "invalid boolean value for option '%c'", short_option);
449435933ddSDimitry Andric else {
450435933ddSDimitry Andric m_step_in_avoid_no_debug =
451435933ddSDimitry Andric avoid_no_debug ? eLazyBoolYes : eLazyBoolNo;
4520127ef0fSEd Maste }
453435933ddSDimitry Andric } break;
454ac7ddfbfSEd Maste
455435933ddSDimitry Andric case 'A': {
4560127ef0fSEd Maste bool success;
4574ba319b5SDimitry Andric bool avoid_no_debug =
4584ba319b5SDimitry Andric OptionArgParser::ToBoolean(option_arg, true, &success);
4590127ef0fSEd Maste if (!success)
460435933ddSDimitry Andric error.SetErrorStringWithFormat(
461435933ddSDimitry Andric "invalid boolean value for option '%c'", short_option);
462435933ddSDimitry Andric else {
463435933ddSDimitry Andric m_step_out_avoid_no_debug =
464435933ddSDimitry Andric avoid_no_debug ? eLazyBoolYes : eLazyBoolNo;
4650127ef0fSEd Maste }
466435933ddSDimitry Andric } break;
4670127ef0fSEd Maste
4680127ef0fSEd Maste case 'c':
469435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_step_count))
470435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid step count '%s'",
471435933ddSDimitry Andric option_arg.str().c_str());
4720127ef0fSEd Maste break;
4734bb0738eSEd Maste
4747aa51b79SEd Maste case 'C':
4757aa51b79SEd Maste m_class_name.clear();
4767aa51b79SEd Maste m_class_name.assign(option_arg);
4777aa51b79SEd Maste break;
4784bb0738eSEd Maste
479435933ddSDimitry Andric case 'm': {
480*b5893f02SDimitry Andric auto enum_values = GetDefinitions()[option_idx].enum_values;
4814ba319b5SDimitry Andric m_run_mode = (lldb::RunMode)OptionArgParser::ToOptionEnum(
482435933ddSDimitry Andric option_arg, enum_values, eOnlyDuringStepping, error);
483435933ddSDimitry Andric } break;
484ac7ddfbfSEd Maste
4854bb0738eSEd Maste case 'e':
486435933ddSDimitry Andric if (option_arg == "block") {
4874bb0738eSEd Maste m_end_line_is_block_end = 1;
4884bb0738eSEd Maste break;
4894bb0738eSEd Maste }
490435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_end_line))
491435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid end line number '%s'",
492435933ddSDimitry Andric option_arg.str().c_str());
4934bb0738eSEd Maste break;
4944bb0738eSEd Maste
4954bb0738eSEd Maste case 'r':
496ac7ddfbfSEd Maste m_avoid_regexp.clear();
497ac7ddfbfSEd Maste m_avoid_regexp.assign(option_arg);
498ac7ddfbfSEd Maste break;
499ac7ddfbfSEd Maste
500ac7ddfbfSEd Maste case 't':
501ac7ddfbfSEd Maste m_step_in_target.clear();
502ac7ddfbfSEd Maste m_step_in_target.assign(option_arg);
503ac7ddfbfSEd Maste break;
5044bb0738eSEd Maste
505ac7ddfbfSEd Maste default:
506435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid short option character '%c'",
507435933ddSDimitry Andric short_option);
508ac7ddfbfSEd Maste break;
509ac7ddfbfSEd Maste }
510ac7ddfbfSEd Maste return error;
511ac7ddfbfSEd Maste }
512ac7ddfbfSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)513435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
5140127ef0fSEd Maste m_step_in_avoid_no_debug = eLazyBoolCalculate;
5150127ef0fSEd Maste m_step_out_avoid_no_debug = eLazyBoolCalculate;
516ac7ddfbfSEd Maste m_run_mode = eOnlyDuringStepping;
5171c3bbb01SEd Maste
5181c3bbb01SEd Maste // Check if we are in Non-Stop mode
519435933ddSDimitry Andric TargetSP target_sp =
520435933ddSDimitry Andric execution_context ? execution_context->GetTargetSP() : TargetSP();
5214bb0738eSEd Maste if (target_sp && target_sp->GetNonStopModeEnabled())
5221c3bbb01SEd Maste m_run_mode = eOnlyThisThread;
5231c3bbb01SEd Maste
524ac7ddfbfSEd Maste m_avoid_regexp.clear();
525ac7ddfbfSEd Maste m_step_in_target.clear();
5267aa51b79SEd Maste m_class_name.clear();
5270127ef0fSEd Maste m_step_count = 1;
5284bb0738eSEd Maste m_end_line = LLDB_INVALID_LINE_NUMBER;
5294bb0738eSEd Maste m_end_line_is_block_end = false;
530ac7ddfbfSEd Maste }
531ac7ddfbfSEd Maste
GetDefinitions()532435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
533435933ddSDimitry Andric return llvm::makeArrayRef(g_thread_step_scope_options);
534ac7ddfbfSEd Maste }
535ac7ddfbfSEd Maste
536ac7ddfbfSEd Maste // Instance variables to hold the values for command options.
5370127ef0fSEd Maste LazyBool m_step_in_avoid_no_debug;
5380127ef0fSEd Maste LazyBool m_step_out_avoid_no_debug;
539ac7ddfbfSEd Maste RunMode m_run_mode;
540ac7ddfbfSEd Maste std::string m_avoid_regexp;
541ac7ddfbfSEd Maste std::string m_step_in_target;
5427aa51b79SEd Maste std::string m_class_name;
5437aa51b79SEd Maste uint32_t m_step_count;
5444bb0738eSEd Maste uint32_t m_end_line;
5454bb0738eSEd Maste bool m_end_line_is_block_end;
546ac7ddfbfSEd Maste };
547ac7ddfbfSEd Maste
CommandObjectThreadStepWithTypeAndScope(CommandInterpreter & interpreter,const char * name,const char * help,const char * syntax,StepType step_type,StepScope step_scope)548ac7ddfbfSEd Maste CommandObjectThreadStepWithTypeAndScope(CommandInterpreter &interpreter,
549435933ddSDimitry Andric const char *name, const char *help,
550ac7ddfbfSEd Maste const char *syntax,
551ac7ddfbfSEd Maste StepType step_type,
552435933ddSDimitry Andric StepScope step_scope)
553435933ddSDimitry Andric : CommandObjectParsed(interpreter, name, help, syntax,
554435933ddSDimitry Andric eCommandRequiresProcess | eCommandRequiresThread |
5551c3bbb01SEd Maste eCommandTryTargetAPILock |
5561c3bbb01SEd Maste eCommandProcessMustBeLaunched |
5571c3bbb01SEd Maste eCommandProcessMustBePaused),
558435933ddSDimitry Andric m_step_type(step_type), m_step_scope(step_scope), m_options() {
559ac7ddfbfSEd Maste CommandArgumentEntry arg;
560ac7ddfbfSEd Maste CommandArgumentData thread_id_arg;
561ac7ddfbfSEd Maste
562ac7ddfbfSEd Maste // Define the first (and only) variant of this arg.
563ac7ddfbfSEd Maste thread_id_arg.arg_type = eArgTypeThreadID;
564ac7ddfbfSEd Maste thread_id_arg.arg_repetition = eArgRepeatOptional;
565ac7ddfbfSEd Maste
566435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
567435933ddSDimitry Andric // argument entry.
568ac7ddfbfSEd Maste arg.push_back(thread_id_arg);
569ac7ddfbfSEd Maste
570ac7ddfbfSEd Maste // Push the data for the first argument into the m_arguments vector.
571ac7ddfbfSEd Maste m_arguments.push_back(arg);
572ac7ddfbfSEd Maste }
573ac7ddfbfSEd Maste
5744bb0738eSEd Maste ~CommandObjectThreadStepWithTypeAndScope() override = default;
575ac7ddfbfSEd Maste
GetOptions()576435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
577ac7ddfbfSEd Maste
578ac7ddfbfSEd Maste protected:
DoExecute(Args & command,CommandReturnObject & result)579435933ddSDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
580ac7ddfbfSEd Maste Process *process = m_exe_ctx.GetProcessPtr();
581ac7ddfbfSEd Maste bool synchronous_execution = m_interpreter.GetSynchronous();
582ac7ddfbfSEd Maste
583ac7ddfbfSEd Maste const uint32_t num_threads = process->GetThreadList().GetSize();
5844bb0738eSEd Maste Thread *thread = nullptr;
585ac7ddfbfSEd Maste
586435933ddSDimitry Andric if (command.GetArgumentCount() == 0) {
5874bb0738eSEd Maste thread = GetDefaultThread();
5884bb0738eSEd Maste
589435933ddSDimitry Andric if (thread == nullptr) {
590ac7ddfbfSEd Maste result.AppendError("no selected thread in process");
591ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
592ac7ddfbfSEd Maste return false;
593ac7ddfbfSEd Maste }
594435933ddSDimitry Andric } else {
595ac7ddfbfSEd Maste const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
596435933ddSDimitry Andric uint32_t step_thread_idx =
597435933ddSDimitry Andric StringConvert::ToUInt32(thread_idx_cstr, LLDB_INVALID_INDEX32);
598435933ddSDimitry Andric if (step_thread_idx == LLDB_INVALID_INDEX32) {
599435933ddSDimitry Andric result.AppendErrorWithFormat("invalid thread index '%s'.\n",
600435933ddSDimitry Andric thread_idx_cstr);
601ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
602ac7ddfbfSEd Maste return false;
603ac7ddfbfSEd Maste }
604435933ddSDimitry Andric thread =
605435933ddSDimitry Andric process->GetThreadList().FindThreadByIndexID(step_thread_idx).get();
606435933ddSDimitry Andric if (thread == nullptr) {
607435933ddSDimitry Andric result.AppendErrorWithFormat(
608435933ddSDimitry Andric "Thread index %u is out of range (valid values are 0 - %u).\n",
609ac7ddfbfSEd Maste step_thread_idx, num_threads);
610ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
611ac7ddfbfSEd Maste return false;
612ac7ddfbfSEd Maste }
613ac7ddfbfSEd Maste }
614ac7ddfbfSEd Maste
615435933ddSDimitry Andric if (m_step_type == eStepTypeScripted) {
616435933ddSDimitry Andric if (m_options.m_class_name.empty()) {
6177aa51b79SEd Maste result.AppendErrorWithFormat("empty class name for scripted step.");
6187aa51b79SEd Maste result.SetStatus(eReturnStatusFailed);
6197aa51b79SEd Maste return false;
620435933ddSDimitry Andric } else if (!m_interpreter.GetScriptInterpreter()->CheckObjectExists(
621435933ddSDimitry Andric m_options.m_class_name.c_str())) {
622435933ddSDimitry Andric result.AppendErrorWithFormat(
623435933ddSDimitry Andric "class for scripted step: \"%s\" does not exist.",
624435933ddSDimitry Andric m_options.m_class_name.c_str());
6257aa51b79SEd Maste result.SetStatus(eReturnStatusFailed);
6267aa51b79SEd Maste return false;
6277aa51b79SEd Maste }
6287aa51b79SEd Maste }
6297aa51b79SEd Maste
630435933ddSDimitry Andric if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER &&
631435933ddSDimitry Andric m_step_type != eStepTypeInto) {
632435933ddSDimitry Andric result.AppendErrorWithFormat(
633435933ddSDimitry Andric "end line option is only valid for step into");
6344bb0738eSEd Maste result.SetStatus(eReturnStatusFailed);
6354bb0738eSEd Maste return false;
6364bb0738eSEd Maste }
6374bb0738eSEd Maste
638ac7ddfbfSEd Maste const bool abort_other_plans = false;
639ac7ddfbfSEd Maste const lldb::RunMode stop_other_threads = m_options.m_run_mode;
640ac7ddfbfSEd Maste
641435933ddSDimitry Andric // This is a bit unfortunate, but not all the commands in this command
6424ba319b5SDimitry Andric // object support only while stepping, so I use the bool for them.
643ac7ddfbfSEd Maste bool bool_stop_other_threads;
644ac7ddfbfSEd Maste if (m_options.m_run_mode == eAllThreads)
645ac7ddfbfSEd Maste bool_stop_other_threads = false;
646ac7ddfbfSEd Maste else if (m_options.m_run_mode == eOnlyDuringStepping)
647435933ddSDimitry Andric bool_stop_other_threads =
648435933ddSDimitry Andric (m_step_type != eStepTypeOut && m_step_type != eStepTypeScripted);
649ac7ddfbfSEd Maste else
650ac7ddfbfSEd Maste bool_stop_other_threads = true;
651ac7ddfbfSEd Maste
652ac7ddfbfSEd Maste ThreadPlanSP new_plan_sp;
653*b5893f02SDimitry Andric Status new_plan_status;
654ac7ddfbfSEd Maste
655435933ddSDimitry Andric if (m_step_type == eStepTypeInto) {
656ac7ddfbfSEd Maste StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
6571c3bbb01SEd Maste assert(frame != nullptr);
658ac7ddfbfSEd Maste
659435933ddSDimitry Andric if (frame->HasDebugInformation()) {
6604bb0738eSEd Maste AddressRange range;
6614bb0738eSEd Maste SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
662435933ddSDimitry Andric if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER) {
6635517e702SDimitry Andric Status error;
664435933ddSDimitry Andric if (!sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range,
665435933ddSDimitry Andric error)) {
666435933ddSDimitry Andric result.AppendErrorWithFormat("invalid end-line option: %s.",
667435933ddSDimitry Andric error.AsCString());
6684bb0738eSEd Maste result.SetStatus(eReturnStatusFailed);
6694bb0738eSEd Maste return false;
6704bb0738eSEd Maste }
671435933ddSDimitry Andric } else if (m_options.m_end_line_is_block_end) {
6725517e702SDimitry Andric Status error;
6734bb0738eSEd Maste Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
674435933ddSDimitry Andric if (!block) {
6754bb0738eSEd Maste result.AppendErrorWithFormat("Could not find the current block.");
6764bb0738eSEd Maste result.SetStatus(eReturnStatusFailed);
6774bb0738eSEd Maste return false;
6784bb0738eSEd Maste }
6794bb0738eSEd Maste
6804bb0738eSEd Maste AddressRange block_range;
6814bb0738eSEd Maste Address pc_address = frame->GetFrameCodeAddress();
6824bb0738eSEd Maste block->GetRangeContainingAddress(pc_address, block_range);
683435933ddSDimitry Andric if (!block_range.GetBaseAddress().IsValid()) {
684435933ddSDimitry Andric result.AppendErrorWithFormat(
685435933ddSDimitry Andric "Could not find the current block address.");
6864bb0738eSEd Maste result.SetStatus(eReturnStatusFailed);
6874bb0738eSEd Maste return false;
6884bb0738eSEd Maste }
689435933ddSDimitry Andric lldb::addr_t pc_offset_in_block =
690435933ddSDimitry Andric pc_address.GetFileAddress() -
691435933ddSDimitry Andric block_range.GetBaseAddress().GetFileAddress();
692435933ddSDimitry Andric lldb::addr_t range_length =
693435933ddSDimitry Andric block_range.GetByteSize() - pc_offset_in_block;
6944bb0738eSEd Maste range = AddressRange(pc_address, range_length);
695435933ddSDimitry Andric } else {
6964bb0738eSEd Maste range = sc.line_entry.range;
6974bb0738eSEd Maste }
6984bb0738eSEd Maste
699435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepInRange(
700435933ddSDimitry Andric abort_other_plans, range,
701ac7ddfbfSEd Maste frame->GetSymbolContext(eSymbolContextEverything),
702435933ddSDimitry Andric m_options.m_step_in_target.c_str(), stop_other_threads,
703*b5893f02SDimitry Andric new_plan_status, m_options.m_step_in_avoid_no_debug,
7040127ef0fSEd Maste m_options.m_step_out_avoid_no_debug);
7050127ef0fSEd Maste
706435933ddSDimitry Andric if (new_plan_sp && !m_options.m_avoid_regexp.empty()) {
707435933ddSDimitry Andric ThreadPlanStepInRange *step_in_range_plan =
708435933ddSDimitry Andric static_cast<ThreadPlanStepInRange *>(new_plan_sp.get());
709ac7ddfbfSEd Maste step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str());
710ac7ddfbfSEd Maste }
711435933ddSDimitry Andric } else
712435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
713*b5893f02SDimitry Andric false, abort_other_plans, bool_stop_other_threads, new_plan_status);
714435933ddSDimitry Andric } else if (m_step_type == eStepTypeOver) {
715ac7ddfbfSEd Maste StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
716ac7ddfbfSEd Maste
717ac7ddfbfSEd Maste if (frame->HasDebugInformation())
718435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepOverRange(
719435933ddSDimitry Andric abort_other_plans,
7209f2f44ceSEd Maste frame->GetSymbolContext(eSymbolContextEverything).line_entry,
721ac7ddfbfSEd Maste frame->GetSymbolContext(eSymbolContextEverything),
722*b5893f02SDimitry Andric stop_other_threads, new_plan_status,
723*b5893f02SDimitry Andric m_options.m_step_out_avoid_no_debug);
724ac7ddfbfSEd Maste else
725435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
726*b5893f02SDimitry Andric true, abort_other_plans, bool_stop_other_threads, new_plan_status);
727435933ddSDimitry Andric } else if (m_step_type == eStepTypeTrace) {
728435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
729*b5893f02SDimitry Andric false, abort_other_plans, bool_stop_other_threads, new_plan_status);
730435933ddSDimitry Andric } else if (m_step_type == eStepTypeTraceOver) {
731435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
732*b5893f02SDimitry Andric true, abort_other_plans, bool_stop_other_threads, new_plan_status);
733435933ddSDimitry Andric } else if (m_step_type == eStepTypeOut) {
734435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepOut(
735435933ddSDimitry Andric abort_other_plans, nullptr, false, bool_stop_other_threads, eVoteYes,
736*b5893f02SDimitry Andric eVoteNoOpinion, thread->GetSelectedFrameIndex(), new_plan_status,
7370127ef0fSEd Maste m_options.m_step_out_avoid_no_debug);
738435933ddSDimitry Andric } else if (m_step_type == eStepTypeScripted) {
739435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepScripted(
740435933ddSDimitry Andric abort_other_plans, m_options.m_class_name.c_str(),
741*b5893f02SDimitry Andric bool_stop_other_threads, new_plan_status);
742435933ddSDimitry Andric } else {
743ac7ddfbfSEd Maste result.AppendError("step type is not supported");
744ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
745ac7ddfbfSEd Maste return false;
746ac7ddfbfSEd Maste }
747ac7ddfbfSEd Maste
748435933ddSDimitry Andric // If we got a new plan, then set it to be a master plan (User level Plans
7494ba319b5SDimitry Andric // should be master plans so that they can be interruptible). Then resume
7504ba319b5SDimitry Andric // the process.
751ac7ddfbfSEd Maste
752435933ddSDimitry Andric if (new_plan_sp) {
753ac7ddfbfSEd Maste new_plan_sp->SetIsMasterPlan(true);
754ac7ddfbfSEd Maste new_plan_sp->SetOkayToDiscard(false);
755ac7ddfbfSEd Maste
756435933ddSDimitry Andric if (m_options.m_step_count > 1) {
757302affcbSDimitry Andric if (!new_plan_sp->SetIterationCount(m_options.m_step_count)) {
758435933ddSDimitry Andric result.AppendWarning(
759435933ddSDimitry Andric "step operation does not support iteration count.");
7600127ef0fSEd Maste }
7610127ef0fSEd Maste }
7620127ef0fSEd Maste
763ac7ddfbfSEd Maste process->GetThreadList().SetSelectedThreadByID(thread->GetID());
7647aa51b79SEd Maste
7651c3bbb01SEd Maste const uint32_t iohandler_id = process->GetIOHandlerID();
7661c3bbb01SEd Maste
7677aa51b79SEd Maste StreamString stream;
7685517e702SDimitry Andric Status error;
7697aa51b79SEd Maste if (synchronous_execution)
7707aa51b79SEd Maste error = process->ResumeSynchronous(&stream);
7717aa51b79SEd Maste else
7727aa51b79SEd Maste error = process->Resume();
773ac7ddfbfSEd Maste
774acac075bSDimitry Andric if (!error.Success()) {
775acac075bSDimitry Andric result.AppendMessage(error.AsCString());
776acac075bSDimitry Andric result.SetStatus(eReturnStatusFailed);
777acac075bSDimitry Andric return false;
778acac075bSDimitry Andric }
779acac075bSDimitry Andric
780435933ddSDimitry Andric // There is a race condition where this thread will return up the call
7814ba319b5SDimitry Andric // stack to the main command handler and show an (lldb) prompt before
7824ba319b5SDimitry Andric // HandlePrivateEvent (from PrivateStateThread) has a chance to call
7834ba319b5SDimitry Andric // PushProcessIOHandler().
7844ba319b5SDimitry Andric process->SyncIOHandler(iohandler_id, std::chrono::seconds(2));
785ac7ddfbfSEd Maste
786435933ddSDimitry Andric if (synchronous_execution) {
787435933ddSDimitry Andric // If any state changed events had anything to say, add that to the
788435933ddSDimitry Andric // result
789435933ddSDimitry Andric if (stream.GetSize() > 0)
790435933ddSDimitry Andric result.AppendMessage(stream.GetString());
791ac7ddfbfSEd Maste
792ac7ddfbfSEd Maste process->GetThreadList().SetSelectedThreadByID(thread->GetID());
793ac7ddfbfSEd Maste result.SetDidChangeProcessState(true);
794ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
795435933ddSDimitry Andric } else {
796ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessContinuingNoResult);
797ac7ddfbfSEd Maste }
798435933ddSDimitry Andric } else {
799*b5893f02SDimitry Andric result.SetError(new_plan_status);
800ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
801ac7ddfbfSEd Maste }
802ac7ddfbfSEd Maste return result.Succeeded();
803ac7ddfbfSEd Maste }
804ac7ddfbfSEd Maste
805ac7ddfbfSEd Maste protected:
806ac7ddfbfSEd Maste StepType m_step_type;
807ac7ddfbfSEd Maste StepScope m_step_scope;
808ac7ddfbfSEd Maste CommandOptions m_options;
809ac7ddfbfSEd Maste };
810ac7ddfbfSEd Maste
811ac7ddfbfSEd Maste //-------------------------------------------------------------------------
812ac7ddfbfSEd Maste // CommandObjectThreadContinue
813ac7ddfbfSEd Maste //-------------------------------------------------------------------------
814ac7ddfbfSEd Maste
815435933ddSDimitry Andric class CommandObjectThreadContinue : public CommandObjectParsed {
816ac7ddfbfSEd Maste public:
CommandObjectThreadContinue(CommandInterpreter & interpreter)8174bb0738eSEd Maste CommandObjectThreadContinue(CommandInterpreter &interpreter)
818435933ddSDimitry Andric : CommandObjectParsed(
819435933ddSDimitry Andric interpreter, "thread continue",
820435933ddSDimitry Andric "Continue execution of the current target process. One "
8214bb0738eSEd Maste "or more threads may be specified, by default all "
8224bb0738eSEd Maste "threads continue.",
823435933ddSDimitry Andric nullptr,
824435933ddSDimitry Andric eCommandRequiresThread | eCommandTryTargetAPILock |
825435933ddSDimitry Andric eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {
826ac7ddfbfSEd Maste CommandArgumentEntry arg;
827ac7ddfbfSEd Maste CommandArgumentData thread_idx_arg;
828ac7ddfbfSEd Maste
829ac7ddfbfSEd Maste // Define the first (and only) variant of this arg.
830ac7ddfbfSEd Maste thread_idx_arg.arg_type = eArgTypeThreadIndex;
831ac7ddfbfSEd Maste thread_idx_arg.arg_repetition = eArgRepeatPlus;
832ac7ddfbfSEd Maste
833435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
834435933ddSDimitry Andric // argument entry.
835ac7ddfbfSEd Maste arg.push_back(thread_idx_arg);
836ac7ddfbfSEd Maste
837ac7ddfbfSEd Maste // Push the data for the first argument into the m_arguments vector.
838ac7ddfbfSEd Maste m_arguments.push_back(arg);
839ac7ddfbfSEd Maste }
840ac7ddfbfSEd Maste
8414bb0738eSEd Maste ~CommandObjectThreadContinue() override = default;
842ac7ddfbfSEd Maste
DoExecute(Args & command,CommandReturnObject & result)843435933ddSDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
844ac7ddfbfSEd Maste bool synchronous_execution = m_interpreter.GetSynchronous();
845ac7ddfbfSEd Maste
846435933ddSDimitry Andric if (!m_interpreter.GetDebugger().GetSelectedTarget()) {
847435933ddSDimitry Andric result.AppendError("invalid target, create a debug target using the "
848435933ddSDimitry Andric "'target create' command");
849ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
850ac7ddfbfSEd Maste return false;
851ac7ddfbfSEd Maste }
852ac7ddfbfSEd Maste
853ac7ddfbfSEd Maste Process *process = m_exe_ctx.GetProcessPtr();
854435933ddSDimitry Andric if (process == nullptr) {
855ac7ddfbfSEd Maste result.AppendError("no process exists. Cannot continue");
856ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
857ac7ddfbfSEd Maste return false;
858ac7ddfbfSEd Maste }
859ac7ddfbfSEd Maste
860ac7ddfbfSEd Maste StateType state = process->GetState();
861435933ddSDimitry Andric if ((state == eStateCrashed) || (state == eStateStopped) ||
862435933ddSDimitry Andric (state == eStateSuspended)) {
863ac7ddfbfSEd Maste const size_t argc = command.GetArgumentCount();
864435933ddSDimitry Andric if (argc > 0) {
8654ba319b5SDimitry Andric // These two lines appear at the beginning of both blocks in this
8664ba319b5SDimitry Andric // if..else, but that is because we need to release the lock before
8674ba319b5SDimitry Andric // calling process->Resume below.
868435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
869435933ddSDimitry Andric process->GetThreadList().GetMutex());
87035617911SEd Maste const uint32_t num_threads = process->GetThreadList().GetSize();
871ac7ddfbfSEd Maste std::vector<Thread *> resume_threads;
872435933ddSDimitry Andric for (auto &entry : command.entries()) {
873435933ddSDimitry Andric uint32_t thread_idx;
874435933ddSDimitry Andric if (entry.ref.getAsInteger(0, thread_idx)) {
875435933ddSDimitry Andric result.AppendErrorWithFormat(
876435933ddSDimitry Andric "invalid thread index argument: \"%s\".\n", entry.c_str());
877435933ddSDimitry Andric result.SetStatus(eReturnStatusFailed);
878435933ddSDimitry Andric return false;
879435933ddSDimitry Andric }
880435933ddSDimitry Andric Thread *thread =
881435933ddSDimitry Andric process->GetThreadList().FindThreadByIndexID(thread_idx).get();
882ac7ddfbfSEd Maste
883435933ddSDimitry Andric if (thread) {
884ac7ddfbfSEd Maste resume_threads.push_back(thread);
885435933ddSDimitry Andric } else {
886435933ddSDimitry Andric result.AppendErrorWithFormat("invalid thread index %u.\n",
887435933ddSDimitry Andric thread_idx);
888ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
889ac7ddfbfSEd Maste return false;
890ac7ddfbfSEd Maste }
891ac7ddfbfSEd Maste }
892ac7ddfbfSEd Maste
893435933ddSDimitry Andric if (resume_threads.empty()) {
894ac7ddfbfSEd Maste result.AppendError("no valid thread indexes were specified");
895ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
896ac7ddfbfSEd Maste return false;
897435933ddSDimitry Andric } else {
898ac7ddfbfSEd Maste if (resume_threads.size() == 1)
899ac7ddfbfSEd Maste result.AppendMessageWithFormat("Resuming thread: ");
900ac7ddfbfSEd Maste else
901ac7ddfbfSEd Maste result.AppendMessageWithFormat("Resuming threads: ");
902ac7ddfbfSEd Maste
903435933ddSDimitry Andric for (uint32_t idx = 0; idx < num_threads; ++idx) {
904435933ddSDimitry Andric Thread *thread =
905435933ddSDimitry Andric process->GetThreadList().GetThreadAtIndex(idx).get();
906435933ddSDimitry Andric std::vector<Thread *>::iterator this_thread_pos =
907435933ddSDimitry Andric find(resume_threads.begin(), resume_threads.end(), thread);
908ac7ddfbfSEd Maste
909435933ddSDimitry Andric if (this_thread_pos != resume_threads.end()) {
910ac7ddfbfSEd Maste resume_threads.erase(this_thread_pos);
9114bb0738eSEd Maste if (!resume_threads.empty())
912ac7ddfbfSEd Maste result.AppendMessageWithFormat("%u, ", thread->GetIndexID());
913ac7ddfbfSEd Maste else
914ac7ddfbfSEd Maste result.AppendMessageWithFormat("%u ", thread->GetIndexID());
915ac7ddfbfSEd Maste
9160127ef0fSEd Maste const bool override_suspend = true;
9170127ef0fSEd Maste thread->SetResumeState(eStateRunning, override_suspend);
918435933ddSDimitry Andric } else {
919ac7ddfbfSEd Maste thread->SetResumeState(eStateSuspended);
920ac7ddfbfSEd Maste }
921ac7ddfbfSEd Maste }
922435933ddSDimitry Andric result.AppendMessageWithFormat("in process %" PRIu64 "\n",
923435933ddSDimitry Andric process->GetID());
924ac7ddfbfSEd Maste }
925435933ddSDimitry Andric } else {
9264ba319b5SDimitry Andric // These two lines appear at the beginning of both blocks in this
9274ba319b5SDimitry Andric // if..else, but that is because we need to release the lock before
9284ba319b5SDimitry Andric // calling process->Resume below.
929435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
930435933ddSDimitry Andric process->GetThreadList().GetMutex());
93135617911SEd Maste const uint32_t num_threads = process->GetThreadList().GetSize();
9324bb0738eSEd Maste Thread *current_thread = GetDefaultThread();
933435933ddSDimitry Andric if (current_thread == nullptr) {
934ac7ddfbfSEd Maste result.AppendError("the process doesn't have a current thread");
935ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
936ac7ddfbfSEd Maste return false;
937ac7ddfbfSEd Maste }
938ac7ddfbfSEd Maste // Set the actions that the threads should each take when resuming
939435933ddSDimitry Andric for (uint32_t idx = 0; idx < num_threads; ++idx) {
940ac7ddfbfSEd Maste Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
941435933ddSDimitry Andric if (thread == current_thread) {
942435933ddSDimitry Andric result.AppendMessageWithFormat("Resuming thread 0x%4.4" PRIx64
943435933ddSDimitry Andric " in process %" PRIu64 "\n",
944435933ddSDimitry Andric thread->GetID(), process->GetID());
9450127ef0fSEd Maste const bool override_suspend = true;
9460127ef0fSEd Maste thread->SetResumeState(eStateRunning, override_suspend);
947435933ddSDimitry Andric } else {
948ac7ddfbfSEd Maste thread->SetResumeState(eStateSuspended);
949ac7ddfbfSEd Maste }
950ac7ddfbfSEd Maste }
951ac7ddfbfSEd Maste }
952ac7ddfbfSEd Maste
9537aa51b79SEd Maste StreamString stream;
9545517e702SDimitry Andric Status error;
9557aa51b79SEd Maste if (synchronous_execution)
9567aa51b79SEd Maste error = process->ResumeSynchronous(&stream);
9577aa51b79SEd Maste else
9587aa51b79SEd Maste error = process->Resume();
9597aa51b79SEd Maste
96035617911SEd Maste // We should not be holding the thread list lock when we do this.
961435933ddSDimitry Andric if (error.Success()) {
962435933ddSDimitry Andric result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
963435933ddSDimitry Andric process->GetID());
964435933ddSDimitry Andric if (synchronous_execution) {
965435933ddSDimitry Andric // If any state changed events had anything to say, add that to the
966435933ddSDimitry Andric // result
967435933ddSDimitry Andric if (stream.GetSize() > 0)
968435933ddSDimitry Andric result.AppendMessage(stream.GetString());
969ac7ddfbfSEd Maste
970ac7ddfbfSEd Maste result.SetDidChangeProcessState(true);
971ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
972435933ddSDimitry Andric } else {
973ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessContinuingNoResult);
974ac7ddfbfSEd Maste }
975435933ddSDimitry Andric } else {
976435933ddSDimitry Andric result.AppendErrorWithFormat("Failed to resume process: %s\n",
977435933ddSDimitry Andric error.AsCString());
978ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
979ac7ddfbfSEd Maste }
980435933ddSDimitry Andric } else {
981435933ddSDimitry Andric result.AppendErrorWithFormat(
982435933ddSDimitry Andric "Process cannot be continued from its current state (%s).\n",
983ac7ddfbfSEd Maste StateAsCString(state));
984ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
985ac7ddfbfSEd Maste }
986ac7ddfbfSEd Maste
987ac7ddfbfSEd Maste return result.Succeeded();
988ac7ddfbfSEd Maste }
989ac7ddfbfSEd Maste };
990ac7ddfbfSEd Maste
991ac7ddfbfSEd Maste //-------------------------------------------------------------------------
992ac7ddfbfSEd Maste // CommandObjectThreadUntil
993ac7ddfbfSEd Maste //-------------------------------------------------------------------------
994ac7ddfbfSEd Maste
995*b5893f02SDimitry Andric static constexpr OptionEnumValueElement g_duo_running_mode[] = {
996*b5893f02SDimitry Andric {eOnlyThisThread, "this-thread", "Run only this thread"},
997*b5893f02SDimitry Andric {eAllThreads, "all-threads", "Run all threads"} };
998*b5893f02SDimitry Andric
DuoRunningModes()999*b5893f02SDimitry Andric static constexpr OptionEnumValues DuoRunningModes() {
1000*b5893f02SDimitry Andric return OptionEnumValues(g_duo_running_mode);
1001*b5893f02SDimitry Andric }
1002*b5893f02SDimitry Andric
1003*b5893f02SDimitry Andric static constexpr OptionDefinition g_thread_until_options[] = {
1004435933ddSDimitry Andric // clang-format off
1005*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "frame", 'f', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeFrameIndex, "Frame index for until operation - defaults to 0" },
1006*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "thread", 't', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeThreadIndex, "Thread index for the thread for until operation" },
1007*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "run-mode",'m', OptionParser::eRequiredArgument, nullptr, DuoRunningModes(), 0, eArgTypeRunMode, "Determine how to run other threads while stepping this one" },
1008*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "address", 'a', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeAddressOrExpression, "Run until we reach the specified address, or leave the function - can be specified multiple times." }
1009435933ddSDimitry Andric // clang-format on
1010435933ddSDimitry Andric };
1011435933ddSDimitry Andric
1012435933ddSDimitry Andric class CommandObjectThreadUntil : public CommandObjectParsed {
1013ac7ddfbfSEd Maste public:
1014435933ddSDimitry Andric class CommandOptions : public Options {
1015ac7ddfbfSEd Maste public:
1016ac7ddfbfSEd Maste uint32_t m_thread_idx;
1017ac7ddfbfSEd Maste uint32_t m_frame_idx;
1018ac7ddfbfSEd Maste
CommandOptions()1019435933ddSDimitry Andric CommandOptions()
1020435933ddSDimitry Andric : Options(), m_thread_idx(LLDB_INVALID_THREAD_ID),
1021435933ddSDimitry Andric m_frame_idx(LLDB_INVALID_FRAME_ID) {
1022435933ddSDimitry Andric // Keep default values of all options in one place: OptionParsingStarting
1023435933ddSDimitry Andric // ()
1024435933ddSDimitry Andric OptionParsingStarting(nullptr);
1025ac7ddfbfSEd Maste }
1026ac7ddfbfSEd Maste
10274bb0738eSEd Maste ~CommandOptions() override = default;
1028ac7ddfbfSEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)10295517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1030435933ddSDimitry Andric ExecutionContext *execution_context) override {
10315517e702SDimitry Andric Status error;
1032ac7ddfbfSEd Maste const int short_option = m_getopt_table[option_idx].val;
1033ac7ddfbfSEd Maste
1034435933ddSDimitry Andric switch (short_option) {
1035435933ddSDimitry Andric case 'a': {
10364ba319b5SDimitry Andric lldb::addr_t tmp_addr = OptionArgParser::ToAddress(
1037435933ddSDimitry Andric execution_context, option_arg, LLDB_INVALID_ADDRESS, &error);
10381c3bbb01SEd Maste if (error.Success())
10391c3bbb01SEd Maste m_until_addrs.push_back(tmp_addr);
1040435933ddSDimitry Andric } break;
1041ac7ddfbfSEd Maste case 't':
1042435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_thread_idx)) {
1043435933ddSDimitry Andric m_thread_idx = LLDB_INVALID_INDEX32;
1044435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid thread index '%s'",
1045435933ddSDimitry Andric option_arg.str().c_str());
1046ac7ddfbfSEd Maste }
1047ac7ddfbfSEd Maste break;
1048ac7ddfbfSEd Maste case 'f':
1049435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_frame_idx)) {
1050435933ddSDimitry Andric m_frame_idx = LLDB_INVALID_FRAME_ID;
1051435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid frame index '%s'",
1052435933ddSDimitry Andric option_arg.str().c_str());
1053ac7ddfbfSEd Maste }
1054ac7ddfbfSEd Maste break;
1055435933ddSDimitry Andric case 'm': {
1056*b5893f02SDimitry Andric auto enum_values = GetDefinitions()[option_idx].enum_values;
10574ba319b5SDimitry Andric lldb::RunMode run_mode = (lldb::RunMode)OptionArgParser::ToOptionEnum(
1058435933ddSDimitry Andric option_arg, enum_values, eOnlyDuringStepping, error);
1059ac7ddfbfSEd Maste
1060435933ddSDimitry Andric if (error.Success()) {
1061ac7ddfbfSEd Maste if (run_mode == eAllThreads)
1062ac7ddfbfSEd Maste m_stop_others = false;
1063ac7ddfbfSEd Maste else
1064ac7ddfbfSEd Maste m_stop_others = true;
1065ac7ddfbfSEd Maste }
1066435933ddSDimitry Andric } break;
1067ac7ddfbfSEd Maste default:
1068435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid short option character '%c'",
1069435933ddSDimitry Andric short_option);
1070ac7ddfbfSEd Maste break;
1071ac7ddfbfSEd Maste }
1072ac7ddfbfSEd Maste return error;
1073ac7ddfbfSEd Maste }
1074ac7ddfbfSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)1075435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
1076ac7ddfbfSEd Maste m_thread_idx = LLDB_INVALID_THREAD_ID;
1077ac7ddfbfSEd Maste m_frame_idx = 0;
1078ac7ddfbfSEd Maste m_stop_others = false;
10791c3bbb01SEd Maste m_until_addrs.clear();
1080ac7ddfbfSEd Maste }
1081ac7ddfbfSEd Maste
GetDefinitions()1082435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1083435933ddSDimitry Andric return llvm::makeArrayRef(g_thread_until_options);
1084ac7ddfbfSEd Maste }
1085ac7ddfbfSEd Maste
1086ac7ddfbfSEd Maste uint32_t m_step_thread_idx;
1087ac7ddfbfSEd Maste bool m_stop_others;
10881c3bbb01SEd Maste std::vector<lldb::addr_t> m_until_addrs;
1089ac7ddfbfSEd Maste
1090ac7ddfbfSEd Maste // Instance variables to hold the values for command options.
1091ac7ddfbfSEd Maste };
1092ac7ddfbfSEd Maste
CommandObjectThreadUntil(CommandInterpreter & interpreter)10934bb0738eSEd Maste CommandObjectThreadUntil(CommandInterpreter &interpreter)
1094435933ddSDimitry Andric : CommandObjectParsed(
1095435933ddSDimitry Andric interpreter, "thread until",
1096435933ddSDimitry Andric "Continue until a line number or address is reached by the "
10974bb0738eSEd Maste "current or specified thread. Stops when returning from "
1098435933ddSDimitry Andric "the current function as a safety measure. "
1099435933ddSDimitry Andric "The target line number(s) are given as arguments, and if more than one"
1100435933ddSDimitry Andric " is provided, stepping will stop when the first one is hit.",
1101435933ddSDimitry Andric nullptr,
1102435933ddSDimitry Andric eCommandRequiresThread | eCommandTryTargetAPILock |
11034bb0738eSEd Maste eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
1104435933ddSDimitry Andric m_options() {
1105ac7ddfbfSEd Maste CommandArgumentEntry arg;
1106ac7ddfbfSEd Maste CommandArgumentData line_num_arg;
1107ac7ddfbfSEd Maste
1108ac7ddfbfSEd Maste // Define the first (and only) variant of this arg.
1109ac7ddfbfSEd Maste line_num_arg.arg_type = eArgTypeLineNum;
1110ac7ddfbfSEd Maste line_num_arg.arg_repetition = eArgRepeatPlain;
1111ac7ddfbfSEd Maste
1112435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
1113435933ddSDimitry Andric // argument entry.
1114ac7ddfbfSEd Maste arg.push_back(line_num_arg);
1115ac7ddfbfSEd Maste
1116ac7ddfbfSEd Maste // Push the data for the first argument into the m_arguments vector.
1117ac7ddfbfSEd Maste m_arguments.push_back(arg);
1118ac7ddfbfSEd Maste }
1119ac7ddfbfSEd Maste
11204bb0738eSEd Maste ~CommandObjectThreadUntil() override = default;
1121ac7ddfbfSEd Maste
GetOptions()1122435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
1123ac7ddfbfSEd Maste
1124ac7ddfbfSEd Maste protected:
DoExecute(Args & command,CommandReturnObject & result)1125435933ddSDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
1126ac7ddfbfSEd Maste bool synchronous_execution = m_interpreter.GetSynchronous();
1127ac7ddfbfSEd Maste
1128ac7ddfbfSEd Maste Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
1129435933ddSDimitry Andric if (target == nullptr) {
1130435933ddSDimitry Andric result.AppendError("invalid target, create a debug target using the "
1131435933ddSDimitry Andric "'target create' command");
1132ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1133ac7ddfbfSEd Maste return false;
1134ac7ddfbfSEd Maste }
1135ac7ddfbfSEd Maste
1136ac7ddfbfSEd Maste Process *process = m_exe_ctx.GetProcessPtr();
1137435933ddSDimitry Andric if (process == nullptr) {
1138ac7ddfbfSEd Maste result.AppendError("need a valid process to step");
1139ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1140435933ddSDimitry Andric } else {
11414bb0738eSEd Maste Thread *thread = nullptr;
11421c3bbb01SEd Maste std::vector<uint32_t> line_numbers;
1143ac7ddfbfSEd Maste
1144435933ddSDimitry Andric if (command.GetArgumentCount() >= 1) {
11451c3bbb01SEd Maste size_t num_args = command.GetArgumentCount();
1146435933ddSDimitry Andric for (size_t i = 0; i < num_args; i++) {
11471c3bbb01SEd Maste uint32_t line_number;
1148435933ddSDimitry Andric line_number = StringConvert::ToUInt32(command.GetArgumentAtIndex(i),
1149435933ddSDimitry Andric UINT32_MAX);
1150435933ddSDimitry Andric if (line_number == UINT32_MAX) {
1151435933ddSDimitry Andric result.AppendErrorWithFormat("invalid line number: '%s'.\n",
1152435933ddSDimitry Andric command.GetArgumentAtIndex(i));
1153ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1154ac7ddfbfSEd Maste return false;
1155435933ddSDimitry Andric } else
11561c3bbb01SEd Maste line_numbers.push_back(line_number);
11571c3bbb01SEd Maste }
1158435933ddSDimitry Andric } else if (m_options.m_until_addrs.empty()) {
1159435933ddSDimitry Andric result.AppendErrorWithFormat("No line number or address provided:\n%s",
1160435933ddSDimitry Andric GetSyntax().str().c_str());
11611c3bbb01SEd Maste result.SetStatus(eReturnStatusFailed);
11621c3bbb01SEd Maste return false;
11631c3bbb01SEd Maste }
11641c3bbb01SEd Maste
1165435933ddSDimitry Andric if (m_options.m_thread_idx == LLDB_INVALID_THREAD_ID) {
11664bb0738eSEd Maste thread = GetDefaultThread();
1167435933ddSDimitry Andric } else {
1168435933ddSDimitry Andric thread = process->GetThreadList()
1169435933ddSDimitry Andric .FindThreadByIndexID(m_options.m_thread_idx)
1170435933ddSDimitry Andric .get();
1171ac7ddfbfSEd Maste }
1172ac7ddfbfSEd Maste
1173435933ddSDimitry Andric if (thread == nullptr) {
1174ac7ddfbfSEd Maste const uint32_t num_threads = process->GetThreadList().GetSize();
1175435933ddSDimitry Andric result.AppendErrorWithFormat(
1176435933ddSDimitry Andric "Thread index %u is out of range (valid values are 0 - %u).\n",
1177435933ddSDimitry Andric m_options.m_thread_idx, num_threads);
1178ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1179ac7ddfbfSEd Maste return false;
1180ac7ddfbfSEd Maste }
1181ac7ddfbfSEd Maste
1182ac7ddfbfSEd Maste const bool abort_other_plans = false;
1183ac7ddfbfSEd Maste
1184435933ddSDimitry Andric StackFrame *frame =
1185435933ddSDimitry Andric thread->GetStackFrameAtIndex(m_options.m_frame_idx).get();
1186435933ddSDimitry Andric if (frame == nullptr) {
1187435933ddSDimitry Andric result.AppendErrorWithFormat(
1188435933ddSDimitry Andric "Frame index %u is out of range for thread %u.\n",
1189435933ddSDimitry Andric m_options.m_frame_idx, m_options.m_thread_idx);
1190ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1191ac7ddfbfSEd Maste return false;
1192ac7ddfbfSEd Maste }
1193ac7ddfbfSEd Maste
1194ac7ddfbfSEd Maste ThreadPlanSP new_plan_sp;
1195*b5893f02SDimitry Andric Status new_plan_status;
1196ac7ddfbfSEd Maste
1197435933ddSDimitry Andric if (frame->HasDebugInformation()) {
11984ba319b5SDimitry Andric // Finally we got here... Translate the given line number to a bunch
11994ba319b5SDimitry Andric // of addresses:
1200ac7ddfbfSEd Maste SymbolContext sc(frame->GetSymbolContext(eSymbolContextCompUnit));
12014bb0738eSEd Maste LineTable *line_table = nullptr;
1202ac7ddfbfSEd Maste if (sc.comp_unit)
1203ac7ddfbfSEd Maste line_table = sc.comp_unit->GetLineTable();
1204ac7ddfbfSEd Maste
1205435933ddSDimitry Andric if (line_table == nullptr) {
1206435933ddSDimitry Andric result.AppendErrorWithFormat("Failed to resolve the line table for "
1207435933ddSDimitry Andric "frame %u of thread index %u.\n",
1208435933ddSDimitry Andric m_options.m_frame_idx,
1209435933ddSDimitry Andric m_options.m_thread_idx);
1210ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1211ac7ddfbfSEd Maste return false;
1212ac7ddfbfSEd Maste }
1213ac7ddfbfSEd Maste
1214ac7ddfbfSEd Maste LineEntry function_start;
1215ac7ddfbfSEd Maste uint32_t index_ptr = 0, end_ptr;
1216ac7ddfbfSEd Maste std::vector<addr_t> address_list;
1217ac7ddfbfSEd Maste
1218ac7ddfbfSEd Maste // Find the beginning & end index of the
1219ac7ddfbfSEd Maste AddressRange fun_addr_range = sc.function->GetAddressRange();
1220ac7ddfbfSEd Maste Address fun_start_addr = fun_addr_range.GetBaseAddress();
1221435933ddSDimitry Andric line_table->FindLineEntryByAddress(fun_start_addr, function_start,
1222435933ddSDimitry Andric &index_ptr);
1223ac7ddfbfSEd Maste
1224ac7ddfbfSEd Maste Address fun_end_addr(fun_start_addr.GetSection(),
1225435933ddSDimitry Andric fun_start_addr.GetOffset() +
1226435933ddSDimitry Andric fun_addr_range.GetByteSize());
1227ac7ddfbfSEd Maste
1228ac7ddfbfSEd Maste bool all_in_function = true;
1229ac7ddfbfSEd Maste
1230435933ddSDimitry Andric line_table->FindLineEntryByAddress(fun_end_addr, function_start,
1231435933ddSDimitry Andric &end_ptr);
12321c3bbb01SEd Maste
1233435933ddSDimitry Andric for (uint32_t line_number : line_numbers) {
12341c3bbb01SEd Maste uint32_t start_idx_ptr = index_ptr;
1235435933ddSDimitry Andric while (start_idx_ptr <= end_ptr) {
1236ac7ddfbfSEd Maste LineEntry line_entry;
1237ac7ddfbfSEd Maste const bool exact = false;
1238435933ddSDimitry Andric start_idx_ptr = sc.comp_unit->FindLineEntry(
1239435933ddSDimitry Andric start_idx_ptr, line_number, sc.comp_unit, exact, &line_entry);
12401c3bbb01SEd Maste if (start_idx_ptr == UINT32_MAX)
1241ac7ddfbfSEd Maste break;
1242ac7ddfbfSEd Maste
1243435933ddSDimitry Andric addr_t address =
1244435933ddSDimitry Andric line_entry.range.GetBaseAddress().GetLoadAddress(target);
1245435933ddSDimitry Andric if (address != LLDB_INVALID_ADDRESS) {
1246ac7ddfbfSEd Maste if (fun_addr_range.ContainsLoadAddress(address, target))
1247ac7ddfbfSEd Maste address_list.push_back(address);
1248ac7ddfbfSEd Maste else
1249ac7ddfbfSEd Maste all_in_function = false;
1250ac7ddfbfSEd Maste }
12511c3bbb01SEd Maste start_idx_ptr++;
12521c3bbb01SEd Maste }
12531c3bbb01SEd Maste }
12541c3bbb01SEd Maste
1255435933ddSDimitry Andric for (lldb::addr_t address : m_options.m_until_addrs) {
12561c3bbb01SEd Maste if (fun_addr_range.ContainsLoadAddress(address, target))
12571c3bbb01SEd Maste address_list.push_back(address);
12581c3bbb01SEd Maste else
12591c3bbb01SEd Maste all_in_function = false;
1260ac7ddfbfSEd Maste }
1261ac7ddfbfSEd Maste
1262435933ddSDimitry Andric if (address_list.empty()) {
1263ac7ddfbfSEd Maste if (all_in_function)
1264435933ddSDimitry Andric result.AppendErrorWithFormat(
1265435933ddSDimitry Andric "No line entries matching until target.\n");
1266ac7ddfbfSEd Maste else
1267435933ddSDimitry Andric result.AppendErrorWithFormat(
1268435933ddSDimitry Andric "Until target outside of the current function.\n");
1269ac7ddfbfSEd Maste
1270ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1271ac7ddfbfSEd Maste return false;
1272ac7ddfbfSEd Maste }
1273ac7ddfbfSEd Maste
1274435933ddSDimitry Andric new_plan_sp = thread->QueueThreadPlanForStepUntil(
1275435933ddSDimitry Andric abort_other_plans, &address_list.front(), address_list.size(),
1276*b5893f02SDimitry Andric m_options.m_stop_others, m_options.m_frame_idx, new_plan_status);
1277*b5893f02SDimitry Andric if (new_plan_sp) {
1278435933ddSDimitry Andric // User level plans should be master plans so they can be interrupted
1279*b5893f02SDimitry Andric // (e.g. by hitting a breakpoint) and other plans executed by the
1280*b5893f02SDimitry Andric // user (stepping around the breakpoint) and then a "continue" will
1281*b5893f02SDimitry Andric // resume the original plan.
1282ac7ddfbfSEd Maste new_plan_sp->SetIsMasterPlan(true);
1283ac7ddfbfSEd Maste new_plan_sp->SetOkayToDiscard(false);
1284435933ddSDimitry Andric } else {
1285*b5893f02SDimitry Andric result.SetError(new_plan_status);
1286*b5893f02SDimitry Andric result.SetStatus(eReturnStatusFailed);
1287*b5893f02SDimitry Andric return false;
1288*b5893f02SDimitry Andric }
1289*b5893f02SDimitry Andric } else {
1290435933ddSDimitry Andric result.AppendErrorWithFormat(
1291435933ddSDimitry Andric "Frame index %u of thread %u has no debug information.\n",
1292435933ddSDimitry Andric m_options.m_frame_idx, m_options.m_thread_idx);
1293ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1294ac7ddfbfSEd Maste return false;
1295ac7ddfbfSEd Maste }
1296ac7ddfbfSEd Maste
1297ac7ddfbfSEd Maste process->GetThreadList().SetSelectedThreadByID(m_options.m_thread_idx);
12987aa51b79SEd Maste
12997aa51b79SEd Maste StreamString stream;
13005517e702SDimitry Andric Status error;
13017aa51b79SEd Maste if (synchronous_execution)
13027aa51b79SEd Maste error = process->ResumeSynchronous(&stream);
13037aa51b79SEd Maste else
13047aa51b79SEd Maste error = process->Resume();
13057aa51b79SEd Maste
1306435933ddSDimitry Andric if (error.Success()) {
1307435933ddSDimitry Andric result.AppendMessageWithFormat("Process %" PRIu64 " resuming\n",
1308435933ddSDimitry Andric process->GetID());
1309435933ddSDimitry Andric if (synchronous_execution) {
1310435933ddSDimitry Andric // If any state changed events had anything to say, add that to the
1311435933ddSDimitry Andric // result
1312435933ddSDimitry Andric if (stream.GetSize() > 0)
1313435933ddSDimitry Andric result.AppendMessage(stream.GetString());
1314ac7ddfbfSEd Maste
1315ac7ddfbfSEd Maste result.SetDidChangeProcessState(true);
1316ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
1317435933ddSDimitry Andric } else {
1318ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessContinuingNoResult);
1319ac7ddfbfSEd Maste }
1320435933ddSDimitry Andric } else {
1321435933ddSDimitry Andric result.AppendErrorWithFormat("Failed to resume process: %s.\n",
1322435933ddSDimitry Andric error.AsCString());
1323ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1324ac7ddfbfSEd Maste }
1325ac7ddfbfSEd Maste }
1326ac7ddfbfSEd Maste return result.Succeeded();
1327ac7ddfbfSEd Maste }
1328ac7ddfbfSEd Maste
1329ac7ddfbfSEd Maste CommandOptions m_options;
1330ac7ddfbfSEd Maste };
1331ac7ddfbfSEd Maste
1332ac7ddfbfSEd Maste //-------------------------------------------------------------------------
1333ac7ddfbfSEd Maste // CommandObjectThreadSelect
1334ac7ddfbfSEd Maste //-------------------------------------------------------------------------
1335ac7ddfbfSEd Maste
1336435933ddSDimitry Andric class CommandObjectThreadSelect : public CommandObjectParsed {
1337ac7ddfbfSEd Maste public:
CommandObjectThreadSelect(CommandInterpreter & interpreter)13384bb0738eSEd Maste CommandObjectThreadSelect(CommandInterpreter &interpreter)
1339435933ddSDimitry Andric : CommandObjectParsed(interpreter, "thread select",
1340435933ddSDimitry Andric "Change the currently selected thread.", nullptr,
1341435933ddSDimitry Andric eCommandRequiresProcess | eCommandTryTargetAPILock |
1342435933ddSDimitry Andric eCommandProcessMustBeLaunched |
1343435933ddSDimitry Andric eCommandProcessMustBePaused) {
1344ac7ddfbfSEd Maste CommandArgumentEntry arg;
1345ac7ddfbfSEd Maste CommandArgumentData thread_idx_arg;
1346ac7ddfbfSEd Maste
1347ac7ddfbfSEd Maste // Define the first (and only) variant of this arg.
1348ac7ddfbfSEd Maste thread_idx_arg.arg_type = eArgTypeThreadIndex;
1349ac7ddfbfSEd Maste thread_idx_arg.arg_repetition = eArgRepeatPlain;
1350ac7ddfbfSEd Maste
1351435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
1352435933ddSDimitry Andric // argument entry.
1353ac7ddfbfSEd Maste arg.push_back(thread_idx_arg);
1354ac7ddfbfSEd Maste
1355ac7ddfbfSEd Maste // Push the data for the first argument into the m_arguments vector.
1356ac7ddfbfSEd Maste m_arguments.push_back(arg);
1357ac7ddfbfSEd Maste }
1358ac7ddfbfSEd Maste
13594bb0738eSEd Maste ~CommandObjectThreadSelect() override = default;
1360ac7ddfbfSEd Maste
1361ac7ddfbfSEd Maste protected:
DoExecute(Args & command,CommandReturnObject & result)1362435933ddSDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
1363ac7ddfbfSEd Maste Process *process = m_exe_ctx.GetProcessPtr();
1364435933ddSDimitry Andric if (process == nullptr) {
1365ac7ddfbfSEd Maste result.AppendError("no process");
1366ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1367ac7ddfbfSEd Maste return false;
1368435933ddSDimitry Andric } else if (command.GetArgumentCount() != 1) {
1369435933ddSDimitry Andric result.AppendErrorWithFormat(
1370435933ddSDimitry Andric "'%s' takes exactly one thread index argument:\nUsage: %s\n",
1371435933ddSDimitry Andric m_cmd_name.c_str(), m_cmd_syntax.c_str());
1372ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1373ac7ddfbfSEd Maste return false;
1374ac7ddfbfSEd Maste }
1375ac7ddfbfSEd Maste
1376435933ddSDimitry Andric uint32_t index_id =
1377435933ddSDimitry Andric StringConvert::ToUInt32(command.GetArgumentAtIndex(0), 0, 0);
1378ac7ddfbfSEd Maste
1379435933ddSDimitry Andric Thread *new_thread =
1380435933ddSDimitry Andric process->GetThreadList().FindThreadByIndexID(index_id).get();
1381435933ddSDimitry Andric if (new_thread == nullptr) {
1382435933ddSDimitry Andric result.AppendErrorWithFormat("invalid thread #%s.\n",
1383435933ddSDimitry Andric command.GetArgumentAtIndex(0));
1384ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1385ac7ddfbfSEd Maste return false;
1386ac7ddfbfSEd Maste }
1387ac7ddfbfSEd Maste
1388ac7ddfbfSEd Maste process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true);
1389ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
1390ac7ddfbfSEd Maste
1391ac7ddfbfSEd Maste return result.Succeeded();
1392ac7ddfbfSEd Maste }
1393ac7ddfbfSEd Maste };
1394ac7ddfbfSEd Maste
1395ac7ddfbfSEd Maste //-------------------------------------------------------------------------
1396ac7ddfbfSEd Maste // CommandObjectThreadList
1397ac7ddfbfSEd Maste //-------------------------------------------------------------------------
1398ac7ddfbfSEd Maste
1399435933ddSDimitry Andric class CommandObjectThreadList : public CommandObjectParsed {
1400ac7ddfbfSEd Maste public:
CommandObjectThreadList(CommandInterpreter & interpreter)14014bb0738eSEd Maste CommandObjectThreadList(CommandInterpreter &interpreter)
1402435933ddSDimitry Andric : CommandObjectParsed(
1403435933ddSDimitry Andric interpreter, "thread list",
1404435933ddSDimitry Andric "Show a summary of each thread in the current target process.",
1405435933ddSDimitry Andric "thread list",
1406435933ddSDimitry Andric eCommandRequiresProcess | eCommandTryTargetAPILock |
1407435933ddSDimitry Andric eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1408ac7ddfbfSEd Maste
14094bb0738eSEd Maste ~CommandObjectThreadList() override = default;
1410ac7ddfbfSEd Maste
1411ac7ddfbfSEd Maste protected:
DoExecute(Args & command,CommandReturnObject & result)1412435933ddSDimitry Andric bool DoExecute(Args &command, CommandReturnObject &result) override {
1413ac7ddfbfSEd Maste Stream &strm = result.GetOutputStream();
1414ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
1415ac7ddfbfSEd Maste Process *process = m_exe_ctx.GetProcessPtr();
1416ac7ddfbfSEd Maste const bool only_threads_with_stop_reason = false;
1417ac7ddfbfSEd Maste const uint32_t start_frame = 0;
1418ac7ddfbfSEd Maste const uint32_t num_frames = 0;
1419ac7ddfbfSEd Maste const uint32_t num_frames_with_source = 0;
1420ac7ddfbfSEd Maste process->GetStatus(strm);
1421435933ddSDimitry Andric process->GetThreadStatus(strm, only_threads_with_stop_reason, start_frame,
1422435933ddSDimitry Andric num_frames, num_frames_with_source, false);
1423ac7ddfbfSEd Maste return result.Succeeded();
1424ac7ddfbfSEd Maste }
1425ac7ddfbfSEd Maste };
1426ac7ddfbfSEd Maste
1427ac7ddfbfSEd Maste //-------------------------------------------------------------------------
14280127ef0fSEd Maste // CommandObjectThreadInfo
14290127ef0fSEd Maste //-------------------------------------------------------------------------
14300127ef0fSEd Maste
1431*b5893f02SDimitry Andric static constexpr OptionDefinition g_thread_info_options[] = {
1432435933ddSDimitry Andric // clang-format off
1433*b5893f02SDimitry Andric { LLDB_OPT_SET_ALL, false, "json", 'j', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Display the thread info in JSON format." },
1434*b5893f02SDimitry Andric { LLDB_OPT_SET_ALL, false, "stop-info", 's', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Display the extended stop info in JSON format." }
1435435933ddSDimitry Andric // clang-format on
1436435933ddSDimitry Andric };
1437435933ddSDimitry Andric
1438435933ddSDimitry Andric class CommandObjectThreadInfo : public CommandObjectIterateOverThreads {
14390127ef0fSEd Maste public:
1440435933ddSDimitry Andric class CommandOptions : public Options {
14410127ef0fSEd Maste public:
CommandOptions()1442435933ddSDimitry Andric CommandOptions() : Options() { OptionParsingStarting(nullptr); }
14430127ef0fSEd Maste
14444bb0738eSEd Maste ~CommandOptions() override = default;
14454bb0738eSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)1446435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
14477aa51b79SEd Maste m_json_thread = false;
14487aa51b79SEd Maste m_json_stopinfo = false;
14490127ef0fSEd Maste }
14500127ef0fSEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)14515517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1452435933ddSDimitry Andric ExecutionContext *execution_context) override {
14530127ef0fSEd Maste const int short_option = m_getopt_table[option_idx].val;
14545517e702SDimitry Andric Status error;
14550127ef0fSEd Maste
1456435933ddSDimitry Andric switch (short_option) {
14570127ef0fSEd Maste case 'j':
14587aa51b79SEd Maste m_json_thread = true;
14597aa51b79SEd Maste break;
14607aa51b79SEd Maste
14617aa51b79SEd Maste case 's':
14627aa51b79SEd Maste m_json_stopinfo = true;
14630127ef0fSEd Maste break;
14640127ef0fSEd Maste
14650127ef0fSEd Maste default:
14665517e702SDimitry Andric return Status("invalid short option character '%c'", short_option);
14670127ef0fSEd Maste }
14680127ef0fSEd Maste return error;
14690127ef0fSEd Maste }
14700127ef0fSEd Maste
GetDefinitions()1471435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1472435933ddSDimitry Andric return llvm::makeArrayRef(g_thread_info_options);
14730127ef0fSEd Maste }
14740127ef0fSEd Maste
14757aa51b79SEd Maste bool m_json_thread;
14767aa51b79SEd Maste bool m_json_stopinfo;
14770127ef0fSEd Maste };
14780127ef0fSEd Maste
CommandObjectThreadInfo(CommandInterpreter & interpreter)14794bb0738eSEd Maste CommandObjectThreadInfo(CommandInterpreter &interpreter)
14804bb0738eSEd Maste : CommandObjectIterateOverThreads(
1481435933ddSDimitry Andric interpreter, "thread info", "Show an extended summary of one or "
1482435933ddSDimitry Andric "more threads. Defaults to the "
1483435933ddSDimitry Andric "current thread.",
1484435933ddSDimitry Andric "thread info",
1485435933ddSDimitry Andric eCommandRequiresProcess | eCommandTryTargetAPILock |
1486435933ddSDimitry Andric eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
1487435933ddSDimitry Andric m_options() {
14884bb0738eSEd Maste m_add_return = false;
14894bb0738eSEd Maste }
14904bb0738eSEd Maste
14914bb0738eSEd Maste ~CommandObjectThreadInfo() override = default;
14924bb0738eSEd Maste
GetOptions()1493435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
14940127ef0fSEd Maste
HandleOneThread(lldb::tid_t tid,CommandReturnObject & result)1495435933ddSDimitry Andric bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
1496435933ddSDimitry Andric ThreadSP thread_sp =
1497435933ddSDimitry Andric m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1498435933ddSDimitry Andric if (!thread_sp) {
1499435933ddSDimitry Andric result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1500435933ddSDimitry Andric tid);
15014bb0738eSEd Maste result.SetStatus(eReturnStatusFailed);
15024bb0738eSEd Maste return false;
15030127ef0fSEd Maste }
15040127ef0fSEd Maste
15054bb0738eSEd Maste Thread *thread = thread_sp.get();
15064bb0738eSEd Maste
15070127ef0fSEd Maste Stream &strm = result.GetOutputStream();
1508435933ddSDimitry Andric if (!thread->GetDescription(strm, eDescriptionLevelFull,
1509435933ddSDimitry Andric m_options.m_json_thread,
1510435933ddSDimitry Andric m_options.m_json_stopinfo)) {
1511435933ddSDimitry Andric result.AppendErrorWithFormat("error displaying info for thread: \"%d\"\n",
1512435933ddSDimitry Andric thread->GetIndexID());
15130127ef0fSEd Maste result.SetStatus(eReturnStatusFailed);
15140127ef0fSEd Maste return false;
15150127ef0fSEd Maste }
15167aa51b79SEd Maste return true;
15170127ef0fSEd Maste }
15180127ef0fSEd Maste
15190127ef0fSEd Maste CommandOptions m_options;
15200127ef0fSEd Maste };
15210127ef0fSEd Maste
15220127ef0fSEd Maste //-------------------------------------------------------------------------
1523*b5893f02SDimitry Andric // CommandObjectThreadException
1524*b5893f02SDimitry Andric //-------------------------------------------------------------------------
1525*b5893f02SDimitry Andric
1526*b5893f02SDimitry Andric class CommandObjectThreadException : public CommandObjectIterateOverThreads {
1527*b5893f02SDimitry Andric public:
CommandObjectThreadException(CommandInterpreter & interpreter)1528*b5893f02SDimitry Andric CommandObjectThreadException(CommandInterpreter &interpreter)
1529*b5893f02SDimitry Andric : CommandObjectIterateOverThreads(
1530*b5893f02SDimitry Andric interpreter, "thread exception",
1531*b5893f02SDimitry Andric "Display the current exception object for a thread. Defaults to "
1532*b5893f02SDimitry Andric "the current thread.",
1533*b5893f02SDimitry Andric "thread exception",
1534*b5893f02SDimitry Andric eCommandRequiresProcess | eCommandTryTargetAPILock |
1535*b5893f02SDimitry Andric eCommandProcessMustBeLaunched | eCommandProcessMustBePaused) {}
1536*b5893f02SDimitry Andric
1537*b5893f02SDimitry Andric ~CommandObjectThreadException() override = default;
1538*b5893f02SDimitry Andric
HandleOneThread(lldb::tid_t tid,CommandReturnObject & result)1539*b5893f02SDimitry Andric bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
1540*b5893f02SDimitry Andric ThreadSP thread_sp =
1541*b5893f02SDimitry Andric m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1542*b5893f02SDimitry Andric if (!thread_sp) {
1543*b5893f02SDimitry Andric result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1544*b5893f02SDimitry Andric tid);
1545*b5893f02SDimitry Andric result.SetStatus(eReturnStatusFailed);
1546*b5893f02SDimitry Andric return false;
1547*b5893f02SDimitry Andric }
1548*b5893f02SDimitry Andric
1549*b5893f02SDimitry Andric Stream &strm = result.GetOutputStream();
1550*b5893f02SDimitry Andric ValueObjectSP exception_object_sp = thread_sp->GetCurrentException();
1551*b5893f02SDimitry Andric if (exception_object_sp) {
1552*b5893f02SDimitry Andric exception_object_sp->Dump(strm);
1553*b5893f02SDimitry Andric }
1554*b5893f02SDimitry Andric
1555*b5893f02SDimitry Andric ThreadSP exception_thread_sp = thread_sp->GetCurrentExceptionBacktrace();
1556*b5893f02SDimitry Andric if (exception_thread_sp && exception_thread_sp->IsValid()) {
1557*b5893f02SDimitry Andric const uint32_t num_frames_with_source = 0;
1558*b5893f02SDimitry Andric const bool stop_format = false;
1559*b5893f02SDimitry Andric exception_thread_sp->GetStatus(strm, 0, UINT32_MAX,
1560*b5893f02SDimitry Andric num_frames_with_source, stop_format);
1561*b5893f02SDimitry Andric }
1562*b5893f02SDimitry Andric
1563*b5893f02SDimitry Andric return true;
1564*b5893f02SDimitry Andric }
1565*b5893f02SDimitry Andric };
1566*b5893f02SDimitry Andric
1567*b5893f02SDimitry Andric //-------------------------------------------------------------------------
1568ac7ddfbfSEd Maste // CommandObjectThreadReturn
1569ac7ddfbfSEd Maste //-------------------------------------------------------------------------
1570ac7ddfbfSEd Maste
1571*b5893f02SDimitry Andric static constexpr OptionDefinition g_thread_return_options[] = {
1572435933ddSDimitry Andric // clang-format off
1573*b5893f02SDimitry Andric { LLDB_OPT_SET_ALL, false, "from-expression", 'x', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Return from the innermost expression evaluation." }
1574435933ddSDimitry Andric // clang-format on
1575435933ddSDimitry Andric };
1576435933ddSDimitry Andric
1577435933ddSDimitry Andric class CommandObjectThreadReturn : public CommandObjectRaw {
1578ac7ddfbfSEd Maste public:
1579435933ddSDimitry Andric class CommandOptions : public Options {
1580ac7ddfbfSEd Maste public:
CommandOptions()1581435933ddSDimitry Andric CommandOptions() : Options(), m_from_expression(false) {
1582435933ddSDimitry Andric // Keep default values of all options in one place: OptionParsingStarting
1583435933ddSDimitry Andric // ()
1584435933ddSDimitry Andric OptionParsingStarting(nullptr);
1585ac7ddfbfSEd Maste }
1586ac7ddfbfSEd Maste
15874bb0738eSEd Maste ~CommandOptions() override = default;
1588ac7ddfbfSEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)15895517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1590435933ddSDimitry Andric ExecutionContext *execution_context) override {
15915517e702SDimitry Andric Status error;
1592ac7ddfbfSEd Maste const int short_option = m_getopt_table[option_idx].val;
1593ac7ddfbfSEd Maste
1594435933ddSDimitry Andric switch (short_option) {
1595435933ddSDimitry Andric case 'x': {
1596ac7ddfbfSEd Maste bool success;
15974ba319b5SDimitry Andric bool tmp_value =
15984ba319b5SDimitry Andric OptionArgParser::ToBoolean(option_arg, false, &success);
1599ac7ddfbfSEd Maste if (success)
1600ac7ddfbfSEd Maste m_from_expression = tmp_value;
1601435933ddSDimitry Andric else {
1602435933ddSDimitry Andric error.SetErrorStringWithFormat(
1603435933ddSDimitry Andric "invalid boolean value '%s' for 'x' option",
1604435933ddSDimitry Andric option_arg.str().c_str());
1605ac7ddfbfSEd Maste }
1606435933ddSDimitry Andric } break;
1607ac7ddfbfSEd Maste default:
1608435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid short option character '%c'",
1609435933ddSDimitry Andric short_option);
1610ac7ddfbfSEd Maste break;
1611ac7ddfbfSEd Maste }
1612ac7ddfbfSEd Maste return error;
1613ac7ddfbfSEd Maste }
1614ac7ddfbfSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)1615435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
1616ac7ddfbfSEd Maste m_from_expression = false;
1617ac7ddfbfSEd Maste }
1618ac7ddfbfSEd Maste
GetDefinitions()1619435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1620435933ddSDimitry Andric return llvm::makeArrayRef(g_thread_return_options);
1621ac7ddfbfSEd Maste }
1622ac7ddfbfSEd Maste
1623ac7ddfbfSEd Maste bool m_from_expression;
1624ac7ddfbfSEd Maste
1625ac7ddfbfSEd Maste // Instance variables to hold the values for command options.
1626ac7ddfbfSEd Maste };
1627ac7ddfbfSEd Maste
CommandObjectThreadReturn(CommandInterpreter & interpreter)16284bb0738eSEd Maste CommandObjectThreadReturn(CommandInterpreter &interpreter)
16294bb0738eSEd Maste : CommandObjectRaw(interpreter, "thread return",
1630435933ddSDimitry Andric "Prematurely return from a stack frame, "
1631435933ddSDimitry Andric "short-circuiting execution of newer frames "
1632435933ddSDimitry Andric "and optionally yielding a specified value. Defaults "
1633435933ddSDimitry Andric "to the exiting the current stack "
16344bb0738eSEd Maste "frame.",
1635435933ddSDimitry Andric "thread return",
1636435933ddSDimitry Andric eCommandRequiresFrame | eCommandTryTargetAPILock |
1637435933ddSDimitry Andric eCommandProcessMustBeLaunched |
1638435933ddSDimitry Andric eCommandProcessMustBePaused),
1639435933ddSDimitry Andric m_options() {
1640ac7ddfbfSEd Maste CommandArgumentEntry arg;
1641ac7ddfbfSEd Maste CommandArgumentData expression_arg;
1642ac7ddfbfSEd Maste
1643ac7ddfbfSEd Maste // Define the first (and only) variant of this arg.
1644ac7ddfbfSEd Maste expression_arg.arg_type = eArgTypeExpression;
1645ac7ddfbfSEd Maste expression_arg.arg_repetition = eArgRepeatOptional;
1646ac7ddfbfSEd Maste
1647435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
1648435933ddSDimitry Andric // argument entry.
1649ac7ddfbfSEd Maste arg.push_back(expression_arg);
1650ac7ddfbfSEd Maste
1651ac7ddfbfSEd Maste // Push the data for the first argument into the m_arguments vector.
1652ac7ddfbfSEd Maste m_arguments.push_back(arg);
1653ac7ddfbfSEd Maste }
1654ac7ddfbfSEd Maste
16554bb0738eSEd Maste ~CommandObjectThreadReturn() override = default;
16564bb0738eSEd Maste
GetOptions()1657435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
1658ac7ddfbfSEd Maste
1659ac7ddfbfSEd Maste protected:
DoExecute(llvm::StringRef command,CommandReturnObject & result)16604ba319b5SDimitry Andric bool DoExecute(llvm::StringRef command,
16614ba319b5SDimitry Andric CommandReturnObject &result) override {
1662435933ddSDimitry Andric // I am going to handle this by hand, because I don't want you to have to
1663435933ddSDimitry Andric // say:
1664ac7ddfbfSEd Maste // "thread return -- -5".
16654ba319b5SDimitry Andric if (command.startswith("-x")) {
16664ba319b5SDimitry Andric if (command.size() != 2U)
1667435933ddSDimitry Andric result.AppendWarning("Return values ignored when returning from user "
1668435933ddSDimitry Andric "called expressions");
1669ac7ddfbfSEd Maste
1670ac7ddfbfSEd Maste Thread *thread = m_exe_ctx.GetThreadPtr();
16715517e702SDimitry Andric Status error;
1672ac7ddfbfSEd Maste error = thread->UnwindInnermostExpression();
1673435933ddSDimitry Andric if (!error.Success()) {
1674435933ddSDimitry Andric result.AppendErrorWithFormat("Unwinding expression failed - %s.",
1675435933ddSDimitry Andric error.AsCString());
1676ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1677435933ddSDimitry Andric } else {
1678435933ddSDimitry Andric bool success =
1679435933ddSDimitry Andric thread->SetSelectedFrameByIndexNoisily(0, result.GetOutputStream());
1680435933ddSDimitry Andric if (success) {
1681ac7ddfbfSEd Maste m_exe_ctx.SetFrameSP(thread->GetSelectedFrame());
1682ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
1683435933ddSDimitry Andric } else {
1684435933ddSDimitry Andric result.AppendErrorWithFormat(
1685435933ddSDimitry Andric "Could not select 0th frame after unwinding expression.");
1686ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1687ac7ddfbfSEd Maste }
1688ac7ddfbfSEd Maste }
1689ac7ddfbfSEd Maste return result.Succeeded();
1690ac7ddfbfSEd Maste }
1691ac7ddfbfSEd Maste
1692ac7ddfbfSEd Maste ValueObjectSP return_valobj_sp;
1693ac7ddfbfSEd Maste
1694ac7ddfbfSEd Maste StackFrameSP frame_sp = m_exe_ctx.GetFrameSP();
1695ac7ddfbfSEd Maste uint32_t frame_idx = frame_sp->GetFrameIndex();
1696ac7ddfbfSEd Maste
1697435933ddSDimitry Andric if (frame_sp->IsInlined()) {
1698ac7ddfbfSEd Maste result.AppendError("Don't know how to return from inlined frames.");
1699ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1700ac7ddfbfSEd Maste return false;
1701ac7ddfbfSEd Maste }
1702ac7ddfbfSEd Maste
17034ba319b5SDimitry Andric if (!command.empty()) {
1704ac7ddfbfSEd Maste Target *target = m_exe_ctx.GetTargetPtr();
1705ac7ddfbfSEd Maste EvaluateExpressionOptions options;
1706ac7ddfbfSEd Maste
1707ac7ddfbfSEd Maste options.SetUnwindOnError(true);
1708ac7ddfbfSEd Maste options.SetUseDynamic(eNoDynamicValues);
1709ac7ddfbfSEd Maste
17100127ef0fSEd Maste ExpressionResults exe_results = eExpressionSetupError;
1711435933ddSDimitry Andric exe_results = target->EvaluateExpression(command, frame_sp.get(),
1712435933ddSDimitry Andric return_valobj_sp, options);
1713435933ddSDimitry Andric if (exe_results != eExpressionCompleted) {
1714ac7ddfbfSEd Maste if (return_valobj_sp)
1715435933ddSDimitry Andric result.AppendErrorWithFormat(
1716435933ddSDimitry Andric "Error evaluating result expression: %s",
1717435933ddSDimitry Andric return_valobj_sp->GetError().AsCString());
1718ac7ddfbfSEd Maste else
1719435933ddSDimitry Andric result.AppendErrorWithFormat(
1720435933ddSDimitry Andric "Unknown error evaluating result expression.");
1721ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1722ac7ddfbfSEd Maste return false;
1723ac7ddfbfSEd Maste }
1724ac7ddfbfSEd Maste }
1725ac7ddfbfSEd Maste
17265517e702SDimitry Andric Status error;
1727ac7ddfbfSEd Maste ThreadSP thread_sp = m_exe_ctx.GetThreadSP();
1728ac7ddfbfSEd Maste const bool broadcast = true;
1729ac7ddfbfSEd Maste error = thread_sp->ReturnFromFrame(frame_sp, return_valobj_sp, broadcast);
1730435933ddSDimitry Andric if (!error.Success()) {
1731435933ddSDimitry Andric result.AppendErrorWithFormat(
1732435933ddSDimitry Andric "Error returning from frame %d of thread %d: %s.", frame_idx,
1733435933ddSDimitry Andric thread_sp->GetIndexID(), error.AsCString());
1734ac7ddfbfSEd Maste result.SetStatus(eReturnStatusFailed);
1735ac7ddfbfSEd Maste return false;
1736ac7ddfbfSEd Maste }
1737ac7ddfbfSEd Maste
1738ac7ddfbfSEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
1739ac7ddfbfSEd Maste return true;
1740ac7ddfbfSEd Maste }
1741ac7ddfbfSEd Maste
1742ac7ddfbfSEd Maste CommandOptions m_options;
1743ac7ddfbfSEd Maste };
17444bb0738eSEd Maste
174535617911SEd Maste //-------------------------------------------------------------------------
174635617911SEd Maste // CommandObjectThreadJump
174735617911SEd Maste //-------------------------------------------------------------------------
174835617911SEd Maste
1749*b5893f02SDimitry Andric static constexpr OptionDefinition g_thread_jump_options[] = {
1750435933ddSDimitry Andric // clang-format off
1751*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, "Specifies the source file to jump to." },
1752*b5893f02SDimitry Andric { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeLineNum, "Specifies the line number to jump to." },
1753*b5893f02SDimitry Andric { LLDB_OPT_SET_2, true, "by", 'b', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeOffset, "Jumps by a relative line offset from the current line." },
1754*b5893f02SDimitry Andric { LLDB_OPT_SET_3, true, "address", 'a', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeAddressOrExpression, "Jumps to a specific address." },
1755*b5893f02SDimitry Andric { LLDB_OPT_SET_1 | LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "force", 'r', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Allows the PC to leave the current function." }
1756435933ddSDimitry Andric // clang-format on
1757435933ddSDimitry Andric };
1758435933ddSDimitry Andric
1759435933ddSDimitry Andric class CommandObjectThreadJump : public CommandObjectParsed {
176035617911SEd Maste public:
1761435933ddSDimitry Andric class CommandOptions : public Options {
176235617911SEd Maste public:
CommandOptions()1763435933ddSDimitry Andric CommandOptions() : Options() { OptionParsingStarting(nullptr); }
176435617911SEd Maste
17654bb0738eSEd Maste ~CommandOptions() override = default;
17664bb0738eSEd Maste
OptionParsingStarting(ExecutionContext * execution_context)1767435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
176835617911SEd Maste m_filenames.Clear();
176935617911SEd Maste m_line_num = 0;
177035617911SEd Maste m_line_offset = 0;
177135617911SEd Maste m_load_addr = LLDB_INVALID_ADDRESS;
177235617911SEd Maste m_force = false;
177335617911SEd Maste }
177435617911SEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)17755517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1776435933ddSDimitry Andric ExecutionContext *execution_context) override {
177735617911SEd Maste const int short_option = m_getopt_table[option_idx].val;
17785517e702SDimitry Andric Status error;
177935617911SEd Maste
1780435933ddSDimitry Andric switch (short_option) {
178135617911SEd Maste case 'f':
1782*b5893f02SDimitry Andric m_filenames.AppendIfUnique(FileSpec(option_arg));
178335617911SEd Maste if (m_filenames.GetSize() > 1)
17845517e702SDimitry Andric return Status("only one source file expected.");
178535617911SEd Maste break;
178635617911SEd Maste case 'l':
1787435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_line_num))
17885517e702SDimitry Andric return Status("invalid line number: '%s'.", option_arg.str().c_str());
178935617911SEd Maste break;
179035617911SEd Maste case 'b':
1791435933ddSDimitry Andric if (option_arg.getAsInteger(0, m_line_offset))
17925517e702SDimitry Andric return Status("invalid line offset: '%s'.", option_arg.str().c_str());
179335617911SEd Maste break;
179435617911SEd Maste case 'a':
17954ba319b5SDimitry Andric m_load_addr = OptionArgParser::ToAddress(execution_context, option_arg,
1796435933ddSDimitry Andric LLDB_INVALID_ADDRESS, &error);
179735617911SEd Maste break;
179835617911SEd Maste case 'r':
179935617911SEd Maste m_force = true;
180035617911SEd Maste break;
180135617911SEd Maste default:
18025517e702SDimitry Andric return Status("invalid short option character '%c'", short_option);
180335617911SEd Maste }
180435617911SEd Maste return error;
180535617911SEd Maste }
180635617911SEd Maste
GetDefinitions()1807435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1808435933ddSDimitry Andric return llvm::makeArrayRef(g_thread_jump_options);
180935617911SEd Maste }
181035617911SEd Maste
181135617911SEd Maste FileSpecList m_filenames;
181235617911SEd Maste uint32_t m_line_num;
181335617911SEd Maste int32_t m_line_offset;
181435617911SEd Maste lldb::addr_t m_load_addr;
181535617911SEd Maste bool m_force;
181635617911SEd Maste };
181735617911SEd Maste
CommandObjectThreadJump(CommandInterpreter & interpreter)1818435933ddSDimitry Andric CommandObjectThreadJump(CommandInterpreter &interpreter)
1819435933ddSDimitry Andric : CommandObjectParsed(
1820435933ddSDimitry Andric interpreter, "thread jump",
1821435933ddSDimitry Andric "Sets the program counter to a new address.", "thread jump",
1822435933ddSDimitry Andric eCommandRequiresFrame | eCommandTryTargetAPILock |
1823435933ddSDimitry Andric eCommandProcessMustBeLaunched | eCommandProcessMustBePaused),
1824435933ddSDimitry Andric m_options() {}
182535617911SEd Maste
18264bb0738eSEd Maste ~CommandObjectThreadJump() override = default;
18274bb0738eSEd Maste
GetOptions()1828435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
182935617911SEd Maste
183035617911SEd Maste protected:
DoExecute(Args & args,CommandReturnObject & result)1831435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
183235617911SEd Maste RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext();
183335617911SEd Maste StackFrame *frame = m_exe_ctx.GetFramePtr();
183435617911SEd Maste Thread *thread = m_exe_ctx.GetThreadPtr();
183535617911SEd Maste Target *target = m_exe_ctx.GetTargetPtr();
1836435933ddSDimitry Andric const SymbolContext &sym_ctx =
1837435933ddSDimitry Andric frame->GetSymbolContext(eSymbolContextLineEntry);
183835617911SEd Maste
1839435933ddSDimitry Andric if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) {
184035617911SEd Maste // Use this address directly.
184135617911SEd Maste Address dest = Address(m_options.m_load_addr);
184235617911SEd Maste
184335617911SEd Maste lldb::addr_t callAddr = dest.GetCallableLoadAddress(target);
1844435933ddSDimitry Andric if (callAddr == LLDB_INVALID_ADDRESS) {
184535617911SEd Maste result.AppendErrorWithFormat("Invalid destination address.");
184635617911SEd Maste result.SetStatus(eReturnStatusFailed);
184735617911SEd Maste return false;
184835617911SEd Maste }
184935617911SEd Maste
1850435933ddSDimitry Andric if (!reg_ctx->SetPC(callAddr)) {
1851435933ddSDimitry Andric result.AppendErrorWithFormat("Error changing PC value for thread %d.",
1852435933ddSDimitry Andric thread->GetIndexID());
185335617911SEd Maste result.SetStatus(eReturnStatusFailed);
185435617911SEd Maste return false;
185535617911SEd Maste }
1856435933ddSDimitry Andric } else {
185735617911SEd Maste // Pick either the absolute line, or work out a relative one.
185835617911SEd Maste int32_t line = (int32_t)m_options.m_line_num;
185935617911SEd Maste if (line == 0)
186035617911SEd Maste line = sym_ctx.line_entry.line + m_options.m_line_offset;
186135617911SEd Maste
186235617911SEd Maste // Try the current file, but override if asked.
186335617911SEd Maste FileSpec file = sym_ctx.line_entry.file;
186435617911SEd Maste if (m_options.m_filenames.GetSize() == 1)
186535617911SEd Maste file = m_options.m_filenames.GetFileSpecAtIndex(0);
186635617911SEd Maste
1867435933ddSDimitry Andric if (!file) {
1868435933ddSDimitry Andric result.AppendErrorWithFormat(
1869435933ddSDimitry Andric "No source file available for the current location.");
187035617911SEd Maste result.SetStatus(eReturnStatusFailed);
187135617911SEd Maste return false;
187235617911SEd Maste }
187335617911SEd Maste
187435617911SEd Maste std::string warnings;
18755517e702SDimitry Andric Status err = thread->JumpToLine(file, line, m_options.m_force, &warnings);
187635617911SEd Maste
1877435933ddSDimitry Andric if (err.Fail()) {
187835617911SEd Maste result.SetError(err);
187935617911SEd Maste return false;
188035617911SEd Maste }
188135617911SEd Maste
188235617911SEd Maste if (!warnings.empty())
188335617911SEd Maste result.AppendWarning(warnings.c_str());
188435617911SEd Maste }
188535617911SEd Maste
188635617911SEd Maste result.SetStatus(eReturnStatusSuccessFinishResult);
188735617911SEd Maste return true;
188835617911SEd Maste }
188935617911SEd Maste
189035617911SEd Maste CommandOptions m_options;
189135617911SEd Maste };
18924bb0738eSEd Maste
1893ac7ddfbfSEd Maste //-------------------------------------------------------------------------
18947aa51b79SEd Maste // Next are the subcommands of CommandObjectMultiwordThreadPlan
18957aa51b79SEd Maste //-------------------------------------------------------------------------
18967aa51b79SEd Maste
18977aa51b79SEd Maste //-------------------------------------------------------------------------
18987aa51b79SEd Maste // CommandObjectThreadPlanList
18997aa51b79SEd Maste //-------------------------------------------------------------------------
19004bb0738eSEd Maste
1901*b5893f02SDimitry Andric static constexpr OptionDefinition g_thread_plan_list_options[] = {
1902435933ddSDimitry Andric // clang-format off
1903*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "verbose", 'v', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Display more information about the thread plans" },
1904*b5893f02SDimitry Andric { LLDB_OPT_SET_1, false, "internal", 'i', OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Display internal as well as user thread plans" }
1905435933ddSDimitry Andric // clang-format on
1906435933ddSDimitry Andric };
1907435933ddSDimitry Andric
1908435933ddSDimitry Andric class CommandObjectThreadPlanList : public CommandObjectIterateOverThreads {
19097aa51b79SEd Maste public:
1910435933ddSDimitry Andric class CommandOptions : public Options {
19117aa51b79SEd Maste public:
CommandOptions()1912435933ddSDimitry Andric CommandOptions() : Options() {
1913435933ddSDimitry Andric // Keep default values of all options in one place: OptionParsingStarting
1914435933ddSDimitry Andric // ()
1915435933ddSDimitry Andric OptionParsingStarting(nullptr);
19167aa51b79SEd Maste }
19177aa51b79SEd Maste
19184bb0738eSEd Maste ~CommandOptions() override = default;
19197aa51b79SEd Maste
SetOptionValue(uint32_t option_idx,llvm::StringRef option_arg,ExecutionContext * execution_context)19205517e702SDimitry Andric Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
1921435933ddSDimitry Andric ExecutionContext *execution_context) override {
19225517e702SDimitry Andric Status error;
19237aa51b79SEd Maste const int short_option = m_getopt_table[option_idx].val;
19247aa51b79SEd Maste
1925435933ddSDimitry Andric switch (short_option) {
19267aa51b79SEd Maste case 'i':
19277aa51b79SEd Maste m_internal = true;
19287aa51b79SEd Maste break;
19297aa51b79SEd Maste case 'v':
19307aa51b79SEd Maste m_verbose = true;
19317aa51b79SEd Maste break;
19327aa51b79SEd Maste default:
1933435933ddSDimitry Andric error.SetErrorStringWithFormat("invalid short option character '%c'",
1934435933ddSDimitry Andric short_option);
19357aa51b79SEd Maste break;
19367aa51b79SEd Maste }
19377aa51b79SEd Maste return error;
19387aa51b79SEd Maste }
19397aa51b79SEd Maste
OptionParsingStarting(ExecutionContext * execution_context)1940435933ddSDimitry Andric void OptionParsingStarting(ExecutionContext *execution_context) override {
19417aa51b79SEd Maste m_verbose = false;
19427aa51b79SEd Maste m_internal = false;
19437aa51b79SEd Maste }
19447aa51b79SEd Maste
GetDefinitions()1945435933ddSDimitry Andric llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
1946435933ddSDimitry Andric return llvm::makeArrayRef(g_thread_plan_list_options);
19477aa51b79SEd Maste }
19487aa51b79SEd Maste
19497aa51b79SEd Maste // Instance variables to hold the values for command options.
19507aa51b79SEd Maste bool m_verbose;
19517aa51b79SEd Maste bool m_internal;
19527aa51b79SEd Maste };
19537aa51b79SEd Maste
CommandObjectThreadPlanList(CommandInterpreter & interpreter)19544bb0738eSEd Maste CommandObjectThreadPlanList(CommandInterpreter &interpreter)
19554bb0738eSEd Maste : CommandObjectIterateOverThreads(
19564bb0738eSEd Maste interpreter, "thread plan list",
1957435933ddSDimitry Andric "Show thread plans for one or more threads. If no threads are "
1958435933ddSDimitry Andric "specified, show the "
19594bb0738eSEd Maste "current thread. Use the thread-index \"all\" to see all threads.",
1960435933ddSDimitry Andric nullptr,
1961435933ddSDimitry Andric eCommandRequiresProcess | eCommandRequiresThread |
1962435933ddSDimitry Andric eCommandTryTargetAPILock | eCommandProcessMustBeLaunched |
1963435933ddSDimitry Andric eCommandProcessMustBePaused),
1964435933ddSDimitry Andric m_options() {}
19657aa51b79SEd Maste
19664bb0738eSEd Maste ~CommandObjectThreadPlanList() override = default;
19677aa51b79SEd Maste
GetOptions()1968435933ddSDimitry Andric Options *GetOptions() override { return &m_options; }
19697aa51b79SEd Maste
19707aa51b79SEd Maste protected:
HandleOneThread(lldb::tid_t tid,CommandReturnObject & result)1971435933ddSDimitry Andric bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
1972435933ddSDimitry Andric ThreadSP thread_sp =
1973435933ddSDimitry Andric m_exe_ctx.GetProcessPtr()->GetThreadList().FindThreadByID(tid);
1974435933ddSDimitry Andric if (!thread_sp) {
1975435933ddSDimitry Andric result.AppendErrorWithFormat("thread no longer exists: 0x%" PRIx64 "\n",
1976435933ddSDimitry Andric tid);
19774bb0738eSEd Maste result.SetStatus(eReturnStatusFailed);
19784bb0738eSEd Maste return false;
19794bb0738eSEd Maste }
19804bb0738eSEd Maste
19814bb0738eSEd Maste Thread *thread = thread_sp.get();
19824bb0738eSEd Maste
19837aa51b79SEd Maste Stream &strm = result.GetOutputStream();
19847aa51b79SEd Maste DescriptionLevel desc_level = eDescriptionLevelFull;
19857aa51b79SEd Maste if (m_options.m_verbose)
19867aa51b79SEd Maste desc_level = eDescriptionLevelVerbose;
19877aa51b79SEd Maste
19884bb0738eSEd Maste thread->DumpThreadPlans(&strm, desc_level, m_options.m_internal, true);
19897aa51b79SEd Maste return true;
19907aa51b79SEd Maste }
19914bb0738eSEd Maste
19927aa51b79SEd Maste CommandOptions m_options;
19937aa51b79SEd Maste };
19947aa51b79SEd Maste
1995435933ddSDimitry Andric class CommandObjectThreadPlanDiscard : public CommandObjectParsed {
19967aa51b79SEd Maste public:
CommandObjectThreadPlanDiscard(CommandInterpreter & interpreter)19974bb0738eSEd Maste CommandObjectThreadPlanDiscard(CommandInterpreter &interpreter)
1998435933ddSDimitry Andric : CommandObjectParsed(interpreter, "thread plan discard",
1999435933ddSDimitry Andric "Discards thread plans up to and including the "
2000435933ddSDimitry Andric "specified index (see 'thread plan list'.) "
20014bb0738eSEd Maste "Only user visible plans can be discarded.",
2002435933ddSDimitry Andric nullptr,
2003435933ddSDimitry Andric eCommandRequiresProcess | eCommandRequiresThread |
2004435933ddSDimitry Andric eCommandTryTargetAPILock |
2005435933ddSDimitry Andric eCommandProcessMustBeLaunched |
2006435933ddSDimitry Andric eCommandProcessMustBePaused) {
20077aa51b79SEd Maste CommandArgumentEntry arg;
20087aa51b79SEd Maste CommandArgumentData plan_index_arg;
20097aa51b79SEd Maste
20107aa51b79SEd Maste // Define the first (and only) variant of this arg.
20117aa51b79SEd Maste plan_index_arg.arg_type = eArgTypeUnsignedInteger;
20127aa51b79SEd Maste plan_index_arg.arg_repetition = eArgRepeatPlain;
20137aa51b79SEd Maste
2014435933ddSDimitry Andric // There is only one variant this argument could be; put it into the
2015435933ddSDimitry Andric // argument entry.
20167aa51b79SEd Maste arg.push_back(plan_index_arg);
20177aa51b79SEd Maste
20187aa51b79SEd Maste // Push the data for the first argument into the m_arguments vector.
20197aa51b79SEd Maste m_arguments.push_back(arg);
20207aa51b79SEd Maste }
20217aa51b79SEd Maste
20224bb0738eSEd Maste ~CommandObjectThreadPlanDiscard() override = default;
20237aa51b79SEd Maste
DoExecute(Args & args,CommandReturnObject & result)2024435933ddSDimitry Andric bool DoExecute(Args &args, CommandReturnObject &result) override {
20257aa51b79SEd Maste Thread *thread = m_exe_ctx.GetThreadPtr();
2026435933ddSDimitry Andric if (args.GetArgumentCount() != 1) {
2027435933ddSDimitry Andric result.AppendErrorWithFormat("Too many arguments, expected one - the "
2028435933ddSDimitry Andric "thread plan index - but got %zu.",
20297aa51b79SEd Maste args.GetArgumentCount());
20307aa51b79SEd Maste result.SetStatus(eReturnStatusFailed);
20317aa51b79SEd Maste return false;
20327aa51b79SEd Maste }
20337aa51b79SEd Maste
20347aa51b79SEd Maste bool success;
2035435933ddSDimitry Andric uint32_t thread_plan_idx =
2036435933ddSDimitry Andric StringConvert::ToUInt32(args.GetArgumentAtIndex(0), 0, 0, &success);
2037435933ddSDimitry Andric if (!success) {
2038435933ddSDimitry Andric result.AppendErrorWithFormat(
2039435933ddSDimitry Andric "Invalid thread index: \"%s\" - should be unsigned int.",
20407aa51b79SEd Maste args.GetArgumentAtIndex(0));
20417aa51b79SEd Maste result.SetStatus(eReturnStatusFailed);
20427aa51b79SEd Maste return false;
20437aa51b79SEd Maste }
20447aa51b79SEd Maste
2045435933ddSDimitry Andric if (thread_plan_idx == 0) {
2046435933ddSDimitry Andric result.AppendErrorWithFormat(
2047435933ddSDimitry Andric "You wouldn't really want me to discard the base thread plan.");
20487aa51b79SEd Maste result.SetStatus(eReturnStatusFailed);
20497aa51b79SEd Maste return false;
20507aa51b79SEd Maste }
20517aa51b79SEd Maste
2052435933ddSDimitry Andric if (thread->DiscardUserThreadPlansUpToIndex(thread_plan_idx)) {
20537aa51b79SEd Maste result.SetStatus(eReturnStatusSuccessFinishNoResult);
20547aa51b79SEd Maste return true;
2055435933ddSDimitry Andric } else {
2056435933ddSDimitry Andric result.AppendErrorWithFormat(
2057435933ddSDimitry Andric "Could not find User thread plan with index %s.",
20587aa51b79SEd Maste args.GetArgumentAtIndex(0));
20597aa51b79SEd Maste result.SetStatus(eReturnStatusFailed);
20607aa51b79SEd Maste return false;
20617aa51b79SEd Maste }
20627aa51b79SEd Maste }
20637aa51b79SEd Maste };
20647aa51b79SEd Maste
20657aa51b79SEd Maste //-------------------------------------------------------------------------
20667aa51b79SEd Maste // CommandObjectMultiwordThreadPlan
20677aa51b79SEd Maste //-------------------------------------------------------------------------
20687aa51b79SEd Maste
2069435933ddSDimitry Andric class CommandObjectMultiwordThreadPlan : public CommandObjectMultiword {
20707aa51b79SEd Maste public:
CommandObjectMultiwordThreadPlan(CommandInterpreter & interpreter)20714bb0738eSEd Maste CommandObjectMultiwordThreadPlan(CommandInterpreter &interpreter)
2072435933ddSDimitry Andric : CommandObjectMultiword(
2073435933ddSDimitry Andric interpreter, "plan",
2074435933ddSDimitry Andric "Commands for managing thread plans that control execution.",
2075435933ddSDimitry Andric "thread plan <subcommand> [<subcommand objects]") {
2076435933ddSDimitry Andric LoadSubCommand(
2077435933ddSDimitry Andric "list", CommandObjectSP(new CommandObjectThreadPlanList(interpreter)));
2078435933ddSDimitry Andric LoadSubCommand(
2079435933ddSDimitry Andric "discard",
2080435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadPlanDiscard(interpreter)));
20817aa51b79SEd Maste }
20827aa51b79SEd Maste
20834bb0738eSEd Maste ~CommandObjectMultiwordThreadPlan() override = default;
20847aa51b79SEd Maste };
20857aa51b79SEd Maste
20867aa51b79SEd Maste //-------------------------------------------------------------------------
2087ac7ddfbfSEd Maste // CommandObjectMultiwordThread
2088ac7ddfbfSEd Maste //-------------------------------------------------------------------------
2089ac7ddfbfSEd Maste
CommandObjectMultiwordThread(CommandInterpreter & interpreter)2090435933ddSDimitry Andric CommandObjectMultiwordThread::CommandObjectMultiwordThread(
2091435933ddSDimitry Andric CommandInterpreter &interpreter)
2092435933ddSDimitry Andric : CommandObjectMultiword(interpreter, "thread", "Commands for operating on "
2093435933ddSDimitry Andric "one or more threads in "
2094435933ddSDimitry Andric "the current process.",
2095435933ddSDimitry Andric "thread <subcommand> [<subcommand-options>]") {
2096435933ddSDimitry Andric LoadSubCommand("backtrace", CommandObjectSP(new CommandObjectThreadBacktrace(
2097435933ddSDimitry Andric interpreter)));
2098435933ddSDimitry Andric LoadSubCommand("continue",
2099435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadContinue(interpreter)));
2100435933ddSDimitry Andric LoadSubCommand("list",
2101435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadList(interpreter)));
2102435933ddSDimitry Andric LoadSubCommand("return",
2103435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadReturn(interpreter)));
2104435933ddSDimitry Andric LoadSubCommand("jump",
2105435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadJump(interpreter)));
2106435933ddSDimitry Andric LoadSubCommand("select",
2107435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadSelect(interpreter)));
2108435933ddSDimitry Andric LoadSubCommand("until",
2109435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadUntil(interpreter)));
2110435933ddSDimitry Andric LoadSubCommand("info",
2111435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadInfo(interpreter)));
2112*b5893f02SDimitry Andric LoadSubCommand(
2113*b5893f02SDimitry Andric "exception",
2114*b5893f02SDimitry Andric CommandObjectSP(new CommandObjectThreadException(interpreter)));
21154bb0738eSEd Maste LoadSubCommand("step-in",
21164bb0738eSEd Maste CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
21174bb0738eSEd Maste interpreter, "thread step-in",
2118435933ddSDimitry Andric "Source level single step, stepping into calls. Defaults "
2119435933ddSDimitry Andric "to current thread unless specified.",
21204bb0738eSEd Maste nullptr, eStepTypeInto, eStepScopeSource)));
2121ac7ddfbfSEd Maste
21224bb0738eSEd Maste LoadSubCommand("step-out",
21234bb0738eSEd Maste CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
2124435933ddSDimitry Andric interpreter, "thread step-out",
2125435933ddSDimitry Andric "Finish executing the current stack frame and stop after "
21264bb0738eSEd Maste "returning. Defaults to current thread unless specified.",
21274bb0738eSEd Maste nullptr, eStepTypeOut, eStepScopeSource)));
2128ac7ddfbfSEd Maste
21294bb0738eSEd Maste LoadSubCommand("step-over",
21304bb0738eSEd Maste CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
21314bb0738eSEd Maste interpreter, "thread step-over",
2132435933ddSDimitry Andric "Source level single step, stepping over calls. Defaults "
2133435933ddSDimitry Andric "to current thread unless specified.",
21344bb0738eSEd Maste nullptr, eStepTypeOver, eStepScopeSource)));
2135ac7ddfbfSEd Maste
2136435933ddSDimitry Andric LoadSubCommand("step-inst",
21374bb0738eSEd Maste CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
21384bb0738eSEd Maste interpreter, "thread step-inst",
2139435933ddSDimitry Andric "Instruction level single step, stepping into calls. "
2140435933ddSDimitry Andric "Defaults to current thread unless specified.",
21414bb0738eSEd Maste nullptr, eStepTypeTrace, eStepScopeInstruction)));
2142ac7ddfbfSEd Maste
2143435933ddSDimitry Andric LoadSubCommand("step-inst-over",
21444bb0738eSEd Maste CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
21454bb0738eSEd Maste interpreter, "thread step-inst-over",
2146435933ddSDimitry Andric "Instruction level single step, stepping over calls. "
2147435933ddSDimitry Andric "Defaults to current thread unless specified.",
21484bb0738eSEd Maste nullptr, eStepTypeTraceOver, eStepScopeInstruction)));
21497aa51b79SEd Maste
2150435933ddSDimitry Andric LoadSubCommand(
2151435933ddSDimitry Andric "step-scripted",
2152435933ddSDimitry Andric CommandObjectSP(new CommandObjectThreadStepWithTypeAndScope(
2153435933ddSDimitry Andric interpreter, "thread step-scripted",
21547aa51b79SEd Maste "Step as instructed by the script class passed in the -C option.",
2155435933ddSDimitry Andric nullptr, eStepTypeScripted, eStepScopeSource)));
21567aa51b79SEd Maste
2157435933ddSDimitry Andric LoadSubCommand("plan", CommandObjectSP(new CommandObjectMultiwordThreadPlan(
2158435933ddSDimitry Andric interpreter)));
2159ac7ddfbfSEd Maste }
2160ac7ddfbfSEd Maste
21614bb0738eSEd Maste CommandObjectMultiwordThread::~CommandObjectMultiwordThread() = default;
2162