[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / lldb / source / API / SBLaunchInfo.cpp
blob5c5e69704c7cf95fead48482c9e9b56e989c459a
1 //===-- SBLaunchInfo.cpp ----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBLaunchInfo.h"
10 #include "SBReproducerPrivate.h"
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBListener.h"
14 #include "lldb/Host/ProcessLaunchInfo.h"
16 using namespace lldb;
17 using namespace lldb_private;
19 class lldb_private::SBLaunchInfoImpl : public ProcessLaunchInfo {
20 public:
21 SBLaunchInfoImpl()
22 : ProcessLaunchInfo(), m_envp(GetEnvironment().getEnvp()) {}
24 const char *const *GetEnvp() const { return m_envp; }
25 void RegenerateEnvp() { m_envp = GetEnvironment().getEnvp(); }
27 SBLaunchInfoImpl &operator=(const ProcessLaunchInfo &rhs) {
28 ProcessLaunchInfo::operator=(rhs);
29 RegenerateEnvp();
30 return *this;
33 private:
34 Environment::Envp m_envp;
37 SBLaunchInfo::SBLaunchInfo(const char **argv)
38 : m_opaque_sp(new SBLaunchInfoImpl()) {
39 LLDB_RECORD_CONSTRUCTOR(SBLaunchInfo, (const char **), argv);
41 m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
42 if (argv && argv[0])
43 m_opaque_sp->GetArguments().SetArguments(argv);
46 SBLaunchInfo::~SBLaunchInfo() {}
48 const lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() const {
49 return *m_opaque_sp;
52 void SBLaunchInfo::set_ref(const ProcessLaunchInfo &info) {
53 *m_opaque_sp = info;
56 lldb::pid_t SBLaunchInfo::GetProcessID() {
57 LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBLaunchInfo, GetProcessID);
59 return m_opaque_sp->GetProcessID();
62 uint32_t SBLaunchInfo::GetUserID() {
63 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetUserID);
65 return m_opaque_sp->GetUserID();
68 uint32_t SBLaunchInfo::GetGroupID() {
69 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetGroupID);
71 return m_opaque_sp->GetGroupID();
74 bool SBLaunchInfo::UserIDIsValid() {
75 LLDB_RECORD_METHOD_NO_ARGS(bool, SBLaunchInfo, UserIDIsValid);
77 return m_opaque_sp->UserIDIsValid();
80 bool SBLaunchInfo::GroupIDIsValid() {
81 LLDB_RECORD_METHOD_NO_ARGS(bool, SBLaunchInfo, GroupIDIsValid);
83 return m_opaque_sp->GroupIDIsValid();
86 void SBLaunchInfo::SetUserID(uint32_t uid) {
87 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetUserID, (uint32_t), uid);
89 m_opaque_sp->SetUserID(uid);
92 void SBLaunchInfo::SetGroupID(uint32_t gid) {
93 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetGroupID, (uint32_t), gid);
95 m_opaque_sp->SetGroupID(gid);
98 SBFileSpec SBLaunchInfo::GetExecutableFile() {
99 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBLaunchInfo, GetExecutableFile);
101 return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_sp->GetExecutableFile()));
104 void SBLaunchInfo::SetExecutableFile(SBFileSpec exe_file,
105 bool add_as_first_arg) {
106 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetExecutableFile,
107 (lldb::SBFileSpec, bool), exe_file, add_as_first_arg);
109 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
112 SBListener SBLaunchInfo::GetListener() {
113 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBListener, SBLaunchInfo, GetListener);
115 return LLDB_RECORD_RESULT(SBListener(m_opaque_sp->GetListener()));
118 void SBLaunchInfo::SetListener(SBListener &listener) {
119 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetListener, (lldb::SBListener &),
120 listener);
122 m_opaque_sp->SetListener(listener.GetSP());
125 uint32_t SBLaunchInfo::GetNumArguments() {
126 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetNumArguments);
128 return m_opaque_sp->GetArguments().GetArgumentCount();
131 const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
132 LLDB_RECORD_METHOD(const char *, SBLaunchInfo, GetArgumentAtIndex, (uint32_t),
133 idx);
135 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
138 void SBLaunchInfo::SetArguments(const char **argv, bool append) {
139 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetArguments, (const char **, bool),
140 argv, append);
142 if (append) {
143 if (argv)
144 m_opaque_sp->GetArguments().AppendArguments(argv);
145 } else {
146 if (argv)
147 m_opaque_sp->GetArguments().SetArguments(argv);
148 else
149 m_opaque_sp->GetArguments().Clear();
153 uint32_t SBLaunchInfo::GetNumEnvironmentEntries() {
154 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetNumEnvironmentEntries);
156 return m_opaque_sp->GetEnvironment().size();
159 const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) {
160 LLDB_RECORD_METHOD(const char *, SBLaunchInfo, GetEnvironmentEntryAtIndex,
161 (uint32_t), idx);
163 if (idx > GetNumEnvironmentEntries())
164 return nullptr;
165 return m_opaque_sp->GetEnvp()[idx];
168 void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
169 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetEnvironmentEntries,
170 (const char **, bool), envp, append);
172 Environment env(envp);
173 if (append)
174 m_opaque_sp->GetEnvironment().insert(env.begin(), env.end());
175 else
176 m_opaque_sp->GetEnvironment() = env;
177 m_opaque_sp->RegenerateEnvp();
180 void SBLaunchInfo::Clear() {
181 LLDB_RECORD_METHOD_NO_ARGS(void, SBLaunchInfo, Clear);
183 m_opaque_sp->Clear();
186 const char *SBLaunchInfo::GetWorkingDirectory() const {
187 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBLaunchInfo,
188 GetWorkingDirectory);
190 return m_opaque_sp->GetWorkingDirectory().GetCString();
193 void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
194 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetWorkingDirectory, (const char *),
195 working_dir);
197 m_opaque_sp->SetWorkingDirectory(FileSpec(working_dir));
200 uint32_t SBLaunchInfo::GetLaunchFlags() {
201 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetLaunchFlags);
203 return m_opaque_sp->GetFlags().Get();
206 void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
207 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetLaunchFlags, (uint32_t), flags);
209 m_opaque_sp->GetFlags().Reset(flags);
212 const char *SBLaunchInfo::GetProcessPluginName() {
213 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBLaunchInfo, GetProcessPluginName);
215 return m_opaque_sp->GetProcessPluginName();
218 void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
219 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetProcessPluginName, (const char *),
220 plugin_name);
222 return m_opaque_sp->SetProcessPluginName(plugin_name);
225 const char *SBLaunchInfo::GetShell() {
226 LLDB_RECORD_METHOD_NO_ARGS(const char *, SBLaunchInfo, GetShell);
228 // Constify this string so that it is saved in the string pool. Otherwise it
229 // would be freed when this function goes out of scope.
230 ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
231 return shell.AsCString();
234 void SBLaunchInfo::SetShell(const char *path) {
235 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetShell, (const char *), path);
237 m_opaque_sp->SetShell(FileSpec(path));
240 bool SBLaunchInfo::GetShellExpandArguments() {
241 LLDB_RECORD_METHOD_NO_ARGS(bool, SBLaunchInfo, GetShellExpandArguments);
243 return m_opaque_sp->GetShellExpandArguments();
246 void SBLaunchInfo::SetShellExpandArguments(bool expand) {
247 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetShellExpandArguments, (bool),
248 expand);
250 m_opaque_sp->SetShellExpandArguments(expand);
253 uint32_t SBLaunchInfo::GetResumeCount() {
254 LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBLaunchInfo, GetResumeCount);
256 return m_opaque_sp->GetResumeCount();
259 void SBLaunchInfo::SetResumeCount(uint32_t c) {
260 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetResumeCount, (uint32_t), c);
262 m_opaque_sp->SetResumeCount(c);
265 bool SBLaunchInfo::AddCloseFileAction(int fd) {
266 LLDB_RECORD_METHOD(bool, SBLaunchInfo, AddCloseFileAction, (int), fd);
268 return m_opaque_sp->AppendCloseFileAction(fd);
271 bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
272 LLDB_RECORD_METHOD(bool, SBLaunchInfo, AddDuplicateFileAction, (int, int), fd,
273 dup_fd);
275 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
278 bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
279 bool write) {
280 LLDB_RECORD_METHOD(bool, SBLaunchInfo, AddOpenFileAction,
281 (int, const char *, bool, bool), fd, path, read, write);
283 return m_opaque_sp->AppendOpenFileAction(fd, FileSpec(path), read, write);
286 bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
287 LLDB_RECORD_METHOD(bool, SBLaunchInfo, AddSuppressFileAction,
288 (int, bool, bool), fd, read, write);
290 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
293 void SBLaunchInfo::SetLaunchEventData(const char *data) {
294 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetLaunchEventData, (const char *),
295 data);
297 m_opaque_sp->SetLaunchEventData(data);
300 const char *SBLaunchInfo::GetLaunchEventData() const {
301 LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBLaunchInfo,
302 GetLaunchEventData);
304 return m_opaque_sp->GetLaunchEventData();
307 void SBLaunchInfo::SetDetachOnError(bool enable) {
308 LLDB_RECORD_METHOD(void, SBLaunchInfo, SetDetachOnError, (bool), enable);
310 m_opaque_sp->SetDetachOnError(enable);
313 bool SBLaunchInfo::GetDetachOnError() const {
314 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBLaunchInfo, GetDetachOnError);
316 return m_opaque_sp->GetDetachOnError();
319 namespace lldb_private {
320 namespace repro {
322 template <>
323 void RegisterMethods<SBLaunchInfo>(Registry &R) {
324 LLDB_REGISTER_CONSTRUCTOR(SBLaunchInfo, (const char **));
325 LLDB_REGISTER_METHOD(lldb::pid_t, SBLaunchInfo, GetProcessID, ());
326 LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetUserID, ());
327 LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetGroupID, ());
328 LLDB_REGISTER_METHOD(bool, SBLaunchInfo, UserIDIsValid, ());
329 LLDB_REGISTER_METHOD(bool, SBLaunchInfo, GroupIDIsValid, ());
330 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetUserID, (uint32_t));
331 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetGroupID, (uint32_t));
332 LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBLaunchInfo, GetExecutableFile, ());
333 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetExecutableFile,
334 (lldb::SBFileSpec, bool));
335 LLDB_REGISTER_METHOD(lldb::SBListener, SBLaunchInfo, GetListener, ());
336 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetListener, (lldb::SBListener &));
337 LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetNumArguments, ());
338 LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetArgumentAtIndex,
339 (uint32_t));
340 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetArguments,
341 (const char **, bool));
342 LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetNumEnvironmentEntries, ());
343 LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetEnvironmentEntryAtIndex,
344 (uint32_t));
345 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetEnvironmentEntries,
346 (const char **, bool));
347 LLDB_REGISTER_METHOD(void, SBLaunchInfo, Clear, ());
348 LLDB_REGISTER_METHOD_CONST(const char *, SBLaunchInfo, GetWorkingDirectory,
349 ());
350 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetWorkingDirectory,
351 (const char *));
352 LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetLaunchFlags, ());
353 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetLaunchFlags, (uint32_t));
354 LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetProcessPluginName, ());
355 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetProcessPluginName,
356 (const char *));
357 LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetShell, ());
358 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetShell, (const char *));
359 LLDB_REGISTER_METHOD(bool, SBLaunchInfo, GetShellExpandArguments, ());
360 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetShellExpandArguments, (bool));
361 LLDB_REGISTER_METHOD(uint32_t, SBLaunchInfo, GetResumeCount, ());
362 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetResumeCount, (uint32_t));
363 LLDB_REGISTER_METHOD(bool, SBLaunchInfo, AddCloseFileAction, (int));
364 LLDB_REGISTER_METHOD(bool, SBLaunchInfo, AddDuplicateFileAction,
365 (int, int));
366 LLDB_REGISTER_METHOD(bool, SBLaunchInfo, AddOpenFileAction,
367 (int, const char *, bool, bool));
368 LLDB_REGISTER_METHOD(bool, SBLaunchInfo, AddSuppressFileAction,
369 (int, bool, bool));
370 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetLaunchEventData,
371 (const char *));
372 LLDB_REGISTER_METHOD_CONST(const char *, SBLaunchInfo, GetLaunchEventData,
373 ());
374 LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetDetachOnError, (bool));
375 LLDB_REGISTER_METHOD_CONST(bool, SBLaunchInfo, GetDetachOnError, ());