1 //===-- SBLaunchInfo.cpp ----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBLaunchInfo.h"
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBListener.h"
14 #include "lldb/Target/ProcessLaunchInfo.h"
17 using namespace lldb_private;
19 SBLaunchInfo::SBLaunchInfo(const char **argv)
20 : m_opaque_sp(new ProcessLaunchInfo()) {
21 m_opaque_sp->GetFlags().Reset(eLaunchFlagDebug | eLaunchFlagDisableASLR);
23 m_opaque_sp->GetArguments().SetArguments(argv);
26 SBLaunchInfo::~SBLaunchInfo() {}
28 lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() { return *m_opaque_sp; }
30 const lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() const {
34 lldb::pid_t SBLaunchInfo::GetProcessID() { return m_opaque_sp->GetProcessID(); }
36 uint32_t SBLaunchInfo::GetUserID() { return m_opaque_sp->GetUserID(); }
38 uint32_t SBLaunchInfo::GetGroupID() { return m_opaque_sp->GetGroupID(); }
40 bool SBLaunchInfo::UserIDIsValid() { return m_opaque_sp->UserIDIsValid(); }
42 bool SBLaunchInfo::GroupIDIsValid() { return m_opaque_sp->GroupIDIsValid(); }
44 void SBLaunchInfo::SetUserID(uint32_t uid) { m_opaque_sp->SetUserID(uid); }
46 void SBLaunchInfo::SetGroupID(uint32_t gid) { m_opaque_sp->SetGroupID(gid); }
48 SBFileSpec SBLaunchInfo::GetExecutableFile() {
49 return SBFileSpec(m_opaque_sp->GetExecutableFile());
52 void SBLaunchInfo::SetExecutableFile(SBFileSpec exe_file,
53 bool add_as_first_arg) {
54 m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg);
57 SBListener SBLaunchInfo::GetListener() {
58 return SBListener(m_opaque_sp->GetListener());
61 void SBLaunchInfo::SetListener(SBListener &listener) {
62 m_opaque_sp->SetListener(listener.GetSP());
65 uint32_t SBLaunchInfo::GetNumArguments() {
66 return m_opaque_sp->GetArguments().GetArgumentCount();
69 const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) {
70 return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx);
73 void SBLaunchInfo::SetArguments(const char **argv, bool append) {
76 m_opaque_sp->GetArguments().AppendArguments(argv);
79 m_opaque_sp->GetArguments().SetArguments(argv);
81 m_opaque_sp->GetArguments().Clear();
85 uint32_t SBLaunchInfo::GetNumEnvironmentEntries() {
86 return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount();
89 const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) {
90 return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx);
93 void SBLaunchInfo::SetEnvironmentEntries(const char **envp, bool append) {
96 m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp);
99 m_opaque_sp->GetEnvironmentEntries().SetArguments(envp);
101 m_opaque_sp->GetEnvironmentEntries().Clear();
105 void SBLaunchInfo::Clear() { m_opaque_sp->Clear(); }
107 const char *SBLaunchInfo::GetWorkingDirectory() const {
108 return m_opaque_sp->GetWorkingDirectory().GetCString();
111 void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) {
112 m_opaque_sp->SetWorkingDirectory(FileSpec{working_dir, false});
115 uint32_t SBLaunchInfo::GetLaunchFlags() {
116 return m_opaque_sp->GetFlags().Get();
119 void SBLaunchInfo::SetLaunchFlags(uint32_t flags) {
120 m_opaque_sp->GetFlags().Reset(flags);
123 const char *SBLaunchInfo::GetProcessPluginName() {
124 return m_opaque_sp->GetProcessPluginName();
127 void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) {
128 return m_opaque_sp->SetProcessPluginName(plugin_name);
131 const 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();
138 void SBLaunchInfo::SetShell(const char *path) {
139 m_opaque_sp->SetShell(FileSpec(path, false));
142 bool SBLaunchInfo::GetShellExpandArguments() {
143 return m_opaque_sp->GetShellExpandArguments();
146 void SBLaunchInfo::SetShellExpandArguments(bool expand) {
147 m_opaque_sp->SetShellExpandArguments(expand);
150 uint32_t SBLaunchInfo::GetResumeCount() {
151 return m_opaque_sp->GetResumeCount();
154 void SBLaunchInfo::SetResumeCount(uint32_t c) {
155 m_opaque_sp->SetResumeCount(c);
158 bool SBLaunchInfo::AddCloseFileAction(int fd) {
159 return m_opaque_sp->AppendCloseFileAction(fd);
162 bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) {
163 return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd);
166 bool SBLaunchInfo::AddOpenFileAction(int fd, const char *path, bool read,
168 return m_opaque_sp->AppendOpenFileAction(fd, FileSpec{path, false}, read,
172 bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) {
173 return m_opaque_sp->AppendSuppressFileAction(fd, read, write);
176 void SBLaunchInfo::SetLaunchEventData(const char *data) {
177 m_opaque_sp->SetLaunchEventData(data);
180 const char *SBLaunchInfo::GetLaunchEventData() const {
181 return m_opaque_sp->GetLaunchEventData();
184 void SBLaunchInfo::SetDetachOnError(bool enable) {
185 m_opaque_sp->SetDetachOnError(enable);
188 bool SBLaunchInfo::GetDetachOnError() const {
189 return m_opaque_sp->GetDetachOnError();