1 //===-- SBLaunchInfo.h ------------------------------------------*- 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 
9 #ifndef LLDB_API_SBLAUNCHINFO_H
10 #define LLDB_API_SBLAUNCHINFO_H
11 
12 #include "lldb/API/SBDefines.h"
13 
14 namespace lldb_private {
15 class SBLaunchInfoImpl;
16 }
17 
18 namespace lldb {
19 
20 class SBPlatform;
21 class SBTarget;
22 
23 class LLDB_API SBLaunchInfo {
24 public:
25   SBLaunchInfo(const char **argv);
26 
27   ~SBLaunchInfo();
28 
29   SBLaunchInfo(const SBLaunchInfo &rhs);
30 
31   SBLaunchInfo &operator=(const SBLaunchInfo &rhs);
32 
33   lldb::pid_t GetProcessID();
34 
35   uint32_t GetUserID();
36 
37   uint32_t GetGroupID();
38 
39   bool UserIDIsValid();
40 
41   bool GroupIDIsValid();
42 
43   void SetUserID(uint32_t uid);
44 
45   void SetGroupID(uint32_t gid);
46 
47   SBFileSpec GetExecutableFile();
48 
49   /// Set the executable file that will be used to launch the process and
50   /// optionally set it as the first argument in the argument vector.
51   ///
52   /// This only needs to be specified if clients wish to carefully control
53   /// the exact path will be used to launch a binary. If you create a
54   /// target with a symlink, that symlink will get resolved in the target
55   /// and the resolved path will get used to launch the process. Calling
56   /// this function can help you still launch your process using the
57   /// path of your choice.
58   ///
59   /// If this function is not called prior to launching with
60   /// SBTarget::Launch(...), the target will use the resolved executable
61   /// path that was used to create the target.
62   ///
63   /// \param[in] exe_file
64   ///     The override path to use when launching the executable.
65   ///
66   /// \param[in] add_as_first_arg
67   ///     If true, then the path will be inserted into the argument vector
68   ///     prior to launching. Otherwise the argument vector will be left
69   ///     alone.
70   void SetExecutableFile(SBFileSpec exe_file, bool add_as_first_arg);
71 
72   /// Get the listener that will be used to receive process events.
73   ///
74   /// If no listener has been set via a call to
75   /// SBLaunchInfo::SetListener(), then an invalid SBListener will be
76   /// returned (SBListener::IsValid() will return false). If a listener
77   /// has been set, then the valid listener object will be returned.
78   SBListener GetListener();
79 
80   /// Set the listener that will be used to receive process events.
81   ///
82   /// By default the SBDebugger, which has a listener, that the SBTarget
83   /// belongs to will listen for the process events. Calling this function
84   /// allows a different listener to be used to listen for process events.
85   void SetListener(SBListener &listener);
86 
87   uint32_t GetNumArguments();
88 
89   const char *GetArgumentAtIndex(uint32_t idx);
90 
91   void SetArguments(const char **argv, bool append);
92 
93   uint32_t GetNumEnvironmentEntries();
94 
95   const char *GetEnvironmentEntryAtIndex(uint32_t idx);
96 
97   /// Update this object with the given environment variables.
98   ///
99   /// If append is false, the provided environment will replace the existing
100   /// environment. Otherwise, existing values will be updated of left untouched
101   /// accordingly.
102   ///
103   /// \param [in] envp
104   ///     The new environment variables as a list of strings with the following
105   ///     format
106   ///         name=value
107   ///
108   /// \param [in] append
109   ///     Flag that controls whether to replace the existing environment.
110   void SetEnvironmentEntries(const char **envp, bool append);
111 
112   /// Update this object with the given environment variables.
113   ///
114   /// If append is false, the provided environment will replace the existing
115   /// environment. Otherwise, existing values will be updated of left untouched
116   /// accordingly.
117   ///
118   /// \param [in] env
119   ///     The new environment variables.
120   ///
121   /// \param [in] append
122   ///     Flag that controls whether to replace the existing environment.
123   void SetEnvironment(const SBEnvironment &env, bool append);
124 
125   /// Return the environment variables of this object.
126   ///
127   /// \return
128   ///     An lldb::SBEnvironment object which is a copy of the SBLaunchInfo's
129   ///     environment.
130   SBEnvironment GetEnvironment();
131 
132   void Clear();
133 
134   const char *GetWorkingDirectory() const;
135 
136   void SetWorkingDirectory(const char *working_dir);
137 
138   uint32_t GetLaunchFlags();
139 
140   void SetLaunchFlags(uint32_t flags);
141 
142   const char *GetProcessPluginName();
143 
144   void SetProcessPluginName(const char *plugin_name);
145 
146   const char *GetShell();
147 
148   void SetShell(const char *path);
149 
150   bool GetShellExpandArguments();
151 
152   void SetShellExpandArguments(bool expand);
153 
154   uint32_t GetResumeCount();
155 
156   void SetResumeCount(uint32_t c);
157 
158   bool AddCloseFileAction(int fd);
159 
160   bool AddDuplicateFileAction(int fd, int dup_fd);
161 
162   bool AddOpenFileAction(int fd, const char *path, bool read, bool write);
163 
164   bool AddSuppressFileAction(int fd, bool read, bool write);
165 
166   void SetLaunchEventData(const char *data);
167 
168   const char *GetLaunchEventData() const;
169 
170   bool GetDetachOnError() const;
171 
172   void SetDetachOnError(bool enable);
173 
174 protected:
175   friend class SBPlatform;
176   friend class SBTarget;
177 
178   const lldb_private::ProcessLaunchInfo &ref() const;
179   void set_ref(const lldb_private::ProcessLaunchInfo &info);
180 
181   std::shared_ptr<lldb_private::SBLaunchInfoImpl> m_opaque_sp;
182 };
183 
184 } // namespace lldb
185 
186 #endif // LLDB_API_SBLAUNCHINFO_H
187