Todd Fiala | 6d6b55d | 2014-06-30 00:30:53 +0000 | [diff] [blame] | 1 | //===-- ProcessInfo.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 | |
Todd Fiala | 6d6b55d | 2014-06-30 00:30:53 +0000 | [diff] [blame] | 10 | // C Includes |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 11 | // C++ Includes |
| 12 | #include <climits> |
| 13 | |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Target/ProcessInfo.h" |
Todd Fiala | 6d6b55d | 2014-06-30 00:30:53 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
| 21 | ProcessInfo::ProcessInfo () : |
| 22 | m_executable (), |
| 23 | m_arguments (), |
| 24 | m_environment (), |
| 25 | m_uid (UINT32_MAX), |
| 26 | m_gid (UINT32_MAX), |
| 27 | m_arch(), |
| 28 | m_pid (LLDB_INVALID_PROCESS_ID) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | ProcessInfo::ProcessInfo (const char *name, const ArchSpec &arch, lldb::pid_t pid) : |
| 33 | m_executable (name, false), |
| 34 | m_arguments (), |
| 35 | m_environment(), |
| 36 | m_uid (UINT32_MAX), |
| 37 | m_gid (UINT32_MAX), |
| 38 | m_arch (arch), |
| 39 | m_pid (pid) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | ProcessInfo::Clear () |
| 45 | { |
| 46 | m_executable.Clear(); |
| 47 | m_arguments.Clear(); |
| 48 | m_environment.Clear(); |
| 49 | m_uid = UINT32_MAX; |
| 50 | m_gid = UINT32_MAX; |
| 51 | m_arch.Clear(); |
| 52 | m_pid = LLDB_INVALID_PROCESS_ID; |
| 53 | } |
| 54 | |
| 55 | const char * |
| 56 | ProcessInfo::GetName() const |
| 57 | { |
| 58 | return m_executable.GetFilename().GetCString(); |
| 59 | } |
| 60 | |
| 61 | size_t |
| 62 | ProcessInfo::GetNameLength() const |
| 63 | { |
| 64 | return m_executable.GetFilename().GetLength(); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | ProcessInfo::SetExecutableFile (const FileSpec &exe_file, bool add_exe_file_as_first_arg) |
| 69 | { |
| 70 | if (exe_file) |
| 71 | { |
| 72 | m_executable = exe_file; |
| 73 | if (add_exe_file_as_first_arg) |
| 74 | { |
| 75 | char filename[PATH_MAX]; |
| 76 | if (exe_file.GetPath(filename, sizeof(filename))) |
| 77 | m_arguments.InsertArgumentAtIndex (0, filename); |
| 78 | } |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | m_executable.Clear(); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | const char * |
| 87 | ProcessInfo::GetArg0 () const |
| 88 | { |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 89 | return (m_arg0.empty() ? nullptr : m_arg0.c_str()); |
Todd Fiala | 6d6b55d | 2014-06-30 00:30:53 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void |
| 93 | ProcessInfo::SetArg0 (const char *arg) |
| 94 | { |
| 95 | if (arg && arg[0]) |
| 96 | m_arg0 = arg; |
| 97 | else |
| 98 | m_arg0.clear(); |
| 99 | } |
| 100 | |
| 101 | void |
| 102 | ProcessInfo::SetArguments (char const **argv, bool first_arg_is_executable) |
| 103 | { |
| 104 | m_arguments.SetArguments (argv); |
| 105 | |
| 106 | // Is the first argument the executable? |
| 107 | if (first_arg_is_executable) |
| 108 | { |
| 109 | const char *first_arg = m_arguments.GetArgumentAtIndex (0); |
| 110 | if (first_arg) |
| 111 | { |
| 112 | // Yes the first argument is an executable, set it as the executable |
| 113 | // in the launch options. Don't resolve the file path as the path |
| 114 | // could be a remote platform path |
| 115 | const bool resolve = false; |
| 116 | m_executable.SetFile(first_arg, resolve); |
| 117 | } |
| 118 | } |
| 119 | } |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 120 | |
Todd Fiala | 6d6b55d | 2014-06-30 00:30:53 +0000 | [diff] [blame] | 121 | void |
| 122 | ProcessInfo::SetArguments (const Args& args, bool first_arg_is_executable) |
| 123 | { |
| 124 | // Copy all arguments |
| 125 | m_arguments = args; |
| 126 | |
| 127 | // Is the first argument the executable? |
| 128 | if (first_arg_is_executable) |
| 129 | { |
| 130 | const char *first_arg = m_arguments.GetArgumentAtIndex (0); |
| 131 | if (first_arg) |
| 132 | { |
| 133 | // Yes the first argument is an executable, set it as the executable |
| 134 | // in the launch options. Don't resolve the file path as the path |
| 135 | // could be a remote platform path |
| 136 | const bool resolve = false; |
| 137 | m_executable.SetFile(first_arg, resolve); |
| 138 | } |
| 139 | } |
| 140 | } |