1 //===-- CommandObjectProcess.cpp --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "CommandObjectProcess.h"
14 // Other libraries and framework includes
16 #include "lldb/Breakpoint/Breakpoint.h"
17 #include "lldb/Breakpoint/BreakpointLocation.h"
18 #include "lldb/Breakpoint/BreakpointSite.h"
19 #include "lldb/Core/State.h"
20 #include "lldb/Core/Module.h"
21 #include "lldb/Core/PluginManager.h"
22 #include "lldb/Host/Host.h"
23 #include "lldb/Host/StringConvert.h"
24 #include "lldb/Interpreter/Args.h"
25 #include "lldb/Interpreter/Options.h"
26 #include "lldb/Interpreter/CommandInterpreter.h"
27 #include "lldb/Interpreter/CommandReturnObject.h"
28 #include "lldb/Target/Platform.h"
29 #include "lldb/Target/Process.h"
30 #include "lldb/Target/StopInfo.h"
31 #include "lldb/Target/Target.h"
32 #include "lldb/Target/Thread.h"
33 #include "lldb/Target/UnixSignals.h"
36 using namespace lldb_private;
38 class CommandObjectProcessLaunchOrAttach : public CommandObjectParsed
41 CommandObjectProcessLaunchOrAttach (CommandInterpreter &interpreter,
46 const char *new_process_action) :
47 CommandObjectParsed (interpreter, name, help, syntax, flags),
48 m_new_process_action (new_process_action) {}
50 virtual ~CommandObjectProcessLaunchOrAttach () {}
53 StopProcessIfNecessary (Process *process, StateType &state, CommandReturnObject &result)
55 state = eStateInvalid;
58 state = process->GetState();
60 if (process->IsAlive() && state != eStateConnected)
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());
68 ::snprintf (message, sizeof(message), "There is a running process, kill it and %s?", m_new_process_action.c_str());
70 if (!m_interpreter.Confirm (message, true))
72 result.SetStatus (eReturnStatusFailed);
77 if (process->GetShouldDetach())
79 bool keep_stopped = false;
80 Error detach_error (process->Detach(keep_stopped));
81 if (detach_error.Success())
83 result.SetStatus (eReturnStatusSuccessFinishResult);
88 result.AppendErrorWithFormat ("Failed to detach from process: %s\n", detach_error.AsCString());
89 result.SetStatus (eReturnStatusFailed);
94 Error destroy_error (process->Destroy(false));
95 if (destroy_error.Success())
97 result.SetStatus (eReturnStatusSuccessFinishResult);
102 result.AppendErrorWithFormat ("Failed to kill process: %s\n", destroy_error.AsCString());
103 result.SetStatus (eReturnStatusFailed);
109 return result.Succeeded();
111 std::string m_new_process_action;
113 //-------------------------------------------------------------------------
114 // CommandObjectProcessLaunch
115 //-------------------------------------------------------------------------
116 #pragma mark CommandObjectProcessLaunch
117 class CommandObjectProcessLaunch : public CommandObjectProcessLaunchOrAttach
121 CommandObjectProcessLaunch (CommandInterpreter &interpreter) :
122 CommandObjectProcessLaunchOrAttach (interpreter,
124 "Launch the executable in the debugger.",
126 eCommandRequiresTarget,
128 m_options (interpreter)
130 CommandArgumentEntry arg;
131 CommandArgumentData run_args_arg;
133 // Define the first (and only) variant of this arg.
134 run_args_arg.arg_type = eArgTypeRunArgs;
135 run_args_arg.arg_repetition = eArgRepeatOptional;
137 // There is only one variant this argument could be; put it into the argument entry.
138 arg.push_back (run_args_arg);
140 // Push the data for the first argument into the m_arguments vector.
141 m_arguments.push_back (arg);
145 ~CommandObjectProcessLaunch ()
150 HandleArgumentCompletion (Args &input,
152 int &cursor_char_position,
153 OptionElementVector &opt_element_vector,
154 int match_start_point,
155 int max_return_elements,
159 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
160 completion_str.erase (cursor_char_position);
162 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
163 CommandCompletions::eDiskFileCompletion,
164 completion_str.c_str(),
170 return matches.GetSize();
179 virtual const char *GetRepeatCommand (Args ¤t_command_args, uint32_t index)
181 // No repeat for "process launch"...
187 DoExecute (Args& launch_args, CommandReturnObject &result)
189 Debugger &debugger = m_interpreter.GetDebugger();
190 Target *target = debugger.GetSelectedTarget().get();
191 // If our listener is NULL, users aren't allows to launch
192 ModuleSP exe_module_sp = target->GetExecutableModule();
194 if (exe_module_sp == NULL)
196 result.AppendError ("no file in target, create a debug target using the 'target create' command");
197 result.SetStatus (eReturnStatusFailed);
201 StateType state = eStateInvalid;
203 if (!StopProcessIfNecessary(m_exe_ctx.GetProcessPtr(), state, result))
206 const char *target_settings_argv0 = target->GetArg0();
208 // 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)
214 // The user specified an explicit setting on the process launch line. Use it.
215 disable_aslr = (m_options.disable_aslr == eLazyBoolYes);
219 // The user did not explicitly specify whether to disable ASLR. Fall back to the target.disable-aslr setting.
220 disable_aslr = target->GetDisableASLR ();
224 m_options.launch_info.GetFlags().Set (eLaunchFlagDisableASLR);
226 m_options.launch_info.GetFlags().Clear (eLaunchFlagDisableASLR);
228 if (target->GetDetachOnError())
229 m_options.launch_info.GetFlags().Set (eLaunchFlagDetachOnError);
231 if (target->GetDisableSTDIO())
232 m_options.launch_info.GetFlags().Set (eLaunchFlagDisableSTDIO);
235 target->GetEnvironmentAsArgs (environment);
236 if (environment.GetArgumentCount() > 0)
237 m_options.launch_info.GetEnvironmentEntries ().AppendArguments (environment);
239 if (target_settings_argv0)
241 m_options.launch_info.GetArguments().AppendArgument (target_settings_argv0);
242 m_options.launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), false);
246 m_options.launch_info.SetExecutableFile(exe_module_sp->GetPlatformFileSpec(), true);
249 if (launch_args.GetArgumentCount() == 0)
251 m_options.launch_info.GetArguments().AppendArguments (target->GetProcessLaunchInfo().GetArguments());
255 m_options.launch_info.GetArguments().AppendArguments (launch_args);
256 // Save the arguments for subsequent runs in the current target.
257 target->SetRunArguments (launch_args);
261 Error error = target->Launch(m_options.launch_info, &stream);
265 ProcessSP process_sp (target->GetProcessSP());
268 // There is a race condition where this thread will return up the call stack to the main command
269 // handler and show an (lldb) prompt before HandlePrivateEvent (from PrivateStateThread) has
270 // a chance to call PushProcessIOHandler().
271 process_sp->SyncIOHandler (0, 2000);
273 const char *data = stream.GetData();
274 if (data && strlen(data) > 0)
275 result.AppendMessage(stream.GetData());
276 const char *archname = exe_module_sp->GetArchitecture().GetArchitectureName();
277 result.AppendMessageWithFormat ("Process %" PRIu64 " launched: '%s' (%s)\n", process_sp->GetID(), exe_module_sp->GetFileSpec().GetPath().c_str(), archname);
278 result.SetStatus (eReturnStatusSuccessFinishResult);
279 result.SetDidChangeProcessState (true);
283 result.AppendError("no error returned from Target::Launch, and target has no process");
284 result.SetStatus (eReturnStatusFailed);
289 result.AppendError(error.AsCString());
290 result.SetStatus (eReturnStatusFailed);
292 return result.Succeeded();
296 ProcessLaunchCommandOptions m_options;
300 //#define SET1 LLDB_OPT_SET_1
301 //#define SET2 LLDB_OPT_SET_2
302 //#define SET3 LLDB_OPT_SET_3
305 //CommandObjectProcessLaunch::CommandOptions::g_option_table[] =
307 //{ 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."},
308 //{ SET1 , false, "stdin", 'i', OptionParser::eRequiredArgument, NULL, 0, eArgTypeDirectoryName, "Redirect stdin for the process to <path>."},
309 //{ SET1 , false, "stdout", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypeDirectoryName, "Redirect stdout for the process to <path>."},
310 //{ SET1 , false, "stderr", 'e', OptionParser::eRequiredArgument, NULL, 0, eArgTypeDirectoryName, "Redirect stderr for the process to <path>."},
311 //{ SET1 | SET2 | SET3, false, "plugin", 'p', OptionParser::eRequiredArgument, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."},
312 //{ 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."},
313 //{ SET3, false, "no-stdio", 'n', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Do not set up for terminal I/O to go to running process."},
314 //{ SET1 | SET2 | SET3, false, "working-dir", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeDirectoryName, "Set the current working directory to <path> when running the inferior."},
315 //{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
322 //-------------------------------------------------------------------------
323 // CommandObjectProcessAttach
324 //-------------------------------------------------------------------------
325 #pragma mark CommandObjectProcessAttach
326 class CommandObjectProcessAttach : public CommandObjectProcessLaunchOrAttach
330 class CommandOptions : public Options
334 CommandOptions (CommandInterpreter &interpreter) :
337 // Keep default values of all options in one place: OptionParsingStarting ()
338 OptionParsingStarting ();
346 SetOptionValue (uint32_t option_idx, const char *option_arg)
349 const int short_option = m_getopt_table[option_idx].val;
350 bool success = false;
351 switch (short_option)
354 attach_info.SetContinueOnceAttached(true);
359 lldb::pid_t pid = StringConvert::ToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success);
360 if (!success || pid == LLDB_INVALID_PROCESS_ID)
362 error.SetErrorStringWithFormat("invalid process ID '%s'", option_arg);
366 attach_info.SetProcessID (pid);
372 attach_info.SetProcessPluginName (option_arg);
376 attach_info.GetExecutableFile().SetFile(option_arg, false);
380 attach_info.SetWaitForLaunch(true);
384 attach_info.SetIgnoreExisting(false);
388 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
395 OptionParsingStarting ()
400 const OptionDefinition*
403 return g_option_table;
407 HandleOptionArgumentCompletion (Args &input,
410 OptionElementVector &opt_element_vector,
411 int opt_element_index,
412 int match_start_point,
413 int max_return_elements,
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;
420 // We are only completing the name option for now...
422 const OptionDefinition *opt_defs = GetDefinitions();
423 if (opt_defs[opt_defs_index].short_option == 'n')
425 // Are we in the name?
427 // Look to see if there is a -P argument provided, and if so use that plugin, otherwise
428 // use the default plugin.
430 const char *partial_name = NULL;
431 partial_name = input.GetArgumentAtIndex(opt_arg_pos);
433 PlatformSP platform_sp (m_interpreter.GetPlatform (true));
436 ProcessInstanceInfoList process_infos;
437 ProcessInstanceInfoMatch match_info;
440 match_info.GetProcessInfo().GetExecutableFile().SetFile(partial_name, false);
441 match_info.SetNameMatchType(eNameMatchStartsWith);
443 platform_sp->FindProcesses (match_info, process_infos);
444 const size_t num_matches = process_infos.GetSize();
447 for (size_t i=0; i<num_matches; ++i)
449 matches.AppendString (process_infos.GetProcessNameAtIndex(i),
450 process_infos.GetProcessNameLengthAtIndex(i));
459 // Options table: Required for subclasses of Options.
461 static OptionDefinition g_option_table[];
463 // Instance variables to hold the values for command options.
465 ProcessAttachInfo attach_info;
468 CommandObjectProcessAttach (CommandInterpreter &interpreter) :
469 CommandObjectProcessLaunchOrAttach (interpreter,
471 "Attach to a process.",
472 "process attach <cmd-options>",
475 m_options (interpreter)
479 ~CommandObjectProcessAttach ()
491 DoExecute (Args& command,
492 CommandReturnObject &result)
494 PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
496 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
497 // N.B. The attach should be synchronous. It doesn't help much to get the prompt back between initiating the attach
498 // and the target actually stopping. So even if the interpreter is set to be asynchronous, we wait for the stop
501 StateType state = eStateInvalid;
502 Process *process = m_exe_ctx.GetProcessPtr();
504 if (!StopProcessIfNecessary (process, state, result))
509 // If there isn't a current target create one.
510 TargetSP new_target_sp;
513 error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
517 NULL, // No platform options
519 target = new_target_sp.get();
520 if (target == NULL || error.Fail())
522 result.AppendError(error.AsCString("Error creating target"));
525 m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target);
528 // Record the old executable module, we want to issue a warning if the process of attaching changed the
529 // current executable (like somebody said "file foo" then attached to a PID whose executable was bar.)
531 ModuleSP old_exec_module_sp = target->GetExecutableModule();
532 ArchSpec old_arch_spec = target->GetArchitecture();
534 if (command.GetArgumentCount())
536 result.AppendErrorWithFormat("Invalid arguments for '%s'.\nUsage: %s\n", m_cmd_name.c_str(), m_cmd_syntax.c_str());
537 result.SetStatus (eReturnStatusFailed);
541 m_interpreter.UpdateExecutionContext(nullptr);
543 const auto error = target->Attach(m_options.attach_info, &stream);
546 ProcessSP process_sp (target->GetProcessSP());
549 if (stream.GetData())
550 result.AppendMessage(stream.GetData());
551 result.SetStatus (eReturnStatusSuccessFinishNoResult);
552 result.SetDidChangeProcessState (true);
556 result.AppendError("no error returned from Target::Attach, and target has no process");
557 result.SetStatus (eReturnStatusFailed);
562 result.AppendErrorWithFormat ("attach failed: %s\n", error.AsCString());
563 result.SetStatus (eReturnStatusFailed);
566 if (!result.Succeeded())
569 // Okay, we're done. Last step is to warn if the executable module has changed:
570 char new_path[PATH_MAX];
571 ModuleSP new_exec_module_sp (target->GetExecutableModule());
572 if (!old_exec_module_sp)
574 // We might not have a module if we attached to a raw pid...
575 if (new_exec_module_sp)
577 new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
578 result.AppendMessageWithFormat("Executable module set to \"%s\".\n", new_path);
581 else if (old_exec_module_sp->GetFileSpec() != new_exec_module_sp->GetFileSpec())
583 char old_path[PATH_MAX];
585 old_exec_module_sp->GetFileSpec().GetPath (old_path, PATH_MAX);
586 new_exec_module_sp->GetFileSpec().GetPath (new_path, PATH_MAX);
588 result.AppendWarningWithFormat("Executable module changed from \"%s\" to \"%s\".\n",
592 if (!old_arch_spec.IsValid())
594 result.AppendMessageWithFormat ("Architecture set to: %s.\n", target->GetArchitecture().GetTriple().getTriple().c_str());
596 else if (!old_arch_spec.IsExactMatch(target->GetArchitecture()))
598 result.AppendWarningWithFormat("Architecture changed from %s to %s.\n",
599 old_arch_spec.GetTriple().getTriple().c_str(),
600 target->GetArchitecture().GetTriple().getTriple().c_str());
603 // This supports the use-case scenario of immediately continuing the process once attached.
604 if (m_options.attach_info.GetContinueOnceAttached())
605 m_interpreter.HandleCommand("process continue", eLazyBoolNo, result);
607 return result.Succeeded();
610 CommandOptions m_options;
615 CommandObjectProcessAttach::CommandOptions::g_option_table[] =
617 { LLDB_OPT_SET_ALL, false, "continue",'c', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Immediately continue the process once attached."},
618 { LLDB_OPT_SET_ALL, false, "plugin", 'P', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."},
619 { LLDB_OPT_SET_1, false, "pid", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePid, "The process ID of an existing process to attach to."},
620 { LLDB_OPT_SET_2, false, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeProcessName, "The name of the process to attach to."},
621 { LLDB_OPT_SET_2, false, "include-existing", 'i', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Include existing processes when doing attach -w."},
622 { LLDB_OPT_SET_2, false, "waitfor", 'w', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Wait for the process with <process-name> to launch."},
623 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
626 //-------------------------------------------------------------------------
627 // CommandObjectProcessContinue
628 //-------------------------------------------------------------------------
629 #pragma mark CommandObjectProcessContinue
631 class CommandObjectProcessContinue : public CommandObjectParsed
635 CommandObjectProcessContinue (CommandInterpreter &interpreter) :
636 CommandObjectParsed (interpreter,
638 "Continue execution of all threads in the current process.",
640 eCommandRequiresProcess |
641 eCommandTryTargetAPILock |
642 eCommandProcessMustBeLaunched |
643 eCommandProcessMustBePaused ),
644 m_options(interpreter)
649 ~CommandObjectProcessContinue ()
655 class CommandOptions : public Options
659 CommandOptions (CommandInterpreter &interpreter) :
662 // Keep default values of all options in one place: OptionParsingStarting ()
663 OptionParsingStarting ();
671 SetOptionValue (uint32_t option_idx, const char *option_arg)
674 const int short_option = m_getopt_table[option_idx].val;
675 bool success = false;
676 switch (short_option)
679 m_ignore = StringConvert::ToUInt32 (option_arg, 0, 0, &success);
681 error.SetErrorStringWithFormat ("invalid value for ignore option: \"%s\", should be a number.", option_arg);
685 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
692 OptionParsingStarting ()
697 const OptionDefinition*
700 return g_option_table;
703 // Options table: Required for subclasses of Options.
705 static OptionDefinition g_option_table[];
711 DoExecute (Args& command, CommandReturnObject &result)
713 Process *process = m_exe_ctx.GetProcessPtr();
714 bool synchronous_execution = m_interpreter.GetSynchronous ();
715 StateType state = process->GetState();
716 if (state == eStateStopped)
718 if (command.GetArgumentCount() != 0)
720 result.AppendErrorWithFormat ("The '%s' command does not take any arguments.\n", m_cmd_name.c_str());
721 result.SetStatus (eReturnStatusFailed);
725 if (m_options.m_ignore > 0)
727 ThreadSP sel_thread_sp(process->GetThreadList().GetSelectedThread());
730 StopInfoSP stop_info_sp = sel_thread_sp->GetStopInfo();
731 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonBreakpoint)
733 lldb::break_id_t bp_site_id = (lldb::break_id_t)stop_info_sp->GetValue();
734 BreakpointSiteSP bp_site_sp(process->GetBreakpointSiteList().FindByID(bp_site_id));
737 const size_t num_owners = bp_site_sp->GetNumberOfOwners();
738 for (size_t i = 0; i < num_owners; i++)
740 Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
741 if (!bp_ref.IsInternal())
743 bp_ref.SetIgnoreCount(m_options.m_ignore);
751 { // Scope for thread list mutex:
752 Mutex::Locker locker (process->GetThreadList().GetMutex());
753 const uint32_t num_threads = process->GetThreadList().GetSize();
755 // Set the actions that the threads should each take when resuming
756 for (uint32_t idx=0; idx<num_threads; ++idx)
758 const bool override_suspend = false;
759 process->GetThreadList().GetThreadAtIndex(idx)->SetResumeState (eStateRunning, override_suspend);
763 const uint32_t iohandler_id = process->GetIOHandlerID();
767 if (synchronous_execution)
768 error = process->ResumeSynchronous (&stream);
770 error = process->Resume ();
774 // There is a race condition where this thread will return up the call stack to the main command
775 // handler and show an (lldb) prompt before HandlePrivateEvent (from PrivateStateThread) has
776 // a chance to call PushProcessIOHandler().
777 process->SyncIOHandler(iohandler_id, 2000);
779 result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID());
780 if (synchronous_execution)
782 // If any state changed events had anything to say, add that to the result
783 if (stream.GetData())
784 result.AppendMessage(stream.GetData());
786 result.SetDidChangeProcessState (true);
787 result.SetStatus (eReturnStatusSuccessFinishNoResult);
791 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
796 result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString());
797 result.SetStatus (eReturnStatusFailed);
802 result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n",
803 StateAsCString(state));
804 result.SetStatus (eReturnStatusFailed);
806 return result.Succeeded();
815 CommandOptions m_options;
820 CommandObjectProcessContinue::CommandOptions::g_option_table[] =
822 { LLDB_OPT_SET_ALL, false, "ignore-count",'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeUnsignedInteger,
823 "Ignore <N> crossings of the breakpoint (if it exists) for the currently selected thread."},
824 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
827 //-------------------------------------------------------------------------
828 // CommandObjectProcessDetach
829 //-------------------------------------------------------------------------
830 #pragma mark CommandObjectProcessDetach
832 class CommandObjectProcessDetach : public CommandObjectParsed
835 class CommandOptions : public Options
839 CommandOptions (CommandInterpreter &interpreter) :
840 Options (interpreter)
842 OptionParsingStarting ();
850 SetOptionValue (uint32_t option_idx, const char *option_arg)
853 const int short_option = m_getopt_table[option_idx].val;
855 switch (short_option)
860 tmp_result = Args::StringToBoolean(option_arg, false, &success);
862 error.SetErrorStringWithFormat("invalid boolean option: \"%s\"", option_arg);
866 m_keep_stopped = eLazyBoolYes;
868 m_keep_stopped = eLazyBoolNo;
872 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
879 OptionParsingStarting ()
881 m_keep_stopped = eLazyBoolCalculate;
884 const OptionDefinition*
887 return g_option_table;
890 // Options table: Required for subclasses of Options.
892 static OptionDefinition g_option_table[];
894 // Instance variables to hold the values for command options.
895 LazyBool m_keep_stopped;
898 CommandObjectProcessDetach (CommandInterpreter &interpreter) :
899 CommandObjectParsed (interpreter,
901 "Detach from the current process being debugged.",
903 eCommandRequiresProcess |
904 eCommandTryTargetAPILock |
905 eCommandProcessMustBeLaunched),
906 m_options(interpreter)
910 ~CommandObjectProcessDetach ()
923 DoExecute (Args& command, CommandReturnObject &result)
925 Process *process = m_exe_ctx.GetProcessPtr();
926 // FIXME: This will be a Command Option:
928 if (m_options.m_keep_stopped == eLazyBoolCalculate)
930 // Check the process default:
931 if (process->GetDetachKeepsStopped())
934 keep_stopped = false;
936 else if (m_options.m_keep_stopped == eLazyBoolYes)
939 keep_stopped = false;
941 Error error (process->Detach(keep_stopped));
944 result.SetStatus (eReturnStatusSuccessFinishResult);
948 result.AppendErrorWithFormat ("Detach failed: %s\n", error.AsCString());
949 result.SetStatus (eReturnStatusFailed);
952 return result.Succeeded();
955 CommandOptions m_options;
959 CommandObjectProcessDetach::CommandOptions::g_option_table[] =
961 { 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)." },
962 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
965 //-------------------------------------------------------------------------
966 // CommandObjectProcessConnect
967 //-------------------------------------------------------------------------
968 #pragma mark CommandObjectProcessConnect
970 class CommandObjectProcessConnect : public CommandObjectParsed
974 class CommandOptions : public Options
978 CommandOptions (CommandInterpreter &interpreter) :
981 // Keep default values of all options in one place: OptionParsingStarting ()
982 OptionParsingStarting ();
990 SetOptionValue (uint32_t option_idx, const char *option_arg)
993 const int short_option = m_getopt_table[option_idx].val;
995 switch (short_option)
998 plugin_name.assign (option_arg);
1002 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
1009 OptionParsingStarting ()
1011 plugin_name.clear();
1014 const OptionDefinition*
1017 return g_option_table;
1020 // Options table: Required for subclasses of Options.
1022 static OptionDefinition g_option_table[];
1024 // Instance variables to hold the values for command options.
1026 std::string plugin_name;
1029 CommandObjectProcessConnect (CommandInterpreter &interpreter) :
1030 CommandObjectParsed (interpreter,
1032 "Connect to a remote debug service.",
1033 "process connect <remote-url>",
1035 m_options (interpreter)
1039 ~CommandObjectProcessConnect ()
1052 DoExecute (Args& command,
1053 CommandReturnObject &result)
1056 TargetSP target_sp (m_interpreter.GetDebugger().GetSelectedTarget());
1058 Process *process = m_exe_ctx.GetProcessPtr();
1061 if (process->IsAlive())
1063 result.AppendErrorWithFormat ("Process %" PRIu64 " is currently being debugged, kill the process before connecting.\n",
1065 result.SetStatus (eReturnStatusFailed);
1072 // If there isn't a current target create one.
1074 error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
1078 NULL, // No platform options
1080 if (!target_sp || error.Fail())
1082 result.AppendError(error.AsCString("Error creating target"));
1083 result.SetStatus (eReturnStatusFailed);
1086 m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target_sp.get());
1089 if (command.GetArgumentCount() == 1)
1091 const char *plugin_name = NULL;
1092 if (!m_options.plugin_name.empty())
1093 plugin_name = m_options.plugin_name.c_str();
1095 const char *remote_url = command.GetArgumentAtIndex(0);
1096 process = target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name, NULL).get();
1100 error = process->ConnectRemote (process->GetTarget().GetDebugger().GetOutputFile().get(), remote_url);
1104 result.AppendError(error.AsCString("Remote connect failed"));
1105 result.SetStatus (eReturnStatusFailed);
1106 target_sp->DeleteCurrentProcess();
1112 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",
1114 result.SetStatus (eReturnStatusFailed);
1119 result.AppendErrorWithFormat ("'%s' takes exactly one argument:\nUsage: %s\n",
1121 m_cmd_syntax.c_str());
1122 result.SetStatus (eReturnStatusFailed);
1124 return result.Succeeded();
1127 CommandOptions m_options;
1131 CommandObjectProcessConnect::CommandOptions::g_option_table[] =
1133 { LLDB_OPT_SET_ALL, false, "plugin", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePlugin, "Name of the process plugin you want to use."},
1134 { 0, false, NULL, 0 , 0, NULL, NULL, 0, eArgTypeNone, NULL }
1137 //-------------------------------------------------------------------------
1138 // CommandObjectProcessPlugin
1139 //-------------------------------------------------------------------------
1140 #pragma mark CommandObjectProcessPlugin
1142 class CommandObjectProcessPlugin : public CommandObjectProxy
1146 CommandObjectProcessPlugin (CommandInterpreter &interpreter) :
1147 CommandObjectProxy (interpreter,
1149 "Send a custom command to the current process plug-in.",
1150 "process plugin <args>",
1155 ~CommandObjectProcessPlugin ()
1159 virtual CommandObject *
1160 GetProxyCommandObject()
1162 Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
1164 return process->GetPluginCommandObject();
1170 //-------------------------------------------------------------------------
1171 // CommandObjectProcessLoad
1172 //-------------------------------------------------------------------------
1173 #pragma mark CommandObjectProcessLoad
1175 class CommandObjectProcessLoad : public CommandObjectParsed
1179 CommandObjectProcessLoad (CommandInterpreter &interpreter) :
1180 CommandObjectParsed (interpreter,
1182 "Load a shared library into the current process.",
1183 "process load <filename> [<filename> ...]",
1184 eCommandRequiresProcess |
1185 eCommandTryTargetAPILock |
1186 eCommandProcessMustBeLaunched |
1187 eCommandProcessMustBePaused )
1191 ~CommandObjectProcessLoad ()
1197 DoExecute (Args& command,
1198 CommandReturnObject &result)
1200 Process *process = m_exe_ctx.GetProcessPtr();
1202 const size_t argc = command.GetArgumentCount();
1204 for (uint32_t i=0; i<argc; ++i)
1207 const char *image_path = command.GetArgumentAtIndex(i);
1208 FileSpec image_spec (image_path, false);
1209 process->GetTarget().GetPlatform()->ResolveRemotePath(image_spec, image_spec);
1210 uint32_t image_token = process->LoadImage(image_spec, error);
1211 if (image_token != LLDB_INVALID_IMAGE_TOKEN)
1213 result.AppendMessageWithFormat ("Loading \"%s\"...ok\nImage %u loaded.\n", image_path, image_token);
1214 result.SetStatus (eReturnStatusSuccessFinishResult);
1218 result.AppendErrorWithFormat ("failed to load '%s': %s", image_path, error.AsCString());
1219 result.SetStatus (eReturnStatusFailed);
1222 return result.Succeeded();
1227 //-------------------------------------------------------------------------
1228 // CommandObjectProcessUnload
1229 //-------------------------------------------------------------------------
1230 #pragma mark CommandObjectProcessUnload
1232 class CommandObjectProcessUnload : public CommandObjectParsed
1236 CommandObjectProcessUnload (CommandInterpreter &interpreter) :
1237 CommandObjectParsed (interpreter,
1239 "Unload a shared library from the current process using the index returned by a previous call to \"process load\".",
1240 "process unload <index>",
1241 eCommandRequiresProcess |
1242 eCommandTryTargetAPILock |
1243 eCommandProcessMustBeLaunched |
1244 eCommandProcessMustBePaused )
1248 ~CommandObjectProcessUnload ()
1254 DoExecute (Args& command,
1255 CommandReturnObject &result)
1257 Process *process = m_exe_ctx.GetProcessPtr();
1259 const size_t argc = command.GetArgumentCount();
1261 for (uint32_t i=0; i<argc; ++i)
1263 const char *image_token_cstr = command.GetArgumentAtIndex(i);
1264 uint32_t image_token = StringConvert::ToUInt32(image_token_cstr, LLDB_INVALID_IMAGE_TOKEN, 0);
1265 if (image_token == LLDB_INVALID_IMAGE_TOKEN)
1267 result.AppendErrorWithFormat ("invalid image index argument '%s'", image_token_cstr);
1268 result.SetStatus (eReturnStatusFailed);
1273 Error error (process->UnloadImage(image_token));
1274 if (error.Success())
1276 result.AppendMessageWithFormat ("Unloading shared library with index %u...ok\n", image_token);
1277 result.SetStatus (eReturnStatusSuccessFinishResult);
1281 result.AppendErrorWithFormat ("failed to unload image: %s", error.AsCString());
1282 result.SetStatus (eReturnStatusFailed);
1287 return result.Succeeded();
1291 //-------------------------------------------------------------------------
1292 // CommandObjectProcessSignal
1293 //-------------------------------------------------------------------------
1294 #pragma mark CommandObjectProcessSignal
1296 class CommandObjectProcessSignal : public CommandObjectParsed
1300 CommandObjectProcessSignal (CommandInterpreter &interpreter) :
1301 CommandObjectParsed (interpreter,
1303 "Send a UNIX signal to the current process being debugged.",
1305 eCommandRequiresProcess | eCommandTryTargetAPILock)
1307 CommandArgumentEntry arg;
1308 CommandArgumentData signal_arg;
1310 // Define the first (and only) variant of this arg.
1311 signal_arg.arg_type = eArgTypeUnixSignal;
1312 signal_arg.arg_repetition = eArgRepeatPlain;
1314 // There is only one variant this argument could be; put it into the argument entry.
1315 arg.push_back (signal_arg);
1317 // Push the data for the first argument into the m_arguments vector.
1318 m_arguments.push_back (arg);
1321 ~CommandObjectProcessSignal ()
1327 DoExecute (Args& command,
1328 CommandReturnObject &result)
1330 Process *process = m_exe_ctx.GetProcessPtr();
1332 if (command.GetArgumentCount() == 1)
1334 int signo = LLDB_INVALID_SIGNAL_NUMBER;
1336 const char *signal_name = command.GetArgumentAtIndex(0);
1337 if (::isxdigit (signal_name[0]))
1338 signo = StringConvert::ToSInt32(signal_name, LLDB_INVALID_SIGNAL_NUMBER, 0);
1340 signo = process->GetUnixSignals().GetSignalNumberFromName (signal_name);
1342 if (signo == LLDB_INVALID_SIGNAL_NUMBER)
1344 result.AppendErrorWithFormat ("Invalid signal argument '%s'.\n", command.GetArgumentAtIndex(0));
1345 result.SetStatus (eReturnStatusFailed);
1349 Error error (process->Signal (signo));
1350 if (error.Success())
1352 result.SetStatus (eReturnStatusSuccessFinishResult);
1356 result.AppendErrorWithFormat ("Failed to send signal %i: %s\n", signo, error.AsCString());
1357 result.SetStatus (eReturnStatusFailed);
1363 result.AppendErrorWithFormat("'%s' takes exactly one signal number argument:\nUsage: %s\n", m_cmd_name.c_str(),
1364 m_cmd_syntax.c_str());
1365 result.SetStatus (eReturnStatusFailed);
1367 return result.Succeeded();
1372 //-------------------------------------------------------------------------
1373 // CommandObjectProcessInterrupt
1374 //-------------------------------------------------------------------------
1375 #pragma mark CommandObjectProcessInterrupt
1377 class CommandObjectProcessInterrupt : public CommandObjectParsed
1382 CommandObjectProcessInterrupt (CommandInterpreter &interpreter) :
1383 CommandObjectParsed (interpreter,
1384 "process interrupt",
1385 "Interrupt the current process being debugged.",
1386 "process interrupt",
1387 eCommandRequiresProcess |
1388 eCommandTryTargetAPILock |
1389 eCommandProcessMustBeLaunched)
1393 ~CommandObjectProcessInterrupt ()
1399 DoExecute (Args& command,
1400 CommandReturnObject &result)
1402 Process *process = m_exe_ctx.GetProcessPtr();
1403 if (process == NULL)
1405 result.AppendError ("no process to halt");
1406 result.SetStatus (eReturnStatusFailed);
1410 if (command.GetArgumentCount() == 0)
1412 bool clear_thread_plans = true;
1413 Error error(process->Halt (clear_thread_plans));
1414 if (error.Success())
1416 result.SetStatus (eReturnStatusSuccessFinishResult);
1420 result.AppendErrorWithFormat ("Failed to halt process: %s\n", error.AsCString());
1421 result.SetStatus (eReturnStatusFailed);
1426 result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
1428 m_cmd_syntax.c_str());
1429 result.SetStatus (eReturnStatusFailed);
1431 return result.Succeeded();
1435 //-------------------------------------------------------------------------
1436 // CommandObjectProcessKill
1437 //-------------------------------------------------------------------------
1438 #pragma mark CommandObjectProcessKill
1440 class CommandObjectProcessKill : public CommandObjectParsed
1444 CommandObjectProcessKill (CommandInterpreter &interpreter) :
1445 CommandObjectParsed (interpreter,
1447 "Terminate the current process being debugged.",
1449 eCommandRequiresProcess |
1450 eCommandTryTargetAPILock |
1451 eCommandProcessMustBeLaunched)
1455 ~CommandObjectProcessKill ()
1461 DoExecute (Args& command,
1462 CommandReturnObject &result)
1464 Process *process = m_exe_ctx.GetProcessPtr();
1465 if (process == NULL)
1467 result.AppendError ("no process to kill");
1468 result.SetStatus (eReturnStatusFailed);
1472 if (command.GetArgumentCount() == 0)
1474 Error error (process->Destroy(true));
1475 if (error.Success())
1477 result.SetStatus (eReturnStatusSuccessFinishResult);
1481 result.AppendErrorWithFormat ("Failed to kill process: %s\n", error.AsCString());
1482 result.SetStatus (eReturnStatusFailed);
1487 result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
1489 m_cmd_syntax.c_str());
1490 result.SetStatus (eReturnStatusFailed);
1492 return result.Succeeded();
1496 //-------------------------------------------------------------------------
1497 // CommandObjectProcessSaveCore
1498 //-------------------------------------------------------------------------
1499 #pragma mark CommandObjectProcessSaveCore
1501 class CommandObjectProcessSaveCore : public CommandObjectParsed
1505 CommandObjectProcessSaveCore (CommandInterpreter &interpreter) :
1506 CommandObjectParsed (interpreter,
1507 "process save-core",
1508 "Save the current process as a core file using an appropriate file type.",
1509 "process save-core FILE",
1510 eCommandRequiresProcess |
1511 eCommandTryTargetAPILock |
1512 eCommandProcessMustBeLaunched)
1516 ~CommandObjectProcessSaveCore ()
1522 DoExecute (Args& command,
1523 CommandReturnObject &result)
1525 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
1528 if (command.GetArgumentCount() == 1)
1530 FileSpec output_file(command.GetArgumentAtIndex(0), false);
1531 Error error = PluginManager::SaveCore(process_sp, output_file);
1532 if (error.Success())
1534 result.SetStatus (eReturnStatusSuccessFinishResult);
1538 result.AppendErrorWithFormat ("Failed to save core file for process: %s\n", error.AsCString());
1539 result.SetStatus (eReturnStatusFailed);
1544 result.AppendErrorWithFormat ("'%s' takes one arguments:\nUsage: %s\n",
1546 m_cmd_syntax.c_str());
1547 result.SetStatus (eReturnStatusFailed);
1552 result.AppendError ("invalid process");
1553 result.SetStatus (eReturnStatusFailed);
1557 return result.Succeeded();
1561 //-------------------------------------------------------------------------
1562 // CommandObjectProcessStatus
1563 //-------------------------------------------------------------------------
1564 #pragma mark CommandObjectProcessStatus
1566 class CommandObjectProcessStatus : public CommandObjectParsed
1569 CommandObjectProcessStatus (CommandInterpreter &interpreter) :
1570 CommandObjectParsed (interpreter,
1572 "Show the current status and location of executing process.",
1574 eCommandRequiresProcess | eCommandTryTargetAPILock)
1578 ~CommandObjectProcessStatus()
1584 DoExecute (Args& command, CommandReturnObject &result)
1586 Stream &strm = result.GetOutputStream();
1587 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1588 // No need to check "process" for validity as eCommandRequiresProcess ensures it is valid
1589 Process *process = m_exe_ctx.GetProcessPtr();
1590 const bool only_threads_with_stop_reason = true;
1591 const uint32_t start_frame = 0;
1592 const uint32_t num_frames = 1;
1593 const uint32_t num_frames_with_source = 1;
1594 process->GetStatus(strm);
1595 process->GetThreadStatus (strm,
1596 only_threads_with_stop_reason,
1599 num_frames_with_source);
1600 return result.Succeeded();
1604 //-------------------------------------------------------------------------
1605 // CommandObjectProcessHandle
1606 //-------------------------------------------------------------------------
1607 #pragma mark CommandObjectProcessHandle
1609 class CommandObjectProcessHandle : public CommandObjectParsed
1613 class CommandOptions : public Options
1617 CommandOptions (CommandInterpreter &interpreter) :
1618 Options (interpreter)
1620 OptionParsingStarting ();
1628 SetOptionValue (uint32_t option_idx, const char *option_arg)
1631 const int short_option = m_getopt_table[option_idx].val;
1633 switch (short_option)
1639 notify = option_arg;
1645 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
1652 OptionParsingStarting ()
1659 const OptionDefinition*
1662 return g_option_table;
1665 // Options table: Required for subclasses of Options.
1667 static OptionDefinition g_option_table[];
1669 // Instance variables to hold the values for command options.
1677 CommandObjectProcessHandle (CommandInterpreter &interpreter) :
1678 CommandObjectParsed (interpreter,
1680 "Show or update what the process and debugger should do with various signals received from the OS.",
1682 m_options (interpreter)
1684 SetHelpLong ("If no signals are specified, update them all. If no update option is specified, list the current values.\n");
1685 CommandArgumentEntry arg;
1686 CommandArgumentData signal_arg;
1688 signal_arg.arg_type = eArgTypeUnixSignal;
1689 signal_arg.arg_repetition = eArgRepeatStar;
1691 arg.push_back (signal_arg);
1693 m_arguments.push_back (arg);
1696 ~CommandObjectProcessHandle ()
1707 VerifyCommandOptionValue (const std::string &option, int &real_value)
1711 bool success = false;
1712 bool tmp_value = Args::StringToBoolean (option.c_str(), false, &success);
1714 if (success && tmp_value)
1716 else if (success && !tmp_value)
1720 // If the value isn't 'true' or 'false', it had better be 0 or 1.
1721 real_value = StringConvert::ToUInt32 (option.c_str(), 3);
1722 if (real_value != 0 && real_value != 1)
1730 PrintSignalHeader (Stream &str)
1732 str.Printf ("NAME PASS STOP NOTIFY\n");
1733 str.Printf ("=========== ===== ===== ======\n");
1737 PrintSignal (Stream &str, int32_t signo, const char *sig_name, UnixSignals &signals)
1743 str.Printf ("%-11s ", sig_name);
1744 if (signals.GetSignalInfo (signo, suppress, stop, notify))
1746 bool pass = !suppress;
1747 str.Printf ("%s %s %s",
1748 (pass ? "true " : "false"),
1749 (stop ? "true " : "false"),
1750 (notify ? "true " : "false"));
1756 PrintSignalInformation (Stream &str, Args &signal_args, int num_valid_signals, UnixSignals &signals)
1758 PrintSignalHeader (str);
1760 if (num_valid_signals > 0)
1762 size_t num_args = signal_args.GetArgumentCount();
1763 for (size_t i = 0; i < num_args; ++i)
1765 int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i));
1766 if (signo != LLDB_INVALID_SIGNAL_NUMBER)
1767 PrintSignal (str, signo, signal_args.GetArgumentAtIndex (i), signals);
1770 else // Print info for ALL signals
1772 int32_t signo = signals.GetFirstSignalNumber();
1773 while (signo != LLDB_INVALID_SIGNAL_NUMBER)
1775 PrintSignal (str, signo, signals.GetSignalAsCString (signo), signals);
1776 signo = signals.GetNextSignalNumber (signo);
1783 DoExecute (Args &signal_args, CommandReturnObject &result)
1785 TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
1789 result.AppendError ("No current target;"
1790 " cannot handle signals until you have a valid target and process.\n");
1791 result.SetStatus (eReturnStatusFailed);
1795 ProcessSP process_sp = target_sp->GetProcessSP();
1799 result.AppendError ("No current process; cannot handle signals until you have a valid process.\n");
1800 result.SetStatus (eReturnStatusFailed);
1804 int stop_action = -1; // -1 means leave the current setting alone
1805 int pass_action = -1; // -1 means leave the current setting alone
1806 int notify_action = -1; // -1 means leave the current setting alone
1808 if (! m_options.stop.empty()
1809 && ! VerifyCommandOptionValue (m_options.stop, stop_action))
1811 result.AppendError ("Invalid argument for command option --stop; must be true or false.\n");
1812 result.SetStatus (eReturnStatusFailed);
1816 if (! m_options.notify.empty()
1817 && ! VerifyCommandOptionValue (m_options.notify, notify_action))
1819 result.AppendError ("Invalid argument for command option --notify; must be true or false.\n");
1820 result.SetStatus (eReturnStatusFailed);
1824 if (! m_options.pass.empty()
1825 && ! VerifyCommandOptionValue (m_options.pass, pass_action))
1827 result.AppendError ("Invalid argument for command option --pass; must be true or false.\n");
1828 result.SetStatus (eReturnStatusFailed);
1832 size_t num_args = signal_args.GetArgumentCount();
1833 UnixSignals &signals = process_sp->GetUnixSignals();
1834 int num_signals_set = 0;
1838 for (size_t i = 0; i < num_args; ++i)
1840 int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i));
1841 if (signo != LLDB_INVALID_SIGNAL_NUMBER)
1843 // Casting the actions as bools here should be okay, because VerifyCommandOptionValue guarantees
1844 // the value is either 0 or 1.
1845 if (stop_action != -1)
1846 signals.SetShouldStop (signo, (bool) stop_action);
1847 if (pass_action != -1)
1849 bool suppress = ! ((bool) pass_action);
1850 signals.SetShouldSuppress (signo, suppress);
1852 if (notify_action != -1)
1853 signals.SetShouldNotify (signo, (bool) notify_action);
1858 result.AppendErrorWithFormat ("Invalid signal name '%s'\n", signal_args.GetArgumentAtIndex (i));
1864 // No signal specified, if any command options were specified, update ALL signals.
1865 if ((notify_action != -1) || (stop_action != -1) || (pass_action != -1))
1867 if (m_interpreter.Confirm ("Do you really want to update all the signals?", false))
1869 int32_t signo = signals.GetFirstSignalNumber();
1870 while (signo != LLDB_INVALID_SIGNAL_NUMBER)
1872 if (notify_action != -1)
1873 signals.SetShouldNotify (signo, (bool) notify_action);
1874 if (stop_action != -1)
1875 signals.SetShouldStop (signo, (bool) stop_action);
1876 if (pass_action != -1)
1878 bool suppress = ! ((bool) pass_action);
1879 signals.SetShouldSuppress (signo, suppress);
1881 signo = signals.GetNextSignalNumber (signo);
1887 PrintSignalInformation (result.GetOutputStream(), signal_args, num_signals_set, signals);
1889 if (num_signals_set > 0)
1890 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1892 result.SetStatus (eReturnStatusFailed);
1894 return result.Succeeded();
1897 CommandOptions m_options;
1901 CommandObjectProcessHandle::CommandOptions::g_option_table[] =
1903 { 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." },
1904 { 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." },
1905 { LLDB_OPT_SET_1, false, "pass", 'p', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "Whether or not the signal should be passed to the process." },
1906 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1909 //-------------------------------------------------------------------------
1910 // CommandObjectMultiwordProcess
1911 //-------------------------------------------------------------------------
1913 CommandObjectMultiwordProcess::CommandObjectMultiwordProcess (CommandInterpreter &interpreter) :
1914 CommandObjectMultiword (interpreter,
1916 "A set of commands for operating on a process.",
1917 "process <subcommand> [<subcommand-options>]")
1919 LoadSubCommand ("attach", CommandObjectSP (new CommandObjectProcessAttach (interpreter)));
1920 LoadSubCommand ("launch", CommandObjectSP (new CommandObjectProcessLaunch (interpreter)));
1921 LoadSubCommand ("continue", CommandObjectSP (new CommandObjectProcessContinue (interpreter)));
1922 LoadSubCommand ("connect", CommandObjectSP (new CommandObjectProcessConnect (interpreter)));
1923 LoadSubCommand ("detach", CommandObjectSP (new CommandObjectProcessDetach (interpreter)));
1924 LoadSubCommand ("load", CommandObjectSP (new CommandObjectProcessLoad (interpreter)));
1925 LoadSubCommand ("unload", CommandObjectSP (new CommandObjectProcessUnload (interpreter)));
1926 LoadSubCommand ("signal", CommandObjectSP (new CommandObjectProcessSignal (interpreter)));
1927 LoadSubCommand ("handle", CommandObjectSP (new CommandObjectProcessHandle (interpreter)));
1928 LoadSubCommand ("status", CommandObjectSP (new CommandObjectProcessStatus (interpreter)));
1929 LoadSubCommand ("interrupt", CommandObjectSP (new CommandObjectProcessInterrupt (interpreter)));
1930 LoadSubCommand ("kill", CommandObjectSP (new CommandObjectProcessKill (interpreter)));
1931 LoadSubCommand ("plugin", CommandObjectSP (new CommandObjectProcessPlugin (interpreter)));
1932 LoadSubCommand ("save-core", CommandObjectSP (new CommandObjectProcessSaveCore (interpreter)));
1935 CommandObjectMultiwordProcess::~CommandObjectMultiwordProcess ()