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 <optional>
15#include <ostream>
16#include <string>
17#include <vector>
18#ifdef __APPLE__
19#include <objc/objc.h>
20#else
21typedef void *id;
22#endif
24#include "lldb/Utility/Args.h"
26#include "lldb/Utility/Status.h"
27
28
29// And now the actual magic
31class Process {
32public:
33 lldb::pid_t GetPID() { return m_pid; }
34
35 explicit operator bool() { return m_pid != LLDB_INVALID_PROCESS_ID; }
36
38
39private:
41
43
45
48
49 friend class Device;
50};
51
53public:
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
65private:
66 std::string m_family;
67 std::vector<unsigned int> m_versions;
68};
69
71public:
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
85 std::string GetName();
86
88
90
92
94
95private:
96 id m_dev = nullptr;
97 std::optional<ModelIdentifier> m_model_identifier;
98};
99
101public:
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
114private:
115 std::vector<unsigned int> m_versions;
116 std::string m_build;
117};
118
120public:
122
123 DeviceRuntime(id d);
124
125 explicit operator bool();
126
128
129 bool IsAvailable();
130
131private:
132 id m_dev = nullptr;
133 std::optional<OSVersion> m_os_version;
134};
135
136class Device {
137private:
138 typedef unsigned long int NSUInteger;
139
140public:
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
166
167 std::string GetUDID() const;
168
170
171private:
172 id m_dev = nullptr;
173 std::optional<DeviceType> m_dev_type;
174 std::optional<DeviceRuntime> m_dev_runtime;
175
176 friend class DeviceSet;
177};
178
179bool operator>(const OSVersion &lhs, const OSVersion &rhs);
180
181bool operator>(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
182
183bool operator<(const OSVersion &lhs, const OSVersion &rhs);
184
185bool operator<(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
186
187bool operator==(const OSVersion &lhs, const OSVersion &rhs);
188
189bool operator==(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
190
191bool operator!=(const OSVersion &lhs, const OSVersion &rhs);
192
193bool operator!=(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
194
196public:
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
213private:
214 DeviceSet(id arr) : m_dev(arr) {}
215
217};
218}
219
220#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_OBJCXX_PLATFORMIOSSIMULATORCORESIMULATORSUPPORT_H
static llvm::raw_ostream & error(Stream &strm)
static DeviceSet GetAvailableDevices(const char *developer_dir)
Device GetFanciest(DeviceType::ProductFamilyID dev_id)
void ForEach(std::function< bool(const Device &)> f)
DeviceSet GetDevices(DeviceType::ProductFamilyID dev_id)
static DeviceSet GetAllDevices(const char *developer_dir)
DeviceSet GetDevicesIf(std::function< bool(Device)> f)
Process Spawn(lldb_private::ProcessLaunchInfo &launch_info)
A uniqued constant string class.
Definition: ConstString.h:40
An error handling class.
Definition: Status.h:44
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:86
bool operator>(const OSVersion &lhs, const OSVersion &rhs)
bool operator!=(const OSVersion &lhs, const OSVersion &rhs)
bool operator==(const OSVersion &lhs, const OSVersion &rhs)
bool operator<(const OSVersion &lhs, const OSVersion &rhs)
uint64_t pid_t
Definition: lldb-types.h:81