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
12
14#include "lldb/API/SBError.h"
15#include "lldb/API/SBFileSpec.h"
16#include "lldb/API/SBListener.h"
17#include "lldb/API/SBStream.h"
24
25using namespace lldb;
26using namespace lldb_private;
27
29public:
31
32 const char *const *GetEnvp() const { return m_envp; }
34
36 ProcessLaunchInfo::operator=(rhs);
38 return *this;
39 }
40
41private:
43};
44
47 LLDB_INSTRUMENT_VA(this, argv);
48
49 m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
50 if (argv && argv[0])
51 m_opaque_sp->GetArguments().SetArguments(argv);
52}
53
59
61 LLDB_INSTRUMENT_VA(this, rhs);
62
64 return *this;
65}
66
68
72
74 *m_opaque_sp = info;
75}
76
79
80 return m_opaque_sp->GetProcessID();
81}
82
85
86 return m_opaque_sp->GetUserID();
87}
88
91
92 return m_opaque_sp->GetGroupID();
93}
94
97
98 return m_opaque_sp->UserIDIsValid();
99}
100
102 LLDB_INSTRUMENT_VA(this);
103
104 return m_opaque_sp->GroupIDIsValid();
105}
106
107void SBLaunchInfo::SetUserID(uint32_t uid) {
108 LLDB_INSTRUMENT_VA(this, uid);
109
110 m_opaque_sp->SetUserID(uid);
111}
112
113void SBLaunchInfo::SetGroupID(uint32_t gid) {
114 LLDB_INSTRUMENT_VA(this, gid);
115
116 m_opaque_sp->SetGroupID(gid);
117}
118
120 LLDB_INSTRUMENT_VA(this);
121
122 return SBFileSpec(m_opaque_sp->GetExecutableFile());
123}
124
126 bool add_as_first_arg) {
127 LLDB_INSTRUMENT_VA(this, exe_file, add_as_first_arg);
128
129 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
130}
131
133 LLDB_INSTRUMENT_VA(this);
134
135 return SBListener(m_opaque_sp->GetListener());
136}
137
139 LLDB_INSTRUMENT_VA(this, listener);
140
141 m_opaque_sp->SetListener(listener.GetSP());
142}
143
145 LLDB_INSTRUMENT_VA(this);
146
147 return m_opaque_sp->GetArguments().GetArgumentCount();
148}
149
150const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
151 LLDB_INSTRUMENT_VA(this, idx);
152
154 m_opaque_sp->GetArguments().GetArgumentAtIndex(idx));
155}
156
157void SBLaunchInfo::SetArguments(const char **argv, bool append) {
158 LLDB_INSTRUMENT_VA(this, argv, append);
159
160 if (append) {
161 if (argv)
162 m_opaque_sp->GetArguments().AppendArguments(argv);
163 } else {
164 if (argv)
165 m_opaque_sp->GetArguments().SetArguments(argv);
166 else
167 m_opaque_sp->GetArguments().Clear();
168 }
169}
170
172 LLDB_INSTRUMENT_VA(this);
173
174 return m_opaque_sp->GetEnvironment().size();
175}
176
178 LLDB_INSTRUMENT_VA(this, idx);
179
180 if (idx > GetNumEnvironmentEntries())
181 return nullptr;
182 return StringPool::GetSystemPool().Intern(m_opaque_sp->GetEnvp()[idx]);
183}
184
185void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
186 LLDB_INSTRUMENT_VA(this, envp, append);
188}
189
190void SBLaunchInfo::SetEnvironment(const SBEnvironment &env, bool append) {
191 LLDB_INSTRUMENT_VA(this, env, append);
192 Environment &refEnv = env.ref();
193 if (append) {
194 for (auto &KV : refEnv)
195 m_opaque_sp->GetEnvironment().insert_or_assign(KV.first(), KV.second);
196 } else
197 m_opaque_sp->GetEnvironment() = refEnv;
198 m_opaque_sp->RegenerateEnvp();
199}
200
205
207 LLDB_INSTRUMENT_VA(this);
208
209 m_opaque_sp->Clear();
210}
211
213 LLDB_INSTRUMENT_VA(this);
214
216 m_opaque_sp->GetWorkingDirectory().GetPath());
217}
218
219void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
220 LLDB_INSTRUMENT_VA(this, working_dir);
221
222 m_opaque_sp->SetWorkingDirectory(FileSpec(working_dir));
223}
224
226 LLDB_INSTRUMENT_VA(this);
227
228 return m_opaque_sp->GetFlags().Get();
229}
230
231void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
232 LLDB_INSTRUMENT_VA(this, flags);
233
234 m_opaque_sp->GetFlags().Reset(flags);
235}
236
238 LLDB_INSTRUMENT_VA(this);
239
241 m_opaque_sp->GetProcessPluginName());
242}
243
244void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
245 LLDB_INSTRUMENT_VA(this, plugin_name);
246
247 return m_opaque_sp->SetProcessPluginName(plugin_name);
248}
249
251 LLDB_INSTRUMENT_VA(this);
252
253 // Constify this string so that it is saved in the string pool. Otherwise it
254 // would be freed when this function goes out of scope.
255 ConstString shell(m_opaque_sp->GetShell().GetPath());
256 return shell.AsCString(nullptr);
257}
258
259void SBLaunchInfo::SetShell(const char *path) {
260 LLDB_INSTRUMENT_VA(this, path);
261
262 m_opaque_sp->SetShell(FileSpec(path));
263}
264
266 LLDB_INSTRUMENT_VA(this);
267
268 return m_opaque_sp->GetShellExpandArguments();
269}
270
272 LLDB_INSTRUMENT_VA(this, expand);
273
274 m_opaque_sp->SetShellExpandArguments(expand);
275}
276
278 LLDB_INSTRUMENT_VA(this);
279
280 return m_opaque_sp->GetResumeCount();
281}
282
284 LLDB_INSTRUMENT_VA(this, c);
285
286 m_opaque_sp->SetResumeCount(c);
287}
288
290 LLDB_INSTRUMENT_VA(this, fd);
291
292 return m_opaque_sp->AppendCloseFileAction(fd);
293}
294
295bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
296 LLDB_INSTRUMENT_VA(this, fd, dup_fd);
297
298 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
299}
300
301bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
302 bool write) {
303 LLDB_INSTRUMENT_VA(this, fd, path, read, write);
304
305 return m_opaque_sp->AppendOpenFileAction(fd, FileSpec(path), read, write);
306}
307
308bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
309 LLDB_INSTRUMENT_VA(this, fd, read, write);
310
311 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
312}
313
314void SBLaunchInfo::SetLaunchEventData(const char *data) {
315 LLDB_INSTRUMENT_VA(this, data);
316
317 m_opaque_sp->SetLaunchEventData(data);
318}
319
321 LLDB_INSTRUMENT_VA(this);
322
323 return StringPool::GetSystemPool().Intern(m_opaque_sp->GetLaunchEventData());
324}
325
327 LLDB_INSTRUMENT_VA(this, enable);
328
329 m_opaque_sp->SetDetachOnError(enable);
330}
331
333 LLDB_INSTRUMENT_VA(this);
334
335 return m_opaque_sp->GetDetachOnError();
336}
337
339 LLDB_INSTRUMENT_VA(this);
340
341 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
342
343 if (!metadata_sp || !*metadata_sp)
344 return nullptr;
345
346 // Constify this string so that it is saved in the string pool. Otherwise it
347 // would be freed when this function goes out of scope.
348 ConstString class_name(metadata_sp->GetClassName());
349 return class_name.AsCString(nullptr);
350}
351
352void SBLaunchInfo::SetScriptedProcessClassName(const char *class_name) {
353 LLDB_INSTRUMENT_VA(this, class_name);
354 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
356 metadata_sp ? metadata_sp->GetArgsSP() : nullptr;
357 metadata_sp = std::make_shared<ScriptedMetadata>(class_name, dict_sp);
358 m_opaque_sp->SetScriptedMetadata(metadata_sp);
359}
360
362 LLDB_INSTRUMENT_VA(this);
363
364 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
365
366 SBStructuredData data;
367 if (!metadata_sp)
368 return data;
369
370 lldb_private::StructuredData::DictionarySP dict_sp = metadata_sp->GetArgsSP();
371 data.m_impl_up->SetObjectSP(dict_sp);
372
373 return data;
374}
375
377 LLDB_INSTRUMENT_VA(this, dict);
378 if (!dict.IsValid() || !dict.m_impl_up)
379 return;
380
381 StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();
382
383 if (!obj_sp)
384 return;
385
387 std::make_shared<StructuredData::Dictionary>(obj_sp);
388 if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)
389 return;
390
391 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
392 llvm::StringRef class_name = metadata_sp ? metadata_sp->GetClassName() : "";
393 metadata_sp = std::make_shared<ScriptedMetadata>(class_name, dict_sp);
394 m_opaque_sp->SetScriptedMetadata(metadata_sp);
395}
396
398 LLDB_INSTRUMENT_VA(this);
399
400 lldb::ListenerSP shadow_sp = m_opaque_sp->GetShadowListener();
401 if (!shadow_sp)
402 return SBListener();
403 return SBListener(shadow_sp);
404}
405
407 LLDB_INSTRUMENT_VA(this, listener);
408
409 m_opaque_sp->SetShadowListener(listener.GetSP());
410}
#define LLDB_INSTRUMENT_VA(...)
lldb_private::Environment & ref() const
const lldb_private::FileSpec & ref() const
void SetWorkingDirectory(const char *working_dir)
const char * GetLaunchEventData() const
void SetShadowListener(SBListener &listener)
Set the shadow listener that will receive public process events, additionally to the default process ...
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
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
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()
SBListener GetShadowListener()
Get the shadow listener that receive public process events, additionally to the default process event...
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()
StructuredDataImplUP m_impl_up
A uniqued constant string class.
Definition ConstString.h:40
const char * AsCString(const char *value_if_empty) const
Get the string value as a C string.
A file utility class.
Definition FileSpec.h:56
Environment & GetEnvironment()
Definition ProcessInfo.h:86
SBLaunchInfoImpl & operator=(const ProcessLaunchInfo &rhs)
const char *const * GetEnvp() const
const char * Intern(llvm::StringRef str) const
Definition StringPool.h:78
const char * InternNonEmpty(llvm::StringRef str) const
Like Intern, but an empty string yields nullptr.
Definition StringPool.h:81
static StringPoolRef GetSystemPool()
The system pool. Only valid between Initialize and Terminate.
std::shared_ptr< Dictionary > DictionarySP
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
class LLDB_API SBFileSpec
Definition SBDefines.h:76
std::shared_ptr< lldb_private::ScriptedMetadata > ScriptedMetadataSP
uint64_t pid_t
Definition lldb-types.h:84
class LLDB_API SBEnvironment
Definition SBDefines.h:69
std::shared_ptr< lldb_private::Listener > ListenerSP
@ eStructuredDataTypeInvalid
class LLDB_API SBListener
Definition SBDefines.h:88