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