summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Host/Host.h5
-rw-r--r--lldb/include/lldb/Target/FileAction.h56
-rw-r--r--lldb/include/lldb/Target/ProcessLaunchInfo.h62
-rw-r--r--lldb/lldb.xcodeproj/project.pbxproj6
-rw-r--r--lldb/source/Host/common/Host.cpp70
-rw-r--r--lldb/source/Host/macosx/Host.mm2
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp6
-rw-r--r--lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp6
-rw-r--r--lldb/source/Plugins/Process/POSIX/ProcessPOSIX.h2
-rw-r--r--lldb/source/Plugins/Process/Windows/ProcessWindows.cpp3
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp7
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp8
-rw-r--r--lldb/source/Target/CMakeLists.txt1
-rw-r--r--lldb/source/Target/FileAction.cpp84
-rw-r--r--lldb/source/Target/Process.cpp8
-rw-r--r--lldb/source/Target/ProcessLaunchInfo.cpp175
16 files changed, 251 insertions, 250 deletions
diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index c937a60cdfb..721646fa603 100644
--- a/lldb/include/lldb/Host/Host.h
+++ b/lldb/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 @@ 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
diff --git a/lldb/include/lldb/Target/FileAction.h b/lldb/include/lldb/Target/FileAction.h
new file mode 100644
index 00000000000..d4250c4c6cd
--- /dev/null
+++ b/lldb/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 <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
diff --git a/lldb/include/lldb/Target/ProcessLaunchInfo.h b/lldb/include/lldb/Target/ProcessLaunchInfo.h
index f0983335177..77d829a7e47 100644
--- a/lldb/include/lldb/Target/ProcessLaunchInfo.h
+++ b/lldb/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 @@ 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,
diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj
index 319b410477a..11aebe4e5ae 100644
--- a/lldb/lldb.xcodeproj/project.pbxproj
+++ b/lldb/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 = "<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 */,
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 1599fcbe8ce..33df16f665b 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/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 @@ Host::LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_i
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 char *exe_path, ProcessLaunchInfo &launch_i
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
diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm
index 6b5ca51efb0..0fa6ea560e3 100644
--- a/lldb/source/Host/macosx/Host.mm
+++ b/lldb/source/Host/macosx/Host.mm
@@ -1393,7 +1393,7 @@ 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);
+ const FileAction *file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
if (file_action && file_action->GetPath())
{
xpc_dictionary_set_string(message, LauncherXPCServiceStdInPathKeyKey, file_action->GetPath());
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index f3ea9505ec4..5824ebd1684 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -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;
diff --git a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
index 031405aed5e..a4cb0875ce2 100644
--- a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
+++ b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
@@ -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;
diff --git a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.h b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.h
index b4f297e06c4..7f3756f9508 100644
--- a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.h
+++ b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.h
@@ -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.
diff --git a/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp
index d4210257035..de625e3c4ba 100644
--- a/lldb/source/Plugins/Process/Windows/ProcessWindows.cpp
+++ b/lldb/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 @@ 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};
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index 8b1a56cbc88..d56be34b4d3 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/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 @@ 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;
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index f1ba4775473..0cb2e144d86 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -758,23 +758,23 @@ ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info)
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();
}
diff --git a/lldb/source/Target/CMakeLists.txt b/lldb/source/Target/CMakeLists.txt
index c45e62a8e38..c7b22e05bd5 100644
--- a/lldb/source/Target/CMakeLists.txt
+++ b/lldb/source/Target/CMakeLists.txt
@@ -6,6 +6,7 @@ add_lldb_library(lldbTarget
ABI.cpp
CPPLanguageRuntime.cpp
ExecutionContext.cpp
+ FileAction.cpp
JITLoader.cpp
JITLoaderList.cpp
LanguageRuntime.cpp
diff --git a/lldb/source/Target/FileAction.cpp b/lldb/source/Target/FileAction.cpp
new file mode 100644
index 00000000000..5756147eea4
--- /dev/null
+++ b/lldb/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 <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;
+}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 1609182e61a..95785a93ec2 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -404,7 +404,7 @@ ProcessLaunchCommandOptions::SetOptionValue (uint32_t option_idx, const char *op
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::SetOptionValue (uint32_t option_idx, const char *op
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::SetOptionValue (uint32_t option_idx, const char *op
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::SetOptionValue (uint32_t option_idx, const char *op
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))
diff --git a/lldb/source/Target/ProcessLaunchInfo.cpp b/lldb/source/Target/ProcessLaunchInfo.cpp
index 84baee861ab..7c5bae2205f 100644
--- a/lldb/source/Target/ProcessLaunchInfo.cpp
+++ b/lldb/source/Target/ProcessLaunchInfo.cpp
@@ -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::AppendSuppressFileAction (int fd, bool read, bool write)
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 (size_t idx) const
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::ConvertArgumentsForLaunchingInShell (Error &error,
}
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
OpenPOWER on IntegriCloud