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"
25#include "lldb/Utility/Status.h"
26
27
28// And now the actual magic
30class Process {
31public:
32 lldb::pid_t GetPID() { return m_pid; }
33
34 explicit operator bool() { return m_pid != LLDB_INVALID_PROCESS_ID; }
35
37
38private:
40
42
44
47
48 friend class Device;
49};
50
52public:
53 ModelIdentifier(const std::string &mi);
55
56 explicit operator bool() const { return !m_versions.empty(); }
57
58 size_t GetNumVersions() const { return m_versions.size(); }
59
60 unsigned int GetVersionAtIndex(size_t idx) const { return m_versions[idx]; }
61
62 std::string GetFamily() const { return m_family.c_str(); }
63
64private:
65 std::string m_family;
66 std::vector<unsigned int> m_versions;
67};
68
70public:
71 enum class ProductFamilyID : int32_t {
72 iPhone = 1,
73 iPad = 2,
77 };
78
79 DeviceType();
80
81 DeviceType(id d);
82
83 explicit operator bool();
84
85 std::string GetName();
86
88
89 ProductFamilyID GetProductFamilyID();
90
91private:
92 id m_dev = nullptr;
93 std::optional<ModelIdentifier> m_model_identifier;
94};
95
96class OSVersion {
97public:
98 OSVersion(const std::string &ver, const std::string &build);
99
100 OSVersion();
101
102 explicit operator bool() const { return !m_versions.empty(); }
103
104 size_t GetNumVersions() const { return m_versions.size(); }
105
106 unsigned int GetVersionAtIndex(size_t idx) const { return m_versions[idx]; }
107
108 const char *GetBuild() const { return m_build.c_str(); }
109
110private:
111 std::vector<unsigned int> m_versions;
112 std::string m_build;
113};
114
116public:
118
119 DeviceRuntime(id d);
120
121 explicit operator bool();
122
124
125 bool IsAvailable();
126
127private:
128 id m_dev = nullptr;
129 std::optional<OSVersion> m_os_version;
130};
131
132class Device {
133private:
134 typedef unsigned long int NSUInteger;
135
136public:
144
145 Device();
146
147 Device(id d);
148
149 explicit operator bool();
150
151 std::string GetName() const;
152
154
156
157 State GetState();
158
159 bool Boot(lldb_private::Status &err);
160
162
163 std::string GetUDID() const;
164
166
167private:
168 id m_dev = nullptr;
169 std::optional<DeviceType> m_dev_type;
170 std::optional<DeviceRuntime> m_dev_runtime;
171
172 friend class DeviceSet;
173};
174
175bool operator>(const OSVersion &lhs, const OSVersion &rhs);
176
177bool operator>(const ModelIdentifier &lhs, const ModelIdentifier &rhs);
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
192public:
193 static DeviceSet GetAllDevices(const char *developer_dir);
194
195 static DeviceSet GetAvailableDevices(const char *developer_dir);
196
197 size_t GetNumDevices();
198
199 Device GetDeviceAtIndex(size_t idx);
200
201 void ForEach(std::function<bool(const Device &)> f);
202
203 DeviceSet GetDevicesIf(std::function<bool(Device)> f);
204
206
208
209private:
210 DeviceSet(id arr) : m_dev(arr) {}
211
213};
214}
215
216#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)
OSVersion(const std::string &ver, const std::string &build)
An error handling class.
Definition Status.h:118
#define LLDB_INVALID_PROCESS_ID
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:84