Moved the execution context that was in the Debugger into
the CommandInterpreter where it was always being used.
Make sure that Modules can track their object file offsets correctly to
allow opening of sub object files (like the "__commpage" on darwin).
Modified the Platforms to be able to launch processes. The first part of this
move is the platform soon will become the entity that launches your program
and when it does, it uses a new ProcessLaunchInfo class which encapsulates
all process launching settings. This simplifies the internal APIs needed for
launching. I want to slowly phase out process launching from the process
classes, so for now we can still launch just as we used to, but eventually
the platform is the object that should do the launching.
Modified the Host::LaunchProcess in the MacOSX Host.mm to correctly be able
to launch processes with all of the new eLaunchFlag settings. Modified any
code that was manually launching processes to use the Host::LaunchProcess
functions.
Fixed an issue where lldb_private::Args had implicitly defined copy
constructors that could do the wrong thing. This has now been fixed by adding
an appropriate copy constructor and assignment operator.
Make sure we don't add empty ModuleSP entries to a module list.
Fixed the commpage module creation on MacOSX, but we still need to train
the MacOSX dynamic loader to not get rid of it when it doesn't have an entry
in the all image infos.
Abstracted many more calls from in ProcessGDBRemote down into the
GDBRemoteCommunicationClient subclass to make the classes cleaner and more
efficient.
Fixed the default iOS ARM register context to be correct and also added support
for targets that don't support the qThreadStopInfo packet by selecting the
current thread (only if needed) and then sending a stop reply packet.
Debugserver can now start up with a --unix-socket (-u for short) and can
then bind to port zero and send the port it bound to to a listening process
on the other end. This allows the GDB remote platform to spawn new GDB server
instances (debugserver) to allow platform debugging.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@129351 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectPlatform.cpp b/source/Commands/CommandObjectPlatform.cpp
index a72b0db4..730a1b3 100644
--- a/source/Commands/CommandObjectPlatform.cpp
+++ b/source/Commands/CommandObjectPlatform.cpp
@@ -413,6 +413,134 @@
return result.Succeeded();
}
};
+//----------------------------------------------------------------------
+// "platform process launch"
+//----------------------------------------------------------------------
+class CommandObjectPlatformProcessLaunch : public CommandObject
+{
+public:
+ CommandObjectPlatformProcessLaunch (CommandInterpreter &interpreter) :
+ CommandObject (interpreter,
+ "platform process launch",
+ "Launch a new process on a remote platform.",
+ "platform process launch program",
+ 0),
+ m_options (interpreter)
+ {
+ }
+
+ virtual
+ ~CommandObjectPlatformProcessLaunch ()
+ {
+ }
+
+ virtual bool
+ Execute (Args& args, CommandReturnObject &result)
+ {
+ PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
+
+ if (platform_sp)
+ {
+ Error error;
+ const uint32_t argc = args.GetArgumentCount();
+ Target *target = m_interpreter.GetExecutionContext().target;
+ ModuleSP exe_module_sp;
+ if (target)
+ {
+ exe_module_sp = target->GetExecutableModule();
+ if (exe_module_sp)
+ {
+ m_options.launch_info.GetExecutableFile () = exe_module_sp->GetFileSpec();
+ char exe_path[PATH_MAX];
+ if (m_options.launch_info.GetExecutableFile ().GetPath (exe_path, sizeof(exe_path)))
+ m_options.launch_info.GetArguments().AppendArgument (exe_path);
+ m_options.launch_info.GetArchitecture() = exe_module_sp->GetArchitecture();
+ }
+ }
+
+ if (argc > 0)
+ {
+ if (m_options.launch_info.GetExecutableFile ())
+ {
+ // We already have an executable file, so we will use this
+ // and all arguments to this function are extra arguments
+ m_options.launch_info.GetArguments().AppendArguments (args);
+ }
+ else
+ {
+ // We don't have any file yet, so the first argument is our
+ // executable, and the rest are program arguments
+ const bool first_arg_is_executable = true;
+ m_options.launch_info.SetArgumentsFromArgs (args,
+ first_arg_is_executable,
+ first_arg_is_executable);
+ }
+ }
+
+ if (m_options.launch_info.GetExecutableFile ())
+ {
+ Debugger &debugger = m_interpreter.GetDebugger();
+
+ if (argc == 0)
+ {
+ lldb::UserSettingsControllerSP process_usc_sp (Process::GetSettingsController ());
+ if (process_usc_sp)
+ {
+ SettableVariableType type;
+ StringList settings_args (process_usc_sp->GetVariable ("process.run-args",
+ type,
+ m_interpreter.GetDebugger().GetInstanceName().GetCString(),
+ error));
+ if (error.Success())
+ {
+ const size_t num_settings_args = settings_args.GetSize();
+ for (size_t i=0; i<num_settings_args; ++i)
+ m_options.launch_info.GetArguments().AppendArgument (settings_args.GetStringAtIndex(i));
+ }
+ }
+ }
+
+ ProcessSP process_sp (platform_sp->DebugProcess (m_options.launch_info,
+ debugger,
+ target,
+ debugger.GetListener(),
+ error));
+ if (process_sp && process_sp->IsAlive())
+ {
+ result.SetStatus (eReturnStatusSuccessFinishNoResult);
+ return true;
+ }
+
+ if (error.Success())
+ result.AppendError ("process launch failed");
+ else
+ result.AppendError (error.AsCString());
+ result.SetStatus (eReturnStatusFailed);
+ }
+ else
+ {
+ result.AppendError ("'platform process launch' uses the current target file and arguments, or the executable and its arguments can be specified in this command");
+ result.SetStatus (eReturnStatusFailed);
+ return false;
+ }
+ }
+ else
+ {
+ result.AppendError ("no platform is selected\n");
+ }
+ return result.Succeeded();
+ }
+
+ virtual Options *
+ GetOptions ()
+ {
+ return &m_options;
+ }
+
+protected:
+ ProcessLaunchCommandOptions m_options;
+};
+
//----------------------------------------------------------------------
@@ -454,11 +582,11 @@
lldb::pid_t pid = m_options.match_info.GetProcessInfo().GetProcessID();
if (pid != LLDB_INVALID_PROCESS_ID)
{
- ProcessInfo proc_info;
+ ProcessInstanceInfo proc_info;
if (platform_sp->GetProcessInfo (pid, proc_info))
{
- ProcessInfo::DumpTableHeader (ostrm, platform_sp.get());
- proc_info.DumpAsTableRow(ostrm, platform_sp.get());
+ ProcessInstanceInfo::DumpTableHeader (ostrm, platform_sp.get(), m_options.show_args, m_options.verbose);
+ proc_info.DumpAsTableRow(ostrm, platform_sp.get(), m_options.show_args, m_options.verbose);
result.SetStatus (eReturnStatusSuccessFinishResult);
}
else
@@ -469,24 +597,25 @@
}
else
{
- ProcessInfoList proc_infos;
+ ProcessInstanceInfoList proc_infos;
const uint32_t matches = platform_sp->FindProcesses (m_options.match_info, proc_infos);
+ const char *match_desc = NULL;
+ const char *match_name = m_options.match_info.GetProcessInfo().GetName();
+ if (match_name && match_name[0])
+ {
+ switch (m_options.match_info.GetNameMatchType())
+ {
+ case eNameMatchIgnore: break;
+ case eNameMatchEquals: match_desc = "matched"; break;
+ case eNameMatchContains: match_desc = "contained"; break;
+ case eNameMatchStartsWith: match_desc = "started with"; break;
+ case eNameMatchEndsWith: match_desc = "ended with"; break;
+ case eNameMatchRegularExpression: match_desc = "matched the regular expression"; break;
+ }
+ }
+
if (matches == 0)
{
- const char *match_desc = NULL;
- const char *match_name = m_options.match_info.GetProcessInfo().GetName();
- if (match_name && match_name[0])
- {
- switch (m_options.match_info.GetNameMatchType())
- {
- case eNameMatchIgnore: break;
- case eNameMatchEquals: match_desc = "match"; break;
- case eNameMatchContains: match_desc = "contains"; break;
- case eNameMatchStartsWith: match_desc = "starts with"; break;
- case eNameMatchEndsWith: match_desc = "end with"; break;
- case eNameMatchRegularExpression: match_desc = "match the regular expression"; break;
- }
- }
if (match_desc)
result.AppendErrorWithFormat ("no processes were found that %s \"%s\" on the \"%s\" platform\n",
match_desc,
@@ -498,11 +627,19 @@
}
else
{
-
- ProcessInfo::DumpTableHeader (ostrm, platform_sp.get());
+ result.AppendMessageWithFormat ("%u matching process%s found on \"%s\"",
+ matches,
+ matches > 1 ? "es were" : " was",
+ platform_sp->GetName());
+ if (match_desc)
+ result.AppendMessageWithFormat (" whose name %s \"%s\"",
+ match_desc,
+ match_name);
+ result.AppendMessageWithFormat ("\n");
+ ProcessInstanceInfo::DumpTableHeader (ostrm, platform_sp.get(), m_options.show_args, m_options.verbose);
for (uint32_t i=0; i<matches; ++i)
{
- proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(ostrm, platform_sp.get());
+ proc_infos.GetProcessInfoAtIndex(i).DumpAsTableRow(ostrm, platform_sp.get(), m_options.show_args, m_options.verbose);
}
}
}
@@ -567,7 +704,7 @@
break;
case 'u':
- match_info.GetProcessInfo().SetRealUserID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
+ match_info.GetProcessInfo().SetUserID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
if (!success)
error.SetErrorStringWithFormat("invalid user ID string: '%s'", option_arg);
break;
@@ -579,7 +716,7 @@
break;
case 'g':
- match_info.GetProcessInfo().SetRealGroupID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
+ match_info.GetProcessInfo().SetGroupID (Args::StringToUInt32 (option_arg, UINT32_MAX, 0, &success));
if (!success)
error.SetErrorStringWithFormat("invalid group ID string: '%s'", option_arg);
break;
@@ -596,26 +733,37 @@
case 'n':
match_info.GetProcessInfo().SetName (option_arg);
- if (match_info.GetNameMatchType() == eNameMatchIgnore)
- match_info.SetNameMatchType (eNameMatchEquals);
+ match_info.SetNameMatchType (eNameMatchEquals);
break;
case 'e':
+ match_info.GetProcessInfo().SetName (option_arg);
match_info.SetNameMatchType (eNameMatchEndsWith);
break;
case 's':
+ match_info.GetProcessInfo().SetName (option_arg);
match_info.SetNameMatchType (eNameMatchStartsWith);
break;
case 'c':
+ match_info.GetProcessInfo().SetName (option_arg);
match_info.SetNameMatchType (eNameMatchContains);
break;
case 'r':
+ match_info.GetProcessInfo().SetName (option_arg);
match_info.SetNameMatchType (eNameMatchRegularExpression);
break;
+ case 'A':
+ show_args = true;
+ break;
+
+ case 'v':
+ verbose = true;
+ break;
+
default:
error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
break;
@@ -628,6 +776,8 @@
ResetOptionValues ()
{
match_info.Clear();
+ show_args = false;
+ verbose = false;
}
const OptionDefinition*
@@ -642,7 +792,9 @@
// Instance variables to hold the values for command options.
- ProcessInfoMatch match_info;
+ ProcessInstanceInfoMatch match_info;
+ bool show_args;
+ bool verbose;
};
CommandOptions m_options;
};
@@ -650,49 +802,23 @@
OptionDefinition
CommandObjectPlatformProcessList::CommandOptions::g_option_table[] =
{
-{ LLDB_OPT_SET_1, false, "pid" , 'p', required_argument, NULL, 0, eArgTypePid , "List the process info for a specific process ID." },
-{ LLDB_OPT_SET_2|
- LLDB_OPT_SET_3|
- LLDB_OPT_SET_4|
- LLDB_OPT_SET_5, true , "name" , 'n', required_argument, NULL, 0, eArgTypeProcessName , "Find processes that match the supplied name." },
-{ LLDB_OPT_SET_2, false, "ends-with" , 'e', no_argument , NULL, 0, eArgTypeNone , "Process names must end with the name supplied with the --name option." },
-{ LLDB_OPT_SET_3, false, "starts-with" , 's', no_argument , NULL, 0, eArgTypeNone , "Process names must start with the name supplied with the --name option." },
-{ LLDB_OPT_SET_4, false, "contains" , 'c', no_argument , NULL, 0, eArgTypeNone , "Process names must contain the name supplied with the --name option." },
-{ LLDB_OPT_SET_5, false, "regex" , 'r', no_argument , NULL, 0, eArgTypeNone , "Process names must match name supplied with the --name option as a regular expression." },
-{ LLDB_OPT_SET_2|
- LLDB_OPT_SET_3|
- LLDB_OPT_SET_4|
- LLDB_OPT_SET_5|
- LLDB_OPT_SET_6, false, "parent" , 'P', required_argument, NULL, 0, eArgTypePid , "Find processes that have a matching parent process ID." },
-{ LLDB_OPT_SET_2|
- LLDB_OPT_SET_3|
- LLDB_OPT_SET_4|
- LLDB_OPT_SET_5|
- LLDB_OPT_SET_6, false, "uid" , 'u', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching user ID." },
-{ LLDB_OPT_SET_2|
- LLDB_OPT_SET_3|
- LLDB_OPT_SET_4|
- LLDB_OPT_SET_5|
- LLDB_OPT_SET_6, false, "euid" , 'U', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching effective user ID." },
-{ LLDB_OPT_SET_2|
- LLDB_OPT_SET_3|
- LLDB_OPT_SET_4|
- LLDB_OPT_SET_5|
- LLDB_OPT_SET_6, false, "gid" , 'g', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching group ID." },
-{ LLDB_OPT_SET_2|
- LLDB_OPT_SET_3|
- LLDB_OPT_SET_4|
- LLDB_OPT_SET_5|
- LLDB_OPT_SET_6, false, "egid" , 'G', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching effective group ID." },
-{ LLDB_OPT_SET_2|
- LLDB_OPT_SET_3|
- LLDB_OPT_SET_4|
- LLDB_OPT_SET_5|
- LLDB_OPT_SET_6, false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Find processes that have a matching architecture." },
-{ 0 , false, NULL , 0 , 0 , NULL, 0, eArgTypeNone , NULL }
+{ LLDB_OPT_SET_1, false, "pid" , 'p', required_argument, NULL, 0, eArgTypePid , "List the process info for a specific process ID." },
+{ LLDB_OPT_SET_2, true , "name" , 'n', required_argument, NULL, 0, eArgTypeProcessName , "Find processes with executable basenames that match a string." },
+{ LLDB_OPT_SET_3, true , "ends-with" , 'e', required_argument, NULL, 0, eArgTypeNone , "Find processes with executable basenames that end with a string." },
+{ LLDB_OPT_SET_4, true , "starts-with" , 's', required_argument, NULL, 0, eArgTypeNone , "Find processes with executable basenames that start with a string." },
+{ LLDB_OPT_SET_5, true , "contains" , 'c', required_argument, NULL, 0, eArgTypeNone , "Find processes with executable basenames that contain a string." },
+{ LLDB_OPT_SET_6, true , "regex" , 'r', required_argument, NULL, 0, eArgTypeNone , "Find processes with executable basenames that match a regular expression." },
+{ ~LLDB_OPT_SET_1, false, "parent" , 'P', required_argument, NULL, 0, eArgTypePid , "Find processes that have a matching parent process ID." },
+{ ~LLDB_OPT_SET_1, false, "uid" , 'u', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching user ID." },
+{ ~LLDB_OPT_SET_1, false, "euid" , 'U', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching effective user ID." },
+{ ~LLDB_OPT_SET_1, false, "gid" , 'g', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching group ID." },
+{ ~LLDB_OPT_SET_1, false, "egid" , 'G', required_argument, NULL, 0, eArgTypeNone , "Find processes that have a matching effective group ID." },
+{ ~LLDB_OPT_SET_1, false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Find processes that have a matching architecture." },
+{ LLDB_OPT_SET_ALL, false, "show-args" , 'A', no_argument , NULL, 0, eArgTypeNone , "Show process arguments instead of the process executable basename." },
+{ LLDB_OPT_SET_ALL, false, "verbose" , 'v', no_argument , NULL, 0, eArgTypeNone , "Enable verbose output." },
+{ 0 , false, NULL , 0 , 0 , NULL, 0, eArgTypeNone , NULL }
};
-
//----------------------------------------------------------------------
// "platform process info"
//----------------------------------------------------------------------
@@ -746,7 +872,7 @@
lldb::pid_t pid = Args::StringToUInt32 (arg, LLDB_INVALID_PROCESS_ID, 0, &success);
if (success)
{
- ProcessInfo proc_info;
+ ProcessInstanceInfo proc_info;
if (platform_sp->GetProcessInfo (pid, proc_info))
{
ostrm.Printf ("Process information for process %i:\n", pid);
@@ -805,7 +931,7 @@
"platform process [attach|launch|list] ...")
{
// LoadSubCommand ("attach", CommandObjectSP (new CommandObjectPlatformProcessAttach (interpreter)));
-// LoadSubCommand ("launch", CommandObjectSP (new CommandObjectPlatformProcessLaunch (interpreter)));
+ LoadSubCommand ("launch", CommandObjectSP (new CommandObjectPlatformProcessLaunch (interpreter)));
LoadSubCommand ("info" , CommandObjectSP (new CommandObjectPlatformProcessInfo (interpreter)));
LoadSubCommand ("list" , CommandObjectSP (new CommandObjectPlatformProcessList (interpreter)));