LLDB mainline
MonitoringProcessLauncher.cpp
Go to the documentation of this file.
1//===-- MonitoringProcessLauncher.cpp -------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
14#include "lldb/Utility/Log.h"
15
16#include "llvm/Support/FileSystem.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
22 std::unique_ptr<ProcessLauncher> delegate_launcher)
23 : m_delegate_launcher(std::move(delegate_launcher)) {}
24
27 Status &error) {
28 ProcessLaunchInfo resolved_info(launch_info);
29
30 error.Clear();
31
33 FileSpec exe_spec(resolved_info.GetExecutableFile());
34
35 if (!fs.Exists(exe_spec))
36 FileSystem::Instance().Resolve(exe_spec);
37
38 if (!fs.Exists(exe_spec))
40
41 if (!fs.Exists(exe_spec)) {
43 "executable doesn't exist: '{0}'", exe_spec);
44 return HostProcess();
45 }
46
47 resolved_info.SetExecutableFile(exe_spec, false);
48 assert(!resolved_info.GetFlags().Test(eLaunchFlagLaunchInTTY));
49
50 HostProcess process =
51 m_delegate_launcher->LaunchProcess(resolved_info, error);
52
53 if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) {
55
56 assert(launch_info.GetMonitorProcessCallback());
57 llvm::Expected<HostThread> maybe_thread =
58 process.StartMonitoring(launch_info.GetMonitorProcessCallback());
59 if (!maybe_thread)
61 "failed to launch host thread: {}",
62 llvm::toString(maybe_thread.takeError()));
63 if (log)
64 log->PutCString("started monitoring child process.");
65 } else {
66 // Invalid process ID, something didn't go well
67 if (error.Success())
68 error =
69 Status::FromErrorString("process launch failed for unknown reasons");
70 }
71 return process;
72}
static llvm::raw_ostream & error(Stream &strm)
A file utility class.
Definition: FileSpec.h:56
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
lldb::pid_t GetProcessId() const
Definition: HostProcess.cpp:25
llvm::Expected< HostThread > StartMonitoring(const Host::MonitorChildProcessCallback &callback)
Definition: HostProcess.cpp:31
void PutCString(const char *cstr)
Definition: Log.cpp:145
std::unique_ptr< ProcessLauncher > m_delegate_launcher
HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Status &error) override
Launch the process specified in launch_info.
MonitoringProcessLauncher(std::unique_ptr< ProcessLauncher > delegate_launcher)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
Definition: ProcessInfo.cpp:65
FileSpec & GetExecutableFile()
Definition: ProcessInfo.h:43
const Host::MonitorChildProcessCallback & GetMonitorProcessCallback() const
An error handling class.
Definition: Status.h:115
static Status FromErrorString(const char *str)
Definition: Status.h:138
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition: Status.h:148
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:89
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.
Definition: Log.h:332
Definition: SBAddress.h:15