LLDB  mainline
SBLaunchInfo.cpp
Go to the documentation of this file.
1 //===-- SBLaunchInfo.cpp ----------------------------------------*- C++ -*-===//
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 
10 #include "SBReproducerPrivate.h"
11 
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBListener.h"
15 
16 using namespace lldb;
17 using namespace lldb_private;
18 
20 public:
22  : ProcessLaunchInfo(), m_envp(GetEnvironment().getEnvp()) {}
23 
24  const char *const *GetEnvp() const { return m_envp; }
25  void RegenerateEnvp() { m_envp = GetEnvironment().getEnvp(); }
26 
28  ProcessLaunchInfo::operator=(rhs);
29  RegenerateEnvp();
30  return *this;
31  }
32 
33 private:
34  Environment::Envp m_envp;
35 };
36 
37 SBLaunchInfo::SBLaunchInfo(const char **argv)
38  : m_opaque_sp(new SBLaunchInfoImpl()) {
39  LLDB_RECORD_CONSTRUCTOR(SBLaunchInfo, (const char **), argv);
40 
41  m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
42  if (argv && argv[0])
43  m_opaque_sp->GetArguments().SetArguments(argv);
44 }
45 
47 
49  return *m_opaque_sp;
50 }
51 
53  *m_opaque_sp = info;
54 }
55 
58 
59  return m_opaque_sp->GetProcessID();
60 }
61 
64 
65  return m_opaque_sp->GetUserID();
66 }
67 
70 
71  return m_opaque_sp->GetGroupID();
72 }
73 
76 
77  return m_opaque_sp->UserIDIsValid();
78 }
79 
82 
83  return m_opaque_sp->GroupIDIsValid();
84 }
85 
88 
89  m_opaque_sp->SetUserID(uid);
90 }
91 
94 
95  m_opaque_sp->SetGroupID(gid);
96 }
97 
100 
101  return LLDB_RECORD_RESULT(SBFileSpec(m_opaque_sp->GetExecutableFile()));
102 }
103 
105  bool add_as_first_arg) {
107  (lldb::SBFileSpec, bool), exe_file, add_as_first_arg);
108 
109  m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
110 }
111 
114 
115  return LLDB_RECORD_RESULT(SBListener(m_opaque_sp->GetListener()));
116 }
117 
120  listener);
121 
122  m_opaque_sp->SetListener(listener.GetSP());
123 }
124 
127 
128  return m_opaque_sp->GetArguments().GetArgumentCount();
129 }
130 
133  idx);
134 
135  return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
136 }
137 
138 void SBLaunchInfo::SetArguments(const char **argv, bool append) {
139  LLDB_RECORD_METHOD(void, SBLaunchInfo, SetArguments, (const char **, bool),
140  argv, append);
141 
142  if (append) {
143  if (argv)
144  m_opaque_sp->GetArguments().AppendArguments(argv);
145  } else {
146  if (argv)
147  m_opaque_sp->GetArguments().SetArguments(argv);
148  else
149  m_opaque_sp->GetArguments().Clear();
150  }
151 }
152 
155 
156  return m_opaque_sp->GetEnvironment().size();
157 }
158 
161  (uint32_t), idx);
162 
163  if (idx > GetNumEnvironmentEntries())
164  return nullptr;
165  return m_opaque_sp->GetEnvp()[idx];
166 }
167 
168 void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
170  (const char **, bool), envp, append);
171 
172  Environment env(envp);
173  if (append)
174  m_opaque_sp->GetEnvironment().insert(env.begin(), env.end());
175  else
176  m_opaque_sp->GetEnvironment() = env;
177  m_opaque_sp->RegenerateEnvp();
178 }
179 
182 
183  m_opaque_sp->Clear();
184 }
185 
189 
190  return m_opaque_sp->GetWorkingDirectory().GetCString();
191 }
192 
193 void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
194  LLDB_RECORD_METHOD(void, SBLaunchInfo, SetWorkingDirectory, (const char *),
195  working_dir);
196 
197  m_opaque_sp->SetWorkingDirectory(FileSpec(working_dir));
198 }
199 
202 
203  return m_opaque_sp->GetFlags().Get();
204 }
205 
208 
209  m_opaque_sp->GetFlags().Reset(flags);
210 }
211 
214 
215  return m_opaque_sp->GetProcessPluginName();
216 }
217 
218 void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
220  plugin_name);
221 
222  return m_opaque_sp->SetProcessPluginName(plugin_name);
223 }
224 
225 const char *SBLaunchInfo::GetShell() {
227 
228  // Constify this string so that it is saved in the string pool. Otherwise it
229  // would be freed when this function goes out of scope.
230  ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
231  return shell.AsCString();
232 }
233 
234 void SBLaunchInfo::SetShell(const char *path) {
235  LLDB_RECORD_METHOD(void, SBLaunchInfo, SetShell, (const char *), path);
236 
237  m_opaque_sp->SetShell(FileSpec(path));
238 }
239 
242 
243  return m_opaque_sp->GetShellExpandArguments();
244 }
245 
248  expand);
249 
250  m_opaque_sp->SetShellExpandArguments(expand);
251 }
252 
255 
256  return m_opaque_sp->GetResumeCount();
257 }
258 
261 
262  m_opaque_sp->SetResumeCount(c);
263 }
264 
267 
268  return m_opaque_sp->AppendCloseFileAction(fd);
269 }
270 
271 bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
273  dup_fd);
274 
275  return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
276 }
277 
278 bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
279  bool write) {
281  (int, const char *, bool, bool), fd, path, read, write);
282 
283  return m_opaque_sp->AppendOpenFileAction(fd, FileSpec(path), read, write);
284 }
285 
286 bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
288  (int, bool, bool), fd, read, write);
289 
290  return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
291 }
292 
293 void SBLaunchInfo::SetLaunchEventData(const char *data) {
294  LLDB_RECORD_METHOD(void, SBLaunchInfo, SetLaunchEventData, (const char *),
295  data);
296 
297  m_opaque_sp->SetLaunchEventData(data);
298 }
299 
300 const char *SBLaunchInfo::GetLaunchEventData() const {
303 
304  return m_opaque_sp->GetLaunchEventData();
305 }
306 
308  LLDB_RECORD_METHOD(void, SBLaunchInfo, SetDetachOnError, (bool), enable);
309 
310  m_opaque_sp->SetDetachOnError(enable);
311 }
312 
315 
316  return m_opaque_sp->GetDetachOnError();
317 }
318 
319 namespace lldb_private {
320 namespace repro {
321 
322 template <>
324  LLDB_REGISTER_CONSTRUCTOR(SBLaunchInfo, (const char **));
334  (lldb::SBFileSpec, bool));
339  (uint32_t));
341  (const char **, bool));
344  (uint32_t));
346  (const char **, bool));
349  ());
351  (const char *));
356  (const char *));
357  LLDB_REGISTER_METHOD(const char *, SBLaunchInfo, GetShell, ());
358  LLDB_REGISTER_METHOD(void, SBLaunchInfo, SetShell, (const char *));
365  (int, int));
367  (int, const char *, bool, bool));
369  (int, bool, bool));
371  (const char *));
373  ());
376 }
377 
378 }
379 }
const char * GetProcessPluginName()
The registry contains a unique mapping between functions and their ID.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
SBListener GetListener()
Get the listener that will be used to receive process events.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:224
void SetLaunchFlags(uint32_t flags)
void SetDetachOnError(bool enable)
void SetResumeCount(uint32_t c)
uint32_t GetNumEnvironmentEntries()
bool GetDetachOnError() const
const char * GetEnvironmentEntryAtIndex(uint32_t idx)
A file utility class.
Definition: FileSpec.h:55
bool AddSuppressFileAction(int fd, bool read, bool write)
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...
bool AddCloseFileAction(int fd)
bool GetShellExpandArguments()
SBFileSpec GetExecutableFile()
void SetListener(SBListener &listener)
Set the listener that will be used to receive process events.
bool AddDuplicateFileAction(int fd, int dup_fd)
void SetArguments(const char **argv, bool append)
void set_ref(const lldb_private::ProcessLaunchInfo &info)
class LLDB_API SBFileSpec
Definition: SBDefines.h:44
const char *const * GetEnvp() const
void SetLaunchEventData(const char *data)
lldb::ListenerSP GetSP()
Definition: SBListener.cpp:315
std::shared_ptr< lldb_private::SBLaunchInfoImpl > m_opaque_sp
Definition: SBLaunchInfo.h:144
void RegisterMethods< SBLaunchInfo >(Registry &R)
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
uint32_t GetNumArguments()
const char * GetLaunchEventData() const
void SetEnvironmentEntries(const char **envp, bool append)
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
uint32_t GetResumeCount()
const char * GetShell()
const lldb_private::ProcessLaunchInfo & ref() const
bool AddOpenFileAction(int fd, const char *path, bool read, bool write)
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
const char * GetWorkingDirectory() const
class LLDB_API SBListener
Definition: SBDefines.h:54
void SetShellExpandArguments(bool expand)
SBLaunchInfo(const char **argv)
void SetGroupID(uint32_t gid)
A uniqued constant string class.
Definition: ConstString.h:38
uint32_t GetGroupID()
void SetShell(const char *path)
uint32_t GetLaunchFlags()
Definition: SBAddress.h:15
uint64_t pid_t
Definition: lldb-types.h:85
uint32_t GetUserID()
SBLaunchInfoImpl & operator=(const ProcessLaunchInfo &rhs)
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
void SetWorkingDirectory(const char *working_dir)
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
void SetProcessPluginName(const char *plugin_name)
lldb::pid_t GetProcessID()
#define LLDB_RECORD_RESULT(Result)
void SetUserID(uint32_t uid)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
const char * GetArgumentAtIndex(uint32_t idx)