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 | { |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 308 | { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypeCount, "How many frames to display (-1 for all)"}, |
| 309 | { LLDB_OPT_SET_1, false, "start", 's', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFrameIndex, "Frame in which to start the backtrace"}, |
Jason Molenda | 750ea69 | 2013-11-12 07:02:07 +0000 | [diff] [blame] | 310 | { LLDB_OPT_SET_1, false, "extended", 'e', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "Show the extended backtrace, if available"}, |
Caroline Tice | deaab22 | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 311 | { 0, false, NULL, 0, 0, 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 | |
| 374 | case 'm': |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 375 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 377 | 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] | 378 | } |
| 379 | break; |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 380 | |
| 381 | case 'r': |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 382 | { |
| 383 | m_avoid_regexp.clear(); |
| 384 | m_avoid_regexp.assign(option_arg); |
| 385 | } |
| 386 | break; |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 387 | |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 388 | case 't': |
| 389 | { |
| 390 | m_step_in_target.clear(); |
| 391 | m_step_in_target.assign(option_arg); |
| 392 | |
| 393 | } |
| 394 | break; |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 395 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 396 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Greg Clayton | 8087ca2 | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 397 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | |
| 399 | } |
| 400 | return error; |
| 401 | } |
| 402 | |
| 403 | void |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 404 | OptionParsingStarting () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 405 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame^] | 406 | m_step_in_avoid_no_debug = eLazyBoolCalculate; |
| 407 | m_step_out_avoid_no_debug = eLazyBoolCalculate; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 408 | m_run_mode = eOnlyDuringStepping; |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 409 | m_avoid_regexp.clear(); |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 410 | m_step_in_target.clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 413 | const OptionDefinition* |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 414 | GetDefinitions () |
| 415 | { |
| 416 | return g_option_table; |
| 417 | } |
| 418 | |
| 419 | // Options table: Required for subclasses of Options. |
| 420 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 421 | static OptionDefinition g_option_table[]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | |
| 423 | // Instance variables to hold the values for command options. |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame^] | 424 | LazyBool m_step_in_avoid_no_debug; |
| 425 | LazyBool m_step_out_avoid_no_debug; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | RunMode m_run_mode; |
Jim Ingham | a56c800 | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 427 | std::string m_avoid_regexp; |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 428 | std::string m_step_in_target; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 429 | }; |
| 430 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 431 | CommandObjectThreadStepWithTypeAndScope (CommandInterpreter &interpreter, |
| 432 | const char *name, |
| 433 | const char *help, |
| 434 | const char *syntax, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 435 | StepType step_type, |
| 436 | StepScope step_scope) : |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 437 | CommandObjectParsed (interpreter, name, help, syntax, |
| 438 | eFlagRequiresProcess | |
| 439 | eFlagRequiresThread | |
| 440 | eFlagTryTargetAPILock | |
| 441 | eFlagProcessMustBeLaunched | |
| 442 | eFlagProcessMustBePaused ), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 443 | m_step_type (step_type), |
| 444 | m_step_scope (step_scope), |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 445 | m_options (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 446 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 447 | CommandArgumentEntry arg; |
| 448 | CommandArgumentData thread_id_arg; |
| 449 | |
| 450 | // Define the first (and only) variant of this arg. |
| 451 | thread_id_arg.arg_type = eArgTypeThreadID; |
| 452 | thread_id_arg.arg_repetition = eArgRepeatOptional; |
| 453 | |
| 454 | // There is only one variant this argument could be; put it into the argument entry. |
| 455 | arg.push_back (thread_id_arg); |
| 456 | |
| 457 | // Push the data for the first argument into the m_arguments vector. |
| 458 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | virtual |
| 462 | ~CommandObjectThreadStepWithTypeAndScope () |
| 463 | { |
| 464 | } |
| 465 | |
| 466 | virtual |
| 467 | Options * |
| 468 | GetOptions () |
| 469 | { |
| 470 | return &m_options; |
| 471 | } |
| 472 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 473 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 474 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 475 | DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 477 | Process *process = m_exe_ctx.GetProcessPtr(); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 478 | bool synchronous_execution = m_interpreter.GetSynchronous(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 479 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 480 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
| 481 | Thread *thread = NULL; |
| 482 | |
| 483 | if (command.GetArgumentCount() == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 484 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 485 | thread = process->GetThreadList().GetSelectedThread().get(); |
| 486 | if (thread == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 488 | result.AppendError ("no selected thread in process"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | result.SetStatus (eReturnStatusFailed); |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 490 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 491 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 492 | } |
| 493 | else |
| 494 | { |
| 495 | const char *thread_idx_cstr = command.GetArgumentAtIndex(0); |
| 496 | uint32_t step_thread_idx = Args::StringToUInt32 (thread_idx_cstr, LLDB_INVALID_INDEX32); |
| 497 | if (step_thread_idx == LLDB_INVALID_INDEX32) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 498 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 499 | result.AppendErrorWithFormat ("invalid thread index '%s'.\n", thread_idx_cstr); |
| 500 | result.SetStatus (eReturnStatusFailed); |
| 501 | return false; |
| 502 | } |
| 503 | thread = process->GetThreadList().FindThreadByIndexID(step_thread_idx).get(); |
| 504 | if (thread == NULL) |
| 505 | { |
| 506 | result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n", |
| 507 | step_thread_idx, num_threads); |
| 508 | result.SetStatus (eReturnStatusFailed); |
| 509 | return false; |
| 510 | } |
| 511 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 512 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 513 | const bool abort_other_plans = false; |
| 514 | const lldb::RunMode stop_other_threads = m_options.m_run_mode; |
| 515 | |
| 516 | // This is a bit unfortunate, but not all the commands in this command object support |
| 517 | // only while stepping, so I use the bool for them. |
| 518 | bool bool_stop_other_threads; |
| 519 | if (m_options.m_run_mode == eAllThreads) |
| 520 | bool_stop_other_threads = false; |
| 521 | else if (m_options.m_run_mode == eOnlyDuringStepping) |
| 522 | { |
| 523 | if (m_step_type == eStepTypeOut) |
| 524 | bool_stop_other_threads = false; |
| 525 | else |
| 526 | bool_stop_other_threads = true; |
| 527 | } |
| 528 | else |
| 529 | bool_stop_other_threads = true; |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 530 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 531 | ThreadPlanSP new_plan_sp; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 532 | |
| 533 | if (m_step_type == eStepTypeInto) |
| 534 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 535 | StackFrame *frame = thread->GetStackFrameAtIndex(0).get(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 536 | |
| 537 | if (frame->HasDebugInformation ()) |
| 538 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 539 | new_plan_sp = thread->QueueThreadPlanForStepInRange (abort_other_plans, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 540 | frame->GetSymbolContext(eSymbolContextEverything).line_entry.range, |
| 541 | frame->GetSymbolContext(eSymbolContextEverything), |
| 542 | m_options.m_step_in_target.c_str(), |
| 543 | stop_other_threads, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame^] | 544 | m_options.m_step_in_avoid_no_debug, |
| 545 | m_options.m_step_out_avoid_no_debug); |
| 546 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 547 | if (new_plan_sp && !m_options.m_avoid_regexp.empty()) |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 548 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 549 | ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (new_plan_sp.get()); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 550 | step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str()); |
Jim Ingham | 29412d1 | 2012-05-16 00:37:40 +0000 | [diff] [blame] | 551 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 552 | } |
| 553 | else |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 554 | 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] | 555 | |
| 556 | } |
| 557 | else if (m_step_type == eStepTypeOver) |
| 558 | { |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 559 | StackFrame *frame = thread->GetStackFrameAtIndex(0).get(); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 560 | |
| 561 | if (frame->HasDebugInformation()) |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 562 | new_plan_sp = thread->QueueThreadPlanForStepOverRange (abort_other_plans, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 563 | frame->GetSymbolContext(eSymbolContextEverything).line_entry.range, |
| 564 | frame->GetSymbolContext(eSymbolContextEverything), |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame^] | 565 | stop_other_threads, |
| 566 | m_options.m_step_out_avoid_no_debug); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 567 | else |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 568 | new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction (true, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 569 | abort_other_plans, |
| 570 | bool_stop_other_threads); |
| 571 | |
| 572 | } |
| 573 | else if (m_step_type == eStepTypeTrace) |
| 574 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 575 | 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] | 576 | } |
| 577 | else if (m_step_type == eStepTypeTraceOver) |
| 578 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 579 | 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] | 580 | } |
| 581 | else if (m_step_type == eStepTypeOut) |
| 582 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 583 | new_plan_sp = thread->QueueThreadPlanForStepOut (abort_other_plans, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 584 | NULL, |
| 585 | false, |
| 586 | bool_stop_other_threads, |
| 587 | eVoteYes, |
| 588 | eVoteNoOpinion, |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame^] | 589 | thread->GetSelectedFrameIndex(), |
| 590 | m_options.m_step_out_avoid_no_debug); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 591 | } |
| 592 | else |
| 593 | { |
| 594 | result.AppendError ("step type is not supported"); |
| 595 | result.SetStatus (eReturnStatusFailed); |
| 596 | return false; |
| 597 | } |
| 598 | |
| 599 | // If we got a new plan, then set it to be a master plan (User level Plans should be master plans |
| 600 | // so that they can be interruptible). Then resume the process. |
| 601 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 602 | if (new_plan_sp) |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 603 | { |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 604 | new_plan_sp->SetIsMasterPlan (true); |
| 605 | new_plan_sp->SetOkayToDiscard (false); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 606 | |
| 607 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
| 608 | process->Resume (); |
| 609 | |
| 610 | |
| 611 | if (synchronous_execution) |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 612 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 613 | StateType state = process->WaitForProcessToStop (NULL); |
| 614 | |
| 615 | //EventSP event_sp; |
| 616 | //StateType state = process->WaitForStateChangedEvents (NULL, event_sp); |
| 617 | //while (! StateIsStoppedState (state)) |
| 618 | // { |
| 619 | // state = process->WaitForStateChangedEvents (NULL, event_sp); |
| 620 | // } |
| 621 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
| 622 | result.SetDidChangeProcessState (true); |
| 623 | result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state)); |
| 624 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | } |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 626 | else |
| 627 | { |
| 628 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 629 | } |
| 630 | } |
| 631 | else |
| 632 | { |
| 633 | result.AppendError ("Couldn't find thread plan to implement step type."); |
| 634 | result.SetStatus (eReturnStatusFailed); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 635 | } |
| 636 | return result.Succeeded(); |
| 637 | } |
| 638 | |
| 639 | protected: |
| 640 | StepType m_step_type; |
| 641 | StepScope m_step_scope; |
| 642 | CommandOptions m_options; |
| 643 | }; |
| 644 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 645 | static OptionEnumValueElement |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 646 | g_tri_running_mode[] = |
| 647 | { |
Greg Clayton | ed8a705 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 648 | { eOnlyThisThread, "this-thread", "Run only this thread"}, |
| 649 | { eAllThreads, "all-threads", "Run all threads"}, |
| 650 | { eOnlyDuringStepping, "while-stepping", "Run only this thread while stepping"}, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 | { 0, NULL, NULL } |
| 652 | }; |
| 653 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 654 | static OptionEnumValueElement |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 655 | g_duo_running_mode[] = |
| 656 | { |
Greg Clayton | ed8a705 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 657 | { eOnlyThisThread, "this-thread", "Run only this thread"}, |
| 658 | { eAllThreads, "all-threads", "Run all threads"}, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | { 0, NULL, NULL } |
| 660 | }; |
| 661 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 662 | OptionDefinition |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 663 | CommandObjectThreadStepWithTypeAndScope::CommandOptions::g_option_table[] = |
| 664 | { |
Jim Ingham | 4b4b247 | 2014-03-13 02:47:14 +0000 | [diff] [blame^] | 665 | { LLDB_OPT_SET_1, false, "step-in-avoids-no-debug", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "A boolean value that sets whether stepping into functions will step over functions with no debug information."}, |
| 666 | { LLDB_OPT_SET_1, false, "step-out-avoids-no-debug", 'A', OptionParser::eRequiredArgument, 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."}, |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 667 | { LLDB_OPT_SET_1, false, "run-mode", 'm', OptionParser::eRequiredArgument, g_tri_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping the current thread."}, |
| 668 | { LLDB_OPT_SET_1, false, "step-over-regexp",'r', OptionParser::eRequiredArgument, NULL, 0, eArgTypeRegularExpression, "A regular expression that defines function names to not to stop at when stepping in."}, |
| 669 | { LLDB_OPT_SET_1, false, "step-in-target", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFunctionName, "The name of the directly called function step in should stop at when stepping into."}, |
Caroline Tice | deaab22 | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 670 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | }; |
| 672 | |
| 673 | |
| 674 | //------------------------------------------------------------------------- |
| 675 | // CommandObjectThreadContinue |
| 676 | //------------------------------------------------------------------------- |
| 677 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 678 | class CommandObjectThreadContinue : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 679 | { |
| 680 | public: |
| 681 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 682 | CommandObjectThreadContinue (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 683 | CommandObjectParsed (interpreter, |
| 684 | "thread continue", |
| 685 | "Continue execution of one or more threads in an active process.", |
| 686 | NULL, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 687 | eFlagRequiresThread | |
| 688 | eFlagTryTargetAPILock | |
| 689 | eFlagProcessMustBeLaunched | |
| 690 | eFlagProcessMustBePaused) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 691 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 692 | CommandArgumentEntry arg; |
| 693 | CommandArgumentData thread_idx_arg; |
| 694 | |
| 695 | // Define the first (and only) variant of this arg. |
| 696 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 697 | thread_idx_arg.arg_repetition = eArgRepeatPlus; |
| 698 | |
| 699 | // There is only one variant this argument could be; put it into the argument entry. |
| 700 | arg.push_back (thread_idx_arg); |
| 701 | |
| 702 | // Push the data for the first argument into the m_arguments vector. |
| 703 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | |
| 707 | virtual |
| 708 | ~CommandObjectThreadContinue () |
| 709 | { |
| 710 | } |
| 711 | |
| 712 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 713 | DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 714 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 715 | bool synchronous_execution = m_interpreter.GetSynchronous (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 716 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 717 | if (!m_interpreter.GetDebugger().GetSelectedTarget().get()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 719 | 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] | 720 | result.SetStatus (eReturnStatusFailed); |
| 721 | return false; |
| 722 | } |
| 723 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 724 | Process *process = m_exe_ctx.GetProcessPtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | if (process == NULL) |
| 726 | { |
| 727 | result.AppendError ("no process exists. Cannot continue"); |
| 728 | result.SetStatus (eReturnStatusFailed); |
| 729 | return false; |
| 730 | } |
| 731 | |
| 732 | StateType state = process->GetState(); |
| 733 | if ((state == eStateCrashed) || (state == eStateStopped) || (state == eStateSuspended)) |
| 734 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 735 | const size_t argc = command.GetArgumentCount(); |
| 736 | if (argc > 0) |
| 737 | { |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 738 | // These two lines appear at the beginning of both blocks in |
| 739 | // this if..else, but that is because we need to release the |
| 740 | // lock before calling process->Resume below. |
| 741 | Mutex::Locker locker (process->GetThreadList().GetMutex()); |
| 742 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 743 | std::vector<Thread *> resume_threads; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 744 | for (uint32_t i=0; i<argc; ++i) |
| 745 | { |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 746 | bool success; |
| 747 | const int base = 0; |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 748 | uint32_t thread_idx = Args::StringToUInt32 (command.GetArgumentAtIndex(i), LLDB_INVALID_INDEX32, base, &success); |
| 749 | if (success) |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 750 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 751 | Thread *thread = process->GetThreadList().FindThreadByIndexID(thread_idx).get(); |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 752 | |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 753 | if (thread) |
| 754 | { |
| 755 | resume_threads.push_back(thread); |
| 756 | } |
| 757 | else |
| 758 | { |
| 759 | result.AppendErrorWithFormat("invalid thread index %u.\n", thread_idx); |
| 760 | result.SetStatus (eReturnStatusFailed); |
| 761 | return false; |
| 762 | } |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 763 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 764 | else |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 765 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 766 | result.AppendErrorWithFormat ("invalid thread index argument: \"%s\".\n", command.GetArgumentAtIndex(i)); |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 767 | result.SetStatus (eReturnStatusFailed); |
| 768 | return false; |
| 769 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 770 | } |
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 (resume_threads.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 773 | { |
| 774 | result.AppendError ("no valid thread indexes were specified"); |
| 775 | result.SetStatus (eReturnStatusFailed); |
| 776 | return false; |
| 777 | } |
| 778 | else |
| 779 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 780 | if (resume_threads.size() == 1) |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 781 | result.AppendMessageWithFormat ("Resuming thread: "); |
| 782 | else |
| 783 | result.AppendMessageWithFormat ("Resuming threads: "); |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 784 | |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 785 | for (uint32_t idx=0; idx<num_threads; ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 786 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 787 | Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get(); |
| 788 | 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] | 789 | |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 790 | if (this_thread_pos != resume_threads.end()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 791 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 792 | resume_threads.erase(this_thread_pos); |
| 793 | if (resume_threads.size() > 0) |
Jim Ingham | ce76c62 | 2012-05-31 20:48:41 +0000 | [diff] [blame] | 794 | result.AppendMessageWithFormat ("%u, ", thread->GetIndexID()); |
| 795 | else |
| 796 | result.AppendMessageWithFormat ("%u ", thread->GetIndexID()); |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 797 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 798 | thread->SetResumeState (eStateRunning); |
| 799 | } |
| 800 | else |
| 801 | { |
| 802 | thread->SetResumeState (eStateSuspended); |
| 803 | } |
| 804 | } |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 805 | result.AppendMessageWithFormat ("in process %" PRIu64 "\n", process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | else |
| 809 | { |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 810 | // These two lines appear at the beginning of both blocks in |
| 811 | // this if..else, but that is because we need to release the |
| 812 | // lock before calling process->Resume below. |
| 813 | Mutex::Locker locker (process->GetThreadList().GetMutex()); |
| 814 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 815 | Thread *current_thread = process->GetThreadList().GetSelectedThread().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 816 | if (current_thread == NULL) |
| 817 | { |
| 818 | result.AppendError ("the process doesn't have a current thread"); |
| 819 | result.SetStatus (eReturnStatusFailed); |
| 820 | return false; |
| 821 | } |
| 822 | // Set the actions that the threads should each take when resuming |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 823 | for (uint32_t idx=0; idx<num_threads; ++idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 824 | { |
Greg Clayton | c8a0ce0 | 2012-07-03 20:54:16 +0000 | [diff] [blame] | 825 | Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 826 | if (thread == current_thread) |
| 827 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 828 | result.AppendMessageWithFormat ("Resuming thread 0x%4.4" PRIx64 " in process %" PRIu64 "\n", thread->GetID(), process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 829 | thread->SetResumeState (eStateRunning); |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | thread->SetResumeState (eStateSuspended); |
| 834 | } |
| 835 | } |
| 836 | } |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 837 | |
| 838 | // 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] | 839 | Error error (process->Resume()); |
| 840 | if (error.Success()) |
| 841 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 842 | result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 843 | if (synchronous_execution) |
| 844 | { |
Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 845 | state = process->WaitForProcessToStop (NULL); |
Andrew Kaylor | 9063bf4 | 2013-09-12 19:15:05 +0000 | [diff] [blame] | 846 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 847 | result.SetDidChangeProcessState (true); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 848 | result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 849 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 850 | } |
| 851 | else |
| 852 | { |
| 853 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 854 | } |
| 855 | } |
| 856 | else |
| 857 | { |
| 858 | result.AppendErrorWithFormat("Failed to resume process: %s\n", error.AsCString()); |
| 859 | result.SetStatus (eReturnStatusFailed); |
| 860 | } |
| 861 | } |
| 862 | else |
| 863 | { |
| 864 | result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n", |
| 865 | StateAsCString(state)); |
| 866 | result.SetStatus (eReturnStatusFailed); |
| 867 | } |
| 868 | |
| 869 | return result.Succeeded(); |
| 870 | } |
| 871 | |
| 872 | }; |
| 873 | |
| 874 | //------------------------------------------------------------------------- |
| 875 | // CommandObjectThreadUntil |
| 876 | //------------------------------------------------------------------------- |
| 877 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 878 | class CommandObjectThreadUntil : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | { |
| 880 | public: |
| 881 | |
| 882 | class CommandOptions : public Options |
| 883 | { |
| 884 | public: |
| 885 | uint32_t m_thread_idx; |
| 886 | uint32_t m_frame_idx; |
| 887 | |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 888 | CommandOptions (CommandInterpreter &interpreter) : |
| 889 | Options (interpreter), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 890 | m_thread_idx(LLDB_INVALID_THREAD_ID), |
| 891 | m_frame_idx(LLDB_INVALID_FRAME_ID) |
| 892 | { |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 893 | // Keep default values of all options in one place: OptionParsingStarting () |
| 894 | OptionParsingStarting (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | virtual |
| 898 | ~CommandOptions () |
| 899 | { |
| 900 | } |
| 901 | |
| 902 | virtual Error |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 903 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 904 | { |
| 905 | Error error; |
Greg Clayton | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 906 | const int short_option = m_getopt_table[option_idx].val; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 907 | |
| 908 | switch (short_option) |
| 909 | { |
| 910 | case 't': |
| 911 | { |
Greg Clayton | b132097 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 912 | m_thread_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_INDEX32); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 913 | if (m_thread_idx == LLDB_INVALID_INDEX32) |
| 914 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 915 | error.SetErrorStringWithFormat ("invalid thread index '%s'", option_arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | break; |
| 919 | case 'f': |
| 920 | { |
| 921 | m_frame_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_FRAME_ID); |
| 922 | if (m_frame_idx == LLDB_INVALID_FRAME_ID) |
| 923 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 924 | error.SetErrorStringWithFormat ("invalid frame index '%s'", option_arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 925 | } |
| 926 | } |
| 927 | break; |
| 928 | case 'm': |
| 929 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 930 | OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 931 | 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] | 932 | |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 933 | if (error.Success()) |
| 934 | { |
| 935 | if (run_mode == eAllThreads) |
| 936 | m_stop_others = false; |
| 937 | else |
| 938 | m_stop_others = true; |
| 939 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 940 | } |
| 941 | break; |
| 942 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 943 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 944 | break; |
| 945 | |
| 946 | } |
| 947 | return error; |
| 948 | } |
| 949 | |
| 950 | void |
Greg Clayton | f6b8b58 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 951 | OptionParsingStarting () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 952 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 953 | m_thread_idx = LLDB_INVALID_THREAD_ID; |
| 954 | m_frame_idx = 0; |
| 955 | m_stop_others = false; |
| 956 | } |
| 957 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 958 | const OptionDefinition* |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 959 | GetDefinitions () |
| 960 | { |
| 961 | return g_option_table; |
| 962 | } |
| 963 | |
| 964 | uint32_t m_step_thread_idx; |
| 965 | bool m_stop_others; |
| 966 | |
| 967 | // Options table: Required for subclasses of Options. |
| 968 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 969 | static OptionDefinition g_option_table[]; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 970 | |
| 971 | // Instance variables to hold the values for command options. |
| 972 | }; |
| 973 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 974 | CommandObjectThreadUntil (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 975 | CommandObjectParsed (interpreter, |
| 976 | "thread until", |
| 977 | "Run the current or specified thread until it reaches a given line number or leaves the current function.", |
| 978 | NULL, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 979 | eFlagRequiresThread | |
| 980 | eFlagTryTargetAPILock | |
| 981 | eFlagProcessMustBeLaunched | |
| 982 | eFlagProcessMustBePaused ), |
Greg Clayton | eb0103f | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 983 | m_options (interpreter) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 984 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 985 | CommandArgumentEntry arg; |
| 986 | CommandArgumentData line_num_arg; |
| 987 | |
| 988 | // Define the first (and only) variant of this arg. |
| 989 | line_num_arg.arg_type = eArgTypeLineNum; |
| 990 | line_num_arg.arg_repetition = eArgRepeatPlain; |
| 991 | |
| 992 | // There is only one variant this argument could be; put it into the argument entry. |
| 993 | arg.push_back (line_num_arg); |
| 994 | |
| 995 | // Push the data for the first argument into the m_arguments vector. |
| 996 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | |
| 1000 | virtual |
| 1001 | ~CommandObjectThreadUntil () |
| 1002 | { |
| 1003 | } |
| 1004 | |
| 1005 | virtual |
| 1006 | Options * |
| 1007 | GetOptions () |
| 1008 | { |
| 1009 | return &m_options; |
| 1010 | } |
| 1011 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1012 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1013 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1014 | DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1015 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1016 | bool synchronous_execution = m_interpreter.GetSynchronous (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1017 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1018 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 1019 | if (target == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1020 | { |
Greg Clayton | effe5c9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 1021 | 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] | 1022 | result.SetStatus (eReturnStatusFailed); |
| 1023 | return false; |
| 1024 | } |
| 1025 | |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1026 | Process *process = m_exe_ctx.GetProcessPtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1027 | if (process == NULL) |
| 1028 | { |
| 1029 | result.AppendError ("need a valid process to step"); |
| 1030 | result.SetStatus (eReturnStatusFailed); |
| 1031 | |
| 1032 | } |
| 1033 | else |
| 1034 | { |
| 1035 | Thread *thread = NULL; |
| 1036 | uint32_t line_number; |
| 1037 | |
| 1038 | if (command.GetArgumentCount() != 1) |
| 1039 | { |
| 1040 | result.AppendErrorWithFormat ("No line number provided:\n%s", GetSyntax()); |
| 1041 | result.SetStatus (eReturnStatusFailed); |
| 1042 | return false; |
| 1043 | } |
| 1044 | |
| 1045 | line_number = Args::StringToUInt32 (command.GetArgumentAtIndex(0), UINT32_MAX); |
| 1046 | if (line_number == UINT32_MAX) |
| 1047 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1048 | result.AppendErrorWithFormat ("invalid line number: '%s'.\n", command.GetArgumentAtIndex(0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1049 | result.SetStatus (eReturnStatusFailed); |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
| 1053 | if (m_options.m_thread_idx == LLDB_INVALID_THREAD_ID) |
| 1054 | { |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 1055 | thread = process->GetThreadList().GetSelectedThread().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1056 | } |
| 1057 | else |
| 1058 | { |
Greg Clayton | 76927ee | 2012-05-31 00:29:20 +0000 | [diff] [blame] | 1059 | thread = process->GetThreadList().FindThreadByIndexID(m_options.m_thread_idx).get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | if (thread == NULL) |
| 1063 | { |
| 1064 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1065 | result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n", |
| 1066 | m_options.m_thread_idx, |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1067 | num_threads); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1068 | result.SetStatus (eReturnStatusFailed); |
| 1069 | return false; |
| 1070 | } |
| 1071 | |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 1072 | const bool abort_other_plans = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1073 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1074 | StackFrame *frame = thread->GetStackFrameAtIndex(m_options.m_frame_idx).get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1075 | if (frame == NULL) |
| 1076 | { |
| 1077 | |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1078 | result.AppendErrorWithFormat ("Frame index %u is out of range for thread %u.\n", |
| 1079 | m_options.m_frame_idx, |
| 1080 | m_options.m_thread_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 | result.SetStatus (eReturnStatusFailed); |
| 1082 | return false; |
| 1083 | } |
| 1084 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1085 | ThreadPlanSP new_plan_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1086 | |
| 1087 | if (frame->HasDebugInformation ()) |
| 1088 | { |
| 1089 | // Finally we got here... Translate the given line number to a bunch of addresses: |
| 1090 | SymbolContext sc(frame->GetSymbolContext (eSymbolContextCompUnit)); |
| 1091 | LineTable *line_table = NULL; |
| 1092 | if (sc.comp_unit) |
| 1093 | line_table = sc.comp_unit->GetLineTable(); |
| 1094 | |
| 1095 | if (line_table == NULL) |
| 1096 | { |
| 1097 | result.AppendErrorWithFormat ("Failed to resolve the line table for frame %u of thread index %u.\n", |
| 1098 | m_options.m_frame_idx, m_options.m_thread_idx); |
| 1099 | result.SetStatus (eReturnStatusFailed); |
| 1100 | return false; |
| 1101 | } |
| 1102 | |
| 1103 | LineEntry function_start; |
| 1104 | uint32_t index_ptr = 0, end_ptr; |
| 1105 | std::vector<addr_t> address_list; |
| 1106 | |
| 1107 | // Find the beginning & end index of the |
| 1108 | AddressRange fun_addr_range = sc.function->GetAddressRange(); |
| 1109 | Address fun_start_addr = fun_addr_range.GetBaseAddress(); |
| 1110 | line_table->FindLineEntryByAddress (fun_start_addr, function_start, &index_ptr); |
| 1111 | |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1112 | Address fun_end_addr(fun_start_addr.GetSection(), |
| 1113 | fun_start_addr.GetOffset() + fun_addr_range.GetByteSize()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1114 | line_table->FindLineEntryByAddress (fun_end_addr, function_start, &end_ptr); |
| 1115 | |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1116 | bool all_in_function = true; |
| 1117 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1118 | while (index_ptr <= end_ptr) |
| 1119 | { |
| 1120 | LineEntry line_entry; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 1121 | const bool exact = false; |
| 1122 | 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] | 1123 | if (index_ptr == UINT32_MAX) |
| 1124 | break; |
| 1125 | |
Greg Clayton | f5e56de | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 1126 | addr_t address = line_entry.range.GetBaseAddress().GetLoadAddress(target); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1127 | if (address != LLDB_INVALID_ADDRESS) |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1128 | { |
| 1129 | if (fun_addr_range.ContainsLoadAddress (address, target)) |
| 1130 | address_list.push_back (address); |
| 1131 | else |
| 1132 | all_in_function = false; |
| 1133 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1134 | index_ptr++; |
| 1135 | } |
| 1136 | |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1137 | if (address_list.size() == 0) |
| 1138 | { |
| 1139 | if (all_in_function) |
| 1140 | result.AppendErrorWithFormat ("No line entries matching until target.\n"); |
| 1141 | else |
| 1142 | result.AppendErrorWithFormat ("Until target outside of the current function.\n"); |
| 1143 | |
| 1144 | result.SetStatus (eReturnStatusFailed); |
| 1145 | return false; |
| 1146 | } |
| 1147 | |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1148 | new_plan_sp = thread->QueueThreadPlanForStepUntil (abort_other_plans, |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1149 | &address_list.front(), |
| 1150 | address_list.size(), |
| 1151 | m_options.m_stop_others, |
Jim Ingham | f76ab67 | 2012-09-14 20:48:14 +0000 | [diff] [blame] | 1152 | m_options.m_frame_idx); |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1153 | // User level plans should be master plans so they can be interrupted (e.g. by hitting a breakpoint) |
| 1154 | // and other plans executed by the user (stepping around the breakpoint) and then a "continue" |
| 1155 | // will resume the original plan. |
Jim Ingham | 4d56e9c | 2013-07-18 21:48:26 +0000 | [diff] [blame] | 1156 | new_plan_sp->SetIsMasterPlan (true); |
| 1157 | new_plan_sp->SetOkayToDiscard(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1158 | } |
| 1159 | else |
| 1160 | { |
Jim Ingham | 9b70ddb | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1161 | result.AppendErrorWithFormat ("Frame index %u of thread %u has no debug information.\n", |
| 1162 | m_options.m_frame_idx, |
| 1163 | m_options.m_thread_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1164 | result.SetStatus (eReturnStatusFailed); |
| 1165 | return false; |
| 1166 | |
| 1167 | } |
| 1168 | |
Jim Ingham | 2976d00 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 1169 | process->GetThreadList().SetSelectedThreadByID (m_options.m_thread_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1170 | Error error (process->Resume ()); |
| 1171 | if (error.Success()) |
| 1172 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1173 | result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1174 | if (synchronous_execution) |
| 1175 | { |
| 1176 | StateType state = process->WaitForProcessToStop (NULL); |
| 1177 | |
| 1178 | result.SetDidChangeProcessState (true); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1179 | result.AppendMessageWithFormat ("Process %" PRIu64 " %s\n", process->GetID(), StateAsCString (state)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1180 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1181 | } |
| 1182 | else |
| 1183 | { |
| 1184 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 1185 | } |
| 1186 | } |
| 1187 | else |
| 1188 | { |
| 1189 | result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString()); |
| 1190 | result.SetStatus (eReturnStatusFailed); |
| 1191 | } |
| 1192 | |
| 1193 | } |
| 1194 | return result.Succeeded(); |
| 1195 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1196 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1197 | CommandOptions m_options; |
| 1198 | |
| 1199 | }; |
| 1200 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1201 | OptionDefinition |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1202 | CommandObjectThreadUntil::CommandOptions::g_option_table[] = |
| 1203 | { |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 1204 | { LLDB_OPT_SET_1, false, "frame", 'f', OptionParser::eRequiredArgument, NULL, 0, eArgTypeFrameIndex, "Frame index for until operation - defaults to 0"}, |
| 1205 | { LLDB_OPT_SET_1, false, "thread", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeThreadIndex, "Thread index for the thread for until operation"}, |
| 1206 | { LLDB_OPT_SET_1, false, "run-mode",'m', OptionParser::eRequiredArgument, g_duo_running_mode, 0, eArgTypeRunMode,"Determine how to run other threads while stepping this one"}, |
Caroline Tice | deaab22 | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 1207 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1208 | }; |
| 1209 | |
| 1210 | |
| 1211 | //------------------------------------------------------------------------- |
| 1212 | // CommandObjectThreadSelect |
| 1213 | //------------------------------------------------------------------------- |
| 1214 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1215 | class CommandObjectThreadSelect : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1216 | { |
| 1217 | public: |
| 1218 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1219 | CommandObjectThreadSelect (CommandInterpreter &interpreter) : |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1220 | CommandObjectParsed (interpreter, |
| 1221 | "thread select", |
| 1222 | "Select a thread as the currently active thread.", |
| 1223 | NULL, |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1224 | eFlagRequiresProcess | |
| 1225 | eFlagTryTargetAPILock | |
| 1226 | eFlagProcessMustBeLaunched | |
| 1227 | eFlagProcessMustBePaused ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1228 | { |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1229 | CommandArgumentEntry arg; |
| 1230 | CommandArgumentData thread_idx_arg; |
| 1231 | |
| 1232 | // Define the first (and only) variant of this arg. |
| 1233 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 1234 | thread_idx_arg.arg_repetition = eArgRepeatPlain; |
| 1235 | |
| 1236 | // There is only one variant this argument could be; put it into the argument entry. |
| 1237 | arg.push_back (thread_idx_arg); |
| 1238 | |
| 1239 | // Push the data for the first argument into the m_arguments vector. |
| 1240 | m_arguments.push_back (arg); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | |
| 1244 | virtual |
| 1245 | ~CommandObjectThreadSelect () |
| 1246 | { |
| 1247 | } |
| 1248 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1249 | protected: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1250 | virtual bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1251 | DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1252 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1253 | Process *process = m_exe_ctx.GetProcessPtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1254 | if (process == NULL) |
| 1255 | { |
| 1256 | result.AppendError ("no process"); |
| 1257 | result.SetStatus (eReturnStatusFailed); |
| 1258 | return false; |
| 1259 | } |
| 1260 | else if (command.GetArgumentCount() != 1) |
| 1261 | { |
Jason Molenda | fd54b36 | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1262 | 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] | 1263 | result.SetStatus (eReturnStatusFailed); |
| 1264 | return false; |
| 1265 | } |
| 1266 | |
| 1267 | uint32_t index_id = Args::StringToUInt32(command.GetArgumentAtIndex(0), 0, 0); |
| 1268 | |
| 1269 | Thread *new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get(); |
| 1270 | if (new_thread == NULL) |
| 1271 | { |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1272 | result.AppendErrorWithFormat ("invalid thread #%s.\n", command.GetArgumentAtIndex(0)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1273 | result.SetStatus (eReturnStatusFailed); |
| 1274 | return false; |
| 1275 | } |
| 1276 | |
Jim Ingham | c3faa19 | 2012-12-11 02:31:48 +0000 | [diff] [blame] | 1277 | process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true); |
Johnny Chen | c13ee52 | 2010-09-14 00:53:53 +0000 | [diff] [blame] | 1278 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1279 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1280 | return result.Succeeded(); |
| 1281 | } |
| 1282 | |
| 1283 | }; |
| 1284 | |
| 1285 | |
| 1286 | //------------------------------------------------------------------------- |
| 1287 | // CommandObjectThreadList |
| 1288 | //------------------------------------------------------------------------- |
| 1289 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1290 | class CommandObjectThreadList : public CommandObjectParsed |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1291 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1292 | public: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1293 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1294 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1295 | CommandObjectThreadList (CommandInterpreter &interpreter): |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1296 | CommandObjectParsed (interpreter, |
| 1297 | "thread list", |
| 1298 | "Show a summary of all current threads in a process.", |
| 1299 | "thread list", |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1300 | eFlagRequiresProcess | |
| 1301 | eFlagTryTargetAPILock | |
| 1302 | eFlagProcessMustBeLaunched | |
| 1303 | eFlagProcessMustBePaused ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1304 | { |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1305 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1306 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1307 | ~CommandObjectThreadList() |
| 1308 | { |
| 1309 | } |
| 1310 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1311 | protected: |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1312 | bool |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1313 | DoExecute (Args& command, CommandReturnObject &result) |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1314 | { |
Jim Ingham | 85e8b81 | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 1315 | Stream &strm = result.GetOutputStream(); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1316 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1317 | Process *process = m_exe_ctx.GetProcessPtr(); |
| 1318 | const bool only_threads_with_stop_reason = false; |
| 1319 | const uint32_t start_frame = 0; |
| 1320 | const uint32_t num_frames = 0; |
| 1321 | const uint32_t num_frames_with_source = 0; |
| 1322 | process->GetStatus(strm); |
| 1323 | process->GetThreadStatus (strm, |
| 1324 | only_threads_with_stop_reason, |
| 1325 | start_frame, |
| 1326 | num_frames, |
| 1327 | num_frames_with_source); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1328 | return result.Succeeded(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1329 | } |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1330 | }; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1331 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1332 | //------------------------------------------------------------------------- |
| 1333 | // CommandObjectThreadReturn |
| 1334 | //------------------------------------------------------------------------- |
| 1335 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1336 | class CommandObjectThreadReturn : public CommandObjectRaw |
| 1337 | { |
| 1338 | public: |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1339 | class CommandOptions : public Options |
| 1340 | { |
| 1341 | public: |
| 1342 | |
| 1343 | CommandOptions (CommandInterpreter &interpreter) : |
| 1344 | Options (interpreter), |
| 1345 | m_from_expression (false) |
| 1346 | { |
| 1347 | // Keep default values of all options in one place: OptionParsingStarting () |
| 1348 | OptionParsingStarting (); |
| 1349 | } |
| 1350 | |
| 1351 | virtual |
| 1352 | ~CommandOptions () |
| 1353 | { |
| 1354 | } |
| 1355 | |
| 1356 | virtual Error |
| 1357 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 1358 | { |
| 1359 | Error error; |
| 1360 | const int short_option = m_getopt_table[option_idx].val; |
| 1361 | |
| 1362 | switch (short_option) |
| 1363 | { |
| 1364 | case 'x': |
| 1365 | { |
| 1366 | bool success; |
| 1367 | bool tmp_value = Args::StringToBoolean (option_arg, false, &success); |
| 1368 | if (success) |
| 1369 | m_from_expression = tmp_value; |
| 1370 | else |
| 1371 | { |
| 1372 | error.SetErrorStringWithFormat ("invalid boolean value '%s' for 'x' option", option_arg); |
| 1373 | } |
| 1374 | } |
| 1375 | break; |
| 1376 | default: |
| 1377 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
| 1378 | break; |
| 1379 | |
| 1380 | } |
| 1381 | return error; |
| 1382 | } |
| 1383 | |
| 1384 | void |
| 1385 | OptionParsingStarting () |
| 1386 | { |
| 1387 | m_from_expression = false; |
| 1388 | } |
| 1389 | |
| 1390 | const OptionDefinition* |
| 1391 | GetDefinitions () |
| 1392 | { |
| 1393 | return g_option_table; |
| 1394 | } |
| 1395 | |
| 1396 | bool m_from_expression; |
| 1397 | |
| 1398 | // Options table: Required for subclasses of Options. |
| 1399 | |
| 1400 | static OptionDefinition g_option_table[]; |
| 1401 | |
| 1402 | // Instance variables to hold the values for command options. |
| 1403 | }; |
| 1404 | |
| 1405 | virtual |
| 1406 | Options * |
| 1407 | GetOptions () |
| 1408 | { |
| 1409 | return &m_options; |
| 1410 | } |
| 1411 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1412 | CommandObjectThreadReturn (CommandInterpreter &interpreter) : |
| 1413 | CommandObjectRaw (interpreter, |
| 1414 | "thread return", |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1415 | "Return from the currently selected frame, short-circuiting execution of the frames below it, with an optional return value," |
| 1416 | " or with the -x option from the innermost function evaluation.", |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1417 | "thread return", |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1418 | eFlagRequiresFrame | |
| 1419 | eFlagTryTargetAPILock | |
| 1420 | eFlagProcessMustBeLaunched | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1421 | eFlagProcessMustBePaused ), |
| 1422 | m_options (interpreter) |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1423 | { |
| 1424 | CommandArgumentEntry arg; |
| 1425 | CommandArgumentData expression_arg; |
| 1426 | |
| 1427 | // Define the first (and only) variant of this arg. |
| 1428 | expression_arg.arg_type = eArgTypeExpression; |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1429 | expression_arg.arg_repetition = eArgRepeatOptional; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1430 | |
| 1431 | // There is only one variant this argument could be; put it into the argument entry. |
| 1432 | arg.push_back (expression_arg); |
| 1433 | |
| 1434 | // Push the data for the first argument into the m_arguments vector. |
| 1435 | m_arguments.push_back (arg); |
| 1436 | |
| 1437 | |
| 1438 | } |
| 1439 | |
| 1440 | ~CommandObjectThreadReturn() |
| 1441 | { |
| 1442 | } |
| 1443 | |
| 1444 | protected: |
| 1445 | |
| 1446 | bool DoExecute |
| 1447 | ( |
| 1448 | const char *command, |
| 1449 | CommandReturnObject &result |
| 1450 | ) |
| 1451 | { |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1452 | // I am going to handle this by hand, because I don't want you to have to say: |
| 1453 | // "thread return -- -5". |
| 1454 | if (command[0] == '-' && command[1] == 'x') |
| 1455 | { |
| 1456 | if (command && command[2] != '\0') |
| 1457 | result.AppendWarning("Return values ignored when returning from user called expressions"); |
| 1458 | |
| 1459 | Thread *thread = m_exe_ctx.GetThreadPtr(); |
| 1460 | Error error; |
| 1461 | error = thread->UnwindInnermostExpression(); |
| 1462 | if (!error.Success()) |
| 1463 | { |
| 1464 | result.AppendErrorWithFormat ("Unwinding expression failed - %s.", error.AsCString()); |
| 1465 | result.SetStatus (eReturnStatusFailed); |
| 1466 | } |
| 1467 | else |
| 1468 | { |
| 1469 | bool success = thread->SetSelectedFrameByIndexNoisily (0, result.GetOutputStream()); |
| 1470 | if (success) |
| 1471 | { |
| 1472 | m_exe_ctx.SetFrameSP(thread->GetSelectedFrame ()); |
| 1473 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1474 | } |
| 1475 | else |
| 1476 | { |
| 1477 | result.AppendErrorWithFormat ("Could not select 0th frame after unwinding expression."); |
| 1478 | result.SetStatus (eReturnStatusFailed); |
| 1479 | } |
| 1480 | } |
| 1481 | return result.Succeeded(); |
| 1482 | } |
| 1483 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1484 | ValueObjectSP return_valobj_sp; |
| 1485 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1486 | StackFrameSP frame_sp = m_exe_ctx.GetFrameSP(); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1487 | uint32_t frame_idx = frame_sp->GetFrameIndex(); |
| 1488 | |
| 1489 | if (frame_sp->IsInlined()) |
| 1490 | { |
| 1491 | result.AppendError("Don't know how to return from inlined frames."); |
| 1492 | result.SetStatus (eReturnStatusFailed); |
| 1493 | return false; |
| 1494 | } |
| 1495 | |
| 1496 | if (command && command[0] != '\0') |
| 1497 | { |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1498 | Target *target = m_exe_ctx.GetTargetPtr(); |
Jim Ingham | 35e1bda | 2012-10-16 21:41:58 +0000 | [diff] [blame] | 1499 | EvaluateExpressionOptions options; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1500 | |
| 1501 | options.SetUnwindOnError(true); |
| 1502 | options.SetUseDynamic(eNoDynamicValues); |
| 1503 | |
| 1504 | ExecutionResults exe_results = eExecutionSetupError; |
| 1505 | exe_results = target->EvaluateExpression (command, |
| 1506 | frame_sp.get(), |
| 1507 | return_valobj_sp, |
| 1508 | options); |
| 1509 | if (exe_results != eExecutionCompleted) |
| 1510 | { |
| 1511 | if (return_valobj_sp) |
| 1512 | result.AppendErrorWithFormat("Error evaluating result expression: %s", return_valobj_sp->GetError().AsCString()); |
| 1513 | else |
| 1514 | result.AppendErrorWithFormat("Unknown error evaluating result expression."); |
| 1515 | result.SetStatus (eReturnStatusFailed); |
| 1516 | return false; |
| 1517 | |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | Error error; |
Greg Clayton | f9fc609 | 2013-01-09 19:44:40 +0000 | [diff] [blame] | 1522 | ThreadSP thread_sp = m_exe_ctx.GetThreadSP(); |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1523 | const bool broadcast = true; |
| 1524 | error = thread_sp->ReturnFromFrame (frame_sp, return_valobj_sp, broadcast); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1525 | if (!error.Success()) |
| 1526 | { |
| 1527 | result.AppendErrorWithFormat("Error returning from frame %d of thread %d: %s.", frame_idx, thread_sp->GetIndexID(), error.AsCString()); |
| 1528 | result.SetStatus (eReturnStatusFailed); |
| 1529 | return false; |
| 1530 | } |
| 1531 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1532 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1533 | return true; |
| 1534 | } |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1535 | |
| 1536 | CommandOptions m_options; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1537 | |
| 1538 | }; |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1539 | OptionDefinition |
| 1540 | CommandObjectThreadReturn::CommandOptions::g_option_table[] = |
| 1541 | { |
Virgile Bello | e2607b5 | 2013-09-05 16:42:23 +0000 | [diff] [blame] | 1542 | { LLDB_OPT_SET_ALL, false, "from-expression", 'x', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Return from the innermost expression evaluation."}, |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1543 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 1544 | }; |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1545 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1546 | //------------------------------------------------------------------------- |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1547 | // CommandObjectThreadJump |
| 1548 | //------------------------------------------------------------------------- |
| 1549 | |
| 1550 | class CommandObjectThreadJump : public CommandObjectParsed |
| 1551 | { |
| 1552 | public: |
| 1553 | class CommandOptions : public Options |
| 1554 | { |
| 1555 | public: |
| 1556 | |
| 1557 | CommandOptions (CommandInterpreter &interpreter) : |
| 1558 | Options (interpreter) |
| 1559 | { |
| 1560 | OptionParsingStarting (); |
| 1561 | } |
| 1562 | |
| 1563 | void |
| 1564 | OptionParsingStarting () |
| 1565 | { |
| 1566 | m_filenames.Clear(); |
| 1567 | m_line_num = 0; |
| 1568 | m_line_offset = 0; |
| 1569 | m_load_addr = LLDB_INVALID_ADDRESS; |
| 1570 | m_force = false; |
| 1571 | } |
| 1572 | |
| 1573 | virtual |
| 1574 | ~CommandOptions () |
| 1575 | { |
| 1576 | } |
| 1577 | |
| 1578 | virtual Error |
| 1579 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 1580 | { |
| 1581 | bool success; |
| 1582 | const int short_option = m_getopt_table[option_idx].val; |
| 1583 | Error error; |
| 1584 | |
| 1585 | switch (short_option) |
| 1586 | { |
| 1587 | case 'f': |
| 1588 | m_filenames.AppendIfUnique (FileSpec(option_arg, false)); |
| 1589 | if (m_filenames.GetSize() > 1) |
| 1590 | return Error("only one source file expected."); |
| 1591 | break; |
| 1592 | case 'l': |
| 1593 | m_line_num = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 1594 | if (!success || m_line_num == 0) |
| 1595 | return Error("invalid line number: '%s'.", option_arg); |
| 1596 | break; |
| 1597 | case 'b': |
| 1598 | m_line_offset = Args::StringToSInt32 (option_arg, 0, 0, &success); |
| 1599 | if (!success) |
| 1600 | return Error("invalid line offset: '%s'.", option_arg); |
| 1601 | break; |
| 1602 | case 'a': |
| 1603 | { |
| 1604 | ExecutionContext exe_ctx (m_interpreter.GetExecutionContext()); |
| 1605 | m_load_addr = Args::StringToAddress(&exe_ctx, option_arg, LLDB_INVALID_ADDRESS, &error); |
| 1606 | } |
| 1607 | break; |
| 1608 | case 'r': |
| 1609 | m_force = true; |
| 1610 | break; |
| 1611 | |
| 1612 | default: |
| 1613 | return Error("invalid short option character '%c'", short_option); |
| 1614 | |
| 1615 | } |
| 1616 | return error; |
| 1617 | } |
| 1618 | |
| 1619 | const OptionDefinition* |
| 1620 | GetDefinitions () |
| 1621 | { |
| 1622 | return g_option_table; |
| 1623 | } |
| 1624 | |
| 1625 | FileSpecList m_filenames; |
| 1626 | uint32_t m_line_num; |
| 1627 | int32_t m_line_offset; |
| 1628 | lldb::addr_t m_load_addr; |
| 1629 | bool m_force; |
| 1630 | |
| 1631 | static OptionDefinition g_option_table[]; |
| 1632 | }; |
| 1633 | |
| 1634 | virtual |
| 1635 | Options * |
| 1636 | GetOptions () |
| 1637 | { |
| 1638 | return &m_options; |
| 1639 | } |
| 1640 | |
| 1641 | CommandObjectThreadJump (CommandInterpreter &interpreter) : |
| 1642 | CommandObjectParsed (interpreter, |
| 1643 | "thread jump", |
| 1644 | "Sets the program counter to a new address.", |
| 1645 | "thread jump", |
| 1646 | eFlagRequiresFrame | |
| 1647 | eFlagTryTargetAPILock | |
| 1648 | eFlagProcessMustBeLaunched | |
| 1649 | eFlagProcessMustBePaused ), |
| 1650 | m_options (interpreter) |
| 1651 | { |
| 1652 | } |
| 1653 | |
| 1654 | ~CommandObjectThreadJump() |
| 1655 | { |
| 1656 | } |
| 1657 | |
| 1658 | protected: |
| 1659 | |
| 1660 | bool DoExecute (Args& args, CommandReturnObject &result) |
| 1661 | { |
| 1662 | RegisterContext *reg_ctx = m_exe_ctx.GetRegisterContext(); |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1663 | StackFrame *frame = m_exe_ctx.GetFramePtr(); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1664 | Thread *thread = m_exe_ctx.GetThreadPtr(); |
| 1665 | Target *target = m_exe_ctx.GetTargetPtr(); |
| 1666 | const SymbolContext &sym_ctx = frame->GetSymbolContext (eSymbolContextLineEntry); |
| 1667 | |
| 1668 | if (m_options.m_load_addr != LLDB_INVALID_ADDRESS) |
| 1669 | { |
| 1670 | // Use this address directly. |
| 1671 | Address dest = Address(m_options.m_load_addr); |
| 1672 | |
| 1673 | lldb::addr_t callAddr = dest.GetCallableLoadAddress (target); |
| 1674 | if (callAddr == LLDB_INVALID_ADDRESS) |
| 1675 | { |
| 1676 | result.AppendErrorWithFormat ("Invalid destination address."); |
| 1677 | result.SetStatus (eReturnStatusFailed); |
| 1678 | return false; |
| 1679 | } |
| 1680 | |
| 1681 | if (!reg_ctx->SetPC (callAddr)) |
| 1682 | { |
| 1683 | result.AppendErrorWithFormat ("Error changing PC value for thread %d.", thread->GetIndexID()); |
| 1684 | result.SetStatus (eReturnStatusFailed); |
| 1685 | return false; |
| 1686 | } |
| 1687 | } |
| 1688 | else |
| 1689 | { |
| 1690 | // Pick either the absolute line, or work out a relative one. |
| 1691 | int32_t line = (int32_t)m_options.m_line_num; |
| 1692 | if (line == 0) |
| 1693 | line = sym_ctx.line_entry.line + m_options.m_line_offset; |
| 1694 | |
| 1695 | // Try the current file, but override if asked. |
| 1696 | FileSpec file = sym_ctx.line_entry.file; |
| 1697 | if (m_options.m_filenames.GetSize() == 1) |
| 1698 | file = m_options.m_filenames.GetFileSpecAtIndex(0); |
| 1699 | |
| 1700 | if (!file) |
| 1701 | { |
| 1702 | result.AppendErrorWithFormat ("No source file available for the current location."); |
| 1703 | result.SetStatus (eReturnStatusFailed); |
| 1704 | return false; |
| 1705 | } |
| 1706 | |
| 1707 | std::string warnings; |
| 1708 | Error err = thread->JumpToLine (file, line, m_options.m_force, &warnings); |
| 1709 | |
| 1710 | if (err.Fail()) |
| 1711 | { |
| 1712 | result.SetError (err); |
| 1713 | return false; |
| 1714 | } |
| 1715 | |
| 1716 | if (!warnings.empty()) |
| 1717 | result.AppendWarning (warnings.c_str()); |
| 1718 | } |
| 1719 | |
| 1720 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1721 | return true; |
| 1722 | } |
| 1723 | |
| 1724 | CommandOptions m_options; |
| 1725 | }; |
| 1726 | OptionDefinition |
| 1727 | CommandObjectThreadJump::CommandOptions::g_option_table[] = |
| 1728 | { |
| 1729 | { LLDB_OPT_SET_1, false, "file", 'f', OptionParser::eRequiredArgument, NULL, CommandCompletions::eSourceFileCompletion, eArgTypeFilename, |
| 1730 | "Specifies the source file to jump to."}, |
| 1731 | |
| 1732 | { LLDB_OPT_SET_1, true, "line", 'l', OptionParser::eRequiredArgument, NULL, 0, eArgTypeLineNum, |
| 1733 | "Specifies the line number to jump to."}, |
| 1734 | |
| 1735 | { LLDB_OPT_SET_2, true, "by", 'b', OptionParser::eRequiredArgument, NULL, 0, eArgTypeOffset, |
| 1736 | "Jumps by a relative line offset from the current line."}, |
| 1737 | |
| 1738 | { LLDB_OPT_SET_3, true, "address", 'a', OptionParser::eRequiredArgument, NULL, 0, eArgTypeAddressOrExpression, |
| 1739 | "Jumps to a specific address."}, |
| 1740 | |
| 1741 | { LLDB_OPT_SET_1| |
| 1742 | LLDB_OPT_SET_2| |
| 1743 | LLDB_OPT_SET_3, false, "force",'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone,"Allows the PC to leave the current function."}, |
| 1744 | |
| 1745 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 1746 | }; |
| 1747 | |
| 1748 | //------------------------------------------------------------------------- |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1749 | // CommandObjectMultiwordThread |
| 1750 | //------------------------------------------------------------------------- |
| 1751 | |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1752 | CommandObjectMultiwordThread::CommandObjectMultiwordThread (CommandInterpreter &interpreter) : |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1753 | CommandObjectMultiword (interpreter, |
| 1754 | "thread", |
Caroline Tice | 3f4c09c | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 1755 | "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] | 1756 | "thread <subcommand> [<subcommand-options>]") |
| 1757 | { |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1758 | LoadSubCommand ("backtrace", CommandObjectSP (new CommandObjectThreadBacktrace (interpreter))); |
| 1759 | LoadSubCommand ("continue", CommandObjectSP (new CommandObjectThreadContinue (interpreter))); |
| 1760 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectThreadList (interpreter))); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1761 | LoadSubCommand ("return", CommandObjectSP (new CommandObjectThreadReturn (interpreter))); |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1762 | LoadSubCommand ("jump", CommandObjectSP (new CommandObjectThreadJump (interpreter))); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1763 | LoadSubCommand ("select", CommandObjectSP (new CommandObjectThreadSelect (interpreter))); |
| 1764 | LoadSubCommand ("until", CommandObjectSP (new CommandObjectThreadUntil (interpreter))); |
| 1765 | LoadSubCommand ("step-in", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1766 | interpreter, |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1767 | "thread step-in", |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1768 | "Source level single step in specified thread (current thread, if none specified).", |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1769 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1770 | eStepTypeInto, |
| 1771 | eStepScopeSource))); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1772 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1773 | LoadSubCommand ("step-out", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1774 | interpreter, |
| 1775 | "thread step-out", |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 1776 | "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] | 1777 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1778 | eStepTypeOut, |
| 1779 | eStepScopeSource))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1780 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1781 | LoadSubCommand ("step-over", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1782 | interpreter, |
| 1783 | "thread step-over", |
| 1784 | "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] | 1785 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1786 | eStepTypeOver, |
| 1787 | eStepScopeSource))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1788 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1789 | LoadSubCommand ("step-inst", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1790 | interpreter, |
| 1791 | "thread step-inst", |
| 1792 | "Single step one instruction in specified thread (current thread, if none specified).", |
Caroline Tice | 405fe67 | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1793 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1794 | eStepTypeTrace, |
| 1795 | eStepScopeInstruction))); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1796 | |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1797 | LoadSubCommand ("step-inst-over", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1798 | interpreter, |
| 1799 | "thread step-inst-over", |
| 1800 | "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] | 1801 | NULL, |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1802 | eStepTypeTraceOver, |
| 1803 | eStepScopeInstruction))); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | CommandObjectMultiwordThread::~CommandObjectMultiwordThread () |
| 1807 | { |
| 1808 | } |
| 1809 | |
| 1810 | |