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 "lldb/lldb-python.h"
12 #include "CommandObjectProcess.h"
16 // Other libraries and framework includes
18 #include "lldb/Breakpoint/Breakpoint.h"
19 #include "lldb/Breakpoint/BreakpointLocation.h"
20 #include "lldb/Breakpoint/BreakpointSite.h"
21 #include "lldb/Core/State.h"
22 #include "lldb/Core/Module.h"
23 #include "lldb/Core/PluginManager.h"
24 #include "lldb/Host/Host.h"
25 #include "lldb/Interpreter/Args.h"
26 #include "lldb/Interpreter/Options.h"
27 #include "lldb/Interpreter/CommandInterpreter.h"
28 #include "lldb/Interpreter/CommandReturnObject.h"
29 #include "lldb/Target/Platform.h"
30 #include "lldb/Target/Process.h"
31 #include "lldb/Target/StopInfo.h"
32 #include "lldb/Target/Target.h"
33 #include "lldb/Target/Thread.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());
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.",
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 Args target_setting_args;
252 if (target->GetRunArguments(target_setting_args))
253 m_options.launch_info.GetArguments().AppendArguments (target_setting_args);
257 m_options.launch_info.GetArguments().AppendArguments (launch_args);
258 // Save the arguments for subsequent runs in the current target.
259 target->SetRunArguments (launch_args);
263 Error error = target->Launch(m_options.launch_info, &stream);
267 const char *archname = exe_module_sp->GetArchitecture().GetArchitectureName();
268 ProcessSP process_sp (target->GetProcessSP());
271 const char *data = stream.GetData();
272 if (data && strlen(data) > 0)
273 result.AppendMessage(stream.GetData());
274 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);
280 result.AppendError("no error returned from Target::Launch, and target has no process");
281 result.SetStatus (eReturnStatusFailed);
286 result.AppendError(error.AsCString());
287 result.SetStatus (eReturnStatusFailed);
289 return result.Succeeded();
293 ProcessLaunchCommandOptions m_options;
297 //#define SET1 LLDB_OPT_SET_1
298 //#define SET2 LLDB_OPT_SET_2
299 //#define SET3 LLDB_OPT_SET_3
302 //CommandObjectProcessLaunch::CommandOptions::g_option_table[] =
304 //{ 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."},
312 //{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
319 //-------------------------------------------------------------------------
320 // CommandObjectProcessAttach
321 //-------------------------------------------------------------------------
322 #pragma mark CommandObjectProcessAttach
323 class CommandObjectProcessAttach : public CommandObjectProcessLaunchOrAttach
327 class CommandOptions : public Options
331 CommandOptions (CommandInterpreter &interpreter) :
334 // Keep default values of all options in one place: OptionParsingStarting ()
335 OptionParsingStarting ();
343 SetOptionValue (uint32_t option_idx, const char *option_arg)
346 const int short_option = m_getopt_table[option_idx].val;
347 bool success = false;
348 switch (short_option)
351 attach_info.SetContinueOnceAttached(true);
356 lldb::pid_t pid = Args::StringToUInt32 (option_arg, LLDB_INVALID_PROCESS_ID, 0, &success);
357 if (!success || pid == LLDB_INVALID_PROCESS_ID)
359 error.SetErrorStringWithFormat("invalid process ID '%s'", option_arg);
363 attach_info.SetProcessID (pid);
369 attach_info.SetProcessPluginName (option_arg);
373 attach_info.GetExecutableFile().SetFile(option_arg, false);
377 attach_info.SetWaitForLaunch(true);
381 attach_info.SetIgnoreExisting(false);
385 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
392 OptionParsingStarting ()
397 const OptionDefinition*
400 return g_option_table;
404 HandleOptionArgumentCompletion (Args &input,
407 OptionElementVector &opt_element_vector,
408 int opt_element_index,
409 int match_start_point,
410 int max_return_elements,
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;
417 // We are only completing the name option for now...
419 const OptionDefinition *opt_defs = GetDefinitions();
420 if (opt_defs[opt_defs_index].short_option == 'n')
422 // Are we in the name?
424 // Look to see if there is a -P argument provided, and if so use that plugin, otherwise
425 // use the default plugin.
427 const char *partial_name = NULL;
428 partial_name = input.GetArgumentAtIndex(opt_arg_pos);
430 PlatformSP platform_sp (m_interpreter.GetPlatform (true));
433 ProcessInstanceInfoList process_infos;
434 ProcessInstanceInfoMatch match_info;
437 match_info.GetProcessInfo().GetExecutableFile().SetFile(partial_name, false);
438 match_info.SetNameMatchType(eNameMatchStartsWith);
440 platform_sp->FindProcesses (match_info, process_infos);
441 const size_t num_matches = process_infos.GetSize();
444 for (size_t i=0; i<num_matches; ++i)
446 matches.AppendString (process_infos.GetProcessNameAtIndex(i),
447 process_infos.GetProcessNameLengthAtIndex(i));
456 // Options table: Required for subclasses of Options.
458 static OptionDefinition g_option_table[];
460 // Instance variables to hold the values for command options.
462 ProcessAttachInfo attach_info;
465 CommandObjectProcessAttach (CommandInterpreter &interpreter) :
466 CommandObjectProcessLaunchOrAttach (interpreter,
468 "Attach to a process.",
469 "process attach <cmd-options>",
472 m_options (interpreter)
476 ~CommandObjectProcessAttach ()
488 DoExecute (Args& command,
489 CommandReturnObject &result)
491 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
492 // 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
496 StateType state = eStateInvalid;
497 Process *process = m_exe_ctx.GetProcessPtr();
499 if (!StopProcessIfNecessary (process, state, result))
504 // If there isn't a current target create one.
505 TargetSP new_target_sp;
508 error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
512 NULL, // No platform options
514 target = new_target_sp.get();
515 if (target == NULL || error.Fail())
517 result.AppendError(error.AsCString("Error creating target"));
520 m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target);
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.)
526 ModuleSP old_exec_module_sp = target->GetExecutableModule();
527 ArchSpec old_arch_spec = target->GetArchitecture();
529 if (command.GetArgumentCount())
531 result.AppendErrorWithFormat("Invalid arguments for '%s'.\nUsage: %s\n", m_cmd_name.c_str(), m_cmd_syntax.c_str());
532 result.SetStatus (eReturnStatusFailed);
536 if (state != eStateConnected)
538 const char *plugin_name = m_options.attach_info.GetProcessPluginName();
539 process = target->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name, NULL).get();
545 // 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 ())
549 if (old_exec_module_sp)
550 m_options.attach_info.GetExecutableFile().GetFilename() = old_exec_module_sp->GetPlatformFileSpec().GetFilename();
552 if (!m_options.attach_info.ProcessInfoSpecified ())
554 error.SetErrorString ("no process specified, create a target with a file, or specify the --pid or --name command option");
560 // Update the execution context so the current target and process are now selected
561 // in case we interrupt
562 m_interpreter.UpdateExecutionContext(NULL);
563 ListenerSP listener_sp (new Listener("lldb.CommandObjectProcessAttach.DoExecute.attach.hijack"));
564 m_options.attach_info.SetHijackListener(listener_sp);
565 process->HijackProcessEvents(listener_sp.get());
566 error = process->Attach (m_options.attach_info);
570 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
572 StateType state = process->WaitForProcessToStop (NULL, NULL, false, listener_sp.get(), &stream);
574 process->RestoreProcessEvents();
576 result.SetDidChangeProcessState (true);
578 if (stream.GetData())
579 result.AppendMessage(stream.GetData());
581 if (state == eStateStopped)
583 result.SetStatus (eReturnStatusSuccessFinishNoResult);
587 const char *exit_desc = process->GetExitDescription();
589 result.AppendErrorWithFormat ("attach failed: %s", exit_desc);
591 result.AppendError ("attach failed: process did not stop (no such process or permission problem?)");
593 result.SetStatus (eReturnStatusFailed);
598 result.AppendErrorWithFormat ("attach failed: %s\n", error.AsCString());
599 result.SetStatus (eReturnStatusFailed);
605 if (result.Succeeded())
607 // Okay, we're done. Last step is to warn if the executable module has changed:
608 char new_path[PATH_MAX];
609 ModuleSP new_exec_module_sp (target->GetExecutableModule());
610 if (!old_exec_module_sp)
612 // We might not have a module if we attached to a raw pid...
613 if (new_exec_module_sp)
615 new_exec_module_sp->GetFileSpec().GetPath(new_path, PATH_MAX);
616 result.AppendMessageWithFormat("Executable module set to \"%s\".\n", new_path);
619 else if (old_exec_module_sp->GetFileSpec() != new_exec_module_sp->GetFileSpec())
621 char old_path[PATH_MAX];
623 old_exec_module_sp->GetFileSpec().GetPath (old_path, PATH_MAX);
624 new_exec_module_sp->GetFileSpec().GetPath (new_path, PATH_MAX);
626 result.AppendWarningWithFormat("Executable module changed from \"%s\" to \"%s\".\n",
630 if (!old_arch_spec.IsValid())
632 result.AppendMessageWithFormat ("Architecture set to: %s.\n", target->GetArchitecture().GetTriple().getTriple().c_str());
634 else if (!old_arch_spec.IsExactMatch(target->GetArchitecture()))
636 result.AppendWarningWithFormat("Architecture changed from %s to %s.\n",
637 old_arch_spec.GetTriple().getTriple().c_str(),
638 target->GetArchitecture().GetTriple().getTriple().c_str());
641 // This supports the use-case scenario of immediately continuing the process once attached.
642 if (m_options.attach_info.GetContinueOnceAttached())
643 m_interpreter.HandleCommand("process continue", eLazyBoolNo, result);
645 return result.Succeeded();
648 CommandOptions m_options;
653 CommandObjectProcessAttach::CommandOptions::g_option_table[] =
655 { 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 }
664 //-------------------------------------------------------------------------
665 // CommandObjectProcessContinue
666 //-------------------------------------------------------------------------
667 #pragma mark CommandObjectProcessContinue
669 class CommandObjectProcessContinue : public CommandObjectParsed
673 CommandObjectProcessContinue (CommandInterpreter &interpreter) :
674 CommandObjectParsed (interpreter,
676 "Continue execution of all threads in the current process.",
678 eFlagRequiresProcess |
679 eFlagTryTargetAPILock |
680 eFlagProcessMustBeLaunched |
681 eFlagProcessMustBePaused ),
682 m_options(interpreter)
687 ~CommandObjectProcessContinue ()
693 class CommandOptions : public Options
697 CommandOptions (CommandInterpreter &interpreter) :
700 // Keep default values of all options in one place: OptionParsingStarting ()
701 OptionParsingStarting ();
709 SetOptionValue (uint32_t option_idx, const char *option_arg)
712 const int short_option = m_getopt_table[option_idx].val;
713 bool success = false;
714 switch (short_option)
717 m_ignore = Args::StringToUInt32 (option_arg, 0, 0, &success);
719 error.SetErrorStringWithFormat ("invalid value for ignore option: \"%s\", should be a number.", option_arg);
723 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
730 OptionParsingStarting ()
735 const OptionDefinition*
738 return g_option_table;
741 // Options table: Required for subclasses of Options.
743 static OptionDefinition g_option_table[];
749 DoExecute (Args& command, CommandReturnObject &result)
751 Process *process = m_exe_ctx.GetProcessPtr();
752 bool synchronous_execution = m_interpreter.GetSynchronous ();
753 StateType state = process->GetState();
754 if (state == eStateStopped)
756 if (command.GetArgumentCount() != 0)
758 result.AppendErrorWithFormat ("The '%s' command does not take any arguments.\n", m_cmd_name.c_str());
759 result.SetStatus (eReturnStatusFailed);
763 if (m_options.m_ignore > 0)
765 ThreadSP sel_thread_sp(process->GetThreadList().GetSelectedThread());
768 StopInfoSP stop_info_sp = sel_thread_sp->GetStopInfo();
769 if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonBreakpoint)
771 lldb::break_id_t bp_site_id = (lldb::break_id_t)stop_info_sp->GetValue();
772 BreakpointSiteSP bp_site_sp(process->GetBreakpointSiteList().FindByID(bp_site_id));
775 const size_t num_owners = bp_site_sp->GetNumberOfOwners();
776 for (size_t i = 0; i < num_owners; i++)
778 Breakpoint &bp_ref = bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint();
779 if (!bp_ref.IsInternal())
781 bp_ref.SetIgnoreCount(m_options.m_ignore);
789 { // Scope for thread list mutex:
790 Mutex::Locker locker (process->GetThreadList().GetMutex());
791 const uint32_t num_threads = process->GetThreadList().GetSize();
793 // Set the actions that the threads should each take when resuming
794 for (uint32_t idx=0; idx<num_threads; ++idx)
796 const bool override_suspend = false;
797 process->GetThreadList().GetThreadAtIndex(idx)->SetResumeState (eStateRunning, override_suspend);
803 if (synchronous_execution)
804 error = process->ResumeSynchronous (&stream);
806 error = process->Resume ();
810 // 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);
815 result.AppendMessageWithFormat ("Process %" PRIu64 " resuming\n", process->GetID());
816 if (synchronous_execution)
818 // If any state changed events had anything to say, add that to the result
819 if (stream.GetData())
820 result.AppendMessage(stream.GetData());
822 result.SetDidChangeProcessState (true);
823 result.SetStatus (eReturnStatusSuccessFinishNoResult);
827 result.SetStatus (eReturnStatusSuccessContinuingNoResult);
832 result.AppendErrorWithFormat("Failed to resume process: %s.\n", error.AsCString());
833 result.SetStatus (eReturnStatusFailed);
838 result.AppendErrorWithFormat ("Process cannot be continued from its current state (%s).\n",
839 StateAsCString(state));
840 result.SetStatus (eReturnStatusFailed);
842 return result.Succeeded();
851 CommandOptions m_options;
856 CommandObjectProcessContinue::CommandOptions::g_option_table[] =
858 { LLDB_OPT_SET_ALL, false, "ignore-count",'i', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeUnsignedInteger,
859 "Ignore <N> crossings of the breakpoint (if it exists) for the currently selected thread."},
860 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
863 //-------------------------------------------------------------------------
864 // CommandObjectProcessDetach
865 //-------------------------------------------------------------------------
866 #pragma mark CommandObjectProcessDetach
868 class CommandObjectProcessDetach : public CommandObjectParsed
871 class CommandOptions : public Options
875 CommandOptions (CommandInterpreter &interpreter) :
876 Options (interpreter)
878 OptionParsingStarting ();
886 SetOptionValue (uint32_t option_idx, const char *option_arg)
889 const int short_option = m_getopt_table[option_idx].val;
891 switch (short_option)
896 tmp_result = Args::StringToBoolean(option_arg, false, &success);
898 error.SetErrorStringWithFormat("invalid boolean option: \"%s\"", option_arg);
902 m_keep_stopped = eLazyBoolYes;
904 m_keep_stopped = eLazyBoolNo;
908 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
915 OptionParsingStarting ()
917 m_keep_stopped = eLazyBoolCalculate;
920 const OptionDefinition*
923 return g_option_table;
926 // Options table: Required for subclasses of Options.
928 static OptionDefinition g_option_table[];
930 // Instance variables to hold the values for command options.
931 LazyBool m_keep_stopped;
934 CommandObjectProcessDetach (CommandInterpreter &interpreter) :
935 CommandObjectParsed (interpreter,
937 "Detach from the current process being debugged.",
939 eFlagRequiresProcess |
940 eFlagTryTargetAPILock |
941 eFlagProcessMustBeLaunched),
942 m_options(interpreter)
946 ~CommandObjectProcessDetach ()
959 DoExecute (Args& command, CommandReturnObject &result)
961 Process *process = m_exe_ctx.GetProcessPtr();
962 // FIXME: This will be a Command Option:
964 if (m_options.m_keep_stopped == eLazyBoolCalculate)
966 // Check the process default:
967 if (process->GetDetachKeepsStopped())
970 keep_stopped = false;
972 else if (m_options.m_keep_stopped == eLazyBoolYes)
975 keep_stopped = false;
977 Error error (process->Detach(keep_stopped));
980 result.SetStatus (eReturnStatusSuccessFinishResult);
984 result.AppendErrorWithFormat ("Detach failed: %s\n", error.AsCString());
985 result.SetStatus (eReturnStatusFailed);
988 return result.Succeeded();
991 CommandOptions m_options;
995 CommandObjectProcessDetach::CommandOptions::g_option_table[] =
997 { 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 }
1001 //-------------------------------------------------------------------------
1002 // CommandObjectProcessConnect
1003 //-------------------------------------------------------------------------
1004 #pragma mark CommandObjectProcessConnect
1006 class CommandObjectProcessConnect : public CommandObjectParsed
1010 class CommandOptions : public Options
1014 CommandOptions (CommandInterpreter &interpreter) :
1015 Options(interpreter)
1017 // Keep default values of all options in one place: OptionParsingStarting ()
1018 OptionParsingStarting ();
1026 SetOptionValue (uint32_t option_idx, const char *option_arg)
1029 const int short_option = m_getopt_table[option_idx].val;
1031 switch (short_option)
1034 plugin_name.assign (option_arg);
1038 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
1045 OptionParsingStarting ()
1047 plugin_name.clear();
1050 const OptionDefinition*
1053 return g_option_table;
1056 // Options table: Required for subclasses of Options.
1058 static OptionDefinition g_option_table[];
1060 // Instance variables to hold the values for command options.
1062 std::string plugin_name;
1065 CommandObjectProcessConnect (CommandInterpreter &interpreter) :
1066 CommandObjectParsed (interpreter,
1068 "Connect to a remote debug service.",
1069 "process connect <remote-url>",
1071 m_options (interpreter)
1075 ~CommandObjectProcessConnect ()
1088 DoExecute (Args& command,
1089 CommandReturnObject &result)
1092 TargetSP target_sp (m_interpreter.GetDebugger().GetSelectedTarget());
1094 Process *process = m_exe_ctx.GetProcessPtr();
1097 if (process->IsAlive())
1099 result.AppendErrorWithFormat ("Process %" PRIu64 " is currently being debugged, kill the process before connecting.\n",
1101 result.SetStatus (eReturnStatusFailed);
1108 // If there isn't a current target create one.
1110 error = m_interpreter.GetDebugger().GetTargetList().CreateTarget (m_interpreter.GetDebugger(),
1114 NULL, // No platform options
1116 if (!target_sp || error.Fail())
1118 result.AppendError(error.AsCString("Error creating target"));
1119 result.SetStatus (eReturnStatusFailed);
1122 m_interpreter.GetDebugger().GetTargetList().SetSelectedTarget(target_sp.get());
1125 if (command.GetArgumentCount() == 1)
1127 const char *plugin_name = NULL;
1128 if (!m_options.plugin_name.empty())
1129 plugin_name = m_options.plugin_name.c_str();
1131 const char *remote_url = command.GetArgumentAtIndex(0);
1132 process = target_sp->CreateProcess (m_interpreter.GetDebugger().GetListener(), plugin_name, NULL).get();
1136 error = process->ConnectRemote (process->GetTarget().GetDebugger().GetOutputFile().get(), remote_url);
1140 result.AppendError(error.AsCString("Remote connect failed"));
1141 result.SetStatus (eReturnStatusFailed);
1142 target_sp->DeleteCurrentProcess();
1148 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",
1150 result.SetStatus (eReturnStatusFailed);
1155 result.AppendErrorWithFormat ("'%s' takes exactly one argument:\nUsage: %s\n",
1157 m_cmd_syntax.c_str());
1158 result.SetStatus (eReturnStatusFailed);
1160 return result.Succeeded();
1163 CommandOptions m_options;
1167 CommandObjectProcessConnect::CommandOptions::g_option_table[] =
1169 { 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 }
1173 //-------------------------------------------------------------------------
1174 // CommandObjectProcessPlugin
1175 //-------------------------------------------------------------------------
1176 #pragma mark CommandObjectProcessPlugin
1178 class CommandObjectProcessPlugin : public CommandObjectProxy
1182 CommandObjectProcessPlugin (CommandInterpreter &interpreter) :
1183 CommandObjectProxy (interpreter,
1185 "Send a custom command to the current process plug-in.",
1186 "process plugin <args>",
1191 ~CommandObjectProcessPlugin ()
1195 virtual CommandObject *
1196 GetProxyCommandObject()
1198 Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
1200 return process->GetPluginCommandObject();
1206 //-------------------------------------------------------------------------
1207 // CommandObjectProcessLoad
1208 //-------------------------------------------------------------------------
1209 #pragma mark CommandObjectProcessLoad
1211 class CommandObjectProcessLoad : public CommandObjectParsed
1215 CommandObjectProcessLoad (CommandInterpreter &interpreter) :
1216 CommandObjectParsed (interpreter,
1218 "Load a shared library into the current process.",
1219 "process load <filename> [<filename> ...]",
1220 eFlagRequiresProcess |
1221 eFlagTryTargetAPILock |
1222 eFlagProcessMustBeLaunched |
1223 eFlagProcessMustBePaused )
1227 ~CommandObjectProcessLoad ()
1233 DoExecute (Args& command,
1234 CommandReturnObject &result)
1236 Process *process = m_exe_ctx.GetProcessPtr();
1238 const size_t argc = command.GetArgumentCount();
1240 for (uint32_t i=0; i<argc; ++i)
1243 const char *image_path = command.GetArgumentAtIndex(i);
1244 FileSpec image_spec (image_path, false);
1245 process->GetTarget().GetPlatform()->ResolveRemotePath(image_spec, image_spec);
1246 uint32_t image_token = process->LoadImage(image_spec, error);
1247 if (image_token != LLDB_INVALID_IMAGE_TOKEN)
1249 result.AppendMessageWithFormat ("Loading \"%s\"...ok\nImage %u loaded.\n", image_path, image_token);
1250 result.SetStatus (eReturnStatusSuccessFinishResult);
1254 result.AppendErrorWithFormat ("failed to load '%s': %s", image_path, error.AsCString());
1255 result.SetStatus (eReturnStatusFailed);
1258 return result.Succeeded();
1263 //-------------------------------------------------------------------------
1264 // CommandObjectProcessUnload
1265 //-------------------------------------------------------------------------
1266 #pragma mark CommandObjectProcessUnload
1268 class CommandObjectProcessUnload : public CommandObjectParsed
1272 CommandObjectProcessUnload (CommandInterpreter &interpreter) :
1273 CommandObjectParsed (interpreter,
1275 "Unload a shared library from the current process using the index returned by a previous call to \"process load\".",
1276 "process unload <index>",
1277 eFlagRequiresProcess |
1278 eFlagTryTargetAPILock |
1279 eFlagProcessMustBeLaunched |
1280 eFlagProcessMustBePaused )
1284 ~CommandObjectProcessUnload ()
1290 DoExecute (Args& command,
1291 CommandReturnObject &result)
1293 Process *process = m_exe_ctx.GetProcessPtr();
1295 const size_t argc = command.GetArgumentCount();
1297 for (uint32_t i=0; i<argc; ++i)
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)
1303 result.AppendErrorWithFormat ("invalid image index argument '%s'", image_token_cstr);
1304 result.SetStatus (eReturnStatusFailed);
1309 Error error (process->UnloadImage(image_token));
1310 if (error.Success())
1312 result.AppendMessageWithFormat ("Unloading shared library with index %u...ok\n", image_token);
1313 result.SetStatus (eReturnStatusSuccessFinishResult);
1317 result.AppendErrorWithFormat ("failed to unload image: %s", error.AsCString());
1318 result.SetStatus (eReturnStatusFailed);
1323 return result.Succeeded();
1327 //-------------------------------------------------------------------------
1328 // CommandObjectProcessSignal
1329 //-------------------------------------------------------------------------
1330 #pragma mark CommandObjectProcessSignal
1332 class CommandObjectProcessSignal : public CommandObjectParsed
1336 CommandObjectProcessSignal (CommandInterpreter &interpreter) :
1337 CommandObjectParsed (interpreter,
1339 "Send a UNIX signal to the current process being debugged.",
1341 eFlagRequiresProcess | eFlagTryTargetAPILock)
1343 CommandArgumentEntry arg;
1344 CommandArgumentData signal_arg;
1346 // Define the first (and only) variant of this arg.
1347 signal_arg.arg_type = eArgTypeUnixSignal;
1348 signal_arg.arg_repetition = eArgRepeatPlain;
1350 // There is only one variant this argument could be; put it into the argument entry.
1351 arg.push_back (signal_arg);
1353 // Push the data for the first argument into the m_arguments vector.
1354 m_arguments.push_back (arg);
1357 ~CommandObjectProcessSignal ()
1363 DoExecute (Args& command,
1364 CommandReturnObject &result)
1366 Process *process = m_exe_ctx.GetProcessPtr();
1368 if (command.GetArgumentCount() == 1)
1370 int signo = LLDB_INVALID_SIGNAL_NUMBER;
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);
1376 signo = process->GetUnixSignals().GetSignalNumberFromName (signal_name);
1378 if (signo == LLDB_INVALID_SIGNAL_NUMBER)
1380 result.AppendErrorWithFormat ("Invalid signal argument '%s'.\n", command.GetArgumentAtIndex(0));
1381 result.SetStatus (eReturnStatusFailed);
1385 Error error (process->Signal (signo));
1386 if (error.Success())
1388 result.SetStatus (eReturnStatusSuccessFinishResult);
1392 result.AppendErrorWithFormat ("Failed to send signal %i: %s\n", signo, error.AsCString());
1393 result.SetStatus (eReturnStatusFailed);
1399 result.AppendErrorWithFormat("'%s' takes exactly one signal number argument:\nUsage: %s\n", m_cmd_name.c_str(),
1400 m_cmd_syntax.c_str());
1401 result.SetStatus (eReturnStatusFailed);
1403 return result.Succeeded();
1408 //-------------------------------------------------------------------------
1409 // CommandObjectProcessInterrupt
1410 //-------------------------------------------------------------------------
1411 #pragma mark CommandObjectProcessInterrupt
1413 class CommandObjectProcessInterrupt : public CommandObjectParsed
1418 CommandObjectProcessInterrupt (CommandInterpreter &interpreter) :
1419 CommandObjectParsed (interpreter,
1420 "process interrupt",
1421 "Interrupt the current process being debugged.",
1422 "process interrupt",
1423 eFlagRequiresProcess |
1424 eFlagTryTargetAPILock |
1425 eFlagProcessMustBeLaunched)
1429 ~CommandObjectProcessInterrupt ()
1435 DoExecute (Args& command,
1436 CommandReturnObject &result)
1438 Process *process = m_exe_ctx.GetProcessPtr();
1439 if (process == NULL)
1441 result.AppendError ("no process to halt");
1442 result.SetStatus (eReturnStatusFailed);
1446 if (command.GetArgumentCount() == 0)
1448 bool clear_thread_plans = true;
1449 Error error(process->Halt (clear_thread_plans));
1450 if (error.Success())
1452 result.SetStatus (eReturnStatusSuccessFinishResult);
1456 result.AppendErrorWithFormat ("Failed to halt process: %s\n", error.AsCString());
1457 result.SetStatus (eReturnStatusFailed);
1462 result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
1464 m_cmd_syntax.c_str());
1465 result.SetStatus (eReturnStatusFailed);
1467 return result.Succeeded();
1471 //-------------------------------------------------------------------------
1472 // CommandObjectProcessKill
1473 //-------------------------------------------------------------------------
1474 #pragma mark CommandObjectProcessKill
1476 class CommandObjectProcessKill : public CommandObjectParsed
1480 CommandObjectProcessKill (CommandInterpreter &interpreter) :
1481 CommandObjectParsed (interpreter,
1483 "Terminate the current process being debugged.",
1485 eFlagRequiresProcess |
1486 eFlagTryTargetAPILock |
1487 eFlagProcessMustBeLaunched)
1491 ~CommandObjectProcessKill ()
1497 DoExecute (Args& command,
1498 CommandReturnObject &result)
1500 Process *process = m_exe_ctx.GetProcessPtr();
1501 if (process == NULL)
1503 result.AppendError ("no process to kill");
1504 result.SetStatus (eReturnStatusFailed);
1508 if (command.GetArgumentCount() == 0)
1510 Error error (process->Destroy());
1511 if (error.Success())
1513 result.SetStatus (eReturnStatusSuccessFinishResult);
1517 result.AppendErrorWithFormat ("Failed to kill process: %s\n", error.AsCString());
1518 result.SetStatus (eReturnStatusFailed);
1523 result.AppendErrorWithFormat("'%s' takes no arguments:\nUsage: %s\n",
1525 m_cmd_syntax.c_str());
1526 result.SetStatus (eReturnStatusFailed);
1528 return result.Succeeded();
1532 //-------------------------------------------------------------------------
1533 // CommandObjectProcessSaveCore
1534 //-------------------------------------------------------------------------
1535 #pragma mark CommandObjectProcessSaveCore
1537 class CommandObjectProcessSaveCore : public CommandObjectParsed
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)
1552 ~CommandObjectProcessSaveCore ()
1558 DoExecute (Args& command,
1559 CommandReturnObject &result)
1561 ProcessSP process_sp = m_exe_ctx.GetProcessSP();
1564 if (command.GetArgumentCount() == 1)
1566 FileSpec output_file(command.GetArgumentAtIndex(0), false);
1567 Error error = PluginManager::SaveCore(process_sp, output_file);
1568 if (error.Success())
1570 result.SetStatus (eReturnStatusSuccessFinishResult);
1574 result.AppendErrorWithFormat ("Failed to save core file for process: %s\n", error.AsCString());
1575 result.SetStatus (eReturnStatusFailed);
1580 result.AppendErrorWithFormat ("'%s' takes one arguments:\nUsage: %s\n",
1582 m_cmd_syntax.c_str());
1583 result.SetStatus (eReturnStatusFailed);
1588 result.AppendError ("invalid process");
1589 result.SetStatus (eReturnStatusFailed);
1593 return result.Succeeded();
1597 //-------------------------------------------------------------------------
1598 // CommandObjectProcessStatus
1599 //-------------------------------------------------------------------------
1600 #pragma mark CommandObjectProcessStatus
1602 class CommandObjectProcessStatus : public CommandObjectParsed
1605 CommandObjectProcessStatus (CommandInterpreter &interpreter) :
1606 CommandObjectParsed (interpreter,
1608 "Show the current status and location of executing process.",
1610 eFlagRequiresProcess | eFlagTryTargetAPILock)
1614 ~CommandObjectProcessStatus()
1620 DoExecute (Args& command, CommandReturnObject &result)
1622 Stream &strm = result.GetOutputStream();
1623 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1624 // 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,
1635 num_frames_with_source);
1636 return result.Succeeded();
1640 //-------------------------------------------------------------------------
1641 // CommandObjectProcessHandle
1642 //-------------------------------------------------------------------------
1643 #pragma mark CommandObjectProcessHandle
1645 class CommandObjectProcessHandle : public CommandObjectParsed
1649 class CommandOptions : public Options
1653 CommandOptions (CommandInterpreter &interpreter) :
1654 Options (interpreter)
1656 OptionParsingStarting ();
1664 SetOptionValue (uint32_t option_idx, const char *option_arg)
1667 const int short_option = m_getopt_table[option_idx].val;
1669 switch (short_option)
1675 notify = option_arg;
1681 error.SetErrorStringWithFormat("invalid short option character '%c'", short_option);
1688 OptionParsingStarting ()
1695 const OptionDefinition*
1698 return g_option_table;
1701 // Options table: Required for subclasses of Options.
1703 static OptionDefinition g_option_table[];
1705 // Instance variables to hold the values for command options.
1713 CommandObjectProcessHandle (CommandInterpreter &interpreter) :
1714 CommandObjectParsed (interpreter,
1716 "Show or update what the process and debugger should do with various signals received from the OS.",
1718 m_options (interpreter)
1720 SetHelpLong ("If no signals are specified, update them all. If no update option is specified, list the current values.\n");
1721 CommandArgumentEntry arg;
1722 CommandArgumentData signal_arg;
1724 signal_arg.arg_type = eArgTypeUnixSignal;
1725 signal_arg.arg_repetition = eArgRepeatStar;
1727 arg.push_back (signal_arg);
1729 m_arguments.push_back (arg);
1732 ~CommandObjectProcessHandle ()
1743 VerifyCommandOptionValue (const std::string &option, int &real_value)
1747 bool success = false;
1748 bool tmp_value = Args::StringToBoolean (option.c_str(), false, &success);
1750 if (success && tmp_value)
1752 else if (success && !tmp_value)
1756 // If the value isn't 'true' or 'false', it had better be 0 or 1.
1757 real_value = Args::StringToUInt32 (option.c_str(), 3);
1758 if (real_value != 0 && real_value != 1)
1766 PrintSignalHeader (Stream &str)
1768 str.Printf ("NAME PASS STOP NOTIFY\n");
1769 str.Printf ("========== ===== ===== ======\n");
1773 PrintSignal (Stream &str, int32_t signo, const char *sig_name, UnixSignals &signals)
1779 str.Printf ("%-10s ", sig_name);
1780 if (signals.GetSignalInfo (signo, suppress, stop, notify))
1782 bool pass = !suppress;
1783 str.Printf ("%s %s %s",
1784 (pass ? "true " : "false"),
1785 (stop ? "true " : "false"),
1786 (notify ? "true " : "false"));
1792 PrintSignalInformation (Stream &str, Args &signal_args, int num_valid_signals, UnixSignals &signals)
1794 PrintSignalHeader (str);
1796 if (num_valid_signals > 0)
1798 size_t num_args = signal_args.GetArgumentCount();
1799 for (size_t i = 0; i < num_args; ++i)
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);
1806 else // Print info for ALL signals
1808 int32_t signo = signals.GetFirstSignalNumber();
1809 while (signo != LLDB_INVALID_SIGNAL_NUMBER)
1811 PrintSignal (str, signo, signals.GetSignalAsCString (signo), signals);
1812 signo = signals.GetNextSignalNumber (signo);
1819 DoExecute (Args &signal_args, CommandReturnObject &result)
1821 TargetSP target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
1825 result.AppendError ("No current target;"
1826 " cannot handle signals until you have a valid target and process.\n");
1827 result.SetStatus (eReturnStatusFailed);
1831 ProcessSP process_sp = target_sp->GetProcessSP();
1835 result.AppendError ("No current process; cannot handle signals until you have a valid process.\n");
1836 result.SetStatus (eReturnStatusFailed);
1840 int stop_action = -1; // -1 means leave the current setting alone
1841 int pass_action = -1; // -1 means leave the current setting alone
1842 int notify_action = -1; // -1 means leave the current setting alone
1844 if (! m_options.stop.empty()
1845 && ! VerifyCommandOptionValue (m_options.stop, stop_action))
1847 result.AppendError ("Invalid argument for command option --stop; must be true or false.\n");
1848 result.SetStatus (eReturnStatusFailed);
1852 if (! m_options.notify.empty()
1853 && ! VerifyCommandOptionValue (m_options.notify, notify_action))
1855 result.AppendError ("Invalid argument for command option --notify; must be true or false.\n");
1856 result.SetStatus (eReturnStatusFailed);
1860 if (! m_options.pass.empty()
1861 && ! VerifyCommandOptionValue (m_options.pass, pass_action))
1863 result.AppendError ("Invalid argument for command option --pass; must be true or false.\n");
1864 result.SetStatus (eReturnStatusFailed);
1868 size_t num_args = signal_args.GetArgumentCount();
1869 UnixSignals &signals = process_sp->GetUnixSignals();
1870 int num_signals_set = 0;
1874 for (size_t i = 0; i < num_args; ++i)
1876 int32_t signo = signals.GetSignalNumberFromName (signal_args.GetArgumentAtIndex (i));
1877 if (signo != LLDB_INVALID_SIGNAL_NUMBER)
1879 // 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)
1885 bool suppress = ! ((bool) pass_action);
1886 signals.SetShouldSuppress (signo, suppress);
1888 if (notify_action != -1)
1889 signals.SetShouldNotify (signo, (bool) notify_action);
1894 result.AppendErrorWithFormat ("Invalid signal name '%s'\n", signal_args.GetArgumentAtIndex (i));
1900 // No signal specified, if any command options were specified, update ALL signals.
1901 if ((notify_action != -1) || (stop_action != -1) || (pass_action != -1))
1903 if (m_interpreter.Confirm ("Do you really want to update all the signals?", false))
1905 int32_t signo = signals.GetFirstSignalNumber();
1906 while (signo != LLDB_INVALID_SIGNAL_NUMBER)
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)
1914 bool suppress = ! ((bool) pass_action);
1915 signals.SetShouldSuppress (signo, suppress);
1917 signo = signals.GetNextSignalNumber (signo);
1923 PrintSignalInformation (result.GetOutputStream(), signal_args, num_signals_set, signals);
1925 if (num_signals_set > 0)
1926 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1928 result.SetStatus (eReturnStatusFailed);
1930 return result.Succeeded();
1933 CommandOptions m_options;
1937 CommandObjectProcessHandle::CommandOptions::g_option_table[] =
1939 { 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 }
1945 //-------------------------------------------------------------------------
1946 // CommandObjectMultiwordProcess
1947 //-------------------------------------------------------------------------
1949 CommandObjectMultiwordProcess::CommandObjectMultiwordProcess (CommandInterpreter &interpreter) :
1950 CommandObjectMultiword (interpreter,
1952 "A set of commands for operating on a process.",
1953 "process <subcommand> [<subcommand-options>]")
1955 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)));
1965 LoadSubCommand ("interrupt", CommandObjectSP (new CommandObjectProcessInterrupt (interpreter)));
1966 LoadSubCommand ("kill", CommandObjectSP (new CommandObjectProcessKill (interpreter)));
1967 LoadSubCommand ("plugin", CommandObjectSP (new CommandObjectProcessPlugin (interpreter)));
1968 LoadSubCommand ("save-core", CommandObjectSP (new CommandObjectProcessSaveCore (interpreter)));
1971 CommandObjectMultiwordProcess::~CommandObjectMultiwordProcess ()