1 //===-- MonitoringProcessLauncher.cpp ---------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Host/MonitoringProcessLauncher.h"
10 #include "lldb/Host/FileSystem.h"
11 #include "lldb/Host/HostProcess.h"
12 #include "lldb/Host/ProcessLaunchInfo.h"
13 #include "lldb/Utility/Log.h"
15 #include "llvm/Support/FileSystem.h"
18 using namespace lldb_private;
20 MonitoringProcessLauncher::MonitoringProcessLauncher(
21 std::unique_ptr<ProcessLauncher> delegate_launcher)
22 : m_delegate_launcher(std::move(delegate_launcher)) {}
25 MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info,
27 ProcessLaunchInfo resolved_info(launch_info);
31 FileSystem &fs = FileSystem::Instance();
32 FileSpec exe_spec(resolved_info.GetExecutableFile());
34 if (!fs.Exists(exe_spec))
35 FileSystem::Instance().Resolve(exe_spec);
37 if (!fs.Exists(exe_spec))
38 FileSystem::Instance().ResolveExecutableLocation(exe_spec);
40 if (!fs.Exists(exe_spec)) {
41 error.SetErrorStringWithFormatv("executable doesn't exist: '{0}'",
46 resolved_info.SetExecutableFile(exe_spec, false);
47 assert(!resolved_info.GetFlags().Test(eLaunchFlagLaunchInTTY));
50 m_delegate_launcher->LaunchProcess(resolved_info, error);
52 if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) {
53 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
55 assert(launch_info.GetMonitorProcessCallback());
56 llvm::Expected<HostThread> maybe_thread =
57 process.StartMonitoring(launch_info.GetMonitorProcessCallback(),
58 launch_info.GetMonitorSignals());
60 error.SetErrorStringWithFormatv("failed to launch host thread: {}",
61 llvm::toString(maybe_thread.takeError()));
63 log->PutCString("started monitoring child process.");
65 // Invalid process ID, something didn't go well
67 error.SetErrorString("process launch failed for unknown reasons");