LLDB  mainline
ProcessInfo.h
Go to the documentation of this file.
1 //===-- ProcessInfo.h -------------------------------------------*- 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 #ifndef LLDB_UTILITY_PROCESSINFO_H
10 #define LLDB_UTILITY_PROCESSINFO_H
11 
12 #include "lldb/Utility/ArchSpec.h"
13 #include "lldb/Utility/Args.h"
15 #include "lldb/Utility/FileSpec.h"
17 #include "llvm/Support/YAMLTraits.h"
18 #include <vector>
19 
20 namespace lldb_private {
21 
22 class UserIDResolver;
23 
24 // ProcessInfo
25 //
26 // A base class for information for a process. This can be used to fill
27 // out information for a process prior to launching it, or it can be used for
28 // an instance of a process and can be filled in with the existing values for
29 // that process.
30 class ProcessInfo {
31 public:
32  ProcessInfo();
33 
34  ProcessInfo(const char *name, const ArchSpec &arch, lldb::pid_t pid);
35 
36  void Clear();
37 
38  const char *GetName() const;
39 
40  llvm::StringRef GetNameAsStringRef() const;
41 
43 
44  void SetExecutableFile(const FileSpec &exe_file,
45  bool add_exe_file_as_first_arg);
46 
47  const FileSpec &GetExecutableFile() const { return m_executable; }
48 
49  uint32_t GetUserID() const { return m_uid; }
50 
51  uint32_t GetGroupID() const { return m_gid; }
52 
53  bool UserIDIsValid() const { return m_uid != UINT32_MAX; }
54 
55  bool GroupIDIsValid() const { return m_gid != UINT32_MAX; }
56 
57  void SetUserID(uint32_t uid) { m_uid = uid; }
58 
59  void SetGroupID(uint32_t gid) { m_gid = gid; }
60 
62 
63  const ArchSpec &GetArchitecture() const { return m_arch; }
64 
65  void SetArchitecture(const ArchSpec &arch) { m_arch = arch; }
66 
67  lldb::pid_t GetProcessID() const { return m_pid; }
68 
69  void SetProcessID(lldb::pid_t pid) { m_pid = pid; }
70 
71  bool ProcessIDIsValid() const { return m_pid != LLDB_INVALID_PROCESS_ID; }
72 
73  void Dump(Stream &s, Platform *platform) const;
74 
75  Args &GetArguments() { return m_arguments; }
76 
77  const Args &GetArguments() const { return m_arguments; }
78 
79  llvm::StringRef GetArg0() const;
80 
81  void SetArg0(llvm::StringRef arg);
82 
83  void SetArguments(const Args &args, bool first_arg_is_executable);
84 
85  void SetArguments(char const **argv, bool first_arg_is_executable);
86 
88  const Environment &GetEnvironment() const { return m_environment; }
89 
90 protected:
91  template <class T> friend struct llvm::yaml::MappingTraits;
93  std::string m_arg0; // argv[0] if supported. If empty, then use m_executable.
94  // Not all process plug-ins support specifying an argv[0] that differs from
95  // the resolved platform executable (which is in m_executable)
96  Args m_arguments; // All program arguments except argv[0]
102 };
103 
104 // ProcessInstanceInfo
105 //
106 // Describes an existing process and any discoverable information that pertains
107 // to that process.
109 public:
111 
112  ProcessInstanceInfo(const char *name, const ArchSpec &arch, lldb::pid_t pid)
113  : ProcessInfo(name, arch, pid), m_euid(UINT32_MAX), m_egid(UINT32_MAX),
115 
116  void Clear() {
118  m_euid = UINT32_MAX;
119  m_egid = UINT32_MAX;
121  }
122 
123  uint32_t GetEffectiveUserID() const { return m_euid; }
124 
125  uint32_t GetEffectiveGroupID() const { return m_egid; }
126 
127  bool EffectiveUserIDIsValid() const { return m_euid != UINT32_MAX; }
128 
129  bool EffectiveGroupIDIsValid() const { return m_egid != UINT32_MAX; }
130 
131  void SetEffectiveUserID(uint32_t uid) { m_euid = uid; }
132 
133  void SetEffectiveGroupID(uint32_t gid) { m_egid = gid; }
134 
136 
138 
139  bool ParentProcessIDIsValid() const {
141  }
142 
143  void Dump(Stream &s, UserIDResolver &resolver) const;
144 
145  static void DumpTableHeader(Stream &s, bool show_args, bool verbose);
146 
147  void DumpAsTableRow(Stream &s, UserIDResolver &resolver, bool show_args,
148  bool verbose) const;
149 
150 protected:
151  friend struct llvm::yaml::MappingTraits<ProcessInstanceInfo>;
155 };
156 
157 typedef std::vector<ProcessInstanceInfo> ProcessInstanceInfoList;
158 
159 // ProcessInstanceInfoMatch
160 //
161 // A class to help matching one ProcessInstanceInfo to another.
162 
164 public:
166 
167  ProcessInstanceInfoMatch(const char *process_name,
168  NameMatch process_name_match_type)
169  : m_match_info(), m_name_match_type(process_name_match_type),
170  m_match_all_users(false) {
171  m_match_info.GetExecutableFile().SetFile(process_name,
172  FileSpec::Style::native);
173  }
174 
176 
178 
179  bool GetMatchAllUsers() const { return m_match_all_users; }
180 
181  void SetMatchAllUsers(bool b) { m_match_all_users = b; }
182 
184 
185  void SetNameMatchType(NameMatch name_match_type) {
186  m_name_match_type = name_match_type;
187  }
188 
189  /// Return true iff the architecture in this object matches arch_spec.
190  bool ArchitectureMatches(const ArchSpec &arch_spec) const;
191 
192  /// Return true iff the process name in this object matches process_name.
193  bool NameMatches(const char *process_name) const;
194 
195  /// Return true iff the process ID and parent process IDs in this object match
196  /// the ones in proc_info.
197  bool ProcessIDsMatch(const ProcessInstanceInfo &proc_info) const;
198 
199  /// Return true iff the (both effective and real) user and group IDs in this
200  /// object match the ones in proc_info.
201  bool UserIDsMatch(const ProcessInstanceInfo &proc_info) const;
202 
203  bool Matches(const ProcessInstanceInfo &proc_info) const;
204 
205  bool MatchAllProcesses() const;
206  void Clear();
207 
208 protected:
211  bool m_match_all_users = false;
212 };
213 
214 namespace repro {
215 llvm::Optional<ProcessInstanceInfoList> GetReplayProcessInstanceInfoList();
216 } // namespace repro
217 } // namespace lldb_private
218 
219 LLVM_YAML_IS_SEQUENCE_VECTOR(lldb_private::ProcessInstanceInfo)
220 
221 namespace llvm {
222 namespace yaml {
223 template <> struct MappingTraits<lldb_private::ProcessInstanceInfo> {
224  static void mapping(IO &io, lldb_private::ProcessInstanceInfo &PII);
225 };
226 } // namespace yaml
227 } // namespace llvm
228 
229 #endif // LLDB_UTILITY_PROCESSINFO_H
lldb_private::ProcessInfo::GetArguments
Args & GetArguments()
Definition: ProcessInfo.h:75
lldb_private::ProcessInstanceInfo
Definition: ProcessInfo.h:108
lldb_private::ProcessInstanceInfoMatch::SetNameMatchType
void SetNameMatchType(NameMatch name_match_type)
Definition: ProcessInfo.h:185
lldb_private::ProcessInstanceInfoMatch::m_name_match_type
NameMatch m_name_match_type
Definition: ProcessInfo.h:210
lldb_private::ProcessInfo::m_uid
uint32_t m_uid
Definition: ProcessInfo.h:98
llvm
Definition: Debugger.h:49
lldb_private::ProcessInfo::GetEnvironment
const Environment & GetEnvironment() const
Definition: ProcessInfo.h:88
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ProcessInfo::ProcessIDIsValid
bool ProcessIDIsValid() const
Definition: ProcessInfo.h:71
lldb_private::ProcessInfo::SetExecutableFile
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
Definition: ProcessInfo.cpp:62
lldb_private::ProcessInstanceInfoMatch::GetMatchAllUsers
bool GetMatchAllUsers() const
Definition: ProcessInfo.h:179
lldb_private::ProcessInfo::SetArchitecture
void SetArchitecture(const ArchSpec &arch)
Definition: ProcessInfo.h:65
LLDB_INVALID_PROCESS_ID
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:93
lldb_private::ProcessInfo::MappingTraits
friend struct llvm::yaml::MappingTraits
Definition: ProcessInfo.h:91
lldb_private::ProcessInfo::m_executable
FileSpec m_executable
Definition: ProcessInfo.h:92
lldb_private::ProcessInstanceInfo::Clear
void Clear()
Definition: ProcessInfo.h:116
lldb_private::ProcessInstanceInfoMatch::NameMatches
bool NameMatches(const char *process_name) const
Return true iff the process name in this object matches process_name.
Definition: ProcessInfo.cpp:251
lldb_private::ProcessInstanceInfoMatch::GetProcessInfo
const ProcessInstanceInfo & GetProcessInfo() const
Definition: ProcessInfo.h:177
lldb_private::ProcessInfo::m_arch
ArchSpec m_arch
Definition: ProcessInfo.h:100
lldb_private::ProcessInfo::GetGroupID
uint32_t GetGroupID() const
Definition: ProcessInfo.h:51
lldb_private::ProcessInstanceInfoMatch::SetMatchAllUsers
void SetMatchAllUsers(bool b)
Definition: ProcessInfo.h:181
lldb_private::ProcessInfo::GetUserID
uint32_t GetUserID() const
Definition: ProcessInfo.h:49
lldb_private::ProcessInstanceInfo::ProcessInstanceInfo
ProcessInstanceInfo()
Definition: ProcessInfo.h:110
lldb_private::repro::GetReplayProcessInstanceInfoList
llvm::Optional< ProcessInstanceInfoList > GetReplayProcessInstanceInfoList()
Definition: ProcessInfo.cpp:352
lldb_private::ProcessInstanceInfoMatch::ArchitectureMatches
bool ArchitectureMatches(const ArchSpec &arch_spec) const
Return true iff the architecture in this object matches arch_spec.
Definition: ProcessInfo.cpp:245
lldb_private::ProcessInstanceInfo::GetEffectiveGroupID
uint32_t GetEffectiveGroupID() const
Definition: ProcessInfo.h:125
lldb_private::ProcessInstanceInfoMatch::Clear
void Clear()
Definition: ProcessInfo.cpp:330
lldb_private::ProcessInfo::SetUserID
void SetUserID(uint32_t uid)
Definition: ProcessInfo.h:57
lldb_private::ProcessInstanceInfoMatch
Definition: ProcessInfo.h:163
lldb_private::ProcessInstanceInfo::m_euid
uint32_t m_euid
Definition: ProcessInfo.h:152
lldb_private::ProcessInstanceInfo::m_egid
uint32_t m_egid
Definition: ProcessInfo.h:153
lldb_private::ProcessInfo::GetProcessID
lldb::pid_t GetProcessID() const
Definition: ProcessInfo.h:67
lldb_private::ProcessInfo::SetProcessID
void SetProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:69
lldb_private::ProcessInstanceInfo::SetEffectiveUserID
void SetEffectiveUserID(uint32_t uid)
Definition: ProcessInfo.h:131
lldb_private::Stream
Definition: Stream.h:28
lldb_private::Args
Definition: Args.h:33
lldb_private::ProcessInstanceInfo::EffectiveUserIDIsValid
bool EffectiveUserIDIsValid() const
Definition: ProcessInfo.h:127
lldb_private::ProcessInstanceInfo::m_parent_pid
lldb::pid_t m_parent_pid
Definition: ProcessInfo.h:154
lldb_private::ProcessInfo::GetExecutableFile
const FileSpec & GetExecutableFile() const
Definition: ProcessInfo.h:47
lldb_private::ProcessInfo::UserIDIsValid
bool UserIDIsValid() const
Definition: ProcessInfo.h:53
lldb_private::ProcessInstanceInfoMatch::Matches
bool Matches(const ProcessInstanceInfo &proc_info) const
Definition: ProcessInfo.cpp:292
lldb_private::NameMatch
NameMatch
Definition: NameMatches.h:15
lldb_private::ProcessInstanceInfo::DumpTableHeader
static void DumpTableHeader(Stream &s, bool show_args, bool verbose)
Definition: ProcessInfo.cpp:163
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::ProcessInfo::m_arguments
Args m_arguments
Definition: ProcessInfo.h:96
lldb_private::ProcessInfo::Clear
void Clear()
Definition: ProcessInfo.cpp:32
lldb_private::ProcessInstanceInfo::GetEffectiveUserID
uint32_t GetEffectiveUserID() const
Definition: ProcessInfo.h:123
Args.h
lldb_private::ProcessInfo
Definition: ProcessInfo.h:30
lldb_private::ProcessInstanceInfo::SetEffectiveGroupID
void SetEffectiveGroupID(uint32_t gid)
Definition: ProcessInfo.h:133
lldb_private::ProcessInfo::ProcessInfo
ProcessInfo()
Definition: ProcessInfo.cpp:24
lldb_private::ProcessInfo::GroupIDIsValid
bool GroupIDIsValid() const
Definition: ProcessInfo.h:55
NameMatches.h
lldb_private::ProcessInfo::SetArg0
void SetArg0(llvm::StringRef arg)
Definition: ProcessInfo.cpp:79
lldb_private::ProcessInstanceInfoMatch::GetProcessInfo
ProcessInstanceInfo & GetProcessInfo()
Definition: ProcessInfo.h:175
lldb_private::ProcessInstanceInfoMatch::MatchAllProcesses
bool MatchAllProcesses() const
Definition: ProcessInfo.cpp:299
lldb_private::ProcessInstanceInfo::ParentProcessIDIsValid
bool ParentProcessIDIsValid() const
Definition: ProcessInfo.h:139
lldb_private::ProcessInfo::GetName
const char * GetName() const
Definition: ProcessInfo.cpp:42
lldb_private::ProcessInstanceInfoMatch::ProcessInstanceInfoMatch
ProcessInstanceInfoMatch()
Definition: ProcessInfo.h:165
lldb_private::ProcessInfo::m_pid
lldb::pid_t m_pid
Definition: ProcessInfo.h:101
lldb_private::ProcessInfo::GetNameAsStringRef
llvm::StringRef GetNameAsStringRef() const
Definition: ProcessInfo.cpp:46
lldb_private::ProcessInstanceInfoMatch::m_match_all_users
bool m_match_all_users
Definition: ProcessInfo.h:211
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
lldb_private::ProcessInfo::m_environment
Environment m_environment
Definition: ProcessInfo.h:97
lldb_private::ProcessInfo::m_gid
uint32_t m_gid
Definition: ProcessInfo.h:99
lldb_private::ProcessInstanceInfo::EffectiveGroupIDIsValid
bool EffectiveGroupIDIsValid() const
Definition: ProcessInfo.h:129
lldb_private::ProcessInstanceInfoMatch::GetNameMatchType
NameMatch GetNameMatchType() const
Definition: ProcessInfo.h:183
lldb_private::UserIDResolver
An abstract interface for things that know how to map numeric user/group IDs into names.
Definition: UserIDResolver.h:22
lldb_private::ProcessInstanceInfo::GetParentProcessID
lldb::pid_t GetParentProcessID() const
Definition: ProcessInfo.h:135
lldb_private::ProcessInstanceInfoMatch::UserIDsMatch
bool UserIDsMatch(const ProcessInstanceInfo &proc_info) const
Return true iff the (both effective and real) user and group IDs in this object match the ones in pro...
Definition: ProcessInfo.cpp:273
uint32_t
lldb_private::ProcessInfo::GetEnvironment
Environment & GetEnvironment()
Definition: ProcessInfo.h:87
lldb_private::ProcessInstanceInfoMatch::m_match_info
ProcessInstanceInfo m_match_info
Definition: ProcessInfo.h:209
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::NameMatch::Ignore
@ Ignore
lldb_private::ProcessInstanceInfo::Dump
void Dump(Stream &s, UserIDResolver &resolver) const
Definition: ProcessInfo.cpp:113
ArchSpec.h
UINT32_MAX
#define UINT32_MAX
Definition: lldb-defines.h:31
lldb_private::Environment
Definition: Environment.h:18
lldb_private::ProcessInstanceInfoMatch::ProcessInstanceInfoMatch
ProcessInstanceInfoMatch(const char *process_name, NameMatch process_name_match_type)
Definition: ProcessInfo.h:167
lldb_private::ProcessInfo::m_arg0
std::string m_arg0
Definition: ProcessInfo.h:93
lldb_private::Platform
Definition: Platform.h:72
lldb_private::ProcessInstanceInfo::DumpAsTableRow
void DumpAsTableRow(Stream &s, UserIDResolver &resolver, bool show_args, bool verbose) const
Definition: ProcessInfo.cpp:186
Environment.h
lldb_private::ProcessInfo::GetArchitecture
ArchSpec & GetArchitecture()
Definition: ProcessInfo.h:61
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ProcessInfo::GetArchitecture
const ArchSpec & GetArchitecture() const
Definition: ProcessInfo.h:63
lldb_private::ProcessInfo::GetExecutableFile
FileSpec & GetExecutableFile()
Definition: ProcessInfo.h:42
FileSpec.h
lldb_private::ProcessInstanceInfo::ProcessInstanceInfo
ProcessInstanceInfo(const char *name, const ArchSpec &arch, lldb::pid_t pid)
Definition: ProcessInfo.h:112
lldb_private::ProcessInfo::GetArg0
llvm::StringRef GetArg0() const
Definition: ProcessInfo.cpp:77
lldb_private::FileSpec::SetFile
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:174
lldb_private::ProcessInfo::GetArguments
const Args & GetArguments() const
Definition: ProcessInfo.h:77
lldb_private::ProcessInfo::Dump
void Dump(Stream &s, Platform *platform) const
Definition: ProcessInfo.cpp:50
lldb_private::ProcessInstanceInfoList
std::vector< ProcessInstanceInfo > ProcessInstanceInfoList
Definition: Host.h:30
lldb_private::ProcessInstanceInfoMatch::ProcessIDsMatch
bool ProcessIDsMatch(const ProcessInstanceInfo &proc_info) const
Return true iff the process ID and parent process IDs in this object match the ones in proc_info.
Definition: ProcessInfo.cpp:261
lldb_private::ProcessInstanceInfo::SetParentProcessID
void SetParentProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:137
lldb_private::ProcessInfo::SetArguments
void SetArguments(const Args &args, bool first_arg_is_executable)
Definition: ProcessInfo.cpp:97
lldb_private::ProcessInfo::SetGroupID
void SetGroupID(uint32_t gid)
Definition: ProcessInfo.h:59