LLDB mainline
SBLaunchInfo.cpp
Go to the documentation of this file.
1//===-- SBLaunchInfo.cpp --------------------------------------------------===//
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//===----------------------------------------------------------------------===//
8
11
13#include "lldb/API/SBError.h"
14#include "lldb/API/SBFileSpec.h"
15#include "lldb/API/SBListener.h"
16#include "lldb/API/SBStream.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
25public:
27
28 const char *const *GetEnvp() const { return m_envp; }
30
32 ProcessLaunchInfo::operator=(rhs);
34 return *this;
35 }
36
37private:
39};
40
42 : m_opaque_sp(new SBLaunchInfoImpl()) {
43 LLDB_INSTRUMENT_VA(this, argv);
44
45 m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
46 if (argv && argv[0])
47 m_opaque_sp->GetArguments().SetArguments(argv);
48}
49
51 LLDB_INSTRUMENT_VA(this, rhs);
52
54}
55
57 LLDB_INSTRUMENT_VA(this, rhs);
58
60 return *this;
61}
62
64
66 return *m_opaque_sp;
67}
68
70 *m_opaque_sp = info;
71}
72
75
76 return m_opaque_sp->GetProcessID();
77}
78
81
82 return m_opaque_sp->GetUserID();
83}
84
87
88 return m_opaque_sp->GetGroupID();
89}
90
93
94 return m_opaque_sp->UserIDIsValid();
95}
96
99
100 return m_opaque_sp->GroupIDIsValid();
101}
102
104 LLDB_INSTRUMENT_VA(this, uid);
105
106 m_opaque_sp->SetUserID(uid);
107}
108
110 LLDB_INSTRUMENT_VA(this, gid);
111
112 m_opaque_sp->SetGroupID(gid);
113}
114
116 LLDB_INSTRUMENT_VA(this);
117
118 return SBFileSpec(m_opaque_sp->GetExecutableFile());
119}
120
122 bool add_as_first_arg) {
123 LLDB_INSTRUMENT_VA(this, exe_file, add_as_first_arg);
124
125 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
126}
127
129 LLDB_INSTRUMENT_VA(this);
130
131 return SBListener(m_opaque_sp->GetListener());
132}
133
135 LLDB_INSTRUMENT_VA(this, listener);
136
137 m_opaque_sp->SetListener(listener.GetSP());
138}
139
141 LLDB_INSTRUMENT_VA(this);
142
143 return m_opaque_sp->GetArguments().GetArgumentCount();
144}
145
147 LLDB_INSTRUMENT_VA(this, idx);
148
149 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
150}
151
152void SBLaunchInfo::SetArguments(const char **argv, bool append) {
153 LLDB_INSTRUMENT_VA(this, argv, append);
154
155 if (append) {
156 if (argv)
157 m_opaque_sp->GetArguments().AppendArguments(argv);
158 } else {
159 if (argv)
160 m_opaque_sp->GetArguments().SetArguments(argv);
161 else
162 m_opaque_sp->GetArguments().Clear();
163 }
164}
165
167 LLDB_INSTRUMENT_VA(this);
168
169 return m_opaque_sp->GetEnvironment().size();
170}
171
173 LLDB_INSTRUMENT_VA(this, idx);
174
175 if (idx > GetNumEnvironmentEntries())
176 return nullptr;
177 return m_opaque_sp->GetEnvp()[idx];
178}
179
180void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
181 LLDB_INSTRUMENT_VA(this, envp, append);
183}
184
185void SBLaunchInfo::SetEnvironment(const SBEnvironment &env, bool append) {
186 LLDB_INSTRUMENT_VA(this, env, append);
187 Environment &refEnv = env.ref();
188 if (append) {
189 for (auto &KV : refEnv)
190 m_opaque_sp->GetEnvironment().insert_or_assign(KV.first(), KV.second);
191 } else
192 m_opaque_sp->GetEnvironment() = refEnv;
193 m_opaque_sp->RegenerateEnvp();
194}
195
197 LLDB_INSTRUMENT_VA(this);
198 return SBEnvironment(Environment(m_opaque_sp->GetEnvironment()));
199}
200
202 LLDB_INSTRUMENT_VA(this);
203
204 m_opaque_sp->Clear();
205}
206
208 LLDB_INSTRUMENT_VA(this);
209
210 return m_opaque_sp->GetWorkingDirectory().GetPathAsConstString().AsCString();
211}
212
213void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
214 LLDB_INSTRUMENT_VA(this, working_dir);
215
216 m_opaque_sp->SetWorkingDirectory(FileSpec(working_dir));
217}
218
220 LLDB_INSTRUMENT_VA(this);
221
222 return m_opaque_sp->GetFlags().Get();
223}
224
226 LLDB_INSTRUMENT_VA(this, flags);
227
228 m_opaque_sp->GetFlags().Reset(flags);
229}
230
232 LLDB_INSTRUMENT_VA(this);
233
234 return m_opaque_sp->GetProcessPluginName();
235}
236
237void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
238 LLDB_INSTRUMENT_VA(this, plugin_name);
239
240 return m_opaque_sp->SetProcessPluginName(plugin_name);
241}
242
244 LLDB_INSTRUMENT_VA(this);
245
246 // Constify this string so that it is saved in the string pool. Otherwise it
247 // would be freed when this function goes out of scope.
248 ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
249 return shell.AsCString();
250}
251
252void SBLaunchInfo::SetShell(const char *path) {
253 LLDB_INSTRUMENT_VA(this, path);
254
255 m_opaque_sp->SetShell(FileSpec(path));
256}
257
259 LLDB_INSTRUMENT_VA(this);
260
261 return m_opaque_sp->GetShellExpandArguments();
262}
263
265 LLDB_INSTRUMENT_VA(this, expand);
266
267 m_opaque_sp->SetShellExpandArguments(expand);
268}
269
271 LLDB_INSTRUMENT_VA(this);
272
273 return m_opaque_sp->GetResumeCount();
274}
275
277 LLDB_INSTRUMENT_VA(this, c);
278
279 m_opaque_sp->SetResumeCount(c);
280}
281
283 LLDB_INSTRUMENT_VA(this, fd);
284
285 return m_opaque_sp->AppendCloseFileAction(fd);
286}
287
288bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
289 LLDB_INSTRUMENT_VA(this, fd, dup_fd);
290
291 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
292}
293
294bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
295 bool write) {
296 LLDB_INSTRUMENT_VA(this, fd, path, read, write);
297
298 return m_opaque_sp->AppendOpenFileAction(fd, FileSpec(path), read, write);
299}
300
301bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
302 LLDB_INSTRUMENT_VA(this, fd, read, write);
303
304 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
305}
306
307void SBLaunchInfo::SetLaunchEventData(const char *data) {
308 LLDB_INSTRUMENT_VA(this, data);
309
310 m_opaque_sp->SetLaunchEventData(data);
311}
312
314 LLDB_INSTRUMENT_VA(this);
315
316 return m_opaque_sp->GetLaunchEventData();
317}
318
320 LLDB_INSTRUMENT_VA(this, enable);
321
322 m_opaque_sp->SetDetachOnError(enable);
323}
324
326 LLDB_INSTRUMENT_VA(this);
327
328 return m_opaque_sp->GetDetachOnError();
329}
330
332 LLDB_INSTRUMENT_VA(this);
333
334 // Constify this string so that it is saved in the string pool. Otherwise it
335 // would be freed when this function goes out of scope.
336 ConstString class_name(m_opaque_sp->GetScriptedProcessClassName().c_str());
337 return class_name.AsCString();
338}
339
340void SBLaunchInfo::SetScriptedProcessClassName(const char *class_name) {
341 LLDB_INSTRUMENT_VA(this, class_name);
342
343 m_opaque_sp->SetScriptedProcessClassName(class_name);
344}
345
347 LLDB_INSTRUMENT_VA(this);
348
350 m_opaque_sp->GetScriptedProcessDictionarySP();
351
352 SBStructuredData data;
353 data.m_impl_up->SetObjectSP(dict_sp);
354
355 return data;
356}
357
359 LLDB_INSTRUMENT_VA(this, dict);
360 if (!dict.IsValid() || !dict.m_impl_up)
361 return;
362
363 StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();
364
365 if (!obj_sp)
366 return;
367
369 std::make_shared<StructuredData::Dictionary>(obj_sp);
370 if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)
371 return;
372
373 m_opaque_sp->SetScriptedProcessDictionarySP(dict_sp);
374}
#define LLDB_INSTRUMENT_VA(...)
lldb_private::Environment & ref() const
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
void SetWorkingDirectory(const char *working_dir)
const char * GetLaunchEventData() const
uint32_t GetUserID()
lldb::pid_t GetProcessID()
void SetProcessPluginName(const char *plugin_name)
uint32_t GetNumEnvironmentEntries()
void SetExecutableFile(SBFileSpec exe_file, bool add_as_first_arg)
Set the executable file that will be used to launch the process and optionally set it as the first ar...
lldb::SBStructuredData GetScriptedProcessDictionary() const
const char * GetScriptedProcessClassName() const
uint32_t GetGroupID()
void set_ref(const lldb_private::ProcessLaunchInfo &info)
const char * GetProcessPluginName()
uint32_t GetLaunchFlags()
bool GetDetachOnError() const
bool AddCloseFileAction(int fd)
void SetScriptedProcessClassName(const char *class_name)
void SetUserID(uint32_t uid)
bool AddSuppressFileAction(int fd, bool read, bool write)
SBLaunchInfo & operator=(const SBLaunchInfo &rhs)
SBListener GetListener()
Get the listener that will be used to receive process events.
std::shared_ptr< lldb_private::SBLaunchInfoImpl > m_opaque_sp
Definition: SBLaunchInfo.h:189
void SetResumeCount(uint32_t c)
const char * GetEnvironmentEntryAtIndex(uint32_t idx)
void SetEnvironmentEntries(const char **envp, bool append)
Update this object with the given environment variables.
bool AddDuplicateFileAction(int fd, int dup_fd)
SBFileSpec GetExecutableFile()
void SetLaunchFlags(uint32_t flags)
void SetDetachOnError(bool enable)
uint32_t GetResumeCount()
SBEnvironment GetEnvironment()
Return the environment variables of this object.
void SetShell(const char *path)
void SetShellExpandArguments(bool expand)
bool AddOpenFileAction(int fd, const char *path, bool read, bool write)
SBLaunchInfo(const char **argv)
const char * GetArgumentAtIndex(uint32_t idx)
void SetLaunchEventData(const char *data)
uint32_t GetNumArguments()
bool GetShellExpandArguments()
void SetListener(SBListener &listener)
Set the listener that will be used to receive process events.
void SetScriptedProcessDictionary(lldb::SBStructuredData dict)
void SetEnvironment(const SBEnvironment &env, bool append)
Update this object with the given environment variables.
void SetGroupID(uint32_t gid)
const char * GetWorkingDirectory() const
const lldb_private::ProcessLaunchInfo & ref() const
void SetArguments(const char **argv, bool append)
const char * GetShell()
lldb::ListenerSP GetSP()
Definition: SBListener.cpp:286
StructuredDataImplUP m_impl_up
A uniqued constant string class.
Definition: ConstString.h:39
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:192
A file utility class.
Definition: FileSpec.h:56
Environment & GetEnvironment()
Definition: ProcessInfo.h:86
SBLaunchInfoImpl & operator=(const ProcessLaunchInfo &rhs)
const char *const * GetEnvp() const
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
uint64_t pid_t
Definition: lldb-types.h:85
@ eStructuredDataTypeInvalid