1 //===-- SBLaunchInfo.cpp ----------------------------------------*- 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 #include "lldb/lldb-python.h"
11 
12 #include "lldb/API/SBLaunchInfo.h"
13 
14 #include "lldb/API/SBFileSpec.h"
15 #include "lldb/API/SBListener.h"
16 #include "lldb/Target/ProcessLaunchInfo.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 SBLaunchInfo::SBLaunchInfo (const char **argv) :
22     m_opaque_sp(new ProcessLaunchInfo())
23 {
24     m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR);
25     if (argv && argv[0])
26         m_opaque_sp->GetArguments().SetArguments(argv);
27 }
28 
29 SBLaunchInfo::~SBLaunchInfo()
30 {
31 }
32 
33 lldb_private::ProcessLaunchInfo &
34 SBLaunchInfo::ref ()
35 {
36     return *m_opaque_sp;
37 }
38 
39 const lldb_private::ProcessLaunchInfo &
40 SBLaunchInfo::ref () const
41 {
42     return *m_opaque_sp;
43 }
44 
45 lldb::pid_t
46 SBLaunchInfo::GetProcessID()
47 {
48     return m_opaque_sp->GetProcessID();
49 }
50 
51 uint32_t
52 SBLaunchInfo::GetUserID()
53 {
54     return m_opaque_sp->GetUserID();
55 }
56 
57 uint32_t
58 SBLaunchInfo::GetGroupID()
59 {
60     return m_opaque_sp->GetGroupID();
61 }
62 
63 bool
64 SBLaunchInfo::UserIDIsValid ()
65 {
66     return m_opaque_sp->UserIDIsValid();
67 }
68 
69 bool
70 SBLaunchInfo::GroupIDIsValid ()
71 {
72     return m_opaque_sp->GroupIDIsValid();
73 }
74 
75 void
76 SBLaunchInfo::SetUserID (uint32_t uid)
77 {
78     m_opaque_sp->SetUserID (uid);
79 }
80 
81 void
82 SBLaunchInfo::SetGroupID (uint32_t gid)
83 {
84     m_opaque_sp->SetGroupID (gid);
85 }
86 
87 SBFileSpec
88 SBLaunchInfo::GetExecutableFile ()
89 {
90     return SBFileSpec (m_opaque_sp->GetExecutableFile());
91 }
92 
93 void
94 SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg)
95 {
96     m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
97 }
98 
99 SBListener
100 SBLaunchInfo::GetListener ()
101 {
102     return SBListener(m_opaque_sp->GetListener());
103 }
104 
105 void
106 SBLaunchInfo::SetListener (SBListener &listener)
107 {
108     m_opaque_sp->SetListener(listener.GetSP());
109 }
110 
111 uint32_t
112 SBLaunchInfo::GetNumArguments ()
113 {
114     return m_opaque_sp->GetArguments().GetArgumentCount();
115 }
116 
117 const char *
118 SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
119 {
120     return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
121 }
122 
123 void
124 SBLaunchInfo::SetArguments (const char **argv, bool append)
125 {
126     if (append)
127     {
128         if (argv)
129             m_opaque_sp->GetArguments().AppendArguments(argv);
130     }
131     else
132     {
133         if (argv)
134             m_opaque_sp->GetArguments().SetArguments(argv);
135         else
136             m_opaque_sp->GetArguments().Clear();
137     }
138 }
139 
140 uint32_t
141 SBLaunchInfo::GetNumEnvironmentEntries ()
142 {
143     return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
144 }
145 
146 const char *
147 SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
148 {
149     return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
150 }
151 
152 void
153 SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append)
154 {
155     if (append)
156     {
157         if (envp)
158             m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
159     }
160     else
161     {
162         if (envp)
163             m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
164         else
165             m_opaque_sp->GetEnvironmentEntries().Clear();
166     }
167 }
168 
169 void
170 SBLaunchInfo::Clear ()
171 {
172     m_opaque_sp->Clear();
173 }
174 
175 const char *
176 SBLaunchInfo::GetWorkingDirectory () const
177 {
178     return m_opaque_sp->GetWorkingDirectory();
179 }
180 
181 void
182 SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
183 {
184     m_opaque_sp->SetWorkingDirectory(working_dir);
185 }
186 
187 uint32_t
188 SBLaunchInfo::GetLaunchFlags ()
189 {
190     return m_opaque_sp->GetFlags().Get();
191 }
192 
193 void
194 SBLaunchInfo::SetLaunchFlags (uint32_t flags)
195 {
196     m_opaque_sp->GetFlags().Reset(flags);
197 }
198 
199 const char *
200 SBLaunchInfo::GetProcessPluginName ()
201 {
202     return m_opaque_sp->GetProcessPluginName();
203 }
204 
205 void
206 SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
207 {
208     return m_opaque_sp->SetProcessPluginName (plugin_name);
209 }
210 
211 const char *
212 SBLaunchInfo::GetShell ()
213 {
214     // Constify this string so that it is saved in the string pool.  Otherwise
215     // it would be freed when this function goes out of scope.
216     ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
217     return shell.AsCString();
218 }
219 
220 void
221 SBLaunchInfo::SetShell (const char * path)
222 {
223     m_opaque_sp->SetShell (FileSpec(path, false));
224 }
225 
226 bool
227 SBLaunchInfo::GetShellExpandArguments ()
228 {
229     return m_opaque_sp->GetShellExpandArguments();
230 }
231 
232 void
233 SBLaunchInfo::SetShellExpandArguments (bool expand)
234 {
235     m_opaque_sp->SetShellExpandArguments(expand);
236 }
237 
238 uint32_t
239 SBLaunchInfo::GetResumeCount ()
240 {
241     return m_opaque_sp->GetResumeCount();
242 }
243 
244 void
245 SBLaunchInfo::SetResumeCount (uint32_t c)
246 {
247     m_opaque_sp->SetResumeCount (c);
248 }
249 
250 bool
251 SBLaunchInfo::AddCloseFileAction (int fd)
252 {
253     return m_opaque_sp->AppendCloseFileAction(fd);
254 }
255 
256 bool
257 SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
258 {
259     return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
260 }
261 
262 bool
263 SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write)
264 {
265     return m_opaque_sp->AppendOpenFileAction(fd, path, read, write);
266 }
267 
268 bool
269 SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
270 {
271     return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
272 }
273 
274 void
275 SBLaunchInfo::SetLaunchEventData (const char *data)
276 {
277     m_opaque_sp->SetLaunchEventData (data);
278 }
279 
280 const char *
281 SBLaunchInfo::GetLaunchEventData () const
282 {
283     return m_opaque_sp->GetLaunchEventData ();
284 }
285 
286 void
287 SBLaunchInfo::SetDetachOnError (bool enable)
288 {
289     m_opaque_sp->SetDetachOnError (enable);
290 }
291 
292 bool
293 SBLaunchInfo::GetDetachOnError () const
294 {
295     return m_opaque_sp->GetDetachOnError ();
296 }
297