Index: lldb/trunk/include/lldb/Host/Host.h =================================================================== --- lldb/trunk/include/lldb/Host/Host.h +++ lldb/trunk/include/lldb/Host/Host.h @@ -23,6 +23,9 @@ namespace lldb_private { +class FileAction; +class ProcessLaunchInfo; + //---------------------------------------------------------------------- /// @class Host Host.h "lldb/Host/Host.h" /// @brief A class that provides host computer information. @@ -508,6 +511,8 @@ static Error LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t &pid); + + static bool AddPosixSpawnFileAction(void *file_actions, const FileAction *info, Log *log, Error &error); #endif static lldb::pid_t Index: lldb/trunk/include/lldb/Target/FileAction.h =================================================================== --- lldb/trunk/include/lldb/Target/FileAction.h +++ lldb/trunk/include/lldb/Target/FileAction.h @@ -0,0 +1,56 @@ +//===-- ProcessLaunchInfo.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef liblldb_Target_FileAction_h +#define liblldb_Target_FileAction_h + +#include + +namespace lldb_private +{ + +class FileAction +{ + public: + enum Action + { + eFileActionNone, + eFileActionClose, + eFileActionDuplicate, + eFileActionOpen + }; + + FileAction(); + + void Clear(); + + bool Close(int fd); + + bool Duplicate(int fd, int dup_fd); + + bool Open(int fd, const char *path, bool read, bool write); + + int GetFD() const { return m_fd; } + + Action GetAction() const { return m_action; } + + int GetActionArgument() const { return m_arg; } + + const char *GetPath() const; + + protected: + Action m_action; // The action for this file + int m_fd; // An existing file descriptor + int m_arg; // oflag for eFileActionOpen*, dup_fd for eFileActionDuplicate + std::string m_path; // A file path to use for opening after fork or posix_spawn +}; + +} // namespace lldb_private + +#endif Index: lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h =================================================================== --- lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h +++ lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h @@ -16,6 +16,7 @@ // LLDB Headers #include "lldb/Core/Flags.h" #include "lldb/Host/Host.h" +#include "lldb/Target/FileAction.h" #include "lldb/Target/ProcessInfo.h" #include "lldb/Utility/PseudoTerminal.h" @@ -32,67 +33,6 @@ { public: - class FileAction - { - public: - enum Action - { - eFileActionNone, - eFileActionClose, - eFileActionDuplicate, - eFileActionOpen - }; - - FileAction (); - - void - Clear(); - - bool - Close (int fd); - - bool - Duplicate (int fd, int dup_fd); - - bool - Open (int fd, const char *path, bool read, bool write); - - #ifndef LLDB_DISABLE_POSIX - static bool - AddPosixSpawnFileAction (void *file_actions, - const FileAction *info, - Log *log, - Error& error); - #endif - - int - GetFD () const - { - return m_fd; - } - - Action - GetAction () const - { - return m_action; - } - - int - GetActionArgument () const - { - return m_arg; - } - - const char * - GetPath () const; - - protected: - Action m_action; // The action for this file - int m_fd; // An existing file descriptor - int m_arg; // oflag for eFileActionOpen*, dup_fd for eFileActionDuplicate - std::string m_path; // A file path to use for opening after fork or posix_spawn - }; - ProcessLaunchInfo (); ProcessLaunchInfo (const char *stdin_path, Index: lldb/trunk/lldb.xcodeproj/project.pbxproj =================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj +++ lldb/trunk/lldb.xcodeproj/project.pbxproj @@ -582,6 +582,7 @@ 26FFC19C14FC072100087D58 /* DYLDRendezvous.h in Headers */ = {isa = PBXBuildFile; fileRef = 26FFC19614FC072100087D58 /* DYLDRendezvous.h */; }; 26FFC19D14FC072100087D58 /* DynamicLoaderPOSIXDYLD.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26FFC19714FC072100087D58 /* DynamicLoaderPOSIXDYLD.cpp */; }; 26FFC19E14FC072100087D58 /* DynamicLoaderPOSIXDYLD.h in Headers */ = {isa = PBXBuildFile; fileRef = 26FFC19814FC072100087D58 /* DynamicLoaderPOSIXDYLD.h */; }; + 3FDFDDBD199C3A06009756A7 /* FileAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */; }; 449ACC98197DEA0B008D175E /* FastDemangle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 449ACC96197DE9EC008D175E /* FastDemangle.cpp */; }; 490A36C0180F0E6F00BA31F8 /* PlatformWindows.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490A36BD180F0E6F00BA31F8 /* PlatformWindows.cpp */; }; 490A36C2180F0E9300BA31F8 /* PlatformWindows.h in Headers */ = {isa = PBXBuildFile; fileRef = 490A36BE180F0E6F00BA31F8 /* PlatformWindows.h */; }; @@ -1731,6 +1732,8 @@ 26FFC19614FC072100087D58 /* DYLDRendezvous.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DYLDRendezvous.h; sourceTree = ""; }; 26FFC19714FC072100087D58 /* DynamicLoaderPOSIXDYLD.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DynamicLoaderPOSIXDYLD.cpp; sourceTree = ""; }; 26FFC19814FC072100087D58 /* DynamicLoaderPOSIXDYLD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicLoaderPOSIXDYLD.h; sourceTree = ""; }; + 3FDFD6C3199C396E009756A7 /* FileAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileAction.h; path = include/lldb/Target/FileAction.h; sourceTree = ""; }; + 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileAction.cpp; path = source/Target/FileAction.cpp; sourceTree = ""; }; 449ACC96197DE9EC008D175E /* FastDemangle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FastDemangle.cpp; path = source/Core/FastDemangle.cpp; sourceTree = ""; }; 4906FD4012F2255300A2A77C /* ASTDumper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ASTDumper.cpp; path = source/Expression/ASTDumper.cpp; sourceTree = ""; }; 4906FD4412F2257600A2A77C /* ASTDumper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTDumper.h; path = include/lldb/Expression/ASTDumper.h; sourceTree = ""; }; @@ -3570,6 +3573,8 @@ 26BC7DEF10F1B80200F91463 /* Target */ = { isa = PBXGroup; children = ( + 3FDFD6C3199C396E009756A7 /* FileAction.h */, + 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */, 23EDE3311926843600F6A132 /* NativeRegisterContext.h */, 23EDE3301926839700F6A132 /* NativeRegisterContext.cpp */, 497E7B331188ED300065CCA1 /* ABI.h */, @@ -4985,6 +4990,7 @@ 9A4F35101368A51A00823F52 /* StreamAsynchronousIO.cpp in Sources */, 2692BA15136610C100F9E14D /* UnwindAssemblyInstEmulation.cpp in Sources */, 263E949F13661AEA00E7D1CE /* UnwindAssembly-x86.cpp in Sources */, + 3FDFDDBD199C3A06009756A7 /* FileAction.cpp in Sources */, 264D8D5013661BD7003A368F /* UnwindAssembly.cpp in Sources */, AF23B4DB19009C66003E2A58 /* FreeBSDSignals.cpp in Sources */, 26ECA04313665FED008D1F18 /* ARM_DWARF_Registers.cpp in Sources */, Index: lldb/trunk/source/Host/common/Host.cpp =================================================================== --- lldb/trunk/source/Host/common/Host.cpp +++ lldb/trunk/source/Host/common/Host.cpp @@ -68,7 +68,9 @@ #include "lldb/Host/Endian.h" #include "lldb/Host/FileSpec.h" #include "lldb/Host/Mutex.h" +#include "lldb/Target/FileAction.h" #include "lldb/Target/Process.h" +#include "lldb/Target/ProcessLaunchInfo.h" #include "lldb/Target/TargetList.h" #include "lldb/Utility/CleanUp.h" @@ -1955,10 +1957,10 @@ for (size_t i=0; i(_file_actions); + + switch (info->GetAction()) + { + case FileAction::eFileActionNone: + error.Clear(); + break; + + case FileAction::eFileActionClose: + if (info->GetFD() == -1) + error.SetErrorString("invalid fd for posix_spawn_file_actions_addclose(...)"); + else + { + error.SetError(::posix_spawn_file_actions_addclose(file_actions, info->GetFD()), eErrorTypePOSIX); + if (log && (error.Fail() || log)) + error.PutToLog(log, "posix_spawn_file_actions_addclose (action=%p, fd=%i)", + static_cast(file_actions), info->GetFD()); + } + break; + + case FileAction::eFileActionDuplicate: + if (info->GetFD() == -1) + error.SetErrorString("invalid fd for posix_spawn_file_actions_adddup2(...)"); + else if (info->GetActionArgument() == -1) + error.SetErrorString("invalid duplicate fd for posix_spawn_file_actions_adddup2(...)"); + else + { + error.SetError(::posix_spawn_file_actions_adddup2(file_actions, info->GetFD(), info->GetActionArgument()), + eErrorTypePOSIX); + if (log && (error.Fail() || log)) + error.PutToLog(log, "posix_spawn_file_actions_adddup2 (action=%p, fd=%i, dup_fd=%i)", + static_cast(file_actions), info->GetFD(), info->GetActionArgument()); + } + break; + + case FileAction::eFileActionOpen: + if (info->GetFD() == -1) + error.SetErrorString("invalid fd in posix_spawn_file_actions_addopen(...)"); + else + { + int oflag = info->GetActionArgument(); + + mode_t mode = 0; + + if (oflag & O_CREAT) + mode = 0640; + + error.SetError( + ::posix_spawn_file_actions_addopen(file_actions, info->GetFD(), info->GetPath(), oflag, mode), + eErrorTypePOSIX); + if (error.Fail() || log) + error.PutToLog(log, "posix_spawn_file_actions_addopen (action=%p, fd=%i, path='%s', oflag=%i, mode=%i)", + static_cast(file_actions), info->GetFD(), info->GetPath(), oflag, mode); + } + break; + } + return error.Success(); +} + #endif // LaunchProcedssPosixSpawn: Apple, Linux, FreeBSD and other GLIBC systems Index: lldb/trunk/source/Host/macosx/Host.mm =================================================================== --- lldb/trunk/source/Host/macosx/Host.mm +++ lldb/trunk/source/Host/macosx/Host.mm @@ -1393,7 +1393,7 @@ // 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); + const FileAction *file_action = launch_info.GetFileActionForFD(STDIN_FILENO); if (file_action && file_action->GetPath()) { xpc_dictionary_set_string(message, LauncherXPCServiceStdInPathKeyKey, file_action->GetPath()); Index: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -126,14 +126,14 @@ } const char * - GetFilePath (const lldb_private::ProcessLaunchInfo::FileAction *file_action, const char *default_path) + GetFilePath (const lldb_private::FileAction *file_action, const char *default_path) { const char *pts_name = "/dev/pts/"; const char *path = NULL; if (file_action) { - if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen) + if (file_action->GetAction () == FileAction::eFileActionOpen) { path = file_action->GetPath (); // By default the stdio paths passed in will be pseudo-terminal @@ -1040,7 +1040,7 @@ } } - const lldb_private::ProcessLaunchInfo::FileAction *file_action; + const lldb_private::FileAction *file_action; // Default of NULL will mean to use existing open file descriptors. const char *stdin_path = NULL; Index: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h =================================================================== --- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h +++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h @@ -158,7 +158,7 @@ GetUnixSignals(); const char * - GetFilePath(const lldb_private::ProcessLaunchInfo::FileAction *file_action, + GetFilePath(const lldb_private::FileAction *file_action, const char *default_path); /// Stops all threads in the process. Index: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp +++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp @@ -177,7 +177,7 @@ const char * ProcessPOSIX::GetFilePath( - const lldb_private::ProcessLaunchInfo::FileAction *file_action, + const lldb_private::FileAction *file_action, const char *default_path) { const char *pts_name = "/dev/pts/"; @@ -185,7 +185,7 @@ if (file_action) { - if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen) + if (file_action->GetAction () == FileAction::eFileActionOpen) { path = file_action->GetPath(); // By default the stdio paths passed in will be pseudo-terminal @@ -219,7 +219,7 @@ SetPrivateState(eStateLaunching); - const lldb_private::ProcessLaunchInfo::FileAction *file_action; + const lldb_private::FileAction *file_action; // Default of NULL will mean to use existing open file descriptors const char *stdin_path = NULL; Index: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp +++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp @@ -18,6 +18,7 @@ #include "lldb/Host/Host.h" #include "lldb/Symbol/ObjectFile.h" #include "lldb/Target/DynamicLoader.h" +#include "lldb/Target/FileAction.h" #include "lldb/Target/Target.h" #include "ProcessWindows.h" @@ -30,7 +31,7 @@ HANDLE GetStdioHandle(ProcessLaunchInfo &launch_info, int fd) { - const ProcessLaunchInfo::FileAction *action = launch_info.GetFileActionForFD(fd); + const FileAction *action = launch_info.GetFileActionForFD(fd); if (action == nullptr) return NULL; SECURITY_ATTRIBUTES secattr = {0}; Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp @@ -33,6 +33,7 @@ #include "lldb/Host/File.h" #include "lldb/Host/Host.h" #include "lldb/Host/TimeValue.h" +#include "lldb/Target/FileAction.h" #include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/NativeRegisterContext.h" @@ -2150,7 +2151,7 @@ GDBRemoteCommunicationServer::Handle_QSetSTDIN (StringExtractorGDBRemote &packet) { packet.SetFilePos(::strlen ("QSetSTDIN:")); - ProcessLaunchInfo::FileAction file_action; + FileAction file_action; std::string path; packet.GetHexByteString(path); const bool read = false; @@ -2167,7 +2168,7 @@ GDBRemoteCommunicationServer::Handle_QSetSTDOUT (StringExtractorGDBRemote &packet) { packet.SetFilePos(::strlen ("QSetSTDOUT:")); - ProcessLaunchInfo::FileAction file_action; + FileAction file_action; std::string path; packet.GetHexByteString(path); const bool read = true; @@ -2184,7 +2185,7 @@ GDBRemoteCommunicationServer::Handle_QSetSTDERR (StringExtractorGDBRemote &packet) { packet.SetFilePos(::strlen ("QSetSTDERR:")); - ProcessLaunchInfo::FileAction file_action; + FileAction file_action; std::string path; packet.GetHexByteString(path); const bool read = true; Index: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -758,23 +758,23 @@ const char *stderr_path = NULL; const char *working_dir = launch_info.GetWorkingDirectory(); - const ProcessLaunchInfo::FileAction *file_action; + const FileAction *file_action; file_action = launch_info.GetFileActionForFD (STDIN_FILENO); if (file_action) { - if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen) + if (file_action->GetAction () == FileAction::eFileActionOpen) stdin_path = file_action->GetPath(); } file_action = launch_info.GetFileActionForFD (STDOUT_FILENO); if (file_action) { - if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen) + if (file_action->GetAction () == FileAction::eFileActionOpen) stdout_path = file_action->GetPath(); } file_action = launch_info.GetFileActionForFD (STDERR_FILENO); if (file_action) { - if (file_action->GetAction () == ProcessLaunchInfo::FileAction::eFileActionOpen) + if (file_action->GetAction () == FileAction::eFileActionOpen) stderr_path = file_action->GetPath(); } Index: lldb/trunk/source/Target/CMakeLists.txt =================================================================== --- lldb/trunk/source/Target/CMakeLists.txt +++ lldb/trunk/source/Target/CMakeLists.txt @@ -6,6 +6,7 @@ ABI.cpp CPPLanguageRuntime.cpp ExecutionContext.cpp + FileAction.cpp JITLoader.cpp JITLoaderList.cpp LanguageRuntime.cpp Index: lldb/trunk/source/Target/FileAction.cpp =================================================================== --- lldb/trunk/source/Target/FileAction.cpp +++ lldb/trunk/source/Target/FileAction.cpp @@ -0,0 +1,84 @@ +//===-- FileAction.cpp ------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include + +#if defined(_WIN32) +#include "lldb/Host/Windows/win32.h" // For O_NOCTTY +#endif + +#include "lldb/Target/FileAction.h" + +using namespace lldb_private; + +//---------------------------------------------------------------------------- +// FileAction member functions +//---------------------------------------------------------------------------- + +FileAction::FileAction() : m_action(eFileActionNone), m_fd(-1), m_arg(-1), m_path() {} + +void FileAction::Clear() +{ + m_action = eFileActionNone; + m_fd = -1; + m_arg = -1; + m_path.clear(); +} + +const char *FileAction::GetPath() const +{ + if (m_path.empty()) + return NULL; + return m_path.c_str(); +} + +bool FileAction::Open(int fd, const char *path, bool read, bool write) +{ + if ((read || write) && fd >= 0 && path && path[0]) + { + m_action = eFileActionOpen; + m_fd = fd; + if (read && write) + m_arg = O_NOCTTY | O_CREAT | O_RDWR; + else if (read) + m_arg = O_NOCTTY | O_RDONLY; + else + m_arg = O_NOCTTY | O_CREAT | O_WRONLY; + m_path.assign(path); + return true; + } + else + { + Clear(); + } + return false; +} + +bool FileAction::Close(int fd) +{ + Clear(); + if (fd >= 0) + { + m_action = eFileActionClose; + m_fd = fd; + } + return m_fd >= 0; +} + +bool FileAction::Duplicate(int fd, int dup_fd) +{ + Clear(); + if (fd >= 0 && dup_fd >= 0) + { + m_action = eFileActionDuplicate; + m_fd = fd; + m_arg = dup_fd; + } + return m_fd >= 0; +} Index: lldb/trunk/source/Target/Process.cpp =================================================================== --- lldb/trunk/source/Target/Process.cpp +++ lldb/trunk/source/Target/Process.cpp @@ -404,7 +404,7 @@ case 'i': // STDIN for read only { - ProcessLaunchInfo::FileAction action; + FileAction action; if (action.Open (STDIN_FILENO, option_arg, true, false)) launch_info.AppendFileAction (action); } @@ -412,7 +412,7 @@ case 'o': // Open STDOUT for write only { - ProcessLaunchInfo::FileAction action; + FileAction action; if (action.Open (STDOUT_FILENO, option_arg, false, true)) launch_info.AppendFileAction (action); } @@ -420,7 +420,7 @@ case 'e': // STDERR for write only { - ProcessLaunchInfo::FileAction action; + FileAction action; if (action.Open (STDERR_FILENO, option_arg, false, true)) launch_info.AppendFileAction (action); } @@ -433,7 +433,7 @@ case 'n': // Disable STDIO { - ProcessLaunchInfo::FileAction action; + FileAction action; if (action.Open (STDIN_FILENO, "/dev/null", true, false)) launch_info.AppendFileAction (action); if (action.Open (STDOUT_FILENO, "/dev/null", false, true)) Index: lldb/trunk/source/Target/ProcessLaunchInfo.cpp =================================================================== --- lldb/trunk/source/Target/ProcessLaunchInfo.cpp +++ lldb/trunk/source/Target/ProcessLaunchInfo.cpp @@ -9,47 +9,18 @@ #include "lldb/Host/Config.h" -#include "lldb/Target/ProcessLaunchInfo.h" - #ifndef LLDB_DISABLE_POSIX #include #endif +#include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Target/FileAction.h" #include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; //---------------------------------------------------------------------------- -// ProcessLaunchInfo::FileAction member functions -//---------------------------------------------------------------------------- - -ProcessLaunchInfo::FileAction::FileAction () : - m_action (eFileActionNone), - m_fd (-1), - m_arg (-1), - m_path () -{ -} - -void -ProcessLaunchInfo::FileAction::Clear() -{ - m_action = eFileActionNone; - m_fd = -1; - m_arg = -1; - m_path.clear(); -} - -const char * -ProcessLaunchInfo::FileAction::GetPath () const -{ - if (m_path.empty()) - return NULL; - return m_path.c_str(); -} - -//---------------------------------------------------------------------------- // ProcessLaunchInfo member functions //---------------------------------------------------------------------------- @@ -69,8 +40,7 @@ { } -ProcessLaunchInfo::ProcessLaunchInfo ( - const char *stdin_path, +ProcessLaunchInfo::ProcessLaunchInfo (const char *stdin_path, const char *stdout_path, const char *stderr_path, const char *working_directory, @@ -90,7 +60,7 @@ { if (stdin_path) { - ProcessLaunchInfo::FileAction file_action; + FileAction file_action; const bool read = true; const bool write = false; if (file_action.Open(STDIN_FILENO, stdin_path, read, write)) @@ -98,7 +68,7 @@ } if (stdout_path) { - ProcessLaunchInfo::FileAction file_action; + FileAction file_action; const bool read = false; const bool write = true; if (file_action.Open(STDOUT_FILENO, stdout_path, read, write)) @@ -106,7 +76,7 @@ } if (stderr_path) { - ProcessLaunchInfo::FileAction file_action; + FileAction file_action; const bool read = false; const bool write = true; if (file_action.Open(STDERR_FILENO, stderr_path, read, write)) @@ -164,7 +134,7 @@ return false; } -const ProcessLaunchInfo::FileAction * +const FileAction * ProcessLaunchInfo::GetFileActionAtIndex (size_t idx) const { if (idx < m_file_actions.size()) @@ -172,7 +142,7 @@ return NULL; } -const ProcessLaunchInfo::FileAction * +const FileAction * ProcessLaunchInfo::GetFileActionForFD (int fd) const { for (size_t idx=0, count=m_file_actions.size(); idx < count; ++idx) @@ -490,132 +460,3 @@ } return false; } - - -bool -ProcessLaunchInfo::FileAction::Open (int fd, const char *path, bool read, bool write) -{ - if ((read || write) && fd >= 0 && path && path[0]) - { - m_action = eFileActionOpen; - m_fd = fd; - if (read && write) - m_arg = O_NOCTTY | O_CREAT | O_RDWR; - else if (read) - m_arg = O_NOCTTY | O_RDONLY; - else - m_arg = O_NOCTTY | O_CREAT | O_WRONLY; - m_path.assign (path); - return true; - } - else - { - Clear(); - } - return false; -} - -bool -ProcessLaunchInfo::FileAction::Close (int fd) -{ - Clear(); - if (fd >= 0) - { - m_action = eFileActionClose; - m_fd = fd; - } - return m_fd >= 0; -} - - -bool -ProcessLaunchInfo::FileAction::Duplicate (int fd, int dup_fd) -{ - Clear(); - if (fd >= 0 && dup_fd >= 0) - { - m_action = eFileActionDuplicate; - m_fd = fd; - m_arg = dup_fd; - } - return m_fd >= 0; -} - - - -#ifndef LLDB_DISABLE_POSIX -bool -ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (void *_file_actions, - const FileAction *info, - Log *log, - Error& error) -{ - if (info == NULL) - return false; - - posix_spawn_file_actions_t *file_actions = reinterpret_cast(_file_actions); - - switch (info->m_action) - { - case eFileActionNone: - error.Clear(); - break; - - case eFileActionClose: - if (info->m_fd == -1) - error.SetErrorString ("invalid fd for posix_spawn_file_actions_addclose(...)"); - else - { - error.SetError (::posix_spawn_file_actions_addclose (file_actions, info->m_fd), - eErrorTypePOSIX); - if (log && (error.Fail() || log)) - error.PutToLog(log, "posix_spawn_file_actions_addclose (action=%p, fd=%i)", - static_cast(file_actions), info->m_fd); - } - break; - - case eFileActionDuplicate: - if (info->m_fd == -1) - error.SetErrorString ("invalid fd for posix_spawn_file_actions_adddup2(...)"); - else if (info->m_arg == -1) - error.SetErrorString ("invalid duplicate fd for posix_spawn_file_actions_adddup2(...)"); - else - { - error.SetError (::posix_spawn_file_actions_adddup2 (file_actions, info->m_fd, info->m_arg), - eErrorTypePOSIX); - if (log && (error.Fail() || log)) - error.PutToLog(log, "posix_spawn_file_actions_adddup2 (action=%p, fd=%i, dup_fd=%i)", - static_cast(file_actions), info->m_fd, - info->m_arg); - } - break; - - case eFileActionOpen: - if (info->m_fd == -1) - error.SetErrorString ("invalid fd in posix_spawn_file_actions_addopen(...)"); - else - { - int oflag = info->m_arg; - - mode_t mode = 0; - - if (oflag & O_CREAT) - mode = 0640; - - error.SetError (::posix_spawn_file_actions_addopen (file_actions, - info->m_fd, - info->m_path.c_str(), - oflag, - mode), - eErrorTypePOSIX); - if (error.Fail() || log) - error.PutToLog(log, - "posix_spawn_file_actions_addopen (action=%p, fd=%i, path='%s', oflag=%i, mode=%i)", - static_cast(file_actions), info->m_fd, - info->m_path.c_str(), oflag, mode); - } - break; - } - return error.Success(); -} -#endif