Path: blob/main/contrib/llvm-project/lldb/source/Host/common/MonitoringProcessLauncher.cpp
39606 views
//===-- MonitoringProcessLauncher.cpp -------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Host/MonitoringProcessLauncher.h"9#include "lldb/Host/FileSystem.h"10#include "lldb/Host/HostProcess.h"11#include "lldb/Host/ProcessLaunchInfo.h"12#include "lldb/Utility/LLDBLog.h"13#include "lldb/Utility/Log.h"1415#include "llvm/Support/FileSystem.h"1617using namespace lldb;18using namespace lldb_private;1920MonitoringProcessLauncher::MonitoringProcessLauncher(21std::unique_ptr<ProcessLauncher> delegate_launcher)22: m_delegate_launcher(std::move(delegate_launcher)) {}2324HostProcess25MonitoringProcessLauncher::LaunchProcess(const ProcessLaunchInfo &launch_info,26Status &error) {27ProcessLaunchInfo resolved_info(launch_info);2829error.Clear();3031FileSystem &fs = FileSystem::Instance();32FileSpec exe_spec(resolved_info.GetExecutableFile());3334if (!fs.Exists(exe_spec))35FileSystem::Instance().Resolve(exe_spec);3637if (!fs.Exists(exe_spec))38FileSystem::Instance().ResolveExecutableLocation(exe_spec);3940if (!fs.Exists(exe_spec)) {41error.SetErrorStringWithFormatv("executable doesn't exist: '{0}'",42exe_spec);43return HostProcess();44}4546resolved_info.SetExecutableFile(exe_spec, false);47assert(!resolved_info.GetFlags().Test(eLaunchFlagLaunchInTTY));4849HostProcess process =50m_delegate_launcher->LaunchProcess(resolved_info, error);5152if (process.GetProcessId() != LLDB_INVALID_PROCESS_ID) {53Log *log = GetLog(LLDBLog::Process);5455assert(launch_info.GetMonitorProcessCallback());56llvm::Expected<HostThread> maybe_thread =57process.StartMonitoring(launch_info.GetMonitorProcessCallback());58if (!maybe_thread)59error.SetErrorStringWithFormatv("failed to launch host thread: {}",60llvm::toString(maybe_thread.takeError()));61if (log)62log->PutCString("started monitoring child process.");63} else {64// Invalid process ID, something didn't go well65if (error.Success())66error.SetErrorString("process launch failed for unknown reasons");67}68return process;69}707172