1 //===-- SBProcessInfo.cpp ---------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/API/SBProcessInfo.h"
10 
11 #include "lldb/API/SBFileSpec.h"
12 #include "lldb/Target/Process.h"
13 
14 using namespace lldb;
15 using namespace lldb_private;
16 
17 SBProcessInfo::SBProcessInfo() : m_opaque_up() {}
18 
19 SBProcessInfo::SBProcessInfo(const SBProcessInfo &rhs) : m_opaque_up() {
20   if (rhs.IsValid()) {
21     ref() = *rhs.m_opaque_up;
22   }
23 }
24 
25 SBProcessInfo::~SBProcessInfo() {}
26 
27 SBProcessInfo &SBProcessInfo::operator=(const SBProcessInfo &rhs) {
28   if (this != &rhs) {
29     if (rhs.IsValid())
30       ref() = *rhs.m_opaque_up;
31     else
32       m_opaque_up.reset();
33   }
34   return *this;
35 }
36 
37 ProcessInstanceInfo &SBProcessInfo::ref() {
38   if (m_opaque_up == nullptr) {
39     m_opaque_up.reset(new ProcessInstanceInfo());
40   }
41   return *m_opaque_up;
42 }
43 
44 void SBProcessInfo::SetProcessInfo(const ProcessInstanceInfo &proc_info_ref) {
45   ref() = proc_info_ref;
46 }
47 
48 bool SBProcessInfo::IsValid() const { return m_opaque_up != nullptr; }
49 
50 const char *SBProcessInfo::GetName() {
51   const char *name = nullptr;
52   if (m_opaque_up) {
53     name = m_opaque_up->GetName();
54   }
55   return name;
56 }
57 
58 SBFileSpec SBProcessInfo::GetExecutableFile() {
59   SBFileSpec file_spec;
60   if (m_opaque_up) {
61     file_spec.SetFileSpec(m_opaque_up->GetExecutableFile());
62   }
63   return file_spec;
64 }
65 
66 lldb::pid_t SBProcessInfo::GetProcessID() {
67   lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID;
68   if (m_opaque_up) {
69     proc_id = m_opaque_up->GetProcessID();
70   }
71   return proc_id;
72 }
73 
74 uint32_t SBProcessInfo::GetUserID() {
75   uint32_t user_id = UINT32_MAX;
76   if (m_opaque_up) {
77     user_id = m_opaque_up->GetUserID();
78   }
79   return user_id;
80 }
81 
82 uint32_t SBProcessInfo::GetGroupID() {
83   uint32_t group_id = UINT32_MAX;
84   if (m_opaque_up) {
85     group_id = m_opaque_up->GetGroupID();
86   }
87   return group_id;
88 }
89 
90 bool SBProcessInfo::UserIDIsValid() {
91   bool is_valid = false;
92   if (m_opaque_up) {
93     is_valid = m_opaque_up->UserIDIsValid();
94   }
95   return is_valid;
96 }
97 
98 bool SBProcessInfo::GroupIDIsValid() {
99   bool is_valid = false;
100   if (m_opaque_up) {
101     is_valid = m_opaque_up->GroupIDIsValid();
102   }
103   return is_valid;
104 }
105 
106 uint32_t SBProcessInfo::GetEffectiveUserID() {
107   uint32_t user_id = UINT32_MAX;
108   if (m_opaque_up) {
109     user_id = m_opaque_up->GetEffectiveUserID();
110   }
111   return user_id;
112 }
113 
114 uint32_t SBProcessInfo::GetEffectiveGroupID() {
115   uint32_t group_id = UINT32_MAX;
116   if (m_opaque_up) {
117     group_id = m_opaque_up->GetEffectiveGroupID();
118   }
119   return group_id;
120 }
121 
122 bool SBProcessInfo::EffectiveUserIDIsValid() {
123   bool is_valid = false;
124   if (m_opaque_up) {
125     is_valid = m_opaque_up->EffectiveUserIDIsValid();
126   }
127   return is_valid;
128 }
129 
130 bool SBProcessInfo::EffectiveGroupIDIsValid() {
131   bool is_valid = false;
132   if (m_opaque_up) {
133     is_valid = m_opaque_up->EffectiveGroupIDIsValid();
134   }
135   return is_valid;
136 }
137 
138 lldb::pid_t SBProcessInfo::GetParentProcessID() {
139   lldb::pid_t proc_id = LLDB_INVALID_PROCESS_ID;
140   if (m_opaque_up) {
141     proc_id = m_opaque_up->GetParentProcessID();
142   }
143   return proc_id;
144 }
145