Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectProcess.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 "CommandObjectProcess.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Jim Ingham | 124e690 | 2012-08-11 01:27:55 +0000 | [diff] [blame] | 16 | #include "lldb/Breakpoint/Breakpoint.h" |
| 17 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 18 | #include "lldb/Breakpoint/BreakpointSite.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/State.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Module.h" |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 21 | #include "lldb/Host/Host.h" |
Jim Ingham | 124e690 | 2012-08-11 01:27:55 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/Args.h" |
| 23 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 25 | #include "lldb/Interpreter/CommandReturnObject.h" |
Greg Clayton | e4b9c1f | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Platform.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "lldb/Target/Process.h" |
Jim Ingham | 124e690 | 2012-08-11 01:27:55 +0000 | [diff] [blame] | 28 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Target.h" |
| 30 | #include "lldb/Target/Thread.h" |
| 31 | |
| 32 | using namespace lldb; |
| 33 | using namespace lldb_private; |
| 34 | |
| 35 | //------------------------------------------------------------------------- |
| 36 | // CommandObjectProcessLaunch |
| 37 | //------------------------------------------------------------------------- |
Jim Ingham | 5a15e69 | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 38 | #pragma mark CommandObjectProcessLaunch |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 39 | class CommandObjectProcessLaunch : public CommandObjectParsed |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | { |
| 41 | public: |
| 42 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 43 | CommandObjectProcessLaunch (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 44 | CommandObjectParsed (interpreter, |
| 45 | "process launch", |
| 46 | "Launch the executable in the debugger.", |
| 47 | NULL), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 48 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 50 | CommandArgumentEntry arg; |
| 51 | CommandArgumentData run_args_arg; |
| 52 | |
| 53 | // Define the first (and only) variant of this arg. |
| 54 | run_args_arg.arg_type = eArgTypeRunArgs; |
| 55 | run_args_arg.arg_repetition = eArgRepeatOptional; |
| 56 | |
| 57 | // There is only one variant this argument could be; put it into the argument entry. |
| 58 | arg.push_back (run_args_arg); |
| 59 | |
| 60 | // Push the data for the first argument into the m_arguments vector. |
| 61 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | |
| 65 | ~CommandObjectProcessLaunch () |
| 66 | { |
| 67 | } |
| 68 | |
Jim Ingham | 392d9e0 | 2012-08-10 21:48:41 +0000 | [diff] [blame] | 69 | int |
| 70 | HandleArgumentCompletion (Args &input, |
| 71 | int &cursor_index, |
| 72 | int &cursor_char_position, |
| 73 | OptionElementVector &opt_element_vector, |
| 74 | int match_start_point, |
| 75 | int max_return_elements, |
| 76 | bool &word_complete, |
| 77 | StringList &matches) |
| 78 | { |
| 79 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 80 | completion_str.erase (cursor_char_position); |
| 81 | |
| 82 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
| 83 | CommandCompletions::eDiskFileCompletion, |
| 84 | completion_str.c_str(), |
| 85 | match_start_point, |
| 86 | max_return_elements, |
| 87 | NULL, |
| 88 | word_complete, |
| 89 | matches); |
| 90 | return matches.GetSize(); |
| 91 | } |
| 92 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | Options * |
| 94 | GetOptions () |
| 95 | { |
| 96 | return &m_options; |
| 97 | } |
| 98 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 99 | virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index) |
| 100 | { |
| 101 | // No repeat for "process launch"... |
| 102 | return ""; |
| 103 | } |
| 104 | |
| 105 | protected: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 107 | DoExecute (Args& launch_args, CommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | { |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 109 | Debugger &debugger = m_interpreter.GetDebugger(); |
| 110 | Target *target = debugger.GetSelectedTarget().get(); |
| 111 | Error error; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | |
| 113 | if (target == NULL) |
| 114 | { |
Greg Clayton | e1f50b9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 115 | 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] | 116 | result.SetStatus (eReturnStatusFailed); |
| 117 | return false; |
| 118 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | // If our listener is NULL, users aren't allows to launch |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 120 | char filename[PATH_MAX]; |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 121 | const Module *exe_module = target->GetExecutableModulePointer(); |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 122 | |
| 123 | if (exe_module == NULL) |
| 124 | { |
Greg Clayton | e1f50b9 | 2011-05-03 22:09:39 +0000 | [diff] [blame] | 125 | result.AppendError ("no file in target, create a debug target using the 'target create' command"); |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 126 | result.SetStatus (eReturnStatusFailed); |
| 127 | return false; |
| 128 | } |
| 129 | |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 130 | exe_module->GetFileSpec().GetPath (filename, sizeof(filename)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 131 | |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 132 | const bool add_exe_file_as_first_arg = true; |
Greg Clayton | 1d1f39e | 2011-11-29 04:03:30 +0000 | [diff] [blame] | 133 | m_options.launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), add_exe_file_as_first_arg); |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 134 | |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 135 | StateType state = eStateInvalid; |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 136 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 137 | if (process) |
| 138 | { |
| 139 | state = process->GetState(); |
| 140 | |
| 141 | if (process->IsAlive() && state != eStateConnected) |
| 142 | { |
| 143 | char message[1024]; |
| 144 | if (process->GetState() == eStateAttaching) |
| 145 | ::strncpy (message, "There is a pending attach, abort it and launch a new process?", sizeof(message)); |
| 146 | else |
| 147 | ::strncpy (message, "There is a running process, kill it and restart?", sizeof(message)); |
| 148 | |
| 149 | if (!m_interpreter.Confirm (message, true)) |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 150 | { |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 151 | result.SetStatus (eReturnStatusFailed); |
| 152 | return false; |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 153 | } |
| 154 | else |
| 155 | { |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 156 | Error destroy_error (process->Destroy()); |
| 157 | if (destroy_error.Success()) |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 158 | { |
| 159 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 160 | } |
| 161 | else |
| 162 | { |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 163 | result.AppendErrorWithFormat ("Failed to kill process: %s\n", destroy_error.AsCString()); |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 164 | result.SetStatus (eReturnStatusFailed); |
| 165 | } |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 166 | } |
| 167 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 168 | } |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 169 | |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 170 | if (launch_args.GetArgumentCount() == 0) |
| 171 | { |
Greg Clayton | 73844aa | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 172 | Args target_setting_args; |
| 173 | if (target->GetRunArguments(target_setting_args) > 0) |
| 174 | m_options.launch_info.GetArguments().AppendArguments (target_setting_args); |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 175 | } |
| 176 | else |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 177 | { |
Greg Clayton | 3e6f2cc | 2011-11-21 21:51:18 +0000 | [diff] [blame] | 178 | // Save the arguments for subsequent runs in the current target. |
| 179 | target->SetRunArguments (launch_args); |
| 180 | |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 181 | m_options.launch_info.GetArguments().AppendArguments (launch_args); |
| 182 | } |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 183 | |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 184 | if (target->GetDisableASLR()) |
| 185 | m_options.launch_info.GetFlags().Set (eLaunchFlagDisableASLR); |
| 186 | |
| 187 | if (target->GetDisableSTDIO()) |
| 188 | m_options.launch_info.GetFlags().Set (eLaunchFlagDisableSTDIO); |
| 189 | |
| 190 | m_options.launch_info.GetFlags().Set (eLaunchFlagDebug); |
| 191 | |
| 192 | Args environment; |
| 193 | target->GetEnvironmentAsArgs (environment); |
| 194 | if (environment.GetArgumentCount() > 0) |
| 195 | m_options.launch_info.GetEnvironmentEntries ().AppendArguments (environment); |
| 196 | |
Greg Clayton | 464c616 | 2011-11-17 22:14:31 +0000 | [diff] [blame] | 197 | // Finalize the file actions, and if none were given, default to opening |
| 198 | // up a pseudo terminal |
| 199 | const bool default_to_use_pty = true; |
| 200 | m_options.launch_info.FinalizeFileActions (target, default_to_use_pty); |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 201 | |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 202 | if (state == eStateConnected) |
| 203 | { |
| 204 | if (m_options.launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY)) |
| 205 | { |
| 206 | result.AppendWarning("can't launch in tty when launching through a remote connection"); |
| 207 | m_options.launch_info.GetFlags().Clear (eLaunchFlagLaunchInTTY); |
| 208 | } |
| 209 | } |
| 210 | else |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 211 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 212 | if (!m_options.launch_info.GetArchitecture().IsValid()) |
Greg Clayton | 2d9adb7 | 2011-11-12 02:10:56 +0000 | [diff] [blame] | 213 | m_options.launch_info.GetArchitecture() = target->GetArchitecture(); |
| 214 | |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 215 | PlatformSP platform_sp (target->GetPlatform()); |
| 216 | |
| 217 | if (platform_sp && platform_sp->CanDebugProcess ()) |
| 218 | { |
| 219 | process = target->GetPlatform()->DebugProcess (m_options.launch_info, |
| 220 | debugger, |
| 221 | target, |
| 222 | debugger.GetListener(), |
| 223 | error).get(); |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | const char *plugin_name = m_options.launch_info.GetProcessPluginName(); |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 228 | process = target->CreateProcess (debugger.GetListener(), plugin_name, NULL).get(); |
Greg Clayton | 75d8c25 | 2011-11-28 01:45:00 +0000 | [diff] [blame] | 229 | if (process) |
| 230 | error = process->Launch (m_options.launch_info); |
| 231 | } |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 232 | |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 233 | if (process == NULL) |
| 234 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 235 | result.SetError (error, "failed to launch or debug process"); |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 236 | return false; |
| 237 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | } |
Greg Clayton | abb3302 | 2011-11-08 02:43:13 +0000 | [diff] [blame] | 239 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 240 | if (error.Success()) |
| 241 | { |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 242 | const char *archname = exe_module->GetArchitecture().GetArchitectureName(); |
Greg Clayton | c1d3775 | 2010-10-18 01:45:30 +0000 | [diff] [blame] | 243 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 244 | result.AppendMessageWithFormat ("Process %llu launched: '%s' (%s)\n", process->GetID(), filename, archname); |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 245 | result.SetDidChangeProcessState (true); |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 246 | if (m_options.launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false) |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 247 | { |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 248 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 249 | StateType state = process->WaitForProcessToStop (NULL); |
| 250 | |
| 251 | if (state == eStateStopped) |
| 252 | { |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 253 | error = process->Resume(); |
| 254 | if (error.Success()) |
| 255 | { |
| 256 | bool synchronous_execution = m_interpreter.GetSynchronous (); |
| 257 | if (synchronous_execution) |
| 258 | { |
| 259 | state = process->WaitForProcessToStop (NULL); |
Greg Clayton | 2020608 | 2011-11-17 01:23:07 +0000 | [diff] [blame] | 260 | const bool must_be_alive = true; |
| 261 | if (!StateIsStoppedState(state, must_be_alive)) |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 262 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 263 | result.AppendErrorWithFormat ("process isn't stopped: %s", StateAsCString(state)); |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 264 | } |
Greg Clayton | d8c6253 | 2010-10-07 04:19:01 +0000 | [diff] [blame] | 265 | result.SetDidChangeProcessState (true); |
| 266 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 267 | } |
| 268 | else |
| 269 | { |
| 270 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 271 | } |
| 272 | } |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 273 | else |
| 274 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 275 | result.AppendErrorWithFormat ("process resume at entry point failed: %s", error.AsCString()); |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 276 | result.SetStatus (eReturnStatusFailed); |
| 277 | } |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 278 | } |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 279 | else |
| 280 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 281 | result.AppendErrorWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state)); |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 282 | result.SetStatus (eReturnStatusFailed); |
| 283 | } |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 284 | } |
| 285 | } |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 286 | else |
| 287 | { |
Greg Clayton | a9eb827 | 2011-07-02 21:07:54 +0000 | [diff] [blame] | 288 | result.AppendErrorWithFormat ("process launch failed: %s", error.AsCString()); |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 289 | result.SetStatus (eReturnStatusFailed); |
| 290 | } |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 291 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | return result.Succeeded(); |
| 293 | } |
| 294 | |
| 295 | protected: |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 296 | ProcessLaunchCommandOptions m_options; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | |
Greg Clayton | 36bc5ea | 2011-11-03 21:22:33 +0000 | [diff] [blame] | 300 | //#define SET1 LLDB_OPT_SET_1 |
| 301 | //#define SET2 LLDB_OPT_SET_2 |
| 302 | //#define SET3 LLDB_OPT_SET_3 |
| 303 | // |
| 304 | //OptionDefinition |
| 305 | //CommandObjectProcessLaunch::CommandOptions::g_option_table[] = |
| 306 | //{ |
| 307 | //{ SET1 | SET2 | SET3, false, "stop-at-entry", 's', no_argument, NULL, 0, eArgTypeNone, "Stop at the entry point of the program when launching a process."}, |
| 308 | //{ SET1 , false, "stdin", 'i', required_argument, NULL, 0, eArgTypePath, "Redirect stdin for the process to <path>."}, |
| 309 | //{ SET1 , false, "stdout", 'o', required_argument, NULL, 0, eArgTypePath, "Redirect stdout for the process to <path>."}, |
| 310 | //{ SET1 , false, "stderr", 'e', required_argument, NULL, 0, eArgTypePath, "Redirect stderr for the process to <path>."}, |
| 311 | //{ SET1 | SET2 | SET3, false, "plugin", 'p', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, |
| 312 | //{ SET2 , false, "tty", 't', optional_argument, NULL, 0, eArgTypePath, "Start the process in a terminal. If <path> is specified, look for a terminal whose name contains <path>, else start the process in a new terminal."}, |
| 313 | //{ SET3, false, "no-stdio", 'n', no_argument, NULL, 0, eArgTypeNone, "Do not set up for terminal I/O to go to running process."}, |
| 314 | //{ SET1 | SET2 | SET3, false, "working-dir", 'w', required_argument, NULL, 0, eArgTypePath, "Set the current working directory to <path> when running the inferior."}, |
| 315 | //{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 316 | //}; |
| 317 | // |
| 318 | //#undef SET1 |
| 319 | //#undef SET2 |
| 320 | //#undef SET3 |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 321 | |
| 322 | //------------------------------------------------------------------------- |
| 323 | // CommandObjectProcessAttach |
| 324 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 325 | #pragma mark CommandObjectProcessAttach |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 326 | class CommandObjectProcessAttach : public CommandObjectParsed |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 327 | { |
| 328 | public: |
| 329 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 330 | class CommandOptions : public Options |
| 331 | { |
| 332 | public: |
| 333 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 334 | CommandOptions (CommandInterpreter &interpreter) : |
| 335 | Options(interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 336 | { |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 337 | // Keep default values of all options in one place: OptionParsingStarting () |
| 338 | OptionParsingStarting (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | ~CommandOptions () |
| 342 | { |
| 343 | } |
| 344 | |
| 345 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 346 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 347 | { |
| 348 | Error error; |
| 349 | char short_option = (char) m_getopt_table[option_idx].val; |
| 350 | bool success = false; |
| 351 | switch (short_option) |
| 352 | { |
Johnny Chen | 7c09997 | 2012-05-24 00:43:00 +0000 | [diff] [blame] | 353 | case 'c': |
| 354 | attach_info.SetContinueOnceAttached(true); |
| 355 | break; |
| 356 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 357 | case 'p': |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 359 | lldb::pid_t pid = Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success); |
| 360 | if (!success || pid == LLDB_INVALID_PROCESS_ID) |
| 361 | { |
| 362 | error.SetErrorStringWithFormat("invalid process ID '%s'", option_arg); |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | attach_info.SetProcessID (pid); |
| 367 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 368 | } |
| 369 | break; |
| 370 | |
| 371 | case 'P': |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 372 | attach_info.SetProcessPluginName (option_arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | break; |
| 374 | |
| 375 | case 'n': |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 376 | attach_info.GetExecutableFile().SetFile(option_arg, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 377 | break; |
| 378 | |
| 379 | case 'w': |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 380 | attach_info.SetWaitForLaunch(true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 381 | break; |
Jim Ingham | 3a458eb | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 382 | |
| 383 | case 'i': |
| 384 | attach_info.SetIgnoreExisting(false); |
| 385 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 386 | |
| 387 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 388 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 389 | break; |
| 390 | } |
| 391 | return error; |
| 392 | } |
| 393 | |
| 394 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 395 | OptionParsingStarting () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 396 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 397 | attach_info.Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 400 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 401 | GetDefinitions () |
| 402 | { |
| 403 | return g_option_table; |
| 404 | } |
| 405 | |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 406 | virtual bool |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 407 | HandleOptionArgumentCompletion (Args &input, |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 408 | int cursor_index, |
| 409 | int char_pos, |
| 410 | OptionElementVector &opt_element_vector, |
| 411 | int opt_element_index, |
| 412 | int match_start_point, |
| 413 | int max_return_elements, |
| 414 | bool &word_complete, |
| 415 | StringList &matches) |
| 416 | { |
| 417 | int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos; |
| 418 | int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index; |
| 419 | |
| 420 | // We are only completing the name option for now... |
| 421 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 422 | const OptionDefinition *opt_defs = GetDefinitions(); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 423 | if (opt_defs[opt_defs_index].short_option == 'n') |
| 424 | { |
| 425 | // Are we in the name? |
| 426 | |
| 427 | // Look to see if there is a -P argument provided, and if so use that plugin, otherwise |
| 428 | // use the default plugin. |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 429 | |
| 430 | const char *partial_name = NULL; |
| 431 | partial_name = input.GetArgumentAtIndex(opt_arg_pos); |
Greg Clayton | e4b9c1f | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 432 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 433 | PlatformSP platform_sp (m_interpreter.GetPlatform (true)); |
Greg Clayton | e4b9c1f | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 434 | if (platform_sp) |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 435 | { |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 436 | ProcessInstanceInfoList process_infos; |
| 437 | ProcessInstanceInfoMatch match_info; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 438 | if (partial_name) |
| 439 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 440 | match_info.GetProcessInfo().GetExecutableFile().SetFile(partial_name, false); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 441 | match_info.SetNameMatchType(eNameMatchStartsWith); |
| 442 | } |
| 443 | platform_sp->FindProcesses (match_info, process_infos); |
Greg Clayton | e4b9c1f | 2011-03-08 22:40:15 +0000 | [diff] [blame] | 444 | const uint32_t num_matches = process_infos.GetSize(); |
| 445 | if (num_matches > 0) |
| 446 | { |
| 447 | for (uint32_t i=0; i<num_matches; ++i) |
| 448 | { |
| 449 | matches.AppendString (process_infos.GetProcessNameAtIndex(i), |
| 450 | process_infos.GetProcessNameLengthAtIndex(i)); |
| 451 | } |
| 452 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | return false; |
| 457 | } |
| 458 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 459 | // Options table: Required for subclasses of Options. |
| 460 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 461 | static OptionDefinition g_option_table[]; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 462 | |
| 463 | // Instance variables to hold the values for command options. |
| 464 | |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 465 | ProcessAttachInfo attach_info; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 466 | }; |
| 467 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 468 | CommandObjectProcessAttach (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 469 | CommandObjectParsed (interpreter, |
| 470 | "process attach", |
| 471 | "Attach to a process.", |
| 472 | "process attach <cmd-options>"), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 473 | m_options (interpreter) |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 474 | { |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | ~CommandObjectProcessAttach () |
| 478 | { |
| 479 | } |
| 480 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 481 | Options * |
| 482 | GetOptions () |
| 483 | { |
| 484 | return &m_options; |
| 485 | } |
| 486 | |
| 487 | protected: |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 488 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 489 | DoExecute (Args& command, |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 490 | CommandReturnObject &result) |
| 491 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 492 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Jim Ingham | ee940e2 | 2011-09-15 01:08:57 +0000 | [diff] [blame] | 493 | // N.B. The attach should be synchronous. It doesn't help much to get the prompt back between initiating the attach |
| 494 | // and the target actually stopping. So even if the interpreter is set to be asynchronous, we wait for the stop |
| 495 | // ourselves here. |
Jim Ingham | c2dc7c8 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 496 | |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 497 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 498 | StateType state = eStateInvalid; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 499 | if (process) |
| 500 | { |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 501 | state = process->GetState(); |
| 502 | if (process->IsAlive() && state != eStateConnected) |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 503 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 504 | result.AppendErrorWithFormat ("Process %llu is currently being debugged, kill the process before attaching.\n", |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 505 | process->GetID()); |
| 506 | result.SetStatus (eReturnStatusFailed); |
| 507 | return false; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | if (target == NULL) |
| 512 | { |
| 513 | // If there isn't a current target create one. |
| 514 | TargetSP new_target_sp; |
| 515 | FileSpec emptyFileSpec; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 516 | Error error; |
| 517 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 518 | error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(), |
| 519 | emptyFileSpec, |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 520 | NULL, |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 521 | false, |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 522 | NULL, // No platform options |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 523 | new_target_sp); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 524 | target = new_target_sp.get(); |
| 525 | if (target == NULL || error.Fail()) |
| 526 | { |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 527 | result.AppendError(error.AsCString("Error creating target")); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 528 | return false; |
| 529 | } |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 530 | m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | // Record the old executable module, we want to issue a warning if the process of attaching changed the |
| 534 | // current executable (like somebody said "file foo" then attached to a PID whose executable was bar.) |
| 535 | |
| 536 | ModuleSP old_exec_module_sp = target->GetExecutableModule(); |
| 537 | ArchSpec old_arch_spec = target->GetArchitecture(); |
| 538 | |
| 539 | if (command.GetArgumentCount()) |
| 540 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 541 | result.AppendErrorWithFormat("Invalid arguments for '%s'.\nUsage: %s\n", m_cmd_name.c_str(), m_cmd_syntax.c_str()); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 542 | result.SetStatus (eReturnStatusFailed); |
| 543 | } |
| 544 | else |
| 545 | { |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 546 | if (state != eStateConnected) |
| 547 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 548 | const char *plugin_name = m_options.attach_info.GetProcessPluginName(); |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 549 | process = target->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name, NULL).get(); |
Greg Clayton | a2f7423 | 2011-02-24 22:24:29 +0000 | [diff] [blame] | 550 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 551 | |
| 552 | if (process) |
| 553 | { |
| 554 | Error error; |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 555 | // If no process info was specified, then use the target executable |
| 556 | // name as the process to attach to by default |
| 557 | if (!m_options.attach_info.ProcessInfoSpecified ()) |
Jim Ingham | 4805a1c | 2010-09-15 01:34:14 +0000 | [diff] [blame] | 558 | { |
| 559 | if (old_exec_module_sp) |
Greg Clayton | 1d1f39e | 2011-11-29 04:03:30 +0000 | [diff] [blame] | 560 | m_options.attach_info.GetExecutableFile().GetFilename() = old_exec_module_sp->GetPlatformFileSpec().GetFilename(); |
Jim Ingham | 4805a1c | 2010-09-15 01:34:14 +0000 | [diff] [blame] | 561 | |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 562 | if (!m_options.attach_info.ProcessInfoSpecified ()) |
| 563 | { |
| 564 | error.SetErrorString ("no process specified, create a target with a file, or specify the --pid or --name command option"); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | if (error.Success()) |
| 569 | { |
| 570 | error = process->Attach (m_options.attach_info); |
| 571 | |
Jim Ingham | 4805a1c | 2010-09-15 01:34:14 +0000 | [diff] [blame] | 572 | if (error.Success()) |
| 573 | { |
| 574 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 575 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 576 | else |
| 577 | { |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 578 | result.AppendErrorWithFormat ("attach failed: %s\n", error.AsCString()); |
Jim Ingham | 4805a1c | 2010-09-15 01:34:14 +0000 | [diff] [blame] | 579 | result.SetStatus (eReturnStatusFailed); |
| 580 | return false; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 581 | } |
Jim Ingham | c2dc7c8 | 2011-01-29 01:49:25 +0000 | [diff] [blame] | 582 | // If we're synchronous, wait for the stopped event and report that. |
| 583 | // Otherwise just return. |
| 584 | // FIXME: in the async case it will now be possible to get to the command |
| 585 | // interpreter with a state eStateAttaching. Make sure we handle that correctly. |
Jim Ingham | ee940e2 | 2011-09-15 01:08:57 +0000 | [diff] [blame] | 586 | StateType state = process->WaitForProcessToStop (NULL); |
Greg Clayton | 527154d | 2011-11-15 03:53:30 +0000 | [diff] [blame] | 587 | |
Jim Ingham | ee940e2 | 2011-09-15 01:08:57 +0000 | [diff] [blame] | 588 | result.SetDidChangeProcessState (true); |
Johnny Chen | 9986a3b | 2012-05-18 00:51:36 +0000 | [diff] [blame] | 589 | |
| 590 | if (state == eStateStopped) |
| 591 | { |
| 592 | result.AppendMessageWithFormat ("Process %llu %s\n", process->GetID(), StateAsCString (state)); |
| 593 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 594 | } |
| 595 | else |
| 596 | { |
| 597 | result.AppendError ("attach failed: process did not stop (no such process or permission problem?)"); |
Jim Ingham | 5d90ade | 2012-07-27 23:57:19 +0000 | [diff] [blame] | 598 | process->Destroy(); |
Johnny Chen | 9986a3b | 2012-05-18 00:51:36 +0000 | [diff] [blame] | 599 | result.SetStatus (eReturnStatusFailed); |
| 600 | return false; |
| 601 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 602 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
| 606 | if (result.Succeeded()) |
| 607 | { |
| 608 | // Okay, we're done. Last step is to warn if the executable module has changed: |
Greg Clayton | 7e2f91c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 609 | char new_path[PATH_MAX]; |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 610 | ModuleSP new_exec_module_sp (target->GetExecutableModule()); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 611 | if (!old_exec_module_sp) |
| 612 | { |
Greg Clayton | 7e2f91c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 613 | // We might not have a module if we attached to a raw pid... |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 614 | if (new_exec_module_sp) |
Greg Clayton | 7e2f91c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 615 | { |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 616 | new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX); |
Greg Clayton | 7e2f91c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 617 | result.AppendMessageWithFormat("Executable module set to \"%s\".\n", new_path); |
| 618 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 619 | } |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 620 | else if (old_exec_module_sp->GetFileSpec() != new_exec_module_sp->GetFileSpec()) |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 621 | { |
Greg Clayton | 7e2f91c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 622 | char old_path[PATH_MAX]; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 623 | |
Greg Clayton | 5beb99d | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 624 | old_exec_module_sp->GetFileSpec().GetPath (old_path, PATH_MAX); |
| 625 | new_exec_module_sp->GetFileSpec().GetPath (new_path, PATH_MAX); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 626 | |
| 627 | result.AppendWarningWithFormat("Executable module changed from \"%s\" to \"%s\".\n", |
| 628 | old_path, new_path); |
| 629 | } |
| 630 | |
| 631 | if (!old_arch_spec.IsValid()) |
| 632 | { |
Greg Clayton | 92cb9a9 | 2012-09-14 02:41:36 +0000 | [diff] [blame] | 633 | result.AppendMessageWithFormat ("Architecture set to: %s.\n", target->GetArchitecture().GetTriple().getTriple().c_str()); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 634 | } |
| 635 | else if (old_arch_spec != target->GetArchitecture()) |
| 636 | { |
| 637 | result.AppendWarningWithFormat("Architecture changed from %s to %s.\n", |
Greg Clayton | 92cb9a9 | 2012-09-14 02:41:36 +0000 | [diff] [blame] | 638 | old_arch_spec.GetTriple().getTriple().c_str(), |
| 639 | target->GetArchitecture().GetTriple().getTriple().c_str()); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 640 | } |
Johnny Chen | 7c09997 | 2012-05-24 00:43:00 +0000 | [diff] [blame] | 641 | |
| 642 | // This supports the use-case scenario of immediately continuing the process once attached. |
| 643 | if (m_options.attach_info.GetContinueOnceAttached()) |
Sean Callanan | 4336d93 | 2012-05-31 01:30:08 +0000 | [diff] [blame] | 644 | m_interpreter.HandleCommand("process continue", eLazyBoolNo, result); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 645 | } |
| 646 | return result.Succeeded(); |
| 647 | } |
| 648 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 649 | CommandOptions m_options; |
| 650 | }; |
| 651 | |
| 652 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 653 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 654 | CommandObjectProcessAttach::CommandOptions::g_option_table[] = |
| 655 | { |
Jim Ingham | 3a458eb | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 656 | { LLDB_OPT_SET_ALL, false, "continue",'c', no_argument, NULL, 0, eArgTypeNone, "Immediately continue the process once attached."}, |
| 657 | { LLDB_OPT_SET_ALL, false, "plugin", 'P', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, |
| 658 | { LLDB_OPT_SET_1, false, "pid", 'p', required_argument, NULL, 0, eArgTypePid, "The process ID of an existing process to attach to."}, |
| 659 | { LLDB_OPT_SET_2, false, "name", 'n', required_argument, NULL, 0, eArgTypeProcessName, "The name of the process to attach to."}, |
| 660 | { LLDB_OPT_SET_2, false, "include-existing", 'i', no_argument, NULL, 0, eArgTypeNone, "Include existing processes when doing attach -w."}, |
| 661 | { LLDB_OPT_SET_2, false, "waitfor", 'w', no_argument, NULL, 0, eArgTypeNone, "Wait for the process with <process-name> to launch."}, |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 662 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | //------------------------------------------------------------------------- |
| 666 | // CommandObjectProcessContinue |
| 667 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 668 | #pragma mark CommandObjectProcessContinue |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 670 | class CommandObjectProcessContinue : public CommandObjectParsed |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | { |
| 672 | public: |
| 673 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 674 | CommandObjectProcessContinue (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 675 | CommandObjectParsed (interpreter, |
| 676 | "process continue", |
| 677 | "Continue execution of all threads in the current process.", |
| 678 | "process continue", |
Jim Ingham | 124e690 | 2012-08-11 01:27:55 +0000 | [diff] [blame] | 679 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), |
| 680 | m_options(interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 681 | { |
| 682 | } |
| 683 | |
| 684 | |
| 685 | ~CommandObjectProcessContinue () |
| 686 | { |
| 687 | } |
| 688 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 689 | protected: |
Jim Ingham | 124e690 | 2012-08-11 01:27:55 +0000 | [diff] [blame] | 690 | |
| 691 | class CommandOptions : public Options |
| 692 | { |
| 693 | public: |
| 694 | |
| 695 | CommandOptions (CommandInterpreter &interpreter) : |
| 696 | Options(interpreter) |
| 697 | { |
| 698 | // Keep default values of all options in one place: OptionParsingStarting () |
| 699 | OptionParsingStarting (); |
| 700 | } |
| 701 | |
| 702 | ~CommandOptions () |
| 703 | { |
| 704 | } |
| 705 | |
| 706 | Error |
| 707 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
| 708 | { |
| 709 | Error error; |
| 710 | char short_option = (char) m_getopt_table[option_idx].val; |
| 711 | bool success = false; |
| 712 | switch (short_option) |
| 713 | { |
| 714 | case 'i': |
| 715 | m_ignore = Args::StringToUInt32 (option_arg, 0, 0, &success); |
| 716 | if (!success) |
| 717 | error.SetErrorStringWithFormat ("invalid value for ignore option: \"%s\", should be a number.", option_arg); |
| 718 | break; |
| 719 | |
| 720 | default: |
| 721 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
| 722 | break; |
| 723 | } |
| 724 | return error; |
| 725 | } |
| 726 | |
| 727 | void |
| 728 | OptionParsingStarting () |
| 729 | { |
| 730 | m_ignore = 0; |
| 731 | } |
| 732 | |
| 733 | const OptionDefinition* |
| 734 | GetDefinitions () |
| 735 | { |
| 736 | return g_option_table; |
| 737 | } |
| 738 | |
| 739 | // Options table: Required for subclasses of Options. |
| 740 | |
| 741 | static OptionDefinition g_option_table[]; |
| 742 | |
| 743 | uint32_t m_ignore; |
| 744 | }; |
| 745 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 746 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 747 | DoExecute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 748 | CommandReturnObject &result) |
| 749 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 750 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 751 | bool synchronous_execution = m_interpreter.GetSynchronous (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 752 | |
| 753 | if (process == NULL) |
| 754 | { |
| 755 | result.AppendError ("no process to continue"); |
| 756 | result.SetStatus (eReturnStatusFailed); |
| 757 | return false; |
| 758 | } |
| 759 | |
| 760 | StateType state = process->GetState(); |
| 761 | if (state == eStateStopped) |
| 762 | { |
| 763 | if (command.GetArgumentCount() != 0) |
| 764 | { |
| 765 | result.AppendErrorWithFormat ("The '%s' command does not take any arguments.\n", m_cmd_name.c_str()); |
| 766 | result.SetStatus (eReturnStatusFailed); |
| 767 | return false; |
| 768 | } |
| 769 | |
Jim Ingham | 124e690 | 2012-08-11 01:27:55 +0000 | [diff] [blame] | 770 | if (m_options.m_ignore > 0) |
| 771 | { |
| 772 | ThreadSP sel_thread_sp(process->GetThreadList().GetSelectedThread()); |
| 773 | if (sel_thread_sp) |
| 774 | { |
| 775 | StopInfoSP stop_info_sp = sel_thread_sp->GetStopInfo(); |
| 776 | if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonBreakpoint) |
| 777 | { |
| 778 | uint64_t bp_site_id = stop_info_sp->GetValue(); |
| 779 | BreakpointSiteSP bp_site_sp(process->GetBreakpointSiteList().FindByID(bp_site_id)); |
| 780 | if (bp_site_sp) |
| 781 | { |
| 782 | uint32_t num_owners = bp_site_sp->GetNumberOfOwners(); |
| 783 | for (uint32_t i = 0; i < num_owners; i++) |
| 784 | { |
| 785 | Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint(); |
| 786 | if (!bp_ref.IsInternal()) |
| 787 | { |
| 788 | bp_ref.SetIgnoreCount(m_options.m_ignore); |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | |
Jim Ingham | b995059 | 2012-09-10 20:50:15 +0000 | [diff] [blame] | 796 | { // Scope for thread list mutex: |
| 797 | Mutex::Locker locker (process->GetThreadList().GetMutex()); |
| 798 | const uint32_t num_threads = process->GetThreadList().GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 799 | |
Jim Ingham | b995059 | 2012-09-10 20:50:15 +0000 | [diff] [blame] | 800 | // Set the actions that the threads should each take when resuming |
| 801 | for (uint32_t idx=0; idx<num_threads; ++idx) |
| 802 | { |
| 803 | process->GetThreadList().GetThreadAtIndex(idx)->SetResumeState (eStateRunning); |
| 804 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | } |
Jim Ingham | b995059 | 2012-09-10 20:50:15 +0000 | [diff] [blame] | 806 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 807 | Error error(process->Resume()); |
| 808 | if (error.Success()) |
| 809 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 810 | result.AppendMessageWithFormat ("Process %llu resuming\n", process->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | if (synchronous_execution) |
| 812 | { |
Greg Clayton | bef1583 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 813 | state = process->WaitForProcessToStop (NULL); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 814 | |
| 815 | result.SetDidChangeProcessState (true); |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 816 | result.AppendMessageWithFormat ("Process %llu %s\n", process->GetID(), StateAsCString (state)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 817 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 818 | } |
| 819 | else |
| 820 | { |
| 821 | result.SetStatus (eReturnStatusSuccessContinuingNoResult); |
| 822 | } |
| 823 | } |
| 824 | else |
| 825 | { |
| 826 | result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString()); |
| 827 | result.SetStatus (eReturnStatusFailed); |
| 828 | } |
| 829 | } |
| 830 | else |
| 831 | { |
| 832 | result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n", |
| 833 | StateAsCString(state)); |
| 834 | result.SetStatus (eReturnStatusFailed); |
| 835 | } |
| 836 | return result.Succeeded(); |
| 837 | } |
Jim Ingham | 124e690 | 2012-08-11 01:27:55 +0000 | [diff] [blame] | 838 | |
| 839 | Options * |
| 840 | GetOptions () |
| 841 | { |
| 842 | return &m_options; |
| 843 | } |
| 844 | |
| 845 | CommandOptions m_options; |
| 846 | |
| 847 | }; |
| 848 | |
| 849 | OptionDefinition |
| 850 | CommandObjectProcessContinue::CommandOptions::g_option_table[] = |
| 851 | { |
| 852 | { LLDB_OPT_SET_ALL, false, "ignore-count",'i', required_argument, NULL, 0, eArgTypeUnsignedInteger, |
| 853 | "Ignore <N> crossings of the breakpoint (if it exists) for the currently selected thread."}, |
| 854 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 855 | }; |
| 856 | |
| 857 | //------------------------------------------------------------------------- |
| 858 | // CommandObjectProcessDetach |
| 859 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 860 | #pragma mark CommandObjectProcessDetach |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 861 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 862 | class CommandObjectProcessDetach : public CommandObjectParsed |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | { |
| 864 | public: |
| 865 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 866 | CommandObjectProcessDetach (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 867 | CommandObjectParsed (interpreter, |
| 868 | "process detach", |
| 869 | "Detach from the current process being debugged.", |
| 870 | "process detach", |
| 871 | eFlagProcessMustBeLaunched) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 872 | { |
| 873 | } |
| 874 | |
| 875 | ~CommandObjectProcessDetach () |
| 876 | { |
| 877 | } |
| 878 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 879 | protected: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 880 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 881 | DoExecute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 882 | CommandReturnObject &result) |
| 883 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 884 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | if (process == NULL) |
| 886 | { |
| 887 | result.AppendError ("must have a valid process in order to detach"); |
| 888 | result.SetStatus (eReturnStatusFailed); |
| 889 | return false; |
| 890 | } |
| 891 | |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 892 | result.AppendMessageWithFormat ("Detaching from process %llu\n", process->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 893 | Error error (process->Detach()); |
| 894 | if (error.Success()) |
| 895 | { |
| 896 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 897 | } |
| 898 | else |
| 899 | { |
| 900 | result.AppendErrorWithFormat ("Detach failed: %s\n", error.AsCString()); |
| 901 | result.SetStatus (eReturnStatusFailed); |
| 902 | return false; |
| 903 | } |
| 904 | return result.Succeeded(); |
| 905 | } |
| 906 | }; |
| 907 | |
| 908 | //------------------------------------------------------------------------- |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 909 | // CommandObjectProcessConnect |
| 910 | //------------------------------------------------------------------------- |
| 911 | #pragma mark CommandObjectProcessConnect |
| 912 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 913 | class CommandObjectProcessConnect : public CommandObjectParsed |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 914 | { |
| 915 | public: |
| 916 | |
| 917 | class CommandOptions : public Options |
| 918 | { |
| 919 | public: |
| 920 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 921 | CommandOptions (CommandInterpreter &interpreter) : |
| 922 | Options(interpreter) |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 923 | { |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 924 | // Keep default values of all options in one place: OptionParsingStarting () |
| 925 | OptionParsingStarting (); |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | ~CommandOptions () |
| 929 | { |
| 930 | } |
| 931 | |
| 932 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 933 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 934 | { |
| 935 | Error error; |
| 936 | char short_option = (char) m_getopt_table[option_idx].val; |
| 937 | |
| 938 | switch (short_option) |
| 939 | { |
| 940 | case 'p': |
| 941 | plugin_name.assign (option_arg); |
| 942 | break; |
| 943 | |
| 944 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 945 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 946 | break; |
| 947 | } |
| 948 | return error; |
| 949 | } |
| 950 | |
| 951 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 952 | OptionParsingStarting () |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 953 | { |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 954 | plugin_name.clear(); |
| 955 | } |
| 956 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 957 | const OptionDefinition* |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 958 | GetDefinitions () |
| 959 | { |
| 960 | return g_option_table; |
| 961 | } |
| 962 | |
| 963 | // Options table: Required for subclasses of Options. |
| 964 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 965 | static OptionDefinition g_option_table[]; |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 966 | |
| 967 | // Instance variables to hold the values for command options. |
| 968 | |
| 969 | std::string plugin_name; |
| 970 | }; |
| 971 | |
| 972 | CommandObjectProcessConnect (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 973 | CommandObjectParsed (interpreter, |
| 974 | "process connect", |
| 975 | "Connect to a remote debug service.", |
| 976 | "process connect <remote-url>", |
| 977 | 0), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 978 | m_options (interpreter) |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 979 | { |
| 980 | } |
| 981 | |
| 982 | ~CommandObjectProcessConnect () |
| 983 | { |
| 984 | } |
| 985 | |
| 986 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 987 | Options * |
| 988 | GetOptions () |
| 989 | { |
| 990 | return &m_options; |
| 991 | } |
| 992 | |
| 993 | protected: |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 994 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 995 | DoExecute (Args& command, |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 996 | CommandReturnObject &result) |
| 997 | { |
| 998 | |
| 999 | TargetSP target_sp (m_interpreter.GetDebugger().GetSelectedTarget()); |
| 1000 | Error error; |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1001 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1002 | if (process) |
| 1003 | { |
| 1004 | if (process->IsAlive()) |
| 1005 | { |
Greg Clayton | 444e35b | 2011-10-19 18:09:39 +0000 | [diff] [blame] | 1006 | result.AppendErrorWithFormat ("Process %llu is currently being debugged, kill the process before connecting.\n", |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1007 | process->GetID()); |
| 1008 | result.SetStatus (eReturnStatusFailed); |
| 1009 | return false; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | if (!target_sp) |
| 1014 | { |
| 1015 | // If there isn't a current target create one. |
| 1016 | FileSpec emptyFileSpec; |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1017 | |
| 1018 | error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(), |
| 1019 | emptyFileSpec, |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1020 | NULL, |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1021 | false, |
Greg Clayton | 3e8c25f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1022 | NULL, // No platform options |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1023 | target_sp); |
| 1024 | if (!target_sp || error.Fail()) |
| 1025 | { |
| 1026 | result.AppendError(error.AsCString("Error creating target")); |
| 1027 | result.SetStatus (eReturnStatusFailed); |
| 1028 | return false; |
| 1029 | } |
| 1030 | m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target_sp.get()); |
| 1031 | } |
| 1032 | |
| 1033 | if (command.GetArgumentCount() == 1) |
| 1034 | { |
| 1035 | const char *plugin_name = NULL; |
| 1036 | if (!m_options.plugin_name.empty()) |
| 1037 | plugin_name = m_options.plugin_name.c_str(); |
| 1038 | |
| 1039 | const char *remote_url = command.GetArgumentAtIndex(0); |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 1040 | process = target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name, NULL).get(); |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1041 | |
| 1042 | if (process) |
| 1043 | { |
| 1044 | error = process->ConnectRemote (remote_url); |
| 1045 | |
| 1046 | if (error.Fail()) |
| 1047 | { |
| 1048 | result.AppendError(error.AsCString("Remote connect failed")); |
| 1049 | result.SetStatus (eReturnStatusFailed); |
Greg Clayton | 0cbb93b | 2012-03-31 00:10:30 +0000 | [diff] [blame] | 1050 | target_sp->DeleteCurrentProcess(); |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1051 | return false; |
| 1052 | } |
| 1053 | } |
| 1054 | else |
| 1055 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1056 | result.AppendErrorWithFormat ("Unable to find process plug-in for remote URL '%s'.\nPlease specify a process plug-in name with the --plugin option, or specify an object file using the \"file\" command.\n", |
| 1057 | m_cmd_name.c_str()); |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1058 | result.SetStatus (eReturnStatusFailed); |
| 1059 | } |
| 1060 | } |
| 1061 | else |
| 1062 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1063 | result.AppendErrorWithFormat ("'%s' takes exactly one argument:\nUsage: %s\n", |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1064 | m_cmd_name.c_str(), |
| 1065 | m_cmd_syntax.c_str()); |
| 1066 | result.SetStatus (eReturnStatusFailed); |
| 1067 | } |
| 1068 | return result.Succeeded(); |
| 1069 | } |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1070 | |
| 1071 | CommandOptions m_options; |
| 1072 | }; |
| 1073 | |
| 1074 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1075 | OptionDefinition |
Greg Clayton | e71e258 | 2011-02-04 01:58:07 +0000 | [diff] [blame] | 1076 | CommandObjectProcessConnect::CommandOptions::g_option_table[] = |
| 1077 | { |
| 1078 | { LLDB_OPT_SET_ALL, false, "plugin", 'p', required_argument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."}, |
| 1079 | { 0, false, NULL, 0 , 0, NULL, 0, eArgTypeNone, NULL } |
| 1080 | }; |
| 1081 | |
| 1082 | //------------------------------------------------------------------------- |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1083 | // CommandObjectProcessLoad |
| 1084 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 1085 | #pragma mark CommandObjectProcessLoad |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1086 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1087 | class CommandObjectProcessLoad : public CommandObjectParsed |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1088 | { |
| 1089 | public: |
| 1090 | |
| 1091 | CommandObjectProcessLoad (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1092 | CommandObjectParsed (interpreter, |
| 1093 | "process load", |
| 1094 | "Load a shared library into the current process.", |
| 1095 | "process load <filename> [<filename> ...]", |
| 1096 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1097 | { |
| 1098 | } |
| 1099 | |
| 1100 | ~CommandObjectProcessLoad () |
| 1101 | { |
| 1102 | } |
| 1103 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1104 | protected: |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1105 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1106 | DoExecute (Args& command, |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1107 | CommandReturnObject &result) |
| 1108 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1109 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1110 | if (process == NULL) |
| 1111 | { |
| 1112 | result.AppendError ("must have a valid process in order to load a shared library"); |
| 1113 | result.SetStatus (eReturnStatusFailed); |
| 1114 | return false; |
| 1115 | } |
| 1116 | |
| 1117 | const uint32_t argc = command.GetArgumentCount(); |
| 1118 | |
| 1119 | for (uint32_t i=0; i<argc; ++i) |
| 1120 | { |
| 1121 | Error error; |
| 1122 | const char *image_path = command.GetArgumentAtIndex(i); |
| 1123 | FileSpec image_spec (image_path, false); |
Greg Clayton | f2bf870 | 2011-08-11 16:25:18 +0000 | [diff] [blame] | 1124 | process->GetTarget().GetPlatform()->ResolveRemotePath(image_spec, image_spec); |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1125 | uint32_t image_token = process->LoadImage(image_spec, error); |
| 1126 | if (image_token != LLDB_INVALID_IMAGE_TOKEN) |
| 1127 | { |
| 1128 | result.AppendMessageWithFormat ("Loading \"%s\"...ok\nImage %u loaded.\n", image_path, image_token); |
| 1129 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1130 | } |
| 1131 | else |
| 1132 | { |
| 1133 | result.AppendErrorWithFormat ("failed to load '%s': %s", image_path, error.AsCString()); |
| 1134 | result.SetStatus (eReturnStatusFailed); |
| 1135 | } |
| 1136 | } |
| 1137 | return result.Succeeded(); |
| 1138 | } |
| 1139 | }; |
| 1140 | |
| 1141 | |
| 1142 | //------------------------------------------------------------------------- |
| 1143 | // CommandObjectProcessUnload |
| 1144 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 1145 | #pragma mark CommandObjectProcessUnload |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1146 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1147 | class CommandObjectProcessUnload : public CommandObjectParsed |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1148 | { |
| 1149 | public: |
| 1150 | |
| 1151 | CommandObjectProcessUnload (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1152 | CommandObjectParsed (interpreter, |
| 1153 | "process unload", |
| 1154 | "Unload a shared library from the current process using the index returned by a previous call to \"process load\".", |
| 1155 | "process unload <index>", |
| 1156 | eFlagProcessMustBeLaunched | eFlagProcessMustBePaused) |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1157 | { |
| 1158 | } |
| 1159 | |
| 1160 | ~CommandObjectProcessUnload () |
| 1161 | { |
| 1162 | } |
| 1163 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1164 | protected: |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1165 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1166 | DoExecute (Args& command, |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1167 | CommandReturnObject &result) |
| 1168 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1169 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Greg Clayton | 0baa394 | 2010-11-04 01:54:29 +0000 | [diff] [blame] | 1170 | if (process == NULL) |
| 1171 | { |
| 1172 | result.AppendError ("must have a valid process in order to load a shared library"); |
| 1173 | result.SetStatus (eReturnStatusFailed); |
| 1174 | return false; |
| 1175 | } |
| 1176 | |
| 1177 | const uint32_t argc = command.GetArgumentCount(); |
| 1178 | |
| 1179 | for (uint32_t i=0; i<argc; ++i) |
| 1180 | { |
| 1181 | const char *image_token_cstr = command.GetArgumentAtIndex(i); |
| 1182 | uint32_t image_token = Args::StringToUInt32(image_token_cstr, LLDB_INVALID_IMAGE_TOKEN, 0); |
| 1183 | if (image_token == LLDB_INVALID_IMAGE_TOKEN) |
| 1184 | { |
| 1185 | result.AppendErrorWithFormat ("invalid image index argument '%s'", image_token_cstr); |
| 1186 | result.SetStatus (eReturnStatusFailed); |
| 1187 | break; |
| 1188 | } |
| 1189 | else |
| 1190 | { |
| 1191 | Error error (process->UnloadImage(image_token)); |
| 1192 | if (error.Success()) |
| 1193 | { |
| 1194 | result.AppendMessageWithFormat ("Unloading shared library with index %u...ok\n", image_token); |
| 1195 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1196 | } |
| 1197 | else |
| 1198 | { |
| 1199 | result.AppendErrorWithFormat ("failed to unload image: %s", error.AsCString()); |
| 1200 | result.SetStatus (eReturnStatusFailed); |
| 1201 | break; |
| 1202 | } |
| 1203 | } |
| 1204 | } |
| 1205 | return result.Succeeded(); |
| 1206 | } |
| 1207 | }; |
| 1208 | |
| 1209 | //------------------------------------------------------------------------- |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1210 | // CommandObjectProcessSignal |
| 1211 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 1212 | #pragma mark CommandObjectProcessSignal |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1213 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1214 | class CommandObjectProcessSignal : public CommandObjectParsed |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1215 | { |
| 1216 | public: |
| 1217 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1218 | CommandObjectProcessSignal (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1219 | CommandObjectParsed (interpreter, |
| 1220 | "process signal", |
| 1221 | "Send a UNIX signal to the current process being debugged.", |
| 1222 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1223 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1224 | CommandArgumentEntry arg; |
| 1225 | CommandArgumentData signal_arg; |
| 1226 | |
| 1227 | // Define the first (and only) variant of this arg. |
Caroline Tice | 3a62e6d | 2010-10-18 22:56:57 +0000 | [diff] [blame] | 1228 | signal_arg.arg_type = eArgTypeUnixSignal; |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1229 | signal_arg.arg_repetition = eArgRepeatPlain; |
| 1230 | |
| 1231 | // There is only one variant this argument could be; put it into the argument entry. |
| 1232 | arg.push_back (signal_arg); |
| 1233 | |
| 1234 | // Push the data for the first argument into the m_arguments vector. |
| 1235 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | ~CommandObjectProcessSignal () |
| 1239 | { |
| 1240 | } |
| 1241 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1242 | protected: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1243 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1244 | DoExecute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1245 | CommandReturnObject &result) |
| 1246 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1247 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1248 | if (process == NULL) |
| 1249 | { |
| 1250 | result.AppendError ("no process to signal"); |
| 1251 | result.SetStatus (eReturnStatusFailed); |
| 1252 | return false; |
| 1253 | } |
| 1254 | |
| 1255 | if (command.GetArgumentCount() == 1) |
| 1256 | { |
Greg Clayton | 8f6be2a | 2010-10-09 01:40:57 +0000 | [diff] [blame] | 1257 | int signo = LLDB_INVALID_SIGNAL_NUMBER; |
| 1258 | |
| 1259 | const char *signal_name = command.GetArgumentAtIndex(0); |
| 1260 | if (::isxdigit (signal_name[0])) |
| 1261 | signo = Args::StringToSInt32(signal_name, LLDB_INVALID_SIGNAL_NUMBER, 0); |
| 1262 | else |
| 1263 | signo = process->GetUnixSignals().GetSignalNumberFromName (signal_name); |
| 1264 | |
| 1265 | if (signo == LLDB_INVALID_SIGNAL_NUMBER) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1266 | { |
| 1267 | result.AppendErrorWithFormat ("Invalid signal argument '%s'.\n", command.GetArgumentAtIndex(0)); |
| 1268 | result.SetStatus (eReturnStatusFailed); |
| 1269 | } |
| 1270 | else |
| 1271 | { |
| 1272 | Error error (process->Signal (signo)); |
| 1273 | if (error.Success()) |
| 1274 | { |
| 1275 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1276 | } |
| 1277 | else |
| 1278 | { |
| 1279 | result.AppendErrorWithFormat ("Failed to send signal %i: %s\n", signo, error.AsCString()); |
| 1280 | result.SetStatus (eReturnStatusFailed); |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | else |
| 1285 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1286 | result.AppendErrorWithFormat("'%s' takes exactly one signal number argument:\nUsage: %s\n", m_cmd_name.c_str(), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1287 | m_cmd_syntax.c_str()); |
| 1288 | result.SetStatus (eReturnStatusFailed); |
| 1289 | } |
| 1290 | return result.Succeeded(); |
| 1291 | } |
| 1292 | }; |
| 1293 | |
| 1294 | |
| 1295 | //------------------------------------------------------------------------- |
| 1296 | // CommandObjectProcessInterrupt |
| 1297 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 1298 | #pragma mark CommandObjectProcessInterrupt |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1299 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1300 | class CommandObjectProcessInterrupt : public CommandObjectParsed |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1301 | { |
| 1302 | public: |
| 1303 | |
| 1304 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1305 | CommandObjectProcessInterrupt (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1306 | CommandObjectParsed (interpreter, |
| 1307 | "process interrupt", |
| 1308 | "Interrupt the current process being debugged.", |
| 1309 | "process interrupt", |
| 1310 | eFlagProcessMustBeLaunched) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1311 | { |
| 1312 | } |
| 1313 | |
| 1314 | ~CommandObjectProcessInterrupt () |
| 1315 | { |
| 1316 | } |
| 1317 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1318 | protected: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1319 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1320 | DoExecute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1321 | CommandReturnObject &result) |
| 1322 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1323 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1324 | if (process == NULL) |
| 1325 | { |
| 1326 | result.AppendError ("no process to halt"); |
| 1327 | result.SetStatus (eReturnStatusFailed); |
| 1328 | return false; |
| 1329 | } |
| 1330 | |
| 1331 | if (command.GetArgumentCount() == 0) |
| 1332 | { |
| 1333 | Error error(process->Halt ()); |
| 1334 | if (error.Success()) |
| 1335 | { |
| 1336 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1337 | |
| 1338 | // Maybe we should add a "SuspendThreadPlans so we |
| 1339 | // can halt, and keep in place all the current thread plans. |
| 1340 | process->GetThreadList().DiscardThreadPlans(); |
| 1341 | } |
| 1342 | else |
| 1343 | { |
| 1344 | result.AppendErrorWithFormat ("Failed to halt process: %s\n", error.AsCString()); |
| 1345 | result.SetStatus (eReturnStatusFailed); |
| 1346 | } |
| 1347 | } |
| 1348 | else |
| 1349 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1350 | result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1351 | m_cmd_name.c_str(), |
| 1352 | m_cmd_syntax.c_str()); |
| 1353 | result.SetStatus (eReturnStatusFailed); |
| 1354 | } |
| 1355 | return result.Succeeded(); |
| 1356 | } |
| 1357 | }; |
| 1358 | |
| 1359 | //------------------------------------------------------------------------- |
| 1360 | // CommandObjectProcessKill |
| 1361 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 1362 | #pragma mark CommandObjectProcessKill |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1363 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1364 | class CommandObjectProcessKill : public CommandObjectParsed |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1365 | { |
| 1366 | public: |
| 1367 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1368 | CommandObjectProcessKill (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1369 | CommandObjectParsed (interpreter, |
| 1370 | "process kill", |
| 1371 | "Terminate the current process being debugged.", |
| 1372 | "process kill", |
| 1373 | eFlagProcessMustBeLaunched) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1374 | { |
| 1375 | } |
| 1376 | |
| 1377 | ~CommandObjectProcessKill () |
| 1378 | { |
| 1379 | } |
| 1380 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1381 | protected: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1382 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1383 | DoExecute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1384 | CommandReturnObject &result) |
| 1385 | { |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1386 | Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1387 | if (process == NULL) |
| 1388 | { |
| 1389 | result.AppendError ("no process to kill"); |
| 1390 | result.SetStatus (eReturnStatusFailed); |
| 1391 | return false; |
| 1392 | } |
| 1393 | |
| 1394 | if (command.GetArgumentCount() == 0) |
| 1395 | { |
| 1396 | Error error (process->Destroy()); |
| 1397 | if (error.Success()) |
| 1398 | { |
| 1399 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1400 | } |
| 1401 | else |
| 1402 | { |
| 1403 | result.AppendErrorWithFormat ("Failed to kill process: %s\n", error.AsCString()); |
| 1404 | result.SetStatus (eReturnStatusFailed); |
| 1405 | } |
| 1406 | } |
| 1407 | else |
| 1408 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 1409 | result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1410 | m_cmd_name.c_str(), |
| 1411 | m_cmd_syntax.c_str()); |
| 1412 | result.SetStatus (eReturnStatusFailed); |
| 1413 | } |
| 1414 | return result.Succeeded(); |
| 1415 | } |
| 1416 | }; |
| 1417 | |
| 1418 | //------------------------------------------------------------------------- |
Jim Ingham | 41313fc | 2010-06-18 01:23:09 +0000 | [diff] [blame] | 1419 | // CommandObjectProcessStatus |
| 1420 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 1421 | #pragma mark CommandObjectProcessStatus |
| 1422 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1423 | class CommandObjectProcessStatus : public CommandObjectParsed |
Jim Ingham | 41313fc | 2010-06-18 01:23:09 +0000 | [diff] [blame] | 1424 | { |
| 1425 | public: |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1426 | CommandObjectProcessStatus (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1427 | CommandObjectParsed (interpreter, |
| 1428 | "process status", |
| 1429 | "Show the current status and location of executing process.", |
| 1430 | "process status", |
| 1431 | 0) |
Jim Ingham | 41313fc | 2010-06-18 01:23:09 +0000 | [diff] [blame] | 1432 | { |
| 1433 | } |
| 1434 | |
| 1435 | ~CommandObjectProcessStatus() |
| 1436 | { |
| 1437 | } |
| 1438 | |
| 1439 | |
| 1440 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1441 | DoExecute (Args& command, CommandReturnObject &result) |
Jim Ingham | 41313fc | 2010-06-18 01:23:09 +0000 | [diff] [blame] | 1442 | { |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1443 | Stream &strm = result.GetOutputStream(); |
Jim Ingham | 41313fc | 2010-06-18 01:23:09 +0000 | [diff] [blame] | 1444 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 1445 | ExecutionContext exe_ctx(m_interpreter.GetExecutionContext()); |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1446 | Process *process = exe_ctx.GetProcessPtr(); |
| 1447 | if (process) |
Jim Ingham | 41313fc | 2010-06-18 01:23:09 +0000 | [diff] [blame] | 1448 | { |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1449 | const bool only_threads_with_stop_reason = true; |
| 1450 | const uint32_t start_frame = 0; |
| 1451 | const uint32_t num_frames = 1; |
| 1452 | const uint32_t num_frames_with_source = 1; |
Greg Clayton | 567e7f3 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1453 | process->GetStatus(strm); |
| 1454 | process->GetThreadStatus (strm, |
| 1455 | only_threads_with_stop_reason, |
| 1456 | start_frame, |
| 1457 | num_frames, |
| 1458 | num_frames_with_source); |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1459 | |
Jim Ingham | 41313fc | 2010-06-18 01:23:09 +0000 | [diff] [blame] | 1460 | } |
| 1461 | else |
| 1462 | { |
Greg Clayton | abe0fed | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1463 | result.AppendError ("No process."); |
Jim Ingham | 41313fc | 2010-06-18 01:23:09 +0000 | [diff] [blame] | 1464 | result.SetStatus (eReturnStatusFailed); |
| 1465 | } |
| 1466 | return result.Succeeded(); |
| 1467 | } |
| 1468 | }; |
| 1469 | |
| 1470 | //------------------------------------------------------------------------- |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1471 | // CommandObjectProcessHandle |
| 1472 | //------------------------------------------------------------------------- |
Jim Ingham | 22dc972 | 2010-12-09 18:58:16 +0000 | [diff] [blame] | 1473 | #pragma mark CommandObjectProcessHandle |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1474 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1475 | class CommandObjectProcessHandle : public CommandObjectParsed |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1476 | { |
| 1477 | public: |
| 1478 | |
| 1479 | class CommandOptions : public Options |
| 1480 | { |
| 1481 | public: |
| 1482 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1483 | CommandOptions (CommandInterpreter &interpreter) : |
| 1484 | Options (interpreter) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1485 | { |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 1486 | OptionParsingStarting (); |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | ~CommandOptions () |
| 1490 | { |
| 1491 | } |
| 1492 | |
| 1493 | Error |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 1494 | SetOptionValue (uint32_t option_idx, const char *option_arg) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1495 | { |
| 1496 | Error error; |
| 1497 | char short_option = (char) m_getopt_table[option_idx].val; |
| 1498 | |
| 1499 | switch (short_option) |
| 1500 | { |
| 1501 | case 's': |
| 1502 | stop = option_arg; |
| 1503 | break; |
| 1504 | case 'n': |
| 1505 | notify = option_arg; |
| 1506 | break; |
| 1507 | case 'p': |
| 1508 | pass = option_arg; |
| 1509 | break; |
| 1510 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 1511 | error.SetErrorStringWithFormat("invalid short option character '%c'", short_option); |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1512 | break; |
| 1513 | } |
| 1514 | return error; |
| 1515 | } |
| 1516 | |
| 1517 | void |
Greg Clayton | 143fcc3 | 2011-04-13 00:18:08 +0000 | [diff] [blame] | 1518 | OptionParsingStarting () |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1519 | { |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1520 | stop.clear(); |
| 1521 | notify.clear(); |
| 1522 | pass.clear(); |
| 1523 | } |
| 1524 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1525 | const OptionDefinition* |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1526 | GetDefinitions () |
| 1527 | { |
| 1528 | return g_option_table; |
| 1529 | } |
| 1530 | |
| 1531 | // Options table: Required for subclasses of Options. |
| 1532 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1533 | static OptionDefinition g_option_table[]; |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1534 | |
| 1535 | // Instance variables to hold the values for command options. |
| 1536 | |
| 1537 | std::string stop; |
| 1538 | std::string notify; |
| 1539 | std::string pass; |
| 1540 | }; |
| 1541 | |
| 1542 | |
| 1543 | CommandObjectProcessHandle (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1544 | CommandObjectParsed (interpreter, |
| 1545 | "process handle", |
| 1546 | "Show or update what the process and debugger should do with various signals received from the OS.", |
| 1547 | NULL), |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1548 | m_options (interpreter) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1549 | { |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1550 | SetHelpLong ("If no signals are specified, update them all. If no update option is specified, list the current values.\n"); |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1551 | CommandArgumentEntry arg; |
Caroline Tice | 3a62e6d | 2010-10-18 22:56:57 +0000 | [diff] [blame] | 1552 | CommandArgumentData signal_arg; |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1553 | |
Caroline Tice | 3a62e6d | 2010-10-18 22:56:57 +0000 | [diff] [blame] | 1554 | signal_arg.arg_type = eArgTypeUnixSignal; |
| 1555 | signal_arg.arg_repetition = eArgRepeatStar; |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1556 | |
Caroline Tice | 3a62e6d | 2010-10-18 22:56:57 +0000 | [diff] [blame] | 1557 | arg.push_back (signal_arg); |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1558 | |
| 1559 | m_arguments.push_back (arg); |
| 1560 | } |
| 1561 | |
| 1562 | ~CommandObjectProcessHandle () |
| 1563 | { |
| 1564 | } |
| 1565 | |
| 1566 | Options * |
| 1567 | GetOptions () |
| 1568 | { |
| 1569 | return &m_options; |
| 1570 | } |
| 1571 | |
| 1572 | bool |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1573 | VerifyCommandOptionValue (const std::string &option, int &real_value) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1574 | { |
| 1575 | bool okay = true; |
| 1576 | |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1577 | bool success = false; |
| 1578 | bool tmp_value = Args::StringToBoolean (option.c_str(), false, &success); |
| 1579 | |
| 1580 | if (success && tmp_value) |
| 1581 | real_value = 1; |
| 1582 | else if (success && !tmp_value) |
| 1583 | real_value = 0; |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1584 | else |
| 1585 | { |
| 1586 | // If the value isn't 'true' or 'false', it had better be 0 or 1. |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1587 | real_value = Args::StringToUInt32 (option.c_str(), 3); |
| 1588 | if (real_value != 0 && real_value != 1) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1589 | okay = false; |
| 1590 | } |
| 1591 | |
| 1592 | return okay; |
| 1593 | } |
| 1594 | |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1595 | void |
| 1596 | PrintSignalHeader (Stream &str) |
| 1597 | { |
| 1598 | str.Printf ("NAME PASS STOP NOTIFY\n"); |
| 1599 | str.Printf ("========== ===== ===== ======\n"); |
| 1600 | } |
| 1601 | |
| 1602 | void |
| 1603 | PrintSignal (Stream &str, int32_t signo, const char *sig_name, UnixSignals &signals) |
| 1604 | { |
| 1605 | bool stop; |
| 1606 | bool suppress; |
| 1607 | bool notify; |
| 1608 | |
| 1609 | str.Printf ("%-10s ", sig_name); |
| 1610 | if (signals.GetSignalInfo (signo, suppress, stop, notify)) |
| 1611 | { |
| 1612 | bool pass = !suppress; |
| 1613 | str.Printf ("%s %s %s", |
| 1614 | (pass ? "true " : "false"), |
| 1615 | (stop ? "true " : "false"), |
| 1616 | (notify ? "true " : "false")); |
| 1617 | } |
| 1618 | str.Printf ("\n"); |
| 1619 | } |
| 1620 | |
| 1621 | void |
| 1622 | PrintSignalInformation (Stream &str, Args &signal_args, int num_valid_signals, UnixSignals &signals) |
| 1623 | { |
| 1624 | PrintSignalHeader (str); |
| 1625 | |
| 1626 | if (num_valid_signals > 0) |
| 1627 | { |
| 1628 | size_t num_args = signal_args.GetArgumentCount(); |
| 1629 | for (size_t i = 0; i < num_args; ++i) |
| 1630 | { |
| 1631 | int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i)); |
| 1632 | if (signo != LLDB_INVALID_SIGNAL_NUMBER) |
| 1633 | PrintSignal (str, signo, signal_args.GetArgumentAtIndex (i), signals); |
| 1634 | } |
| 1635 | } |
| 1636 | else // Print info for ALL signals |
| 1637 | { |
| 1638 | int32_t signo = signals.GetFirstSignalNumber(); |
| 1639 | while (signo != LLDB_INVALID_SIGNAL_NUMBER) |
| 1640 | { |
| 1641 | PrintSignal (str, signo, signals.GetSignalAsCString (signo), signals); |
| 1642 | signo = signals.GetNextSignalNumber (signo); |
| 1643 | } |
| 1644 | } |
| 1645 | } |
| 1646 | |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1647 | protected: |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1648 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1649 | DoExecute (Args &signal_args, CommandReturnObject &result) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1650 | { |
| 1651 | TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget(); |
| 1652 | |
| 1653 | if (!target_sp) |
| 1654 | { |
| 1655 | result.AppendError ("No current target;" |
| 1656 | " cannot handle signals until you have a valid target and process.\n"); |
| 1657 | result.SetStatus (eReturnStatusFailed); |
| 1658 | return false; |
| 1659 | } |
| 1660 | |
| 1661 | ProcessSP process_sp = target_sp->GetProcessSP(); |
| 1662 | |
| 1663 | if (!process_sp) |
| 1664 | { |
| 1665 | result.AppendError ("No current process; cannot handle signals until you have a valid process.\n"); |
| 1666 | result.SetStatus (eReturnStatusFailed); |
| 1667 | return false; |
| 1668 | } |
| 1669 | |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1670 | int stop_action = -1; // -1 means leave the current setting alone |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1671 | int pass_action = -1; // -1 means leave the current setting alone |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1672 | int notify_action = -1; // -1 means leave the current setting alone |
| 1673 | |
| 1674 | if (! m_options.stop.empty() |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1675 | && ! VerifyCommandOptionValue (m_options.stop, stop_action)) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1676 | { |
| 1677 | result.AppendError ("Invalid argument for command option --stop; must be true or false.\n"); |
| 1678 | result.SetStatus (eReturnStatusFailed); |
| 1679 | return false; |
| 1680 | } |
| 1681 | |
| 1682 | if (! m_options.notify.empty() |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1683 | && ! VerifyCommandOptionValue (m_options.notify, notify_action)) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1684 | { |
| 1685 | result.AppendError ("Invalid argument for command option --notify; must be true or false.\n"); |
| 1686 | result.SetStatus (eReturnStatusFailed); |
| 1687 | return false; |
| 1688 | } |
| 1689 | |
| 1690 | if (! m_options.pass.empty() |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1691 | && ! VerifyCommandOptionValue (m_options.pass, pass_action)) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1692 | { |
| 1693 | result.AppendError ("Invalid argument for command option --pass; must be true or false.\n"); |
| 1694 | result.SetStatus (eReturnStatusFailed); |
| 1695 | return false; |
| 1696 | } |
| 1697 | |
| 1698 | size_t num_args = signal_args.GetArgumentCount(); |
| 1699 | UnixSignals &signals = process_sp->GetUnixSignals(); |
| 1700 | int num_signals_set = 0; |
| 1701 | |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1702 | if (num_args > 0) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1703 | { |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1704 | for (size_t i = 0; i < num_args; ++i) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1705 | { |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1706 | int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i)); |
| 1707 | if (signo != LLDB_INVALID_SIGNAL_NUMBER) |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1708 | { |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1709 | // Casting the actions as bools here should be okay, because VerifyCommandOptionValue guarantees |
| 1710 | // the value is either 0 or 1. |
| 1711 | if (stop_action != -1) |
| 1712 | signals.SetShouldStop (signo, (bool) stop_action); |
| 1713 | if (pass_action != -1) |
| 1714 | { |
| 1715 | bool suppress = ! ((bool) pass_action); |
| 1716 | signals.SetShouldSuppress (signo, suppress); |
| 1717 | } |
| 1718 | if (notify_action != -1) |
| 1719 | signals.SetShouldNotify (signo, (bool) notify_action); |
| 1720 | ++num_signals_set; |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1721 | } |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1722 | else |
| 1723 | { |
| 1724 | result.AppendErrorWithFormat ("Invalid signal name '%s'\n", signal_args.GetArgumentAtIndex (i)); |
| 1725 | } |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1726 | } |
| 1727 | } |
Caroline Tice | e747198 | 2010-10-14 21:31:13 +0000 | [diff] [blame] | 1728 | else |
| 1729 | { |
| 1730 | // No signal specified, if any command options were specified, update ALL signals. |
| 1731 | if ((notify_action != -1) || (stop_action != -1) || (pass_action != -1)) |
| 1732 | { |
| 1733 | if (m_interpreter.Confirm ("Do you really want to update all the signals?", false)) |
| 1734 | { |
| 1735 | int32_t signo = signals.GetFirstSignalNumber(); |
| 1736 | while (signo != LLDB_INVALID_SIGNAL_NUMBER) |
| 1737 | { |
| 1738 | if (notify_action != -1) |
| 1739 | signals.SetShouldNotify (signo, (bool) notify_action); |
| 1740 | if (stop_action != -1) |
| 1741 | signals.SetShouldStop (signo, (bool) stop_action); |
| 1742 | if (pass_action != -1) |
| 1743 | { |
| 1744 | bool suppress = ! ((bool) pass_action); |
| 1745 | signals.SetShouldSuppress (signo, suppress); |
| 1746 | } |
| 1747 | signo = signals.GetNextSignalNumber (signo); |
| 1748 | } |
| 1749 | } |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | PrintSignalInformation (result.GetOutputStream(), signal_args, num_signals_set, signals); |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1754 | |
| 1755 | if (num_signals_set > 0) |
| 1756 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1757 | else |
| 1758 | result.SetStatus (eReturnStatusFailed); |
| 1759 | |
| 1760 | return result.Succeeded(); |
| 1761 | } |
| 1762 | |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1763 | CommandOptions m_options; |
| 1764 | }; |
| 1765 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1766 | OptionDefinition |
Caroline Tice | 23d6f27 | 2010-10-13 20:44:39 +0000 | [diff] [blame] | 1767 | CommandObjectProcessHandle::CommandOptions::g_option_table[] = |
| 1768 | { |
| 1769 | { LLDB_OPT_SET_1, false, "stop", 's', required_argument, NULL, 0, eArgTypeBoolean, "Whether or not the process should be stopped if the signal is received." }, |
| 1770 | { LLDB_OPT_SET_1, false, "notify", 'n', required_argument, NULL, 0, eArgTypeBoolean, "Whether or not the debugger should notify the user if the signal is received." }, |
| 1771 | { LLDB_OPT_SET_1, false, "pass", 'p', required_argument, NULL, 0, eArgTypeBoolean, "Whether or not the signal should be passed to the process." }, |
| 1772 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 1773 | }; |
| 1774 | |
| 1775 | //------------------------------------------------------------------------- |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1776 | // CommandObjectMultiwordProcess |
| 1777 | //------------------------------------------------------------------------- |
| 1778 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1779 | CommandObjectMultiwordProcess::CommandObjectMultiwordProcess (CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1780 | CommandObjectMultiword (interpreter, |
| 1781 | "process", |
| 1782 | "A set of commands for operating on a process.", |
| 1783 | "process <subcommand> [<subcommand-options>]") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1784 | { |
Greg Clayton | a9eb827 | 2011-07-02 21:07:54 +0000 | [diff] [blame] | 1785 | LoadSubCommand ("attach", CommandObjectSP (new CommandObjectProcessAttach (interpreter))); |
| 1786 | LoadSubCommand ("launch", CommandObjectSP (new CommandObjectProcessLaunch (interpreter))); |
| 1787 | LoadSubCommand ("continue", CommandObjectSP (new CommandObjectProcessContinue (interpreter))); |
| 1788 | LoadSubCommand ("connect", CommandObjectSP (new CommandObjectProcessConnect (interpreter))); |
| 1789 | LoadSubCommand ("detach", CommandObjectSP (new CommandObjectProcessDetach (interpreter))); |
| 1790 | LoadSubCommand ("load", CommandObjectSP (new CommandObjectProcessLoad (interpreter))); |
| 1791 | LoadSubCommand ("unload", CommandObjectSP (new CommandObjectProcessUnload (interpreter))); |
| 1792 | LoadSubCommand ("signal", CommandObjectSP (new CommandObjectProcessSignal (interpreter))); |
| 1793 | LoadSubCommand ("handle", CommandObjectSP (new CommandObjectProcessHandle (interpreter))); |
| 1794 | LoadSubCommand ("status", CommandObjectSP (new CommandObjectProcessStatus (interpreter))); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1795 | LoadSubCommand ("interrupt", CommandObjectSP (new CommandObjectProcessInterrupt (interpreter))); |
Greg Clayton | a9eb827 | 2011-07-02 21:07:54 +0000 | [diff] [blame] | 1796 | LoadSubCommand ("kill", CommandObjectSP (new CommandObjectProcessKill (interpreter))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | CommandObjectMultiwordProcess::~CommandObjectMultiwordProcess () |
| 1800 | { |
| 1801 | } |
| 1802 | |