1 //===-- MonitoringProcessLauncher.cpp ---------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Host/MonitoringProcessLauncher.h"
11 #include "lldb/Core/Error.h"
12 #include "lldb/Core/Log.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Core/ModuleSpec.h"
15 #include "lldb/Host/HostProcess.h"
16 #include "lldb/Target/Platform.h"
17 #include "lldb/Target/Process.h"
18 #include "lldb/Target/ProcessLaunchInfo.h"
21 using namespace lldb_private;
23 MonitoringProcessLauncher::MonitoringProcessLauncher(
24 std::unique_ptr<ProcessLauncher> delegate_launcher)
25 : m_delegate_launcher(std::move(delegate_launcher)) {}
28 MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info,
30 ProcessLaunchInfo resolved_info(launch_info);
33 char exe_path[PATH_MAX];
35 PlatformSP host_platform_sp(Platform::GetHostPlatform());
37 const ArchSpec &arch_spec = resolved_info.GetArchitecture();
39 FileSpec exe_spec(resolved_info.GetExecutableFile());
41 FileSpec::FileType file_type = exe_spec.GetFileType();
42 if (file_type != FileSpec::eFileTypeRegular) {
43 ModuleSpec module_spec(exe_spec, arch_spec);
44 lldb::ModuleSP exe_module_sp;
46 host_platform_sp->ResolveExecutable(module_spec, exe_module_sp, NULL);
52 exe_spec = exe_module_sp->GetFileSpec();
55 if (exe_spec.Exists()) {
56 exe_spec.GetPath(exe_path, sizeof(exe_path));
58 resolved_info.GetExecutableFile().GetPath(exe_path, sizeof(exe_path));
59 error.SetErrorStringWithFormat("executable doesn't exist: '%s'", exe_path);
63 resolved_info.SetExecutableFile(exe_spec, false);
64 assert(!resolved_info.GetFlags().Test(eLaunchFlagLaunchInTTY));
67 m_delegate_launcher->LaunchProcess(resolved_info, error);
69 if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) {
70 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
72 Host::MonitorChildProcessCallback callback =
73 launch_info.GetMonitorProcessCallback();
75 bool monitor_signals = false;
77 // If the ProcessLaunchInfo specified a callback, use that.
78 monitor_signals = launch_info.GetMonitorSignals();
80 callback = Process::SetProcessExitStatus;
83 process.StartMonitoring(callback, monitor_signals);
85 log->PutCString("started monitoring child process.");
87 // Invalid process ID, something didn't go well
89 error.SetErrorString("process launch failed for unknown reasons");