Chris Lattner | 24943d2 | 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 | |
| 10 | #include "CommandObjectThread.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/State.h" |
| 18 | #include "lldb/Core/SourceManager.h" |
| 19 | |
Greg Clayton | cd54803 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 20 | #include "lldb/Host/Host.h" |
| 21 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 23 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 24 | |
| 25 | #include "lldb/Target/Process.h" |
| 26 | #include "lldb/Target/RegisterContext.h" |
| 27 | #include "lldb/Target/Target.h" |
| 28 | #include "lldb/Target/Thread.h" |
| 29 | #include "lldb/Target/ThreadPlan.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 31 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 32 | #include "lldb/Target/ThreadPlanStepRange.h" |
| 33 | #include "lldb/Target/ThreadPlanStepInRange.h" |
| 34 | #include "lldb/Symbol/LineTable.h" |
| 35 | #include "lldb/Symbol/LineEntry.h" |
| 36 | |
| 37 | using namespace lldb; |
| 38 | using namespace lldb_private; |
| 39 | |
| 40 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | //------------------------------------------------------------------------- |
| 42 | // CommandObjectThreadBacktrace |
| 43 | //------------------------------------------------------------------------- |
| 44 | |
| 45 | class CommandObjectThreadBacktrace : public CommandObject |
| 46 | { |
| 47 | public: |
| 48 | |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 49 | class CommandOptions : public Options |
| 50 | { |
| 51 | public: |
| 52 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 53 | CommandOptions (CommandInterpreter &interpreter) : |
| 54 | Options(interpreter) |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 55 | { |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 56 | // Keep default values of all options in one place: OptionParsingStarting () |
| 57 | OptionParsingStarting (); |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | virtual |
| 61 | ~CommandOptions () |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | virtual Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 66 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 67 | { |
| 68 | Error error; |
| 69 | char short_option = (char) m_getopt_table[option_idx].val; |
| 70 | |
| 71 | switch (short_option) |
| 72 | { |
| 73 | case 'c': |
| 74 | { |
| 75 | bool success; |
| 76 | int32_t input_count = Args::StringToSInt32 (option_arg, -1, 0, &success); |
| 77 | if (!success) |
| 78 | error.SetErrorStringWithFormat("Invalid integer value for option '%c'.\n", short_option); |
| 79 | if (input_count < -1) |
| 80 | m_count = UINT32_MAX; |
| 81 | else |
| 82 | m_count = input_count; |
| 83 | } |
| 84 | break; |
| 85 | case 's': |
| 86 | { |
| 87 | bool success; |
| 88 | m_start = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 89 | if (!success) |
| 90 | error.SetErrorStringWithFormat("Invalid integer value for option '%c'.\n", short_option); |
| 91 | } |
| 92 | break; |
| 93 | default: |
| 94 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 95 | break; |
| 96 | |
| 97 | } |
| 98 | return error; |
| 99 | } |
| 100 | |
| 101 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 102 | OptionParsingStarting () |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 103 | { |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 104 | m_count = UINT32_MAX; |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 105 | m_start = 0; |
| 106 | } |
| 107 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 108 | const OptionDefinition* |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 109 | GetDefinitions () |
| 110 | { |
| 111 | return g_option_table; |
| 112 | } |
| 113 | |
| 114 | // Options table: Required for subclasses of Options. |
| 115 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 116 | static OptionDefinition g_option_table[]; |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 117 | |
| 118 | // Instance variables to hold the values for command options. |
| 119 | uint32_t m_count; |
| 120 | uint32_t m_start; |
| 121 | }; |
| 122 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 123 | CommandObjectThreadBacktrace (CommandInterpreter &interpreter) : |
| 124 | CommandObject (interpreter, |
| 125 | "thread backtrace", |
Caroline Tice | 31fbb64 | 2010-09-08 22:08:58 +0000 | [diff] [blame] | 126 | "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.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 127 | NULL, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 128 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 129 | m_options(interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 130 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 131 | CommandArgumentEntry arg; |
| 132 | CommandArgumentData thread_idx_arg; |
| 133 | |
| 134 | // Define the first (and only) variant of this arg. |
| 135 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 136 | thread_idx_arg.arg_repetition = eArgRepeatStar; |
| 137 | |
| 138 | // There is only one variant this argument could be; put it into the argument entry. |
| 139 | arg.push_back (thread_idx_arg); |
| 140 | |
| 141 | // Push the data for the first argument into the m_arguments vector. |
| 142 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | ~CommandObjectThreadBacktrace() |
| 146 | { |
| 147 | } |
| 148 | |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 149 | virtual Options * |
| 150 | GetOptions () |
| 151 | { |
| 152 | return &m_options; |
| 153 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 154 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 155 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 156 | Execute (Args& command, CommandReturnObject &result) |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 157 | { |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 158 | result.SetStatus (eReturnStatusSuccessFinishResult); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 159 | Stream &strm = result.GetOutputStream(); |
| 160 | |
| 161 | // Don't show source context when doing backtraces. |
| 162 | const uint32_t num_frames_with_source = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | if (command.GetArgumentCount() == 0) |
| 164 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 165 | ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | if (exe_ctx.thread) |
| 167 | { |
Johnny Chen | 2d268cb | 2011-06-02 18:02:15 +0000 | [diff] [blame] | 168 | // Thread::GetStatus() returns the number of frames shown. |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 169 | if (exe_ctx.thread->GetStatus (strm, |
| 170 | m_options.m_start, |
| 171 | m_options.m_count, |
| 172 | num_frames_with_source)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | { |
| 174 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 175 | } |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | result.AppendError ("invalid thread"); |
| 180 | result.SetStatus (eReturnStatusFailed); |
| 181 | } |
| 182 | } |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 183 | else if (command.GetArgumentCount() == 1 && ::strcmp (command.GetArgumentAtIndex(0), "all") == 0) |
| 184 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 185 | Process *process = m_interpreter.GetExecutionContext().process; |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 186 | uint32_t num_threads = process->GetThreadList().GetSize(); |
| 187 | for (uint32_t i = 0; i < num_threads; i++) |
| 188 | { |
| 189 | ThreadSP thread_sp = process->GetThreadList().GetThreadAtIndex(i); |
Johnny Chen | 05750a6 | 2011-06-01 23:19:52 +0000 | [diff] [blame] | 190 | if (!thread_sp->GetStatus (strm, |
| 191 | m_options.m_start, |
| 192 | m_options.m_count, |
| 193 | num_frames_with_source)) |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 194 | { |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 195 | result.AppendErrorWithFormat ("error displaying backtrace for thread: \"0x%4.4x\"\n", i); |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 196 | result.SetStatus (eReturnStatusFailed); |
| 197 | return false; |
| 198 | } |
Jim Ingham | 7868bcc | 2011-07-26 02:39:59 +0000 | [diff] [blame^] | 199 | |
| 200 | if (i < num_threads - 1) |
| 201 | result.AppendMessage(""); |
| 202 | |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 203 | } |
| 204 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | else |
| 206 | { |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 207 | uint32_t num_args = command.GetArgumentCount(); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 208 | Process *process = m_interpreter.GetExecutionContext().process; |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 209 | std::vector<ThreadSP> thread_sps; |
| 210 | |
| 211 | for (uint32_t i = 0; i < num_args; i++) |
| 212 | { |
| 213 | bool success; |
| 214 | |
| 215 | uint32_t thread_idx = Args::StringToUInt32(command.GetArgumentAtIndex(i), 0, 0, &success); |
| 216 | if (!success) |
| 217 | { |
| 218 | result.AppendErrorWithFormat ("invalid thread specification: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 219 | result.SetStatus (eReturnStatusFailed); |
| 220 | return false; |
| 221 | } |
| 222 | |
| 223 | thread_sps.push_back(process->GetThreadList().FindThreadByIndexID(thread_idx)); |
| 224 | |
| 225 | if (!thread_sps[i]) |
| 226 | { |
| 227 | result.AppendErrorWithFormat ("no thread with index: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 228 | result.SetStatus (eReturnStatusFailed); |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | } |
| 233 | |
| 234 | for (uint32_t i = 0; i < num_args; i++) |
| 235 | { |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 236 | if (!thread_sps[i]->GetStatus (strm, |
| 237 | m_options.m_start, |
| 238 | m_options.m_count, |
| 239 | num_frames_with_source)) |
Jim Ingham | eb10f7b | 2010-08-27 00:58:05 +0000 | [diff] [blame] | 240 | { |
| 241 | result.AppendErrorWithFormat ("error displaying backtrace for thread: \"%s\"\n", command.GetArgumentAtIndex(i)); |
| 242 | result.SetStatus (eReturnStatusFailed); |
| 243 | return false; |
| 244 | } |
| 245 | |
| 246 | if (i < num_args - 1) |
| 247 | result.AppendMessage(""); |
| 248 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | } |
| 250 | return result.Succeeded(); |
| 251 | } |
| 252 | protected: |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 253 | CommandOptions m_options; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | }; |
| 255 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 256 | OptionDefinition |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 257 | CommandObjectThreadBacktrace::CommandOptions::g_option_table[] = |
| 258 | { |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 259 | { LLDB_OPT_SET_1, false, "count", 'c', required_argument, NULL, 0, eArgTypeCount, "How many frames to display (-1 for all)"}, |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 260 | { LLDB_OPT_SET_1, false, "start", 's', required_argument, NULL, 0, eArgTypeFrameIndex, "Frame in which to start the backtrace"}, |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 261 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 262 | }; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | |
Greg Clayton | c041815 | 2010-07-07 17:07:17 +0000 | [diff] [blame] | 264 | enum StepScope |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | { |
| 266 | eStepScopeSource, |
| 267 | eStepScopeInstruction |
| 268 | }; |
| 269 | |
| 270 | class CommandObjectThreadStepWithTypeAndScope : public CommandObject |
| 271 | { |
| 272 | public: |
| 273 | |
| 274 | class CommandOptions : public Options |
| 275 | { |
| 276 | public: |
| 277 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 278 | CommandOptions (CommandInterpreter &interpreter) : |
| 279 | Options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | { |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 281 | // Keep default values of all options in one place: OptionParsingStarting () |
| 282 | OptionParsingStarting (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | virtual |
| 286 | ~CommandOptions () |
| 287 | { |
| 288 | } |
| 289 | |
| 290 | virtual Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 291 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | { |
| 293 | Error error; |
| 294 | char short_option = (char) m_getopt_table[option_idx].val; |
| 295 | |
| 296 | switch (short_option) |
| 297 | { |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 298 | case 'a': |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 299 | { |
| 300 | bool success; |
| 301 | m_avoid_no_debug = Args::StringToBoolean (option_arg, true, &success); |
| 302 | if (!success) |
| 303 | error.SetErrorStringWithFormat("Invalid boolean value for option '%c'.\n", short_option); |
| 304 | } |
| 305 | break; |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 306 | |
| 307 | case 'm': |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 308 | { |
| 309 | bool found_one = false; |
| 310 | OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; |
| 311 | m_run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, &found_one); |
| 312 | if (!found_one) |
| 313 | error.SetErrorStringWithFormat("Invalid enumeration value for option '%c'.\n", short_option); |
| 314 | } |
| 315 | break; |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 316 | |
| 317 | case 'r': |
Jim Ingham | 809ab9b | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 318 | { |
| 319 | m_avoid_regexp.clear(); |
| 320 | m_avoid_regexp.assign(option_arg); |
| 321 | } |
| 322 | break; |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 323 | |
| 324 | default: |
| 325 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 326 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 327 | |
| 328 | } |
| 329 | return error; |
| 330 | } |
| 331 | |
| 332 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 333 | OptionParsingStarting () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 334 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 335 | m_avoid_no_debug = true; |
| 336 | m_run_mode = eOnlyDuringStepping; |
Jim Ingham | 809ab9b | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 337 | m_avoid_regexp.clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 340 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 341 | GetDefinitions () |
| 342 | { |
| 343 | return g_option_table; |
| 344 | } |
| 345 | |
| 346 | // Options table: Required for subclasses of Options. |
| 347 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 348 | static OptionDefinition g_option_table[]; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 349 | |
| 350 | // Instance variables to hold the values for command options. |
| 351 | bool m_avoid_no_debug; |
| 352 | RunMode m_run_mode; |
Jim Ingham | 809ab9b | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 353 | std::string m_avoid_regexp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 356 | CommandObjectThreadStepWithTypeAndScope (CommandInterpreter &interpreter, |
| 357 | const char *name, |
| 358 | const char *help, |
| 359 | const char *syntax, |
| 360 | uint32_t flags, |
| 361 | StepType step_type, |
| 362 | StepScope step_scope) : |
| 363 | CommandObject (interpreter, name, help, syntax, flags), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 364 | m_step_type (step_type), |
| 365 | m_step_scope (step_scope), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 366 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 367 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 368 | CommandArgumentEntry arg; |
| 369 | CommandArgumentData thread_id_arg; |
| 370 | |
| 371 | // Define the first (and only) variant of this arg. |
| 372 | thread_id_arg.arg_type = eArgTypeThreadID; |
| 373 | thread_id_arg.arg_repetition = eArgRepeatOptional; |
| 374 | |
| 375 | // There is only one variant this argument could be; put it into the argument entry. |
| 376 | arg.push_back (thread_id_arg); |
| 377 | |
| 378 | // Push the data for the first argument into the m_arguments vector. |
| 379 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | virtual |
| 383 | ~CommandObjectThreadStepWithTypeAndScope () |
| 384 | { |
| 385 | } |
| 386 | |
| 387 | virtual |
| 388 | Options * |
| 389 | GetOptions () |
| 390 | { |
| 391 | return &m_options; |
| 392 | } |
| 393 | |
| 394 | virtual bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 395 | Execute |
| 396 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 397 | Args& command, |
| 398 | CommandReturnObject &result |
| 399 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 400 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 401 | Process *process = m_interpreter.GetExecutionContext().process; |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 402 | bool synchronous_execution = m_interpreter.GetSynchronous(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 403 | |
| 404 | if (process == NULL) |
| 405 | { |
| 406 | result.AppendError ("need a valid process to step"); |
| 407 | result.SetStatus (eReturnStatusFailed); |
| 408 | |
| 409 | } |
| 410 | else |
| 411 | { |
| 412 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
| 413 | Thread *thread = NULL; |
| 414 | |
| 415 | if (command.GetArgumentCount() == 0) |
| 416 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 417 | thread = process->GetThreadList().GetSelectedThread().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 418 | if (thread == NULL) |
| 419 | { |
Jim Ingham | 8ab1a80 | 2010-08-26 23:36:03 +0000 | [diff] [blame] | 420 | result.AppendError ("no selected thread in process"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | result.SetStatus (eReturnStatusFailed); |
| 422 | return false; |
| 423 | } |
| 424 | } |
| 425 | else |
| 426 | { |
| 427 | const char *thread_idx_cstr = command.GetArgumentAtIndex(0); |
| 428 | uint32_t step_thread_idx = Args::StringToUInt32 (thread_idx_cstr, LLDB_INVALID_INDEX32); |
| 429 | if (step_thread_idx == LLDB_INVALID_INDEX32) |
| 430 | { |
| 431 | result.AppendErrorWithFormat ("Invalid thread index '%s'.\n", thread_idx_cstr); |
| 432 | result.SetStatus (eReturnStatusFailed); |
| 433 | return false; |
| 434 | } |
| 435 | thread = process->GetThreadList().FindThreadByIndexID(step_thread_idx).get(); |
| 436 | if (thread == NULL) |
| 437 | { |
| 438 | result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n", |
| 439 | step_thread_idx, 0, num_threads); |
| 440 | result.SetStatus (eReturnStatusFailed); |
| 441 | return false; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | const bool abort_other_plans = false; |
| 446 | const lldb::RunMode stop_other_threads = m_options.m_run_mode; |
| 447 | |
| 448 | // This is a bit unfortunate, but not all the commands in this command object support |
| 449 | // only while stepping, so I use the bool for them. |
| 450 | bool bool_stop_other_threads; |
| 451 | if (m_options.m_run_mode == eAllThreads) |
| 452 | bool_stop_other_threads = false; |
| 453 | else |
| 454 | bool_stop_other_threads = true; |
| 455 | |
| 456 | if (m_step_type == eStepTypeInto) |
| 457 | { |
| 458 | StackFrame *frame = thread->GetStackFrameAtIndex(0).get(); |
| 459 | ThreadPlan *new_plan; |
| 460 | |
| 461 | if (frame->HasDebugInformation ()) |
| 462 | { |
| 463 | new_plan = thread->QueueThreadPlanForStepRange (abort_other_plans, m_step_type, |
| 464 | frame->GetSymbolContext(eSymbolContextEverything).line_entry.range, |
| 465 | frame->GetSymbolContext(eSymbolContextEverything), |
Greg Clayton | 8f5fd6b | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 466 | stop_other_threads, |
| 467 | m_options.m_avoid_no_debug); |
Jim Ingham | 809ab9b | 2010-07-10 02:27:39 +0000 | [diff] [blame] | 468 | if (new_plan && !m_options.m_avoid_regexp.empty()) |
| 469 | { |
| 470 | ThreadPlanStepInRange *step_in_range_plan = static_cast<ThreadPlanStepInRange *> (new_plan); |
| 471 | step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str()); |
| 472 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 473 | } |
| 474 | else |
| 475 | new_plan = thread->QueueThreadPlanForStepSingleInstruction (false, abort_other_plans, bool_stop_other_threads); |
| 476 | |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 477 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 478 | process->Resume (); |
| 479 | } |
| 480 | else if (m_step_type == eStepTypeOver) |
| 481 | { |
| 482 | StackFrame *frame = thread->GetStackFrameAtIndex(0).get(); |
| 483 | ThreadPlan *new_plan; |
| 484 | |
| 485 | if (frame->HasDebugInformation()) |
| 486 | new_plan = thread->QueueThreadPlanForStepRange (abort_other_plans, |
| 487 | m_step_type, |
| 488 | frame->GetSymbolContext(eSymbolContextEverything).line_entry.range, |
| 489 | frame->GetSymbolContext(eSymbolContextEverything), |
Greg Clayton | 8f5fd6b | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 490 | stop_other_threads, |
| 491 | false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 492 | else |
| 493 | new_plan = thread->QueueThreadPlanForStepSingleInstruction (true, |
| 494 | abort_other_plans, |
| 495 | bool_stop_other_threads); |
| 496 | |
| 497 | // FIXME: This will keep the step plan on the thread stack when we hit a breakpoint while stepping over. |
| 498 | // Maybe there should be a parameter to control this. |
| 499 | new_plan->SetOkayToDiscard(false); |
| 500 | |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 501 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 502 | process->Resume (); |
| 503 | } |
| 504 | else if (m_step_type == eStepTypeTrace) |
| 505 | { |
| 506 | thread->QueueThreadPlanForStepSingleInstruction (false, abort_other_plans, bool_stop_other_threads); |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 507 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 508 | process->Resume (); |
| 509 | } |
| 510 | else if (m_step_type == eStepTypeTraceOver) |
| 511 | { |
| 512 | thread->QueueThreadPlanForStepSingleInstruction (true, abort_other_plans, bool_stop_other_threads); |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 513 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 514 | process->Resume (); |
| 515 | } |
| 516 | else if (m_step_type == eStepTypeOut) |
| 517 | { |
| 518 | ThreadPlan *new_plan; |
| 519 | |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 520 | new_plan = thread->QueueThreadPlanForStepOut (abort_other_plans, |
| 521 | NULL, |
| 522 | false, |
| 523 | bool_stop_other_threads, |
| 524 | eVoteYes, |
| 525 | eVoteNoOpinion, |
| 526 | thread->GetSelectedFrameIndex()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 527 | // FIXME: This will keep the step plan on the thread stack when we hit a breakpoint while stepping over. |
| 528 | // Maybe there should be a parameter to control this. |
| 529 | new_plan->SetOkayToDiscard(false); |
| 530 | |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 531 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 532 | process->Resume (); |
| 533 | } |
| 534 | else |
| 535 | { |
| 536 | result.AppendError ("step type is not supported"); |
| 537 | result.SetStatus (eReturnStatusFailed); |
| 538 | } |
| 539 | if (synchronous_execution) |
| 540 | { |
| 541 | StateType state = process->WaitForProcessToStop (NULL); |
| 542 | |
| 543 | //EventSP event_sp; |
| 544 | //StateType state = process->WaitForStateChangedEvents (NULL, event_sp); |
| 545 | //while (! StateIsStoppedState (state)) |
| 546 | // { |
| 547 | // state = process->WaitForStateChangedEvents (NULL, event_sp); |
| 548 | // } |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 549 | process->GetThreadList().SetSelectedThreadByID (thread->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | result.SetDidChangeProcessState (true); |
| 551 | result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); |
| 552 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 553 | } |
| 554 | } |
| 555 | return result.Succeeded(); |
| 556 | } |
| 557 | |
| 558 | protected: |
| 559 | StepType m_step_type; |
| 560 | StepScope m_step_scope; |
| 561 | CommandOptions m_options; |
| 562 | }; |
| 563 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 564 | static OptionEnumValueElement |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 565 | g_tri_running_mode[] = |
| 566 | { |
Greg Clayton | fe424a9 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 567 | { eOnlyThisThread, "this-thread", "Run only this thread"}, |
| 568 | { eAllThreads, "all-threads", "Run all threads"}, |
| 569 | { eOnlyDuringStepping, "while-stepping", "Run only this thread while stepping"}, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 570 | { 0, NULL, NULL } |
| 571 | }; |
| 572 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 573 | static OptionEnumValueElement |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 574 | g_duo_running_mode[] = |
| 575 | { |
Greg Clayton | fe424a9 | 2010-09-18 03:37:20 +0000 | [diff] [blame] | 576 | { eOnlyThisThread, "this-thread", "Run only this thread"}, |
| 577 | { eAllThreads, "all-threads", "Run all threads"}, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 578 | { 0, NULL, NULL } |
| 579 | }; |
| 580 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 581 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | CommandObjectThreadStepWithTypeAndScope::CommandOptions::g_option_table[] = |
| 583 | { |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 584 | { LLDB_OPT_SET_1, false, "avoid-no-debug", 'a', required_argument, NULL, 0, eArgTypeBoolean, "A boolean value that sets whether step-in will step over functions with no debug information."}, |
| 585 | { LLDB_OPT_SET_1, false, "run-mode", 'm', required_argument, g_tri_running_mode, 0, eArgTypeRunMode, "Determine how to run other threads while stepping the current thread."}, |
| 586 | { LLDB_OPT_SET_1, false, "step-over-regexp",'r', required_argument, NULL, 0, eArgTypeRegularExpression, "A regular expression that defines function names to step over."}, |
| 587 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 588 | }; |
| 589 | |
| 590 | |
| 591 | //------------------------------------------------------------------------- |
| 592 | // CommandObjectThreadContinue |
| 593 | //------------------------------------------------------------------------- |
| 594 | |
| 595 | class CommandObjectThreadContinue : public CommandObject |
| 596 | { |
| 597 | public: |
| 598 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 599 | CommandObjectThreadContinue (CommandInterpreter &interpreter) : |
| 600 | CommandObject (interpreter, |
| 601 | "thread continue", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 602 | "Continue execution of one or more threads in an active process.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 603 | NULL, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 604 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
| 605 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 606 | CommandArgumentEntry arg; |
| 607 | CommandArgumentData thread_idx_arg; |
| 608 | |
| 609 | // Define the first (and only) variant of this arg. |
| 610 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 611 | thread_idx_arg.arg_repetition = eArgRepeatPlus; |
| 612 | |
| 613 | // There is only one variant this argument could be; put it into the argument entry. |
| 614 | arg.push_back (thread_idx_arg); |
| 615 | |
| 616 | // Push the data for the first argument into the m_arguments vector. |
| 617 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | |
| 621 | virtual |
| 622 | ~CommandObjectThreadContinue () |
| 623 | { |
| 624 | } |
| 625 | |
| 626 | virtual bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 627 | Execute |
| 628 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 629 | Args& command, |
| 630 | CommandReturnObject &result |
| 631 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 632 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 633 | bool synchronous_execution = m_interpreter.GetSynchronous (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 635 | if (!m_interpreter.GetDebugger().GetSelectedTarget().get()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 636 | { |
Greg Clayton | e1f50b9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 637 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | result.SetStatus (eReturnStatusFailed); |
| 639 | return false; |
| 640 | } |
| 641 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 642 | Process *process = m_interpreter.GetExecutionContext().process; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 643 | if (process == NULL) |
| 644 | { |
| 645 | result.AppendError ("no process exists. Cannot continue"); |
| 646 | result.SetStatus (eReturnStatusFailed); |
| 647 | return false; |
| 648 | } |
| 649 | |
| 650 | StateType state = process->GetState(); |
| 651 | if ((state == eStateCrashed) || (state == eStateStopped) || (state == eStateSuspended)) |
| 652 | { |
| 653 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
| 654 | uint32_t idx; |
| 655 | const size_t argc = command.GetArgumentCount(); |
| 656 | if (argc > 0) |
| 657 | { |
| 658 | std::vector<uint32_t> resume_thread_indexes; |
| 659 | for (uint32_t i=0; i<argc; ++i) |
| 660 | { |
| 661 | idx = Args::StringToUInt32 (command.GetArgumentAtIndex(0), LLDB_INVALID_INDEX32); |
| 662 | if (idx < num_threads) |
| 663 | resume_thread_indexes.push_back(idx); |
| 664 | else |
| 665 | result.AppendWarningWithFormat("Thread index %u out of range.\n", idx); |
| 666 | } |
| 667 | |
| 668 | if (resume_thread_indexes.empty()) |
| 669 | { |
| 670 | result.AppendError ("no valid thread indexes were specified"); |
| 671 | result.SetStatus (eReturnStatusFailed); |
| 672 | return false; |
| 673 | } |
| 674 | else |
| 675 | { |
| 676 | result.AppendMessage ("Resuming thread "); |
| 677 | for (idx=0; idx<num_threads; ++idx) |
| 678 | { |
| 679 | Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get(); |
| 680 | if (find(resume_thread_indexes.begin(), resume_thread_indexes.end(), idx) != resume_thread_indexes.end()) |
| 681 | { |
| 682 | result.AppendMessageWithFormat ("%u ", idx); |
| 683 | thread->SetResumeState (eStateRunning); |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | thread->SetResumeState (eStateSuspended); |
| 688 | } |
| 689 | } |
| 690 | result.AppendMessageWithFormat ("in process %i\n", process->GetID()); |
| 691 | } |
| 692 | } |
| 693 | else |
| 694 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 695 | Thread *current_thread = process->GetThreadList().GetSelectedThread().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 696 | if (current_thread == NULL) |
| 697 | { |
| 698 | result.AppendError ("the process doesn't have a current thread"); |
| 699 | result.SetStatus (eReturnStatusFailed); |
| 700 | return false; |
| 701 | } |
| 702 | // Set the actions that the threads should each take when resuming |
| 703 | for (idx=0; idx<num_threads; ++idx) |
| 704 | { |
| 705 | Thread *thread = process->GetThreadList().GetThreadAtIndex(idx).get(); |
| 706 | if (thread == current_thread) |
| 707 | { |
| 708 | result.AppendMessageWithFormat ("Resuming thread 0x%4.4x in process %i\n", thread->GetID(), process->GetID()); |
| 709 | thread->SetResumeState (eStateRunning); |
| 710 | } |
| 711 | else |
| 712 | { |
| 713 | thread->SetResumeState (eStateSuspended); |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | Error error (process->Resume()); |
| 719 | if (error.Success()) |
| 720 | { |
Greg Clayton | c1d3775 | 2010-10-18 01:45:30 +0000 | [diff] [blame] | 721 | result.AppendMessageWithFormat ("Process %i resuming\n", process->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 722 | if (synchronous_execution) |
| 723 | { |
Greg Clayton | bef1583 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 724 | state = process->WaitForProcessToStop (NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | |
| 726 | result.SetDidChangeProcessState (true); |
| 727 | result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); |
| 728 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 729 | } |
| 730 | else |
| 731 | { |
| 732 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 733 | } |
| 734 | } |
| 735 | else |
| 736 | { |
| 737 | result.AppendErrorWithFormat("Failed to resume process: %s\n", error.AsCString()); |
| 738 | result.SetStatus (eReturnStatusFailed); |
| 739 | } |
| 740 | } |
| 741 | else |
| 742 | { |
| 743 | result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n", |
| 744 | StateAsCString(state)); |
| 745 | result.SetStatus (eReturnStatusFailed); |
| 746 | } |
| 747 | |
| 748 | return result.Succeeded(); |
| 749 | } |
| 750 | |
| 751 | }; |
| 752 | |
| 753 | //------------------------------------------------------------------------- |
| 754 | // CommandObjectThreadUntil |
| 755 | //------------------------------------------------------------------------- |
| 756 | |
| 757 | class CommandObjectThreadUntil : public CommandObject |
| 758 | { |
| 759 | public: |
| 760 | |
| 761 | class CommandOptions : public Options |
| 762 | { |
| 763 | public: |
| 764 | uint32_t m_thread_idx; |
| 765 | uint32_t m_frame_idx; |
| 766 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 767 | CommandOptions (CommandInterpreter &interpreter) : |
| 768 | Options (interpreter), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 769 | m_thread_idx(LLDB_INVALID_THREAD_ID), |
| 770 | m_frame_idx(LLDB_INVALID_FRAME_ID) |
| 771 | { |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 772 | // Keep default values of all options in one place: OptionParsingStarting () |
| 773 | OptionParsingStarting (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | virtual |
| 777 | ~CommandOptions () |
| 778 | { |
| 779 | } |
| 780 | |
| 781 | virtual Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 782 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | { |
| 784 | Error error; |
| 785 | char short_option = (char) m_getopt_table[option_idx].val; |
| 786 | |
| 787 | switch (short_option) |
| 788 | { |
| 789 | case 't': |
| 790 | { |
Greg Clayton | bef1583 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 791 | m_thread_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_INDEX32); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 792 | if (m_thread_idx == LLDB_INVALID_INDEX32) |
| 793 | { |
| 794 | error.SetErrorStringWithFormat ("Invalid thread index '%s'.\n", option_arg); |
| 795 | } |
| 796 | } |
| 797 | break; |
| 798 | case 'f': |
| 799 | { |
| 800 | m_frame_idx = Args::StringToUInt32 (option_arg, LLDB_INVALID_FRAME_ID); |
| 801 | if (m_frame_idx == LLDB_INVALID_FRAME_ID) |
| 802 | { |
| 803 | error.SetErrorStringWithFormat ("Invalid frame index '%s'.\n", option_arg); |
| 804 | } |
| 805 | } |
| 806 | break; |
| 807 | case 'm': |
| 808 | { |
| 809 | bool found_one = false; |
| 810 | OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; |
| 811 | lldb::RunMode run_mode = (lldb::RunMode) Args::StringToOptionEnum(option_arg, enum_values, eOnlyDuringStepping, &found_one); |
| 812 | |
| 813 | if (!found_one) |
| 814 | error.SetErrorStringWithFormat("Invalid enumeration value for option '%c'.\n", short_option); |
| 815 | else if (run_mode == eAllThreads) |
| 816 | m_stop_others = false; |
| 817 | else |
| 818 | m_stop_others = true; |
| 819 | |
| 820 | } |
| 821 | break; |
| 822 | default: |
| 823 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 824 | break; |
| 825 | |
| 826 | } |
| 827 | return error; |
| 828 | } |
| 829 | |
| 830 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 831 | OptionParsingStarting () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 832 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 833 | m_thread_idx = LLDB_INVALID_THREAD_ID; |
| 834 | m_frame_idx = 0; |
| 835 | m_stop_others = false; |
| 836 | } |
| 837 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 838 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 839 | GetDefinitions () |
| 840 | { |
| 841 | return g_option_table; |
| 842 | } |
| 843 | |
| 844 | uint32_t m_step_thread_idx; |
| 845 | bool m_stop_others; |
| 846 | |
| 847 | // Options table: Required for subclasses of Options. |
| 848 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 849 | static OptionDefinition g_option_table[]; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 850 | |
| 851 | // Instance variables to hold the values for command options. |
| 852 | }; |
| 853 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 854 | CommandObjectThreadUntil (CommandInterpreter &interpreter) : |
| 855 | CommandObject (interpreter, |
| 856 | "thread until", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 857 | "Run the current or specified thread until it reaches a given line number or leaves the current function.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 858 | NULL, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 859 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 860 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 861 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 862 | CommandArgumentEntry arg; |
| 863 | CommandArgumentData line_num_arg; |
| 864 | |
| 865 | // Define the first (and only) variant of this arg. |
| 866 | line_num_arg.arg_type = eArgTypeLineNum; |
| 867 | line_num_arg.arg_repetition = eArgRepeatPlain; |
| 868 | |
| 869 | // There is only one variant this argument could be; put it into the argument entry. |
| 870 | arg.push_back (line_num_arg); |
| 871 | |
| 872 | // Push the data for the first argument into the m_arguments vector. |
| 873 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | |
| 877 | virtual |
| 878 | ~CommandObjectThreadUntil () |
| 879 | { |
| 880 | } |
| 881 | |
| 882 | virtual |
| 883 | Options * |
| 884 | GetOptions () |
| 885 | { |
| 886 | return &m_options; |
| 887 | } |
| 888 | |
| 889 | virtual bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 890 | Execute |
| 891 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 892 | Args& command, |
| 893 | CommandReturnObject &result |
| 894 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 895 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 896 | bool synchronous_execution = m_interpreter.GetSynchronous (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 897 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 898 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 899 | if (target == NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 900 | { |
Greg Clayton | e1f50b9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 901 | result.AppendError ("invalid target, create a debug target using the 'target create' command"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 902 | result.SetStatus (eReturnStatusFailed); |
| 903 | return false; |
| 904 | } |
| 905 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 906 | Process *process = m_interpreter.GetExecutionContext().process; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 907 | if (process == NULL) |
| 908 | { |
| 909 | result.AppendError ("need a valid process to step"); |
| 910 | result.SetStatus (eReturnStatusFailed); |
| 911 | |
| 912 | } |
| 913 | else |
| 914 | { |
| 915 | Thread *thread = NULL; |
| 916 | uint32_t line_number; |
| 917 | |
| 918 | if (command.GetArgumentCount() != 1) |
| 919 | { |
| 920 | result.AppendErrorWithFormat ("No line number provided:\n%s", GetSyntax()); |
| 921 | result.SetStatus (eReturnStatusFailed); |
| 922 | return false; |
| 923 | } |
| 924 | |
| 925 | line_number = Args::StringToUInt32 (command.GetArgumentAtIndex(0), UINT32_MAX); |
| 926 | if (line_number == UINT32_MAX) |
| 927 | { |
| 928 | result.AppendErrorWithFormat ("Invalid line number: '%s'.\n", command.GetArgumentAtIndex(0)); |
| 929 | result.SetStatus (eReturnStatusFailed); |
| 930 | return false; |
| 931 | } |
| 932 | |
| 933 | if (m_options.m_thread_idx == LLDB_INVALID_THREAD_ID) |
| 934 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 935 | thread = process->GetThreadList().GetSelectedThread().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 936 | } |
| 937 | else |
| 938 | { |
| 939 | thread = process->GetThreadList().GetThreadAtIndex(m_options.m_thread_idx).get(); |
| 940 | } |
| 941 | |
| 942 | if (thread == NULL) |
| 943 | { |
| 944 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
Jim Ingham | b07c62a | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 945 | result.AppendErrorWithFormat ("Thread index %u is out of range (valid values are 0 - %u).\n", |
| 946 | m_options.m_thread_idx, |
| 947 | 0, |
| 948 | num_threads); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 949 | result.SetStatus (eReturnStatusFailed); |
| 950 | return false; |
| 951 | } |
| 952 | |
| 953 | const bool abort_other_plans = true; |
| 954 | |
| 955 | StackFrame *frame = thread->GetStackFrameAtIndex(m_options.m_frame_idx).get(); |
| 956 | if (frame == NULL) |
| 957 | { |
| 958 | |
Jim Ingham | b07c62a | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 959 | result.AppendErrorWithFormat ("Frame index %u is out of range for thread %u.\n", |
| 960 | m_options.m_frame_idx, |
| 961 | m_options.m_thread_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 962 | result.SetStatus (eReturnStatusFailed); |
| 963 | return false; |
| 964 | } |
| 965 | |
| 966 | ThreadPlan *new_plan; |
| 967 | |
| 968 | if (frame->HasDebugInformation ()) |
| 969 | { |
| 970 | // Finally we got here... Translate the given line number to a bunch of addresses: |
| 971 | SymbolContext sc(frame->GetSymbolContext (eSymbolContextCompUnit)); |
| 972 | LineTable *line_table = NULL; |
| 973 | if (sc.comp_unit) |
| 974 | line_table = sc.comp_unit->GetLineTable(); |
| 975 | |
| 976 | if (line_table == NULL) |
| 977 | { |
| 978 | result.AppendErrorWithFormat ("Failed to resolve the line table for frame %u of thread index %u.\n", |
| 979 | m_options.m_frame_idx, m_options.m_thread_idx); |
| 980 | result.SetStatus (eReturnStatusFailed); |
| 981 | return false; |
| 982 | } |
| 983 | |
| 984 | LineEntry function_start; |
| 985 | uint32_t index_ptr = 0, end_ptr; |
| 986 | std::vector<addr_t> address_list; |
| 987 | |
| 988 | // Find the beginning & end index of the |
| 989 | AddressRange fun_addr_range = sc.function->GetAddressRange(); |
| 990 | Address fun_start_addr = fun_addr_range.GetBaseAddress(); |
| 991 | line_table->FindLineEntryByAddress (fun_start_addr, function_start, &index_ptr); |
| 992 | |
Jim Ingham | b07c62a | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 993 | Address fun_end_addr(fun_start_addr.GetSection(), |
| 994 | fun_start_addr.GetOffset() + fun_addr_range.GetByteSize()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 995 | line_table->FindLineEntryByAddress (fun_end_addr, function_start, &end_ptr); |
| 996 | |
Jim Ingham | b07c62a | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 997 | bool all_in_function = true; |
| 998 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 999 | while (index_ptr <= end_ptr) |
| 1000 | { |
| 1001 | LineEntry line_entry; |
| 1002 | index_ptr = sc.comp_unit->FindLineEntry(index_ptr, line_number, sc.comp_unit, &line_entry); |
| 1003 | if (index_ptr == UINT32_MAX) |
| 1004 | break; |
| 1005 | |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 1006 | addr_t address = line_entry.range.GetBaseAddress().GetLoadAddress(target); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1007 | if (address != LLDB_INVALID_ADDRESS) |
Jim Ingham | b07c62a | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1008 | { |
| 1009 | if (fun_addr_range.ContainsLoadAddress (address, target)) |
| 1010 | address_list.push_back (address); |
| 1011 | else |
| 1012 | all_in_function = false; |
| 1013 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1014 | index_ptr++; |
| 1015 | } |
| 1016 | |
Jim Ingham | b07c62a | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1017 | if (address_list.size() == 0) |
| 1018 | { |
| 1019 | if (all_in_function) |
| 1020 | result.AppendErrorWithFormat ("No line entries matching until target.\n"); |
| 1021 | else |
| 1022 | result.AppendErrorWithFormat ("Until target outside of the current function.\n"); |
| 1023 | |
| 1024 | result.SetStatus (eReturnStatusFailed); |
| 1025 | return false; |
| 1026 | } |
| 1027 | |
| 1028 | new_plan = thread->QueueThreadPlanForStepUntil (abort_other_plans, |
| 1029 | &address_list.front(), |
| 1030 | address_list.size(), |
| 1031 | m_options.m_stop_others, |
| 1032 | thread->GetSelectedFrameIndex ()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1033 | new_plan->SetOkayToDiscard(false); |
| 1034 | } |
| 1035 | else |
| 1036 | { |
Jim Ingham | b07c62a | 2011-05-08 00:56:32 +0000 | [diff] [blame] | 1037 | result.AppendErrorWithFormat ("Frame index %u of thread %u has no debug information.\n", |
| 1038 | m_options.m_frame_idx, |
| 1039 | m_options.m_thread_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1040 | result.SetStatus (eReturnStatusFailed); |
| 1041 | return false; |
| 1042 | |
| 1043 | } |
| 1044 | |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 1045 | process->GetThreadList().SetSelectedThreadByID (m_options.m_thread_idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1046 | Error error (process->Resume ()); |
| 1047 | if (error.Success()) |
| 1048 | { |
Greg Clayton | c1d3775 | 2010-10-18 01:45:30 +0000 | [diff] [blame] | 1049 | result.AppendMessageWithFormat ("Process %i resuming\n", process->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1050 | if (synchronous_execution) |
| 1051 | { |
| 1052 | StateType state = process->WaitForProcessToStop (NULL); |
| 1053 | |
| 1054 | result.SetDidChangeProcessState (true); |
| 1055 | result.AppendMessageWithFormat ("Process %i %s\n", process->GetID(), StateAsCString (state)); |
| 1056 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1057 | } |
| 1058 | else |
| 1059 | { |
| 1060 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 1061 | } |
| 1062 | } |
| 1063 | else |
| 1064 | { |
| 1065 | result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString()); |
| 1066 | result.SetStatus (eReturnStatusFailed); |
| 1067 | } |
| 1068 | |
| 1069 | } |
| 1070 | return result.Succeeded(); |
| 1071 | } |
| 1072 | protected: |
| 1073 | CommandOptions m_options; |
| 1074 | |
| 1075 | }; |
| 1076 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1077 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1078 | CommandObjectThreadUntil::CommandOptions::g_option_table[] = |
| 1079 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1080 | { LLDB_OPT_SET_1, false, "frame", 'f', required_argument, NULL, 0, eArgTypeFrameIndex, "Frame index for until operation - defaults to 0"}, |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 1081 | { LLDB_OPT_SET_1, false, "thread", 't', required_argument, NULL, 0, eArgTypeThreadIndex, "Thread index for the thread for until operation"}, |
| 1082 | { LLDB_OPT_SET_1, false, "run-mode",'m', required_argument, g_duo_running_mode, 0, eArgTypeRunMode,"Determine how to run other threads while stepping this one"}, |
| 1083 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1084 | }; |
| 1085 | |
| 1086 | |
| 1087 | //------------------------------------------------------------------------- |
| 1088 | // CommandObjectThreadSelect |
| 1089 | //------------------------------------------------------------------------- |
| 1090 | |
| 1091 | class CommandObjectThreadSelect : public CommandObject |
| 1092 | { |
| 1093 | public: |
| 1094 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1095 | CommandObjectThreadSelect (CommandInterpreter &interpreter) : |
| 1096 | CommandObject (interpreter, |
| 1097 | "thread select", |
| 1098 | "Select a thread as the currently active thread.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1099 | NULL, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1100 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1101 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1102 | CommandArgumentEntry arg; |
| 1103 | CommandArgumentData thread_idx_arg; |
| 1104 | |
| 1105 | // Define the first (and only) variant of this arg. |
| 1106 | thread_idx_arg.arg_type = eArgTypeThreadIndex; |
| 1107 | thread_idx_arg.arg_repetition = eArgRepeatPlain; |
| 1108 | |
| 1109 | // There is only one variant this argument could be; put it into the argument entry. |
| 1110 | arg.push_back (thread_idx_arg); |
| 1111 | |
| 1112 | // Push the data for the first argument into the m_arguments vector. |
| 1113 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | |
| 1117 | virtual |
| 1118 | ~CommandObjectThreadSelect () |
| 1119 | { |
| 1120 | } |
| 1121 | |
| 1122 | virtual bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1123 | Execute |
| 1124 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1125 | Args& command, |
| 1126 | CommandReturnObject &result |
| 1127 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1128 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1129 | Process *process = m_interpreter.GetExecutionContext().process; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1130 | if (process == NULL) |
| 1131 | { |
| 1132 | result.AppendError ("no process"); |
| 1133 | result.SetStatus (eReturnStatusFailed); |
| 1134 | return false; |
| 1135 | } |
| 1136 | else if (command.GetArgumentCount() != 1) |
| 1137 | { |
| 1138 | result.AppendErrorWithFormat("'%s' takes exactly one thread index argument:\nUsage: \n", m_cmd_name.c_str(), m_cmd_syntax.c_str()); |
| 1139 | result.SetStatus (eReturnStatusFailed); |
| 1140 | return false; |
| 1141 | } |
| 1142 | |
| 1143 | uint32_t index_id = Args::StringToUInt32(command.GetArgumentAtIndex(0), 0, 0); |
| 1144 | |
| 1145 | Thread *new_thread = process->GetThreadList().FindThreadByIndexID(index_id).get(); |
| 1146 | if (new_thread == NULL) |
| 1147 | { |
| 1148 | result.AppendErrorWithFormat ("Invalid thread #%s.\n", command.GetArgumentAtIndex(0)); |
| 1149 | result.SetStatus (eReturnStatusFailed); |
| 1150 | return false; |
| 1151 | } |
| 1152 | |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 1153 | process->GetThreadList().SetSelectedThreadByID(new_thread->GetID()); |
Johnny Chen | 8dbb6e8 | 2010-09-14 00:53:53 +0000 | [diff] [blame] | 1154 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1155 | |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1156 | const uint32_t start_frame = 0; |
| 1157 | const uint32_t num_frames = 1; |
| 1158 | const uint32_t num_frames_with_source = 1; |
| 1159 | new_thread->GetStatus (result.GetOutputStream(), |
| 1160 | start_frame, |
| 1161 | num_frames, |
| 1162 | num_frames_with_source); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1163 | |
| 1164 | return result.Succeeded(); |
| 1165 | } |
| 1166 | |
| 1167 | }; |
| 1168 | |
| 1169 | |
| 1170 | //------------------------------------------------------------------------- |
| 1171 | // CommandObjectThreadList |
| 1172 | //------------------------------------------------------------------------- |
| 1173 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1174 | class CommandObjectThreadList : public CommandObject |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1175 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1176 | public: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1177 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1178 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1179 | CommandObjectThreadList (CommandInterpreter &interpreter): |
| 1180 | CommandObject (interpreter, |
| 1181 | "thread list", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 1182 | "Show a summary of all current threads in a process.", |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1183 | "thread list", |
| 1184 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1185 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1186 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1187 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1188 | ~CommandObjectThreadList() |
| 1189 | { |
| 1190 | } |
| 1191 | |
| 1192 | bool |
| 1193 | Execute |
| 1194 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1195 | Args& command, |
| 1196 | CommandReturnObject &result |
| 1197 | ) |
| 1198 | { |
Jim Ingham | 2e8cb8a | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 1199 | Stream &strm = result.GetOutputStream(); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1200 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1201 | ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1202 | if (exe_ctx.process) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1203 | { |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1204 | const bool only_threads_with_stop_reason = false; |
| 1205 | const uint32_t start_frame = 0; |
| 1206 | const uint32_t num_frames = 0; |
| 1207 | const uint32_t num_frames_with_source = 0; |
| 1208 | exe_ctx.process->GetStatus(strm); |
| 1209 | exe_ctx.process->GetThreadStatus (strm, |
| 1210 | only_threads_with_stop_reason, |
| 1211 | start_frame, |
| 1212 | num_frames, |
| 1213 | num_frames_with_source); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1214 | } |
| 1215 | else |
| 1216 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1217 | result.AppendError ("no current location or status available"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1218 | result.SetStatus (eReturnStatusFailed); |
| 1219 | } |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1220 | return result.Succeeded(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1221 | } |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1222 | }; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1223 | |
| 1224 | //------------------------------------------------------------------------- |
| 1225 | // CommandObjectMultiwordThread |
| 1226 | //------------------------------------------------------------------------- |
| 1227 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1228 | CommandObjectMultiwordThread::CommandObjectMultiwordThread (CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1229 | CommandObjectMultiword (interpreter, |
| 1230 | "thread", |
Caroline Tice | c1ad82e | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 1231 | "A set of commands for operating on one or more threads within a running process.", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1232 | "thread <subcommand> [<subcommand-options>]") |
| 1233 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1234 | LoadSubCommand ("backtrace", CommandObjectSP (new CommandObjectThreadBacktrace (interpreter))); |
| 1235 | LoadSubCommand ("continue", CommandObjectSP (new CommandObjectThreadContinue (interpreter))); |
| 1236 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectThreadList (interpreter))); |
| 1237 | LoadSubCommand ("select", CommandObjectSP (new CommandObjectThreadSelect (interpreter))); |
| 1238 | LoadSubCommand ("until", CommandObjectSP (new CommandObjectThreadUntil (interpreter))); |
| 1239 | LoadSubCommand ("step-in", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1240 | interpreter, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1241 | "thread step-in", |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1242 | "Source level single step in specified thread (current thread, if none specified).", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1243 | NULL, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1244 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused, |
| 1245 | eStepTypeInto, |
| 1246 | eStepScopeSource))); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1247 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1248 | LoadSubCommand ("step-out", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1249 | interpreter, |
| 1250 | "thread step-out", |
Peter Collingbourne | 82ce540 | 2011-06-14 03:55:29 +0000 | [diff] [blame] | 1251 | "Finish executing the current function and return to its call site in specified thread (current thread, if none specified).", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1252 | NULL, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1253 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused, |
| 1254 | eStepTypeOut, |
| 1255 | eStepScopeSource))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1256 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1257 | LoadSubCommand ("step-over", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1258 | interpreter, |
| 1259 | "thread step-over", |
| 1260 | "Source level single step in specified thread (current thread, if none specified), stepping over calls.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1261 | NULL, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1262 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused, |
| 1263 | eStepTypeOver, |
| 1264 | eStepScopeSource))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1265 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1266 | LoadSubCommand ("step-inst", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1267 | interpreter, |
| 1268 | "thread step-inst", |
| 1269 | "Single step one instruction in specified thread (current thread, if none specified).", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1270 | NULL, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1271 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused, |
| 1272 | eStepTypeTrace, |
| 1273 | eStepScopeInstruction))); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1274 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1275 | LoadSubCommand ("step-inst-over", CommandObjectSP (new CommandObjectThreadStepWithTypeAndScope ( |
| 1276 | interpreter, |
| 1277 | "thread step-inst-over", |
| 1278 | "Single step one instruction in specified thread (current thread, if none specified), stepping over calls.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1279 | NULL, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1280 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused, |
| 1281 | eStepTypeTraceOver, |
| 1282 | eStepScopeInstruction))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | CommandObjectMultiwordThread::~CommandObjectMultiwordThread () |
| 1286 | { |
| 1287 | } |
| 1288 | |
| 1289 | |