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
SBLaunchInfo(const char ** argv)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
~SBLaunchInfo()27 SBLaunchInfo::~SBLaunchInfo()
28 {
29 }
30
31 lldb_private::ProcessLaunchInfo &
ref()32 SBLaunchInfo::ref ()
33 {
34 return *m_opaque_sp;
35 }
36
37 const lldb_private::ProcessLaunchInfo &
ref() const38 SBLaunchInfo::ref () const
39 {
40 return *m_opaque_sp;
41 }
42
43 lldb::pid_t
GetProcessID()44 SBLaunchInfo::GetProcessID()
45 {
46 return m_opaque_sp->GetProcessID();
47 }
48
49 uint32_t
GetUserID()50 SBLaunchInfo::GetUserID()
51 {
52 return m_opaque_sp->GetUserID();
53 }
54
55 uint32_t
GetGroupID()56 SBLaunchInfo::GetGroupID()
57 {
58 return m_opaque_sp->GetGroupID();
59 }
60
61 bool
UserIDIsValid()62 SBLaunchInfo::UserIDIsValid ()
63 {
64 return m_opaque_sp->UserIDIsValid();
65 }
66
67 bool
GroupIDIsValid()68 SBLaunchInfo::GroupIDIsValid ()
69 {
70 return m_opaque_sp->GroupIDIsValid();
71 }
72
73 void
SetUserID(uint32_t uid)74 SBLaunchInfo::SetUserID (uint32_t uid)
75 {
76 m_opaque_sp->SetUserID (uid);
77 }
78
79 void
SetGroupID(uint32_t gid)80 SBLaunchInfo::SetGroupID (uint32_t gid)
81 {
82 m_opaque_sp->SetGroupID (gid);
83 }
84
85 SBFileSpec
GetExecutableFile()86 SBLaunchInfo::GetExecutableFile ()
87 {
88 return SBFileSpec (m_opaque_sp->GetExecutableFile());
89 }
90
91 void
SetExecutableFile(SBFileSpec exe_file,bool add_as_first_arg)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
GetListener()98 SBLaunchInfo::GetListener ()
99 {
100 return SBListener(m_opaque_sp->GetListener());
101 }
102
103 void
SetListener(SBListener & listener)104 SBLaunchInfo::SetListener (SBListener &listener)
105 {
106 m_opaque_sp->SetListener(listener.GetSP());
107 }
108
109 uint32_t
GetNumArguments()110 SBLaunchInfo::GetNumArguments ()
111 {
112 return m_opaque_sp->GetArguments().GetArgumentCount();
113 }
114
115 const char *
GetArgumentAtIndex(uint32_t idx)116 SBLaunchInfo::GetArgumentAtIndex (uint32_t idx)
117 {
118 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
119 }
120
121 void
SetArguments(const char ** argv,bool append)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
GetNumEnvironmentEntries()139 SBLaunchInfo::GetNumEnvironmentEntries ()
140 {
141 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
142 }
143
144 const char *
GetEnvironmentEntryAtIndex(uint32_t idx)145 SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx)
146 {
147 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
148 }
149
150 void
SetEnvironmentEntries(const char ** envp,bool append)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
Clear()168 SBLaunchInfo::Clear ()
169 {
170 m_opaque_sp->Clear();
171 }
172
173 const char *
GetWorkingDirectory() const174 SBLaunchInfo::GetWorkingDirectory () const
175 {
176 return m_opaque_sp->GetWorkingDirectory().GetCString();
177 }
178
179 void
SetWorkingDirectory(const char * working_dir)180 SBLaunchInfo::SetWorkingDirectory (const char *working_dir)
181 {
182 m_opaque_sp->SetWorkingDirectory(FileSpec{working_dir, false});
183 }
184
185 uint32_t
GetLaunchFlags()186 SBLaunchInfo::GetLaunchFlags ()
187 {
188 return m_opaque_sp->GetFlags().Get();
189 }
190
191 void
SetLaunchFlags(uint32_t flags)192 SBLaunchInfo::SetLaunchFlags (uint32_t flags)
193 {
194 m_opaque_sp->GetFlags().Reset(flags);
195 }
196
197 const char *
GetProcessPluginName()198 SBLaunchInfo::GetProcessPluginName ()
199 {
200 return m_opaque_sp->GetProcessPluginName();
201 }
202
203 void
SetProcessPluginName(const char * plugin_name)204 SBLaunchInfo::SetProcessPluginName (const char *plugin_name)
205 {
206 return m_opaque_sp->SetProcessPluginName (plugin_name);
207 }
208
209 const char *
GetShell()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
SetShell(const char * path)219 SBLaunchInfo::SetShell (const char * path)
220 {
221 m_opaque_sp->SetShell (FileSpec(path, false));
222 }
223
224 bool
GetShellExpandArguments()225 SBLaunchInfo::GetShellExpandArguments ()
226 {
227 return m_opaque_sp->GetShellExpandArguments();
228 }
229
230 void
SetShellExpandArguments(bool expand)231 SBLaunchInfo::SetShellExpandArguments (bool expand)
232 {
233 m_opaque_sp->SetShellExpandArguments(expand);
234 }
235
236 uint32_t
GetResumeCount()237 SBLaunchInfo::GetResumeCount ()
238 {
239 return m_opaque_sp->GetResumeCount();
240 }
241
242 void
SetResumeCount(uint32_t c)243 SBLaunchInfo::SetResumeCount (uint32_t c)
244 {
245 m_opaque_sp->SetResumeCount (c);
246 }
247
248 bool
AddCloseFileAction(int fd)249 SBLaunchInfo::AddCloseFileAction (int fd)
250 {
251 return m_opaque_sp->AppendCloseFileAction(fd);
252 }
253
254 bool
AddDuplicateFileAction(int fd,int dup_fd)255 SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd)
256 {
257 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
258 }
259
260 bool
AddOpenFileAction(int fd,const char * path,bool read,bool write)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
AddSuppressFileAction(int fd,bool read,bool write)267 SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write)
268 {
269 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
270 }
271
272 void
SetLaunchEventData(const char * data)273 SBLaunchInfo::SetLaunchEventData (const char *data)
274 {
275 m_opaque_sp->SetLaunchEventData (data);
276 }
277
278 const char *
GetLaunchEventData() const279 SBLaunchInfo::GetLaunchEventData () const
280 {
281 return m_opaque_sp->GetLaunchEventData ();
282 }
283
284 void
SetDetachOnError(bool enable)285 SBLaunchInfo::SetDetachOnError (bool enable)
286 {
287 m_opaque_sp->SetDetachOnError (enable);
288 }
289
290 bool
GetDetachOnError() const291 SBLaunchInfo::GetDetachOnError () const
292 {
293 return m_opaque_sp->GetDetachOnError ();
294 }
295