diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm index fad2aaac8adf..cf01491901d1 100644 --- a/lldb/source/Host/macosx/Host.mm +++ b/lldb/source/Host/macosx/Host.mm @@ -1499,6 +1499,21 @@ LaunchProcessXPC (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t // Posix spawn stuff. xpc_dictionary_set_int64(message, LauncherXPCServiceCPUTypeKey, launch_info.GetArchitecture().GetMachOCPUType()); xpc_dictionary_set_int64(message, LauncherXPCServicePosixspawnFlagsKey, Host::GetPosixspawnFlags(launch_info)); + const ProcessLaunchInfo::FileAction *file_action = launch_info.GetFileActionForFD(STDIN_FILENO); + if (file_action && file_action->GetPath()) + { + xpc_dictionary_set_string(message, LauncherXPCServiceStdInPathKeyKey, file_action->GetPath()); + } + file_action = launch_info.GetFileActionForFD(STDOUT_FILENO); + if (file_action && file_action->GetPath()) + { + xpc_dictionary_set_string(message, LauncherXPCServiceStdOutPathKeyKey, file_action->GetPath()); + } + file_action = launch_info.GetFileActionForFD(STDERR_FILENO); + if (file_action && file_action->GetPath()) + { + xpc_dictionary_set_string(message, LauncherXPCServiceStdErrPathKeyKey, file_action->GetPath()); + } xpc_object_t reply = xpc_connection_send_message_with_reply_sync(conn, message); xpc_type_t returnType = xpc_get_type(reply); diff --git a/lldb/source/Host/macosx/launcherXPCService/LauncherXPCService.h b/lldb/source/Host/macosx/launcherXPCService/LauncherXPCService.h index 53172513dc18..2181173bc493 100644 --- a/lldb/source/Host/macosx/launcherXPCService/LauncherXPCService.h +++ b/lldb/source/Host/macosx/launcherXPCService/LauncherXPCService.h @@ -9,6 +9,9 @@ #define LauncherXPCServiceEnvPrefxKey "env" #define LauncherXPCServiceCPUTypeKey "cpuType" #define LauncherXPCServicePosixspawnFlagsKey "posixspawnFlags" +#define LauncherXPCServiceStdInPathKeyKey "stdInPath" +#define LauncherXPCServiceStdOutPathKeyKey "stdOutPath" +#define LauncherXPCServiceStdErrPathKeyKey "stdErrPath" #define LauncherXPCServiceChildPIDKey "childPID" #define LauncherXPCServiceErrorTypeKey "errorType" #define LauncherXPCServiceCodeTypeKey "errorCode" diff --git a/lldb/source/Host/macosx/launcherXPCService/main.mm b/lldb/source/Host/macosx/launcherXPCService/main.mm index 6b9a0f3c0728..768faefcbc46 100644 --- a/lldb/source/Host/macosx/launcherXPCService/main.mm +++ b/lldb/source/Host/macosx/launcherXPCService/main.mm @@ -52,17 +52,44 @@ int _setup_posixspawn_attributes_file_actions(xpc_object_t message, posix_spawna if (errorCode) return errorCode; - // Setup any file actions. Here we are emulating what debugserver would do normally in Host.mm since the XPC service meant only for debugserver. + // Setup any file actions. errorCode = posix_spawn_file_actions_init(file_actions); if (errorCode) return errorCode; - errorCode = posix_spawn_file_actions_addclose(file_actions, STDIN_FILENO); + + const char *path = xpc_dictionary_get_string(message, LauncherXPCServiceStdInPathKeyKey); + if (path) + { + errorCode = posix_spawn_file_actions_addopen(file_actions, STDIN_FILENO, path, O_NOCTTY | O_RDONLY, 0); + } + else + { + errorCode = posix_spawn_file_actions_addclose(file_actions, STDIN_FILENO); + } if (errorCode) return errorCode; - errorCode = posix_spawn_file_actions_addclose(file_actions, STDOUT_FILENO); + + path = xpc_dictionary_get_string(message, LauncherXPCServiceStdOutPathKeyKey); + if (path) + { + errorCode = posix_spawn_file_actions_addopen(file_actions, STDOUT_FILENO, path, O_NOCTTY | O_CREAT | O_WRONLY, 0640); + } + else + { + errorCode = posix_spawn_file_actions_addclose(file_actions, STDOUT_FILENO); + } if (errorCode) return errorCode; - errorCode = posix_spawn_file_actions_addclose(file_actions, STDERR_FILENO); + + path = xpc_dictionary_get_string(message, LauncherXPCServiceStdErrPathKeyKey); + if (path) + { + errorCode = posix_spawn_file_actions_addopen(file_actions, STDERR_FILENO, path, O_NOCTTY | O_CREAT | O_RDWR, 0640); + } + else + { + errorCode = posix_spawn_file_actions_addclose(file_actions, STDERR_FILENO); + } return errorCode; }