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 appleXR = 7,
78 };
79
80 DeviceType();
81
82 DeviceType(id d);
83
84 explicit operator bool();
85
86 std::string GetName();
87
89
91
93
95
96private:
97 id m_dev = nullptr;
98 std::optional<ModelIdentifier> m_model_identifier;
99};
100
102public:
103 OSVersion(const std::string &ver, const std::string &build);
104
105 OSVersion();
106
107 explicit operator bool() const { return !m_versions.empty(); }
108
109 size_t GetNumVersions() const { return m_versions.size(); }
110
111 unsigned int GetVersionAtIndex(size_t idx) const { return m_versions[idx]; }
112
113 const char *GetBuild() const { return m_build.c_str(); }
114
115private:
116 std::vector<unsigned int> m_versions;
117 std::string m_build;
118};
119
121public:
123
124 DeviceRuntime(id d);
125
126 explicit operator bool();
127
129
130 bool IsAvailable();
131
132private:
133 id m_dev = nullptr;
134 std::optional<OSVersion> m_os_version;
135};
136
137class Device {
138private:
139 typedef unsigned long int NSUInteger;
140
141public:
142 enum class State : NSUInteger {
143 Creating,
144 Shutdown,
145 Booting,
146 Booted,
148 };
149
150 Device();
151
152 Device(id d);
153
154 explicit operator bool();
155
156 std::string GetName() const;
157
159
161
162 State GetState();
163
164 bool Boot(lldb_private::Status &err);
165
167
168 std::string GetUDID() const;
169
171
172private:
173 id m_dev = nullptr;
174 std::optional<DeviceType> m_dev_type;
175 std::optional<DeviceRuntime> m_dev_runtime;
176
177 friend class DeviceSet;
178};
179
180bool operator>(const OSVersion &lhs, const OSVersion &rhs);
181
182bool operator>(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
183
184bool operator<(const OSVersion &lhs, const OSVersion &rhs);
185
186bool operator<(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
187
188bool operator==(const OSVersion &lhs, const OSVersion &rhs);
189
190bool operator==(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
191
192bool operator!=(const OSVersion &lhs, const OSVersion &rhs);
193
194bool operator!=(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
195
197public:
198 static DeviceSet GetAllDevices(const char *developer_dir);
199
200 static DeviceSet GetAvailableDevices(const char *developer_dir);
201
202 size_t GetNumDevices();
203
204 Device GetDeviceAtIndex(size_t idx);
205
206 void ForEach(std::function<bool(const Device &)> f);
207
208 DeviceSet GetDevicesIf(std::function<bool(Device)> f);
209
211
213
214private:
215 DeviceSet(id arr) : m_dev(arr) {}
216
218};
219}
220
221#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:115
Status Clone() const
Don't call this function in new code.
Definition: Status.h:171
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:89
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:83