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