1 //===-- MonitoringProcessLauncher.cpp ---------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Host/MonitoringProcessLauncher.h" 11 #include "lldb/Host/HostProcess.h" 12 #include "lldb/Target/ProcessLaunchInfo.h" 13 #include "lldb/Utility/Log.h" 14 #include "lldb/Utility/Status.h" 15 16 #include "llvm/Support/FileSystem.h" 17 18 using namespace lldb; 19 using namespace lldb_private; 20 21 MonitoringProcessLauncher::MonitoringProcessLauncher( 22 std::unique_ptr<ProcessLauncher> delegate_launcher) 23 : m_delegate_launcher(std::move(delegate_launcher)) {} 24 25 HostProcess 26 MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info, 27 Status &error) { 28 ProcessLaunchInfo resolved_info(launch_info); 29 30 error.Clear(); 31 32 FileSpec exe_spec(resolved_info.GetExecutableFile()); 33 34 llvm::sys::fs::file_status stats; 35 status(exe_spec.GetPath(), stats); 36 if (!exists(stats)) { 37 exe_spec.ResolvePath(); 38 status(exe_spec.GetPath(), stats); 39 } 40 if (!exists(stats)) { 41 exe_spec.ResolveExecutableLocation(); 42 status(exe_spec.GetPath(), stats); 43 } 44 45 if (!exists(stats)) { 46 error.SetErrorStringWithFormatv("executable doesn't exist: '{0}'", 47 exe_spec); 48 return HostProcess(); 49 } 50 51 resolved_info.SetExecutableFile(exe_spec, false); 52 assert(!resolved_info.GetFlags().Test(eLaunchFlagLaunchInTTY)); 53 54 HostProcess process = 55 m_delegate_launcher->LaunchProcess(resolved_info, error); 56 57 if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) { 58 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); 59 60 assert(launch_info.GetMonitorProcessCallback()); 61 process.StartMonitoring(launch_info.GetMonitorProcessCallback(), 62 launch_info.GetMonitorSignals()); 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.SetErrorString("process launch failed for unknown reasons"); 69 } 70 return process; 71 } 72