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 class lldb_private::SBLaunchInfoImpl : public ProcessLaunchInfo {
20 public:
SBLaunchInfoImpl()21 SBLaunchInfoImpl()
22 : ProcessLaunchInfo(), m_envp(GetEnvironment().getEnvp()) {}
23
GetEnvp() const24 const char *const *GetEnvp() const { return m_envp; }
RegenerateEnvp()25 void RegenerateEnvp() { m_envp = GetEnvironment().getEnvp(); }
26
operator =(const ProcessLaunchInfo & rhs)27 SBLaunchInfoImpl &operator=(const ProcessLaunchInfo &rhs) {
28 ProcessLaunchInfo::operator=(rhs);
29 RegenerateEnvp();
30 return *this;
31 }
32
33 private:
34 Environment::Envp m_envp;
35 };
36
SBLaunchInfo(const char ** argv)37 SBLaunchInfo::SBLaunchInfo(const char **argv)
38 : m_opaque_sp(new SBLaunchInfoImpl()) {
39 m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
40 if (argv && argv[0])
41 m_opaque_sp->GetArguments().SetArguments(argv);
42 }
43
~SBLaunchInfo()44 SBLaunchInfo::~SBLaunchInfo() {}
45
ref() const46 const lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() const {
47 return *m_opaque_sp;
48 }
49
set_ref(const ProcessLaunchInfo & info)50 void SBLaunchInfo::set_ref(const ProcessLaunchInfo &info) {
51 *m_opaque_sp = info;
52 }
53
GetProcessID()54 lldb::pid_t SBLaunchInfo::GetProcessID() { return m_opaque_sp->GetProcessID(); }
55
GetUserID()56 uint32_t SBLaunchInfo::GetUserID() { return m_opaque_sp->GetUserID(); }
57
GetGroupID()58 uint32_t SBLaunchInfo::GetGroupID() { return m_opaque_sp->GetGroupID(); }
59
UserIDIsValid()60 bool SBLaunchInfo::UserIDIsValid() { return m_opaque_sp->UserIDIsValid(); }
61
GroupIDIsValid()62 bool SBLaunchInfo::GroupIDIsValid() { return m_opaque_sp->GroupIDIsValid(); }
63
SetUserID(uint32_t uid)64 void SBLaunchInfo::SetUserID(uint32_t uid) { m_opaque_sp->SetUserID(uid); }
65
SetGroupID(uint32_t gid)66 void SBLaunchInfo::SetGroupID(uint32_t gid) { m_opaque_sp->SetGroupID(gid); }
67
GetExecutableFile()68 SBFileSpec SBLaunchInfo::GetExecutableFile() {
69 return SBFileSpec(m_opaque_sp->GetExecutableFile());
70 }
71
SetExecutableFile(SBFileSpec exe_file,bool add_as_first_arg)72 void SBLaunchInfo::SetExecutableFile(SBFileSpec exe_file,
73 bool add_as_first_arg) {
74 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
75 }
76
GetListener()77 SBListener SBLaunchInfo::GetListener() {
78 return SBListener(m_opaque_sp->GetListener());
79 }
80
SetListener(SBListener & listener)81 void SBLaunchInfo::SetListener(SBListener &listener) {
82 m_opaque_sp->SetListener(listener.GetSP());
83 }
84
GetNumArguments()85 uint32_t SBLaunchInfo::GetNumArguments() {
86 return m_opaque_sp->GetArguments().GetArgumentCount();
87 }
88
GetArgumentAtIndex(uint32_t idx)89 const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
90 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
91 }
92
SetArguments(const char ** argv,bool append)93 void SBLaunchInfo::SetArguments(const char **argv, bool append) {
94 if (append) {
95 if (argv)
96 m_opaque_sp->GetArguments().AppendArguments(argv);
97 } else {
98 if (argv)
99 m_opaque_sp->GetArguments().SetArguments(argv);
100 else
101 m_opaque_sp->GetArguments().Clear();
102 }
103 }
104
GetNumEnvironmentEntries()105 uint32_t SBLaunchInfo::GetNumEnvironmentEntries() {
106 return m_opaque_sp->GetEnvironment().size();
107 }
108
GetEnvironmentEntryAtIndex(uint32_t idx)109 const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) {
110 if (idx > GetNumEnvironmentEntries())
111 return nullptr;
112 return m_opaque_sp->GetEnvp()[idx];
113 }
114
SetEnvironmentEntries(const char ** envp,bool append)115 void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
116 Environment env(envp);
117 if (append)
118 m_opaque_sp->GetEnvironment().insert(env.begin(), env.end());
119 else
120 m_opaque_sp->GetEnvironment() = env;
121 m_opaque_sp->RegenerateEnvp();
122 }
123
Clear()124 void SBLaunchInfo::Clear() { m_opaque_sp->Clear(); }
125
GetWorkingDirectory() const126 const char *SBLaunchInfo::GetWorkingDirectory() const {
127 return m_opaque_sp->GetWorkingDirectory().GetCString();
128 }
129
SetWorkingDirectory(const char * working_dir)130 void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
131 m_opaque_sp->SetWorkingDirectory(FileSpec(working_dir));
132 }
133
GetLaunchFlags()134 uint32_t SBLaunchInfo::GetLaunchFlags() {
135 return m_opaque_sp->GetFlags().Get();
136 }
137
SetLaunchFlags(uint32_t flags)138 void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
139 m_opaque_sp->GetFlags().Reset(flags);
140 }
141
GetProcessPluginName()142 const char *SBLaunchInfo::GetProcessPluginName() {
143 return m_opaque_sp->GetProcessPluginName();
144 }
145
SetProcessPluginName(const char * plugin_name)146 void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
147 return m_opaque_sp->SetProcessPluginName(plugin_name);
148 }
149
GetShell()150 const char *SBLaunchInfo::GetShell() {
151 // Constify this string so that it is saved in the string pool. Otherwise it
152 // would be freed when this function goes out of scope.
153 ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
154 return shell.AsCString();
155 }
156
SetShell(const char * path)157 void SBLaunchInfo::SetShell(const char *path) {
158 m_opaque_sp->SetShell(FileSpec(path));
159 }
160
GetShellExpandArguments()161 bool SBLaunchInfo::GetShellExpandArguments() {
162 return m_opaque_sp->GetShellExpandArguments();
163 }
164
SetShellExpandArguments(bool expand)165 void SBLaunchInfo::SetShellExpandArguments(bool expand) {
166 m_opaque_sp->SetShellExpandArguments(expand);
167 }
168
GetResumeCount()169 uint32_t SBLaunchInfo::GetResumeCount() {
170 return m_opaque_sp->GetResumeCount();
171 }
172
SetResumeCount(uint32_t c)173 void SBLaunchInfo::SetResumeCount(uint32_t c) {
174 m_opaque_sp->SetResumeCount(c);
175 }
176
AddCloseFileAction(int fd)177 bool SBLaunchInfo::AddCloseFileAction(int fd) {
178 return m_opaque_sp->AppendCloseFileAction(fd);
179 }
180
AddDuplicateFileAction(int fd,int dup_fd)181 bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
182 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
183 }
184
AddOpenFileAction(int fd,const char * path,bool read,bool write)185 bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
186 bool write) {
187 return m_opaque_sp->AppendOpenFileAction(fd, FileSpec(path), read, write);
188 }
189
AddSuppressFileAction(int fd,bool read,bool write)190 bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
191 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
192 }
193
SetLaunchEventData(const char * data)194 void SBLaunchInfo::SetLaunchEventData(const char *data) {
195 m_opaque_sp->SetLaunchEventData(data);
196 }
197
GetLaunchEventData() const198 const char *SBLaunchInfo::GetLaunchEventData() const {
199 return m_opaque_sp->GetLaunchEventData();
200 }
201
SetDetachOnError(bool enable)202 void SBLaunchInfo::SetDetachOnError(bool enable) {
203 m_opaque_sp->SetDetachOnError(enable);
204 }
205
GetDetachOnError() const206 bool SBLaunchInfo::GetDetachOnError() const {
207 return m_opaque_sp->GetDetachOnError();
208 }
209