Author: zturner Date: Thu Aug 14 11:01:25 2014 New Revision: 215649 URL: http://llvm.org/viewvc/llvm-project?rev=215649&view=rev Log: Refactor FileAction out of ProcessLaunchInfo.
FileAction was previously a nested class in ProcessLaunchInfo. This led to some unfortunate style consequences, such as requiring the AddPosixSpawnFileAction() funciton to be defined in the Target layer, instead of the more appropriate Host layer. This patch makes FileAction its own independent class in the Target layer, and then moves AddPosixSpawnFileAction() into Host as a result. Differential Revision: http://reviews.llvm.org/D4877 Added: lldb/trunk/include/lldb/Target/FileAction.h lldb/trunk/source/Target/FileAction.cpp Modified: lldb/trunk/include/lldb/Host/Host.h lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h lldb/trunk/lldb.xcodeproj/project.pbxproj lldb/trunk/source/Host/common/Host.cpp lldb/trunk/source/Host/macosx/Host.mm lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp lldb/trunk/source/Target/CMakeLists.txt lldb/trunk/source/Target/Process.cpp lldb/trunk/source/Target/ProcessLaunchInfo.cpp Modified: lldb/trunk/include/lldb/Host/Host.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/include/lldb/Host/Host.h (original) +++ lldb/trunk/include/lldb/Host/Host.h Thu Aug 14 11:01:25 2014 @@ -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 @@ public: 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 Added: lldb/trunk/include/lldb/Target/FileAction.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/FileAction.h?rev=215649&view=auto ============================================================================== --- lldb/trunk/include/lldb/Target/FileAction.h (added) +++ lldb/trunk/include/lldb/Target/FileAction.h Thu Aug 14 11:01:25 2014 @@ -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 <string> + +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 Modified: lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h (original) +++ lldb/trunk/include/lldb/Target/ProcessLaunchInfo.h Thu Aug 14 11:01:25 2014 @@ -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 @@ namespace lldb_private { 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, Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/lldb.xcodeproj/project.pbxproj (original) +++ lldb/trunk/lldb.xcodeproj/project.pbxproj Thu Aug 14 11:01:25 2014 @@ -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 = "<group>"; }; 26FFC19714FC072100087D58 /* DynamicLoaderPOSIXDYLD.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DynamicLoaderPOSIXDYLD.cpp; sourceTree = "<group>"; }; 26FFC19814FC072100087D58 /* DynamicLoaderPOSIXDYLD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicLoaderPOSIXDYLD.h; sourceTree = "<group>"; }; + 3FDFD6C3199C396E009756A7 /* FileAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileAction.h; path = include/lldb/Target/FileAction.h; sourceTree = "<group>"; }; + 3FDFDDBC199C3A06009756A7 /* FileAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FileAction.cpp; path = source/Target/FileAction.cpp; sourceTree = "<group>"; }; 449ACC96197DE9EC008D175E /* FastDemangle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FastDemangle.cpp; path = source/Core/FastDemangle.cpp; sourceTree = "<group>"; }; 4906FD4012F2255300A2A77C /* ASTDumper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ASTDumper.cpp; path = source/Expression/ASTDumper.cpp; sourceTree = "<group>"; }; 4906FD4412F2257600A2A77C /* ASTDumper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTDumper.h; path = include/lldb/Expression/ASTDumper.h; sourceTree = "<group>"; }; @@ -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 */, Modified: lldb/trunk/source/Host/common/Host.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Host/common/Host.cpp (original) +++ lldb/trunk/source/Host/common/Host.cpp Thu Aug 14 11:01:25 2014 @@ -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 @@ Host::LaunchProcessPosixSpawn (const cha for (size_t i=0; i<num_file_actions; ++i) { - const ProcessLaunchInfo::FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i); + const FileAction *launch_file_action = launch_info.GetFileActionAtIndex(i); if (launch_file_action) { - if (!ProcessLaunchInfo::FileAction::AddPosixSpawnFileAction (&file_actions, + if (!AddPosixSpawnFileAction (&file_actions, launch_file_action, log, error)) @@ -2031,6 +2033,70 @@ Host::LaunchProcessPosixSpawn (const cha return error; } +bool Host::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<posix_spawn_file_actions_t *>(_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<void *>(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<void *>(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<void *>(file_actions), info->GetFD(), info->GetPath(), oflag, mode); + } + break; + } + return error.Success(); +} + #endif // LaunchProcedssPosixSpawn: Apple, Linux, FreeBSD and other GLIBC systems Modified: lldb/trunk/source/Host/macosx/Host.mm URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/Host.mm?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Host/macosx/Host.mm (original) +++ lldb/trunk/source/Host/macosx/Host.mm Thu Aug 14 11:01:25 2014 @@ -1393,7 +1393,7 @@ LaunchProcessXPC (const char *exe_path, // 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()); Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original) +++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Thu Aug 14 11:01:25 2014 @@ -126,14 +126,14 @@ namespace } 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 @@ NativeProcessLinux::LaunchProcess ( } } - 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; Modified: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp (original) +++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.cpp Thu Aug 14 11:01:25 2014 @@ -177,7 +177,7 @@ ProcessPOSIX::WillLaunch(Module* module) 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 @@ ProcessPOSIX::GetFilePath( 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 @@ ProcessPOSIX::DoLaunch (Module *module, 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; Modified: lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h (original) +++ lldb/trunk/source/Plugins/Process/POSIX/ProcessPOSIX.h Thu Aug 14 11:01:25 2014 @@ -158,7 +158,7 @@ public: 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. Modified: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp (original) +++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp Thu Aug 14 11:01:25 2014 @@ -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 @@ namespace 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}; Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Thu Aug 14 11:01:25 2014 @@ -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 @@ GDBRemoteCommunication::PacketResult 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 @@ GDBRemoteCommunication::PacketResult 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 @@ GDBRemoteCommunication::PacketResult 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; Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original) +++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Thu Aug 14 11:01:25 2014 @@ -758,23 +758,23 @@ ProcessGDBRemote::DoLaunch (Module *exe_ 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(); } Modified: lldb/trunk/source/Target/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/CMakeLists.txt?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Target/CMakeLists.txt (original) +++ lldb/trunk/source/Target/CMakeLists.txt Thu Aug 14 11:01:25 2014 @@ -6,6 +6,7 @@ add_lldb_library(lldbTarget ABI.cpp CPPLanguageRuntime.cpp ExecutionContext.cpp + FileAction.cpp JITLoader.cpp JITLoaderList.cpp LanguageRuntime.cpp Added: lldb/trunk/source/Target/FileAction.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/FileAction.cpp?rev=215649&view=auto ============================================================================== --- lldb/trunk/source/Target/FileAction.cpp (added) +++ lldb/trunk/source/Target/FileAction.cpp Thu Aug 14 11:01:25 2014 @@ -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 <fcntl.h> + +#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; +} Modified: lldb/trunk/source/Target/Process.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Target/Process.cpp (original) +++ lldb/trunk/source/Target/Process.cpp Thu Aug 14 11:01:25 2014 @@ -404,7 +404,7 @@ ProcessLaunchCommandOptions::SetOptionVa 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 @@ ProcessLaunchCommandOptions::SetOptionVa 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 @@ ProcessLaunchCommandOptions::SetOptionVa 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 @@ ProcessLaunchCommandOptions::SetOptionVa 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)) Modified: lldb/trunk/source/Target/ProcessLaunchInfo.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ProcessLaunchInfo.cpp?rev=215649&r1=215648&r2=215649&view=diff ============================================================================== --- lldb/trunk/source/Target/ProcessLaunchInfo.cpp (original) +++ lldb/trunk/source/Target/ProcessLaunchInfo.cpp Thu Aug 14 11:01:25 2014 @@ -9,47 +9,18 @@ #include "lldb/Host/Config.h" -#include "lldb/Target/ProcessLaunchInfo.h" - #ifndef LLDB_DISABLE_POSIX #include <spawn.h> #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 () { } -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 @@ ProcessLaunchInfo::ProcessLaunchInfo ( { 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 @@ ProcessLaunchInfo::ProcessLaunchInfo ( } 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 @@ ProcessLaunchInfo::ProcessLaunchInfo ( } 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 @@ ProcessLaunchInfo::AppendSuppressFileAct return false; } -const ProcessLaunchInfo::FileAction * +const FileAction * ProcessLaunchInfo::GetFileActionAtIndex (size_t idx) const { if (idx < m_file_actions.size()) @@ -172,7 +142,7 @@ ProcessLaunchInfo::GetFileActionAtIndex 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 @@ ProcessLaunchInfo::ConvertArgumentsForLa } 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<posix_spawn_file_actions_t *>(_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<void*>(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<void*>(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<void*>(file_actions), info->m_fd, - info->m_path.c_str(), oflag, mode); - } - break; - } - return error.Success(); -} -#endif _______________________________________________ lldb-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
