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