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 liblldb_ProcessLaunch_Info_h
10 #define liblldb_ProcessLaunch_Info_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"
23 
24 namespace lldb_private {
25 
26 // ProcessLaunchInfo
27 //
28 // Describes any information that is required to launch a process.
29 
31 public:
33 
34  ProcessLaunchInfo(const FileSpec &stdin_file_spec,
35  const FileSpec &stdout_file_spec,
36  const FileSpec &stderr_file_spec,
37  const FileSpec &working_dir, uint32_t launch_flags);
38 
39  void AppendFileAction(const FileAction &info) {
40  m_file_actions.push_back(info);
41  }
42 
43  bool AppendCloseFileAction(int fd);
44 
45  bool AppendDuplicateFileAction(int fd, int dup_fd);
46 
47  bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read,
48  bool write);
49 
50  bool AppendSuppressFileAction(int fd, bool read, bool write);
51 
52  // Redirect stdin/stdout/stderr to a pty, if no action for the respective file
53  // descriptor is specified. (So if stdin and stdout already have file actions,
54  // but stderr doesn't, then only stderr will be redirected to a pty.)
56 
57  size_t GetNumFileActions() const { return m_file_actions.size(); }
58 
59  const FileAction *GetFileActionAtIndex(size_t idx) const;
60 
61  const FileAction *GetFileActionForFD(int fd) const;
62 
63  Flags &GetFlags() { return m_flags; }
64 
65  const Flags &GetFlags() const { return m_flags; }
66 
67  const FileSpec &GetWorkingDirectory() const;
68 
69  void SetWorkingDirectory(const FileSpec &working_dir);
70 
71  const char *GetProcessPluginName() const;
72 
73  void SetProcessPluginName(llvm::StringRef plugin);
74 
75  const FileSpec &GetShell() const;
76 
77  void SetShell(const FileSpec &shell);
78 
80 
82 
84  return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
85  }
86 
88 
89  bool GetShellExpandArguments() const {
90  return m_flags.Test(lldb::eLaunchFlagShellExpandArguments);
91  }
92 
93  void SetShellExpandArguments(bool expand);
94 
95  void Clear();
96 
97  bool ConvertArgumentsForLaunchingInShell(Status &error, bool localhost,
98  bool will_debug,
99  bool first_arg_is_full_shell_command,
100  int32_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 protected:
152  std::string m_plugin_name;
154  Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
155  std::vector<FileAction> m_file_actions; // File actions for any other files
156  std::shared_ptr<PseudoTerminal> m_pty;
157  uint32_t m_resume_count; // How many times do we resume after launching
161  std::string m_event_data; // A string passed to the plugin launch, having no
162  // meaning to the upper levels of lldb.
163  lldb::ListenerSP m_listener_sp;
164  lldb::ListenerSP m_hijack_listener_sp;
165 };
166 }
167 
168 #endif // liblldb_ProcessLaunch_Info_h
void SetListener(const lldb::ListenerSP &listener_sp)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
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.
std::vector< FileAction > m_file_actions
void SetLaunchEventData(const char *data)
bool AppendSuppressFileAction(int fd, bool read, bool write)
llvm::Error Error
Host::MonitorChildProcessCallback GetMonitorProcessCallback() const
A file utility class.
Definition: FileSpec.h:55
A pseudo terminal helper class.
Host::MonitorChildProcessCallback m_monitor_callback
lldb::ListenerSP GetListener() const
const Flags & GetFlags() const
void SetProcessPluginName(llvm::StringRef plugin)
bool Test(ValueType bit) const
Test a single flag bit.
Definition: Flags.h:107
bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read, bool write)
static bool separate(size_t count)
Definition: UUID.cpp:24
void SetHijackListener(const lldb::ListenerSP &listener_sp)
void SetLaunchInSeparateProcessGroup(bool separate)
const FileAction * GetFileActionForFD(int fd) const
void AppendFileAction(const FileAction &info)
const char * GetLaunchEventData() const
A class to manage flags.
Definition: Flags.h:22
bool ConvertArgumentsForLaunchingInShell(Status &error, bool localhost, bool will_debug, bool first_arg_is_full_shell_command, int32_t num_resumes)
const FileSpec & GetWorkingDirectory() const
void SetWorkingDirectory(const FileSpec &working_dir)
uint64_t pid_t
Definition: lldb-types.h:85
lldb::ListenerSP GetHijackListener() const
const FileSpec & GetShell() const
std::shared_ptr< PseudoTerminal > m_pty
std::function< bool(lldb::pid_t pid, bool exited, int signal, int status)> MonitorChildProcessCallback
Definition: Host.h:68
const FileAction * GetFileActionAtIndex(size_t idx) const
void SetMonitorProcessCallback(const Host::MonitorChildProcessCallback &callback, bool monitor_signals)
void SetShell(const FileSpec &shell)
const char * GetProcessPluginName() const
bool AppendDuplicateFileAction(int fd, int dup_fd)
An error handling class.
Definition: Status.h:44