summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/android
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2016-07-21 14:54:03 +0000
committerPavel Labath <labath@google.com>2016-07-21 14:54:03 +0000
commit5ad891f7193b2d7cc6578c2cbffe7d3a04e4617b (patch)
treefade2b50428c5fbf65bb88b92e583301c890e8a0 /lldb/source/Host/android
parent4caefdf834b20104ddaabe61221de469b52e6b0e (diff)
downloadbcm5719-llvm-5ad891f7193b2d7cc6578c2cbffe7d3a04e4617b.tar.gz
bcm5719-llvm-5ad891f7193b2d7cc6578c2cbffe7d3a04e4617b.zip
Unify process launching code on linux
Summary: We've had two copies of code for launching processes: - one in NativeProcessLinux, used for launching debugged processes - one in ProcessLauncherAndroid, used on android for launching all other kinds of processes These have over time acquired support for various launch options, but neither supported all of them. I now replace them with a single implementation ProcessLauncherLinux, which supports all the options the individual versions supported and set it to be used to launch all processes on linux. This also works around the ETXTBSY issue on android when the process is started from the platform instance, as that used to go through the version which did not contain the workaround. Reviewers: tberghammer Subscribers: tberghammer, danalbert, srhines, lldb-commits Differential Revision: https://reviews.llvm.org/D22457 llvm-svn: 276288
Diffstat (limited to 'lldb/source/Host/android')
-rw-r--r--lldb/source/Host/android/ProcessLauncherAndroid.cpp108
1 files changed, 0 insertions, 108 deletions
diff --git a/lldb/source/Host/android/ProcessLauncherAndroid.cpp b/lldb/source/Host/android/ProcessLauncherAndroid.cpp
deleted file mode 100644
index 24eebc8c030..00000000000
--- a/lldb/source/Host/android/ProcessLauncherAndroid.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-//===-- ProcessLauncherAndroid.cpp ------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Host/FileSpec.h"
-#include "lldb/Host/Host.h"
-#include "lldb/Host/HostProcess.h"
-#include "lldb/Host/android/ProcessLauncherAndroid.h"
-
-#include "lldb/Target/ProcessLaunchInfo.h"
-
-#include <limits.h>
-
-using namespace lldb;
-using namespace lldb_private;
-
-static bool
-DupDescriptor(const FileSpec &file_spec, int fd, int flags)
-{
- int target_fd = ::open(file_spec.GetCString(), flags, 0666);
-
- if (target_fd == -1)
- return false;
-
- if (::dup2(target_fd, fd) == -1)
- return false;
-
- return (::close(target_fd) == -1) ? false : true;
-}
-
-// If there is no PATH variable specified inside the environment then set the path to /system/bin.
-// It is required because the default path used by execve() is wrong on android.
-static void
-FixupEnvironment(Args& env)
-{
- static const char* path = "PATH=";
- static const int path_len = ::strlen(path);
- for (const char** args = env.GetConstArgumentVector(); *args; ++args)
- if (::strncmp(path, *args, path_len) == 0)
- return;
- env.AppendArgument("PATH=/system/bin");
-}
-
-HostProcess
-ProcessLauncherAndroid::LaunchProcess(const ProcessLaunchInfo &launch_info, Error &error)
-{
- // TODO: Handle other launch parameters specified in launc_info
-
- char exe_path[PATH_MAX];
- launch_info.GetExecutableFile().GetPath(exe_path, sizeof(exe_path));
-
- lldb::pid_t pid = ::fork();
- if (pid == static_cast<lldb::pid_t>(-1))
- {
- // Fork failed
- error.SetErrorStringWithFormat("Fork failed with error message: %s", strerror(errno));
- return HostProcess(LLDB_INVALID_PROCESS_ID);
- }
- else if (pid == 0)
- {
- if (const lldb_private::FileAction *file_action = launch_info.GetFileActionForFD(STDIN_FILENO)) {
- FileSpec file_spec = file_action->GetFileSpec();
- if (file_spec)
- if (!DupDescriptor(file_spec, STDIN_FILENO, O_RDONLY))
- exit(-1);
- }
-
- if (const lldb_private::FileAction *file_action = launch_info.GetFileActionForFD(STDOUT_FILENO)) {
- FileSpec file_spec = file_action->GetFileSpec();
- if (file_spec)
- if (!DupDescriptor(file_spec, STDOUT_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
- exit(-1);
- }
-
- if (const lldb_private::FileAction *file_action = launch_info.GetFileActionForFD(STDERR_FILENO)) {
- FileSpec file_spec = file_action->GetFileSpec();
- if (file_spec)
- if (!DupDescriptor(file_spec, STDERR_FILENO, O_WRONLY | O_CREAT | O_TRUNC))
- exit(-1);
- }
-
- // Child process
- const char **argv = launch_info.GetArguments().GetConstArgumentVector();
-
- Args env = launch_info.GetEnvironmentEntries();
- FixupEnvironment(env);
- const char **envp = env.GetConstArgumentVector();
-
- FileSpec working_dir = launch_info.GetWorkingDirectory();
- if (working_dir)
- {
- if (::chdir(working_dir.GetCString()) != 0)
- exit(-1);
- }
-
- execve(argv[0],
- const_cast<char *const *>(argv),
- const_cast<char *const *>(envp));
- exit(-1);
- }
-
- return HostProcess(pid);
-}
OpenPOWER on IntegriCloud