Go to the documentation of this file.
11 #include "lldb/Host/Config.h"
20 #include "llvm/Support/ConvertUTF.h"
21 #include "llvm/Support/FileSystem.h"
32 ProcessLaunchInfo::ProcessLaunchInfo()
33 :
ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0),
34 m_file_actions(), m_pty(new
PseudoTerminal), m_monitor_callback(nullptr),
35 m_listener_sp(), m_hijack_listener_sp(), m_scripted_process_class_name(),
36 m_scripted_process_dictionary_sp() {}
43 :
ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(launch_flags),
45 m_scripted_process_class_name(), m_scripted_process_dictionary_sp() {
46 if (stdin_file_spec) {
48 const bool read =
true;
49 const bool write =
false;
50 if (file_action.
Open(STDIN_FILENO, stdin_file_spec, read, write))
53 if (stdout_file_spec) {
55 const bool read =
false;
56 const bool write =
true;
57 if (file_action.
Open(STDOUT_FILENO, stdout_file_spec, read, write))
60 if (stderr_file_spec) {
62 const bool read =
false;
63 const bool write =
true;
64 if (file_action.
Open(STDERR_FILENO, stderr_file_spec, read, write))
67 if (working_directory)
73 if (file_action.
Close(fd)) {
90 bool read,
bool write) {
92 if (file_action.
Open(fd, file_spec, read, write)) {
116 for (
size_t idx = 0, count =
m_file_actions.size(); idx < count; ++idx) {
152 m_flags.
Set(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
154 m_flags.
Clear(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
159 m_flags.
Set(lldb::eLaunchFlagShellExpandArguments);
181 LLDB_LOG(log,
"pid = {0}, signal = {1}, status = {2}", pid, signal, status);
186 llvm::Expected<HostThread> maybe_thread =
209 bool any_free = stdin_free || stdout_free || stderr_free;
211 return llvm::Error::success();
213 LLDB_LOG(log,
"Generating a pty to use for stdin/out/err");
220 open_flags |= O_CLOEXEC;
225 const FileSpec secondary_file_spec(
m_pty->GetSecondaryName());
235 return llvm::Error::success();
239 Status &
error,
bool will_debug,
bool first_arg_is_full_shell_command,
243 if (
GetFlags().Test(eLaunchFlagLaunchInShell)) {
248 if (argv ==
nullptr || argv[0] ==
nullptr)
250 Args shell_arguments;
253 if (triple.getOS() == llvm::Triple::Win32 &&
254 !triple.isWindowsCygwinEnvironment())
263 const char *argv0 = argv[0];
272 const size_t empty_path_len = new_path.size();
275 new_path += working_dir.
GetPath();
277 llvm::SmallString<64> cwd;
278 if (! llvm::sys::fs::current_path(cwd))
282 if (HostInfo::GetEnvironmentVar(
"PATH", curr_path)) {
283 if (new_path.size() > empty_path_len)
285 new_path += curr_path;
291 if (triple.getOS() != llvm::Triple::Win32 ||
292 triple.isWindowsCygwinEnvironment())
299 llvm::Triple::Apple &&
303 shell_command.
Printf(
" /usr/bin/arch -arch %s",
318 if (first_arg_is_full_shell_command) {
321 if (argv[0] && !argv[1])
322 shell_command.
Printf(
"%s", argv[0]);
326 for (
size_t i = 0; argv[i] !=
nullptr; ++i) {
338 error.SetErrorString(
"invalid shell path");
341 error.SetErrorString(
"not launching in shell");
const char * toString(AppleArm64ExceptionClass EC)
static bool separate(size_t count)
bool AppendDuplicateFileAction(int fd, int dup_fd)
std::shared_ptr< PseudoTerminal > m_pty
bool ProcessIDIsValid() const
void SetWorkingDirectory(const FileSpec &working_dir)
void SetShell(const FileSpec &shell)
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
void AppendArgument(llvm::StringRef arg_str, char quote_char='\0')
Appends a new argument to the end of the list argument list.
std::string m_scripted_process_class_name
const FileAction * GetFileActionForFD(int fd) const
lldb::pid_t GetProcessID() const
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
void SetShellExpandArguments(bool expand)
llvm::Triple & GetTriple()
Architecture triple accessor.
bool Duplicate(int fd, int dup_fd)
static void NoOpMonitorCallback(lldb::pid_t pid, int signal, int status)
A Monitor callback which does not take any action on process events.
static const char * DEV_NULL
void AppendFileAction(const FileAction &info)
llvm::StringRef GetString() const
bool AppendCloseFileAction(int fd)
bool Open(int fd, const FileSpec &file_spec, bool read, bool write)
bool AppendSuppressFileAction(int fd, bool read, bool write)
static llvm::raw_ostream & error(Stream &strm)
Host::MonitorChildProcessCallback m_monitor_callback
void SetDetachOnError(bool enable)
void SetProcessPluginName(llvm::StringRef plugin)
llvm::Error SetUpPtyRedirection()
const FileAction * GetFileActionAtIndex(size_t idx) const
StructuredData::DictionarySP m_scripted_process_dictionary_sp
static std::string GetShellSafeArgument(const FileSpec &shell, llvm::StringRef unsafe_arg)
string(SUBSTRING ${p} 10 -1 pStripped) if($
const FileSpec & GetWorkingDirectory() const
static llvm::Expected< HostThread > StartMonitoringChildProcess(const MonitorChildProcessCallback &callback, lldb::pid_t pid)
Start monitoring a child process.
void SetLaunchInSeparateProcessGroup(bool separate)
void Clear()
Clears the object state.
const char * GetProcessPluginName() const
bool IsRelative() const
Returns true if the filespec represents a relative path.
const char ** GetConstArgumentVector() const
Gets the argument vector.
const FileSpec & GetShell() const
lldb::ListenerSP m_hijack_listener_sp
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read, bool write)
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
static FileSystem & Instance()
ArchSpec & GetArchitecture()
A class that represents a running process on the host machine.
bool MonitorProcess() const
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
void SetResumeCount(uint32_t c)
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
std::string m_plugin_name
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
std::vector< FileAction > m_file_actions
bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug, bool first_arg_is_full_shell_command, uint32_t num_resumes)
lldb::ListenerSP m_listener_sp