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
254 m_opaque_sp->GetShell().GetPath());
255}
256
257void SBLaunchInfo::SetShell(const char *path) {
258 LLDB_INSTRUMENT_VA(this, path);
259
260 m_opaque_sp->SetShell(FileSpec(path));
261}
262
264 LLDB_INSTRUMENT_VA(this);
265
266 return m_opaque_sp->GetShellExpandArguments();
267}
268
270 LLDB_INSTRUMENT_VA(this, expand);
271
272 m_opaque_sp->SetShellExpandArguments(expand);
273}
274
276 LLDB_INSTRUMENT_VA(this);
277
278 return m_opaque_sp->GetResumeCount();
279}
280
282 LLDB_INSTRUMENT_VA(this, c);
283
284 m_opaque_sp->SetResumeCount(c);
285}
286
288 LLDB_INSTRUMENT_VA(this, fd);
289
290 return m_opaque_sp->AppendCloseFileAction(fd);
291}
292
293bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
294 LLDB_INSTRUMENT_VA(this, fd, dup_fd);
295
296 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
297}
298
299bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
300 bool write) {
301 LLDB_INSTRUMENT_VA(this, fd, path, read, write);
302
303 return m_opaque_sp->AppendOpenFileAction(fd, FileSpec(path), read, write);
304}
305
306bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
307 LLDB_INSTRUMENT_VA(this, fd, read, write);
308
309 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
310}
311
312void SBLaunchInfo::SetLaunchEventData(const char *data) {
313 LLDB_INSTRUMENT_VA(this, data);
314
315 m_opaque_sp->SetLaunchEventData(data);
316}
317
319 LLDB_INSTRUMENT_VA(this);
320
321 return StringPool::GetSystemPool().Intern(m_opaque_sp->GetLaunchEventData());
322}
323
325 LLDB_INSTRUMENT_VA(this, enable);
326
327 m_opaque_sp->SetDetachOnError(enable);
328}
329
331 LLDB_INSTRUMENT_VA(this);
332
333 return m_opaque_sp->GetDetachOnError();
334}
335
337 LLDB_INSTRUMENT_VA(this);
338
339 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
340
341 if (!metadata_sp || !*metadata_sp)
342 return nullptr;
343
345 metadata_sp->GetClassName());
346}
347
348void SBLaunchInfo::SetScriptedProcessClassName(const char *class_name) {
349 LLDB_INSTRUMENT_VA(this, class_name);
350 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
352 metadata_sp ? metadata_sp->GetArgsSP() : nullptr;
353 metadata_sp = std::make_shared<ScriptedMetadata>(class_name, dict_sp);
354 m_opaque_sp->SetScriptedMetadata(metadata_sp);
355}
356
358 LLDB_INSTRUMENT_VA(this);
359
360 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
361
362 SBStructuredData data;
363 if (!metadata_sp)
364 return data;
365
366 lldb_private::StructuredData::DictionarySP dict_sp = metadata_sp->GetArgsSP();
367 data.m_impl_up->SetObjectSP(dict_sp);
368
369 return data;
370}
371
373 LLDB_INSTRUMENT_VA(this, dict);
374 if (!dict.IsValid() || !dict.m_impl_up)
375 return;
376
377 StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();
378
379 if (!obj_sp)
380 return;
381
383 std::make_shared<StructuredData::Dictionary>(obj_sp);
384 if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)
385 return;
386
387 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
388 llvm::StringRef class_name = metadata_sp ? metadata_sp->GetClassName() : "";
389 metadata_sp = std::make_shared<ScriptedMetadata>(class_name, dict_sp);
390 m_opaque_sp->SetScriptedMetadata(metadata_sp);
391}
392
394 LLDB_INSTRUMENT_VA(this);
395
396 lldb::ListenerSP shadow_sp = m_opaque_sp->GetShadowListener();
397 if (!shadow_sp)
398 return SBListener();
399 return SBListener(shadow_sp);
400}
401
403 LLDB_INSTRUMENT_VA(this, listener);
404
405 m_opaque_sp->SetShadowListener(listener.GetSP());
406}
#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 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:89