Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 1 | //===-- 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 Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 10 | #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 | |
| 16 | using namespace lldb; |
| 17 | using namespace lldb_private; |
| 18 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | SBLaunchInfo::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 Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | SBLaunchInfo::~SBLaunchInfo() {} |
| 27 | |
| 28 | lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() { return *m_opaque_sp; } |
| 29 | |
| 30 | const lldb_private::ProcessLaunchInfo &SBLaunchInfo::ref() const { |
| 31 | return *m_opaque_sp; |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 34 | lldb::pid_t SBLaunchInfo::GetProcessID() { return m_opaque_sp->GetProcessID(); } |
| 35 | |
| 36 | uint32_t SBLaunchInfo::GetUserID() { return m_opaque_sp->GetUserID(); } |
| 37 | |
| 38 | uint32_t SBLaunchInfo::GetGroupID() { return m_opaque_sp->GetGroupID(); } |
| 39 | |
| 40 | bool SBLaunchInfo::UserIDIsValid() { return m_opaque_sp->UserIDIsValid(); } |
| 41 | |
| 42 | bool SBLaunchInfo::GroupIDIsValid() { return m_opaque_sp->GroupIDIsValid(); } |
| 43 | |
| 44 | void SBLaunchInfo::SetUserID(uint32_t uid) { m_opaque_sp->SetUserID(uid); } |
| 45 | |
| 46 | void SBLaunchInfo::SetGroupID(uint32_t gid) { m_opaque_sp->SetGroupID(gid); } |
| 47 | |
| 48 | SBFileSpec SBLaunchInfo::GetExecutableFile() { |
| 49 | return SBFileSpec(m_opaque_sp->GetExecutableFile()); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | SBListener SBLaunchInfo::GetListener() { |
| 58 | return SBListener(m_opaque_sp->GetListener()); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | void SBLaunchInfo::SetListener(SBListener &listener) { |
| 62 | m_opaque_sp->SetListener(listener.GetSP()); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | uint32_t SBLaunchInfo::GetNumArguments() { |
| 66 | return m_opaque_sp->GetArguments().GetArgumentCount(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | const char *SBLaunchInfo::GetArgumentAtIndex(uint32_t idx) { |
| 70 | return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 73 | void 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 Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 80 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | m_opaque_sp->GetArguments().Clear(); |
| 82 | } |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | uint32_t SBLaunchInfo::GetNumEnvironmentEntries() { |
| 86 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | const char *SBLaunchInfo::GetEnvironmentEntryAtIndex(uint32_t idx) { |
| 90 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | void 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 Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 100 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | m_opaque_sp->GetEnvironmentEntries().Clear(); |
| 102 | } |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | void SBLaunchInfo::Clear() { m_opaque_sp->Clear(); } |
| 106 | |
| 107 | const char *SBLaunchInfo::GetWorkingDirectory() const { |
| 108 | return m_opaque_sp->GetWorkingDirectory().GetCString(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 111 | void SBLaunchInfo::SetWorkingDirectory(const char *working_dir) { |
| 112 | m_opaque_sp->SetWorkingDirectory(FileSpec{working_dir, false}); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 115 | uint32_t SBLaunchInfo::GetLaunchFlags() { |
| 116 | return m_opaque_sp->GetFlags().Get(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 119 | void SBLaunchInfo::SetLaunchFlags(uint32_t flags) { |
| 120 | m_opaque_sp->GetFlags().Reset(flags); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 123 | const char *SBLaunchInfo::GetProcessPluginName() { |
| 124 | return m_opaque_sp->GetProcessPluginName(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 127 | void SBLaunchInfo::SetProcessPluginName(const char *plugin_name) { |
| 128 | return m_opaque_sp->SetProcessPluginName(plugin_name); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 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(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | void SBLaunchInfo::SetShell(const char *path) { |
| 139 | m_opaque_sp->SetShell(FileSpec(path, false)); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | bool SBLaunchInfo::GetShellExpandArguments() { |
| 143 | return m_opaque_sp->GetShellExpandArguments(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 146 | void SBLaunchInfo::SetShellExpandArguments(bool expand) { |
| 147 | m_opaque_sp->SetShellExpandArguments(expand); |
Enrico Granata | c11b101 | 2015-02-10 03:16:55 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 150 | uint32_t SBLaunchInfo::GetResumeCount() { |
| 151 | return m_opaque_sp->GetResumeCount(); |
Enrico Granata | c11b101 | 2015-02-10 03:16:55 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | void SBLaunchInfo::SetResumeCount(uint32_t c) { |
| 155 | m_opaque_sp->SetResumeCount(c); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 158 | bool SBLaunchInfo::AddCloseFileAction(int fd) { |
| 159 | return m_opaque_sp->AppendCloseFileAction(fd); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 162 | bool SBLaunchInfo::AddDuplicateFileAction(int fd, int dup_fd) { |
| 163 | return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | bool 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 Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | bool SBLaunchInfo::AddSuppressFileAction(int fd, bool read, bool write) { |
| 173 | return m_opaque_sp->AppendSuppressFileAction(fd, read, write); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 176 | void SBLaunchInfo::SetLaunchEventData(const char *data) { |
| 177 | m_opaque_sp->SetLaunchEventData(data); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 180 | const char *SBLaunchInfo::GetLaunchEventData() const { |
| 181 | return m_opaque_sp->GetLaunchEventData(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | void SBLaunchInfo::SetDetachOnError(bool enable) { |
| 185 | m_opaque_sp->SetDetachOnError(enable); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 188 | bool SBLaunchInfo::GetDetachOnError() const { |
| 189 | return m_opaque_sp->GetDetachOnError(); |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 190 | } |