Raphael Isemann | 8081428 | 2020-01-24 08:23:27 +0100 | [diff] [blame] | 1 | //===-- SBProcessInfo.cpp -------------------------------------------------===// |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/API/SBProcessInfo.h" |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 10 | #include "SBReproducerPrivate.h" |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 11 | #include "Utils.h" |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBFileSpec.h" |
Zachary Turner | 805e710 | 2019-03-04 21:51:03 +0000 | [diff] [blame] | 13 | #include "lldb/Utility/ProcessInfo.h" |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace lldb; |
| 16 | using namespace lldb_private; |
| 17 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 18 | SBProcessInfo::SBProcessInfo() : m_opaque_up() { |
| 19 | LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBProcessInfo); |
| 20 | } |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 21 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 22 | SBProcessInfo::SBProcessInfo(const SBProcessInfo &rhs) : m_opaque_up() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 23 | LLDB_RECORD_CONSTRUCTOR(SBProcessInfo, (const lldb::SBProcessInfo &), rhs); |
| 24 | |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 25 | m_opaque_up = clone(rhs.m_opaque_up); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Jonas Devlieghere | 866b7a6 | 2020-02-17 22:57:06 -0800 | [diff] [blame] | 28 | SBProcessInfo::~SBProcessInfo() = default; |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 29 | |
| 30 | SBProcessInfo &SBProcessInfo::operator=(const SBProcessInfo &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 31 | LLDB_RECORD_METHOD(lldb::SBProcessInfo &, |
| 32 | SBProcessInfo, operator=,(const lldb::SBProcessInfo &), |
| 33 | rhs); |
| 34 | |
Jonas Devlieghere | bd4bf82 | 2019-03-06 00:05:55 +0000 | [diff] [blame] | 35 | if (this != &rhs) |
| 36 | m_opaque_up = clone(rhs.m_opaque_up); |
Jonas Devlieghere | 306809f | 2019-04-03 21:31:22 +0000 | [diff] [blame] | 37 | return LLDB_RECORD_RESULT(*this); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | ProcessInstanceInfo &SBProcessInfo::ref() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 41 | if (m_opaque_up == nullptr) { |
Jonas Devlieghere | 1c0bbe4 | 2020-06-24 16:25:05 -0700 | [diff] [blame] | 42 | m_opaque_up = std::make_unique<ProcessInstanceInfo>(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 43 | } |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 44 | return *m_opaque_up; |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void SBProcessInfo::SetProcessInfo(const ProcessInstanceInfo &proc_info_ref) { |
| 48 | ref() = proc_info_ref; |
| 49 | } |
| 50 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 51 | bool SBProcessInfo::IsValid() const { |
| 52 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcessInfo, IsValid); |
Pavel Labath | 7f5237b | 2019-03-11 13:58:46 +0000 | [diff] [blame] | 53 | return this->operator bool(); |
| 54 | } |
| 55 | SBProcessInfo::operator bool() const { |
| 56 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBProcessInfo, operator bool); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 57 | |
| 58 | return m_opaque_up != nullptr; |
| 59 | } |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 60 | |
| 61 | const char *SBProcessInfo::GetName() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 62 | LLDB_RECORD_METHOD_NO_ARGS(const char *, SBProcessInfo, GetName); |
| 63 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 64 | const char *name = nullptr; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 65 | if (m_opaque_up) { |
| 66 | name = m_opaque_up->GetName(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 67 | } |
| 68 | return name; |
| 69 | } |
| 70 | |
| 71 | SBFileSpec SBProcessInfo::GetExecutableFile() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 72 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFileSpec, SBProcessInfo, |
| 73 | GetExecutableFile); |
| 74 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 75 | SBFileSpec file_spec; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 76 | if (m_opaque_up) { |
| 77 | file_spec.SetFileSpec(m_opaque_up->GetExecutableFile()); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 78 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 79 | return LLDB_RECORD_RESULT(file_spec); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | lldb::pid_t SBProcessInfo::GetProcessID() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 83 | LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcessInfo, GetProcessID); |
| 84 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 85 | lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 86 | if (m_opaque_up) { |
| 87 | proc_id = m_opaque_up->GetProcessID(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 88 | } |
| 89 | return proc_id; |
| 90 | } |
| 91 | |
| 92 | uint32_t SBProcessInfo::GetUserID() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 93 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetUserID); |
| 94 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 95 | uint32_t user_id = UINT32_MAX; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 96 | if (m_opaque_up) { |
| 97 | user_id = m_opaque_up->GetUserID(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 98 | } |
| 99 | return user_id; |
| 100 | } |
| 101 | |
| 102 | uint32_t SBProcessInfo::GetGroupID() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 103 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetGroupID); |
| 104 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 105 | uint32_t group_id = UINT32_MAX; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 106 | if (m_opaque_up) { |
| 107 | group_id = m_opaque_up->GetGroupID(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 108 | } |
| 109 | return group_id; |
| 110 | } |
| 111 | |
| 112 | bool SBProcessInfo::UserIDIsValid() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 113 | LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, UserIDIsValid); |
| 114 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 115 | bool is_valid = false; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 116 | if (m_opaque_up) { |
| 117 | is_valid = m_opaque_up->UserIDIsValid(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 118 | } |
| 119 | return is_valid; |
| 120 | } |
| 121 | |
| 122 | bool SBProcessInfo::GroupIDIsValid() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 123 | LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, GroupIDIsValid); |
| 124 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 125 | bool is_valid = false; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 126 | if (m_opaque_up) { |
| 127 | is_valid = m_opaque_up->GroupIDIsValid(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 128 | } |
| 129 | return is_valid; |
| 130 | } |
| 131 | |
| 132 | uint32_t SBProcessInfo::GetEffectiveUserID() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 133 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetEffectiveUserID); |
| 134 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 135 | uint32_t user_id = UINT32_MAX; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 136 | if (m_opaque_up) { |
| 137 | user_id = m_opaque_up->GetEffectiveUserID(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 138 | } |
| 139 | return user_id; |
| 140 | } |
| 141 | |
| 142 | uint32_t SBProcessInfo::GetEffectiveGroupID() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 143 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBProcessInfo, GetEffectiveGroupID); |
| 144 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 145 | uint32_t group_id = UINT32_MAX; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 146 | if (m_opaque_up) { |
| 147 | group_id = m_opaque_up->GetEffectiveGroupID(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 148 | } |
| 149 | return group_id; |
| 150 | } |
| 151 | |
| 152 | bool SBProcessInfo::EffectiveUserIDIsValid() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 153 | LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, EffectiveUserIDIsValid); |
| 154 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 155 | bool is_valid = false; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 156 | if (m_opaque_up) { |
| 157 | is_valid = m_opaque_up->EffectiveUserIDIsValid(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 158 | } |
| 159 | return is_valid; |
| 160 | } |
| 161 | |
| 162 | bool SBProcessInfo::EffectiveGroupIDIsValid() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 163 | LLDB_RECORD_METHOD_NO_ARGS(bool, SBProcessInfo, EffectiveGroupIDIsValid); |
| 164 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 165 | bool is_valid = false; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 166 | if (m_opaque_up) { |
| 167 | is_valid = m_opaque_up->EffectiveGroupIDIsValid(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 168 | } |
| 169 | return is_valid; |
| 170 | } |
| 171 | |
| 172 | lldb::pid_t SBProcessInfo::GetParentProcessID() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame] | 173 | LLDB_RECORD_METHOD_NO_ARGS(lldb::pid_t, SBProcessInfo, GetParentProcessID); |
| 174 | |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 175 | lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID; |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 176 | if (m_opaque_up) { |
| 177 | proc_id = m_opaque_up->GetParentProcessID(); |
Vadim Macagon | 141a626 | 2017-08-01 07:34:26 +0000 | [diff] [blame] | 178 | } |
| 179 | return proc_id; |
| 180 | } |
Michal Gorny | ae211ec | 2019-03-19 17:13:13 +0000 | [diff] [blame] | 181 | |
| 182 | namespace lldb_private { |
| 183 | namespace repro { |
| 184 | |
| 185 | template <> |
| 186 | void RegisterMethods<SBProcessInfo>(Registry &R) { |
| 187 | LLDB_REGISTER_CONSTRUCTOR(SBProcessInfo, ()); |
| 188 | LLDB_REGISTER_CONSTRUCTOR(SBProcessInfo, (const lldb::SBProcessInfo &)); |
| 189 | LLDB_REGISTER_METHOD( |
| 190 | lldb::SBProcessInfo &, |
| 191 | SBProcessInfo, operator=,(const lldb::SBProcessInfo &)); |
| 192 | LLDB_REGISTER_METHOD_CONST(bool, SBProcessInfo, IsValid, ()); |
| 193 | LLDB_REGISTER_METHOD_CONST(bool, SBProcessInfo, operator bool, ()); |
| 194 | LLDB_REGISTER_METHOD(const char *, SBProcessInfo, GetName, ()); |
| 195 | LLDB_REGISTER_METHOD(lldb::SBFileSpec, SBProcessInfo, GetExecutableFile, |
| 196 | ()); |
| 197 | LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetProcessID, ()); |
| 198 | LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetUserID, ()); |
| 199 | LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetGroupID, ()); |
| 200 | LLDB_REGISTER_METHOD(bool, SBProcessInfo, UserIDIsValid, ()); |
| 201 | LLDB_REGISTER_METHOD(bool, SBProcessInfo, GroupIDIsValid, ()); |
| 202 | LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetEffectiveUserID, ()); |
| 203 | LLDB_REGISTER_METHOD(uint32_t, SBProcessInfo, GetEffectiveGroupID, ()); |
| 204 | LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveUserIDIsValid, ()); |
| 205 | LLDB_REGISTER_METHOD(bool, SBProcessInfo, EffectiveGroupIDIsValid, ()); |
| 206 | LLDB_REGISTER_METHOD(lldb::pid_t, SBProcessInfo, GetParentProcessID, ()); |
| 207 | } |
| 208 | |
| 209 | } |
| 210 | } |