LLDB  mainline
MonitoringProcessLauncher.cpp
Go to the documentation of this file.
1 //===-- MonitoringProcessLauncher.cpp ---------------------------*- C++ -*-===//
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 
10 #include "lldb/Host/FileSystem.h"
11 #include "lldb/Host/HostProcess.h"
13 #include "lldb/Utility/Log.h"
14 
15 #include "llvm/Support/FileSystem.h"
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 MonitoringProcessLauncher::MonitoringProcessLauncher(
21  std::unique_ptr<ProcessLauncher> delegate_launcher)
22  : m_delegate_launcher(std::move(delegate_launcher)) {}
23 
26  Status &error) {
27  ProcessLaunchInfo resolved_info(launch_info);
28 
29  error.Clear();
30 
32  FileSpec exe_spec(resolved_info.GetExecutableFile());
33 
34  if (!fs.Exists(exe_spec))
35  FileSystem::Instance().Resolve(exe_spec);
36 
37  if (!fs.Exists(exe_spec))
39 
40  if (!fs.Exists(exe_spec)) {
41  error.SetErrorStringWithFormatv("executable doesn't exist: '{0}'",
42  exe_spec);
43  return HostProcess();
44  }
45 
46  resolved_info.SetExecutableFile(exe_spec, false);
47  assert(!resolved_info.GetFlags().Test(eLaunchFlagLaunchInTTY));
48 
49  HostProcess process =
50  m_delegate_launcher->LaunchProcess(resolved_info, error);
51 
52  if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) {
54 
55  assert(launch_info.GetMonitorProcessCallback());
56  process.StartMonitoring(launch_info.GetMonitorProcessCallback(),
57  launch_info.GetMonitorSignals());
58  if (log)
59  log->PutCString("started monitoring child process.");
60  } else {
61  // Invalid process ID, something didn't go well
62  if (error.Success())
63  error.SetErrorString("process launch failed for unknown reasons");
64  }
65  return process;
66 }
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
#define LIBLLDB_LOG_PROCESS
Definition: Logging.h:15
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
Definition: ProcessInfo.cpp:61
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:92
Host::MonitorChildProcessCallback GetMonitorProcessCallback() const
A file utility class.
Definition: FileSpec.h:55
static FileSystem & Instance()
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:107
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:57
HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Status &error) override
Launch the process specified in launch_info.
void Clear()
Clear the object state.
Definition: Status.cpp:167
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
FileSpec & GetExecutableFile()
Definition: ProcessInfo.h:43
bool Success() const
Test for success condition.
Definition: Status.cpp:287
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
void PutCString(const char *cstr)
Definition: Log.cpp:109
Definition: SBAddress.h:15
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
void SetErrorStringWithFormatv(const char *format, Args &&... args)
Definition: Status.h:185
An error handling class.
Definition: Status.h:44