xref: /NextBSD/contrib/llvm/tools/lldb/include/lldb/Target/ProcessLaunchInfo.h (revision 84d351007654069f9643c8e4b4802a7f5f08ee42)
1 //===-- ProcessLaunchInfo.h -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_ProcessLaunch_Info_h
11 #define liblldb_ProcessLaunch_Info_h
12 
13 // C++ Headers
14 #include <string>
15 
16 // LLDB Headers
17 #include "lldb/Core/Flags.h"
18 #include "lldb/Host/FileSpec.h"
19 #include "lldb/Host/Host.h"
20 #include "lldb/Target/FileAction.h"
21 #include "lldb/Target/ProcessInfo.h"
22 #include "lldb/Utility/PseudoTerminal.h"
23 
24 namespace lldb_private
25 {
26 
27     //----------------------------------------------------------------------
28     // ProcessLaunchInfo
29     //
30     // Describes any information that is required to launch a process.
31     //----------------------------------------------------------------------
32 
33     class ProcessLaunchInfo : public ProcessInfo
34     {
35     public:
36 
37         ProcessLaunchInfo ();
38 
39         ProcessLaunchInfo(const FileSpec &stdin_file_spec,
40                           const FileSpec &stdout_file_spec,
41                           const FileSpec &stderr_file_spec,
42                           const FileSpec &working_dir,
43                           uint32_t launch_flags);
44 
45         void
AppendFileAction(const FileAction & info)46         AppendFileAction (const FileAction &info)
47         {
48             m_file_actions.push_back(info);
49         }
50 
51         bool
52         AppendCloseFileAction (int fd);
53 
54         bool
55         AppendDuplicateFileAction (int fd, int dup_fd);
56 
57         bool
58         AppendOpenFileAction(int fd, const FileSpec &file_spec,
59                              bool read, bool write);
60 
61         bool
62         AppendSuppressFileAction (int fd, bool read, bool write);
63 
64         void
65         FinalizeFileActions (Target *target,
66                              bool default_to_use_pty);
67 
68         size_t
GetNumFileActions()69         GetNumFileActions () const
70         {
71             return m_file_actions.size();
72         }
73 
74         const FileAction *
75         GetFileActionAtIndex (size_t idx) const;
76 
77         const FileAction *
78         GetFileActionForFD (int fd) const;
79 
80         Flags &
GetFlags()81         GetFlags ()
82         {
83             return m_flags;
84         }
85 
86         const Flags &
GetFlags()87         GetFlags () const
88         {
89             return m_flags;
90         }
91 
92         const FileSpec &
93         GetWorkingDirectory() const;
94 
95         void
96         SetWorkingDirectory(const FileSpec &working_dir);
97 
98         const char *
99         GetProcessPluginName () const;
100 
101         void
102         SetProcessPluginName (const char *plugin);
103 
104         const FileSpec &
105         GetShell () const;
106 
107         void
108         SetShell (const FileSpec &shell);
109 
110         uint32_t
GetResumeCount()111         GetResumeCount () const
112         {
113             return m_resume_count;
114         }
115 
116         void
SetResumeCount(uint32_t c)117         SetResumeCount (uint32_t c)
118         {
119             m_resume_count = c;
120         }
121 
122         bool
GetLaunchInSeparateProcessGroup()123         GetLaunchInSeparateProcessGroup() const
124         {
125             return m_flags.Test(lldb::eLaunchFlagLaunchInSeparateProcessGroup);
126         }
127 
128         void
129         SetLaunchInSeparateProcessGroup (bool separate);
130 
131         bool
GetShellExpandArguments()132         GetShellExpandArguments () const
133         {
134             return m_flags.Test(lldb::eLaunchFlagShellExpandArguments);
135         }
136 
137         void
138         SetShellExpandArguments (bool expand);
139 
140         void
141         Clear ();
142 
143         bool
144         ConvertArgumentsForLaunchingInShell (Error &error,
145                                              bool localhost,
146                                              bool will_debug,
147                                              bool first_arg_is_full_shell_command,
148                                              int32_t num_resumes);
149 
150         void
151         SetMonitorProcessCallback (Host::MonitorChildProcessCallback callback,
152                                    void *baton,
153                                    bool monitor_signals);
154 
155         Host::MonitorChildProcessCallback
GetMonitorProcessCallback()156         GetMonitorProcessCallback() const
157         {
158             return m_monitor_callback;
159         }
160 
161         void *
GetMonitorProcessBaton()162         GetMonitorProcessBaton() const
163         {
164             return m_monitor_callback_baton;
165         }
166 
167         bool
GetMonitorSignals()168         GetMonitorSignals() const
169         {
170             return m_monitor_signals;
171         }
172 
173         // If the LaunchInfo has a monitor callback, then arrange to monitor the process.
174         // Return true if the LaunchInfo has taken care of monitoring the process, and false if the
175         // caller might want to monitor the process themselves.
176 
177         bool
178         MonitorProcess () const;
179 
180         lldb_utility::PseudoTerminal &
GetPTY()181         GetPTY ()
182         {
183             return *m_pty;
184         }
185 
186         // Get and set the actual listener that will be used for the process events
187         lldb::ListenerSP
GetListener()188         GetListener () const
189         {
190             return m_listener_sp;
191         }
192 
193         void
SetListener(const lldb::ListenerSP & listener_sp)194         SetListener (const lldb::ListenerSP &listener_sp)
195         {
196             m_listener_sp = listener_sp;
197         }
198 
199         Listener &
200         GetListenerForProcess (Debugger &debugger);
201 
202         lldb::ListenerSP
GetHijackListener()203         GetHijackListener () const
204         {
205             return m_hijack_listener_sp;
206         }
207 
208         void
SetHijackListener(const lldb::ListenerSP & listener_sp)209         SetHijackListener (const lldb::ListenerSP &listener_sp)
210         {
211             m_hijack_listener_sp = listener_sp;
212         }
213 
214         void
SetLaunchEventData(const char * data)215         SetLaunchEventData (const char *data)
216         {
217             m_event_data.assign (data);
218         }
219 
220         const char *
GetLaunchEventData()221         GetLaunchEventData () const
222         {
223             return m_event_data.c_str();
224         }
225 
226         void
227         SetDetachOnError (bool enable);
228 
229         bool
GetDetachOnError()230         GetDetachOnError () const
231         {
232             return m_flags.Test(lldb::eLaunchFlagDetachOnError);
233         }
234 
235     protected:
236         FileSpec m_working_dir;
237         std::string m_plugin_name;
238         FileSpec m_shell;
239         Flags m_flags;       // Bitwise OR of bits from lldb::LaunchFlags
240         std::vector<FileAction> m_file_actions; // File actions for any other files
241         std::shared_ptr<lldb_utility::PseudoTerminal> m_pty;
242         uint32_t m_resume_count; // How many times do we resume after launching
243         Host::MonitorChildProcessCallback m_monitor_callback;
244         void *m_monitor_callback_baton;
245         bool m_monitor_signals;
246         std::string m_event_data; // A string passed to the plugin launch, having no meaning to the upper levels of lldb.
247         lldb::ListenerSP m_listener_sp;
248         lldb::ListenerSP m_hijack_listener_sp;
249     };
250 }
251 
252 #endif // liblldb_ProcessLaunch_Info_h
253