1 //===-- ProcessLaunchInfo.h -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ProcessLaunch_Info_h
11 #define liblldb_ProcessLaunch_Info_h
17 #include "lldb/Utility/Flags.h"
19 #include "lldb/Host/Host.h"
20 #include "lldb/Host/PseudoTerminal.h"
21 #include "lldb/Target/FileAction.h"
22 #include "lldb/Target/ProcessInfo.h"
23 #include "lldb/Utility/FileSpec.h"
25 namespace lldb_private {
27 //----------------------------------------------------------------------
30 // Describes any information that is required to launch a process.
31 //----------------------------------------------------------------------
33 class ProcessLaunchInfo : public ProcessInfo {
37 ProcessLaunchInfo(const FileSpec &stdin_file_spec,
38 const FileSpec &stdout_file_spec,
39 const FileSpec &stderr_file_spec,
40 const FileSpec &working_dir, uint32_t launch_flags);
42 void AppendFileAction(const FileAction &info) {
43 m_file_actions.push_back(info);
46 bool AppendCloseFileAction(int fd);
48 bool AppendDuplicateFileAction(int fd, int dup_fd);
50 bool AppendOpenFileAction(int fd, const FileSpec &file_spec, bool read,
53 bool AppendSuppressFileAction(int fd, bool read, bool write);
55 void FinalizeFileActions(Target *target, bool default_to_use_pty);
57 size_t GetNumFileActions() const { return m_file_actions.size(); }
59 const FileAction *GetFileActionAtIndex(size_t idx) const;
61 const FileAction *GetFileActionForFD(int fd) const;
63 Flags &GetFlags() { return m_flags; }
65 const Flags &GetFlags() const { return m_flags; }
67 const FileSpec &GetWorkingDirectory() const;
69 void SetWorkingDirectory(const FileSpec &working_dir);
71 const char *GetProcessPluginName() const;
73 void SetProcessPluginName(llvm::StringRef plugin);
75 const FileSpec &GetShell() const;
77 void SetShell(const FileSpec &shell);
79 uint32_t GetResumeCount() const { return m_resume_count; }
81 void SetResumeCount(uint32_t c) { m_resume_count = c; }
83 bool GetLaunchInSeparateProcessGroup() const {
84 return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
87 void SetLaunchInSeparateProcessGroup(bool separate);
89 bool GetShellExpandArguments() const {
90 return m_flags.Test(lldb::eLaunchFlagShellExpandArguments);
93 void SetShellExpandArguments(bool expand);
97 bool ConvertArgumentsForLaunchingInShell(Status &error, bool localhost,
99 bool first_arg_is_full_shell_command,
100 int32_t num_resumes);
103 SetMonitorProcessCallback(const Host::MonitorChildProcessCallback &callback,
104 bool monitor_signals);
106 Host::MonitorChildProcessCallback GetMonitorProcessCallback() const {
107 return m_monitor_callback;
110 bool GetMonitorSignals() const { return m_monitor_signals; }
112 // If the LaunchInfo has a monitor callback, then arrange to monitor the
114 // Return true if the LaunchInfo has taken care of monitoring the process, and
116 // caller might want to monitor the process themselves.
118 bool MonitorProcess() const;
120 PseudoTerminal &GetPTY() { return *m_pty; }
122 // Get and set the actual listener that will be used for the process events
123 lldb::ListenerSP GetListener() const { return m_listener_sp; }
125 void SetListener(const lldb::ListenerSP &listener_sp) {
126 m_listener_sp = listener_sp;
129 lldb::ListenerSP GetListenerForProcess(Debugger &debugger);
131 lldb::ListenerSP GetHijackListener() const { return m_hijack_listener_sp; }
133 void SetHijackListener(const lldb::ListenerSP &listener_sp) {
134 m_hijack_listener_sp = listener_sp;
137 void SetLaunchEventData(const char *data) { m_event_data.assign(data); }
139 const char *GetLaunchEventData() const { return m_event_data.c_str(); }
141 void SetDetachOnError(bool enable);
143 bool GetDetachOnError() const {
144 return m_flags.Test(lldb::eLaunchFlagDetachOnError);
148 FileSpec m_working_dir;
149 std::string m_plugin_name;
151 Flags m_flags; // Bitwise OR of bits from lldb::LaunchFlags
152 std::vector<FileAction> m_file_actions; // File actions for any other files
153 std::shared_ptr<PseudoTerminal> m_pty;
154 uint32_t m_resume_count; // How many times do we resume after launching
155 Host::MonitorChildProcessCallback m_monitor_callback;
156 void *m_monitor_callback_baton;
157 bool m_monitor_signals;
158 std::string m_event_data; // A string passed to the plugin launch, having no
159 // meaning to the upper levels of lldb.
160 lldb::ListenerSP m_listener_sp;
161 lldb::ListenerSP m_hijack_listener_sp;
165 #endif // liblldb_ProcessLaunch_Info_h