Summary: These were used by Host::LaunchProcess to "resolve" the executable it was about to launch. The only parts of Platform::ResolveExecutable, which seem to be relevant here are the FileSpec::ResolvePath and ResolveExecutableLocation calls. The rest (most) of that function deals with selecting an architecture out of a fat binary and making sure we are able to create a Module with that slice. These are reasonable actions when selecting a binary to debug, but not for a generic process launching framework (it's technically even wrong because we should be able to launch a binary with execute permissions only, but trying to parse such file will obviously fail). I remove the platform call by inlining the relevant FileSpec calls and ignoring the rest of the Platform::ResolveExecutable code. The architecture found by the slice-searching code is being ignored already anyway, as we use the one specified in the LaunchInfo, so the only effect of this should be a different error message in case the executable does not contain the requested architecture -- before we would get an error message from the Platform class, but now we will get an error from the actual posix_spawn syscall (this is only relevant on mac, as it's the only target supporting fat binaries). Launching targets for debugging should not be affected as here the executable is pre-resolved at the point when the Target is created. Reviewers: jingham, clayborg Subscribers: lldb-commits, emaste Differential Revision: https://reviews.llvm.org/D41902 llvm-svn: 322935
82 lines
2.5 KiB
C++
82 lines
2.5 KiB
C++
//===-- MonitoringProcessLauncher.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/MonitoringProcessLauncher.h"
|
|
#include "lldb/Host/HostProcess.h"
|
|
#include "lldb/Target/Process.h"
|
|
#include "lldb/Target/ProcessLaunchInfo.h"
|
|
#include "lldb/Utility/Log.h"
|
|
#include "lldb/Utility/Status.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
MonitoringProcessLauncher::MonitoringProcessLauncher(
|
|
std::unique_ptr<ProcessLauncher> delegate_launcher)
|
|
: m_delegate_launcher(std::move(delegate_launcher)) {}
|
|
|
|
HostProcess
|
|
MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info,
|
|
Status &error) {
|
|
ProcessLaunchInfo resolved_info(launch_info);
|
|
|
|
error.Clear();
|
|
|
|
FileSpec exe_spec(resolved_info.GetExecutableFile());
|
|
|
|
llvm::sys::fs::file_status stats;
|
|
status(exe_spec.GetPath(), stats);
|
|
if (!exists(stats)) {
|
|
exe_spec.ResolvePath();
|
|
status(exe_spec.GetPath(), stats);
|
|
}
|
|
if (!exists(stats)) {
|
|
exe_spec.ResolveExecutableLocation();
|
|
status(exe_spec.GetPath(), stats);
|
|
}
|
|
|
|
if (!exists(stats)) {
|
|
error.SetErrorStringWithFormatv("executable doesn't exist: '{0}'",
|
|
exe_spec);
|
|
return HostProcess();
|
|
}
|
|
|
|
resolved_info.SetExecutableFile(exe_spec, false);
|
|
assert(!resolved_info.GetFlags().Test(eLaunchFlagLaunchInTTY));
|
|
|
|
HostProcess process =
|
|
m_delegate_launcher->LaunchProcess(resolved_info, error);
|
|
|
|
if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) {
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
|
|
|
|
Host::MonitorChildProcessCallback callback =
|
|
launch_info.GetMonitorProcessCallback();
|
|
|
|
bool monitor_signals = false;
|
|
if (callback) {
|
|
// If the ProcessLaunchInfo specified a callback, use that.
|
|
monitor_signals = launch_info.GetMonitorSignals();
|
|
} else {
|
|
callback = Process::SetProcessExitStatus;
|
|
}
|
|
|
|
process.StartMonitoring(callback, monitor_signals);
|
|
if (log)
|
|
log->PutCString("started monitoring child process.");
|
|
} else {
|
|
// Invalid process ID, something didn't go well
|
|
if (error.Success())
|
|
error.SetErrorString("process launch failed for unknown reasons");
|
|
}
|
|
return process;
|
|
}
|