Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "CommandObjectThread.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 18 | #include "lldb/lldb-private.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/State.h" |
| 20 | #include "lldb/Core/SourceManager.h" |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 21 | #include "lldb/Host/Host.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 23 | #include "lldb/Interpreter/CommandReturnObject.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 24 | #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 Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Process.h" |
| 30 | #include "lldb/Target/RegisterContext.h" |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 31 | #include "lldb/Target/SystemRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Target/Target.h" |
| 33 | #include "lldb/Target/Thread.h" |
| 34 | #include "lldb/Target/ThreadPlan.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 36 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 37 | #include "lldb/Target/ThreadPlanStepRange.h" |
| 38 | #include "lldb/Target/ThreadPlanStepInRange.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | |
| 41 | using namespace lldb; |
| 42 | using namespace lldb_private; |
| 43 | |
| 44 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | //------------------------------------------------------------------------- |
| 46 | // CommandObjectThreadBacktrace |
| 47 | //------------------------------------------------------------------------- |
| 48 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 49 | class CommandObjectThreadBacktrace : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | { |
| 51 | public: |
| 52 | |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 53 | class CommandOptions : public Options |
| 54 | { |
| 55 | public: |
| 56 | |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 57 | CommandOptions (CommandInterpreter &interpreter) : |
| 58 | Options(interpreter) |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 59 | { |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 60 | // Keep default values of all options in one place: OptionParsingStarting () |
| 61 | OptionParsingStarting (); |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | virtual |
| 65 | ~CommandOptions () |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | virtual Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 70 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 71 | { |
| 72 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 73 | const int short_option = m_getopt_table[option_idx].val; |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 74 | |
| 75 | switch (short_option) |
| 76 | { |
| 77 | case 'c': |
| 78 | { |
| 79 | bool success; |
| 80 | int32_t input_count = Args::StringToSInt32 (option_arg, -1, 0, &success); |
| 81 | if (!success) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 82 | error.SetErrorStringWithFormat("invalid integer value for option '%c'", short_option); |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 83 | if (input_count < -1) |
| 84 | m_count = UINT32_MAX; |
| 85 | else |
| 86 | m_count = input_count; |
| 87 | } |
| 88 | break; |
| 89 | case 's': |
| 90 | { |
| 91 | bool success; |
| 92 | m_start = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 93 | if (!success) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 94 | error.SetErrorStringWithFormat("invalid integer value for option '%c'", short_option); |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 95 | } |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 96 | case 'e': |
| 97 | { |
| 98 | bool success; |
| 99 | m_extended_backtrace = Args::StringToBoolean (option_arg, false, &success); |
| 100 | if (!success) |
| 101 | error.SetErrorStringWithFormat("invalid boolean value for option '%c'", short_option); |
| 102 | } |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 103 | break; |
| 104 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 105 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 106 | break; |
| 107 | |
| 108 | } |
| 109 | return error; |
| 110 | } |
| 111 | |
| 112 | void |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 113 | OptionParsingStarting () |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 114 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 115 | m_count = UINT32_MAX; |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 116 | m_start = 0; |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 117 | m_extended_backtrace = false; |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 120 | const OptionDefinition* |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 121 | GetDefinitions () |
| 122 | { |
| 123 | return g_option_table; |
| 124 | } |
| 125 | |
| 126 | // Options table: Required for subclasses of Options. |
| 127 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 128 | static OptionDefinition g_option_table[]; |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 129 | |
| 130 | // Instance variables to hold the values for command options. |
| 131 | uint32_t m_count; |
| 132 | uint32_t m_start; |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 133 | bool m_extended_backtrace; |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 136 | CommandObjectThreadBacktrace (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 137 | CommandObjectParsed (interpreter, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 138 | "thread backtrace", |
| 139 | "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.", |
| 140 | NULL, |
| 141 | eFlagRequiresProcess | |
| 142 | eFlagRequiresThread | |
| 143 | eFlagTryTargetAPILock | |
| 144 | eFlagProcessMustBeLaunched | |
| 145 | eFlagProcessMustBePaused ), |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 146 | m_options(interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 147 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 148 | CommandArgumentEntry arg; |
| 149 | CommandArgumentData thread_idx_arg; |
| 150 | |
| 151 | // Define the first (and only) variant of this arg. |
| 152 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 153 | thread_idx_arg.arg_repetition = eArgRepeatStar; |
| 154 | |
| 155 | // There is only one variant this argument could be; put it into the argument entry. |
| 156 | arg.push_back (thread_idx_arg); |
| 157 | |
| 158 | // Push the data for the first argument into the m_arguments vector. |
| 159 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | ~CommandObjectThreadBacktrace() |
| 163 | { |
| 164 | } |
| 165 | |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 166 | virtual Options * |
| 167 | GetOptions () |
| 168 | { |
| 169 | return &m_options; |
| 170 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 171 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 172 | protected: |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 173 | void |
| 174 | DoExtendedBacktrace (Thread *thread, CommandReturnObject &result) |
| 175 | { |
| 176 | SystemRuntime *runtime = thread->GetProcess()->GetSystemRuntime(); |
| 177 | if (runtime) |
| 178 | { |
| 179 | Stream &strm = result.GetOutputStream(); |
| 180 | const std::vector<ConstString> &types = runtime->GetExtendedBacktraceTypes(); |
| 181 | for (auto type : types) |
| 182 | { |
Jason Molenda | 008c45f | 2013-11-12 23:33:32 +0000 | [diff] [blame] | 183 | ThreadSP ext_thread_sp = runtime->GetExtendedBacktraceThread (thread->shared_from_this(), type); |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 184 | if (ext_thread_sp && ext_thread_sp->IsValid ()) |
| 185 | { |
| 186 | const uint32_t num_frames_with_source = 0; |
| 187 | if (ext_thread_sp->GetStatus (strm, |
| 188 | m_options.m_start, |
| 189 | m_options.m_count, |
| 190 | num_frames_with_source)) |
| 191 | { |
| 192 | DoExtendedBacktrace (ext_thread_sp.get(), result); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 199 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 200 | DoExecute (Args& command, CommandReturnObject &result) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 201 | { |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 202 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 203 | Stream &strm = result.GetOutputStream(); |
| 204 | |
| 205 | // Don't show source context when doing backtraces. |
| 206 | const uint32_t num_frames_with_source = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | if (command.GetArgumentCount() == 0) |
| 208 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 209 | Thread *thread = m_exe_ctx.GetThreadPtr(); |
| 210 | // Thread::GetStatus() returns the number of frames shown. |
| 211 | if (thread->GetStatus (strm, |
| 212 | m_options.m_start, |
| 213 | m_options.m_count, |
| 214 | num_frames_with_source)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 215 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 216 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 217 | if (m_options.m_extended_backtrace) |
| 218 | { |
| 219 | DoExtendedBacktrace (thread, result); |
| 220 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | } |
| 222 | } |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 223 | else if (command.GetArgumentCount() == 1 && ::strcmp (command.GetArgumentAtIndex(0), "all") == 0) |
| 224 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 225 | Process *process = m_exe_ctx.GetProcessPtr(); |
Sean Callanan | 5c19eac | 2013-11-06 19:28:40 +0000 | [diff] [blame] | 226 | uint32_t idx = 0; |
| 227 | for (ThreadSP thread_sp : process->Threads()) |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 228 | { |
Sean Callanan | 5c19eac | 2013-11-06 19:28:40 +0000 | [diff] [blame] | 229 | if (idx != 0) |
| 230 | result.AppendMessage(""); |
| 231 | |
Johnny Chen | f2ddc71 | 2011-06-01 23:19:52 +0000 | [diff] [blame] | 232 | if (!thread_sp->GetStatus (strm, |
| 233 | m_options.m_start, |
| 234 | m_options.m_count, |
| 235 | num_frames_with_source)) |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 236 | { |
Sean Callanan | 5c19eac | 2013-11-06 19:28:40 +0000 | [diff] [blame] | 237 | result.AppendErrorWithFormat ("error displaying backtrace for thread: \"0x%4.4x\"\n", idx); |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 238 | result.SetStatus (eReturnStatusFailed); |
| 239 | return false; |
| 240 | } |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 241 | if (m_options.m_extended_backtrace) |
| 242 | { |
| 243 | DoExtendedBacktrace (thread_sp.get(), result); |
| 244 | } |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 245 | |
Sean Callanan | 5c19eac | 2013-11-06 19:28:40 +0000 | [diff] [blame] | 246 | ++idx; |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 247 | } |
| 248 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | else |
| 250 | { |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 251 | const size_t num_args = command.GetArgumentCount(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 252 | Process *process = m_exe_ctx.GetProcessPtr(); |
Jim Ingham | 41f2b94 | 2012-09-10 20:50:15 +0000 | [diff] [blame] | 253 | Mutex::Locker locker (process->GetThreadList().GetMutex()); |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 254 | std::vector<ThreadSP> thread_sps; |
| 255 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 256 | for (size_t i = 0; i < num_args; i++) |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 257 | { |
| 258 | bool success; |
| 259 | |
| 260 | uint32_t thread_idx = Args::StringToUInt32(command.GetArgumentAtIndex(i), 0, 0, &success); |
| 261 | if (!success) |
| 262 | { |
| 263 | result.AppendErrorWithFormat ("invalid thread specification: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 264 | result.SetStatus (eReturnStatusFailed); |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | thread_sps.push_back(process->GetThreadList().FindThreadByIndexID(thread_idx)); |
| 269 | |
| 270 | if (!thread_sps[i]) |
| 271 | { |
| 272 | result.AppendErrorWithFormat ("no thread with index: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 273 | result.SetStatus (eReturnStatusFailed); |
| 274 | return false; |
| 275 | } |
| 276 | |
| 277 | } |
| 278 | |
| 279 | for (uint32_t i = 0; i < num_args; i++) |
| 280 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 281 | if (!thread_sps[i]->GetStatus (strm, |
| 282 | m_options.m_start, |
| 283 | m_options.m_count, |
| 284 | num_frames_with_source)) |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 285 | { |
| 286 | result.AppendErrorWithFormat ("error displaying backtrace for thread: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 287 | result.SetStatus (eReturnStatusFailed); |
| 288 | return false; |
| 289 | } |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 290 | if (m_options.m_extended_backtrace) |
| 291 | { |
| 292 | DoExtendedBacktrace (thread_sps[i].get(), result); |
| 293 | } |
Jim Ingham | 09b263e | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 294 | |
| 295 | if (i < num_args - 1) |
| 296 | result.AppendMessage(""); |
| 297 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | } |
| 299 | return result.Succeeded(); |
| 300 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 301 | |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 302 | CommandOptions m_options; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 305 | OptionDefinition |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 306 | CommandObjectThreadBacktrace::CommandOptions::g_option_table[] = |
| 307 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 308 | { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeCount, "How many frames to display (-1 for all)"}, |
| 309 | { LLDB_OPT_SET_1, false, "start", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFrameIndex, "Frame in which to start the backtrace"}, |
| 310 | { LLDB_OPT_SET_1, false, "extended", 'e', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Show the extended backtrace, if available"}, |
| 311 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | e2e0b45 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 312 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | |
Greg Clayton | 69b518f | 2010-07-07 17:07:17 +0000 | [diff] [blame] | 314 | enum StepScope |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 315 | { |
| 316 | eStepScopeSource, |
| 317 | eStepScopeInstruction |
| 318 | }; |
| 319 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 320 | class CommandObjectThreadStepWithTypeAndScope : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 321 | { |
| 322 | public: |
| 323 | |
| 324 | class CommandOptions : public Options |
| 325 | { |
| 326 | public: |
| 327 | |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 328 | CommandOptions (CommandInterpreter &interpreter) : |
| 329 | Options (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 330 | { |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 331 | // Keep default values of all options in one place: OptionParsingStarting () |
| 332 | OptionParsingStarting (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | virtual |
| 336 | ~CommandOptions () |
| 337 | { |
| 338 | } |
| 339 | |
| 340 | virtual Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 341 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 342 | { |
| 343 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 344 | const int short_option = m_getopt_table[option_idx].val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | |
| 346 | switch (short_option) |
| 347 | { |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 348 | case 'a': |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 349 | { |
| 350 | bool success; |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 351 | bool avoid_no_debug = Args::StringToBoolean (option_arg, true, &success); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 352 | if (!success) |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 353 | error.SetErrorStringWithFormat("invalid boolean value for option '%c'", short_option); |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 354 | else |
| 355 | { |
| 356 | m_step_in_avoid_no_debug = avoid_no_debug ? eLazyBoolYes : eLazyBoolNo; |
| 357 | } |
| 358 | } |
| 359 | break; |
| 360 | |
| 361 | case 'A': |
| 362 | { |
| 363 | bool success; |
| 364 | bool avoid_no_debug = Args::StringToBoolean (option_arg, true, &success); |
| 365 | if (!success) |
| 366 | error.SetErrorStringWithFormat("invalid boolean value for option '%c'", short_option); |
| 367 | else |
| 368 | { |
| 369 | m_step_out_avoid_no_debug = avoid_no_debug ? eLazyBoolYes : eLazyBoolNo; |
| 370 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 371 | } |
| 372 | break; |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 373 | |
Jim Ingham | 7a88ec9 | 2014-07-08 19:28:57 +0000 | [diff] [blame] | 374 | case 'c': |
| 375 | { |
| 376 | m_step_count = Args::StringToUInt32(option_arg, UINT32_MAX, 0); |
| 377 | if (m_step_count == UINT32_MAX) |
| 378 | error.SetErrorStringWithFormat ("invalid ignore count '%s'", option_arg); |
| 379 | break; |
| 380 | } |
| 381 | break; |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 382 | case 'm': |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 383 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 385 | m_run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 386 | } |
| 387 | break; |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 388 | |
| 389 | case 'r': |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 390 | { |
| 391 | m_avoid_regexp.clear(); |
| 392 | m_avoid_regexp.assign(option_arg); |
| 393 | } |
| 394 | break; |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 395 | |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 396 | case 't': |
| 397 | { |
| 398 | m_step_in_target.clear(); |
| 399 | m_step_in_target.assign(option_arg); |
| 400 | |
| 401 | } |
| 402 | break; |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 403 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 404 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 405 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 406 | |
| 407 | } |
| 408 | return error; |
| 409 | } |
| 410 | |
| 411 | void |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 412 | OptionParsingStarting () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 414 | m_step_in_avoid_no_debug = eLazyBoolCalculate; |
| 415 | m_step_out_avoid_no_debug = eLazyBoolCalculate; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 416 | m_run_mode = eOnlyDuringStepping; |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 417 | m_avoid_regexp.clear(); |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 418 | m_step_in_target.clear(); |
Jim Ingham | 7a88ec9 | 2014-07-08 19:28:57 +0000 | [diff] [blame] | 419 | m_step_count = 1; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 422 | const OptionDefinition* |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 423 | GetDefinitions () |
| 424 | { |
| 425 | return g_option_table; |
| 426 | } |
| 427 | |
| 428 | // Options table: Required for subclasses of Options. |
| 429 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 430 | static OptionDefinition g_option_table[]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 431 | |
| 432 | // Instance variables to hold the values for command options. |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 433 | LazyBool m_step_in_avoid_no_debug; |
| 434 | LazyBool m_step_out_avoid_no_debug; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | RunMode m_run_mode; |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 436 | std::string m_avoid_regexp; |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 437 | std::string m_step_in_target; |
Jim Ingham | 7a88ec9 | 2014-07-08 19:28:57 +0000 | [diff] [blame] | 438 | int32_t m_step_count; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 439 | }; |
| 440 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 441 | CommandObjectThreadStepWithTypeAndScope (CommandInterpreter &interpreter, |
| 442 | const char *name, |
| 443 | const char *help, |
| 444 | const char *syntax, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 445 | StepType step_type, |
| 446 | StepScope step_scope) : |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 447 | CommandObjectParsed (interpreter, name, help, syntax, |
| 448 | eFlagRequiresProcess | |
| 449 | eFlagRequiresThread | |
| 450 | eFlagTryTargetAPILock | |
| 451 | eFlagProcessMustBeLaunched | |
| 452 | eFlagProcessMustBePaused ), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 453 | m_step_type (step_type), |
| 454 | m_step_scope (step_scope), |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 455 | m_options (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 456 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 457 | CommandArgumentEntry arg; |
| 458 | CommandArgumentData thread_id_arg; |
| 459 | |
| 460 | // Define the first (and only) variant of this arg. |
| 461 | thread_id_arg.arg_type = eArgTypeThreadID; |
| 462 | thread_id_arg.arg_repetition = eArgRepeatOptional; |
| 463 | |
| 464 | // There is only one variant this argument could be; put it into the argument entry. |
| 465 | arg.push_back (thread_id_arg); |
| 466 | |
| 467 | // Push the data for the first argument into the m_arguments vector. |
| 468 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | virtual |
| 472 | ~CommandObjectThreadStepWithTypeAndScope () |
| 473 | { |
| 474 | } |
| 475 | |
| 476 | virtual |
| 477 | Options * |
| 478 | GetOptions () |
| 479 | { |
| 480 | return &m_options; |
| 481 | } |
| 482 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 483 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 484 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 485 | DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 486 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 487 | Process *process = m_exe_ctx.GetProcessPtr(); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 488 | bool synchronous_execution = m_interpreter.GetSynchronous(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 490 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
| 491 | Thread *thread = NULL; |
| 492 | |
| 493 | if (command.GetArgumentCount() == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 494 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 495 | thread = process->GetThreadList().GetSelectedThread().get(); |
| 496 | if (thread == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 497 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 498 | result.AppendError ("no selected thread in process"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 499 | result.SetStatus (eReturnStatusFailed); |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 500 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 501 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 502 | } |
| 503 | else |
| 504 | { |
| 505 | const char *thread_idx_cstr = command.GetArgumentAtIndex(0); |
| 506 | uint32_t step_thread_idx = Args::StringToUInt32 (thread_idx_cstr, LLDB_INVALID_INDEX32); |
| 507 | if (step_thread_idx == LLDB_INVALID_INDEX32) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 508 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 509 | result.AppendErrorWithFormat ("invalid thread index '%s'.\n", thread_idx_cstr); |
| 510 | result.SetStatus (eReturnStatusFailed); |
| 511 | return false; |
| 512 | } |
| 513 | thread = process->GetThreadList().FindThreadByIndexID(step_thread_idx).get(); |
| 514 | if (thread == NULL) |
| 515 | { |
| 516 | result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n", |
| 517 | step_thread_idx, num_threads); |
| 518 | result.SetStatus (eReturnStatusFailed); |
| 519 | return false; |
| 520 | } |
| 521 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 522 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 523 | const bool abort_other_plans = false; |
| 524 | const lldb::RunMode stop_other_threads = m_options.m_run_mode; |
| 525 | |
| 526 | // This is a bit unfortunate, but not all the commands in this command object support |
| 527 | // only while stepping, so I use the bool for them. |
| 528 | bool bool_stop_other_threads; |
| 529 | if (m_options.m_run_mode == eAllThreads) |
| 530 | bool_stop_other_threads = false; |
| 531 | else if (m_options.m_run_mode == eOnlyDuringStepping) |
| 532 | { |
| 533 | if (m_step_type == eStepTypeOut) |
| 534 | bool_stop_other_threads = false; |
| 535 | else |
| 536 | bool_stop_other_threads = true; |
| 537 | } |
| 538 | else |
| 539 | bool_stop_other_threads = true; |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 540 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 541 | ThreadPlanSP new_plan_sp; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 542 | |
| 543 | if (m_step_type == eStepTypeInto) |
| 544 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 545 | StackFrame *frame = thread->GetStackFrameAtIndex(0).get(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 546 | |
| 547 | if (frame->HasDebugInformation ()) |
| 548 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 549 | new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 550 | frame->GetSymbolContext(eSymbolContextEverything).line_entry.range, |
| 551 | frame->GetSymbolContext(eSymbolContextEverything), |
| 552 | m_options.m_step_in_target.c_str(), |
| 553 | stop_other_threads, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 554 | m_options.m_step_in_avoid_no_debug, |
| 555 | m_options.m_step_out_avoid_no_debug); |
| 556 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 557 | if (new_plan_sp && !m_options.m_avoid_regexp.empty()) |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 558 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 559 | ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (new_plan_sp.get()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 560 | step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str()); |
Jim Ingham | 29412d1 | 2012-05-16 00:37:40 +0000 | [diff] [blame] | 561 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 562 | } |
| 563 | else |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 564 | new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false, abort_other_plans, bool_stop_other_threads); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 565 | |
| 566 | } |
| 567 | else if (m_step_type == eStepTypeOver) |
| 568 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 569 | StackFrame *frame = thread->GetStackFrameAtIndex(0).get(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 570 | |
| 571 | if (frame->HasDebugInformation()) |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 572 | new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 573 | frame->GetSymbolContext(eSymbolContextEverything).line_entry.range, |
| 574 | frame->GetSymbolContext(eSymbolContextEverything), |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 575 | stop_other_threads, |
| 576 | m_options.m_step_out_avoid_no_debug); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 577 | else |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 578 | new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 579 | abort_other_plans, |
| 580 | bool_stop_other_threads); |
| 581 | |
| 582 | } |
| 583 | else if (m_step_type == eStepTypeTrace) |
| 584 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 585 | new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (false, abort_other_plans, bool_stop_other_threads); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 586 | } |
| 587 | else if (m_step_type == eStepTypeTraceOver) |
| 588 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 589 | new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true, abort_other_plans, bool_stop_other_threads); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 590 | } |
| 591 | else if (m_step_type == eStepTypeOut) |
| 592 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 593 | new_plan_sp = thread->QueueThreadPlanForStepOut (abort_other_plans, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 594 | NULL, |
| 595 | false, |
| 596 | bool_stop_other_threads, |
| 597 | eVoteYes, |
| 598 | eVoteNoOpinion, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame] | 599 | thread->GetSelectedFrameIndex(), |
| 600 | m_options.m_step_out_avoid_no_debug); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 601 | } |
| 602 | else |
| 603 | { |
| 604 | result.AppendError ("step type is not supported"); |
| 605 | result.SetStatus (eReturnStatusFailed); |
| 606 | return false; |
| 607 | } |
| 608 | |
| 609 | // If we got a new plan, then set it to be a master plan (User level Plans should be master plans |
| 610 | // so that they can be interruptible). Then resume the process. |
| 611 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 612 | if (new_plan_sp) |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 613 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 614 | new_plan_sp->SetIsMasterPlan (true); |
| 615 | new_plan_sp->SetOkayToDiscard (false); |
Jim Ingham | 7a88ec9 | 2014-07-08 19:28:57 +0000 | [diff] [blame] | 616 | |
| 617 | if (m_options.m_step_count > 1) |
| 618 | { |
| 619 | if (new_plan_sp->SetIterationCount(m_options.m_step_count) != m_options.m_step_count) |
| 620 | { |
| 621 | result.AppendWarning ("step operation does not support iteration count."); |
| 622 | } |
| 623 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 624 | |
| 625 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
| 626 | process->Resume (); |
| 627 | |
| 628 | |
| 629 | if (synchronous_execution) |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 630 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 631 | StateType state = process->WaitForProcessToStop (NULL); |
| 632 | |
| 633 | //EventSP event_sp; |
| 634 | //StateType state = process->WaitForStateChangedEvents (NULL, event_sp); |
| 635 | //while (! StateIsStoppedState (state)) |
| 636 | // { |
| 637 | // state = process->WaitForStateChangedEvents (NULL, event_sp); |
| 638 | // } |
| 639 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
| 640 | result.SetDidChangeProcessState (true); |
| 641 | result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state)); |
| 642 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 643 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 644 | else |
| 645 | { |
| 646 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 647 | } |
| 648 | } |
| 649 | else |
| 650 | { |
| 651 | result.AppendError ("Couldn't find thread plan to implement step type."); |
| 652 | result.SetStatus (eReturnStatusFailed); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 653 | } |
| 654 | return result.Succeeded(); |
| 655 | } |
| 656 | |
| 657 | protected: |
| 658 | StepType m_step_type; |
| 659 | StepScope m_step_scope; |
| 660 | CommandOptions m_options; |
| 661 | }; |
| 662 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 663 | static OptionEnumValueElement |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 664 | g_tri_running_mode[] = |
| 665 | { |
Greg Clayton | ed8a705 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 666 | { eOnlyThisThread, "this-thread", "Run only this thread"}, |
| 667 | { eAllThreads, "all-threads", "Run all threads"}, |
| 668 | { eOnlyDuringStepping, "while-stepping", "Run only this thread while stepping"}, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | { 0, NULL, NULL } |
| 670 | }; |
| 671 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 672 | static OptionEnumValueElement |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 673 | g_duo_running_mode[] = |
| 674 | { |
Greg Clayton | ed8a705 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 675 | { eOnlyThisThread, "this-thread", "Run only this thread"}, |
| 676 | { eAllThreads, "all-threads", "Run all threads"}, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 677 | { 0, NULL, NULL } |
| 678 | }; |
| 679 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 680 | OptionDefinition |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 681 | CommandObjectThreadStepWithTypeAndScope::CommandOptions::g_option_table[] = |
| 682 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 683 | { LLDB_OPT_SET_1, false, "step-in-avoids-no-debug", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "A boolean value that sets whether stepping into functions will step over functions with no debug information."}, |
| 684 | { LLDB_OPT_SET_1, false, "step-out-avoids-no-debug", 'A', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "A boolean value, if true stepping out of functions will continue to step out till it hits a function with debug information."}, |
| 685 | { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, NULL, NULL, 1, eArgTypeCount, "How many times to perform the stepping operation - currently only supported for step-inst and next-inst."}, |
| 686 | { LLDB_OPT_SET_1, false, "run-mode", 'm', OptionParser::eRequiredArgument, NULL, g_tri_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping the current thread."}, |
| 687 | { LLDB_OPT_SET_1, false, "step-over-regexp",'r', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeRegularExpression, "A regular expression that defines function names to not to stop at when stepping in."}, |
| 688 | { LLDB_OPT_SET_1, false, "step-in-target", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFunctionName, "The name of the directly called function step in should stop at when stepping into."}, |
| 689 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 690 | }; |
| 691 | |
| 692 | |
| 693 | //------------------------------------------------------------------------- |
| 694 | // CommandObjectThreadContinue |
| 695 | //------------------------------------------------------------------------- |
| 696 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 697 | class CommandObjectThreadContinue : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 698 | { |
| 699 | public: |
| 700 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 701 | CommandObjectThreadContinue (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 702 | CommandObjectParsed (interpreter, |
| 703 | "thread continue", |
| 704 | "Continue execution of one or more threads in an active process.", |
| 705 | NULL, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 706 | eFlagRequiresThread | |
| 707 | eFlagTryTargetAPILock | |
| 708 | eFlagProcessMustBeLaunched | |
| 709 | eFlagProcessMustBePaused) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 710 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 711 | CommandArgumentEntry arg; |
| 712 | CommandArgumentData thread_idx_arg; |
| 713 | |
| 714 | // Define the first (and only) variant of this arg. |
| 715 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 716 | thread_idx_arg.arg_repetition = eArgRepeatPlus; |
| 717 | |
| 718 | // There is only one variant this argument could be; put it into the argument entry. |
| 719 | arg.push_back (thread_idx_arg); |
| 720 | |
| 721 | // Push the data for the first argument into the m_arguments vector. |
| 722 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | |
| 726 | virtual |
| 727 | ~CommandObjectThreadContinue () |
| 728 | { |
| 729 | } |
| 730 | |
| 731 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 732 | DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 733 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 734 | bool synchronous_execution = m_interpreter.GetSynchronous (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 736 | if (!m_interpreter.GetDebugger().GetSelectedTarget().get()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 737 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 738 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 739 | result.SetStatus (eReturnStatusFailed); |
| 740 | return false; |
| 741 | } |
| 742 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 743 | Process *process = m_exe_ctx.GetProcessPtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | if (process == NULL) |
| 745 | { |
| 746 | result.AppendError ("no process exists. Cannot continue"); |
| 747 | result.SetStatus (eReturnStatusFailed); |
| 748 | return false; |
| 749 | } |
| 750 | |
| 751 | StateType state = process->GetState(); |
| 752 | if ((state == eStateCrashed) || (state == eStateStopped) || (state == eStateSuspended)) |
| 753 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | const size_t argc = command.GetArgumentCount(); |
| 755 | if (argc > 0) |
| 756 | { |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 757 | // These two lines appear at the beginning of both blocks in |
| 758 | // this if..else, but that is because we need to release the |
| 759 | // lock before calling process->Resume below. |
| 760 | Mutex::Locker locker (process->GetThreadList().GetMutex()); |
| 761 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 762 | std::vector<Thread *> resume_threads; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 763 | for (uint32_t i=0; i<argc; ++i) |
| 764 | { |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 765 | bool success; |
| 766 | const int base = 0; |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 767 | uint32_t thread_idx = Args::StringToUInt32 (command.GetArgumentAtIndex(i), LLDB_INVALID_INDEX32, base, &success); |
| 768 | if (success) |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 769 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 770 | Thread *thread = process->GetThreadList().FindThreadByIndexID(thread_idx).get(); |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 771 | |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 772 | if (thread) |
| 773 | { |
| 774 | resume_threads.push_back(thread); |
| 775 | } |
| 776 | else |
| 777 | { |
| 778 | result.AppendErrorWithFormat("invalid thread index %u.\n", thread_idx); |
| 779 | result.SetStatus (eReturnStatusFailed); |
| 780 | return false; |
| 781 | } |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 782 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | else |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 784 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 785 | result.AppendErrorWithFormat ("invalid thread index argument: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 786 | result.SetStatus (eReturnStatusFailed); |
| 787 | return false; |
| 788 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 789 | } |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 790 | |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 791 | if (resume_threads.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 792 | { |
| 793 | result.AppendError ("no valid thread indexes were specified"); |
| 794 | result.SetStatus (eReturnStatusFailed); |
| 795 | return false; |
| 796 | } |
| 797 | else |
| 798 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 799 | if (resume_threads.size() == 1) |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 800 | result.AppendMessageWithFormat ("Resuming thread: "); |
| 801 | else |
| 802 | result.AppendMessageWithFormat ("Resuming threads: "); |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 803 | |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 804 | for (uint32_t idx=0; idx<num_threads; ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 806 | Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get(); |
| 807 | std::vector<Thread *>::iterator this_thread_pos = find(resume_threads.begin(), resume_threads.end(), thread); |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 808 | |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 809 | if (this_thread_pos != resume_threads.end()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 810 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 811 | resume_threads.erase(this_thread_pos); |
| 812 | if (resume_threads.size() > 0) |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 813 | result.AppendMessageWithFormat ("%u, ", thread->GetIndexID()); |
| 814 | else |
| 815 | result.AppendMessageWithFormat ("%u ", thread->GetIndexID()); |
Jim Ingham | 6c9ed91 | 2014-04-03 01:26:14 +0000 | [diff] [blame] | 816 | |
| 817 | const bool override_suspend = true; |
| 818 | thread->SetResumeState (eStateRunning, override_suspend); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 819 | } |
| 820 | else |
| 821 | { |
| 822 | thread->SetResumeState (eStateSuspended); |
| 823 | } |
| 824 | } |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 825 | result.AppendMessageWithFormat ("in process %" PRIu64 "\n", process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | else |
| 829 | { |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 830 | // These two lines appear at the beginning of both blocks in |
| 831 | // this if..else, but that is because we need to release the |
| 832 | // lock before calling process->Resume below. |
| 833 | Mutex::Locker locker (process->GetThreadList().GetMutex()); |
| 834 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 835 | Thread *current_thread = process->GetThreadList().GetSelectedThread().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 836 | if (current_thread == NULL) |
| 837 | { |
| 838 | result.AppendError ("the process doesn't have a current thread"); |
| 839 | result.SetStatus (eReturnStatusFailed); |
| 840 | return false; |
| 841 | } |
| 842 | // Set the actions that the threads should each take when resuming |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 843 | for (uint32_t idx=0; idx<num_threads; ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 844 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 845 | Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 846 | if (thread == current_thread) |
| 847 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 848 | result.AppendMessageWithFormat ("Resuming thread 0x%4.4" PRIx64 " in process %" PRIu64 "\n", thread->GetID(), process->GetID()); |
Jim Ingham | 6c9ed91 | 2014-04-03 01:26:14 +0000 | [diff] [blame] | 849 | const bool override_suspend = true; |
| 850 | thread->SetResumeState (eStateRunning, override_suspend); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 851 | } |
| 852 | else |
| 853 | { |
| 854 | thread->SetResumeState (eStateSuspended); |
| 855 | } |
| 856 | } |
| 857 | } |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 858 | |
| 859 | // We should not be holding the thread list lock when we do this. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 860 | Error error (process->Resume()); |
| 861 | if (error.Success()) |
| 862 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 863 | result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 864 | if (synchronous_execution) |
| 865 | { |
Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 866 | state = process->WaitForProcessToStop (NULL); |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 867 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 868 | result.SetDidChangeProcessState (true); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 869 | result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 870 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 871 | } |
| 872 | else |
| 873 | { |
| 874 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 875 | } |
| 876 | } |
| 877 | else |
| 878 | { |
| 879 | result.AppendErrorWithFormat("Failed to resume process: %s\n", error.AsCString()); |
| 880 | result.SetStatus (eReturnStatusFailed); |
| 881 | } |
| 882 | } |
| 883 | else |
| 884 | { |
| 885 | result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n", |
| 886 | StateAsCString(state)); |
| 887 | result.SetStatus (eReturnStatusFailed); |
| 888 | } |
| 889 | |
| 890 | return result.Succeeded(); |
| 891 | } |
| 892 | |
| 893 | }; |
| 894 | |
| 895 | //------------------------------------------------------------------------- |
| 896 | // CommandObjectThreadUntil |
| 897 | //------------------------------------------------------------------------- |
| 898 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 899 | class CommandObjectThreadUntil : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 900 | { |
| 901 | public: |
| 902 | |
| 903 | class CommandOptions : public Options |
| 904 | { |
| 905 | public: |
| 906 | uint32_t m_thread_idx; |
| 907 | uint32_t m_frame_idx; |
| 908 | |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 909 | CommandOptions (CommandInterpreter &interpreter) : |
| 910 | Options (interpreter), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 911 | m_thread_idx(LLDB_INVALID_THREAD_ID), |
| 912 | m_frame_idx(LLDB_INVALID_FRAME_ID) |
| 913 | { |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 914 | // Keep default values of all options in one place: OptionParsingStarting () |
| 915 | OptionParsingStarting (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | virtual |
| 919 | ~CommandOptions () |
| 920 | { |
| 921 | } |
| 922 | |
| 923 | virtual Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 924 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 925 | { |
| 926 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 927 | const int short_option = m_getopt_table[option_idx].val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 928 | |
| 929 | switch (short_option) |
| 930 | { |
| 931 | case 't': |
| 932 | { |
Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 933 | m_thread_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_INDEX32); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 934 | if (m_thread_idx == LLDB_INVALID_INDEX32) |
| 935 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 936 | error.SetErrorStringWithFormat ("invalid thread index '%s'", option_arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | break; |
| 940 | case 'f': |
| 941 | { |
| 942 | m_frame_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_FRAME_ID); |
| 943 | if (m_frame_idx == LLDB_INVALID_FRAME_ID) |
| 944 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 945 | error.SetErrorStringWithFormat ("invalid frame index '%s'", option_arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | break; |
| 949 | case 'm': |
| 950 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 951 | OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 952 | lldb::RunMode run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 953 | |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 954 | if (error.Success()) |
| 955 | { |
| 956 | if (run_mode == eAllThreads) |
| 957 | m_stop_others = false; |
| 958 | else |
| 959 | m_stop_others = true; |
| 960 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 961 | } |
| 962 | break; |
| 963 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 964 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 965 | break; |
| 966 | |
| 967 | } |
| 968 | return error; |
| 969 | } |
| 970 | |
| 971 | void |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 972 | OptionParsingStarting () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 973 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 974 | m_thread_idx = LLDB_INVALID_THREAD_ID; |
| 975 | m_frame_idx = 0; |
| 976 | m_stop_others = false; |
| 977 | } |
| 978 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 979 | const OptionDefinition* |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 980 | GetDefinitions () |
| 981 | { |
| 982 | return g_option_table; |
| 983 | } |
| 984 | |
| 985 | uint32_t m_step_thread_idx; |
| 986 | bool m_stop_others; |
| 987 | |
| 988 | // Options table: Required for subclasses of Options. |
| 989 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 990 | static OptionDefinition g_option_table[]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 991 | |
| 992 | // Instance variables to hold the values for command options. |
| 993 | }; |
| 994 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 995 | CommandObjectThreadUntil (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 996 | CommandObjectParsed (interpreter, |
| 997 | "thread until", |
| 998 | "Run the current or specified thread until it reaches a given line number or leaves the current function.", |
| 999 | NULL, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1000 | eFlagRequiresThread | |
| 1001 | eFlagTryTargetAPILock | |
| 1002 | eFlagProcessMustBeLaunched | |
| 1003 | eFlagProcessMustBePaused ), |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1004 | m_options (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1005 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1006 | CommandArgumentEntry arg; |
| 1007 | CommandArgumentData line_num_arg; |
| 1008 | |
| 1009 | // Define the first (and only) variant of this arg. |
| 1010 | line_num_arg.arg_type = eArgTypeLineNum; |
| 1011 | line_num_arg.arg_repetition = eArgRepeatPlain; |
| 1012 | |
| 1013 | // There is only one variant this argument could be; put it into the argument entry. |
| 1014 | arg.push_back (line_num_arg); |
| 1015 | |
| 1016 | // Push the data for the first argument into the m_arguments vector. |
| 1017 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | |
| 1021 | virtual |
| 1022 | ~CommandObjectThreadUntil () |
| 1023 | { |
| 1024 | } |
| 1025 | |
| 1026 | virtual |
| 1027 | Options * |
| 1028 | GetOptions () |
| 1029 | { |
| 1030 | return &m_options; |
| 1031 | } |
| 1032 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1033 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1034 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1035 | DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1036 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1037 | bool synchronous_execution = m_interpreter.GetSynchronous (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1038 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1039 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 1040 | if (target == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1041 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1042 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1043 | result.SetStatus (eReturnStatusFailed); |
| 1044 | return false; |
| 1045 | } |
| 1046 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1047 | Process *process = m_exe_ctx.GetProcessPtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1048 | if (process == NULL) |
| 1049 | { |
| 1050 | result.AppendError ("need a valid process to step"); |
| 1051 | result.SetStatus (eReturnStatusFailed); |
| 1052 | |
| 1053 | } |
| 1054 | else |
| 1055 | { |
| 1056 | Thread *thread = NULL; |
| 1057 | uint32_t line_number; |
| 1058 | |
| 1059 | if (command.GetArgumentCount() != 1) |
| 1060 | { |
| 1061 | result.AppendErrorWithFormat ("No line number provided:\n%s", GetSyntax()); |
| 1062 | result.SetStatus (eReturnStatusFailed); |
| 1063 | return false; |
| 1064 | } |
| 1065 | |
| 1066 | line_number = Args::StringToUInt32 (command.GetArgumentAtIndex(0), UINT32_MAX); |
| 1067 | if (line_number == UINT32_MAX) |
| 1068 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1069 | result.AppendErrorWithFormat ("invalid line number: '%s'.\n", command.GetArgumentAtIndex(0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1070 | result.SetStatus (eReturnStatusFailed); |
| 1071 | return false; |
| 1072 | } |
| 1073 | |
| 1074 | if (m_options.m_thread_idx == LLDB_INVALID_THREAD_ID) |
| 1075 | { |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 1076 | thread = process->GetThreadList().GetSelectedThread().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1077 | } |
| 1078 | else |
| 1079 | { |
Greg Clayton | 76927ee | 2012-05-31 00:29:20 +0000 | [diff] [blame] | 1080 | thread = process->GetThreadList().FindThreadByIndexID(m_options.m_thread_idx).get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | if (thread == NULL) |
| 1084 | { |
| 1085 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1086 | result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n", |
| 1087 | m_options.m_thread_idx, |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1088 | num_threads); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1089 | result.SetStatus (eReturnStatusFailed); |
| 1090 | return false; |
| 1091 | } |
| 1092 | |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 1093 | const bool abort_other_plans = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1094 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1095 | StackFrame *frame = thread->GetStackFrameAtIndex(m_options.m_frame_idx).get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1096 | if (frame == NULL) |
| 1097 | { |
| 1098 | |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1099 | result.AppendErrorWithFormat ("Frame index %u is out of range for thread %u.\n", |
| 1100 | m_options.m_frame_idx, |
| 1101 | m_options.m_thread_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1102 | result.SetStatus (eReturnStatusFailed); |
| 1103 | return false; |
| 1104 | } |
| 1105 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1106 | ThreadPlanSP new_plan_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1107 | |
| 1108 | if (frame->HasDebugInformation ()) |
| 1109 | { |
| 1110 | // Finally we got here... Translate the given line number to a bunch of addresses: |
| 1111 | SymbolContext sc(frame->GetSymbolContext (eSymbolContextCompUnit)); |
| 1112 | LineTable *line_table = NULL; |
| 1113 | if (sc.comp_unit) |
| 1114 | line_table = sc.comp_unit->GetLineTable(); |
| 1115 | |
| 1116 | if (line_table == NULL) |
| 1117 | { |
| 1118 | result.AppendErrorWithFormat ("Failed to resolve the line table for frame %u of thread index %u.\n", |
| 1119 | m_options.m_frame_idx, m_options.m_thread_idx); |
| 1120 | result.SetStatus (eReturnStatusFailed); |
| 1121 | return false; |
| 1122 | } |
| 1123 | |
| 1124 | LineEntry function_start; |
| 1125 | uint32_t index_ptr = 0, end_ptr; |
| 1126 | std::vector<addr_t> address_list; |
| 1127 | |
| 1128 | // Find the beginning & end index of the |
| 1129 | AddressRange fun_addr_range = sc.function->GetAddressRange(); |
| 1130 | Address fun_start_addr = fun_addr_range.GetBaseAddress(); |
| 1131 | line_table->FindLineEntryByAddress (fun_start_addr, function_start, &index_ptr); |
| 1132 | |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1133 | Address fun_end_addr(fun_start_addr.GetSection(), |
| 1134 | fun_start_addr.GetOffset() + fun_addr_range.GetByteSize()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1135 | line_table->FindLineEntryByAddress (fun_end_addr, function_start, &end_ptr); |
| 1136 | |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1137 | bool all_in_function = true; |
| 1138 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1139 | while (index_ptr <= end_ptr) |
| 1140 | { |
| 1141 | LineEntry line_entry; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1142 | const bool exact = false; |
| 1143 | index_ptr = sc.comp_unit->FindLineEntry(index_ptr, line_number, sc.comp_unit, exact, &line_entry); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1144 | if (index_ptr == UINT32_MAX) |
| 1145 | break; |
| 1146 | |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 1147 | addr_t address = line_entry.range.GetBaseAddress().GetLoadAddress(target); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1148 | if (address != LLDB_INVALID_ADDRESS) |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1149 | { |
| 1150 | if (fun_addr_range.ContainsLoadAddress (address, target)) |
| 1151 | address_list.push_back (address); |
| 1152 | else |
| 1153 | all_in_function = false; |
| 1154 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1155 | index_ptr++; |
| 1156 | } |
| 1157 | |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1158 | if (address_list.size() == 0) |
| 1159 | { |
| 1160 | if (all_in_function) |
| 1161 | result.AppendErrorWithFormat ("No line entries matching until target.\n"); |
| 1162 | else |
| 1163 | result.AppendErrorWithFormat ("Until target outside of the current function.\n"); |
| 1164 | |
| 1165 | result.SetStatus (eReturnStatusFailed); |
| 1166 | return false; |
| 1167 | } |
| 1168 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1169 | new_plan_sp = thread->QueueThreadPlanForStepUntil (abort_other_plans, |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1170 | &address_list.front(), |
| 1171 | address_list.size(), |
| 1172 | m_options.m_stop_others, |
Jim Ingham | f76ab67 | 2012-09-14 20:48:14 +0000 | [diff] [blame] | 1173 | m_options.m_frame_idx); |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1174 | // User level plans should be master plans so they can be interrupted (e.g. by hitting a breakpoint) |
| 1175 | // and other plans executed by the user (stepping around the breakpoint) and then a "continue" |
| 1176 | // will resume the original plan. |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1177 | new_plan_sp->SetIsMasterPlan (true); |
| 1178 | new_plan_sp->SetOkayToDiscard(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1179 | } |
| 1180 | else |
| 1181 | { |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1182 | result.AppendErrorWithFormat ("Frame index %u of thread %u has no debug information.\n", |
| 1183 | m_options.m_frame_idx, |
| 1184 | m_options.m_thread_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1185 | result.SetStatus (eReturnStatusFailed); |
| 1186 | return false; |
| 1187 | |
| 1188 | } |
| 1189 | |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 1190 | process->GetThreadList().SetSelectedThreadByID (m_options.m_thread_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1191 | Error error (process->Resume ()); |
| 1192 | if (error.Success()) |
| 1193 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1194 | result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1195 | if (synchronous_execution) |
| 1196 | { |
| 1197 | StateType state = process->WaitForProcessToStop (NULL); |
| 1198 | |
| 1199 | result.SetDidChangeProcessState (true); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1200 | result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1201 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1202 | } |
| 1203 | else |
| 1204 | { |
| 1205 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 1206 | } |
| 1207 | } |
| 1208 | else |
| 1209 | { |
| 1210 | result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString()); |
| 1211 | result.SetStatus (eReturnStatusFailed); |
| 1212 | } |
| 1213 | |
| 1214 | } |
| 1215 | return result.Succeeded(); |
| 1216 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1217 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1218 | CommandOptions m_options; |
| 1219 | |
| 1220 | }; |
| 1221 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1222 | OptionDefinition |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1223 | CommandObjectThreadUntil::CommandOptions::g_option_table[] = |
| 1224 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1225 | { LLDB_OPT_SET_1, false, "frame", 'f', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeFrameIndex, "Frame index for until operation - defaults to 0"}, |
| 1226 | { LLDB_OPT_SET_1, false, "thread", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeThreadIndex, "Thread index for the thread for until operation"}, |
| 1227 | { LLDB_OPT_SET_1, false, "run-mode",'m', OptionParser::eRequiredArgument, NULL, g_duo_running_mode, 0, eArgTypeRunMode,"Determine how to run other threads while stepping this one"}, |
| 1228 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1229 | }; |
| 1230 | |
| 1231 | |
| 1232 | //------------------------------------------------------------------------- |
| 1233 | // CommandObjectThreadSelect |
| 1234 | //------------------------------------------------------------------------- |
| 1235 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1236 | class CommandObjectThreadSelect : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1237 | { |
| 1238 | public: |
| 1239 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1240 | CommandObjectThreadSelect (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1241 | CommandObjectParsed (interpreter, |
| 1242 | "thread select", |
| 1243 | "Select a thread as the currently active thread.", |
| 1244 | NULL, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1245 | eFlagRequiresProcess | |
| 1246 | eFlagTryTargetAPILock | |
| 1247 | eFlagProcessMustBeLaunched | |
| 1248 | eFlagProcessMustBePaused ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1249 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1250 | CommandArgumentEntry arg; |
| 1251 | CommandArgumentData thread_idx_arg; |
| 1252 | |
| 1253 | // Define the first (and only) variant of this arg. |
| 1254 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 1255 | thread_idx_arg.arg_repetition = eArgRepeatPlain; |
| 1256 | |
| 1257 | // There is only one variant this argument could be; put it into the argument entry. |
| 1258 | arg.push_back (thread_idx_arg); |
| 1259 | |
| 1260 | // Push the data for the first argument into the m_arguments vector. |
| 1261 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | |
| 1265 | virtual |
| 1266 | ~CommandObjectThreadSelect () |
| 1267 | { |
| 1268 | } |
| 1269 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1270 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1271 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1272 | DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1273 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1274 | Process *process = m_exe_ctx.GetProcessPtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1275 | if (process == NULL) |
| 1276 | { |
| 1277 | result.AppendError ("no process"); |
| 1278 | result.SetStatus (eReturnStatusFailed); |
| 1279 | return false; |
| 1280 | } |
| 1281 | else if (command.GetArgumentCount() != 1) |
| 1282 | { |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1283 | result.AppendErrorWithFormat("'%s' takes exactly one thread index argument:\nUsage: %s\n", m_cmd_name.c_str(), m_cmd_syntax.c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1284 | result.SetStatus (eReturnStatusFailed); |
| 1285 | return false; |
| 1286 | } |
| 1287 | |
| 1288 | uint32_t index_id = Args::StringToUInt32(command.GetArgumentAtIndex(0), 0, 0); |
| 1289 | |
| 1290 | Thread *new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get(); |
| 1291 | if (new_thread == NULL) |
| 1292 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1293 | result.AppendErrorWithFormat ("invalid thread #%s.\n", command.GetArgumentAtIndex(0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1294 | result.SetStatus (eReturnStatusFailed); |
| 1295 | return false; |
| 1296 | } |
| 1297 | |
Jim Ingham | c3faa19 | 2012-12-11 02:31:48 +0000 | [diff] [blame] | 1298 | process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true); |
Johnny Chen | c13ee52 | 2010-09-14 00:53:53 +0000 | [diff] [blame] | 1299 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1300 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1301 | return result.Succeeded(); |
| 1302 | } |
| 1303 | |
| 1304 | }; |
| 1305 | |
| 1306 | |
| 1307 | //------------------------------------------------------------------------- |
| 1308 | // CommandObjectThreadList |
| 1309 | //------------------------------------------------------------------------- |
| 1310 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1311 | class CommandObjectThreadList : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1312 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1313 | public: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1314 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1315 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1316 | CommandObjectThreadList (CommandInterpreter &interpreter): |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1317 | CommandObjectParsed (interpreter, |
| 1318 | "thread list", |
| 1319 | "Show a summary of all current threads in a process.", |
| 1320 | "thread list", |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1321 | eFlagRequiresProcess | |
| 1322 | eFlagTryTargetAPILock | |
| 1323 | eFlagProcessMustBeLaunched | |
| 1324 | eFlagProcessMustBePaused ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1325 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1326 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1327 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1328 | ~CommandObjectThreadList() |
| 1329 | { |
| 1330 | } |
| 1331 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1332 | protected: |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1333 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1334 | DoExecute (Args& command, CommandReturnObject &result) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1335 | { |
Jim Ingham | 85e8b81 | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 1336 | Stream &strm = result.GetOutputStream(); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1337 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1338 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 1339 | const bool only_threads_with_stop_reason = false; |
| 1340 | const uint32_t start_frame = 0; |
| 1341 | const uint32_t num_frames = 0; |
| 1342 | const uint32_t num_frames_with_source = 0; |
| 1343 | process->GetStatus(strm); |
| 1344 | process->GetThreadStatus (strm, |
| 1345 | only_threads_with_stop_reason, |
| 1346 | start_frame, |
| 1347 | num_frames, |
| 1348 | num_frames_with_source); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1349 | return result.Succeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1350 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1351 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1352 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1353 | //------------------------------------------------------------------------- |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 1354 | // CommandObjectThreadInfo |
| 1355 | //------------------------------------------------------------------------- |
| 1356 | |
| 1357 | class CommandObjectThreadInfo : public CommandObjectParsed |
| 1358 | { |
| 1359 | public: |
| 1360 | |
| 1361 | CommandObjectThreadInfo (CommandInterpreter &interpreter) : |
| 1362 | CommandObjectParsed (interpreter, |
| 1363 | "thread info", |
| 1364 | "Show an extended summary of information about thread(s) in a process.", |
| 1365 | "thread info", |
| 1366 | eFlagRequiresProcess | |
| 1367 | eFlagTryTargetAPILock | |
| 1368 | eFlagProcessMustBeLaunched | |
| 1369 | eFlagProcessMustBePaused), |
| 1370 | m_options (interpreter) |
| 1371 | { |
| 1372 | CommandArgumentEntry arg; |
| 1373 | CommandArgumentData thread_idx_arg; |
| 1374 | |
| 1375 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 1376 | thread_idx_arg.arg_repetition = eArgRepeatStar; |
| 1377 | |
| 1378 | // There is only one variant this argument could be; put it into the argument entry. |
| 1379 | arg.push_back (thread_idx_arg); |
| 1380 | |
| 1381 | // Push the data for the first argument into the m_arguments vector. |
| 1382 | m_arguments.push_back (arg); |
| 1383 | } |
| 1384 | |
| 1385 | class CommandOptions : public Options |
| 1386 | { |
| 1387 | public: |
| 1388 | |
| 1389 | CommandOptions (CommandInterpreter &interpreter) : |
| 1390 | Options (interpreter) |
| 1391 | { |
| 1392 | OptionParsingStarting (); |
| 1393 | } |
| 1394 | |
| 1395 | void |
| 1396 | OptionParsingStarting () |
| 1397 | { |
| 1398 | m_json = false; |
| 1399 | } |
| 1400 | |
| 1401 | virtual |
| 1402 | ~CommandOptions () |
| 1403 | { |
| 1404 | } |
| 1405 | |
| 1406 | virtual Error |
| 1407 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 1408 | { |
| 1409 | const int short_option = m_getopt_table[option_idx].val; |
| 1410 | Error error; |
| 1411 | |
| 1412 | switch (short_option) |
| 1413 | { |
| 1414 | case 'j': |
| 1415 | m_json = true; |
| 1416 | break; |
| 1417 | |
| 1418 | default: |
| 1419 | return Error("invalid short option character '%c'", short_option); |
| 1420 | |
| 1421 | } |
| 1422 | return error; |
| 1423 | } |
| 1424 | |
| 1425 | const OptionDefinition* |
| 1426 | GetDefinitions () |
| 1427 | { |
| 1428 | return g_option_table; |
| 1429 | } |
| 1430 | |
| 1431 | bool m_json; |
| 1432 | |
| 1433 | static OptionDefinition g_option_table[]; |
| 1434 | }; |
| 1435 | |
| 1436 | virtual |
| 1437 | Options * |
| 1438 | GetOptions () |
| 1439 | { |
| 1440 | return &m_options; |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | virtual |
| 1445 | ~CommandObjectThreadInfo () |
| 1446 | { |
| 1447 | } |
| 1448 | |
| 1449 | virtual bool |
| 1450 | DoExecute (Args& command, CommandReturnObject &result) |
| 1451 | { |
| 1452 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1453 | Stream &strm = result.GetOutputStream(); |
| 1454 | |
| 1455 | if (command.GetArgumentCount() == 0) |
| 1456 | { |
| 1457 | Thread *thread = m_exe_ctx.GetThreadPtr(); |
| 1458 | if (thread->GetDescription (strm, eDescriptionLevelFull, m_options.m_json)) |
| 1459 | { |
| 1460 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1461 | } |
| 1462 | } |
| 1463 | else if (command.GetArgumentCount() == 1 && ::strcmp (command.GetArgumentAtIndex(0), "all") == 0) |
| 1464 | { |
| 1465 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 1466 | uint32_t idx = 0; |
| 1467 | for (ThreadSP thread_sp : process->Threads()) |
| 1468 | { |
| 1469 | if (idx != 0) |
| 1470 | result.AppendMessage(""); |
| 1471 | if (!thread_sp->GetDescription (strm, eDescriptionLevelFull, m_options.m_json)) |
| 1472 | { |
| 1473 | result.AppendErrorWithFormat ("error displaying info for thread: \"0x%4.4x\"\n", idx); |
| 1474 | result.SetStatus (eReturnStatusFailed); |
| 1475 | return false; |
| 1476 | } |
| 1477 | ++idx; |
| 1478 | } |
| 1479 | } |
| 1480 | else |
| 1481 | { |
| 1482 | const size_t num_args = command.GetArgumentCount(); |
| 1483 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 1484 | Mutex::Locker locker (process->GetThreadList().GetMutex()); |
| 1485 | std::vector<ThreadSP> thread_sps; |
| 1486 | |
| 1487 | for (size_t i = 0; i < num_args; i++) |
| 1488 | { |
| 1489 | bool success; |
| 1490 | |
| 1491 | uint32_t thread_idx = Args::StringToUInt32(command.GetArgumentAtIndex(i), 0, 0, &success); |
| 1492 | if (!success) |
| 1493 | { |
| 1494 | result.AppendErrorWithFormat ("invalid thread specification: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 1495 | result.SetStatus (eReturnStatusFailed); |
| 1496 | return false; |
| 1497 | } |
| 1498 | |
| 1499 | thread_sps.push_back(process->GetThreadList().FindThreadByIndexID(thread_idx)); |
| 1500 | |
| 1501 | if (!thread_sps[i]) |
| 1502 | { |
| 1503 | result.AppendErrorWithFormat ("no thread with index: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 1504 | result.SetStatus (eReturnStatusFailed); |
| 1505 | return false; |
| 1506 | } |
| 1507 | |
| 1508 | } |
| 1509 | |
| 1510 | for (uint32_t i = 0; i < num_args; i++) |
| 1511 | { |
| 1512 | if (!thread_sps[i]->GetDescription (strm, eDescriptionLevelFull, m_options.m_json)) |
| 1513 | { |
| 1514 | result.AppendErrorWithFormat ("error displaying info for thread: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 1515 | result.SetStatus (eReturnStatusFailed); |
| 1516 | return false; |
| 1517 | } |
| 1518 | |
| 1519 | if (i < num_args - 1) |
| 1520 | result.AppendMessage(""); |
| 1521 | } |
| 1522 | |
| 1523 | } |
| 1524 | return result.Succeeded(); |
| 1525 | } |
| 1526 | |
| 1527 | CommandOptions m_options; |
| 1528 | |
| 1529 | }; |
| 1530 | |
| 1531 | OptionDefinition |
| 1532 | CommandObjectThreadInfo::CommandOptions::g_option_table[] = |
| 1533 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1534 | { LLDB_OPT_SET_ALL, false, "json",'j', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Display the thread info in JSON format."}, |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 1535 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1536 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 1537 | }; |
| 1538 | |
| 1539 | |
| 1540 | //------------------------------------------------------------------------- |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1541 | // CommandObjectThreadReturn |
| 1542 | //------------------------------------------------------------------------- |
| 1543 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1544 | class CommandObjectThreadReturn : public CommandObjectRaw |
| 1545 | { |
| 1546 | public: |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1547 | class CommandOptions : public Options |
| 1548 | { |
| 1549 | public: |
| 1550 | |
| 1551 | CommandOptions (CommandInterpreter &interpreter) : |
| 1552 | Options (interpreter), |
| 1553 | m_from_expression (false) |
| 1554 | { |
| 1555 | // Keep default values of all options in one place: OptionParsingStarting () |
| 1556 | OptionParsingStarting (); |
| 1557 | } |
| 1558 | |
| 1559 | virtual |
| 1560 | ~CommandOptions () |
| 1561 | { |
| 1562 | } |
| 1563 | |
| 1564 | virtual Error |
| 1565 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 1566 | { |
| 1567 | Error error; |
| 1568 | const int short_option = m_getopt_table[option_idx].val; |
| 1569 | |
| 1570 | switch (short_option) |
| 1571 | { |
| 1572 | case 'x': |
| 1573 | { |
| 1574 | bool success; |
| 1575 | bool tmp_value = Args::StringToBoolean (option_arg, false, &success); |
| 1576 | if (success) |
| 1577 | m_from_expression = tmp_value; |
| 1578 | else |
| 1579 | { |
| 1580 | error.SetErrorStringWithFormat ("invalid boolean value '%s' for 'x' option", option_arg); |
| 1581 | } |
| 1582 | } |
| 1583 | break; |
| 1584 | default: |
| 1585 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
| 1586 | break; |
| 1587 | |
| 1588 | } |
| 1589 | return error; |
| 1590 | } |
| 1591 | |
| 1592 | void |
| 1593 | OptionParsingStarting () |
| 1594 | { |
| 1595 | m_from_expression = false; |
| 1596 | } |
| 1597 | |
| 1598 | const OptionDefinition* |
| 1599 | GetDefinitions () |
| 1600 | { |
| 1601 | return g_option_table; |
| 1602 | } |
| 1603 | |
| 1604 | bool m_from_expression; |
| 1605 | |
| 1606 | // Options table: Required for subclasses of Options. |
| 1607 | |
| 1608 | static OptionDefinition g_option_table[]; |
| 1609 | |
| 1610 | // Instance variables to hold the values for command options. |
| 1611 | }; |
| 1612 | |
| 1613 | virtual |
| 1614 | Options * |
| 1615 | GetOptions () |
| 1616 | { |
| 1617 | return &m_options; |
| 1618 | } |
| 1619 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1620 | CommandObjectThreadReturn (CommandInterpreter &interpreter) : |
| 1621 | CommandObjectRaw (interpreter, |
| 1622 | "thread return", |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1623 | "Return from the currently selected frame, short-circuiting execution of the frames below it, with an optional return value," |
| 1624 | " or with the -x option from the innermost function evaluation.", |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1625 | "thread return", |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1626 | eFlagRequiresFrame | |
| 1627 | eFlagTryTargetAPILock | |
| 1628 | eFlagProcessMustBeLaunched | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1629 | eFlagProcessMustBePaused ), |
| 1630 | m_options (interpreter) |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1631 | { |
| 1632 | CommandArgumentEntry arg; |
| 1633 | CommandArgumentData expression_arg; |
| 1634 | |
| 1635 | // Define the first (and only) variant of this arg. |
| 1636 | expression_arg.arg_type = eArgTypeExpression; |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1637 | expression_arg.arg_repetition = eArgRepeatOptional; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1638 | |
| 1639 | // There is only one variant this argument could be; put it into the argument entry. |
| 1640 | arg.push_back (expression_arg); |
| 1641 | |
| 1642 | // Push the data for the first argument into the m_arguments vector. |
| 1643 | m_arguments.push_back (arg); |
| 1644 | |
| 1645 | |
| 1646 | } |
| 1647 | |
| 1648 | ~CommandObjectThreadReturn() |
| 1649 | { |
| 1650 | } |
| 1651 | |
| 1652 | protected: |
| 1653 | |
| 1654 | bool DoExecute |
| 1655 | ( |
| 1656 | const char *command, |
| 1657 | CommandReturnObject &result |
| 1658 | ) |
| 1659 | { |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1660 | // I am going to handle this by hand, because I don't want you to have to say: |
| 1661 | // "thread return -- -5". |
| 1662 | if (command[0] == '-' && command[1] == 'x') |
| 1663 | { |
| 1664 | if (command && command[2] != '\0') |
| 1665 | result.AppendWarning("Return values ignored when returning from user called expressions"); |
| 1666 | |
| 1667 | Thread *thread = m_exe_ctx.GetThreadPtr(); |
| 1668 | Error error; |
| 1669 | error = thread->UnwindInnermostExpression(); |
| 1670 | if (!error.Success()) |
| 1671 | { |
| 1672 | result.AppendErrorWithFormat ("Unwinding expression failed - %s.", error.AsCString()); |
| 1673 | result.SetStatus (eReturnStatusFailed); |
| 1674 | } |
| 1675 | else |
| 1676 | { |
| 1677 | bool success = thread->SetSelectedFrameByIndexNoisily (0, result.GetOutputStream()); |
| 1678 | if (success) |
| 1679 | { |
| 1680 | m_exe_ctx.SetFrameSP(thread->GetSelectedFrame ()); |
| 1681 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1682 | } |
| 1683 | else |
| 1684 | { |
| 1685 | result.AppendErrorWithFormat ("Could not select 0th frame after unwinding expression."); |
| 1686 | result.SetStatus (eReturnStatusFailed); |
| 1687 | } |
| 1688 | } |
| 1689 | return result.Succeeded(); |
| 1690 | } |
| 1691 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1692 | ValueObjectSP return_valobj_sp; |
| 1693 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1694 | StackFrameSP frame_sp = m_exe_ctx.GetFrameSP(); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1695 | uint32_t frame_idx = frame_sp->GetFrameIndex(); |
| 1696 | |
| 1697 | if (frame_sp->IsInlined()) |
| 1698 | { |
| 1699 | result.AppendError("Don't know how to return from inlined frames."); |
| 1700 | result.SetStatus (eReturnStatusFailed); |
| 1701 | return false; |
| 1702 | } |
| 1703 | |
| 1704 | if (command && command[0] != '\0') |
| 1705 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1706 | Target *target = m_exe_ctx.GetTargetPtr(); |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 1707 | EvaluateExpressionOptions options; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1708 | |
| 1709 | options.SetUnwindOnError(true); |
| 1710 | options.SetUseDynamic(eNoDynamicValues); |
| 1711 | |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 1712 | ExpressionResults exe_results = eExpressionSetupError; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1713 | exe_results = target->EvaluateExpression (command, |
| 1714 | frame_sp.get(), |
| 1715 | return_valobj_sp, |
| 1716 | options); |
Jim Ingham | 8646d3c | 2014-05-05 02:47:44 +0000 | [diff] [blame] | 1717 | if (exe_results != eExpressionCompleted) |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1718 | { |
| 1719 | if (return_valobj_sp) |
| 1720 | result.AppendErrorWithFormat("Error evaluating result expression: %s", return_valobj_sp->GetError().AsCString()); |
| 1721 | else |
| 1722 | result.AppendErrorWithFormat("Unknown error evaluating result expression."); |
| 1723 | result.SetStatus (eReturnStatusFailed); |
| 1724 | return false; |
| 1725 | |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | Error error; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1730 | ThreadSP thread_sp = m_exe_ctx.GetThreadSP(); |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1731 | const bool broadcast = true; |
| 1732 | error = thread_sp->ReturnFromFrame (frame_sp, return_valobj_sp, broadcast); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1733 | if (!error.Success()) |
| 1734 | { |
| 1735 | result.AppendErrorWithFormat("Error returning from frame %d of thread %d: %s.", frame_idx, thread_sp->GetIndexID(), error.AsCString()); |
| 1736 | result.SetStatus (eReturnStatusFailed); |
| 1737 | return false; |
| 1738 | } |
| 1739 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1740 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1741 | return true; |
| 1742 | } |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1743 | |
| 1744 | CommandOptions m_options; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1745 | |
| 1746 | }; |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1747 | OptionDefinition |
| 1748 | CommandObjectThreadReturn::CommandOptions::g_option_table[] = |
| 1749 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1750 | { LLDB_OPT_SET_ALL, false, "from-expression", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Return from the innermost expression evaluation."}, |
| 1751 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1752 | }; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1753 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1754 | //------------------------------------------------------------------------- |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1755 | // CommandObjectThreadJump |
| 1756 | //------------------------------------------------------------------------- |
| 1757 | |
| 1758 | class CommandObjectThreadJump : public CommandObjectParsed |
| 1759 | { |
| 1760 | public: |
| 1761 | class CommandOptions : public Options |
| 1762 | { |
| 1763 | public: |
| 1764 | |
| 1765 | CommandOptions (CommandInterpreter &interpreter) : |
| 1766 | Options (interpreter) |
| 1767 | { |
| 1768 | OptionParsingStarting (); |
| 1769 | } |
| 1770 | |
| 1771 | void |
| 1772 | OptionParsingStarting () |
| 1773 | { |
| 1774 | m_filenames.Clear(); |
| 1775 | m_line_num = 0; |
| 1776 | m_line_offset = 0; |
| 1777 | m_load_addr = LLDB_INVALID_ADDRESS; |
| 1778 | m_force = false; |
| 1779 | } |
| 1780 | |
| 1781 | virtual |
| 1782 | ~CommandOptions () |
| 1783 | { |
| 1784 | } |
| 1785 | |
| 1786 | virtual Error |
| 1787 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 1788 | { |
| 1789 | bool success; |
| 1790 | const int short_option = m_getopt_table[option_idx].val; |
| 1791 | Error error; |
| 1792 | |
| 1793 | switch (short_option) |
| 1794 | { |
| 1795 | case 'f': |
| 1796 | m_filenames.AppendIfUnique (FileSpec(option_arg, false)); |
| 1797 | if (m_filenames.GetSize() > 1) |
| 1798 | return Error("only one source file expected."); |
| 1799 | break; |
| 1800 | case 'l': |
| 1801 | m_line_num = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 1802 | if (!success || m_line_num == 0) |
| 1803 | return Error("invalid line number: '%s'.", option_arg); |
| 1804 | break; |
| 1805 | case 'b': |
| 1806 | m_line_offset = Args::StringToSInt32 (option_arg, 0, 0, &success); |
| 1807 | if (!success) |
| 1808 | return Error("invalid line offset: '%s'.", option_arg); |
| 1809 | break; |
| 1810 | case 'a': |
| 1811 | { |
| 1812 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 1813 | m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); |
| 1814 | } |
| 1815 | break; |
| 1816 | case 'r': |
| 1817 | m_force = true; |
| 1818 | break; |
| 1819 | |
| 1820 | default: |
| 1821 | return Error("invalid short option character '%c'", short_option); |
| 1822 | |
| 1823 | } |
| 1824 | return error; |
| 1825 | } |
| 1826 | |
| 1827 | const OptionDefinition* |
| 1828 | GetDefinitions () |
| 1829 | { |
| 1830 | return g_option_table; |
| 1831 | } |
| 1832 | |
| 1833 | FileSpecList m_filenames; |
| 1834 | uint32_t m_line_num; |
| 1835 | int32_t m_line_offset; |
| 1836 | lldb::addr_t m_load_addr; |
| 1837 | bool m_force; |
| 1838 | |
| 1839 | static OptionDefinition g_option_table[]; |
| 1840 | }; |
| 1841 | |
| 1842 | virtual |
| 1843 | Options * |
| 1844 | GetOptions () |
| 1845 | { |
| 1846 | return &m_options; |
| 1847 | } |
| 1848 | |
| 1849 | CommandObjectThreadJump (CommandInterpreter &interpreter) : |
| 1850 | CommandObjectParsed (interpreter, |
| 1851 | "thread jump", |
| 1852 | "Sets the program counter to a new address.", |
| 1853 | "thread jump", |
| 1854 | eFlagRequiresFrame | |
| 1855 | eFlagTryTargetAPILock | |
| 1856 | eFlagProcessMustBeLaunched | |
| 1857 | eFlagProcessMustBePaused ), |
| 1858 | m_options (interpreter) |
| 1859 | { |
| 1860 | } |
| 1861 | |
| 1862 | ~CommandObjectThreadJump() |
| 1863 | { |
| 1864 | } |
| 1865 | |
| 1866 | protected: |
| 1867 | |
| 1868 | bool DoExecute (Args& args, CommandReturnObject &result) |
| 1869 | { |
| 1870 | RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext(); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1871 | StackFrame *frame = m_exe_ctx.GetFramePtr(); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1872 | Thread *thread = m_exe_ctx.GetThreadPtr(); |
| 1873 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 1874 | const SymbolContext &sym_ctx = frame->GetSymbolContext (eSymbolContextLineEntry); |
| 1875 | |
| 1876 | if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) |
| 1877 | { |
| 1878 | // Use this address directly. |
| 1879 | Address dest = Address(m_options.m_load_addr); |
| 1880 | |
| 1881 | lldb::addr_t callAddr = dest.GetCallableLoadAddress (target); |
| 1882 | if (callAddr == LLDB_INVALID_ADDRESS) |
| 1883 | { |
| 1884 | result.AppendErrorWithFormat ("Invalid destination address."); |
| 1885 | result.SetStatus (eReturnStatusFailed); |
| 1886 | return false; |
| 1887 | } |
| 1888 | |
| 1889 | if (!reg_ctx->SetPC (callAddr)) |
| 1890 | { |
| 1891 | result.AppendErrorWithFormat ("Error changing PC value for thread %d.", thread->GetIndexID()); |
| 1892 | result.SetStatus (eReturnStatusFailed); |
| 1893 | return false; |
| 1894 | } |
| 1895 | } |
| 1896 | else |
| 1897 | { |
| 1898 | // Pick either the absolute line, or work out a relative one. |
| 1899 | int32_t line = (int32_t)m_options.m_line_num; |
| 1900 | if (line == 0) |
| 1901 | line = sym_ctx.line_entry.line + m_options.m_line_offset; |
| 1902 | |
| 1903 | // Try the current file, but override if asked. |
| 1904 | FileSpec file = sym_ctx.line_entry.file; |
| 1905 | if (m_options.m_filenames.GetSize() == 1) |
| 1906 | file = m_options.m_filenames.GetFileSpecAtIndex(0); |
| 1907 | |
| 1908 | if (!file) |
| 1909 | { |
| 1910 | result.AppendErrorWithFormat ("No source file available for the current location."); |
| 1911 | result.SetStatus (eReturnStatusFailed); |
| 1912 | return false; |
| 1913 | } |
| 1914 | |
| 1915 | std::string warnings; |
| 1916 | Error err = thread->JumpToLine (file, line, m_options.m_force, &warnings); |
| 1917 | |
| 1918 | if (err.Fail()) |
| 1919 | { |
| 1920 | result.SetError (err); |
| 1921 | return false; |
| 1922 | } |
| 1923 | |
| 1924 | if (!warnings.empty()) |
| 1925 | result.AppendWarning (warnings.c_str()); |
| 1926 | } |
| 1927 | |
| 1928 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1929 | return true; |
| 1930 | } |
| 1931 | |
| 1932 | CommandOptions m_options; |
| 1933 | }; |
| 1934 | OptionDefinition |
| 1935 | CommandObjectThreadJump::CommandOptions::g_option_table[] = |
| 1936 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1937 | { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1938 | "Specifies the source file to jump to."}, |
| 1939 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1940 | { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeLineNum, |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1941 | "Specifies the line number to jump to."}, |
| 1942 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1943 | { LLDB_OPT_SET_2, true, "by", 'b', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeOffset, |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1944 | "Jumps by a relative line offset from the current line."}, |
| 1945 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1946 | { LLDB_OPT_SET_3, true, "address", 'a', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeAddressOrExpression, |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1947 | "Jumps to a specific address."}, |
| 1948 | |
| 1949 | { LLDB_OPT_SET_1| |
| 1950 | LLDB_OPT_SET_2| |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1951 | LLDB_OPT_SET_3, false, "force",'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone,"Allows the PC to leave the current function."}, |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1952 | |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 1953 | { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL } |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1954 | }; |
| 1955 | |
| 1956 | //------------------------------------------------------------------------- |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1957 | // CommandObjectMultiwordThread |
| 1958 | //------------------------------------------------------------------------- |
| 1959 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1960 | CommandObjectMultiwordThread::CommandObjectMultiwordThread (CommandInterpreter &interpreter) : |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1961 | CommandObjectMultiword (interpreter, |
| 1962 | "thread", |
Caroline Tice | 3f4c09c | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 1963 | "A set of commands for operating on one or more threads within a running process.", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1964 | "thread <subcommand> [<subcommand-options>]") |
| 1965 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1966 | LoadSubCommand ("backtrace", CommandObjectSP (new CommandObjectThreadBacktrace (interpreter))); |
| 1967 | LoadSubCommand ("continue", CommandObjectSP (new CommandObjectThreadContinue (interpreter))); |
| 1968 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectThreadList (interpreter))); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1969 | LoadSubCommand ("return", CommandObjectSP (new CommandObjectThreadReturn (interpreter))); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1970 | LoadSubCommand ("jump", CommandObjectSP (new CommandObjectThreadJump (interpreter))); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1971 | LoadSubCommand ("select", CommandObjectSP (new CommandObjectThreadSelect (interpreter))); |
| 1972 | LoadSubCommand ("until", CommandObjectSP (new CommandObjectThreadUntil (interpreter))); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 1973 | LoadSubCommand ("info", CommandObjectSP (new CommandObjectThreadInfo (interpreter))); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1974 | LoadSubCommand ("step-in", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1975 | interpreter, |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1976 | "thread step-in", |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1977 | "Source level single step in specified thread (current thread, if none specified).", |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1978 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1979 | eStepTypeInto, |
| 1980 | eStepScopeSource))); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1981 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1982 | LoadSubCommand ("step-out", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1983 | interpreter, |
| 1984 | "thread step-out", |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1985 | "Finish executing the function of the currently selected frame and return to its call site in specified thread (current thread, if none specified).", |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1986 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1987 | eStepTypeOut, |
| 1988 | eStepScopeSource))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1989 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1990 | LoadSubCommand ("step-over", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1991 | interpreter, |
| 1992 | "thread step-over", |
| 1993 | "Source level single step in specified thread (current thread, if none specified), stepping over calls.", |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1994 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1995 | eStepTypeOver, |
| 1996 | eStepScopeSource))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1997 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1998 | LoadSubCommand ("step-inst", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1999 | interpreter, |
| 2000 | "thread step-inst", |
| 2001 | "Single step one instruction in specified thread (current thread, if none specified).", |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 2002 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2003 | eStepTypeTrace, |
| 2004 | eStepScopeInstruction))); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 2005 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2006 | LoadSubCommand ("step-inst-over", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 2007 | interpreter, |
| 2008 | "thread step-inst-over", |
| 2009 | "Single step one instruction in specified thread (current thread, if none specified), stepping over calls.", |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 2010 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 2011 | eStepTypeTraceOver, |
| 2012 | eStepScopeInstruction))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | CommandObjectMultiwordThread::~CommandObjectMultiwordThread () |
| 2016 | { |
| 2017 | } |
| 2018 | |
| 2019 | |