blob: 4b1239856e826300e79b952f70c74bb977fbabe0 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectThread.cpp ---------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "CommandObjectThread.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
Jim Inghamf59388a2012-09-14 02:14:15 +000018#include "lldb/lldb-private.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/State.h"
20#include "lldb/Core/SourceManager.h"
Greg Claytoncd548032011-02-01 01:31:41 +000021#include "lldb/Host/Host.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Interpreter/CommandInterpreter.h"
23#include "lldb/Interpreter/CommandReturnObject.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000024#include "lldb/Interpreter/Options.h"
25#include "lldb/Symbol/CompileUnit.h"
26#include "lldb/Symbol/Function.h"
27#include "lldb/Symbol/LineTable.h"
28#include "lldb/Symbol/LineEntry.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Target/Process.h"
30#include "lldb/Target/RegisterContext.h"
31#include "lldb/Target/Target.h"
32#include "lldb/Target/Thread.h"
33#include "lldb/Target/ThreadPlan.h"
Chris Lattner24943d22010-06-08 16:52:24 +000034#include "lldb/Target/ThreadPlanStepInstruction.h"
35#include "lldb/Target/ThreadPlanStepOut.h"
36#include "lldb/Target/ThreadPlanStepRange.h"
37#include "lldb/Target/ThreadPlanStepInRange.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000038
Chris Lattner24943d22010-06-08 16:52:24 +000039
40using namespace lldb;
41using namespace lldb_private;
42
43
Chris Lattner24943d22010-06-08 16:52:24 +000044//-------------------------------------------------------------------------
45// CommandObjectThreadBacktrace
46//-------------------------------------------------------------------------
47
Jim Inghamda26bd22012-06-08 21:56:10 +000048class CommandObjectThreadBacktrace : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +000049{
50public:
51
Jim Ingham8ab1a802010-08-26 23:36:03 +000052 class CommandOptions : public Options
53 {
54 public:
55
Greg Claytonf15996e2011-04-07 22:46:35 +000056 CommandOptions (CommandInterpreter &interpreter) :
57 Options(interpreter)
Jim Ingham8ab1a802010-08-26 23:36:03 +000058 {
Greg Clayton143fcc32011-04-13 00:18:08 +000059 // Keep default values of all options in one place: OptionParsingStarting ()
60 OptionParsingStarting ();
Jim Ingham8ab1a802010-08-26 23:36:03 +000061 }
62
63 virtual
64 ~CommandOptions ()
65 {
66 }
67
68 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +000069 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Ingham8ab1a802010-08-26 23:36:03 +000070 {
71 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +000072 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham8ab1a802010-08-26 23:36:03 +000073
74 switch (short_option)
75 {
76 case 'c':
77 {
78 bool success;
79 int32_t input_count = Args::StringToSInt32 (option_arg, -1, 0, &success);
80 if (!success)
Greg Clayton9c236732011-10-26 00:56:27 +000081 error.SetErrorStringWithFormat("invalid integer value for option '%c'", short_option);
Jim Ingham8ab1a802010-08-26 23:36:03 +000082 if (input_count < -1)
83 m_count = UINT32_MAX;
84 else
85 m_count = input_count;
86 }
87 break;
88 case 's':
89 {
90 bool success;
91 m_start = Args::StringToUInt32 (option_arg, 0, 0, &success);
92 if (!success)
Greg Clayton9c236732011-10-26 00:56:27 +000093 error.SetErrorStringWithFormat("invalid integer value for option '%c'", short_option);
Jim Ingham8ab1a802010-08-26 23:36:03 +000094 }
95 break;
96 default:
Greg Clayton9c236732011-10-26 00:56:27 +000097 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
Jim Ingham8ab1a802010-08-26 23:36:03 +000098 break;
99
100 }
101 return error;
102 }
103
104 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000105 OptionParsingStarting ()
Jim Ingham8ab1a802010-08-26 23:36:03 +0000106 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000107 m_count = UINT32_MAX;
Jim Ingham8ab1a802010-08-26 23:36:03 +0000108 m_start = 0;
109 }
110
Greg Claytonb3448432011-03-24 21:19:54 +0000111 const OptionDefinition*
Jim Ingham8ab1a802010-08-26 23:36:03 +0000112 GetDefinitions ()
113 {
114 return g_option_table;
115 }
116
117 // Options table: Required for subclasses of Options.
118
Greg Claytonb3448432011-03-24 21:19:54 +0000119 static OptionDefinition g_option_table[];
Jim Ingham8ab1a802010-08-26 23:36:03 +0000120
121 // Instance variables to hold the values for command options.
122 uint32_t m_count;
123 uint32_t m_start;
124 };
125
Greg Clayton238c0a12010-09-18 01:14:36 +0000126 CommandObjectThreadBacktrace (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000127 CommandObjectParsed (interpreter,
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000128 "thread backtrace",
129 "Show the stack for one or more threads. If no threads are specified, show the currently selected thread. Use the thread-index \"all\" to see all threads.",
130 NULL,
131 eFlagRequiresProcess |
132 eFlagRequiresThread |
133 eFlagTryTargetAPILock |
134 eFlagProcessMustBeLaunched |
135 eFlagProcessMustBePaused ),
Greg Claytonf15996e2011-04-07 22:46:35 +0000136 m_options(interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000137 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000138 CommandArgumentEntry arg;
139 CommandArgumentData thread_idx_arg;
140
141 // Define the first (and only) variant of this arg.
142 thread_idx_arg.arg_type = eArgTypeThreadIndex;
143 thread_idx_arg.arg_repetition = eArgRepeatStar;
144
145 // There is only one variant this argument could be; put it into the argument entry.
146 arg.push_back (thread_idx_arg);
147
148 // Push the data for the first argument into the m_arguments vector.
149 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000150 }
151
152 ~CommandObjectThreadBacktrace()
153 {
154 }
155
Jim Ingham8ab1a802010-08-26 23:36:03 +0000156 virtual Options *
157 GetOptions ()
158 {
159 return &m_options;
160 }
Chris Lattner24943d22010-06-08 16:52:24 +0000161
Jim Inghamda26bd22012-06-08 21:56:10 +0000162protected:
Greg Clayton63094e02010-06-23 01:19:29 +0000163 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000164 DoExecute (Args& command, CommandReturnObject &result)
Greg Claytonabe0fed2011-04-18 08:33:37 +0000165 {
Jim Inghameb10f7b2010-08-27 00:58:05 +0000166 result.SetStatus (eReturnStatusSuccessFinishResult);
Greg Claytonabe0fed2011-04-18 08:33:37 +0000167 Stream &strm = result.GetOutputStream();
168
169 // Don't show source context when doing backtraces.
170 const uint32_t num_frames_with_source = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000171 if (command.GetArgumentCount() == 0)
172 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000173 Thread *thread = m_exe_ctx.GetThreadPtr();
174 // Thread::GetStatus() returns the number of frames shown.
175 if (thread->GetStatus (strm,
176 m_options.m_start,
177 m_options.m_count,
178 num_frames_with_source))
Chris Lattner24943d22010-06-08 16:52:24 +0000179 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000180 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000181 }
182 }
Jim Inghameb10f7b2010-08-27 00:58:05 +0000183 else if (command.GetArgumentCount() == 1 && ::strcmp (command.GetArgumentAtIndex(0), "all") == 0)
184 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000185 Process *process = m_exe_ctx.GetProcessPtr();
Jim Inghamb9950592012-09-10 20:50:15 +0000186 Mutex::Locker locker (process->GetThreadList().GetMutex());
Jim Inghameb10f7b2010-08-27 00:58:05 +0000187 uint32_t num_threads = process->GetThreadList().GetSize();
188 for (uint32_t i = 0; i < num_threads; i++)
189 {
190 ThreadSP thread_sp = process->GetThreadList().GetThreadAtIndex(i);
Johnny Chen05750a62011-06-01 23:19:52 +0000191 if (!thread_sp->GetStatus (strm,
192 m_options.m_start,
193 m_options.m_count,
194 num_frames_with_source))
Jim Inghameb10f7b2010-08-27 00:58:05 +0000195 {
Greg Claytonf04d6612010-09-03 22:45:01 +0000196 result.AppendErrorWithFormat ("error displaying backtrace for thread: \"0x%4.4x\"\n", i);
Jim Inghameb10f7b2010-08-27 00:58:05 +0000197 result.SetStatus (eReturnStatusFailed);
198 return false;
199 }
Jim Ingham7868bcc2011-07-26 02:39:59 +0000200
201 if (i < num_threads - 1)
202 result.AppendMessage("");
203
Jim Inghameb10f7b2010-08-27 00:58:05 +0000204 }
205 }
Chris Lattner24943d22010-06-08 16:52:24 +0000206 else
207 {
Greg Clayton36da2aa2013-01-25 18:06:21 +0000208 const size_t num_args = command.GetArgumentCount();
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000209 Process *process = m_exe_ctx.GetProcessPtr();
Jim Inghamb9950592012-09-10 20:50:15 +0000210 Mutex::Locker locker (process->GetThreadList().GetMutex());
Jim Inghameb10f7b2010-08-27 00:58:05 +0000211 std::vector<ThreadSP> thread_sps;
212
Greg Clayton36da2aa2013-01-25 18:06:21 +0000213 for (size_t i = 0; i < num_args; i++)
Jim Inghameb10f7b2010-08-27 00:58:05 +0000214 {
215 bool success;
216
217 uint32_t thread_idx = Args::StringToUInt32(command.GetArgumentAtIndex(i), 0, 0, &success);
218 if (!success)
219 {
220 result.AppendErrorWithFormat ("invalid thread specification: \"%s\"\n", command.GetArgumentAtIndex(i));
221 result.SetStatus (eReturnStatusFailed);
222 return false;
223 }
224
225 thread_sps.push_back(process->GetThreadList().FindThreadByIndexID(thread_idx));
226
227 if (!thread_sps[i])
228 {
229 result.AppendErrorWithFormat ("no thread with index: \"%s\"\n", command.GetArgumentAtIndex(i));
230 result.SetStatus (eReturnStatusFailed);
231 return false;
232 }
233
234 }
235
236 for (uint32_t i = 0; i < num_args; i++)
237 {
Greg Claytonabe0fed2011-04-18 08:33:37 +0000238 if (!thread_sps[i]->GetStatus (strm,
239 m_options.m_start,
240 m_options.m_count,
241 num_frames_with_source))
Jim Inghameb10f7b2010-08-27 00:58:05 +0000242 {
243 result.AppendErrorWithFormat ("error displaying backtrace for thread: \"%s\"\n", command.GetArgumentAtIndex(i));
244 result.SetStatus (eReturnStatusFailed);
245 return false;
246 }
247
248 if (i < num_args - 1)
249 result.AppendMessage("");
250 }
Chris Lattner24943d22010-06-08 16:52:24 +0000251 }
252 return result.Succeeded();
253 }
Jim Inghamda26bd22012-06-08 21:56:10 +0000254
Jim Ingham8ab1a802010-08-26 23:36:03 +0000255 CommandOptions m_options;
Chris Lattner24943d22010-06-08 16:52:24 +0000256};
257
Greg Claytonb3448432011-03-24 21:19:54 +0000258OptionDefinition
Jim Ingham8ab1a802010-08-26 23:36:03 +0000259CommandObjectThreadBacktrace::CommandOptions::g_option_table[] =
260{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000261{ LLDB_OPT_SET_1, false, "count", 'c', required_argument, NULL, 0, eArgTypeCount, "How many frames to display (-1 for all)"},
Caroline Tice43b014a2010-10-04 22:28:36 +0000262{ LLDB_OPT_SET_1, false, "start", 's', required_argument, NULL, 0, eArgTypeFrameIndex, "Frame in which to start the backtrace"},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000263{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Jim Ingham8ab1a802010-08-26 23:36:03 +0000264};
Chris Lattner24943d22010-06-08 16:52:24 +0000265
Greg Claytonc0418152010-07-07 17:07:17 +0000266enum StepScope
Chris Lattner24943d22010-06-08 16:52:24 +0000267{
268 eStepScopeSource,
269 eStepScopeInstruction
270};
271
Jim Inghamda26bd22012-06-08 21:56:10 +0000272class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000273{
274public:
275
276 class CommandOptions : public Options
277 {
278 public:
279
Greg Claytonf15996e2011-04-07 22:46:35 +0000280 CommandOptions (CommandInterpreter &interpreter) :
281 Options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000282 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000283 // Keep default values of all options in one place: OptionParsingStarting ()
284 OptionParsingStarting ();
Chris Lattner24943d22010-06-08 16:52:24 +0000285 }
286
287 virtual
288 ~CommandOptions ()
289 {
290 }
291
292 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000293 SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000294 {
295 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +0000296 const int short_option = m_getopt_table[option_idx].val;
Chris Lattner24943d22010-06-08 16:52:24 +0000297
298 switch (short_option)
299 {
Greg Clayton8d3802d2010-10-08 04:20:14 +0000300 case 'a':
Chris Lattner24943d22010-06-08 16:52:24 +0000301 {
302 bool success;
303 m_avoid_no_debug = Args::StringToBoolean (option_arg, true, &success);
304 if (!success)
Greg Clayton9c236732011-10-26 00:56:27 +0000305 error.SetErrorStringWithFormat("invalid boolean value for option '%c'", short_option);
Chris Lattner24943d22010-06-08 16:52:24 +0000306 }
307 break;
Greg Clayton8d3802d2010-10-08 04:20:14 +0000308
309 case 'm':
Chris Lattner24943d22010-06-08 16:52:24 +0000310 {
Chris Lattner24943d22010-06-08 16:52:24 +0000311 OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
Greg Clayton61aca5d2011-10-07 18:58:12 +0000312 m_run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, error);
Chris Lattner24943d22010-06-08 16:52:24 +0000313 }
314 break;
Greg Clayton8d3802d2010-10-08 04:20:14 +0000315
316 case 'r':
Jim Ingham809ab9b2010-07-10 02:27:39 +0000317 {
318 m_avoid_regexp.clear();
319 m_avoid_regexp.assign(option_arg);
320 }
321 break;
Greg Clayton8d3802d2010-10-08 04:20:14 +0000322
Jim Inghamf2ca5732012-12-12 19:58:40 +0000323 case 't':
324 {
325 m_step_in_target.clear();
326 m_step_in_target.assign(option_arg);
327
328 }
329 break;
Greg Clayton8d3802d2010-10-08 04:20:14 +0000330 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000331 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
Greg Clayton8d3802d2010-10-08 04:20:14 +0000332 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000333
334 }
335 return error;
336 }
337
338 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000339 OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000340 {
Chris Lattner24943d22010-06-08 16:52:24 +0000341 m_avoid_no_debug = true;
342 m_run_mode = eOnlyDuringStepping;
Jim Ingham809ab9b2010-07-10 02:27:39 +0000343 m_avoid_regexp.clear();
Jim Inghamf2ca5732012-12-12 19:58:40 +0000344 m_step_in_target.clear();
Chris Lattner24943d22010-06-08 16:52:24 +0000345 }
346
Greg Claytonb3448432011-03-24 21:19:54 +0000347 const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000348 GetDefinitions ()
349 {
350 return g_option_table;
351 }
352
353 // Options table: Required for subclasses of Options.
354
Greg Claytonb3448432011-03-24 21:19:54 +0000355 static OptionDefinition g_option_table[];
Chris Lattner24943d22010-06-08 16:52:24 +0000356
357 // Instance variables to hold the values for command options.
358 bool m_avoid_no_debug;
359 RunMode m_run_mode;
Jim Ingham809ab9b2010-07-10 02:27:39 +0000360 std::string m_avoid_regexp;
Jim Inghamf2ca5732012-12-12 19:58:40 +0000361 std::string m_step_in_target;
Chris Lattner24943d22010-06-08 16:52:24 +0000362 };
363
Greg Clayton238c0a12010-09-18 01:14:36 +0000364 CommandObjectThreadStepWithTypeAndScope (CommandInterpreter &interpreter,
365 const char *name,
366 const char *help,
367 const char *syntax,
Greg Clayton238c0a12010-09-18 01:14:36 +0000368 StepType step_type,
369 StepScope step_scope) :
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000370 CommandObjectParsed (interpreter, name, help, syntax,
371 eFlagRequiresProcess |
372 eFlagRequiresThread |
373 eFlagTryTargetAPILock |
374 eFlagProcessMustBeLaunched |
375 eFlagProcessMustBePaused ),
Chris Lattner24943d22010-06-08 16:52:24 +0000376 m_step_type (step_type),
377 m_step_scope (step_scope),
Greg Claytonf15996e2011-04-07 22:46:35 +0000378 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000379 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000380 CommandArgumentEntry arg;
381 CommandArgumentData thread_id_arg;
382
383 // Define the first (and only) variant of this arg.
384 thread_id_arg.arg_type = eArgTypeThreadID;
385 thread_id_arg.arg_repetition = eArgRepeatOptional;
386
387 // There is only one variant this argument could be; put it into the argument entry.
388 arg.push_back (thread_id_arg);
389
390 // Push the data for the first argument into the m_arguments vector.
391 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000392 }
393
394 virtual
395 ~CommandObjectThreadStepWithTypeAndScope ()
396 {
397 }
398
399 virtual
400 Options *
401 GetOptions ()
402 {
403 return &m_options;
404 }
405
Jim Inghamda26bd22012-06-08 21:56:10 +0000406protected:
Chris Lattner24943d22010-06-08 16:52:24 +0000407 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000408 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000409 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000410 Process *process = m_exe_ctx.GetProcessPtr();
Greg Clayton238c0a12010-09-18 01:14:36 +0000411 bool synchronous_execution = m_interpreter.GetSynchronous();
Chris Lattner24943d22010-06-08 16:52:24 +0000412
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000413 const uint32_t num_threads = process->GetThreadList().GetSize();
414 Thread *thread = NULL;
415
416 if (command.GetArgumentCount() == 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000417 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000418 thread = process->GetThreadList().GetSelectedThread().get();
419 if (thread == NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000420 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000421 result.AppendError ("no selected thread in process");
Chris Lattner24943d22010-06-08 16:52:24 +0000422 result.SetStatus (eReturnStatusFailed);
Jim Ingham88e3de22012-05-03 21:19:36 +0000423 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000424 }
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000425 }
426 else
427 {
428 const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
429 uint32_t step_thread_idx = Args::StringToUInt32 (thread_idx_cstr, LLDB_INVALID_INDEX32);
430 if (step_thread_idx == LLDB_INVALID_INDEX32)
Chris Lattner24943d22010-06-08 16:52:24 +0000431 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000432 result.AppendErrorWithFormat ("invalid thread index '%s'.\n", thread_idx_cstr);
433 result.SetStatus (eReturnStatusFailed);
434 return false;
435 }
436 thread = process->GetThreadList().FindThreadByIndexID(step_thread_idx).get();
437 if (thread == NULL)
438 {
439 result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n",
440 step_thread_idx, num_threads);
441 result.SetStatus (eReturnStatusFailed);
442 return false;
443 }
444 }
Jim Ingham88e3de22012-05-03 21:19:36 +0000445
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000446 const bool abort_other_plans = false;
447 const lldb::RunMode stop_other_threads = m_options.m_run_mode;
448
449 // This is a bit unfortunate, but not all the commands in this command object support
450 // only while stepping, so I use the bool for them.
451 bool bool_stop_other_threads;
452 if (m_options.m_run_mode == eAllThreads)
453 bool_stop_other_threads = false;
454 else if (m_options.m_run_mode == eOnlyDuringStepping)
455 {
456 if (m_step_type == eStepTypeOut)
457 bool_stop_other_threads = false;
458 else
459 bool_stop_other_threads = true;
460 }
461 else
462 bool_stop_other_threads = true;
Jim Ingham88e3de22012-05-03 21:19:36 +0000463
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000464 ThreadPlan *new_plan = NULL;
465
466 if (m_step_type == eStepTypeInto)
467 {
468 StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
469
470 if (frame->HasDebugInformation ())
471 {
472 new_plan = thread->QueueThreadPlanForStepInRange (abort_other_plans,
473 frame->GetSymbolContext(eSymbolContextEverything).line_entry.range,
474 frame->GetSymbolContext(eSymbolContextEverything),
475 m_options.m_step_in_target.c_str(),
476 stop_other_threads,
477 m_options.m_avoid_no_debug);
478 if (new_plan && !m_options.m_avoid_regexp.empty())
Jim Ingham88e3de22012-05-03 21:19:36 +0000479 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000480 ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (new_plan);
481 step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str());
Jim Ingham53628e72012-05-16 00:37:40 +0000482 }
Jim Ingham88e3de22012-05-03 21:19:36 +0000483 }
484 else
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000485 new_plan = thread->QueueThreadPlanForStepSingleInstruction (false, abort_other_plans, bool_stop_other_threads);
486
487 }
488 else if (m_step_type == eStepTypeOver)
489 {
490 StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
491
492 if (frame->HasDebugInformation())
493 new_plan = thread->QueueThreadPlanForStepOverRange (abort_other_plans,
494 frame->GetSymbolContext(eSymbolContextEverything).line_entry.range,
495 frame->GetSymbolContext(eSymbolContextEverything),
496 stop_other_threads);
497 else
498 new_plan = thread->QueueThreadPlanForStepSingleInstruction (true,
499 abort_other_plans,
500 bool_stop_other_threads);
501
502 }
503 else if (m_step_type == eStepTypeTrace)
504 {
505 new_plan = thread->QueueThreadPlanForStepSingleInstruction (false, abort_other_plans, bool_stop_other_threads);
506 }
507 else if (m_step_type == eStepTypeTraceOver)
508 {
509 new_plan = thread->QueueThreadPlanForStepSingleInstruction (true, abort_other_plans, bool_stop_other_threads);
510 }
511 else if (m_step_type == eStepTypeOut)
512 {
513 new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans,
514 NULL,
515 false,
516 bool_stop_other_threads,
517 eVoteYes,
518 eVoteNoOpinion,
519 thread->GetSelectedFrameIndex());
520 }
521 else
522 {
523 result.AppendError ("step type is not supported");
524 result.SetStatus (eReturnStatusFailed);
525 return false;
526 }
527
528 // If we got a new plan, then set it to be a master plan (User level Plans should be master plans
529 // so that they can be interruptible). Then resume the process.
530
531 if (new_plan != NULL)
532 {
533 new_plan->SetIsMasterPlan (true);
534 new_plan->SetOkayToDiscard (false);
535
536 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
537 process->Resume ();
538
539
540 if (synchronous_execution)
Jim Ingham88e3de22012-05-03 21:19:36 +0000541 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000542 StateType state = process->WaitForProcessToStop (NULL);
543
544 //EventSP event_sp;
545 //StateType state = process->WaitForStateChangedEvents (NULL, event_sp);
546 //while (! StateIsStoppedState (state))
547 // {
548 // state = process->WaitForStateChangedEvents (NULL, event_sp);
549 // }
550 process->GetThreadList().SetSelectedThreadByID (thread->GetID());
551 result.SetDidChangeProcessState (true);
552 result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state));
553 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +0000554 }
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000555 else
556 {
557 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
558 }
559 }
560 else
561 {
562 result.AppendError ("Couldn't find thread plan to implement step type.");
563 result.SetStatus (eReturnStatusFailed);
Chris Lattner24943d22010-06-08 16:52:24 +0000564 }
565 return result.Succeeded();
566 }
567
568protected:
569 StepType m_step_type;
570 StepScope m_step_scope;
571 CommandOptions m_options;
572};
573
Greg Claytonb3448432011-03-24 21:19:54 +0000574static OptionEnumValueElement
Chris Lattner24943d22010-06-08 16:52:24 +0000575g_tri_running_mode[] =
576{
Greg Claytonfe424a92010-09-18 03:37:20 +0000577{ eOnlyThisThread, "this-thread", "Run only this thread"},
578{ eAllThreads, "all-threads", "Run all threads"},
579{ eOnlyDuringStepping, "while-stepping", "Run only this thread while stepping"},
Chris Lattner24943d22010-06-08 16:52:24 +0000580{ 0, NULL, NULL }
581};
582
Greg Claytonb3448432011-03-24 21:19:54 +0000583static OptionEnumValueElement
Chris Lattner24943d22010-06-08 16:52:24 +0000584g_duo_running_mode[] =
585{
Greg Claytonfe424a92010-09-18 03:37:20 +0000586{ eOnlyThisThread, "this-thread", "Run only this thread"},
587{ eAllThreads, "all-threads", "Run all threads"},
Chris Lattner24943d22010-06-08 16:52:24 +0000588{ 0, NULL, NULL }
589};
590
Greg Claytonb3448432011-03-24 21:19:54 +0000591OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +0000592CommandObjectThreadStepWithTypeAndScope::CommandOptions::g_option_table[] =
593{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000594{ LLDB_OPT_SET_1, false, "avoid-no-debug", 'a', required_argument, NULL, 0, eArgTypeBoolean, "A boolean value that sets whether step-in will step over functions with no debug information."},
595{ LLDB_OPT_SET_1, false, "run-mode", 'm', required_argument, g_tri_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping the current thread."},
Jim Inghamf2ca5732012-12-12 19:58:40 +0000596{ LLDB_OPT_SET_1, false, "step-over-regexp",'r', required_argument, NULL, 0, eArgTypeRegularExpression, "A regular expression that defines function names to not to stop at when stepping in."},
597{ LLDB_OPT_SET_1, false, "step-in-target", 't', required_argument, NULL, 0, eArgTypeFunctionName, "The name of the directly called function step in should stop at when stepping into."},
Caroline Tice4d6675c2010-10-01 19:59:14 +0000598{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +0000599};
600
601
602//-------------------------------------------------------------------------
603// CommandObjectThreadContinue
604//-------------------------------------------------------------------------
605
Jim Inghamda26bd22012-06-08 21:56:10 +0000606class CommandObjectThreadContinue : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000607{
608public:
609
Greg Clayton238c0a12010-09-18 01:14:36 +0000610 CommandObjectThreadContinue (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000611 CommandObjectParsed (interpreter,
612 "thread continue",
613 "Continue execution of one or more threads in an active process.",
614 NULL,
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000615 eFlagRequiresThread |
616 eFlagTryTargetAPILock |
617 eFlagProcessMustBeLaunched |
618 eFlagProcessMustBePaused)
Chris Lattner24943d22010-06-08 16:52:24 +0000619 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000620 CommandArgumentEntry arg;
621 CommandArgumentData thread_idx_arg;
622
623 // Define the first (and only) variant of this arg.
624 thread_idx_arg.arg_type = eArgTypeThreadIndex;
625 thread_idx_arg.arg_repetition = eArgRepeatPlus;
626
627 // There is only one variant this argument could be; put it into the argument entry.
628 arg.push_back (thread_idx_arg);
629
630 // Push the data for the first argument into the m_arguments vector.
631 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000632 }
633
634
635 virtual
636 ~CommandObjectThreadContinue ()
637 {
638 }
639
640 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000641 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000642 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000643 bool synchronous_execution = m_interpreter.GetSynchronous ();
Chris Lattner24943d22010-06-08 16:52:24 +0000644
Greg Clayton238c0a12010-09-18 01:14:36 +0000645 if (!m_interpreter.GetDebugger().GetSelectedTarget().get())
Chris Lattner24943d22010-06-08 16:52:24 +0000646 {
Greg Claytone1f50b92011-05-03 22:09:39 +0000647 result.AppendError ("invalid target, create a debug target using the 'target create' command");
Chris Lattner24943d22010-06-08 16:52:24 +0000648 result.SetStatus (eReturnStatusFailed);
649 return false;
650 }
651
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000652 Process *process = m_exe_ctx.GetProcessPtr();
Chris Lattner24943d22010-06-08 16:52:24 +0000653 if (process == NULL)
654 {
655 result.AppendError ("no process exists. Cannot continue");
656 result.SetStatus (eReturnStatusFailed);
657 return false;
658 }
659
660 StateType state = process->GetState();
661 if ((state == eStateCrashed) || (state == eStateStopped) || (state == eStateSuspended))
662 {
Greg Claytonedd601a2012-07-03 20:54:16 +0000663 Mutex::Locker locker (process->GetThreadList().GetMutex());
Chris Lattner24943d22010-06-08 16:52:24 +0000664 const uint32_t num_threads = process->GetThreadList().GetSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000665 const size_t argc = command.GetArgumentCount();
666 if (argc > 0)
667 {
Greg Claytonedd601a2012-07-03 20:54:16 +0000668 std::vector<Thread *> resume_threads;
Chris Lattner24943d22010-06-08 16:52:24 +0000669 for (uint32_t i=0; i<argc; ++i)
670 {
Jim Inghamd07b4f52012-05-31 20:48:41 +0000671 bool success;
672 const int base = 0;
Greg Claytonedd601a2012-07-03 20:54:16 +0000673 uint32_t thread_idx = Args::StringToUInt32 (command.GetArgumentAtIndex(i), LLDB_INVALID_INDEX32, base, &success);
674 if (success)
Jim Inghamd07b4f52012-05-31 20:48:41 +0000675 {
Greg Claytonedd601a2012-07-03 20:54:16 +0000676 Thread *thread = process->GetThreadList().FindThreadByIndexID(thread_idx).get();
677
678 if (thread)
679 {
680 resume_threads.push_back(thread);
681 }
682 else
683 {
684 result.AppendErrorWithFormat("invalid thread index %u.\n", thread_idx);
685 result.SetStatus (eReturnStatusFailed);
686 return false;
687 }
Jim Inghamd07b4f52012-05-31 20:48:41 +0000688 }
Chris Lattner24943d22010-06-08 16:52:24 +0000689 else
Jim Inghamd07b4f52012-05-31 20:48:41 +0000690 {
Greg Claytonedd601a2012-07-03 20:54:16 +0000691 result.AppendErrorWithFormat ("invalid thread index argument: \"%s\".\n", command.GetArgumentAtIndex(i));
Jim Inghamd07b4f52012-05-31 20:48:41 +0000692 result.SetStatus (eReturnStatusFailed);
693 return false;
694 }
Chris Lattner24943d22010-06-08 16:52:24 +0000695 }
Greg Claytonedd601a2012-07-03 20:54:16 +0000696
697 if (resume_threads.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000698 {
699 result.AppendError ("no valid thread indexes were specified");
700 result.SetStatus (eReturnStatusFailed);
701 return false;
702 }
703 else
704 {
Greg Claytonedd601a2012-07-03 20:54:16 +0000705 if (resume_threads.size() == 1)
Jim Inghamd07b4f52012-05-31 20:48:41 +0000706 result.AppendMessageWithFormat ("Resuming thread: ");
707 else
708 result.AppendMessageWithFormat ("Resuming threads: ");
Greg Claytonedd601a2012-07-03 20:54:16 +0000709
710 for (uint32_t idx=0; idx<num_threads; ++idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000711 {
Greg Claytonedd601a2012-07-03 20:54:16 +0000712 Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
713 std::vector<Thread *>::iterator this_thread_pos = find(resume_threads.begin(), resume_threads.end(), thread);
Jim Inghamd07b4f52012-05-31 20:48:41 +0000714
Greg Claytonedd601a2012-07-03 20:54:16 +0000715 if (this_thread_pos != resume_threads.end())
Chris Lattner24943d22010-06-08 16:52:24 +0000716 {
Greg Claytonedd601a2012-07-03 20:54:16 +0000717 resume_threads.erase(this_thread_pos);
718 if (resume_threads.size() > 0)
Jim Inghamd07b4f52012-05-31 20:48:41 +0000719 result.AppendMessageWithFormat ("%u, ", thread->GetIndexID());
720 else
721 result.AppendMessageWithFormat ("%u ", thread->GetIndexID());
722
Chris Lattner24943d22010-06-08 16:52:24 +0000723 thread->SetResumeState (eStateRunning);
724 }
725 else
726 {
727 thread->SetResumeState (eStateSuspended);
728 }
729 }
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000730 result.AppendMessageWithFormat ("in process %" PRIu64 "\n", process->GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000731 }
732 }
733 else
734 {
Jim Inghamc8332952010-08-26 21:32:51 +0000735 Thread *current_thread = process->GetThreadList().GetSelectedThread().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000736 if (current_thread == NULL)
737 {
738 result.AppendError ("the process doesn't have a current thread");
739 result.SetStatus (eReturnStatusFailed);
740 return false;
741 }
742 // Set the actions that the threads should each take when resuming
Greg Claytonedd601a2012-07-03 20:54:16 +0000743 for (uint32_t idx=0; idx<num_threads; ++idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000744 {
Greg Claytonedd601a2012-07-03 20:54:16 +0000745 Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000746 if (thread == current_thread)
747 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000748 result.AppendMessageWithFormat ("Resuming thread 0x%4.4" PRIx64 " in process %" PRIu64 "\n", thread->GetID(), process->GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000749 thread->SetResumeState (eStateRunning);
750 }
751 else
752 {
753 thread->SetResumeState (eStateSuspended);
754 }
755 }
756 }
Greg Claytonedd601a2012-07-03 20:54:16 +0000757
Chris Lattner24943d22010-06-08 16:52:24 +0000758 Error error (process->Resume());
759 if (error.Success())
760 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000761 result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000762 if (synchronous_execution)
763 {
Greg Claytonbef15832010-07-14 00:18:15 +0000764 state = process->WaitForProcessToStop (NULL);
Greg Claytonedd601a2012-07-03 20:54:16 +0000765
Chris Lattner24943d22010-06-08 16:52:24 +0000766 result.SetDidChangeProcessState (true);
Daniel Malea5f35a4b2012-11-29 21:49:15 +0000767 result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state));
Chris Lattner24943d22010-06-08 16:52:24 +0000768 result.SetStatus (eReturnStatusSuccessFinishNoResult);
769 }
770 else
771 {
772 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
773 }
774 }
775 else
776 {
777 result.AppendErrorWithFormat("Failed to resume process: %s\n", error.AsCString());
778 result.SetStatus (eReturnStatusFailed);
779 }
780 }
781 else
782 {
783 result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n",
784 StateAsCString(state));
785 result.SetStatus (eReturnStatusFailed);
786 }
787
788 return result.Succeeded();
789 }
790
791};
792
793//-------------------------------------------------------------------------
794// CommandObjectThreadUntil
795//-------------------------------------------------------------------------
796
Jim Inghamda26bd22012-06-08 21:56:10 +0000797class CommandObjectThreadUntil : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +0000798{
799public:
800
801 class CommandOptions : public Options
802 {
803 public:
804 uint32_t m_thread_idx;
805 uint32_t m_frame_idx;
806
Greg Claytonf15996e2011-04-07 22:46:35 +0000807 CommandOptions (CommandInterpreter &interpreter) :
808 Options (interpreter),
Chris Lattner24943d22010-06-08 16:52:24 +0000809 m_thread_idx(LLDB_INVALID_THREAD_ID),
810 m_frame_idx(LLDB_INVALID_FRAME_ID)
811 {
Greg Clayton143fcc32011-04-13 00:18:08 +0000812 // Keep default values of all options in one place: OptionParsingStarting ()
813 OptionParsingStarting ();
Chris Lattner24943d22010-06-08 16:52:24 +0000814 }
815
816 virtual
817 ~CommandOptions ()
818 {
819 }
820
821 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000822 SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +0000823 {
824 Error error;
Greg Clayton6475c422012-12-04 00:32:51 +0000825 const int short_option = m_getopt_table[option_idx].val;
Chris Lattner24943d22010-06-08 16:52:24 +0000826
827 switch (short_option)
828 {
829 case 't':
830 {
Greg Claytonbef15832010-07-14 00:18:15 +0000831 m_thread_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_INDEX32);
Chris Lattner24943d22010-06-08 16:52:24 +0000832 if (m_thread_idx == LLDB_INVALID_INDEX32)
833 {
Greg Clayton9c236732011-10-26 00:56:27 +0000834 error.SetErrorStringWithFormat ("invalid thread index '%s'", option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000835 }
836 }
837 break;
838 case 'f':
839 {
840 m_frame_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_FRAME_ID);
841 if (m_frame_idx == LLDB_INVALID_FRAME_ID)
842 {
Greg Clayton9c236732011-10-26 00:56:27 +0000843 error.SetErrorStringWithFormat ("invalid frame index '%s'", option_arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000844 }
845 }
846 break;
847 case 'm':
848 {
Chris Lattner24943d22010-06-08 16:52:24 +0000849 OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
Greg Clayton61aca5d2011-10-07 18:58:12 +0000850 lldb::RunMode run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, error);
Chris Lattner24943d22010-06-08 16:52:24 +0000851
Greg Clayton61aca5d2011-10-07 18:58:12 +0000852 if (error.Success())
853 {
854 if (run_mode == eAllThreads)
855 m_stop_others = false;
856 else
857 m_stop_others = true;
858 }
Chris Lattner24943d22010-06-08 16:52:24 +0000859 }
860 break;
861 default:
Greg Clayton9c236732011-10-26 00:56:27 +0000862 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
Chris Lattner24943d22010-06-08 16:52:24 +0000863 break;
864
865 }
866 return error;
867 }
868
869 void
Greg Clayton143fcc32011-04-13 00:18:08 +0000870 OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +0000871 {
Chris Lattner24943d22010-06-08 16:52:24 +0000872 m_thread_idx = LLDB_INVALID_THREAD_ID;
873 m_frame_idx = 0;
874 m_stop_others = false;
875 }
876
Greg Claytonb3448432011-03-24 21:19:54 +0000877 const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +0000878 GetDefinitions ()
879 {
880 return g_option_table;
881 }
882
883 uint32_t m_step_thread_idx;
884 bool m_stop_others;
885
886 // Options table: Required for subclasses of Options.
887
Greg Claytonb3448432011-03-24 21:19:54 +0000888 static OptionDefinition g_option_table[];
Chris Lattner24943d22010-06-08 16:52:24 +0000889
890 // Instance variables to hold the values for command options.
891 };
892
Greg Clayton238c0a12010-09-18 01:14:36 +0000893 CommandObjectThreadUntil (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +0000894 CommandObjectParsed (interpreter,
895 "thread until",
896 "Run the current or specified thread until it reaches a given line number or leaves the current function.",
897 NULL,
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000898 eFlagRequiresThread |
899 eFlagTryTargetAPILock |
900 eFlagProcessMustBeLaunched |
901 eFlagProcessMustBePaused ),
Greg Claytonf15996e2011-04-07 22:46:35 +0000902 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000903 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000904 CommandArgumentEntry arg;
905 CommandArgumentData line_num_arg;
906
907 // Define the first (and only) variant of this arg.
908 line_num_arg.arg_type = eArgTypeLineNum;
909 line_num_arg.arg_repetition = eArgRepeatPlain;
910
911 // There is only one variant this argument could be; put it into the argument entry.
912 arg.push_back (line_num_arg);
913
914 // Push the data for the first argument into the m_arguments vector.
915 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +0000916 }
917
918
919 virtual
920 ~CommandObjectThreadUntil ()
921 {
922 }
923
924 virtual
925 Options *
926 GetOptions ()
927 {
928 return &m_options;
929 }
930
Jim Inghamda26bd22012-06-08 21:56:10 +0000931protected:
Chris Lattner24943d22010-06-08 16:52:24 +0000932 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +0000933 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +0000934 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000935 bool synchronous_execution = m_interpreter.GetSynchronous ();
Chris Lattner24943d22010-06-08 16:52:24 +0000936
Greg Clayton238c0a12010-09-18 01:14:36 +0000937 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Greg Claytoneea26402010-09-14 23:36:40 +0000938 if (target == NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000939 {
Greg Claytone1f50b92011-05-03 22:09:39 +0000940 result.AppendError ("invalid target, create a debug target using the 'target create' command");
Chris Lattner24943d22010-06-08 16:52:24 +0000941 result.SetStatus (eReturnStatusFailed);
942 return false;
943 }
944
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000945 Process *process = m_exe_ctx.GetProcessPtr();
Chris Lattner24943d22010-06-08 16:52:24 +0000946 if (process == NULL)
947 {
948 result.AppendError ("need a valid process to step");
949 result.SetStatus (eReturnStatusFailed);
950
951 }
952 else
953 {
954 Thread *thread = NULL;
955 uint32_t line_number;
956
957 if (command.GetArgumentCount() != 1)
958 {
959 result.AppendErrorWithFormat ("No line number provided:\n%s", GetSyntax());
960 result.SetStatus (eReturnStatusFailed);
961 return false;
962 }
963
964 line_number = Args::StringToUInt32 (command.GetArgumentAtIndex(0), UINT32_MAX);
965 if (line_number == UINT32_MAX)
966 {
Greg Clayton9c236732011-10-26 00:56:27 +0000967 result.AppendErrorWithFormat ("invalid line number: '%s'.\n", command.GetArgumentAtIndex(0));
Chris Lattner24943d22010-06-08 16:52:24 +0000968 result.SetStatus (eReturnStatusFailed);
969 return false;
970 }
971
972 if (m_options.m_thread_idx == LLDB_INVALID_THREAD_ID)
973 {
Jim Inghamc8332952010-08-26 21:32:51 +0000974 thread = process->GetThreadList().GetSelectedThread().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000975 }
976 else
977 {
Greg Claytona2243772012-05-31 00:29:20 +0000978 thread = process->GetThreadList().FindThreadByIndexID(m_options.m_thread_idx).get();
Chris Lattner24943d22010-06-08 16:52:24 +0000979 }
980
981 if (thread == NULL)
982 {
983 const uint32_t num_threads = process->GetThreadList().GetSize();
Jim Inghamb07c62a2011-05-08 00:56:32 +0000984 result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n",
985 m_options.m_thread_idx,
Jim Inghamb07c62a2011-05-08 00:56:32 +0000986 num_threads);
Chris Lattner24943d22010-06-08 16:52:24 +0000987 result.SetStatus (eReturnStatusFailed);
988 return false;
989 }
990
Jim Inghamd82bc6d2012-05-11 23:47:32 +0000991 const bool abort_other_plans = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000992
993 StackFrame *frame = thread->GetStackFrameAtIndex(m_options.m_frame_idx).get();
994 if (frame == NULL)
995 {
996
Jim Inghamb07c62a2011-05-08 00:56:32 +0000997 result.AppendErrorWithFormat ("Frame index %u is out of range for thread %u.\n",
998 m_options.m_frame_idx,
999 m_options.m_thread_idx);
Chris Lattner24943d22010-06-08 16:52:24 +00001000 result.SetStatus (eReturnStatusFailed);
1001 return false;
1002 }
1003
Jim Ingham88e3de22012-05-03 21:19:36 +00001004 ThreadPlan *new_plan = NULL;
Chris Lattner24943d22010-06-08 16:52:24 +00001005
1006 if (frame->HasDebugInformation ())
1007 {
1008 // Finally we got here... Translate the given line number to a bunch of addresses:
1009 SymbolContext sc(frame->GetSymbolContext (eSymbolContextCompUnit));
1010 LineTable *line_table = NULL;
1011 if (sc.comp_unit)
1012 line_table = sc.comp_unit->GetLineTable();
1013
1014 if (line_table == NULL)
1015 {
1016 result.AppendErrorWithFormat ("Failed to resolve the line table for frame %u of thread index %u.\n",
1017 m_options.m_frame_idx, m_options.m_thread_idx);
1018 result.SetStatus (eReturnStatusFailed);
1019 return false;
1020 }
1021
1022 LineEntry function_start;
1023 uint32_t index_ptr = 0, end_ptr;
1024 std::vector<addr_t> address_list;
1025
1026 // Find the beginning & end index of the
1027 AddressRange fun_addr_range = sc.function->GetAddressRange();
1028 Address fun_start_addr = fun_addr_range.GetBaseAddress();
1029 line_table->FindLineEntryByAddress (fun_start_addr, function_start, &index_ptr);
1030
Jim Inghamb07c62a2011-05-08 00:56:32 +00001031 Address fun_end_addr(fun_start_addr.GetSection(),
1032 fun_start_addr.GetOffset() + fun_addr_range.GetByteSize());
Chris Lattner24943d22010-06-08 16:52:24 +00001033 line_table->FindLineEntryByAddress (fun_end_addr, function_start, &end_ptr);
1034
Jim Inghamb07c62a2011-05-08 00:56:32 +00001035 bool all_in_function = true;
1036
Chris Lattner24943d22010-06-08 16:52:24 +00001037 while (index_ptr <= end_ptr)
1038 {
1039 LineEntry line_entry;
Jim Inghamd6d47972011-09-23 00:54:11 +00001040 const bool exact = false;
1041 index_ptr = sc.comp_unit->FindLineEntry(index_ptr, line_number, sc.comp_unit, exact, &line_entry);
Chris Lattner24943d22010-06-08 16:52:24 +00001042 if (index_ptr == UINT32_MAX)
1043 break;
1044
Greg Claytoneea26402010-09-14 23:36:40 +00001045 addr_t address = line_entry.range.GetBaseAddress().GetLoadAddress(target);
Chris Lattner24943d22010-06-08 16:52:24 +00001046 if (address != LLDB_INVALID_ADDRESS)
Jim Inghamb07c62a2011-05-08 00:56:32 +00001047 {
1048 if (fun_addr_range.ContainsLoadAddress (address, target))
1049 address_list.push_back (address);
1050 else
1051 all_in_function = false;
1052 }
Chris Lattner24943d22010-06-08 16:52:24 +00001053 index_ptr++;
1054 }
1055
Jim Inghamb07c62a2011-05-08 00:56:32 +00001056 if (address_list.size() == 0)
1057 {
1058 if (all_in_function)
1059 result.AppendErrorWithFormat ("No line entries matching until target.\n");
1060 else
1061 result.AppendErrorWithFormat ("Until target outside of the current function.\n");
1062
1063 result.SetStatus (eReturnStatusFailed);
1064 return false;
1065 }
1066
1067 new_plan = thread->QueueThreadPlanForStepUntil (abort_other_plans,
1068 &address_list.front(),
1069 address_list.size(),
1070 m_options.m_stop_others,
Jim Inghamfade78a2012-09-14 20:48:14 +00001071 m_options.m_frame_idx);
Jim Ingham88e3de22012-05-03 21:19:36 +00001072 // User level plans should be master plans so they can be interrupted (e.g. by hitting a breakpoint)
1073 // and other plans executed by the user (stepping around the breakpoint) and then a "continue"
1074 // will resume the original plan.
1075 new_plan->SetIsMasterPlan (true);
Chris Lattner24943d22010-06-08 16:52:24 +00001076 new_plan->SetOkayToDiscard(false);
1077 }
1078 else
1079 {
Jim Inghamb07c62a2011-05-08 00:56:32 +00001080 result.AppendErrorWithFormat ("Frame index %u of thread %u has no debug information.\n",
1081 m_options.m_frame_idx,
1082 m_options.m_thread_idx);
Chris Lattner24943d22010-06-08 16:52:24 +00001083 result.SetStatus (eReturnStatusFailed);
1084 return false;
1085
1086 }
1087
Jim Inghamc8332952010-08-26 21:32:51 +00001088 process->GetThreadList().SetSelectedThreadByID (m_options.m_thread_idx);
Chris Lattner24943d22010-06-08 16:52:24 +00001089 Error error (process->Resume ());
1090 if (error.Success())
1091 {
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001092 result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID());
Chris Lattner24943d22010-06-08 16:52:24 +00001093 if (synchronous_execution)
1094 {
1095 StateType state = process->WaitForProcessToStop (NULL);
1096
1097 result.SetDidChangeProcessState (true);
Daniel Malea5f35a4b2012-11-29 21:49:15 +00001098 result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state));
Chris Lattner24943d22010-06-08 16:52:24 +00001099 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1100 }
1101 else
1102 {
1103 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
1104 }
1105 }
1106 else
1107 {
1108 result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString());
1109 result.SetStatus (eReturnStatusFailed);
1110 }
1111
1112 }
1113 return result.Succeeded();
1114 }
Jim Inghamda26bd22012-06-08 21:56:10 +00001115
Chris Lattner24943d22010-06-08 16:52:24 +00001116 CommandOptions m_options;
1117
1118};
1119
Greg Claytonb3448432011-03-24 21:19:54 +00001120OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +00001121CommandObjectThreadUntil::CommandOptions::g_option_table[] =
1122{
Caroline Tice43b014a2010-10-04 22:28:36 +00001123{ LLDB_OPT_SET_1, false, "frame", 'f', required_argument, NULL, 0, eArgTypeFrameIndex, "Frame index for until operation - defaults to 0"},
Caroline Tice4d6675c2010-10-01 19:59:14 +00001124{ LLDB_OPT_SET_1, false, "thread", 't', required_argument, NULL, 0, eArgTypeThreadIndex, "Thread index for the thread for until operation"},
1125{ LLDB_OPT_SET_1, false, "run-mode",'m', required_argument, g_duo_running_mode, 0, eArgTypeRunMode,"Determine how to run other threads while stepping this one"},
1126{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +00001127};
1128
1129
1130//-------------------------------------------------------------------------
1131// CommandObjectThreadSelect
1132//-------------------------------------------------------------------------
1133
Jim Inghamda26bd22012-06-08 21:56:10 +00001134class CommandObjectThreadSelect : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +00001135{
1136public:
1137
Greg Clayton238c0a12010-09-18 01:14:36 +00001138 CommandObjectThreadSelect (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +00001139 CommandObjectParsed (interpreter,
1140 "thread select",
1141 "Select a thread as the currently active thread.",
1142 NULL,
Greg Claytonea0bb4d2013-01-09 19:44:40 +00001143 eFlagRequiresProcess |
1144 eFlagTryTargetAPILock |
1145 eFlagProcessMustBeLaunched |
1146 eFlagProcessMustBePaused )
Chris Lattner24943d22010-06-08 16:52:24 +00001147 {
Caroline Tice43b014a2010-10-04 22:28:36 +00001148 CommandArgumentEntry arg;
1149 CommandArgumentData thread_idx_arg;
1150
1151 // Define the first (and only) variant of this arg.
1152 thread_idx_arg.arg_type = eArgTypeThreadIndex;
1153 thread_idx_arg.arg_repetition = eArgRepeatPlain;
1154
1155 // There is only one variant this argument could be; put it into the argument entry.
1156 arg.push_back (thread_idx_arg);
1157
1158 // Push the data for the first argument into the m_arguments vector.
1159 m_arguments.push_back (arg);
Chris Lattner24943d22010-06-08 16:52:24 +00001160 }
1161
1162
1163 virtual
1164 ~CommandObjectThreadSelect ()
1165 {
1166 }
1167
Jim Inghamda26bd22012-06-08 21:56:10 +00001168protected:
Chris Lattner24943d22010-06-08 16:52:24 +00001169 virtual bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001170 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +00001171 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +00001172 Process *process = m_exe_ctx.GetProcessPtr();
Chris Lattner24943d22010-06-08 16:52:24 +00001173 if (process == NULL)
1174 {
1175 result.AppendError ("no process");
1176 result.SetStatus (eReturnStatusFailed);
1177 return false;
1178 }
1179 else if (command.GetArgumentCount() != 1)
1180 {
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001181 result.AppendErrorWithFormat("'%s' takes exactly one thread index argument:\nUsage: %s\n", m_cmd_name.c_str(), m_cmd_syntax.c_str());
Chris Lattner24943d22010-06-08 16:52:24 +00001182 result.SetStatus (eReturnStatusFailed);
1183 return false;
1184 }
1185
1186 uint32_t index_id = Args::StringToUInt32(command.GetArgumentAtIndex(0), 0, 0);
1187
1188 Thread *new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get();
1189 if (new_thread == NULL)
1190 {
Greg Clayton9c236732011-10-26 00:56:27 +00001191 result.AppendErrorWithFormat ("invalid thread #%s.\n", command.GetArgumentAtIndex(0));
Chris Lattner24943d22010-06-08 16:52:24 +00001192 result.SetStatus (eReturnStatusFailed);
1193 return false;
1194 }
1195
Jim Ingham2e281232012-12-11 02:31:48 +00001196 process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true);
Johnny Chen8dbb6e82010-09-14 00:53:53 +00001197 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +00001198
Chris Lattner24943d22010-06-08 16:52:24 +00001199 return result.Succeeded();
1200 }
1201
1202};
1203
1204
1205//-------------------------------------------------------------------------
1206// CommandObjectThreadList
1207//-------------------------------------------------------------------------
1208
Jim Inghamda26bd22012-06-08 21:56:10 +00001209class CommandObjectThreadList : public CommandObjectParsed
Chris Lattner24943d22010-06-08 16:52:24 +00001210{
Greg Clayton63094e02010-06-23 01:19:29 +00001211public:
Chris Lattner24943d22010-06-08 16:52:24 +00001212
Chris Lattner24943d22010-06-08 16:52:24 +00001213
Greg Clayton238c0a12010-09-18 01:14:36 +00001214 CommandObjectThreadList (CommandInterpreter &interpreter):
Jim Inghamda26bd22012-06-08 21:56:10 +00001215 CommandObjectParsed (interpreter,
1216 "thread list",
1217 "Show a summary of all current threads in a process.",
1218 "thread list",
Greg Claytonea0bb4d2013-01-09 19:44:40 +00001219 eFlagRequiresProcess |
1220 eFlagTryTargetAPILock |
1221 eFlagProcessMustBeLaunched |
1222 eFlagProcessMustBePaused )
Chris Lattner24943d22010-06-08 16:52:24 +00001223 {
Greg Clayton63094e02010-06-23 01:19:29 +00001224 }
Chris Lattner24943d22010-06-08 16:52:24 +00001225
Greg Clayton63094e02010-06-23 01:19:29 +00001226 ~CommandObjectThreadList()
1227 {
1228 }
1229
Jim Inghamda26bd22012-06-08 21:56:10 +00001230protected:
Greg Clayton63094e02010-06-23 01:19:29 +00001231 bool
Jim Inghamda26bd22012-06-08 21:56:10 +00001232 DoExecute (Args& command, CommandReturnObject &result)
Greg Clayton63094e02010-06-23 01:19:29 +00001233 {
Jim Ingham2e8cb8a2011-02-19 02:53:09 +00001234 Stream &strm = result.GetOutputStream();
Greg Clayton63094e02010-06-23 01:19:29 +00001235 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Greg Claytonea0bb4d2013-01-09 19:44:40 +00001236 Process *process = m_exe_ctx.GetProcessPtr();
1237 const bool only_threads_with_stop_reason = false;
1238 const uint32_t start_frame = 0;
1239 const uint32_t num_frames = 0;
1240 const uint32_t num_frames_with_source = 0;
1241 process->GetStatus(strm);
1242 process->GetThreadStatus (strm,
1243 only_threads_with_stop_reason,
1244 start_frame,
1245 num_frames,
1246 num_frames_with_source);
Greg Clayton63094e02010-06-23 01:19:29 +00001247 return result.Succeeded();
Chris Lattner24943d22010-06-08 16:52:24 +00001248 }
Greg Clayton63094e02010-06-23 01:19:29 +00001249};
Chris Lattner24943d22010-06-08 16:52:24 +00001250
Jim Inghambe51f8a2013-01-31 21:46:01 +00001251//-------------------------------------------------------------------------
1252// CommandObjectThreadReturn
1253//-------------------------------------------------------------------------
1254
Jim Inghamf59388a2012-09-14 02:14:15 +00001255class CommandObjectThreadReturn : public CommandObjectRaw
1256{
1257public:
Jim Inghambe51f8a2013-01-31 21:46:01 +00001258 class CommandOptions : public Options
1259 {
1260 public:
1261
1262 CommandOptions (CommandInterpreter &interpreter) :
1263 Options (interpreter),
1264 m_from_expression (false)
1265 {
1266 // Keep default values of all options in one place: OptionParsingStarting ()
1267 OptionParsingStarting ();
1268 }
1269
1270 virtual
1271 ~CommandOptions ()
1272 {
1273 }
1274
1275 virtual Error
1276 SetOptionValue (uint32_t option_idx, const char *option_arg)
1277 {
1278 Error error;
1279 const int short_option = m_getopt_table[option_idx].val;
1280
1281 switch (short_option)
1282 {
1283 case 'x':
1284 {
1285 bool success;
1286 bool tmp_value = Args::StringToBoolean (option_arg, false, &success);
1287 if (success)
1288 m_from_expression = tmp_value;
1289 else
1290 {
1291 error.SetErrorStringWithFormat ("invalid boolean value '%s' for 'x' option", option_arg);
1292 }
1293 }
1294 break;
1295 default:
1296 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
1297 break;
1298
1299 }
1300 return error;
1301 }
1302
1303 void
1304 OptionParsingStarting ()
1305 {
1306 m_from_expression = false;
1307 }
1308
1309 const OptionDefinition*
1310 GetDefinitions ()
1311 {
1312 return g_option_table;
1313 }
1314
1315 bool m_from_expression;
1316
1317 // Options table: Required for subclasses of Options.
1318
1319 static OptionDefinition g_option_table[];
1320
1321 // Instance variables to hold the values for command options.
1322 };
1323
1324 virtual
1325 Options *
1326 GetOptions ()
1327 {
1328 return &m_options;
1329 }
1330
Jim Inghamf59388a2012-09-14 02:14:15 +00001331 CommandObjectThreadReturn (CommandInterpreter &interpreter) :
1332 CommandObjectRaw (interpreter,
1333 "thread return",
Jim Inghambe51f8a2013-01-31 21:46:01 +00001334 "Return from the currently selected frame, short-circuiting execution of the frames below it, with an optional return value,"
1335 " or with the -x option from the innermost function evaluation.",
Jim Inghamf59388a2012-09-14 02:14:15 +00001336 "thread return",
Greg Claytonea0bb4d2013-01-09 19:44:40 +00001337 eFlagRequiresFrame |
1338 eFlagTryTargetAPILock |
1339 eFlagProcessMustBeLaunched |
Jim Inghambe51f8a2013-01-31 21:46:01 +00001340 eFlagProcessMustBePaused ),
1341 m_options (interpreter)
Jim Inghamf59388a2012-09-14 02:14:15 +00001342 {
1343 CommandArgumentEntry arg;
1344 CommandArgumentData expression_arg;
1345
1346 // Define the first (and only) variant of this arg.
1347 expression_arg.arg_type = eArgTypeExpression;
Jim Inghambe51f8a2013-01-31 21:46:01 +00001348 expression_arg.arg_repetition = eArgRepeatOptional;
Jim Inghamf59388a2012-09-14 02:14:15 +00001349
1350 // There is only one variant this argument could be; put it into the argument entry.
1351 arg.push_back (expression_arg);
1352
1353 // Push the data for the first argument into the m_arguments vector.
1354 m_arguments.push_back (arg);
1355
1356
1357 }
1358
1359 ~CommandObjectThreadReturn()
1360 {
1361 }
1362
1363protected:
1364
1365 bool DoExecute
1366 (
1367 const char *command,
1368 CommandReturnObject &result
1369 )
1370 {
Jim Inghambe51f8a2013-01-31 21:46:01 +00001371 // I am going to handle this by hand, because I don't want you to have to say:
1372 // "thread return -- -5".
1373 if (command[0] == '-' && command[1] == 'x')
1374 {
1375 if (command && command[2] != '\0')
1376 result.AppendWarning("Return values ignored when returning from user called expressions");
1377
1378 Thread *thread = m_exe_ctx.GetThreadPtr();
1379 Error error;
1380 error = thread->UnwindInnermostExpression();
1381 if (!error.Success())
1382 {
1383 result.AppendErrorWithFormat ("Unwinding expression failed - %s.", error.AsCString());
1384 result.SetStatus (eReturnStatusFailed);
1385 }
1386 else
1387 {
1388 bool success = thread->SetSelectedFrameByIndexNoisily (0, result.GetOutputStream());
1389 if (success)
1390 {
1391 m_exe_ctx.SetFrameSP(thread->GetSelectedFrame ());
1392 result.SetStatus (eReturnStatusSuccessFinishResult);
1393 }
1394 else
1395 {
1396 result.AppendErrorWithFormat ("Could not select 0th frame after unwinding expression.");
1397 result.SetStatus (eReturnStatusFailed);
1398 }
1399 }
1400 return result.Succeeded();
1401 }
1402
Jim Inghamf59388a2012-09-14 02:14:15 +00001403 ValueObjectSP return_valobj_sp;
1404
Greg Claytonea0bb4d2013-01-09 19:44:40 +00001405 StackFrameSP frame_sp = m_exe_ctx.GetFrameSP();
Jim Inghamf59388a2012-09-14 02:14:15 +00001406 uint32_t frame_idx = frame_sp->GetFrameIndex();
1407
1408 if (frame_sp->IsInlined())
1409 {
1410 result.AppendError("Don't know how to return from inlined frames.");
1411 result.SetStatus (eReturnStatusFailed);
1412 return false;
1413 }
1414
1415 if (command && command[0] != '\0')
1416 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +00001417 Target *target = m_exe_ctx.GetTargetPtr();
Jim Ingham47beabb2012-10-16 21:41:58 +00001418 EvaluateExpressionOptions options;
Jim Inghamf59388a2012-09-14 02:14:15 +00001419
1420 options.SetUnwindOnError(true);
1421 options.SetUseDynamic(eNoDynamicValues);
1422
1423 ExecutionResults exe_results = eExecutionSetupError;
1424 exe_results = target->EvaluateExpression (command,
1425 frame_sp.get(),
1426 return_valobj_sp,
1427 options);
1428 if (exe_results != eExecutionCompleted)
1429 {
1430 if (return_valobj_sp)
1431 result.AppendErrorWithFormat("Error evaluating result expression: %s", return_valobj_sp->GetError().AsCString());
1432 else
1433 result.AppendErrorWithFormat("Unknown error evaluating result expression.");
1434 result.SetStatus (eReturnStatusFailed);
1435 return false;
1436
1437 }
1438 }
1439
1440 Error error;
Greg Claytonea0bb4d2013-01-09 19:44:40 +00001441 ThreadSP thread_sp = m_exe_ctx.GetThreadSP();
Jim Ingham94a5d0d2012-10-10 18:32:14 +00001442 const bool broadcast = true;
1443 error = thread_sp->ReturnFromFrame (frame_sp, return_valobj_sp, broadcast);
Jim Inghamf59388a2012-09-14 02:14:15 +00001444 if (!error.Success())
1445 {
1446 result.AppendErrorWithFormat("Error returning from frame %d of thread %d: %s.", frame_idx, thread_sp->GetIndexID(), error.AsCString());
1447 result.SetStatus (eReturnStatusFailed);
1448 return false;
1449 }
1450
Jim Inghamf59388a2012-09-14 02:14:15 +00001451 result.SetStatus (eReturnStatusSuccessFinishResult);
1452 return true;
1453 }
Jim Inghambe51f8a2013-01-31 21:46:01 +00001454
1455 CommandOptions m_options;
Jim Inghamf59388a2012-09-14 02:14:15 +00001456
1457};
Jim Inghambe51f8a2013-01-31 21:46:01 +00001458OptionDefinition
1459CommandObjectThreadReturn::CommandOptions::g_option_table[] =
1460{
1461{ LLDB_OPT_SET_ALL, false, "from-expression", 'x', no_argument, NULL, 0, eArgTypeNone, "Return from the innermost expression evaluation."},
1462{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1463};
Jim Inghamf59388a2012-09-14 02:14:15 +00001464
Chris Lattner24943d22010-06-08 16:52:24 +00001465//-------------------------------------------------------------------------
1466// CommandObjectMultiwordThread
1467//-------------------------------------------------------------------------
1468
Greg Clayton63094e02010-06-23 01:19:29 +00001469CommandObjectMultiwordThread::CommandObjectMultiwordThread (CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00001470 CommandObjectMultiword (interpreter,
1471 "thread",
Caroline Ticec1ad82e2010-09-07 22:38:08 +00001472 "A set of commands for operating on one or more threads within a running process.",
Chris Lattner24943d22010-06-08 16:52:24 +00001473 "thread <subcommand> [<subcommand-options>]")
1474{
Greg Clayton238c0a12010-09-18 01:14:36 +00001475 LoadSubCommand ("backtrace", CommandObjectSP (new CommandObjectThreadBacktrace (interpreter)));
1476 LoadSubCommand ("continue", CommandObjectSP (new CommandObjectThreadContinue (interpreter)));
1477 LoadSubCommand ("list", CommandObjectSP (new CommandObjectThreadList (interpreter)));
Jim Inghamf59388a2012-09-14 02:14:15 +00001478 LoadSubCommand ("return", CommandObjectSP (new CommandObjectThreadReturn (interpreter)));
Greg Clayton238c0a12010-09-18 01:14:36 +00001479 LoadSubCommand ("select", CommandObjectSP (new CommandObjectThreadSelect (interpreter)));
1480 LoadSubCommand ("until", CommandObjectSP (new CommandObjectThreadUntil (interpreter)));
1481 LoadSubCommand ("step-in", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope (
1482 interpreter,
Greg Clayton63094e02010-06-23 01:19:29 +00001483 "thread step-in",
Greg Clayton238c0a12010-09-18 01:14:36 +00001484 "Source level single step in specified thread (current thread, if none specified).",
Caroline Tice43b014a2010-10-04 22:28:36 +00001485 NULL,
Greg Clayton238c0a12010-09-18 01:14:36 +00001486 eStepTypeInto,
1487 eStepScopeSource)));
Greg Clayton63094e02010-06-23 01:19:29 +00001488
Greg Clayton238c0a12010-09-18 01:14:36 +00001489 LoadSubCommand ("step-out", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope (
1490 interpreter,
1491 "thread step-out",
Jim Ingham1586d972011-12-17 01:35:57 +00001492 "Finish executing the function of the currently selected frame and return to its call site in specified thread (current thread, if none specified).",
Caroline Tice43b014a2010-10-04 22:28:36 +00001493 NULL,
Greg Clayton238c0a12010-09-18 01:14:36 +00001494 eStepTypeOut,
1495 eStepScopeSource)));
Chris Lattner24943d22010-06-08 16:52:24 +00001496
Greg Clayton238c0a12010-09-18 01:14:36 +00001497 LoadSubCommand ("step-over", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope (
1498 interpreter,
1499 "thread step-over",
1500 "Source level single step in specified thread (current thread, if none specified), stepping over calls.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001501 NULL,
Greg Clayton238c0a12010-09-18 01:14:36 +00001502 eStepTypeOver,
1503 eStepScopeSource)));
Chris Lattner24943d22010-06-08 16:52:24 +00001504
Greg Clayton238c0a12010-09-18 01:14:36 +00001505 LoadSubCommand ("step-inst", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope (
1506 interpreter,
1507 "thread step-inst",
1508 "Single step one instruction in specified thread (current thread, if none specified).",
Caroline Tice43b014a2010-10-04 22:28:36 +00001509 NULL,
Greg Clayton238c0a12010-09-18 01:14:36 +00001510 eStepTypeTrace,
1511 eStepScopeInstruction)));
Greg Clayton63094e02010-06-23 01:19:29 +00001512
Greg Clayton238c0a12010-09-18 01:14:36 +00001513 LoadSubCommand ("step-inst-over", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope (
1514 interpreter,
1515 "thread step-inst-over",
1516 "Single step one instruction in specified thread (current thread, if none specified), stepping over calls.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001517 NULL,
Greg Clayton238c0a12010-09-18 01:14:36 +00001518 eStepTypeTraceOver,
1519 eStepScopeInstruction)));
Chris Lattner24943d22010-06-08 16:52:24 +00001520}
1521
1522CommandObjectMultiwordThread::~CommandObjectMultiwordThread ()
1523{
1524}
1525
1526