LLDB  mainline
PlatformiOSSimulatorCoreSimulatorSupport.h
Go to the documentation of this file.
1 //===-- PlatformiOSSimulatorCoreSimulatorSupport.h ----------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_OBJCXX_PLATFORMIOSSIMULATORCORESIMULATORSUPPORT_H
11 #define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_OBJCXX_PLATFORMIOSSIMULATORCORESIMULATORSUPPORT_H
12 
13 #include <functional>
14 #include <ostream>
15 #include <string>
16 #include <vector>
17 #ifdef __APPLE__
18 #include <objc/objc.h>
19 #else
20 typedef void *id;
21 #endif
23 #include "lldb/Utility/Args.h"
25 #include "lldb/Utility/Status.h"
26 
27 #include "llvm/ADT/Optional.h"
28 
29 // And now the actual magic
31 class Process {
32 public:
33  lldb::pid_t GetPID() { return m_pid; }
34 
35  explicit operator bool() { return m_pid != LLDB_INVALID_PROCESS_ID; }
36 
38 
39 private:
41 
43 
45 
48 
49  friend class Device;
50 };
51 
53 public:
54  ModelIdentifier(const std::string &mi);
56 
57  explicit operator bool() const { return !m_versions.empty(); }
58 
59  size_t GetNumVersions() const { return m_versions.size(); }
60 
61  unsigned int GetVersionAtIndex(size_t idx) const { return m_versions[idx]; }
62 
63  std::string GetFamily() const { return m_family.c_str(); }
64 
65 private:
67  std::vector<unsigned int> m_versions;
68 };
69 
70 class DeviceType {
71 public:
72  enum class ProductFamilyID : int32_t {
73  iPhone = 1,
74  iPad = 2,
75  appleTV = 3,
76  appleWatch = 4
77  };
78 
79  DeviceType();
80 
81  DeviceType(id d);
82 
83  explicit operator bool();
84 
86 
88 
90 
92 
94 
95 private:
96  id m_dev;
97  llvm::Optional<ModelIdentifier> m_model_identifier;
98 };
99 
100 class OSVersion {
101 public:
102  OSVersion(const std::string &ver, const std::string &build);
103 
104  OSVersion();
105 
106  explicit operator bool() const { return !m_versions.empty(); }
107 
108  size_t GetNumVersions() const { return m_versions.size(); }
109 
110  unsigned int GetVersionAtIndex(size_t idx) const { return m_versions[idx]; }
111 
112  const char *GetBuild() const { return m_build.c_str(); }
113 
114 private:
115  std::vector<unsigned int> m_versions;
117 };
118 
120 public:
121  DeviceRuntime();
122 
123  DeviceRuntime(id d);
124 
125  explicit operator bool();
126 
128 
129  bool IsAvailable();
130 
131 private:
132  id m_dev;
133  llvm::Optional<OSVersion> m_os_version;
134 };
135 
136 class Device {
137 private:
138  typedef unsigned long int NSUInteger;
139 
140 public:
141  enum class State : NSUInteger {
142  Creating,
143  Shutdown,
144  Booting,
145  Booted,
147  };
148 
149  Device();
150 
151  Device(id d);
152 
153  explicit operator bool();
154 
155  std::string GetName() const;
156 
158 
160 
161  State GetState();
162 
163  bool Boot(lldb_private::Status &err);
164 
165  bool Shutdown(lldb_private::Status &err);
166 
167  std::string GetUDID() const;
168 
170 
171 private:
172  id m_dev;
173  llvm::Optional<DeviceType> m_dev_type;
174  llvm::Optional<DeviceRuntime> m_dev_runtime;
175 
176  friend class DeviceSet;
177 };
178 
179 bool operator>(const OSVersion &lhs, const OSVersion &rhs);
180 
181 bool operator>(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
182 
183 bool operator<(const OSVersion &lhs, const OSVersion &rhs);
184 
185 bool operator<(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
186 
187 bool operator==(const OSVersion &lhs, const OSVersion &rhs);
188 
189 bool operator==(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
190 
191 bool operator!=(const OSVersion &lhs, const OSVersion &rhs);
192 
193 bool operator!=(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
194 
195 class DeviceSet {
196 public:
197  static DeviceSet GetAllDevices(const char *developer_dir);
198 
199  static DeviceSet GetAvailableDevices(const char *developer_dir);
200 
201  size_t GetNumDevices();
202 
203  Device GetDeviceAtIndex(size_t idx);
204 
205  void ForEach(std::function<bool(const Device &)> f);
206 
207  DeviceSet GetDevicesIf(std::function<bool(Device)> f);
208 
210 
212 
213 private:
214  DeviceSet(id arr) : m_dev(arr) {}
215 
216  id m_dev;
217 };
218 }
219 
220 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_OBJCXX_PLATFORMIOSSIMULATORCORESIMULATORSUPPORT_H
CoreSimulatorSupport::operator<
bool operator<(const OSVersion &lhs, const OSVersion &rhs)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:267
CoreSimulatorSupport::OSVersion::GetVersionAtIndex
unsigned int GetVersionAtIndex(size_t idx) const
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:110
CoreSimulatorSupport::ModelIdentifier::ModelIdentifier
ModelIdentifier()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:147
CoreSimulatorSupport::Device::GetName
std::string GetName() const
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:210
CoreSimulatorSupport::Device::GetDeviceType
DeviceType GetDeviceType()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:225
CoreSimulatorSupport::Device::State::Creating
@ Creating
CoreSimulatorSupport::DeviceType::GetProductFamily
lldb_private::ConstString GetProductFamily()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:81
CoreSimulatorSupport::ModelIdentifier
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:52
CoreSimulatorSupport::OSVersion::m_build
std::string m_build
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:116
LLDB_INVALID_PROCESS_ID
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:92
CoreSimulatorSupport::DeviceSet::ForEach
void ForEach(std::function< bool(const Device &)> f)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:593
CoreSimulatorSupport::ModelIdentifier::GetNumVersions
size_t GetNumVersions() const
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:59
CoreSimulatorSupport::OSVersion::GetNumVersions
size_t GetNumVersions() const
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:108
CoreSimulatorSupport::ModelIdentifier::m_versions
std::vector< unsigned int > m_versions
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:67
CoreSimulatorSupport::operator!=
bool operator!=(const OSVersion &lhs, const OSVersion &rhs)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:321
ProcessLaunchInfo.h
CoreSimulatorSupport::Device::Spawn
Process Spawn(lldb_private::ProcessLaunchInfo &launch_info)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:451
CoreSimulatorSupport::operator==
bool operator==(const OSVersion &lhs, const OSVersion &rhs)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:294
CoreSimulatorSupport::Process::m_error
lldb_private::Status m_error
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:47
CoreSimulatorSupport::Device::State::Shutdown
@ Shutdown
CoreSimulatorSupport::DeviceType::GetProductFamilyID
ProductFamilyID GetProductFamilyID()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:86
CoreSimulatorSupport::DeviceRuntime::m_dev
id m_dev
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:132
CoreSimulatorSupport::DeviceSet::GetNumDevices
size_t GetNumDevices()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:570
CoreSimulatorSupport::DeviceRuntime::DeviceRuntime
DeviceRuntime()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:90
CoreSimulatorSupport::Process::GetError
lldb_private::Status GetError()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:37
CoreSimulatorSupport::Device::Shutdown
bool Shutdown(lldb_private::Status &err)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:372
CoreSimulatorSupport::DeviceType::ProductFamilyID::appleWatch
@ appleWatch
CoreSimulatorSupport::Device::Device
Device()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:102
CoreSimulatorSupport
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:30
CoreSimulatorSupport::Device::GetState
State GetState()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:110
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone
@ iPhone
CoreSimulatorSupport::DeviceSet::GetFanciest
Device GetFanciest(DeviceType::ProductFamilyID dev_id)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:616
CoreSimulatorSupport::Device::NSUInteger
unsigned long int NSUInteger
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:138
CoreSimulatorSupport::Device::GetDeviceRuntime
DeviceRuntime GetDeviceRuntime()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:233
lldb_private::ProcessLaunchInfo
Definition: ProcessLaunchInfo.h:31
Args.h
CoreSimulatorSupport::DeviceType::GetModelIdentifier
ModelIdentifier GetModelIdentifier()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:174
CoreSimulatorSupport::DeviceType::GetIdentifier
lldb_private::ConstString GetIdentifier()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:77
CoreSimulatorSupport::Device::m_dev_type
llvm::Optional< DeviceType > m_dev_type
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:173
CoreSimulatorSupport::DeviceSet::m_dev
id m_dev
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:216
CoreSimulatorSupport::DeviceType::GetName
std::string GetName()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:203
CoreSimulatorSupport::OSVersion::OSVersion
OSVersion()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:171
lldb_private::ConstString
Definition: ConstString.h:40
CoreSimulatorSupport::DeviceSet::GetDeviceAtIndex
Device GetDeviceAtIndex(size_t idx)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:575
CoreSimulatorSupport::DeviceType::ProductFamilyID::iPad
@ iPad
CoreSimulatorSupport::Device::GetUDID
std::string GetUDID() const
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:217
CoreSimulatorSupport::operator>
bool operator>(const OSVersion &lhs, const OSVersion &rhs)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:241
CoreSimulatorSupport::ModelIdentifier::GetFamily
std::string GetFamily() const
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:63
CoreSimulatorSupport::DeviceRuntime::m_os_version
llvm::Optional< OSVersion > m_os_version
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:133
CoreSimulatorSupport::OSVersion::GetBuild
const char * GetBuild() const
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:112
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
CoreSimulatorSupport::OSVersion::m_versions
std::vector< unsigned int > m_versions
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:115
CoreSimulatorSupport::DeviceSet::GetDevicesIf
DeviceSet GetDevicesIf(std::function< bool(Device)> f)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:581
CoreSimulatorSupport::Device::State
State
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:141
CoreSimulatorSupport::Process
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:31
CoreSimulatorSupport::DeviceType::m_model_identifier
llvm::Optional< ModelIdentifier > m_model_identifier
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:97
CoreSimulatorSupport::OSVersion
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:100
CoreSimulatorSupport::DeviceType
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:70
CoreSimulatorSupport::DeviceType::ProductFamilyID::appleTV
@ appleTV
CoreSimulatorSupport::DeviceSet::DeviceSet
DeviceSet(id arr)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:214
CoreSimulatorSupport::Process::m_pid
lldb::pid_t m_pid
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:46
lldb_private::Status
Definition: Status.h:44
CoreSimulatorSupport::DeviceRuntime::GetVersion
OSVersion GetVersion()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:188
CoreSimulatorSupport::DeviceRuntime::IsAvailable
bool IsAvailable()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:98
CoreSimulatorSupport::DeviceSet::GetDevices
DeviceSet GetDevices(DeviceType::ProductFamilyID dev_id)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:602
CoreSimulatorSupport::DeviceSet::GetAvailableDevices
static DeviceSet GetAvailableDevices(const char *developer_dir)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:562
id
void * id
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:20
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
CoreSimulatorSupport::DeviceType::ProductFamilyID
ProductFamilyID
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:72
CoreSimulatorSupport::Device::Boot
bool Boot(lldb_private::Status &err)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:347
CoreSimulatorSupport::Device
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:136
CoreSimulatorSupport::Device::State::Booted
@ Booted
CoreSimulatorSupport::Device::m_dev
id m_dev
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:172
CoreSimulatorSupport::Process::Process
Process(lldb::pid_t p)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:61
Status.h
CoreSimulatorSupport::ModelIdentifier::m_family
std::string m_family
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:66
CoreSimulatorSupport::Device::m_dev_runtime
llvm::Optional< DeviceRuntime > m_dev_runtime
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:174
CoreSimulatorSupport::Device::State::ShuttingDown
@ ShuttingDown
CoreSimulatorSupport::DeviceType::m_dev
id m_dev
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:96
ConstString.h
CoreSimulatorSupport::ModelIdentifier::GetVersionAtIndex
unsigned int GetVersionAtIndex(size_t idx) const
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:61
CoreSimulatorSupport::DeviceSet::GetAllDevices
static DeviceSet GetAllDevices(const char *developer_dir)
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:544
CoreSimulatorSupport::DeviceRuntime
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:119
CoreSimulatorSupport::Device::State::Booting
@ Booting
CoreSimulatorSupport::DeviceType::DeviceType
DeviceType()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.mm:69
CoreSimulatorSupport::Process::GetPID
lldb::pid_t GetPID()
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:33
CoreSimulatorSupport::DeviceSet
Definition: PlatformiOSSimulatorCoreSimulatorSupport.h:195