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 
18 #include "lldb/Host/FileAction.h"
19 #include "lldb/Host/Host.h"
21 #include "lldb/Utility/FileSpec.h"
24 
25 namespace lldb_private {
26 
27 // ProcessLaunchInfo
28 //
29 // Describes any information that is required to launch a process.
30 
32 public:
34 
35  ProcessLaunchInfo(const FileSpec &stdin_file_spec,
36  const FileSpec &stdout_file_spec,
37  const FileSpec &stderr_file_spec,
38  const FileSpec &working_dir, uint32_t launch_flags);
39 
40  void AppendFileAction(const FileAction &info) {
41  m_file_actions.push_back(info);
42  }
43 
44  bool AppendCloseFileAction(int fd);
45 
46  bool AppendDuplicateFileAction(int fd, int dup_fd);
47 
48  bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read,
49  bool write);
50 
51  bool AppendSuppressFileAction(int fd, bool read, bool write);
52 
53  // Redirect stdin/stdout/stderr to a pty, if no action for the respective file
54  // descriptor is specified. (So if stdin and stdout already have file actions,
55  // but stderr doesn't, then only stderr will be redirected to a pty.)
57 
58  size_t GetNumFileActions() const { return m_file_actions.size(); }
59 
60  const FileAction *GetFileActionAtIndex(size_t idx) const;
61 
62  const FileAction *GetFileActionForFD(int fd) const;
63 
64  Flags &GetFlags() { return m_flags; }
65 
66  const Flags &GetFlags() const { return m_flags; }
67 
68  const FileSpec &GetWorkingDirectory() const;
69 
70  void SetWorkingDirectory(const FileSpec &working_dir);
71 
72  const char *GetProcessPluginName() const;
73 
74  void SetProcessPluginName(llvm::StringRef plugin);
75 
76  const FileSpec &GetShell() const;
77 
78  void SetShell(const FileSpec &shell);
79 
81 
83 
85  return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
86  }
87 
89 
90  bool GetShellExpandArguments() const {
91  return m_flags.Test(lldb::eLaunchFlagShellExpandArguments);
92  }
93 
94  void SetShellExpandArguments(bool expand);
95 
96  void Clear();
97 
98  bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug,
99  bool first_arg_is_full_shell_command,
100  uint32_t num_resumes);
101 
102  void
104  bool monitor_signals);
105 
107  return m_monitor_callback;
108  }
109 
110  /// A Monitor callback which does not take any action on process events. Use
111  /// this if you don't need to take any particular action when the process
112  /// terminates, but you still need to reap it.
113  static bool NoOpMonitorCallback(lldb::pid_t pid, bool exited, int signal,
114  int status);
115 
116  bool GetMonitorSignals() const { return m_monitor_signals; }
117 
118  // If the LaunchInfo has a monitor callback, then arrange to monitor the
119  // process. Return true if the LaunchInfo has taken care of monitoring the
120  // process, and false if the caller might want to monitor the process
121  // themselves.
122 
123  bool MonitorProcess() const;
124 
125  PseudoTerminal &GetPTY() { return *m_pty; }
126 
127  // Get and set the actual listener that will be used for the process events
128  lldb::ListenerSP GetListener() const { return m_listener_sp; }
129 
130  void SetListener(const lldb::ListenerSP &listener_sp) {
131  m_listener_sp = listener_sp;
132  }
133 
134  lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
135 
136  void SetHijackListener(const lldb::ListenerSP &listener_sp) {
137  m_hijack_listener_sp = listener_sp;
138  }
139 
140  void SetLaunchEventData(const char *data) { m_event_data.assign(data); }
141 
142  const char *GetLaunchEventData() const { return m_event_data.c_str(); }
143 
144  void SetDetachOnError(bool enable);
145 
146  bool GetDetachOnError() const {
147  return m_flags.Test(lldb::eLaunchFlagDetachOnError);
148  }
149 
150  bool IsScriptedProcess() const {
151  return !m_scripted_process_class_name.empty();
152  }
153 
156  }
157 
160  }
161 
165  }
166 
169  m_scripted_process_dictionary_sp = dictionary_sp;
170  }
171 
172 protected:
176  Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
177  std::vector<FileAction> m_file_actions; // File actions for any other files
178  std::shared_ptr<PseudoTerminal> m_pty;
179  uint32_t m_resume_count = 0; // How many times do we resume after launching
181  void *m_monitor_callback_baton = nullptr;
182  bool m_monitor_signals = false;
183  std::string m_event_data; // A string passed to the plugin launch, having no
184  // meaning to the upper levels of lldb.
185  lldb::ListenerSP m_listener_sp;
186  lldb::ListenerSP m_hijack_listener_sp;
187  std::string m_scripted_process_class_name; // The name of the class that will
188  // manage a scripted process.
190  m_scripted_process_dictionary_sp; // A dictionary that holds key/value
191  // pairs passed to the scripted process.
192 };
193 }
194 
195 #endif // LLDB_HOST_PROCESSLAUNCHINFO_H
lldb_private::PseudoTerminal
Definition: PseudoTerminal.h:24
lldb_private::ProcessLaunchInfo::GetDetachOnError
bool GetDetachOnError() const
Definition: ProcessLaunchInfo.h:146
separate
static bool separate(size_t count)
Definition: UUID.cpp:24
lldb_private::ProcessLaunchInfo::AppendDuplicateFileAction
bool AppendDuplicateFileAction(int fd, int dup_fd)
Definition: ProcessLaunchInfo.cpp:81
lldb_private::ProcessLaunchInfo::m_event_data
std::string m_event_data
Definition: ProcessLaunchInfo.h:183
lldb_private::ProcessLaunchInfo::m_pty
std::shared_ptr< PseudoTerminal > m_pty
Definition: ProcessLaunchInfo.h:178
lldb_private::ProcessLaunchInfo::SetWorkingDirectory
void SetWorkingDirectory(const FileSpec &working_dir)
Definition: ProcessLaunchInfo.cpp:128
lldb_private::Host::MonitorChildProcessCallback
std::function< bool(lldb::pid_t pid, bool exited, int signal, int status)> MonitorChildProcessCallback
Definition: Host.h:68
lldb_private::ProcessLaunchInfo::GetMonitorProcessCallback
Host::MonitorChildProcessCallback GetMonitorProcessCallback() const
Definition: ProcessLaunchInfo.h:106
StructuredData.h
Host.h
lldb_private::ProcessLaunchInfo::SetShell
void SetShell(const FileSpec &shell)
Definition: ProcessLaunchInfo.cpp:142
lldb_private::ProcessLaunchInfo::SetListener
void SetListener(const lldb::ListenerSP &listener_sp)
Definition: ProcessLaunchInfo.h:130
lldb_private::ProcessLaunchInfo::IsScriptedProcess
bool IsScriptedProcess() const
Definition: ProcessLaunchInfo.h:150
lldb_private::ProcessLaunchInfo::SetScriptedProcessDictionarySP
void SetScriptedProcessDictionarySP(lldb_private::StructuredData::DictionarySP dictionary_sp)
Definition: ProcessLaunchInfo.h:167
lldb_private::ProcessLaunchInfo::m_scripted_process_class_name
std::string m_scripted_process_class_name
Definition: ProcessLaunchInfo.h:187
lldb_private::ProcessLaunchInfo::m_working_dir
FileSpec m_working_dir
Definition: ProcessLaunchInfo.h:173
lldb_private::ProcessLaunchInfo::m_monitor_callback_baton
void * m_monitor_callback_baton
Definition: ProcessLaunchInfo.h:181
lldb_private::ProcessLaunchInfo::GetFileActionForFD
const FileAction * GetFileActionForFD(int fd) const
Definition: ProcessLaunchInfo.cpp:116
lldb_private::Flags
Definition: Flags.h:22
lldb_private::Flags::Test
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:96
lldb_private::ProcessLaunchInfo::SetShellExpandArguments
void SetShellExpandArguments(bool expand)
Definition: ProcessLaunchInfo.cpp:158
lldb_private::ProcessLaunchInfo::GetFlags
Flags & GetFlags()
Definition: ProcessLaunchInfo.h:64
lldb_private::ProcessLaunchInfo::NoOpMonitorCallback
static bool NoOpMonitorCallback(lldb::pid_t pid, bool exited, int signal, int status)
A Monitor callback which does not take any action on process events.
Definition: ProcessLaunchInfo.cpp:185
lldb_private::ProcessLaunchInfo::SetHijackListener
void SetHijackListener(const lldb::ListenerSP &listener_sp)
Definition: ProcessLaunchInfo.h:136
lldb_private::ProcessLaunchInfo::AppendFileAction
void AppendFileAction(const FileAction &info)
Definition: ProcessLaunchInfo.h:40
lldb_private::FileAction
Definition: FileAction.h:17
lldb_private::ProcessLaunchInfo::m_flags
Flags m_flags
Definition: ProcessLaunchInfo.h:176
lldb_private::ProcessLaunchInfo::AppendCloseFileAction
bool AppendCloseFileAction(int fd)
Definition: ProcessLaunchInfo.cpp:72
lldb_private::ProcessLaunchInfo::m_monitor_signals
bool m_monitor_signals
Definition: ProcessLaunchInfo.h:182
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::ProcessLaunchInfo::AppendSuppressFileAction
bool AppendSuppressFileAction(int fd, bool read, bool write)
Definition: ProcessLaunchInfo.cpp:100
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::ProcessLaunchInfo::m_monitor_callback
Host::MonitorChildProcessCallback m_monitor_callback
Definition: ProcessLaunchInfo.h:180
ProcessInfo.h
lldb_private::ProcessLaunchInfo::Clear
void Clear()
Definition: ProcessLaunchInfo.cpp:165
lldb_private::ProcessLaunchInfo::GetScriptedProcessClassName
std::string GetScriptedProcessClassName() const
Definition: ProcessLaunchInfo.h:154
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb_private::ProcessInfo
Definition: ProcessInfo.h:30
lldb_private::ProcessLaunchInfo::SetDetachOnError
void SetDetachOnError(bool enable)
Definition: ProcessLaunchInfo.cpp:206
lldb_private::ProcessLaunchInfo::GetScriptedProcessDictionarySP
lldb_private::StructuredData::DictionarySP GetScriptedProcessDictionarySP() const
Definition: ProcessLaunchInfo.h:163
lldb_private::ProcessLaunchInfo::SetProcessPluginName
void SetProcessPluginName(llvm::StringRef plugin)
Definition: ProcessLaunchInfo.cpp:136
lldb_private::ProcessLaunchInfo::GetShellExpandArguments
bool GetShellExpandArguments() const
Definition: ProcessLaunchInfo.h:90
lldb_private::ProcessLaunchInfo::SetUpPtyRedirection
llvm::Error SetUpPtyRedirection()
Definition: ProcessLaunchInfo.cpp:213
lldb_private::ProcessLaunchInfo::GetFileActionAtIndex
const FileAction * GetFileActionAtIndex(size_t idx) const
Definition: ProcessLaunchInfo.cpp:110
lldb_private::ProcessLaunchInfo::GetListener
lldb::ListenerSP GetListener() const
Definition: ProcessLaunchInfo.h:128
lldb_private::StructuredData::DictionarySP
std::shared_ptr< Dictionary > DictionarySP
Definition: StructuredData.h:67
lldb_private::ProcessLaunchInfo::m_scripted_process_dictionary_sp
StructuredData::DictionarySP m_scripted_process_dictionary_sp
Definition: ProcessLaunchInfo.h:190
lldb_private::ProcessLaunchInfo::GetNumFileActions
size_t GetNumFileActions() const
Definition: ProcessLaunchInfo.h:58
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
lldb_private::ProcessLaunchInfo::GetWorkingDirectory
const FileSpec & GetWorkingDirectory() const
Definition: ProcessLaunchInfo.cpp:124
lldb_private::ProcessLaunchInfo::SetLaunchInSeparateProcessGroup
void SetLaunchInSeparateProcessGroup(bool separate)
Definition: ProcessLaunchInfo.cpp:151
lldb_private::ProcessLaunchInfo::m_resume_count
uint32_t m_resume_count
Definition: ProcessLaunchInfo.h:179
lldb_private::ProcessLaunchInfo::GetPTY
PseudoTerminal & GetPTY()
Definition: ProcessLaunchInfo.h:125
lldb_private::ProcessLaunchInfo::GetMonitorSignals
bool GetMonitorSignals() const
Definition: ProcessLaunchInfo.h:116
lldb_private::ProcessLaunchInfo::ProcessLaunchInfo
ProcessLaunchInfo()
Definition: ProcessLaunchInfo.cpp:31
lldb_private::ProcessLaunchInfo::SetMonitorProcessCallback
void SetMonitorProcessCallback(const Host::MonitorChildProcessCallback &callback, bool monitor_signals)
Definition: ProcessLaunchInfo.cpp:179
lldb_private::ProcessLaunchInfo::GetLaunchEventData
const char * GetLaunchEventData() const
Definition: ProcessLaunchInfo.h:142
lldb_private::ProcessLaunchInfo::GetProcessPluginName
const char * GetProcessPluginName() const
Definition: ProcessLaunchInfo.cpp:132
lldb_private::ProcessLaunchInfo::SetScriptedProcessClassName
void SetScriptedProcessClassName(std::string name)
Definition: ProcessLaunchInfo.h:158
lldb_private::Status
Definition: Status.h:44
lldb_private::ProcessLaunchInfo::GetResumeCount
uint32_t GetResumeCount() const
Definition: ProcessLaunchInfo.h:80
uint32_t
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::ProcessLaunchInfo::GetShell
const FileSpec & GetShell() const
Definition: ProcessLaunchInfo.cpp:140
lldb_private::ProcessLaunchInfo::m_shell
FileSpec m_shell
Definition: ProcessLaunchInfo.h:175
lldb_private::ProcessLaunchInfo::m_hijack_listener_sp
lldb::ListenerSP m_hijack_listener_sp
Definition: ProcessLaunchInfo.h:186
PseudoTerminal.h
lldb_private::ProcessLaunchInfo::GetHijackListener
lldb::ListenerSP GetHijackListener() const
Definition: ProcessLaunchInfo.h:134
lldb_private::ProcessLaunchInfo::AppendOpenFileAction
bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read, bool write)
Definition: ProcessLaunchInfo.cpp:90
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
FileSpec.h
lldb_private::ProcessLaunchInfo::MonitorProcess
bool MonitorProcess() const
Definition: ProcessLaunchInfo.cpp:192
Flags.h
lldb_private::ProcessLaunchInfo::SetResumeCount
void SetResumeCount(uint32_t c)
Definition: ProcessLaunchInfo.h:82
lldb_private::ProcessLaunchInfo::GetLaunchInSeparateProcessGroup
bool GetLaunchInSeparateProcessGroup() const
Definition: ProcessLaunchInfo.h:84
lldb_private::ProcessLaunchInfo::m_plugin_name
std::string m_plugin_name
Definition: ProcessLaunchInfo.h:174
FileAction.h
lldb_private::ProcessLaunchInfo::m_file_actions
std::vector< FileAction > m_file_actions
Definition: ProcessLaunchInfo.h:177
lldb_private::ProcessLaunchInfo::GetFlags
const Flags & GetFlags() const
Definition: ProcessLaunchInfo.h:66
lldb_private::ProcessLaunchInfo::SetLaunchEventData
void SetLaunchEventData(const char *data)
Definition: ProcessLaunchInfo.h:140
lldb_private::ProcessLaunchInfo::ConvertArgumentsForLaunchingInShell
bool ConvertArgumentsForLaunchingInShell(Status &error, bool will_debug, bool first_arg_is_full_shell_command, uint32_t num_resumes)
Definition: ProcessLaunchInfo.cpp:246
lldb_private::ProcessLaunchInfo::m_listener_sp
lldb::ListenerSP m_listener_sp
Definition: ProcessLaunchInfo.h:185