blob: aa1759ab3d0023411afffadd4f6aa1ba5b0077c3 [file] [log] [blame]
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +00001//===-- SBLaunchInfo.cpp ----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000010#include "lldb/API/SBLaunchInfo.h"
11
12#include "lldb/API/SBFileSpec.h"
13#include "lldb/API/SBListener.h"
14#include "lldb/Target/ProcessLaunchInfo.h"
15
16using namespace lldb;
17using namespace lldb_private;
18
Pavel Labath62930e52018-01-10 11:57:31 +000019class lldb_private::SBLaunchInfoImpl : public ProcessLaunchInfo {
20public:
21 SBLaunchInfoImpl()
22 : ProcessLaunchInfo(), m_envp(GetEnvironment().getEnvp()) {}
23
24 const char *const *GetEnvp() const { return m_envp; }
25 void RegenerateEnvp() { m_envp = GetEnvironment().getEnvp(); }
26
27 SBLaunchInfoImpl &operator=(const ProcessLaunchInfo &rhs) {
28 ProcessLaunchInfo::operator=(rhs);
29 RegenerateEnvp();
30 return *this;
31 }
32
33private:
34 Environment::Envp m_envp;
35};
36
Kate Stoneb9c1b512016-09-06 20:57:50 +000037SBLaunchInfo::SBLaunchInfo(const char **argv)
Pavel Labath62930e52018-01-10 11:57:31 +000038 : m_opaque_sp(new SBLaunchInfoImpl()) {
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
40 if (argv && argv[0])
41 m_opaque_sp->GetArguments().SetArguments(argv);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000042}
43
Kate Stoneb9c1b512016-09-06 20:57:50 +000044SBLaunchInfo::~SBLaunchInfo() {}
45
Kate Stoneb9c1b512016-09-06 20:57:50 +000046const lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() const {
47 return *m_opaque_sp;
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000048}
49
Pavel Labath62930e52018-01-10 11:57:31 +000050void SBLaunchInfo::set_ref(const ProcessLaunchInfo &info) {
51 *m_opaque_sp = info;
52}
53
Kate Stoneb9c1b512016-09-06 20:57:50 +000054lldb::pid_t SBLaunchInfo::GetProcessID() { return m_opaque_sp->GetProcessID(); }
55
56uint32_t SBLaunchInfo::GetUserID() { return m_opaque_sp->GetUserID(); }
57
58uint32_t SBLaunchInfo::GetGroupID() { return m_opaque_sp->GetGroupID(); }
59
60bool SBLaunchInfo::UserIDIsValid() { return m_opaque_sp->UserIDIsValid(); }
61
62bool SBLaunchInfo::GroupIDIsValid() { return m_opaque_sp->GroupIDIsValid(); }
63
64void SBLaunchInfo::SetUserID(uint32_t uid) { m_opaque_sp->SetUserID(uid); }
65
66void SBLaunchInfo::SetGroupID(uint32_t gid) { m_opaque_sp->SetGroupID(gid); }
67
68SBFileSpec SBLaunchInfo::GetExecutableFile() {
69 return SBFileSpec(m_opaque_sp->GetExecutableFile());
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000070}
71
Kate Stoneb9c1b512016-09-06 20:57:50 +000072void SBLaunchInfo::SetExecutableFile(SBFileSpec exe_file,
73 bool add_as_first_arg) {
74 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
Ilia K8f37ca52015-02-13 14:31:06 +000075}
76
Kate Stoneb9c1b512016-09-06 20:57:50 +000077SBListener SBLaunchInfo::GetListener() {
78 return SBListener(m_opaque_sp->GetListener());
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000079}
80
Kate Stoneb9c1b512016-09-06 20:57:50 +000081void SBLaunchInfo::SetListener(SBListener &listener) {
82 m_opaque_sp->SetListener(listener.GetSP());
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000083}
84
Kate Stoneb9c1b512016-09-06 20:57:50 +000085uint32_t SBLaunchInfo::GetNumArguments() {
86 return m_opaque_sp->GetArguments().GetArgumentCount();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000087}
88
Kate Stoneb9c1b512016-09-06 20:57:50 +000089const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
90 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000091}
92
Kate Stoneb9c1b512016-09-06 20:57:50 +000093void SBLaunchInfo::SetArguments(const char **argv, bool append) {
94 if (append) {
95 if (argv)
96 m_opaque_sp->GetArguments().AppendArguments(argv);
97 } else {
98 if (argv)
99 m_opaque_sp->GetArguments().SetArguments(argv);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000100 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 m_opaque_sp->GetArguments().Clear();
102 }
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000103}
104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105uint32_t SBLaunchInfo::GetNumEnvironmentEntries() {
Pavel Labath62930e52018-01-10 11:57:31 +0000106 return m_opaque_sp->GetEnvironment().size();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000107}
108
Kate Stoneb9c1b512016-09-06 20:57:50 +0000109const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) {
Pavel Labath62930e52018-01-10 11:57:31 +0000110 if (idx > GetNumEnvironmentEntries())
111 return nullptr;
112 return m_opaque_sp->GetEnvp()[idx];
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000113}
114
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
Pavel Labath62930e52018-01-10 11:57:31 +0000116 Environment env(envp);
117 if (append)
118 m_opaque_sp->GetEnvironment().insert(env.begin(), env.end());
119 else
120 m_opaque_sp->GetEnvironment() = env;
121 m_opaque_sp->RegenerateEnvp();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000122}
123
Kate Stoneb9c1b512016-09-06 20:57:50 +0000124void SBLaunchInfo::Clear() { m_opaque_sp->Clear(); }
125
126const char *SBLaunchInfo::GetWorkingDirectory() const {
127 return m_opaque_sp->GetWorkingDirectory().GetCString();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000128}
129
Kate Stoneb9c1b512016-09-06 20:57:50 +0000130void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
131 m_opaque_sp->SetWorkingDirectory(FileSpec{working_dir, false});
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000132}
133
Kate Stoneb9c1b512016-09-06 20:57:50 +0000134uint32_t SBLaunchInfo::GetLaunchFlags() {
135 return m_opaque_sp->GetFlags().Get();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000136}
137
Kate Stoneb9c1b512016-09-06 20:57:50 +0000138void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
139 m_opaque_sp->GetFlags().Reset(flags);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000140}
141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142const char *SBLaunchInfo::GetProcessPluginName() {
143 return m_opaque_sp->GetProcessPluginName();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000144}
145
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
147 return m_opaque_sp->SetProcessPluginName(plugin_name);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000148}
149
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150const char *SBLaunchInfo::GetShell() {
Adrian Prantl05097242018-04-30 16:49:04 +0000151 // Constify this string so that it is saved in the string pool. Otherwise it
152 // would be freed when this function goes out of scope.
Kate Stoneb9c1b512016-09-06 20:57:50 +0000153 ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
154 return shell.AsCString();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000155}
156
Kate Stoneb9c1b512016-09-06 20:57:50 +0000157void SBLaunchInfo::SetShell(const char *path) {
158 m_opaque_sp->SetShell(FileSpec(path, false));
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000159}
160
Kate Stoneb9c1b512016-09-06 20:57:50 +0000161bool SBLaunchInfo::GetShellExpandArguments() {
162 return m_opaque_sp->GetShellExpandArguments();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000163}
164
Kate Stoneb9c1b512016-09-06 20:57:50 +0000165void SBLaunchInfo::SetShellExpandArguments(bool expand) {
166 m_opaque_sp->SetShellExpandArguments(expand);
Enrico Granatac11b1012015-02-10 03:16:55 +0000167}
168
Kate Stoneb9c1b512016-09-06 20:57:50 +0000169uint32_t SBLaunchInfo::GetResumeCount() {
170 return m_opaque_sp->GetResumeCount();
Enrico Granatac11b1012015-02-10 03:16:55 +0000171}
172
Kate Stoneb9c1b512016-09-06 20:57:50 +0000173void SBLaunchInfo::SetResumeCount(uint32_t c) {
174 m_opaque_sp->SetResumeCount(c);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000175}
176
Kate Stoneb9c1b512016-09-06 20:57:50 +0000177bool SBLaunchInfo::AddCloseFileAction(int fd) {
178 return m_opaque_sp->AppendCloseFileAction(fd);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000179}
180
Kate Stoneb9c1b512016-09-06 20:57:50 +0000181bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
182 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000183}
184
Kate Stoneb9c1b512016-09-06 20:57:50 +0000185bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
186 bool write) {
187 return m_opaque_sp->AppendOpenFileAction(fd, FileSpec{path, false}, read,
188 write);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000189}
190
Kate Stoneb9c1b512016-09-06 20:57:50 +0000191bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
192 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000193}
194
Kate Stoneb9c1b512016-09-06 20:57:50 +0000195void SBLaunchInfo::SetLaunchEventData(const char *data) {
196 m_opaque_sp->SetLaunchEventData(data);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000197}
198
Kate Stoneb9c1b512016-09-06 20:57:50 +0000199const char *SBLaunchInfo::GetLaunchEventData() const {
200 return m_opaque_sp->GetLaunchEventData();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000201}
202
Kate Stoneb9c1b512016-09-06 20:57:50 +0000203void SBLaunchInfo::SetDetachOnError(bool enable) {
204 m_opaque_sp->SetDetachOnError(enable);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000205}
206
Kate Stoneb9c1b512016-09-06 20:57:50 +0000207bool SBLaunchInfo::GetDetachOnError() const {
208 return m_opaque_sp->GetDetachOnError();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000209}