blob: 5f5afccee68085c219acc9953de367e7cd2b190e [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
Kate Stoneb9c1b512016-09-06 20:57:50 +000019SBLaunchInfo::SBLaunchInfo(const char **argv)
20 : m_opaque_sp(new ProcessLaunchInfo()) {
21 m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
22 if (argv && argv[0])
23 m_opaque_sp->GetArguments().SetArguments(argv);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000024}
25
Kate Stoneb9c1b512016-09-06 20:57:50 +000026SBLaunchInfo::~SBLaunchInfo() {}
27
28lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() { return *m_opaque_sp; }
29
30const lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() const {
31 return *m_opaque_sp;
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000032}
33
Kate Stoneb9c1b512016-09-06 20:57:50 +000034lldb::pid_t SBLaunchInfo::GetProcessID() { return m_opaque_sp->GetProcessID(); }
35
36uint32_t SBLaunchInfo::GetUserID() { return m_opaque_sp->GetUserID(); }
37
38uint32_t SBLaunchInfo::GetGroupID() { return m_opaque_sp->GetGroupID(); }
39
40bool SBLaunchInfo::UserIDIsValid() { return m_opaque_sp->UserIDIsValid(); }
41
42bool SBLaunchInfo::GroupIDIsValid() { return m_opaque_sp->GroupIDIsValid(); }
43
44void SBLaunchInfo::SetUserID(uint32_t uid) { m_opaque_sp->SetUserID(uid); }
45
46void SBLaunchInfo::SetGroupID(uint32_t gid) { m_opaque_sp->SetGroupID(gid); }
47
48SBFileSpec SBLaunchInfo::GetExecutableFile() {
49 return SBFileSpec(m_opaque_sp->GetExecutableFile());
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000050}
51
Kate Stoneb9c1b512016-09-06 20:57:50 +000052void SBLaunchInfo::SetExecutableFile(SBFileSpec exe_file,
53 bool add_as_first_arg) {
54 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
Ilia K8f37ca52015-02-13 14:31:06 +000055}
56
Kate Stoneb9c1b512016-09-06 20:57:50 +000057SBListener SBLaunchInfo::GetListener() {
58 return SBListener(m_opaque_sp->GetListener());
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000059}
60
Kate Stoneb9c1b512016-09-06 20:57:50 +000061void SBLaunchInfo::SetListener(SBListener &listener) {
62 m_opaque_sp->SetListener(listener.GetSP());
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000063}
64
Kate Stoneb9c1b512016-09-06 20:57:50 +000065uint32_t SBLaunchInfo::GetNumArguments() {
66 return m_opaque_sp->GetArguments().GetArgumentCount();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000067}
68
Kate Stoneb9c1b512016-09-06 20:57:50 +000069const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
70 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000071}
72
Kate Stoneb9c1b512016-09-06 20:57:50 +000073void SBLaunchInfo::SetArguments(const char **argv, bool append) {
74 if (append) {
75 if (argv)
76 m_opaque_sp->GetArguments().AppendArguments(argv);
77 } else {
78 if (argv)
79 m_opaque_sp->GetArguments().SetArguments(argv);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000080 else
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 m_opaque_sp->GetArguments().Clear();
82 }
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000083}
84
Kate Stoneb9c1b512016-09-06 20:57:50 +000085uint32_t SBLaunchInfo::GetNumEnvironmentEntries() {
86 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000087}
88
Kate Stoneb9c1b512016-09-06 20:57:50 +000089const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) {
90 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +000091}
92
Kate Stoneb9c1b512016-09-06 20:57:50 +000093void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
94 if (append) {
95 if (envp)
96 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
97 } else {
98 if (envp)
99 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000100 else
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 m_opaque_sp->GetEnvironmentEntries().Clear();
102 }
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000103}
104
Kate Stoneb9c1b512016-09-06 20:57:50 +0000105void SBLaunchInfo::Clear() { m_opaque_sp->Clear(); }
106
107const char *SBLaunchInfo::GetWorkingDirectory() const {
108 return m_opaque_sp->GetWorkingDirectory().GetCString();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000109}
110
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
112 m_opaque_sp->SetWorkingDirectory(FileSpec{working_dir, false});
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000113}
114
Kate Stoneb9c1b512016-09-06 20:57:50 +0000115uint32_t SBLaunchInfo::GetLaunchFlags() {
116 return m_opaque_sp->GetFlags().Get();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000117}
118
Kate Stoneb9c1b512016-09-06 20:57:50 +0000119void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
120 m_opaque_sp->GetFlags().Reset(flags);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000121}
122
Kate Stoneb9c1b512016-09-06 20:57:50 +0000123const char *SBLaunchInfo::GetProcessPluginName() {
124 return m_opaque_sp->GetProcessPluginName();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000125}
126
Kate Stoneb9c1b512016-09-06 20:57:50 +0000127void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
128 return m_opaque_sp->SetProcessPluginName(plugin_name);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000129}
130
Kate Stoneb9c1b512016-09-06 20:57:50 +0000131const char *SBLaunchInfo::GetShell() {
132 // Constify this string so that it is saved in the string pool. Otherwise
133 // it would be freed when this function goes out of scope.
134 ConstString shell(m_opaque_sp->GetShell().GetPath().c_str());
135 return shell.AsCString();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000136}
137
Kate Stoneb9c1b512016-09-06 20:57:50 +0000138void SBLaunchInfo::SetShell(const char *path) {
139 m_opaque_sp->SetShell(FileSpec(path, false));
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000140}
141
Kate Stoneb9c1b512016-09-06 20:57:50 +0000142bool SBLaunchInfo::GetShellExpandArguments() {
143 return m_opaque_sp->GetShellExpandArguments();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000144}
145
Kate Stoneb9c1b512016-09-06 20:57:50 +0000146void SBLaunchInfo::SetShellExpandArguments(bool expand) {
147 m_opaque_sp->SetShellExpandArguments(expand);
Enrico Granatac11b1012015-02-10 03:16:55 +0000148}
149
Kate Stoneb9c1b512016-09-06 20:57:50 +0000150uint32_t SBLaunchInfo::GetResumeCount() {
151 return m_opaque_sp->GetResumeCount();
Enrico Granatac11b1012015-02-10 03:16:55 +0000152}
153
Kate Stoneb9c1b512016-09-06 20:57:50 +0000154void SBLaunchInfo::SetResumeCount(uint32_t c) {
155 m_opaque_sp->SetResumeCount(c);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000156}
157
Kate Stoneb9c1b512016-09-06 20:57:50 +0000158bool SBLaunchInfo::AddCloseFileAction(int fd) {
159 return m_opaque_sp->AppendCloseFileAction(fd);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000160}
161
Kate Stoneb9c1b512016-09-06 20:57:50 +0000162bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
163 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000164}
165
Kate Stoneb9c1b512016-09-06 20:57:50 +0000166bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
167 bool write) {
168 return m_opaque_sp->AppendOpenFileAction(fd, FileSpec{path, false}, read,
169 write);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000170}
171
Kate Stoneb9c1b512016-09-06 20:57:50 +0000172bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
173 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000174}
175
Kate Stoneb9c1b512016-09-06 20:57:50 +0000176void SBLaunchInfo::SetLaunchEventData(const char *data) {
177 m_opaque_sp->SetLaunchEventData(data);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000178}
179
Kate Stoneb9c1b512016-09-06 20:57:50 +0000180const char *SBLaunchInfo::GetLaunchEventData() const {
181 return m_opaque_sp->GetLaunchEventData();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000182}
183
Kate Stoneb9c1b512016-09-06 20:57:50 +0000184void SBLaunchInfo::SetDetachOnError(bool enable) {
185 m_opaque_sp->SetDetachOnError(enable);
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000186}
187
Kate Stoneb9c1b512016-09-06 20:57:50 +0000188bool SBLaunchInfo::GetDetachOnError() const {
189 return m_opaque_sp->GetDetachOnError();
Oleksiy Vyalov1ef7b2c2015-02-04 23:19:15 +0000190}