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 | |
| 10 | #include "lldb/lldb-python.h" |
| 11 | |
| 12 | #include "lldb/API/SBLaunchInfo.h" |
| 13 | |
| 14 | #include "lldb/API/SBFileSpec.h" |
| 15 | #include "lldb/API/SBListener.h" |
| 16 | #include "lldb/Target/ProcessLaunchInfo.h" |
| 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | SBLaunchInfo::SBLaunchInfo (const char **argv) : |
| 22 | m_opaque_sp(new ProcessLaunchInfo()) |
| 23 | { |
| 24 | m_opaque_sp->GetFlags().Reset (eLaunchFlagDebug | eLaunchFlagDisableASLR); |
| 25 | if (argv && argv[0]) |
| 26 | m_opaque_sp->GetArguments().SetArguments(argv); |
| 27 | } |
| 28 | |
| 29 | SBLaunchInfo::~SBLaunchInfo() |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | lldb_private::ProcessLaunchInfo & |
| 34 | SBLaunchInfo::ref () |
| 35 | { |
| 36 | return *m_opaque_sp; |
| 37 | } |
| 38 | |
| 39 | lldb::pid_t |
| 40 | SBLaunchInfo::GetProcessID() |
| 41 | { |
| 42 | return m_opaque_sp->GetProcessID(); |
| 43 | } |
| 44 | |
| 45 | uint32_t |
| 46 | SBLaunchInfo::GetUserID() |
| 47 | { |
| 48 | return m_opaque_sp->GetUserID(); |
| 49 | } |
| 50 | |
| 51 | uint32_t |
| 52 | SBLaunchInfo::GetGroupID() |
| 53 | { |
| 54 | return m_opaque_sp->GetGroupID(); |
| 55 | } |
| 56 | |
| 57 | bool |
| 58 | SBLaunchInfo::UserIDIsValid () |
| 59 | { |
| 60 | return m_opaque_sp->UserIDIsValid(); |
| 61 | } |
| 62 | |
| 63 | bool |
| 64 | SBLaunchInfo::GroupIDIsValid () |
| 65 | { |
| 66 | return m_opaque_sp->GroupIDIsValid(); |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | SBLaunchInfo::SetUserID (uint32_t uid) |
| 71 | { |
| 72 | m_opaque_sp->SetUserID (uid); |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | SBLaunchInfo::SetGroupID (uint32_t gid) |
| 77 | { |
| 78 | m_opaque_sp->SetGroupID (gid); |
| 79 | } |
| 80 | |
| 81 | SBFileSpec |
| 82 | SBLaunchInfo::GetExecutableFile () |
| 83 | { |
| 84 | return SBFileSpec (m_opaque_sp->GetExecutableFile()); |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg) |
| 89 | { |
| 90 | m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg); |
| 91 | } |
| 92 | |
| 93 | SBListener |
| 94 | SBLaunchInfo::GetListener () |
| 95 | { |
| 96 | return SBListener(m_opaque_sp->GetListener()); |
| 97 | } |
| 98 | |
| 99 | void |
| 100 | SBLaunchInfo::SetListener (SBListener &listener) |
| 101 | { |
| 102 | m_opaque_sp->SetListener(listener.GetSP()); |
| 103 | } |
| 104 | |
| 105 | uint32_t |
| 106 | SBLaunchInfo::GetNumArguments () |
| 107 | { |
| 108 | return m_opaque_sp->GetArguments().GetArgumentCount(); |
| 109 | } |
| 110 | |
| 111 | const char * |
| 112 | SBLaunchInfo::GetArgumentAtIndex (uint32_t idx) |
| 113 | { |
| 114 | return m_opaque_sp->GetArguments().GetArgumentAtIndex(idx); |
| 115 | } |
| 116 | |
| 117 | void |
| 118 | SBLaunchInfo::SetArguments (const char **argv, bool append) |
| 119 | { |
| 120 | if (append) |
| 121 | { |
| 122 | if (argv) |
| 123 | m_opaque_sp->GetArguments().AppendArguments(argv); |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | if (argv) |
| 128 | m_opaque_sp->GetArguments().SetArguments(argv); |
| 129 | else |
| 130 | m_opaque_sp->GetArguments().Clear(); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | uint32_t |
| 135 | SBLaunchInfo::GetNumEnvironmentEntries () |
| 136 | { |
| 137 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentCount(); |
| 138 | } |
| 139 | |
| 140 | const char * |
| 141 | SBLaunchInfo::GetEnvironmentEntryAtIndex (uint32_t idx) |
| 142 | { |
| 143 | return m_opaque_sp->GetEnvironmentEntries().GetArgumentAtIndex(idx); |
| 144 | } |
| 145 | |
| 146 | void |
| 147 | SBLaunchInfo::SetEnvironmentEntries (const char **envp, bool append) |
| 148 | { |
| 149 | if (append) |
| 150 | { |
| 151 | if (envp) |
| 152 | m_opaque_sp->GetEnvironmentEntries().AppendArguments(envp); |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | if (envp) |
| 157 | m_opaque_sp->GetEnvironmentEntries().SetArguments(envp); |
| 158 | else |
| 159 | m_opaque_sp->GetEnvironmentEntries().Clear(); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void |
| 164 | SBLaunchInfo::Clear () |
| 165 | { |
| 166 | m_opaque_sp->Clear(); |
| 167 | } |
| 168 | |
| 169 | const char * |
| 170 | SBLaunchInfo::GetWorkingDirectory () const |
| 171 | { |
| 172 | return m_opaque_sp->GetWorkingDirectory(); |
| 173 | } |
| 174 | |
| 175 | void |
| 176 | SBLaunchInfo::SetWorkingDirectory (const char *working_dir) |
| 177 | { |
| 178 | m_opaque_sp->SetWorkingDirectory(working_dir); |
| 179 | } |
| 180 | |
| 181 | uint32_t |
| 182 | SBLaunchInfo::GetLaunchFlags () |
| 183 | { |
| 184 | return m_opaque_sp->GetFlags().Get(); |
| 185 | } |
| 186 | |
| 187 | void |
| 188 | SBLaunchInfo::SetLaunchFlags (uint32_t flags) |
| 189 | { |
| 190 | m_opaque_sp->GetFlags().Reset(flags); |
| 191 | } |
| 192 | |
| 193 | const char * |
| 194 | SBLaunchInfo::GetProcessPluginName () |
| 195 | { |
| 196 | return m_opaque_sp->GetProcessPluginName(); |
| 197 | } |
| 198 | |
| 199 | void |
| 200 | SBLaunchInfo::SetProcessPluginName (const char *plugin_name) |
| 201 | { |
| 202 | return m_opaque_sp->SetProcessPluginName (plugin_name); |
| 203 | } |
| 204 | |
| 205 | const char * |
| 206 | SBLaunchInfo::GetShell () |
| 207 | { |
| 208 | // Constify this string so that it is saved in the string pool. Otherwise |
| 209 | // it would be freed when this function goes out of scope. |
| 210 | ConstString shell(m_opaque_sp->GetShell().GetPath().c_str()); |
| 211 | return shell.AsCString(); |
| 212 | } |
| 213 | |
| 214 | void |
| 215 | SBLaunchInfo::SetShell (const char * path) |
| 216 | { |
| 217 | m_opaque_sp->SetShell (FileSpec(path, false)); |
| 218 | } |
| 219 | |
| 220 | uint32_t |
| 221 | SBLaunchInfo::GetResumeCount () |
| 222 | { |
| 223 | return m_opaque_sp->GetResumeCount(); |
| 224 | } |
| 225 | |
| 226 | void |
| 227 | SBLaunchInfo::SetResumeCount (uint32_t c) |
| 228 | { |
| 229 | m_opaque_sp->SetResumeCount (c); |
| 230 | } |
| 231 | |
| 232 | bool |
| 233 | SBLaunchInfo::AddCloseFileAction (int fd) |
| 234 | { |
| 235 | return m_opaque_sp->AppendCloseFileAction(fd); |
| 236 | } |
| 237 | |
| 238 | bool |
| 239 | SBLaunchInfo::AddDuplicateFileAction (int fd, int dup_fd) |
| 240 | { |
| 241 | return m_opaque_sp->AppendDuplicateFileAction(fd, dup_fd); |
| 242 | } |
| 243 | |
| 244 | bool |
| 245 | SBLaunchInfo::AddOpenFileAction (int fd, const char *path, bool read, bool write) |
| 246 | { |
| 247 | return m_opaque_sp->AppendOpenFileAction(fd, path, read, write); |
| 248 | } |
| 249 | |
| 250 | bool |
| 251 | SBLaunchInfo::AddSuppressFileAction (int fd, bool read, bool write) |
| 252 | { |
| 253 | return m_opaque_sp->AppendSuppressFileAction(fd, read, write); |
| 254 | } |
| 255 | |
| 256 | void |
| 257 | SBLaunchInfo::SetLaunchEventData (const char *data) |
| 258 | { |
| 259 | m_opaque_sp->SetLaunchEventData (data); |
| 260 | } |
| 261 | |
| 262 | const char * |
| 263 | SBLaunchInfo::GetLaunchEventData () const |
| 264 | { |
| 265 | return m_opaque_sp->GetLaunchEventData (); |
| 266 | } |
| 267 | |
| 268 | void |
| 269 | SBLaunchInfo::SetDetachOnError (bool enable) |
| 270 | { |
| 271 | m_opaque_sp->SetDetachOnError (enable); |
| 272 | } |
| 273 | |
| 274 | bool |
| 275 | SBLaunchInfo::GetDetachOnError () const |
| 276 | { |
| 277 | return m_opaque_sp->GetDetachOnError (); |
| 278 | } |