LLDB mainline
ProcessLaunchInfo.h
Go to the documentation of this file.
1//===-- ProcessLaunchInfo.h -------------------------------------*- 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
9#ifndef LLDB_HOST_PROCESSLAUNCHINFO_H
10#define LLDB_HOST_PROCESSLAUNCHINFO_H
11
12// C++ Headers
13#include <string>
14
15// LLDB Headers
16#include "lldb/Utility/Flags.h"
17
19#include "lldb/Host/Host.h"
20#ifdef _WIN32
22#else
24#endif
27
28namespace lldb_private {
29
30#if defined(_WIN32)
31using PTY = PseudoConsole;
32#else
34#endif
35
36// ProcessLaunchInfo
37//
38// Describes any information that is required to launch a process.
39
41public:
43
44 ProcessLaunchInfo(const FileSpec &stdin_file_spec,
45 const FileSpec &stdout_file_spec,
46 const FileSpec &stderr_file_spec,
47 const FileSpec &working_dir, uint32_t launch_flags);
48
49 void AppendFileAction(const FileAction &info) {
50 m_file_actions.push_back(info);
51 }
52
53 bool AppendCloseFileAction(int fd);
54
55 bool AppendDuplicateFileAction(int fd, int dup_fd);
56
57 bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read,
58 bool write);
59
60 bool AppendSuppressFileAction(int fd, bool read, bool write);
61
62 // Redirect stdin/stdout/stderr to a pty, if no action for the respective file
63 // descriptor is specified. (So if stdin and stdout already have file actions,
64 // but stderr doesn't, then only stderr will be redirected to a pty.)
65 llvm::Error SetUpPtyRedirection();
66
67 size_t GetNumFileActions() const { return m_file_actions.size(); }
68
69 const FileAction *GetFileActionAtIndex(size_t idx) const;
70
71 const FileAction *GetFileActionForFD(int fd) const;
72
73 Flags &GetFlags() { return m_flags; }
74
75 const Flags &GetFlags() const { return m_flags; }
76
77 const FileSpec &GetWorkingDirectory() const;
78
79 void SetWorkingDirectory(const FileSpec &working_dir);
80
81 llvm::StringRef GetProcessPluginName() const;
82
83 void SetProcessPluginName(llvm::StringRef plugin);
84
85 const FileSpec &GetShell() const;
86
87 void SetShell(const FileSpec &shell);
88
89 uint32_t GetResumeCount() const { return m_resume_count; }
90
91 void SetResumeCount(uint32_t c) { m_resume_count = c; }
92
94 return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
95 }
96
98
100 return m_flags.Test(lldb::eLaunchFlagShellExpandArguments);
101 }
102
103 void SetShellExpandArguments(bool expand);
104
105 void Clear();
106
107 bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug,
108 bool first_arg_is_full_shell_command,
109 uint32_t num_resumes);
110
112 m_monitor_callback = std::move(callback);
113 }
114
118
119 /// A Monitor callback which does not take any action on process events. Use
120 /// this if you don't need to take any particular action when the process
121 /// terminates, but you still need to reap it.
122 static void NoOpMonitorCallback(lldb::pid_t pid, int signal, int status);
123
124 // If the LaunchInfo has a monitor callback, then arrange to monitor the
125 // process. Return true if the LaunchInfo has taken care of monitoring the
126 // process, and false if the caller might want to monitor the process
127 // themselves.
128
129 bool MonitorProcess() const;
130
131 PTY &GetPTY() const { return *m_pty; }
132
133 std::shared_ptr<PTY> GetPTYSP() const { return m_pty; }
134
135 void SetLaunchEventData(const char *data) { m_event_data.assign(data); }
136
137 const char *GetLaunchEventData() const { return m_event_data.c_str(); }
138
139 void SetDetachOnError(bool enable);
140
141 bool GetDetachOnError() const {
142 return m_flags.Test(lldb::eLaunchFlagDetachOnError);
143 }
144
145protected:
147 std::string m_plugin_name;
149 Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
150 std::vector<FileAction> m_file_actions; // File actions for any other files
151 std::shared_ptr<PTY> m_pty;
152 uint32_t m_resume_count = 0; // How many times do we resume after launching
154 std::string m_event_data; // A string passed to the plugin launch, having no
155 // meaning to the upper levels of lldb.
156};
157}
158
159#endif // LLDB_HOST_PROCESSLAUNCHINFO_H
static llvm::raw_ostream & error(Stream &strm)
static bool separate(size_t count)
Definition UUID.cpp:29
A file utility class.
Definition FileSpec.h:57
A class to manage flags.
Definition Flags.h:22
std::function< void(lldb::pid_t pid, int signal, int status)> MonitorChildProcessCallback
Definition Host.h:88
llvm::StringRef GetProcessPluginName() const
const FileSpec & GetShell() const
std::vector< FileAction > m_file_actions
const char * GetLaunchEventData() const
bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read, bool write)
void SetLaunchEventData(const char *data)
bool AppendSuppressFileAction(int fd, bool read, bool write)
static void NoOpMonitorCallback(lldb::pid_t pid, int signal, int status)
A Monitor callback which does not take any action on process events.
const FileAction * GetFileActionAtIndex(size_t idx) const
void SetShell(const FileSpec &shell)
const Host::MonitorChildProcessCallback & GetMonitorProcessCallback() const
const FileAction * GetFileActionForFD(int fd) const
void SetProcessPluginName(llvm::StringRef plugin)
std::shared_ptr< PTY > GetPTYSP() const
void SetMonitorProcessCallback(Host::MonitorChildProcessCallback callback)
bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug, bool first_arg_is_full_shell_command, uint32_t num_resumes)
bool AppendDuplicateFileAction(int fd, int dup_fd)
void AppendFileAction(const FileAction &info)
void SetLaunchInSeparateProcessGroup(bool separate)
void SetWorkingDirectory(const FileSpec &working_dir)
Host::MonitorChildProcessCallback m_monitor_callback
const FileSpec & GetWorkingDirectory() const
A pseudo terminal helper class.
An error handling class.
Definition Status.h:118
A class that represents a running process on the host machine.
PseudoTerminal PTY
uint64_t pid_t
Definition lldb-types.h:83