blob: ec7b478fbecc48a2b5caee53d6cf821ca39cdca2 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "CommandObjectProcess.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
Jim Ingham0e410842012-08-11 01:27:55 +000018#include "lldb/Breakpoint/Breakpoint.h"
19#include "lldb/Breakpoint/BreakpointLocation.h"
20#include "lldb/Breakpoint/BreakpointSite.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021#include "lldb/Core/State.h"
Greg Clayton1f746072012-08-29 21:13:06 +000022#include "lldb/Core/Module.h"
Greg Claytona2715cf2014-06-13 00:54:12 +000023#include "lldb/Core/PluginManager.h"
Greg Clayton7260f622011-04-18 08:33:37 +000024#include "lldb/Host/Host.h"
Jim Ingham0e410842012-08-11 01:27:55 +000025#include "lldb/Interpreter/Args.h"
26#include "lldb/Interpreter/Options.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Interpreter/CommandInterpreter.h"
28#include "lldb/Interpreter/CommandReturnObject.h"
Greg Claytone996fd32011-03-08 22:40:15 +000029#include "lldb/Target/Platform.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030#include "lldb/Target/Process.h"
Jim Ingham0e410842012-08-11 01:27:55 +000031#include "lldb/Target/StopInfo.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Target/Target.h"
33#include "lldb/Target/Thread.h"
34
35using namespace lldb;
36using namespace lldb_private;
37
Jim Inghamdcb1d852013-03-29 00:56:30 +000038class CommandObjectProcessLaunchOrAttach : public CommandObjectParsed
39{
40public:
41 CommandObjectProcessLaunchOrAttach (CommandInterpreter &interpreter,
42 const char *name,
43 const char *help,
44 const char *syntax,
45 uint32_t flags,
46 const char *new_process_action) :
47 CommandObjectParsed (interpreter, name, help, syntax, flags),
48 m_new_process_action (new_process_action) {}
49
50 virtual ~CommandObjectProcessLaunchOrAttach () {}
51protected:
52 bool
Greg Claytonb09c5382013-12-13 17:20:18 +000053 StopProcessIfNecessary (Process *process, StateType &state, CommandReturnObject &result)
Jim Inghamdcb1d852013-03-29 00:56:30 +000054 {
55 state = eStateInvalid;
56 if (process)
57 {
58 state = process->GetState();
59
60 if (process->IsAlive() && state != eStateConnected)
61 {
62 char message[1024];
63 if (process->GetState() == eStateAttaching)
64 ::snprintf (message, sizeof(message), "There is a pending attach, abort it and %s?", m_new_process_action.c_str());
65 else if (process->GetShouldDetach())
66 ::snprintf (message, sizeof(message), "There is a running process, detach from it and %s?", m_new_process_action.c_str());
67 else
68 ::snprintf (message, sizeof(message), "There is a running process, kill it and %s?", m_new_process_action.c_str());
69
70 if (!m_interpreter.Confirm (message, true))
71 {
72 result.SetStatus (eReturnStatusFailed);
73 return false;
74 }
75 else
76 {
77 if (process->GetShouldDetach())
78 {
Jim Inghamacff8952013-05-02 00:27:30 +000079 bool keep_stopped = false;
80 Error detach_error (process->Detach(keep_stopped));
Jim Inghamdcb1d852013-03-29 00:56:30 +000081 if (detach_error.Success())
82 {
83 result.SetStatus (eReturnStatusSuccessFinishResult);
84 process = NULL;
85 }
86 else
87 {
88 result.AppendErrorWithFormat ("Failed to detach from process: %s\n", detach_error.AsCString());
89 result.SetStatus (eReturnStatusFailed);
90 }
91 }
92 else
93 {
94 Error destroy_error (process->Destroy());
95 if (destroy_error.Success())
96 {
97 result.SetStatus (eReturnStatusSuccessFinishResult);
98 process = NULL;
99 }
100 else
101 {
102 result.AppendErrorWithFormat ("Failed to kill process: %s\n", destroy_error.AsCString());
103 result.SetStatus (eReturnStatusFailed);
104 }
105 }
106 }
107 }
108 }
109 return result.Succeeded();
110 }
111 std::string m_new_process_action;
112};
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000113//-------------------------------------------------------------------------
114// CommandObjectProcessLaunch
115//-------------------------------------------------------------------------
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000116#pragma mark CommandObjectProcessLaunch
Jim Inghamdcb1d852013-03-29 00:56:30 +0000117class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118{
119public:
120
Greg Claytona7015092010-09-18 01:14:36 +0000121 CommandObjectProcessLaunch (CommandInterpreter &interpreter) :
Jim Inghamdcb1d852013-03-29 00:56:30 +0000122 CommandObjectProcessLaunchOrAttach (interpreter,
123 "process launch",
124 "Launch the executable in the debugger.",
125 NULL,
126 eFlagRequiresTarget,
127 "restart"),
Greg Claytoneb0103f2011-04-07 22:46:35 +0000128 m_options (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129 {
Caroline Tice405fe672010-10-04 22:28:36 +0000130 CommandArgumentEntry arg;
131 CommandArgumentData run_args_arg;
132
133 // Define the first (and only) variant of this arg.
134 run_args_arg.arg_type = eArgTypeRunArgs;
135 run_args_arg.arg_repetition = eArgRepeatOptional;
136
137 // There is only one variant this argument could be; put it into the argument entry.
138 arg.push_back (run_args_arg);
139
140 // Push the data for the first argument into the m_arguments vector.
141 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000142 }
143
144
145 ~CommandObjectProcessLaunch ()
146 {
147 }
148
Greg Claytonc7bece562013-01-25 18:06:21 +0000149 virtual int
Jim Inghame9ce62b2012-08-10 21:48:41 +0000150 HandleArgumentCompletion (Args &input,
151 int &cursor_index,
152 int &cursor_char_position,
153 OptionElementVector &opt_element_vector,
154 int match_start_point,
155 int max_return_elements,
156 bool &word_complete,
157 StringList &matches)
158 {
159 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
160 completion_str.erase (cursor_char_position);
161
162 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
163 CommandCompletions::eDiskFileCompletion,
164 completion_str.c_str(),
165 match_start_point,
166 max_return_elements,
167 NULL,
168 word_complete,
169 matches);
170 return matches.GetSize();
171 }
172
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000173 Options *
174 GetOptions ()
175 {
176 return &m_options;
177 }
178
Jim Ingham5a988412012-06-08 21:56:10 +0000179 virtual const char *GetRepeatCommand (Args &current_command_args, uint32_t index)
180 {
181 // No repeat for "process launch"...
182 return "";
183 }
184
185protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000187 DoExecute (Args& launch_args, CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000188 {
Greg Clayton1d885962011-11-08 02:43:13 +0000189 Debugger &debugger = m_interpreter.GetDebugger();
190 Target *target = debugger.GetSelectedTarget().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191 // If our listener is NULL, users aren't allows to launch
Greg Claytonb09c5382013-12-13 17:20:18 +0000192 ModuleSP exe_module_sp = target->GetExecutableModule();
Greg Clayton71337622011-02-24 22:24:29 +0000193
Greg Claytonb09c5382013-12-13 17:20:18 +0000194 if (exe_module_sp == NULL)
Greg Clayton71337622011-02-24 22:24:29 +0000195 {
Greg Claytoneffe5c92011-05-03 22:09:39 +0000196 result.AppendError ("no file in target, create a debug target using the 'target create' command");
Greg Clayton71337622011-02-24 22:24:29 +0000197 result.SetStatus (eReturnStatusFailed);
198 return false;
199 }
200
Greg Clayton71337622011-02-24 22:24:29 +0000201 StateType state = eStateInvalid;
Greg Clayton71337622011-02-24 22:24:29 +0000202
Greg Claytonb09c5382013-12-13 17:20:18 +0000203 if (!StopProcessIfNecessary(m_exe_ctx.GetProcessPtr(), state, result))
Jim Inghamdcb1d852013-03-29 00:56:30 +0000204 return false;
Jim Inghambb9caf72010-12-09 18:58:16 +0000205
Greg Clayton45392552012-10-17 22:57:12 +0000206 const char *target_settings_argv0 = target->GetArg0();
207
Todd Fiala51637922014-08-19 17:40:43 +0000208 // Determine whether we will disable ASLR or leave it in the default state (i.e. enabled if the platform supports it).
209 // First check if the process launch options explicitly turn on/off disabling ASLR. If so, use that setting;
210 // otherwise, use the 'settings target.disable-aslr' setting.
211 bool disable_aslr = false;
212 if (m_options.disable_aslr != eLazyBoolCalculate)
213 {
214 // The user specified an explicit setting on the process launch line. Use it.
215 disable_aslr = (m_options.disable_aslr == eLazyBoolYes);
216 }
217 else
218 {
219 // The user did not explicitly specify whether to disable ASLR. Fall back to the target.disable-aslr setting.
220 disable_aslr = target->GetDisableASLR ();
221 }
222
223 if (disable_aslr)
Greg Claytonb09c5382013-12-13 17:20:18 +0000224 m_options.launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
Todd Fiala51637922014-08-19 17:40:43 +0000225 else
226 m_options.launch_info.GetFlags().Clear (eLaunchFlagDisableASLR);
Greg Clayton45392552012-10-17 22:57:12 +0000227
Jim Ingham106d0282014-06-25 02:32:56 +0000228 if (target->GetDetachOnError())
229 m_options.launch_info.GetFlags().Set (eLaunchFlagDetachOnError);
230
Greg Claytonb09c5382013-12-13 17:20:18 +0000231 if (target->GetDisableSTDIO())
232 m_options.launch_info.GetFlags().Set (eLaunchFlagDisableSTDIO);
233
234 Args environment;
235 target->GetEnvironmentAsArgs (environment);
236 if (environment.GetArgumentCount() > 0)
237 m_options.launch_info.GetEnvironmentEntries ().AppendArguments (environment);
238
Greg Clayton45392552012-10-17 22:57:12 +0000239 if (target_settings_argv0)
240 {
241 m_options.launch_info.GetArguments().AppendArgument (target_settings_argv0);
Greg Claytonb09c5382013-12-13 17:20:18 +0000242 m_options.launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), false);
Greg Clayton45392552012-10-17 22:57:12 +0000243 }
244 else
245 {
Greg Claytonb09c5382013-12-13 17:20:18 +0000246 m_options.launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), true);
Greg Clayton45392552012-10-17 22:57:12 +0000247 }
248
Greg Clayton144f3a92011-11-15 03:53:30 +0000249 if (launch_args.GetArgumentCount() == 0)
250 {
Greg Clayton67cc0632012-08-22 17:17:09 +0000251 Args target_setting_args;
Greg Clayton45392552012-10-17 22:57:12 +0000252 if (target->GetRunArguments(target_setting_args))
Greg Clayton67cc0632012-08-22 17:17:09 +0000253 m_options.launch_info.GetArguments().AppendArguments (target_setting_args);
Greg Clayton144f3a92011-11-15 03:53:30 +0000254 }
255 else
Greg Clayton1d885962011-11-08 02:43:13 +0000256 {
Greg Clayton45392552012-10-17 22:57:12 +0000257 m_options.launch_info.GetArguments().AppendArguments (launch_args);
Greg Clayton162b5972011-11-21 21:51:18 +0000258 // Save the arguments for subsequent runs in the current target.
259 target->SetRunArguments (launch_args);
Greg Clayton1d885962011-11-08 02:43:13 +0000260 }
Greg Claytondc6224e2014-10-21 01:00:42 +0000261
262 StreamString stream;
Greg Clayton8012cad2014-11-17 19:39:20 +0000263 Error error = target->Launch(m_options.launch_info, &stream);
Jim Inghamdcb1d852013-03-29 00:56:30 +0000264
Greg Claytona7015092010-09-18 01:14:36 +0000265 if (error.Success())
266 {
Greg Claytonb09c5382013-12-13 17:20:18 +0000267 const char *archname = exe_module_sp->GetArchitecture().GetArchitectureName();
268 ProcessSP process_sp (target->GetProcessSP());
269 if (process_sp)
Greg Claytona7015092010-09-18 01:14:36 +0000270 {
Stephane Sezerf2ef94e2014-12-13 05:23:51 +0000271 const char *data = stream.GetData();
272 if (data && strlen(data) > 0)
Greg Claytondc6224e2014-10-21 01:00:42 +0000273 result.AppendMessage(stream.GetData());
Greg Claytonb09c5382013-12-13 17:20:18 +0000274 result.AppendMessageWithFormat ("Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(), exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
275 result.SetStatus (eReturnStatusSuccessFinishResult);
276 result.SetDidChangeProcessState (true);
277 }
278 else
279 {
280 result.AppendError("no error returned from Target::Launch, and target has no process");
281 result.SetStatus (eReturnStatusFailed);
Greg Claytona7015092010-09-18 01:14:36 +0000282 }
283 }
Greg Clayton514487e2011-02-15 21:59:32 +0000284 else
285 {
Greg Claytonb09c5382013-12-13 17:20:18 +0000286 result.AppendError(error.AsCString());
Greg Clayton514487e2011-02-15 21:59:32 +0000287 result.SetStatus (eReturnStatusFailed);
288 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289 return result.Succeeded();
290 }
291
292protected:
Greg Clayton982c9762011-11-03 21:22:33 +0000293 ProcessLaunchCommandOptions m_options;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294};
295
296
Greg Clayton982c9762011-11-03 21:22:33 +0000297//#define SET1 LLDB_OPT_SET_1
298//#define SET2 LLDB_OPT_SET_2
299//#define SET3 LLDB_OPT_SET_3
300//
301//OptionDefinition
302//CommandObjectProcessLaunch::CommandOptions::g_option_table[] =
303//{
Virgile Belloe2607b52013-09-05 16:42:23 +0000304//{ SET1 | SET2 | SET3, false, "stop-at-entry", 's', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Stop at the entry point of the program when launching a process."},
305//{ SET1 , false, "stdin", 'i', OptionParser::eRequiredArgument, NULL, 0, eArgTypeDirectoryName, "Redirect stdin for the process to <path>."},
306//{ SET1 , false, "stdout", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeDirectoryName, "Redirect stdout for the process to <path>."},
307//{ SET1 , false, "stderr", 'e', OptionParser::eRequiredArgument, NULL, 0, eArgTypeDirectoryName, "Redirect stderr for the process to <path>."},
308//{ SET1 | SET2 | SET3, false, "plugin", 'p', OptionParser::eRequiredArgument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."},
309//{ SET2 , false, "tty", 't', OptionParser::eOptionalArgument, NULL, 0, eArgTypeDirectoryName, "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."},
310//{ SET3, false, "no-stdio", 'n', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Do not set up for terminal I/O to go to running process."},
311//{ SET1 | SET2 | SET3, false, "working-dir", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeDirectoryName, "Set the current working directory to <path> when running the inferior."},
Greg Clayton982c9762011-11-03 21:22:33 +0000312//{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
313//};
314//
315//#undef SET1
316//#undef SET2
317//#undef SET3
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000318
319//-------------------------------------------------------------------------
320// CommandObjectProcessAttach
321//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +0000322#pragma mark CommandObjectProcessAttach
Jim Inghamdcb1d852013-03-29 00:56:30 +0000323class CommandObjectProcessAttach : public CommandObjectProcessLaunchOrAttach
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000324{
325public:
326
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000327 class CommandOptions : public Options
328 {
329 public:
330
Greg Claytoneb0103f2011-04-07 22:46:35 +0000331 CommandOptions (CommandInterpreter &interpreter) :
332 Options(interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333 {
Greg Claytonf6b8b582011-04-13 00:18:08 +0000334 // Keep default values of all options in one place: OptionParsingStarting ()
335 OptionParsingStarting ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336 }
337
338 ~CommandOptions ()
339 {
340 }
341
342 Error
Greg Claytonf6b8b582011-04-13 00:18:08 +0000343 SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000344 {
345 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000346 const int short_option = m_getopt_table[option_idx].val;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347 bool success = false;
348 switch (short_option)
349 {
Johnny Chena95ce622012-05-24 00:43:00 +0000350 case 'c':
351 attach_info.SetContinueOnceAttached(true);
352 break;
353
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354 case 'p':
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355 {
Greg Clayton144f3a92011-11-15 03:53:30 +0000356 lldb::pid_t pid = Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success);
357 if (!success || pid == LLDB_INVALID_PROCESS_ID)
358 {
359 error.SetErrorStringWithFormat("invalid process ID '%s'", option_arg);
360 }
361 else
362 {
363 attach_info.SetProcessID (pid);
364 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000365 }
366 break;
367
368 case 'P':
Greg Clayton144f3a92011-11-15 03:53:30 +0000369 attach_info.SetProcessPluginName (option_arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000370 break;
371
372 case 'n':
Greg Clayton144f3a92011-11-15 03:53:30 +0000373 attach_info.GetExecutableFile().SetFile(option_arg, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374 break;
375
376 case 'w':
Greg Clayton144f3a92011-11-15 03:53:30 +0000377 attach_info.SetWaitForLaunch(true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000378 break;
Jim Inghamcd16df92012-07-20 21:37:13 +0000379
380 case 'i':
381 attach_info.SetIgnoreExisting(false);
382 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383
384 default:
Greg Clayton86edbf42011-10-26 00:56:27 +0000385 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000386 break;
387 }
388 return error;
389 }
390
391 void
Greg Claytonf6b8b582011-04-13 00:18:08 +0000392 OptionParsingStarting ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393 {
Greg Clayton144f3a92011-11-15 03:53:30 +0000394 attach_info.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000395 }
396
Greg Claytone0d378b2011-03-24 21:19:54 +0000397 const OptionDefinition*
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398 GetDefinitions ()
399 {
400 return g_option_table;
401 }
402
Jim Ingham5aee1622010-08-09 23:31:02 +0000403 virtual bool
Greg Claytoneb0103f2011-04-07 22:46:35 +0000404 HandleOptionArgumentCompletion (Args &input,
Jim Ingham5aee1622010-08-09 23:31:02 +0000405 int cursor_index,
406 int char_pos,
407 OptionElementVector &opt_element_vector,
408 int opt_element_index,
409 int match_start_point,
410 int max_return_elements,
411 bool &word_complete,
412 StringList &matches)
413 {
414 int opt_arg_pos = opt_element_vector[opt_element_index].opt_arg_pos;
415 int opt_defs_index = opt_element_vector[opt_element_index].opt_defs_index;
416
417 // We are only completing the name option for now...
418
Greg Claytone0d378b2011-03-24 21:19:54 +0000419 const OptionDefinition *opt_defs = GetDefinitions();
Jim Ingham5aee1622010-08-09 23:31:02 +0000420 if (opt_defs[opt_defs_index].short_option == 'n')
421 {
422 // Are we in the name?
423
424 // Look to see if there is a -P argument provided, and if so use that plugin, otherwise
425 // use the default plugin.
Jim Ingham5aee1622010-08-09 23:31:02 +0000426
427 const char *partial_name = NULL;
428 partial_name = input.GetArgumentAtIndex(opt_arg_pos);
Greg Claytone996fd32011-03-08 22:40:15 +0000429
Greg Clayton8b82f082011-04-12 05:54:46 +0000430 PlatformSP platform_sp (m_interpreter.GetPlatform (true));
Greg Claytone996fd32011-03-08 22:40:15 +0000431 if (platform_sp)
Jim Ingham5aee1622010-08-09 23:31:02 +0000432 {
Greg Clayton8b82f082011-04-12 05:54:46 +0000433 ProcessInstanceInfoList process_infos;
434 ProcessInstanceInfoMatch match_info;
Greg Clayton32e0a752011-03-30 18:16:51 +0000435 if (partial_name)
436 {
Greg Clayton144f3a92011-11-15 03:53:30 +0000437 match_info.GetProcessInfo().GetExecutableFile().SetFile(partial_name, false);
Greg Clayton32e0a752011-03-30 18:16:51 +0000438 match_info.SetNameMatchType(eNameMatchStartsWith);
439 }
440 platform_sp->FindProcesses (match_info, process_infos);
Greg Claytonc7bece562013-01-25 18:06:21 +0000441 const size_t num_matches = process_infos.GetSize();
Greg Claytone996fd32011-03-08 22:40:15 +0000442 if (num_matches > 0)
443 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000444 for (size_t i=0; i<num_matches; ++i)
Greg Claytone996fd32011-03-08 22:40:15 +0000445 {
446 matches.AppendString (process_infos.GetProcessNameAtIndex(i),
447 process_infos.GetProcessNameLengthAtIndex(i));
448 }
449 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000450 }
451 }
452
453 return false;
454 }
455
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000456 // Options table: Required for subclasses of Options.
457
Greg Claytone0d378b2011-03-24 21:19:54 +0000458 static OptionDefinition g_option_table[];
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000459
460 // Instance variables to hold the values for command options.
461
Greg Clayton144f3a92011-11-15 03:53:30 +0000462 ProcessAttachInfo attach_info;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000463 };
464
Greg Claytona7015092010-09-18 01:14:36 +0000465 CommandObjectProcessAttach (CommandInterpreter &interpreter) :
Jim Inghamdcb1d852013-03-29 00:56:30 +0000466 CommandObjectProcessLaunchOrAttach (interpreter,
467 "process attach",
468 "Attach to a process.",
469 "process attach <cmd-options>",
470 0,
471 "attach"),
Greg Claytoneb0103f2011-04-07 22:46:35 +0000472 m_options (interpreter)
Jim Ingham5aee1622010-08-09 23:31:02 +0000473 {
Jim Ingham5aee1622010-08-09 23:31:02 +0000474 }
475
476 ~CommandObjectProcessAttach ()
477 {
478 }
479
Jim Ingham5a988412012-06-08 21:56:10 +0000480 Options *
481 GetOptions ()
482 {
483 return &m_options;
484 }
485
486protected:
Jim Ingham5aee1622010-08-09 23:31:02 +0000487 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000488 DoExecute (Args& command,
Jim Ingham5aee1622010-08-09 23:31:02 +0000489 CommandReturnObject &result)
490 {
Greg Claytona7015092010-09-18 01:14:36 +0000491 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Jim Ingham31412642011-09-15 01:08:57 +0000492 // N.B. The attach should be synchronous. It doesn't help much to get the prompt back between initiating the attach
493 // and the target actually stopping. So even if the interpreter is set to be asynchronous, we wait for the stop
494 // ourselves here.
Jim Inghambb3a2832011-01-29 01:49:25 +0000495
Greg Clayton71337622011-02-24 22:24:29 +0000496 StateType state = eStateInvalid;
Jim Inghamdcb1d852013-03-29 00:56:30 +0000497 Process *process = m_exe_ctx.GetProcessPtr();
498
499 if (!StopProcessIfNecessary (process, state, result))
500 return false;
501
Jim Ingham5aee1622010-08-09 23:31:02 +0000502 if (target == NULL)
503 {
504 // If there isn't a current target create one.
505 TargetSP new_target_sp;
Jim Ingham5aee1622010-08-09 23:31:02 +0000506 Error error;
507
Greg Claytona7015092010-09-18 01:14:36 +0000508 error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
Greg Claytona0ca6602012-10-18 16:33:33 +0000509 NULL,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000510 NULL,
Greg Claytona7015092010-09-18 01:14:36 +0000511 false,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000512 NULL, // No platform options
Greg Claytona7015092010-09-18 01:14:36 +0000513 new_target_sp);
Jim Ingham5aee1622010-08-09 23:31:02 +0000514 target = new_target_sp.get();
515 if (target == NULL || error.Fail())
516 {
Greg Claytonb766a732011-02-04 01:58:07 +0000517 result.AppendError(error.AsCString("Error creating target"));
Jim Ingham5aee1622010-08-09 23:31:02 +0000518 return false;
519 }
Greg Claytona7015092010-09-18 01:14:36 +0000520 m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target);
Jim Ingham5aee1622010-08-09 23:31:02 +0000521 }
522
523 // Record the old executable module, we want to issue a warning if the process of attaching changed the
524 // current executable (like somebody said "file foo" then attached to a PID whose executable was bar.)
525
526 ModuleSP old_exec_module_sp = target->GetExecutableModule();
527 ArchSpec old_arch_spec = target->GetArchitecture();
528
529 if (command.GetArgumentCount())
530 {
Jason Molendafd54b362011-09-20 21:44:10 +0000531 result.AppendErrorWithFormat("Invalid arguments for '%s'.\nUsage: %s\n", m_cmd_name.c_str(), m_cmd_syntax.c_str());
Jim Ingham5aee1622010-08-09 23:31:02 +0000532 result.SetStatus (eReturnStatusFailed);
533 }
534 else
535 {
Greg Clayton71337622011-02-24 22:24:29 +0000536 if (state != eStateConnected)
537 {
Greg Clayton144f3a92011-11-15 03:53:30 +0000538 const char *plugin_name = m_options.attach_info.GetProcessPluginName();
Greg Claytonc3776bf2012-02-09 06:16:32 +0000539 process = target->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name, NULL).get();
Greg Clayton71337622011-02-24 22:24:29 +0000540 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000541
542 if (process)
543 {
544 Error error;
Greg Clayton144f3a92011-11-15 03:53:30 +0000545 // If no process info was specified, then use the target executable
546 // name as the process to attach to by default
547 if (!m_options.attach_info.ProcessInfoSpecified ())
Jim Ingham3a0b9cd2010-09-15 01:34:14 +0000548 {
549 if (old_exec_module_sp)
Greg Claytonad9e8282011-11-29 04:03:30 +0000550 m_options.attach_info.GetExecutableFile().GetFilename() = old_exec_module_sp->GetPlatformFileSpec().GetFilename();
Jim Ingham3a0b9cd2010-09-15 01:34:14 +0000551
Greg Clayton144f3a92011-11-15 03:53:30 +0000552 if (!m_options.attach_info.ProcessInfoSpecified ())
553 {
554 error.SetErrorString ("no process specified, create a target with a file, or specify the --pid or --name command option");
555 }
556 }
557
558 if (error.Success())
559 {
Greg Clayton06357c92014-07-30 17:38:47 +0000560 // Update the execution context so the current target and process are now selected
561 // in case we interrupt
562 m_interpreter.UpdateExecutionContext(NULL);
Greg Clayton44d93782014-01-27 23:43:24 +0000563 ListenerSP listener_sp (new Listener("lldb.CommandObjectProcessAttach.DoExecute.attach.hijack"));
564 m_options.attach_info.SetHijackListener(listener_sp);
565 process->HijackProcessEvents(listener_sp.get());
Greg Clayton144f3a92011-11-15 03:53:30 +0000566 error = process->Attach (m_options.attach_info);
567
Jim Ingham3a0b9cd2010-09-15 01:34:14 +0000568 if (error.Success())
569 {
570 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
Greg Claytondc6224e2014-10-21 01:00:42 +0000571 StreamString stream;
572 StateType state = process->WaitForProcessToStop (NULL, NULL, false, listener_sp.get(), &stream);
Greg Clayton44d93782014-01-27 23:43:24 +0000573
574 process->RestoreProcessEvents();
575
576 result.SetDidChangeProcessState (true);
577
Greg Claytondc6224e2014-10-21 01:00:42 +0000578 if (stream.GetData())
579 result.AppendMessage(stream.GetData());
580
Greg Clayton44d93782014-01-27 23:43:24 +0000581 if (state == eStateStopped)
582 {
Greg Clayton44d93782014-01-27 23:43:24 +0000583 result.SetStatus (eReturnStatusSuccessFinishNoResult);
584 }
585 else
586 {
Greg Clayton06357c92014-07-30 17:38:47 +0000587 const char *exit_desc = process->GetExitDescription();
588 if (exit_desc)
589 result.AppendErrorWithFormat ("attach failed: %s", exit_desc);
590 else
591 result.AppendError ("attach failed: process did not stop (no such process or permission problem?)");
Greg Clayton44d93782014-01-27 23:43:24 +0000592 process->Destroy();
593 result.SetStatus (eReturnStatusFailed);
594 }
Jim Ingham3a0b9cd2010-09-15 01:34:14 +0000595 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000596 else
597 {
Greg Clayton144f3a92011-11-15 03:53:30 +0000598 result.AppendErrorWithFormat ("attach failed: %s\n", error.AsCString());
Jim Ingham3a0b9cd2010-09-15 01:34:14 +0000599 result.SetStatus (eReturnStatusFailed);
Johnny Chenaa739092012-05-18 00:51:36 +0000600 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000601 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000602 }
603 }
604
605 if (result.Succeeded())
606 {
607 // Okay, we're done. Last step is to warn if the executable module has changed:
Greg Clayton513c26c2011-01-29 07:10:55 +0000608 char new_path[PATH_MAX];
Greg Claytonaa149cb2011-08-11 02:48:45 +0000609 ModuleSP new_exec_module_sp (target->GetExecutableModule());
Jim Ingham5aee1622010-08-09 23:31:02 +0000610 if (!old_exec_module_sp)
611 {
Greg Clayton513c26c2011-01-29 07:10:55 +0000612 // We might not have a module if we attached to a raw pid...
Greg Claytonaa149cb2011-08-11 02:48:45 +0000613 if (new_exec_module_sp)
Greg Clayton513c26c2011-01-29 07:10:55 +0000614 {
Greg Claytonaa149cb2011-08-11 02:48:45 +0000615 new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
Greg Clayton513c26c2011-01-29 07:10:55 +0000616 result.AppendMessageWithFormat("Executable module set to \"%s\".\n", new_path);
617 }
Jim Ingham5aee1622010-08-09 23:31:02 +0000618 }
Greg Claytonaa149cb2011-08-11 02:48:45 +0000619 else if (old_exec_module_sp->GetFileSpec() != new_exec_module_sp->GetFileSpec())
Jim Ingham5aee1622010-08-09 23:31:02 +0000620 {
Greg Clayton513c26c2011-01-29 07:10:55 +0000621 char old_path[PATH_MAX];
Jim Ingham5aee1622010-08-09 23:31:02 +0000622
Greg Claytonaa149cb2011-08-11 02:48:45 +0000623 old_exec_module_sp->GetFileSpec().GetPath (old_path, PATH_MAX);
624 new_exec_module_sp->GetFileSpec().GetPath (new_path, PATH_MAX);
Jim Ingham5aee1622010-08-09 23:31:02 +0000625
626 result.AppendWarningWithFormat("Executable module changed from \"%s\" to \"%s\".\n",
627 old_path, new_path);
628 }
629
630 if (!old_arch_spec.IsValid())
631 {
Greg Claytonc1b1f1e2012-09-14 02:41:36 +0000632 result.AppendMessageWithFormat ("Architecture set to: %s.\n", target->GetArchitecture().GetTriple().getTriple().c_str());
Jim Ingham5aee1622010-08-09 23:31:02 +0000633 }
Sean Callananbf4b7be2012-12-13 22:07:14 +0000634 else if (!old_arch_spec.IsExactMatch(target->GetArchitecture()))
Jim Ingham5aee1622010-08-09 23:31:02 +0000635 {
636 result.AppendWarningWithFormat("Architecture changed from %s to %s.\n",
Greg Claytonc1b1f1e2012-09-14 02:41:36 +0000637 old_arch_spec.GetTriple().getTriple().c_str(),
638 target->GetArchitecture().GetTriple().getTriple().c_str());
Jim Ingham5aee1622010-08-09 23:31:02 +0000639 }
Johnny Chena95ce622012-05-24 00:43:00 +0000640
641 // This supports the use-case scenario of immediately continuing the process once attached.
642 if (m_options.attach_info.GetContinueOnceAttached())
Sean Callanan5bcaf582012-05-31 01:30:08 +0000643 m_interpreter.HandleCommand("process continue", eLazyBoolNo, result);
Jim Ingham5aee1622010-08-09 23:31:02 +0000644 }
645 return result.Succeeded();
646 }
647
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000648 CommandOptions m_options;
649};
650
651
Greg Claytone0d378b2011-03-24 21:19:54 +0000652OptionDefinition
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653CommandObjectProcessAttach::CommandOptions::g_option_table[] =
654{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000655{ LLDB_OPT_SET_ALL, false, "continue",'c', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Immediately continue the process once attached."},
656{ LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."},
657{ LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePid, "The process ID of an existing process to attach to."},
658{ LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeProcessName, "The name of the process to attach to."},
659{ LLDB_OPT_SET_2, false, "include-existing", 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Include existing processes when doing attach -w."},
660{ LLDB_OPT_SET_2, false, "waitfor", 'w', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Wait for the process with <process-name> to launch."},
661{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000662};
663
664//-------------------------------------------------------------------------
665// CommandObjectProcessContinue
666//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +0000667#pragma mark CommandObjectProcessContinue
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668
Jim Ingham5a988412012-06-08 21:56:10 +0000669class CommandObjectProcessContinue : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670{
671public:
672
Greg Claytona7015092010-09-18 01:14:36 +0000673 CommandObjectProcessContinue (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000674 CommandObjectParsed (interpreter,
675 "process continue",
676 "Continue execution of all threads in the current process.",
677 "process continue",
Greg Claytonf9fc6092013-01-09 19:44:40 +0000678 eFlagRequiresProcess |
679 eFlagTryTargetAPILock |
680 eFlagProcessMustBeLaunched |
681 eFlagProcessMustBePaused ),
Jim Ingham0e410842012-08-11 01:27:55 +0000682 m_options(interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683 {
684 }
685
686
687 ~CommandObjectProcessContinue ()
688 {
689 }
690
Jim Ingham5a988412012-06-08 21:56:10 +0000691protected:
Jim Ingham0e410842012-08-11 01:27:55 +0000692
693 class CommandOptions : public Options
694 {
695 public:
696
697 CommandOptions (CommandInterpreter &interpreter) :
698 Options(interpreter)
699 {
700 // Keep default values of all options in one place: OptionParsingStarting ()
701 OptionParsingStarting ();
702 }
703
704 ~CommandOptions ()
705 {
706 }
707
708 Error
709 SetOptionValue (uint32_t option_idx, const char *option_arg)
710 {
711 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000712 const int short_option = m_getopt_table[option_idx].val;
Jim Ingham0e410842012-08-11 01:27:55 +0000713 bool success = false;
714 switch (short_option)
715 {
716 case 'i':
717 m_ignore = Args::StringToUInt32 (option_arg, 0, 0, &success);
718 if (!success)
719 error.SetErrorStringWithFormat ("invalid value for ignore option: \"%s\", should be a number.", option_arg);
720 break;
721
722 default:
723 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
724 break;
725 }
726 return error;
727 }
728
729 void
730 OptionParsingStarting ()
731 {
732 m_ignore = 0;
733 }
734
735 const OptionDefinition*
736 GetDefinitions ()
737 {
738 return g_option_table;
739 }
740
741 // Options table: Required for subclasses of Options.
742
743 static OptionDefinition g_option_table[];
744
745 uint32_t m_ignore;
746 };
747
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000748 bool
Greg Claytonf9fc6092013-01-09 19:44:40 +0000749 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000751 Process *process = m_exe_ctx.GetProcessPtr();
Greg Claytona7015092010-09-18 01:14:36 +0000752 bool synchronous_execution = m_interpreter.GetSynchronous ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000753 StateType state = process->GetState();
754 if (state == eStateStopped)
755 {
756 if (command.GetArgumentCount() != 0)
757 {
758 result.AppendErrorWithFormat ("The '%s' command does not take any arguments.\n", m_cmd_name.c_str());
759 result.SetStatus (eReturnStatusFailed);
760 return false;
761 }
762
Jim Ingham0e410842012-08-11 01:27:55 +0000763 if (m_options.m_ignore > 0)
764 {
765 ThreadSP sel_thread_sp(process->GetThreadList().GetSelectedThread());
766 if (sel_thread_sp)
767 {
768 StopInfoSP stop_info_sp = sel_thread_sp->GetStopInfo();
769 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonBreakpoint)
770 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000771 lldb::break_id_t bp_site_id = (lldb::break_id_t)stop_info_sp->GetValue();
Jim Ingham0e410842012-08-11 01:27:55 +0000772 BreakpointSiteSP bp_site_sp(process->GetBreakpointSiteList().FindByID(bp_site_id));
773 if (bp_site_sp)
774 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000775 const size_t num_owners = bp_site_sp->GetNumberOfOwners();
776 for (size_t i = 0; i < num_owners; i++)
Jim Ingham0e410842012-08-11 01:27:55 +0000777 {
778 Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
779 if (!bp_ref.IsInternal())
780 {
781 bp_ref.SetIgnoreCount(m_options.m_ignore);
782 }
783 }
784 }
785 }
786 }
787 }
788
Jim Ingham41f2b942012-09-10 20:50:15 +0000789 { // Scope for thread list mutex:
790 Mutex::Locker locker (process->GetThreadList().GetMutex());
791 const uint32_t num_threads = process->GetThreadList().GetSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000792
Jim Ingham41f2b942012-09-10 20:50:15 +0000793 // Set the actions that the threads should each take when resuming
794 for (uint32_t idx=0; idx<num_threads; ++idx)
795 {
Jim Ingham6c9ed912014-04-03 01:26:14 +0000796 const bool override_suspend = false;
797 process->GetThreadList().GetThreadAtIndex(idx)->SetResumeState (eStateRunning, override_suspend);
Jim Ingham41f2b942012-09-10 20:50:15 +0000798 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799 }
Todd Fialaa3b89e22014-08-12 14:33:19 +0000800
Greg Claytondc6224e2014-10-21 01:00:42 +0000801 StreamString stream;
802 Error error;
803 if (synchronous_execution)
804 error = process->ResumeSynchronous (&stream);
805 else
806 error = process->Resume ();
Todd Fialaa3b89e22014-08-12 14:33:19 +0000807
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000808 if (error.Success())
809 {
Todd Fialaa3b89e22014-08-12 14:33:19 +0000810 // There is a race condition where this thread will return up the call stack to the main command
811 // handler and show an (lldb) prompt before HandlePrivateEvent (from PrivateStateThread) has
812 // a chance to call PushProcessIOHandler().
813 process->SyncIOHandler(2000);
814
Daniel Malead01b2952012-11-29 21:49:15 +0000815 result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816 if (synchronous_execution)
817 {
Greg Claytondc6224e2014-10-21 01:00:42 +0000818 // If any state changed events had anything to say, add that to the result
819 if (stream.GetData())
820 result.AppendMessage(stream.GetData());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821
822 result.SetDidChangeProcessState (true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000823 result.SetStatus (eReturnStatusSuccessFinishNoResult);
824 }
825 else
826 {
827 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
828 }
829 }
830 else
831 {
832 result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString());
833 result.SetStatus (eReturnStatusFailed);
834 }
835 }
836 else
837 {
838 result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n",
839 StateAsCString(state));
840 result.SetStatus (eReturnStatusFailed);
841 }
842 return result.Succeeded();
843 }
Jim Ingham0e410842012-08-11 01:27:55 +0000844
845 Options *
846 GetOptions ()
847 {
848 return &m_options;
849 }
850
851 CommandOptions m_options;
852
853};
854
855OptionDefinition
856CommandObjectProcessContinue::CommandOptions::g_option_table[] =
857{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000858{ LLDB_OPT_SET_ALL, false, "ignore-count",'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeUnsignedInteger,
Jim Ingham0e410842012-08-11 01:27:55 +0000859 "Ignore <N> crossings of the breakpoint (if it exists) for the currently selected thread."},
Zachary Turnerd37221d2014-07-09 16:31:49 +0000860{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000861};
862
863//-------------------------------------------------------------------------
864// CommandObjectProcessDetach
865//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +0000866#pragma mark CommandObjectProcessDetach
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000867
Jim Ingham5a988412012-06-08 21:56:10 +0000868class CommandObjectProcessDetach : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000869{
870public:
Jim Inghamacff8952013-05-02 00:27:30 +0000871 class CommandOptions : public Options
872 {
873 public:
874
875 CommandOptions (CommandInterpreter &interpreter) :
876 Options (interpreter)
877 {
878 OptionParsingStarting ();
879 }
880
881 ~CommandOptions ()
882 {
883 }
884
885 Error
886 SetOptionValue (uint32_t option_idx, const char *option_arg)
887 {
888 Error error;
889 const int short_option = m_getopt_table[option_idx].val;
890
891 switch (short_option)
892 {
893 case 's':
894 bool tmp_result;
895 bool success;
896 tmp_result = Args::StringToBoolean(option_arg, false, &success);
897 if (!success)
898 error.SetErrorStringWithFormat("invalid boolean option: \"%s\"", option_arg);
899 else
900 {
901 if (tmp_result)
902 m_keep_stopped = eLazyBoolYes;
903 else
904 m_keep_stopped = eLazyBoolNo;
905 }
906 break;
907 default:
908 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
909 break;
910 }
911 return error;
912 }
913
914 void
915 OptionParsingStarting ()
916 {
917 m_keep_stopped = eLazyBoolCalculate;
918 }
919
920 const OptionDefinition*
921 GetDefinitions ()
922 {
923 return g_option_table;
924 }
925
926 // Options table: Required for subclasses of Options.
927
928 static OptionDefinition g_option_table[];
929
930 // Instance variables to hold the values for command options.
931 LazyBool m_keep_stopped;
932 };
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000933
Greg Claytona7015092010-09-18 01:14:36 +0000934 CommandObjectProcessDetach (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000935 CommandObjectParsed (interpreter,
936 "process detach",
937 "Detach from the current process being debugged.",
938 "process detach",
Greg Claytonf9fc6092013-01-09 19:44:40 +0000939 eFlagRequiresProcess |
940 eFlagTryTargetAPILock |
Jim Inghamacff8952013-05-02 00:27:30 +0000941 eFlagProcessMustBeLaunched),
942 m_options(interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000943 {
944 }
945
946 ~CommandObjectProcessDetach ()
947 {
948 }
949
Jim Inghamacff8952013-05-02 00:27:30 +0000950 Options *
951 GetOptions ()
952 {
953 return &m_options;
954 }
955
956
Jim Ingham5a988412012-06-08 21:56:10 +0000957protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000958 bool
Greg Claytonf9fc6092013-01-09 19:44:40 +0000959 DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000960 {
Greg Claytonf9fc6092013-01-09 19:44:40 +0000961 Process *process = m_exe_ctx.GetProcessPtr();
Jim Inghamacff8952013-05-02 00:27:30 +0000962 // FIXME: This will be a Command Option:
963 bool keep_stopped;
964 if (m_options.m_keep_stopped == eLazyBoolCalculate)
965 {
966 // Check the process default:
967 if (process->GetDetachKeepsStopped())
968 keep_stopped = true;
969 else
970 keep_stopped = false;
971 }
972 else if (m_options.m_keep_stopped == eLazyBoolYes)
973 keep_stopped = true;
974 else
975 keep_stopped = false;
976
977 Error error (process->Detach(keep_stopped));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000978 if (error.Success())
979 {
980 result.SetStatus (eReturnStatusSuccessFinishResult);
981 }
982 else
983 {
984 result.AppendErrorWithFormat ("Detach failed: %s\n", error.AsCString());
985 result.SetStatus (eReturnStatusFailed);
986 return false;
987 }
988 return result.Succeeded();
989 }
Jim Inghamacff8952013-05-02 00:27:30 +0000990
991 CommandOptions m_options;
992};
993
994OptionDefinition
995CommandObjectProcessDetach::CommandOptions::g_option_table[] =
996{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000997{ LLDB_OPT_SET_1, false, "keep-stopped", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Whether or not the process should be kept stopped on detach (if possible)." },
998{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000999};
1000
1001//-------------------------------------------------------------------------
Greg Claytonb766a732011-02-04 01:58:07 +00001002// CommandObjectProcessConnect
1003//-------------------------------------------------------------------------
1004#pragma mark CommandObjectProcessConnect
1005
Jim Ingham5a988412012-06-08 21:56:10 +00001006class CommandObjectProcessConnect : public CommandObjectParsed
Greg Claytonb766a732011-02-04 01:58:07 +00001007{
1008public:
1009
1010 class CommandOptions : public Options
1011 {
1012 public:
1013
Greg Claytoneb0103f2011-04-07 22:46:35 +00001014 CommandOptions (CommandInterpreter &interpreter) :
1015 Options(interpreter)
Greg Claytonb766a732011-02-04 01:58:07 +00001016 {
Greg Claytonf6b8b582011-04-13 00:18:08 +00001017 // Keep default values of all options in one place: OptionParsingStarting ()
1018 OptionParsingStarting ();
Greg Claytonb766a732011-02-04 01:58:07 +00001019 }
1020
1021 ~CommandOptions ()
1022 {
1023 }
1024
1025 Error
Greg Claytonf6b8b582011-04-13 00:18:08 +00001026 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Claytonb766a732011-02-04 01:58:07 +00001027 {
1028 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001029 const int short_option = m_getopt_table[option_idx].val;
Greg Claytonb766a732011-02-04 01:58:07 +00001030
1031 switch (short_option)
1032 {
1033 case 'p':
1034 plugin_name.assign (option_arg);
1035 break;
1036
1037 default:
Greg Clayton86edbf42011-10-26 00:56:27 +00001038 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
Greg Claytonb766a732011-02-04 01:58:07 +00001039 break;
1040 }
1041 return error;
1042 }
1043
1044 void
Greg Claytonf6b8b582011-04-13 00:18:08 +00001045 OptionParsingStarting ()
Greg Claytonb766a732011-02-04 01:58:07 +00001046 {
Greg Claytonb766a732011-02-04 01:58:07 +00001047 plugin_name.clear();
1048 }
1049
Greg Claytone0d378b2011-03-24 21:19:54 +00001050 const OptionDefinition*
Greg Claytonb766a732011-02-04 01:58:07 +00001051 GetDefinitions ()
1052 {
1053 return g_option_table;
1054 }
1055
1056 // Options table: Required for subclasses of Options.
1057
Greg Claytone0d378b2011-03-24 21:19:54 +00001058 static OptionDefinition g_option_table[];
Greg Claytonb766a732011-02-04 01:58:07 +00001059
1060 // Instance variables to hold the values for command options.
1061
1062 std::string plugin_name;
1063 };
1064
1065 CommandObjectProcessConnect (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001066 CommandObjectParsed (interpreter,
1067 "process connect",
1068 "Connect to a remote debug service.",
1069 "process connect <remote-url>",
1070 0),
Greg Claytoneb0103f2011-04-07 22:46:35 +00001071 m_options (interpreter)
Greg Claytonb766a732011-02-04 01:58:07 +00001072 {
1073 }
1074
1075 ~CommandObjectProcessConnect ()
1076 {
1077 }
1078
1079
Jim Ingham5a988412012-06-08 21:56:10 +00001080 Options *
1081 GetOptions ()
1082 {
1083 return &m_options;
1084 }
1085
1086protected:
Greg Claytonb766a732011-02-04 01:58:07 +00001087 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001088 DoExecute (Args& command,
Greg Claytonb766a732011-02-04 01:58:07 +00001089 CommandReturnObject &result)
1090 {
1091
1092 TargetSP target_sp (m_interpreter.GetDebugger().GetSelectedTarget());
1093 Error error;
Greg Claytonf9fc6092013-01-09 19:44:40 +00001094 Process *process = m_exe_ctx.GetProcessPtr();
Greg Claytonb766a732011-02-04 01:58:07 +00001095 if (process)
1096 {
1097 if (process->IsAlive())
1098 {
Daniel Malead01b2952012-11-29 21:49:15 +00001099 result.AppendErrorWithFormat ("Process %" PRIu64 " is currently being debugged, kill the process before connecting.\n",
Greg Claytonb766a732011-02-04 01:58:07 +00001100 process->GetID());
1101 result.SetStatus (eReturnStatusFailed);
1102 return false;
1103 }
1104 }
1105
1106 if (!target_sp)
1107 {
1108 // If there isn't a current target create one.
Greg Claytonb766a732011-02-04 01:58:07 +00001109
1110 error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
Greg Claytona0ca6602012-10-18 16:33:33 +00001111 NULL,
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001112 NULL,
Greg Claytonb766a732011-02-04 01:58:07 +00001113 false,
Greg Claytoncac9c5f2011-09-24 00:52:29 +00001114 NULL, // No platform options
Greg Claytonb766a732011-02-04 01:58:07 +00001115 target_sp);
1116 if (!target_sp || error.Fail())
1117 {
1118 result.AppendError(error.AsCString("Error creating target"));
1119 result.SetStatus (eReturnStatusFailed);
1120 return false;
1121 }
1122 m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target_sp.get());
1123 }
1124
1125 if (command.GetArgumentCount() == 1)
1126 {
1127 const char *plugin_name = NULL;
1128 if (!m_options.plugin_name.empty())
1129 plugin_name = m_options.plugin_name.c_str();
1130
1131 const char *remote_url = command.GetArgumentAtIndex(0);
Greg Claytonc3776bf2012-02-09 06:16:32 +00001132 process = target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name, NULL).get();
Greg Claytonb766a732011-02-04 01:58:07 +00001133
1134 if (process)
1135 {
Greg Clayton44d93782014-01-27 23:43:24 +00001136 error = process->ConnectRemote (process->GetTarget().GetDebugger().GetOutputFile().get(), remote_url);
Greg Claytonb766a732011-02-04 01:58:07 +00001137
1138 if (error.Fail())
1139 {
1140 result.AppendError(error.AsCString("Remote connect failed"));
1141 result.SetStatus (eReturnStatusFailed);
Greg Clayton1517dd32012-03-31 00:10:30 +00001142 target_sp->DeleteCurrentProcess();
Greg Claytonb766a732011-02-04 01:58:07 +00001143 return false;
1144 }
1145 }
1146 else
1147 {
Jason Molendafd54b362011-09-20 21:44:10 +00001148 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",
Daniel Maleaf00b7512012-12-18 20:00:40 +00001149 remote_url);
Greg Claytonb766a732011-02-04 01:58:07 +00001150 result.SetStatus (eReturnStatusFailed);
1151 }
1152 }
1153 else
1154 {
Jason Molendafd54b362011-09-20 21:44:10 +00001155 result.AppendErrorWithFormat ("'%s' takes exactly one argument:\nUsage: %s\n",
Greg Claytonb766a732011-02-04 01:58:07 +00001156 m_cmd_name.c_str(),
1157 m_cmd_syntax.c_str());
1158 result.SetStatus (eReturnStatusFailed);
1159 }
1160 return result.Succeeded();
1161 }
Greg Claytonb766a732011-02-04 01:58:07 +00001162
1163 CommandOptions m_options;
1164};
1165
Greg Claytone0d378b2011-03-24 21:19:54 +00001166OptionDefinition
Greg Claytonb766a732011-02-04 01:58:07 +00001167CommandObjectProcessConnect::CommandOptions::g_option_table[] =
1168{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001169 { LLDB_OPT_SET_ALL, false, "plugin", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."},
1170 { 0, false, NULL, 0 , 0, NULL, NULL, 0, eArgTypeNone, NULL }
Greg Claytonb766a732011-02-04 01:58:07 +00001171};
1172
1173//-------------------------------------------------------------------------
Greg Clayton998255b2012-10-13 02:07:45 +00001174// CommandObjectProcessPlugin
1175//-------------------------------------------------------------------------
1176#pragma mark CommandObjectProcessPlugin
1177
1178class CommandObjectProcessPlugin : public CommandObjectProxy
1179{
1180public:
1181
1182 CommandObjectProcessPlugin (CommandInterpreter &interpreter) :
1183 CommandObjectProxy (interpreter,
1184 "process plugin",
1185 "Send a custom command to the current process plug-in.",
1186 "process plugin <args>",
1187 0)
1188 {
1189 }
1190
1191 ~CommandObjectProcessPlugin ()
1192 {
1193 }
1194
1195 virtual CommandObject *
1196 GetProxyCommandObject()
1197 {
Greg Claytone05b2ef2013-01-09 22:58:18 +00001198 Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
Greg Clayton998255b2012-10-13 02:07:45 +00001199 if (process)
1200 return process->GetPluginCommandObject();
1201 return NULL;
1202 }
1203};
1204
1205
1206//-------------------------------------------------------------------------
Greg Clayton8f343b02010-11-04 01:54:29 +00001207// CommandObjectProcessLoad
1208//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +00001209#pragma mark CommandObjectProcessLoad
Greg Clayton8f343b02010-11-04 01:54:29 +00001210
Jim Ingham5a988412012-06-08 21:56:10 +00001211class CommandObjectProcessLoad : public CommandObjectParsed
Greg Clayton8f343b02010-11-04 01:54:29 +00001212{
1213public:
1214
1215 CommandObjectProcessLoad (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001216 CommandObjectParsed (interpreter,
1217 "process load",
1218 "Load a shared library into the current process.",
1219 "process load <filename> [<filename> ...]",
Greg Claytonf9fc6092013-01-09 19:44:40 +00001220 eFlagRequiresProcess |
1221 eFlagTryTargetAPILock |
1222 eFlagProcessMustBeLaunched |
1223 eFlagProcessMustBePaused )
Greg Clayton8f343b02010-11-04 01:54:29 +00001224 {
1225 }
1226
1227 ~CommandObjectProcessLoad ()
1228 {
1229 }
1230
Jim Ingham5a988412012-06-08 21:56:10 +00001231protected:
Greg Clayton8f343b02010-11-04 01:54:29 +00001232 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001233 DoExecute (Args& command,
Greg Clayton8f343b02010-11-04 01:54:29 +00001234 CommandReturnObject &result)
1235 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00001236 Process *process = m_exe_ctx.GetProcessPtr();
Greg Clayton8f343b02010-11-04 01:54:29 +00001237
Greg Claytonc7bece562013-01-25 18:06:21 +00001238 const size_t argc = command.GetArgumentCount();
Greg Clayton8f343b02010-11-04 01:54:29 +00001239
1240 for (uint32_t i=0; i<argc; ++i)
1241 {
1242 Error error;
1243 const char *image_path = command.GetArgumentAtIndex(i);
1244 FileSpec image_spec (image_path, false);
Greg Claytonaa516842011-08-11 16:25:18 +00001245 process->GetTarget().GetPlatform()->ResolveRemotePath(image_spec, image_spec);
Greg Clayton8f343b02010-11-04 01:54:29 +00001246 uint32_t image_token = process->LoadImage(image_spec, error);
1247 if (image_token != LLDB_INVALID_IMAGE_TOKEN)
1248 {
1249 result.AppendMessageWithFormat ("Loading \"%s\"...ok\nImage %u loaded.\n", image_path, image_token);
1250 result.SetStatus (eReturnStatusSuccessFinishResult);
1251 }
1252 else
1253 {
1254 result.AppendErrorWithFormat ("failed to load '%s': %s", image_path, error.AsCString());
1255 result.SetStatus (eReturnStatusFailed);
1256 }
1257 }
1258 return result.Succeeded();
1259 }
1260};
1261
1262
1263//-------------------------------------------------------------------------
1264// CommandObjectProcessUnload
1265//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +00001266#pragma mark CommandObjectProcessUnload
Greg Clayton8f343b02010-11-04 01:54:29 +00001267
Jim Ingham5a988412012-06-08 21:56:10 +00001268class CommandObjectProcessUnload : public CommandObjectParsed
Greg Clayton8f343b02010-11-04 01:54:29 +00001269{
1270public:
1271
1272 CommandObjectProcessUnload (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001273 CommandObjectParsed (interpreter,
1274 "process unload",
1275 "Unload a shared library from the current process using the index returned by a previous call to \"process load\".",
1276 "process unload <index>",
Greg Claytonf9fc6092013-01-09 19:44:40 +00001277 eFlagRequiresProcess |
1278 eFlagTryTargetAPILock |
1279 eFlagProcessMustBeLaunched |
1280 eFlagProcessMustBePaused )
Greg Clayton8f343b02010-11-04 01:54:29 +00001281 {
1282 }
1283
1284 ~CommandObjectProcessUnload ()
1285 {
1286 }
1287
Jim Ingham5a988412012-06-08 21:56:10 +00001288protected:
Greg Clayton8f343b02010-11-04 01:54:29 +00001289 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001290 DoExecute (Args& command,
Greg Clayton8f343b02010-11-04 01:54:29 +00001291 CommandReturnObject &result)
1292 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00001293 Process *process = m_exe_ctx.GetProcessPtr();
Greg Clayton8f343b02010-11-04 01:54:29 +00001294
Greg Claytonc7bece562013-01-25 18:06:21 +00001295 const size_t argc = command.GetArgumentCount();
Greg Clayton8f343b02010-11-04 01:54:29 +00001296
1297 for (uint32_t i=0; i<argc; ++i)
1298 {
1299 const char *image_token_cstr = command.GetArgumentAtIndex(i);
1300 uint32_t image_token = Args::StringToUInt32(image_token_cstr, LLDB_INVALID_IMAGE_TOKEN, 0);
1301 if (image_token == LLDB_INVALID_IMAGE_TOKEN)
1302 {
1303 result.AppendErrorWithFormat ("invalid image index argument '%s'", image_token_cstr);
1304 result.SetStatus (eReturnStatusFailed);
1305 break;
1306 }
1307 else
1308 {
1309 Error error (process->UnloadImage(image_token));
1310 if (error.Success())
1311 {
1312 result.AppendMessageWithFormat ("Unloading shared library with index %u...ok\n", image_token);
1313 result.SetStatus (eReturnStatusSuccessFinishResult);
1314 }
1315 else
1316 {
1317 result.AppendErrorWithFormat ("failed to unload image: %s", error.AsCString());
1318 result.SetStatus (eReturnStatusFailed);
1319 break;
1320 }
1321 }
1322 }
1323 return result.Succeeded();
1324 }
1325};
1326
1327//-------------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001328// CommandObjectProcessSignal
1329//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +00001330#pragma mark CommandObjectProcessSignal
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001331
Jim Ingham5a988412012-06-08 21:56:10 +00001332class CommandObjectProcessSignal : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001333{
1334public:
1335
Greg Claytona7015092010-09-18 01:14:36 +00001336 CommandObjectProcessSignal (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001337 CommandObjectParsed (interpreter,
1338 "process signal",
1339 "Send a UNIX signal to the current process being debugged.",
Greg Claytonf9fc6092013-01-09 19:44:40 +00001340 NULL,
1341 eFlagRequiresProcess | eFlagTryTargetAPILock)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001342 {
Caroline Tice405fe672010-10-04 22:28:36 +00001343 CommandArgumentEntry arg;
1344 CommandArgumentData signal_arg;
1345
1346 // Define the first (and only) variant of this arg.
Caroline Ticec0dbdfb2010-10-18 22:56:57 +00001347 signal_arg.arg_type = eArgTypeUnixSignal;
Caroline Tice405fe672010-10-04 22:28:36 +00001348 signal_arg.arg_repetition = eArgRepeatPlain;
1349
1350 // There is only one variant this argument could be; put it into the argument entry.
1351 arg.push_back (signal_arg);
1352
1353 // Push the data for the first argument into the m_arguments vector.
1354 m_arguments.push_back (arg);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001355 }
1356
1357 ~CommandObjectProcessSignal ()
1358 {
1359 }
1360
Jim Ingham5a988412012-06-08 21:56:10 +00001361protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001362 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001363 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001364 CommandReturnObject &result)
1365 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00001366 Process *process = m_exe_ctx.GetProcessPtr();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001367
1368 if (command.GetArgumentCount() == 1)
1369 {
Greg Clayton237cd902010-10-09 01:40:57 +00001370 int signo = LLDB_INVALID_SIGNAL_NUMBER;
1371
1372 const char *signal_name = command.GetArgumentAtIndex(0);
1373 if (::isxdigit (signal_name[0]))
1374 signo = Args::StringToSInt32(signal_name, LLDB_INVALID_SIGNAL_NUMBER, 0);
1375 else
1376 signo = process->GetUnixSignals().GetSignalNumberFromName (signal_name);
1377
1378 if (signo == LLDB_INVALID_SIGNAL_NUMBER)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001379 {
1380 result.AppendErrorWithFormat ("Invalid signal argument '%s'.\n", command.GetArgumentAtIndex(0));
1381 result.SetStatus (eReturnStatusFailed);
1382 }
1383 else
1384 {
1385 Error error (process->Signal (signo));
1386 if (error.Success())
1387 {
1388 result.SetStatus (eReturnStatusSuccessFinishResult);
1389 }
1390 else
1391 {
1392 result.AppendErrorWithFormat ("Failed to send signal %i: %s\n", signo, error.AsCString());
1393 result.SetStatus (eReturnStatusFailed);
1394 }
1395 }
1396 }
1397 else
1398 {
Jason Molendafd54b362011-09-20 21:44:10 +00001399 result.AppendErrorWithFormat("'%s' takes exactly one signal number argument:\nUsage: %s\n", m_cmd_name.c_str(),
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001400 m_cmd_syntax.c_str());
1401 result.SetStatus (eReturnStatusFailed);
1402 }
1403 return result.Succeeded();
1404 }
1405};
1406
1407
1408//-------------------------------------------------------------------------
1409// CommandObjectProcessInterrupt
1410//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +00001411#pragma mark CommandObjectProcessInterrupt
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001412
Jim Ingham5a988412012-06-08 21:56:10 +00001413class CommandObjectProcessInterrupt : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001414{
1415public:
1416
1417
Greg Claytona7015092010-09-18 01:14:36 +00001418 CommandObjectProcessInterrupt (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001419 CommandObjectParsed (interpreter,
1420 "process interrupt",
1421 "Interrupt the current process being debugged.",
1422 "process interrupt",
Greg Claytonf9fc6092013-01-09 19:44:40 +00001423 eFlagRequiresProcess |
1424 eFlagTryTargetAPILock |
Jim Ingham5a988412012-06-08 21:56:10 +00001425 eFlagProcessMustBeLaunched)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426 {
1427 }
1428
1429 ~CommandObjectProcessInterrupt ()
1430 {
1431 }
1432
Jim Ingham5a988412012-06-08 21:56:10 +00001433protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001435 DoExecute (Args& command,
Greg Claytonf9b57b92013-05-10 23:48:10 +00001436 CommandReturnObject &result)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00001438 Process *process = m_exe_ctx.GetProcessPtr();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439 if (process == NULL)
1440 {
1441 result.AppendError ("no process to halt");
1442 result.SetStatus (eReturnStatusFailed);
1443 return false;
1444 }
1445
1446 if (command.GetArgumentCount() == 0)
1447 {
Greg Claytonf9b57b92013-05-10 23:48:10 +00001448 bool clear_thread_plans = true;
1449 Error error(process->Halt (clear_thread_plans));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450 if (error.Success())
1451 {
1452 result.SetStatus (eReturnStatusSuccessFinishResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001453 }
1454 else
1455 {
1456 result.AppendErrorWithFormat ("Failed to halt process: %s\n", error.AsCString());
1457 result.SetStatus (eReturnStatusFailed);
1458 }
1459 }
1460 else
1461 {
Jason Molendafd54b362011-09-20 21:44:10 +00001462 result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001463 m_cmd_name.c_str(),
1464 m_cmd_syntax.c_str());
1465 result.SetStatus (eReturnStatusFailed);
1466 }
1467 return result.Succeeded();
1468 }
1469};
1470
1471//-------------------------------------------------------------------------
1472// CommandObjectProcessKill
1473//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +00001474#pragma mark CommandObjectProcessKill
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001475
Jim Ingham5a988412012-06-08 21:56:10 +00001476class CommandObjectProcessKill : public CommandObjectParsed
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001477{
1478public:
1479
Greg Claytona7015092010-09-18 01:14:36 +00001480 CommandObjectProcessKill (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001481 CommandObjectParsed (interpreter,
1482 "process kill",
1483 "Terminate the current process being debugged.",
1484 "process kill",
Greg Claytonf9fc6092013-01-09 19:44:40 +00001485 eFlagRequiresProcess |
1486 eFlagTryTargetAPILock |
Jim Ingham5a988412012-06-08 21:56:10 +00001487 eFlagProcessMustBeLaunched)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001488 {
1489 }
1490
1491 ~CommandObjectProcessKill ()
1492 {
1493 }
1494
Jim Ingham5a988412012-06-08 21:56:10 +00001495protected:
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001496 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001497 DoExecute (Args& command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001498 CommandReturnObject &result)
1499 {
Greg Claytonf9fc6092013-01-09 19:44:40 +00001500 Process *process = m_exe_ctx.GetProcessPtr();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001501 if (process == NULL)
1502 {
1503 result.AppendError ("no process to kill");
1504 result.SetStatus (eReturnStatusFailed);
1505 return false;
1506 }
1507
1508 if (command.GetArgumentCount() == 0)
1509 {
1510 Error error (process->Destroy());
1511 if (error.Success())
1512 {
1513 result.SetStatus (eReturnStatusSuccessFinishResult);
1514 }
1515 else
1516 {
1517 result.AppendErrorWithFormat ("Failed to kill process: %s\n", error.AsCString());
1518 result.SetStatus (eReturnStatusFailed);
1519 }
1520 }
1521 else
1522 {
Jason Molendafd54b362011-09-20 21:44:10 +00001523 result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001524 m_cmd_name.c_str(),
1525 m_cmd_syntax.c_str());
1526 result.SetStatus (eReturnStatusFailed);
1527 }
1528 return result.Succeeded();
1529 }
1530};
1531
1532//-------------------------------------------------------------------------
Greg Claytona2715cf2014-06-13 00:54:12 +00001533// CommandObjectProcessSaveCore
1534//-------------------------------------------------------------------------
1535#pragma mark CommandObjectProcessSaveCore
1536
1537class CommandObjectProcessSaveCore : public CommandObjectParsed
1538{
1539public:
1540
1541 CommandObjectProcessSaveCore (CommandInterpreter &interpreter) :
1542 CommandObjectParsed (interpreter,
1543 "process save-core",
1544 "Save the current process as a core file using an appropriate file type.",
1545 "process save-core FILE",
1546 eFlagRequiresProcess |
1547 eFlagTryTargetAPILock |
1548 eFlagProcessMustBeLaunched)
1549 {
1550 }
1551
1552 ~CommandObjectProcessSaveCore ()
1553 {
1554 }
1555
1556protected:
1557 bool
1558 DoExecute (Args& command,
1559 CommandReturnObject &result)
1560 {
1561 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
1562 if (process_sp)
1563 {
1564 if (command.GetArgumentCount() == 1)
1565 {
1566 FileSpec output_file(command.GetArgumentAtIndex(0), false);
1567 Error error = PluginManager::SaveCore(process_sp, output_file);
1568 if (error.Success())
1569 {
1570 result.SetStatus (eReturnStatusSuccessFinishResult);
1571 }
1572 else
1573 {
1574 result.AppendErrorWithFormat ("Failed to save core file for process: %s\n", error.AsCString());
1575 result.SetStatus (eReturnStatusFailed);
1576 }
1577 }
1578 else
1579 {
1580 result.AppendErrorWithFormat ("'%s' takes one arguments:\nUsage: %s\n",
1581 m_cmd_name.c_str(),
1582 m_cmd_syntax.c_str());
1583 result.SetStatus (eReturnStatusFailed);
1584 }
1585 }
1586 else
1587 {
1588 result.AppendError ("invalid process");
1589 result.SetStatus (eReturnStatusFailed);
1590 return false;
1591 }
1592
1593 return result.Succeeded();
1594 }
1595};
1596
1597//-------------------------------------------------------------------------
Jim Ingham4b9bea82010-06-18 01:23:09 +00001598// CommandObjectProcessStatus
1599//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +00001600#pragma mark CommandObjectProcessStatus
1601
Jim Ingham5a988412012-06-08 21:56:10 +00001602class CommandObjectProcessStatus : public CommandObjectParsed
Jim Ingham4b9bea82010-06-18 01:23:09 +00001603{
1604public:
Greg Claytona7015092010-09-18 01:14:36 +00001605 CommandObjectProcessStatus (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001606 CommandObjectParsed (interpreter,
1607 "process status",
1608 "Show the current status and location of executing process.",
1609 "process status",
Greg Claytonf9fc6092013-01-09 19:44:40 +00001610 eFlagRequiresProcess | eFlagTryTargetAPILock)
Jim Ingham4b9bea82010-06-18 01:23:09 +00001611 {
1612 }
1613
1614 ~CommandObjectProcessStatus()
1615 {
1616 }
1617
1618
1619 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001620 DoExecute (Args& command, CommandReturnObject &result)
Jim Ingham4b9bea82010-06-18 01:23:09 +00001621 {
Greg Clayton7260f622011-04-18 08:33:37 +00001622 Stream &strm = result.GetOutputStream();
Jim Ingham4b9bea82010-06-18 01:23:09 +00001623 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Greg Claytonf9fc6092013-01-09 19:44:40 +00001624 // No need to check "process" for validity as eFlagRequiresProcess ensures it is valid
1625 Process *process = m_exe_ctx.GetProcessPtr();
1626 const bool only_threads_with_stop_reason = true;
1627 const uint32_t start_frame = 0;
1628 const uint32_t num_frames = 1;
1629 const uint32_t num_frames_with_source = 1;
1630 process->GetStatus(strm);
1631 process->GetThreadStatus (strm,
1632 only_threads_with_stop_reason,
1633 start_frame,
1634 num_frames,
1635 num_frames_with_source);
Jim Ingham4b9bea82010-06-18 01:23:09 +00001636 return result.Succeeded();
1637 }
1638};
1639
1640//-------------------------------------------------------------------------
Caroline Tice35731352010-10-13 20:44:39 +00001641// CommandObjectProcessHandle
1642//-------------------------------------------------------------------------
Jim Inghambb9caf72010-12-09 18:58:16 +00001643#pragma mark CommandObjectProcessHandle
Caroline Tice35731352010-10-13 20:44:39 +00001644
Jim Ingham5a988412012-06-08 21:56:10 +00001645class CommandObjectProcessHandle : public CommandObjectParsed
Caroline Tice35731352010-10-13 20:44:39 +00001646{
1647public:
1648
1649 class CommandOptions : public Options
1650 {
1651 public:
1652
Greg Claytoneb0103f2011-04-07 22:46:35 +00001653 CommandOptions (CommandInterpreter &interpreter) :
1654 Options (interpreter)
Caroline Tice35731352010-10-13 20:44:39 +00001655 {
Greg Claytonf6b8b582011-04-13 00:18:08 +00001656 OptionParsingStarting ();
Caroline Tice35731352010-10-13 20:44:39 +00001657 }
1658
1659 ~CommandOptions ()
1660 {
1661 }
1662
1663 Error
Greg Claytonf6b8b582011-04-13 00:18:08 +00001664 SetOptionValue (uint32_t option_idx, const char *option_arg)
Caroline Tice35731352010-10-13 20:44:39 +00001665 {
1666 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001667 const int short_option = m_getopt_table[option_idx].val;
Caroline Tice35731352010-10-13 20:44:39 +00001668
1669 switch (short_option)
1670 {
1671 case 's':
1672 stop = option_arg;
1673 break;
1674 case 'n':
1675 notify = option_arg;
1676 break;
1677 case 'p':
1678 pass = option_arg;
1679 break;
1680 default:
Greg Clayton86edbf42011-10-26 00:56:27 +00001681 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
Caroline Tice35731352010-10-13 20:44:39 +00001682 break;
1683 }
1684 return error;
1685 }
1686
1687 void
Greg Claytonf6b8b582011-04-13 00:18:08 +00001688 OptionParsingStarting ()
Caroline Tice35731352010-10-13 20:44:39 +00001689 {
Caroline Tice35731352010-10-13 20:44:39 +00001690 stop.clear();
1691 notify.clear();
1692 pass.clear();
1693 }
1694
Greg Claytone0d378b2011-03-24 21:19:54 +00001695 const OptionDefinition*
Caroline Tice35731352010-10-13 20:44:39 +00001696 GetDefinitions ()
1697 {
1698 return g_option_table;
1699 }
1700
1701 // Options table: Required for subclasses of Options.
1702
Greg Claytone0d378b2011-03-24 21:19:54 +00001703 static OptionDefinition g_option_table[];
Caroline Tice35731352010-10-13 20:44:39 +00001704
1705 // Instance variables to hold the values for command options.
1706
1707 std::string stop;
1708 std::string notify;
1709 std::string pass;
1710 };
1711
1712
1713 CommandObjectProcessHandle (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001714 CommandObjectParsed (interpreter,
1715 "process handle",
1716 "Show or update what the process and debugger should do with various signals received from the OS.",
1717 NULL),
Greg Claytoneb0103f2011-04-07 22:46:35 +00001718 m_options (interpreter)
Caroline Tice35731352010-10-13 20:44:39 +00001719 {
Caroline Tice10ad7992010-10-14 21:31:13 +00001720 SetHelpLong ("If no signals are specified, update them all. If no update option is specified, list the current values.\n");
Caroline Tice35731352010-10-13 20:44:39 +00001721 CommandArgumentEntry arg;
Caroline Ticec0dbdfb2010-10-18 22:56:57 +00001722 CommandArgumentData signal_arg;
Caroline Tice35731352010-10-13 20:44:39 +00001723
Caroline Ticec0dbdfb2010-10-18 22:56:57 +00001724 signal_arg.arg_type = eArgTypeUnixSignal;
1725 signal_arg.arg_repetition = eArgRepeatStar;
Caroline Tice35731352010-10-13 20:44:39 +00001726
Caroline Ticec0dbdfb2010-10-18 22:56:57 +00001727 arg.push_back (signal_arg);
Caroline Tice35731352010-10-13 20:44:39 +00001728
1729 m_arguments.push_back (arg);
1730 }
1731
1732 ~CommandObjectProcessHandle ()
1733 {
1734 }
1735
1736 Options *
1737 GetOptions ()
1738 {
1739 return &m_options;
1740 }
1741
1742 bool
Caroline Tice10ad7992010-10-14 21:31:13 +00001743 VerifyCommandOptionValue (const std::string &option, int &real_value)
Caroline Tice35731352010-10-13 20:44:39 +00001744 {
1745 bool okay = true;
1746
Caroline Tice10ad7992010-10-14 21:31:13 +00001747 bool success = false;
1748 bool tmp_value = Args::StringToBoolean (option.c_str(), false, &success);
1749
1750 if (success && tmp_value)
1751 real_value = 1;
1752 else if (success && !tmp_value)
1753 real_value = 0;
Caroline Tice35731352010-10-13 20:44:39 +00001754 else
1755 {
1756 // If the value isn't 'true' or 'false', it had better be 0 or 1.
Caroline Tice10ad7992010-10-14 21:31:13 +00001757 real_value = Args::StringToUInt32 (option.c_str(), 3);
1758 if (real_value != 0 && real_value != 1)
Caroline Tice35731352010-10-13 20:44:39 +00001759 okay = false;
1760 }
1761
1762 return okay;
1763 }
1764
Caroline Tice10ad7992010-10-14 21:31:13 +00001765 void
1766 PrintSignalHeader (Stream &str)
1767 {
1768 str.Printf ("NAME PASS STOP NOTIFY\n");
1769 str.Printf ("========== ===== ===== ======\n");
1770 }
1771
1772 void
1773 PrintSignal (Stream &str, int32_t signo, const char *sig_name, UnixSignals &signals)
1774 {
1775 bool stop;
1776 bool suppress;
1777 bool notify;
1778
1779 str.Printf ("%-10s ", sig_name);
1780 if (signals.GetSignalInfo (signo, suppress, stop, notify))
1781 {
1782 bool pass = !suppress;
1783 str.Printf ("%s %s %s",
1784 (pass ? "true " : "false"),
1785 (stop ? "true " : "false"),
1786 (notify ? "true " : "false"));
1787 }
1788 str.Printf ("\n");
1789 }
1790
1791 void
1792 PrintSignalInformation (Stream &str, Args &signal_args, int num_valid_signals, UnixSignals &signals)
1793 {
1794 PrintSignalHeader (str);
1795
1796 if (num_valid_signals > 0)
1797 {
1798 size_t num_args = signal_args.GetArgumentCount();
1799 for (size_t i = 0; i < num_args; ++i)
1800 {
1801 int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i));
1802 if (signo != LLDB_INVALID_SIGNAL_NUMBER)
1803 PrintSignal (str, signo, signal_args.GetArgumentAtIndex (i), signals);
1804 }
1805 }
1806 else // Print info for ALL signals
1807 {
1808 int32_t signo = signals.GetFirstSignalNumber();
1809 while (signo != LLDB_INVALID_SIGNAL_NUMBER)
1810 {
1811 PrintSignal (str, signo, signals.GetSignalAsCString (signo), signals);
1812 signo = signals.GetNextSignalNumber (signo);
1813 }
1814 }
1815 }
1816
Jim Ingham5a988412012-06-08 21:56:10 +00001817protected:
Caroline Tice35731352010-10-13 20:44:39 +00001818 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001819 DoExecute (Args &signal_args, CommandReturnObject &result)
Caroline Tice35731352010-10-13 20:44:39 +00001820 {
1821 TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
1822
1823 if (!target_sp)
1824 {
1825 result.AppendError ("No current target;"
1826 " cannot handle signals until you have a valid target and process.\n");
1827 result.SetStatus (eReturnStatusFailed);
1828 return false;
1829 }
1830
1831 ProcessSP process_sp = target_sp->GetProcessSP();
1832
1833 if (!process_sp)
1834 {
1835 result.AppendError ("No current process; cannot handle signals until you have a valid process.\n");
1836 result.SetStatus (eReturnStatusFailed);
1837 return false;
1838 }
1839
Caroline Tice35731352010-10-13 20:44:39 +00001840 int stop_action = -1; // -1 means leave the current setting alone
Caroline Tice10ad7992010-10-14 21:31:13 +00001841 int pass_action = -1; // -1 means leave the current setting alone
Caroline Tice35731352010-10-13 20:44:39 +00001842 int notify_action = -1; // -1 means leave the current setting alone
1843
1844 if (! m_options.stop.empty()
Caroline Tice10ad7992010-10-14 21:31:13 +00001845 && ! VerifyCommandOptionValue (m_options.stop, stop_action))
Caroline Tice35731352010-10-13 20:44:39 +00001846 {
1847 result.AppendError ("Invalid argument for command option --stop; must be true or false.\n");
1848 result.SetStatus (eReturnStatusFailed);
1849 return false;
1850 }
1851
1852 if (! m_options.notify.empty()
Caroline Tice10ad7992010-10-14 21:31:13 +00001853 && ! VerifyCommandOptionValue (m_options.notify, notify_action))
Caroline Tice35731352010-10-13 20:44:39 +00001854 {
1855 result.AppendError ("Invalid argument for command option --notify; must be true or false.\n");
1856 result.SetStatus (eReturnStatusFailed);
1857 return false;
1858 }
1859
1860 if (! m_options.pass.empty()
Caroline Tice10ad7992010-10-14 21:31:13 +00001861 && ! VerifyCommandOptionValue (m_options.pass, pass_action))
Caroline Tice35731352010-10-13 20:44:39 +00001862 {
1863 result.AppendError ("Invalid argument for command option --pass; must be true or false.\n");
1864 result.SetStatus (eReturnStatusFailed);
1865 return false;
1866 }
1867
1868 size_t num_args = signal_args.GetArgumentCount();
1869 UnixSignals &signals = process_sp->GetUnixSignals();
1870 int num_signals_set = 0;
1871
Caroline Tice10ad7992010-10-14 21:31:13 +00001872 if (num_args > 0)
Caroline Tice35731352010-10-13 20:44:39 +00001873 {
Caroline Tice10ad7992010-10-14 21:31:13 +00001874 for (size_t i = 0; i < num_args; ++i)
Caroline Tice35731352010-10-13 20:44:39 +00001875 {
Caroline Tice10ad7992010-10-14 21:31:13 +00001876 int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i));
1877 if (signo != LLDB_INVALID_SIGNAL_NUMBER)
Caroline Tice35731352010-10-13 20:44:39 +00001878 {
Caroline Tice10ad7992010-10-14 21:31:13 +00001879 // Casting the actions as bools here should be okay, because VerifyCommandOptionValue guarantees
1880 // the value is either 0 or 1.
1881 if (stop_action != -1)
1882 signals.SetShouldStop (signo, (bool) stop_action);
1883 if (pass_action != -1)
1884 {
1885 bool suppress = ! ((bool) pass_action);
1886 signals.SetShouldSuppress (signo, suppress);
1887 }
1888 if (notify_action != -1)
1889 signals.SetShouldNotify (signo, (bool) notify_action);
1890 ++num_signals_set;
Caroline Tice35731352010-10-13 20:44:39 +00001891 }
Caroline Tice10ad7992010-10-14 21:31:13 +00001892 else
1893 {
1894 result.AppendErrorWithFormat ("Invalid signal name '%s'\n", signal_args.GetArgumentAtIndex (i));
1895 }
Caroline Tice35731352010-10-13 20:44:39 +00001896 }
1897 }
Caroline Tice10ad7992010-10-14 21:31:13 +00001898 else
1899 {
1900 // No signal specified, if any command options were specified, update ALL signals.
1901 if ((notify_action != -1) || (stop_action != -1) || (pass_action != -1))
1902 {
1903 if (m_interpreter.Confirm ("Do you really want to update all the signals?", false))
1904 {
1905 int32_t signo = signals.GetFirstSignalNumber();
1906 while (signo != LLDB_INVALID_SIGNAL_NUMBER)
1907 {
1908 if (notify_action != -1)
1909 signals.SetShouldNotify (signo, (bool) notify_action);
1910 if (stop_action != -1)
1911 signals.SetShouldStop (signo, (bool) stop_action);
1912 if (pass_action != -1)
1913 {
1914 bool suppress = ! ((bool) pass_action);
1915 signals.SetShouldSuppress (signo, suppress);
1916 }
1917 signo = signals.GetNextSignalNumber (signo);
1918 }
1919 }
1920 }
1921 }
1922
1923 PrintSignalInformation (result.GetOutputStream(), signal_args, num_signals_set, signals);
Caroline Tice35731352010-10-13 20:44:39 +00001924
1925 if (num_signals_set > 0)
1926 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1927 else
1928 result.SetStatus (eReturnStatusFailed);
1929
1930 return result.Succeeded();
1931 }
1932
Caroline Tice35731352010-10-13 20:44:39 +00001933 CommandOptions m_options;
1934};
1935
Greg Claytone0d378b2011-03-24 21:19:54 +00001936OptionDefinition
Caroline Tice35731352010-10-13 20:44:39 +00001937CommandObjectProcessHandle::CommandOptions::g_option_table[] =
1938{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001939{ LLDB_OPT_SET_1, false, "stop", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Whether or not the process should be stopped if the signal is received." },
1940{ LLDB_OPT_SET_1, false, "notify", 'n', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Whether or not the debugger should notify the user if the signal is received." },
1941{ LLDB_OPT_SET_1, false, "pass", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Whether or not the signal should be passed to the process." },
1942{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Caroline Tice35731352010-10-13 20:44:39 +00001943};
1944
1945//-------------------------------------------------------------------------
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001946// CommandObjectMultiwordProcess
1947//-------------------------------------------------------------------------
1948
Greg Clayton66111032010-06-23 01:19:29 +00001949CommandObjectMultiwordProcess::CommandObjectMultiwordProcess (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +00001950 CommandObjectMultiword (interpreter,
1951 "process",
1952 "A set of commands for operating on a process.",
1953 "process <subcommand> [<subcommand-options>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001954{
Greg Clayton197bacf2011-07-02 21:07:54 +00001955 LoadSubCommand ("attach", CommandObjectSP (new CommandObjectProcessAttach (interpreter)));
1956 LoadSubCommand ("launch", CommandObjectSP (new CommandObjectProcessLaunch (interpreter)));
1957 LoadSubCommand ("continue", CommandObjectSP (new CommandObjectProcessContinue (interpreter)));
1958 LoadSubCommand ("connect", CommandObjectSP (new CommandObjectProcessConnect (interpreter)));
1959 LoadSubCommand ("detach", CommandObjectSP (new CommandObjectProcessDetach (interpreter)));
1960 LoadSubCommand ("load", CommandObjectSP (new CommandObjectProcessLoad (interpreter)));
1961 LoadSubCommand ("unload", CommandObjectSP (new CommandObjectProcessUnload (interpreter)));
1962 LoadSubCommand ("signal", CommandObjectSP (new CommandObjectProcessSignal (interpreter)));
1963 LoadSubCommand ("handle", CommandObjectSP (new CommandObjectProcessHandle (interpreter)));
1964 LoadSubCommand ("status", CommandObjectSP (new CommandObjectProcessStatus (interpreter)));
Greg Claytona7015092010-09-18 01:14:36 +00001965 LoadSubCommand ("interrupt", CommandObjectSP (new CommandObjectProcessInterrupt (interpreter)));
Greg Clayton197bacf2011-07-02 21:07:54 +00001966 LoadSubCommand ("kill", CommandObjectSP (new CommandObjectProcessKill (interpreter)));
Greg Clayton998255b2012-10-13 02:07:45 +00001967 LoadSubCommand ("plugin", CommandObjectSP (new CommandObjectProcessPlugin (interpreter)));
Greg Claytona2715cf2014-06-13 00:54:12 +00001968 LoadSubCommand ("save-core", CommandObjectSP (new CommandObjectProcessSaveCore (interpreter)));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001969}
1970
1971CommandObjectMultiwordProcess::~CommandObjectMultiwordProcess ()
1972{
1973}
1974