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 
12 #include "lldb/API/SBEnvironment.h"
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 
21 using namespace lldb;
22 using namespace lldb_private;
23 
25 public:
26  SBLaunchInfoImpl() : m_envp(GetEnvironment().getEnvp()) {}
27 
28  const char *const *GetEnvp() const { return m_envp; }
29  void RegenerateEnvp() { m_envp = GetEnvironment().getEnvp(); }
30 
32  ProcessLaunchInfo::operator=(rhs);
33  RegenerateEnvp();
34  return *this;
35  }
36 
37 private:
39 };
40 
41 SBLaunchInfo::SBLaunchInfo(const char **argv)
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 
63 SBLaunchInfo::~SBLaunchInfo() = default;
64 
66  return *m_opaque_sp;
67 }
68 
70  *m_opaque_sp = info;
71 }
72 
74  LLDB_INSTRUMENT_VA(this);
75 
76  return m_opaque_sp->GetProcessID();
77 }
78 
80  LLDB_INSTRUMENT_VA(this);
81 
82  return m_opaque_sp->GetUserID();
83 }
84 
86  LLDB_INSTRUMENT_VA(this);
87 
88  return m_opaque_sp->GetGroupID();
89 }
90 
92  LLDB_INSTRUMENT_VA(this);
93 
94  return m_opaque_sp->UserIDIsValid();
95 }
96 
98  LLDB_INSTRUMENT_VA(this);
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 
152 void 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 
180 void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
181  LLDB_INSTRUMENT_VA(this, envp, append);
182  SetEnvironment(SBEnvironment(Environment(envp)), append);
183 }
184 
185 void 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 
213 void 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 
237 void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
238  LLDB_INSTRUMENT_VA(this, plugin_name);
239 
240  return m_opaque_sp->SetProcessPluginName(plugin_name);
241 }
242 
243 const char *SBLaunchInfo::GetShell() {
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 
252 void 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 
288 bool 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 
294 bool 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 
301 bool 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 
307 void SBLaunchInfo::SetLaunchEventData(const char *data) {
308  LLDB_INSTRUMENT_VA(this, data);
309 
310  m_opaque_sp->SetLaunchEventData(data);
311 }
312 
313 const char *SBLaunchInfo::GetLaunchEventData() const {
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 
340 void 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 }
Instrumentation.h
lldb::SBLaunchInfo
Definition: SBLaunchInfo.h:23
lldb::SBLaunchInfo::GetWorkingDirectory
const char * GetWorkingDirectory() const
Definition: SBLaunchInfo.cpp:207
lldb_private::SBLaunchInfoImpl::m_envp
Environment::Envp m_envp
Definition: SBLaunchInfo.cpp:38
lldb::SBLaunchInfo::GetNumEnvironmentEntries
uint32_t GetNumEnvironmentEntries()
Definition: SBLaunchInfo.cpp:166
lldb::SBLaunchInfo::SetResumeCount
void SetResumeCount(uint32_t c)
Definition: SBLaunchInfo.cpp:276
lldb::SBEnvironment::ref
lldb_private::Environment & ref() const
Definition: SBEnvironment.cpp:124
lldb_private::Environment::Envp
Definition: Environment.h:22
SBLaunchInfo.h
lldb::SBLaunchInfo::GetResumeCount
uint32_t GetResumeCount()
Definition: SBLaunchInfo.cpp:270
ProcessLaunchInfo.h
lldb::SBListener
class LLDB_API SBListener
Definition: SBDefines.h:68
lldb::SBLaunchInfo::SetUserID
void SetUserID(uint32_t uid)
Definition: SBLaunchInfo.cpp:103
lldb::SBEnvironment
class LLDB_API SBEnvironment
Definition: SBDefines.h:51
lldb_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:192
lldb::SBLaunchInfo::GetShellExpandArguments
bool GetShellExpandArguments()
Definition: SBLaunchInfo.cpp:258
lldb::SBListener::GetSP
lldb::ListenerSP GetSP()
Definition: SBListener.cpp:286
lldb::SBLaunchInfo::GetLaunchEventData
const char * GetLaunchEventData() const
Definition: SBLaunchInfo.cpp:313
lldb::SBLaunchInfo::GetShell
const char * GetShell()
Definition: SBLaunchInfo.cpp:243
lldb::SBLaunchInfo::GetScriptedProcessDictionary
lldb::SBStructuredData GetScriptedProcessDictionary() const
Definition: SBLaunchInfo.cpp:346
lldb::SBLaunchInfo::AddDuplicateFileAction
bool AddDuplicateFileAction(int fd, int dup_fd)
Definition: SBLaunchInfo.cpp:288
lldb::SBLaunchInfo::operator=
SBLaunchInfo & operator=(const SBLaunchInfo &rhs)
Definition: SBLaunchInfo.cpp:56
lldb::SBLaunchInfo::UserIDIsValid
bool UserIDIsValid()
Definition: SBLaunchInfo.cpp:91
lldb::SBLaunchInfo::SetScriptedProcessDictionary
void SetScriptedProcessDictionary(lldb::SBStructuredData dict)
Definition: SBLaunchInfo.cpp:358
lldb::SBLaunchInfo::GetDetachOnError
bool GetDetachOnError() const
Definition: SBLaunchInfo.cpp:325
SBListener.h
lldb_private::SBLaunchInfoImpl::RegenerateEnvp
void RegenerateEnvp()
Definition: SBLaunchInfo.cpp:29
lldb::SBLaunchInfo::SetListener
void SetListener(SBListener &listener)
Set the listener that will be used to receive process events.
Definition: SBLaunchInfo.cpp:134
lldb::SBStructuredData::m_impl_up
StructuredDataImplUP m_impl_up
Definition: SBStructuredData.h:104
lldb::eStructuredDataTypeInvalid
@ eStructuredDataTypeInvalid
Definition: lldb-enumerations.h:793
lldb_private::FileSpec
Definition: FileSpec.h:55
lldb::SBLaunchInfo::m_opaque_sp
std::shared_ptr< lldb_private::SBLaunchInfoImpl > m_opaque_sp
Definition: SBLaunchInfo.h:189
lldb::SBLaunchInfo::~SBLaunchInfo
~SBLaunchInfo()
SBStream.h
lldb::SBLaunchInfo::SetEnvironmentEntries
void SetEnvironmentEntries(const char **envp, bool append)
Update this object with the given environment variables.
Definition: SBLaunchInfo.cpp:180
lldb::SBLaunchInfo::GetListener
SBListener GetListener()
Get the listener that will be used to receive process events.
Definition: SBLaunchInfo.cpp:128
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
lldb::SBLaunchInfo::AddCloseFileAction
bool AddCloseFileAction(int fd)
Definition: SBLaunchInfo.cpp:282
SBFileSpec.h
lldb::SBLaunchInfo::SetLaunchFlags
void SetLaunchFlags(uint32_t flags)
Definition: SBLaunchInfo.cpp:225
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
lldb::SBLaunchInfo::SetLaunchEventData
void SetLaunchEventData(const char *data)
Definition: SBLaunchInfo.cpp:307
lldb_private::ConstString
Definition: ConstString.h:39
lldb::SBLaunchInfo::GetExecutableFile
SBFileSpec GetExecutableFile()
Definition: SBLaunchInfo.cpp:115
lldb::SBFileSpec::ref
const lldb_private::FileSpec & ref() const
Definition: SBFileSpec.cpp:162
lldb_private::SBLaunchInfoImpl::operator=
SBLaunchInfoImpl & operator=(const ProcessLaunchInfo &rhs)
Definition: SBLaunchInfo.cpp:31
lldb::SBEnvironment
Definition: SBEnvironment.h:16
lldb::SBLaunchInfo::GetArgumentAtIndex
const char * GetArgumentAtIndex(uint32_t idx)
Definition: SBLaunchInfo.cpp:146
lldb_private::StructuredData::DictionarySP
std::shared_ptr< Dictionary > DictionarySP
Definition: StructuredData.h:67
lldb::SBLaunchInfo::GetGroupID
uint32_t GetGroupID()
Definition: SBLaunchInfo.cpp:85
lldb::SBLaunchInfo::SetDetachOnError
void SetDetachOnError(bool enable)
Definition: SBLaunchInfo.cpp:319
lldb::SBLaunchInfo::SBLaunchInfo
SBLaunchInfo(const char **argv)
Definition: SBLaunchInfo.cpp:41
lldb::SBLaunchInfo::GetEnvironment
SBEnvironment GetEnvironment()
Return the environment variables of this object.
Definition: SBLaunchInfo.cpp:196
lldb::SBLaunchInfo::GetNumArguments
uint32_t GetNumArguments()
Definition: SBLaunchInfo.cpp:140
lldb::SBLaunchInfo::SetExecutableFile
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...
Definition: SBLaunchInfo.cpp:121
lldb::SBLaunchInfo::GetEnvironmentEntryAtIndex
const char * GetEnvironmentEntryAtIndex(uint32_t idx)
Definition: SBLaunchInfo.cpp:172
lldb::SBLaunchInfo::GetLaunchFlags
uint32_t GetLaunchFlags()
Definition: SBLaunchInfo.cpp:219
lldb::SBListener
Definition: SBListener.h:16
lldb::SBLaunchInfo::ref
const lldb_private::ProcessLaunchInfo & ref() const
Definition: SBLaunchInfo.cpp:65
lldb_private::SBLaunchInfoImpl::SBLaunchInfoImpl
SBLaunchInfoImpl()
Definition: SBLaunchInfo.cpp:26
lldb::SBLaunchInfo::GetProcessID
lldb::pid_t GetProcessID()
Definition: SBLaunchInfo.cpp:73
uint32_t
lldb::SBStructuredData
Definition: SBStructuredData.h:17
lldb::SBLaunchInfo::Clear
void Clear()
Definition: SBLaunchInfo.cpp:201
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb::SBLaunchInfo::AddOpenFileAction
bool AddOpenFileAction(int fd, const char *path, bool read, bool write)
Definition: SBLaunchInfo.cpp:294
lldb::SBLaunchInfo::SetGroupID
void SetGroupID(uint32_t gid)
Definition: SBLaunchInfo.cpp:109
lldb_private::Environment
Definition: Environment.h:18
lldb::SBLaunchInfo::set_ref
void set_ref(const lldb_private::ProcessLaunchInfo &info)
Definition: SBLaunchInfo.cpp:69
SBStructuredData.h
lldb::SBFileSpec
Definition: SBFileSpec.h:16
StructuredDataImpl.h
SBEnvironment.h
lldb::SBLaunchInfo::SetEnvironment
void SetEnvironment(const SBEnvironment &env, bool append)
Update this object with the given environment variables.
Definition: SBLaunchInfo.cpp:185
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBLaunchInfo::SetArguments
void SetArguments(const char **argv, bool append)
Definition: SBLaunchInfo.cpp:152
lldb::SBLaunchInfo::GetUserID
uint32_t GetUserID()
Definition: SBLaunchInfo.cpp:79
lldb::SBLaunchInfo::SetWorkingDirectory
void SetWorkingDirectory(const char *working_dir)
Definition: SBLaunchInfo.cpp:213
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBLaunchInfo::GetScriptedProcessClassName
const char * GetScriptedProcessClassName() const
Definition: SBLaunchInfo.cpp:331
lldb::SBLaunchInfo::GroupIDIsValid
bool GroupIDIsValid()
Definition: SBLaunchInfo.cpp:97
lldb_private::SBLaunchInfoImpl::GetEnvp
const char *const * GetEnvp() const
Definition: SBLaunchInfo.cpp:28
lldb::SBLaunchInfo::AddSuppressFileAction
bool AddSuppressFileAction(int fd, bool read, bool write)
Definition: SBLaunchInfo.cpp:301
lldb::SBLaunchInfo::SetScriptedProcessClassName
void SetScriptedProcessClassName(const char *class_name)
Definition: SBLaunchInfo.cpp:340
lldb::SBLaunchInfo::SetShellExpandArguments
void SetShellExpandArguments(bool expand)
Definition: SBLaunchInfo.cpp:264
lldb_private::SBLaunchInfoImpl
Definition: SBLaunchInfo.cpp:24
lldb::SBLaunchInfo::SetProcessPluginName
void SetProcessPluginName(const char *plugin_name)
Definition: SBLaunchInfo.cpp:237
lldb
Definition: SBAddress.h:15
lldb::SBFileSpec
class LLDB_API SBFileSpec
Definition: SBDefines.h:58
lldb::SBLaunchInfo::SetShell
void SetShell(const char *path)
Definition: SBLaunchInfo.cpp:252
SBError.h
lldb::SBLaunchInfo::GetProcessPluginName
const char * GetProcessPluginName()
Definition: SBLaunchInfo.cpp:231
lldb::SBStructuredData::IsValid
bool IsValid() const
Definition: SBStructuredData.cpp:77