[Go to site: main page, start]

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"
23
24using namespace lldb;
25using namespace lldb_private;
26
28public:
30
31 const char *const *GetEnvp() const { return m_envp; }
33
35 ProcessLaunchInfo::operator=(rhs);
37 return *this;
38 }
39
40private:
42};
43
46 LLDB_INSTRUMENT_VA(this, argv);
47
48 m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
49 if (argv && argv[0])
50 m_opaque_sp->GetArguments().SetArguments(argv);
51}
52
58
60 LLDB_INSTRUMENT_VA(this, rhs);
61
63 return *this;
64}
65
67
71
73 *m_opaque_sp = info;
74}
75
78
79 return m_opaque_sp->GetProcessID();
80}
81
84
85 return m_opaque_sp->GetUserID();
86}
87
90
91 return m_opaque_sp->GetGroupID();
92}
93
96
97 return m_opaque_sp->UserIDIsValid();
98}
99
101 LLDB_INSTRUMENT_VA(this);
102
103 return m_opaque_sp->GroupIDIsValid();
104}
105
106void SBLaunchInfo::SetUserID(uint32_t uid) {
107 LLDB_INSTRUMENT_VA(this, uid);
108
109 m_opaque_sp->SetUserID(uid);
110}
111
112void SBLaunchInfo::SetGroupID(uint32_t gid) {
113 LLDB_INSTRUMENT_VA(this, gid);
114
115 m_opaque_sp->SetGroupID(gid);
116}
117
119 LLDB_INSTRUMENT_VA(this);
120
121 return SBFileSpec(m_opaque_sp->GetExecutableFile());
122}
123
125 bool add_as_first_arg) {
126 LLDB_INSTRUMENT_VA(this, exe_file, add_as_first_arg);
127
128 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
129}
130
132 LLDB_INSTRUMENT_VA(this);
133
134 return SBListener(m_opaque_sp->GetListener());
135}
136
138 LLDB_INSTRUMENT_VA(this, listener);
139
140 m_opaque_sp->SetListener(listener.GetSP());
141}
142
144 LLDB_INSTRUMENT_VA(this);
145
146 return m_opaque_sp->GetArguments().GetArgumentCount();
147}
148
149const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
150 LLDB_INSTRUMENT_VA(this, idx);
151
152 return ConstString(m_opaque_sp->GetArguments().GetArgumentAtIndex(idx))
153 .GetCString();
154}
155
156void SBLaunchInfo::SetArguments(const char **argv, bool append) {
157 LLDB_INSTRUMENT_VA(this, argv, append);
158
159 if (append) {
160 if (argv)
161 m_opaque_sp->GetArguments().AppendArguments(argv);
162 } else {
163 if (argv)
164 m_opaque_sp->GetArguments().SetArguments(argv);
165 else
166 m_opaque_sp->GetArguments().Clear();
167 }
168}
169
171 LLDB_INSTRUMENT_VA(this);
172
173 return m_opaque_sp->GetEnvironment().size();
174}
175
177 LLDB_INSTRUMENT_VA(this, idx);
178
179 if (idx > GetNumEnvironmentEntries())
180 return nullptr;
181 return ConstString(m_opaque_sp->GetEnvp()[idx]).GetCString();
182}
183
184void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
185 LLDB_INSTRUMENT_VA(this, envp, append);
187}
188
189void SBLaunchInfo::SetEnvironment(const SBEnvironment &env, bool append) {
190 LLDB_INSTRUMENT_VA(this, env, append);
191 Environment &refEnv = env.ref();
192 if (append) {
193 for (auto &KV : refEnv)
194 m_opaque_sp->GetEnvironment().insert_or_assign(KV.first(), KV.second);
195 } else
196 m_opaque_sp->GetEnvironment() = refEnv;
197 m_opaque_sp->RegenerateEnvp();
198}
199
204
206 LLDB_INSTRUMENT_VA(this);
207
208 m_opaque_sp->Clear();
209}
210
212 LLDB_INSTRUMENT_VA(this);
213
214 return ConstString(m_opaque_sp->GetWorkingDirectory().GetPath())
215 .AsCString(nullptr);
216}
217
218void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
219 LLDB_INSTRUMENT_VA(this, working_dir);
220
221 m_opaque_sp->SetWorkingDirectory(FileSpec(working_dir));
222}
223
225 LLDB_INSTRUMENT_VA(this);
226
227 return m_opaque_sp->GetFlags().Get();
228}
229
230void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
231 LLDB_INSTRUMENT_VA(this, flags);
232
233 m_opaque_sp->GetFlags().Reset(flags);
234}
235
237 LLDB_INSTRUMENT_VA(this);
238
239 return ConstString(m_opaque_sp->GetProcessPluginName()).GetCString();
240}
241
242void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
243 LLDB_INSTRUMENT_VA(this, plugin_name);
244
245 return m_opaque_sp->SetProcessPluginName(plugin_name);
246}
247
249 LLDB_INSTRUMENT_VA(this);
250
251 // Constify this string so that it is saved in the string pool. Otherwise it
252 // would be freed when this function goes out of scope.
253 ConstString shell(m_opaque_sp->GetShell().GetPath());
254 return shell.AsCString(nullptr);
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 ConstString(m_opaque_sp->GetLaunchEventData()).GetCString();
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
344 // Constify this string so that it is saved in the string pool. Otherwise it
345 // would be freed when this function goes out of scope.
346 ConstString class_name(metadata_sp->GetClassName());
347 return class_name.AsCString(nullptr);
348}
349
350void SBLaunchInfo::SetScriptedProcessClassName(const char *class_name) {
351 LLDB_INSTRUMENT_VA(this, class_name);
352 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
354 metadata_sp ? metadata_sp->GetArgsSP() : nullptr;
355 metadata_sp = std::make_shared<ScriptedMetadata>(class_name, dict_sp);
356 m_opaque_sp->SetScriptedMetadata(metadata_sp);
357}
358
360 LLDB_INSTRUMENT_VA(this);
361
362 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
363
364 SBStructuredData data;
365 if (!metadata_sp)
366 return data;
367
368 lldb_private::StructuredData::DictionarySP dict_sp = metadata_sp->GetArgsSP();
369 data.m_impl_up->SetObjectSP(dict_sp);
370
371 return data;
372}
373
375 LLDB_INSTRUMENT_VA(this, dict);
376 if (!dict.IsValid() || !dict.m_impl_up)
377 return;
378
379 StructuredData::ObjectSP obj_sp = dict.m_impl_up->GetObjectSP();
380
381 if (!obj_sp)
382 return;
383
385 std::make_shared<StructuredData::Dictionary>(obj_sp);
386 if (!dict_sp || dict_sp->GetType() == lldb::eStructuredDataTypeInvalid)
387 return;
388
389 ScriptedMetadataSP metadata_sp = m_opaque_sp->GetScriptedMetadata();
390 llvm::StringRef class_name = metadata_sp ? metadata_sp->GetClassName() : "";
391 metadata_sp = std::make_shared<ScriptedMetadata>(class_name, dict_sp);
392 m_opaque_sp->SetScriptedMetadata(metadata_sp);
393}
394
396 LLDB_INSTRUMENT_VA(this);
397
398 lldb::ListenerSP shadow_sp = m_opaque_sp->GetShadowListener();
399 if (!shadow_sp)
400 return SBListener();
401 return SBListener(shadow_sp);
402}
403
405 LLDB_INSTRUMENT_VA(this, listener);
406
407 m_opaque_sp->SetShadowListener(listener.GetSP());
408}
#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 * GetCString() const
Get the string value as a C string.
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
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:75
std::shared_ptr< lldb_private::ScriptedMetadata > ScriptedMetadataSP
uint64_t pid_t
Definition lldb-types.h:84
class LLDB_API SBEnvironment
Definition SBDefines.h:68
std::shared_ptr< lldb_private::Listener > ListenerSP
@ eStructuredDataTypeInvalid
class LLDB_API SBListener
Definition SBDefines.h:87