2020-01-24 08:23:27 +01:00
|
|
|
//===-- MonitoringProcessLauncher.cpp -------------------------------------===//
|
2014-10-14 21:55:08 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-10-14 21:55:08 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Host/MonitoringProcessLauncher.h"
|
2018-11-01 17:09:22 +00:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2014-10-14 21:55:08 +00:00
|
|
|
#include "lldb/Host/HostProcess.h"
|
2019-02-04 14:28:08 +00:00
|
|
|
#include "lldb/Host/ProcessLaunchInfo.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
2014-10-14 21:55:08 +00:00
|
|
|
|
2017-03-08 17:56:08 +00:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
|
|
2014-10-14 21:55:08 +00:00
|
|
|
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,
|
2017-05-12 04:51:55 +00:00
|
|
|
Status &error) {
|
2014-10-14 21:55:08 +00:00
|
|
|
ProcessLaunchInfo resolved_info(launch_info);
|
|
|
|
|
|
|
|
|
|
error.Clear();
|
|
|
|
|
|
2018-12-03 22:41:32 +00:00
|
|
|
FileSystem &fs = FileSystem::Instance();
|
2014-10-14 21:55:08 +00:00
|
|
|
FileSpec exe_spec(resolved_info.GetExecutableFile());
|
|
|
|
|
|
2018-12-03 22:41:32 +00:00
|
|
|
if (!fs.Exists(exe_spec))
|
2018-11-01 21:05:36 +00:00
|
|
|
FileSystem::Instance().Resolve(exe_spec);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-12-03 22:41:32 +00:00
|
|
|
if (!fs.Exists(exe_spec))
|
|
|
|
|
FileSystem::Instance().ResolveExecutableLocation(exe_spec);
|
|
|
|
|
|
|
|
|
|
if (!fs.Exists(exe_spec)) {
|
2018-01-19 11:10:54 +00:00
|
|
|
error.SetErrorStringWithFormatv("executable doesn't exist: '{0}'",
|
|
|
|
|
exe_spec);
|
2014-10-14 21:55:08 +00:00
|
|
|
return HostProcess();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-14 21:55:08 +00:00
|
|
|
resolved_info.SetExecutableFile(exe_spec, false);
|
|
|
|
|
assert(!resolved_info.GetFlags().Test(eLaunchFlagLaunchInTTY));
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-10-14 21:55:08 +00:00
|
|
|
HostProcess process =
|
|
|
|
|
m_delegate_launcher->LaunchProcess(resolved_info, error);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2014-10-14 21:55:08 +00:00
|
|
|
if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) {
|
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-05-15 13:42:26 +00:00
|
|
|
assert(launch_info.GetMonitorProcessCallback());
|
2019-07-08 07:07:05 +00:00
|
|
|
llvm::Expected<HostThread> maybe_thread =
|
|
|
|
|
process.StartMonitoring(launch_info.GetMonitorProcessCallback(),
|
|
|
|
|
launch_info.GetMonitorSignals());
|
|
|
|
|
if (!maybe_thread)
|
|
|
|
|
error.SetErrorStringWithFormatv("failed to launch host thread: {}",
|
|
|
|
|
llvm::toString(maybe_thread.takeError()));
|
2014-10-14 21:55:08 +00:00
|
|
|
if (log)
|
|
|
|
|
log->PutCString("started monitoring child process.");
|
|
|
|
|
} else {
|
|
|
|
|
// Invalid process ID, something didn't go well
|
2016-05-11 16:59:04 +00:00
|
|
|
if (error.Success())
|
2014-10-14 21:55:08 +00:00
|
|
|
error.SetErrorString("process launch failed for unknown reasons");
|
|
|
|
|
}
|
|
|
|
|
return process;
|
|
|
|
|
}
|