14#include <CoreFoundation/CoreFoundation.h>
15#include <Foundation/Foundation.h>
20#include "llvm/ADT/StringRef.h"
28+ (id)sharedServiceContextForDeveloperDir:(NSString *)dir
29 error:(NSError **)error;
36@protocol LLDBCoreSimulatorSupport <NSObject>
37- (id)defaultDeviceSetWithError:(NSError **)error;
49- (BOOL)bootWithOptions:(NSDictionary *)options error:(NSError **)error;
51- (BOOL)shutdownWithError:(NSError **)error;
53- (BOOL)spawnWithPath:(NSString *)path
54 options:(nullable NSDictionary<NSString *,
id> *)options
55 terminationQueue:(nullable dispatch_queue_t)terminationQueue
56 terminationHandler:(nullable
void (^)(
int status))terminationHandler
57 pid:(pid_t *_Nullable)pid
58 error:(NSError *__autoreleasing _Nullable *_Nullable)error;
74CoreSimulatorSupport::DeviceType::operator
bool() {
return m_dev != nil; }
86CoreSimulatorSupport::DeviceRuntime::operator
bool() {
return m_dev != nil; }
89 return [m_dev available];
97CoreSimulatorSupport::Device::operator
bool() {
return m_dev != nil; }
100 return (
State)([m_dev state]);
105 bool first_digit =
false;
106 unsigned int val = 0;
112 val = 10 * val + (c -
'0');
113 }
else if (c ==
',') {
138 const std::string &build)
141 unsigned int val = 0;
146 }
else if (::isdigit(c)) {
147 val = 10 * val + (c -
'0');
163 auto utf8_model_id = [[m_dev modelIdentifier] UTF8String];
164 if (utf8_model_id && *utf8_model_id)
177 auto utf8_ver_string = [[m_dev versionString] UTF8String];
178 auto utf8_build_ver = [[m_dev buildVersionString] UTF8String];
179 if (utf8_ver_string && *utf8_ver_string && utf8_build_ver &&
191 auto utf8_name = [[m_dev name] UTF8String];
193 return std::string(utf8_name);
198 auto utf8_name = [[m_dev name] UTF8String];
200 return std::string(utf8_name);
205 auto utf8_udid = [[[m_dev UDID] UUIDString] UTF8String];
207 return std::string(utf8_udid);
209 return std::string();
340#define kSimDeviceBootPersist \
344 NSDictionary *options = @{
348#undef kSimDeviceBootPersist
351 if ([
m_dev bootWithOptions:options
error:&nserror]) {
362 if ([
m_dev shutdownWithError:&nserror]) {
372 NSMutableDictionary *options, NSString *key,
383 "close file action for %i not supported", fd);
388 "duplication file action for %i not supported", fd);
398 if (file_spec == secondary_spec) {
407 [options setValue:[NSNumber numberWithInteger:secondary_fd]
415 if (created_fd >= 0) {
419 else if (oflag & O_WRONLY)
421 else if (oflag & O_RDONLY)
423 file = std::make_shared<NativeFile>(created_fd, file_options,
true);
424 [options setValue:[NSNumber numberWithInteger:created_fd] forKey:key];
429 "unable to open file '{0}': {1}", file_spec.
GetPath(),
441#define kSimDeviceSpawnEnvironment \
444#define kSimDeviceSpawnStdin @"stdin"
445#define kSimDeviceSpawnStdout @"stdout"
447#define kSimDeviceSpawnStderr @"stderr"
449#define kSimDeviceSpawnArguments \
452#define kSimDeviceSpawnWaitForDebugger \
454#define kSimDeviceSpawnStandalone @"standalone"
458 options[kSimDeviceSpawnStandalone] = @(YES);
460 if (launch_info.
GetFlags().
Test(lldb::eLaunchFlagDebug))
461 [
options setObject:@YES forKey:kSimDeviceSpawnWaitForDebugger];
469 stringWithUTF8String:args.GetArgumentAtIndex(idx)]];
471 [
options setObject:args_array forKey:kSimDeviceSpawnArguments];
477 NSString *key_ns = [
NSString stringWithUTF8String:KV.first().str().c_str()];
478 NSString *value_ns = [
NSString stringWithUTF8String:KV.second.c_str()];
480 [
env_dict setValue:value_ns forKey:key_ns];
483 [
options setObject:env_dict forKey:kSimDeviceSpawnEnvironment];
490 STDIN_FILENO, stdin_file);
496 STDOUT_FILENO, stdout_file);
502 STDERR_FILENO, stderr_file);
507#undef kSimDeviceSpawnEnvironment
508#undef kSimDeviceSpawnStdin
509#undef kSimDeviceSpawnStdout
510#undef kSimDeviceSpawnStderr
511#undef kSimDeviceSpawnWaitForDebugger
512#undef kSimDeviceSpawnArguments
517 BOOL success = [m_dev
518 spawnWithPath:[
NSString stringWithUTF8String:launch_info
524 terminationHandler:nil
529 const char *nserror_string = [[
nserror description] UTF8String];
531 :
"unable to launch");
539 if (!developer_dir || !developer_dir[0])
542 Class SimServiceContextClass = NSClassFromString(
@"SimServiceContext");
543 NSString *dev_dir = @(developer_dir);
544 NSError *
error = nil;
552 return DeviceSet([[serviceContext defaultDeviceSetWithError:&
error] devices]);
557 const char *developer_dir) {
565 return [m_dev count];
578 for (NSUInteger i = 0; i < GetNumDevices(); i++) {
579 Device d(GetDeviceAtIndex(i));
581 [
array addObject:(id)d.m_dev];
588 std::function<
bool(
const Device &)> f) {
589 const size_t n = GetNumDevices();
590 for (NSUInteger i = 0; i < n; ++i) {
598 NSMutableArray *array = [[NSMutableArray alloc] init];
599 const size_t n = GetNumDevices();
600 for (NSUInteger i = 0; i < n; ++i) {
601 Device d(GetDeviceAtIndex(i));
602 if (d && d.GetDeviceType() &&
603 d.GetDeviceType().GetProductFamilyID() == dev_id)
604 [array addObject:(id)d.m_dev];
614 for (NSUInteger i = 0; i < GetNumDevices(); i++) {
615 Device d(GetDeviceAtIndex(i));
622 dev.GetDeviceType().GetModelIdentifier()) ||
624 dev.GetDeviceRuntime().GetVersion())
static llvm::raw_ostream & error(Stream &strm)
std::optional< OSVersion > m_os_version
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)
Device GetDeviceAtIndex(size_t idx)
ProductFamilyID GetProductFamilyID()
std::optional< ModelIdentifier > m_model_identifier
ModelIdentifier GetModelIdentifier()
Process Spawn(lldb_private::ProcessLaunchInfo &launch_info)
std::string GetUDID() const
std::string GetName() const
DeviceRuntime GetDeviceRuntime()
bool Boot(lldb_private::Status &err)
std::optional< DeviceType > m_dev_type
std::optional< DeviceRuntime > m_dev_runtime
DeviceType GetDeviceType()
unsigned int GetVersionAtIndex(size_t idx) const
ModelIdentifier(const std::string &mi)
std::vector< unsigned int > m_versions
std::string GetFamily() const
size_t GetNumVersions() const
OSVersion(const std::string &ver, const std::string &build)
std::vector< unsigned int > m_versions
unsigned int GetVersionAtIndex(size_t idx) const
size_t GetNumVersions() const
lldb_private::Status m_error
A command line argument class.
size_t GetArgumentCount() const
Gets the number of arguments left in this command object.
Represents a file descriptor action to be performed during process launch.
Action GetAction() const
Get the type of action.
int GetActionArgument() const
Get the action-specific argument.
const FileSpec & GetFileSpec() const
Get the file specification for open actions.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
bool Test(ValueType bit) const
Test a single flag bit.
Environment & GetEnvironment()
const FileAction * GetFileActionForFD(int fd) const
llvm::Error OpenSecondary(int oflag)
Open the secondary for the current primary pseudo terminal.
@ invalid_fd
Invalid file descriptor value.
int GetPrimaryFileDescriptor() const
The primary file descriptor accessor.
std::string GetSecondaryName() const
Get the name of the secondary pseudo terminal.
int GetSecondaryFileDescriptor() const
The secondary file descriptor accessor.
void Clear()
Clear the object state.
static Status FromErrno()
Set the current error to errno.
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
static Status FromErrorString(const char *str)
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
#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)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::File > FileSP
NSString * versionString()
NSString * productFamily()
NSString * buildVersionString()
int32_t productFamilyID()
NSString * modelIdentifier()