11#include "lldb/Host/Config.h"
20#include "llvm/Support/ConvertUTF.h"
21#include "llvm/Support/FileSystem.h"
42 uint32_t launch_flags)
45 if (stdin_file_spec) {
47 const bool read =
true;
48 const bool write =
false;
49 if (file_action.
Open(STDIN_FILENO, stdin_file_spec, read, write))
52 if (stdout_file_spec) {
54 const bool read =
false;
55 const bool write =
true;
56 if (file_action.
Open(STDOUT_FILENO, stdout_file_spec, read, write))
59 if (stderr_file_spec) {
61 const bool read =
false;
62 const bool write =
true;
63 if (file_action.
Open(STDERR_FILENO, stderr_file_spec, read, write))
66 if (working_directory)
72 if (file_action.
Close(fd)) {
89 bool read,
bool write) {
91 if (file_action.
Open(fd, file_spec, read, write)) {
115 for (
size_t idx = 0, count =
m_file_actions.size(); idx < count; ++idx) {
144 m_flags.Set(lldb::eLaunchFlagLaunchInShell);
146 m_flags.Clear(lldb::eLaunchFlagLaunchInShell);
151 m_flags.Set(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
153 m_flags.Clear(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
158 m_flags.Set(lldb::eLaunchFlagShellExpandArguments);
160 m_flags.Clear(lldb::eLaunchFlagShellExpandArguments);
178 LLDB_LOG(log,
"pid = {0}, signal = {1}, status = {2}", pid, signal, status);
183 llvm::Expected<HostThread> maybe_thread =
187 "failed to launch host thread: {0}");
195 m_flags.Set(lldb::eLaunchFlagDetachOnError);
197 m_flags.Clear(lldb::eLaunchFlagDetachOnError);
206 bool any_free = stdin_free || stdout_free || stderr_free;
208 return llvm::Error::success();
210 LLDB_LOG(log,
"Generating a pty to use for stdin/out/err");
213 if (llvm::Error Err =
m_pty->OpenPseudoConsole())
215 return llvm::Error::success();
217 int open_flags = O_RDWR |
O_NOCTTY | O_CLOEXEC;
218 if (llvm::Error Err =
m_pty->OpenFirstAvailablePrimary(open_flags))
221 const FileSpec secondary_file_spec(
m_pty->GetSecondaryName());
231 return llvm::Error::success();
236 Status &
error,
bool will_debug,
bool first_arg_is_full_shell_command,
237 uint32_t num_resumes) {
240 if (
GetFlags().Test(eLaunchFlagLaunchInShell)) {
242 std::string shell_executable =
m_shell.GetPath();
245 if (argv ==
nullptr || argv[0] ==
nullptr)
247 Args shell_arguments;
250 if (triple.getOS() == llvm::Triple::Win32 &&
251 !triple.isWindowsCygwinEnvironment())
260 const char *argv0 = argv[0];
268 std::string new_path(
"PATH=\"");
269 const size_t empty_path_len = new_path.size();
272 new_path += working_dir.
GetPath();
274 llvm::SmallString<64> cwd;
275 if (! llvm::sys::fs::current_path(cwd))
278 std::string curr_path;
279 if (HostInfo::GetEnvironmentVar(
"PATH", curr_path)) {
280 if (new_path.size() > empty_path_len)
282 new_path += curr_path;
288 if (triple.getOS() != llvm::Triple::Win32 ||
289 triple.isWindowsCygwinEnvironment())
296 llvm::Triple::Apple &&
300 shell_command.
Printf(
" /usr/bin/arch -arch %s",
315 if (first_arg_is_full_shell_command) {
318 if (argv[0] && !argv[1])
319 shell_command.
Printf(
"%s", argv[0]);
323 for (
size_t i = 0; argv[i] !=
nullptr; ++i) {
325 if (safe_arg.empty())
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOG_ERROR(log, error,...)
static bool separate(size_t count)
llvm::Triple & GetTriple()
Architecture triple accessor.
A command line argument class.
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
static std::string GetShellSafeArgument(const FileSpec &shell, llvm::StringRef unsafe_arg)
const char ** GetConstArgumentVector() const
Gets the argument vector.
bool Duplicate(int fd, int dup_fd)
bool Open(int fd, const FileSpec &file_spec, bool read, bool write)
bool IsRelative() const
Returns true if the filespec represents a relative path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static const char * DEV_NULL
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
static FileSystem & Instance()
static llvm::Expected< HostThread > StartMonitoringChildProcess(const MonitorChildProcessCallback &callback, lldb::pid_t pid)
Start monitoring a child process.
bool ProcessIDIsValid() const
lldb::pid_t GetProcessID() const
lldb::ListenerSP m_hijack_listener_sp
lldb::ListenerSP m_listener_sp
ArchSpec & GetArchitecture()
llvm::StringRef GetProcessPluginName() const
const FileSpec & GetShell() const
bool MonitorProcess() const
std::shared_ptr< PTY > m_pty
std::vector< FileAction > m_file_actions
llvm::Error SetUpPtyRedirection()
bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read, bool write)
bool AppendSuppressFileAction(int fd, bool read, bool write)
bool AppendCloseFileAction(int fd)
static void NoOpMonitorCallback(lldb::pid_t pid, int signal, int status)
A Monitor callback which does not take any action on process events.
const FileAction * GetFileActionAtIndex(size_t idx) const
std::string m_plugin_name
void SetShell(const FileSpec &shell)
const FileAction * GetFileActionForFD(int fd) const
void SetProcessPluginName(llvm::StringRef plugin)
bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug, bool first_arg_is_full_shell_command, uint32_t num_resumes)
bool AppendDuplicateFileAction(int fd, int dup_fd)
void AppendFileAction(const FileAction &info)
void SetLaunchInSeparateProcessGroup(bool separate)
void SetShellExpandArguments(bool expand)
void SetDetachOnError(bool enable)
void SetResumeCount(uint32_t c)
void SetWorkingDirectory(const FileSpec &working_dir)
Host::MonitorChildProcessCallback m_monitor_callback
const FileSpec & GetWorkingDirectory() const
static Status FromErrorString(const char *str)
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.