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; }
94CoreSimulatorSupport::DeviceRuntime::operator
bool() {
return m_dev != nil; }
97 return [m_dev available];
105CoreSimulatorSupport::Device::operator
bool() {
return m_dev != nil; }
108 return (
State)([m_dev state]);
113 bool first_digit =
false;
114 unsigned int val = 0;
120 val = 10 * val + (c -
'0');
121 }
else if (c ==
',') {
146 const std::string &build)
149 unsigned int val = 0;
154 }
else if (::isdigit(c)) {
155 val = 10 * val + (c -
'0');
171 auto utf8_model_id = [[m_dev modelIdentifier] UTF8String];
172 if (utf8_model_id && *utf8_model_id)
185 auto utf8_ver_string = [[m_dev versionString] UTF8String];
186 auto utf8_build_ver = [[m_dev buildVersionString] UTF8String];
187 if (utf8_ver_string && *utf8_ver_string && utf8_build_ver &&
199 auto utf8_name = [[m_dev name] UTF8String];
201 return std::string(utf8_name);
206 auto utf8_name = [[m_dev name] UTF8String];
208 return std::string(utf8_name);
213 auto utf8_udid = [[[m_dev UDID] UUIDString] UTF8String];
215 return std::string(utf8_udid);
217 return std::string();
348#define kSimDeviceBootPersist \
352 NSDictionary *options = @{
356#undef kSimDeviceBootPersist
359 if ([
m_dev bootWithOptions:options
error:&nserror]) {
370 if ([
m_dev shutdownWithError:&nserror]) {
380 NSMutableDictionary *options, NSString *key,
391 "close file action for %i not supported", fd);
396 "duplication file action for %i not supported", fd);
406 if (file_spec == secondary_spec) {
415 [options setValue:[NSNumber numberWithInteger:secondary_fd]
423 if (created_fd >= 0) {
427 else if (oflag & O_WRONLY)
429 else if (oflag & O_RDONLY)
431 file = std::make_shared<NativeFile>(created_fd, file_options,
true);
432 [options setValue:[NSNumber numberWithInteger:created_fd] forKey:key];
437 "unable to open file '{0}': {1}", file_spec.
GetPath(),
449#define kSimDeviceSpawnEnvironment \
452#define kSimDeviceSpawnStdin @"stdin"
453#define kSimDeviceSpawnStdout @"stdout"
455#define kSimDeviceSpawnStderr @"stderr"
457#define kSimDeviceSpawnArguments \
460#define kSimDeviceSpawnWaitForDebugger \
462#define kSimDeviceSpawnStandalone @"standalone"
466 options[kSimDeviceSpawnStandalone] = @(YES);
468 if (launch_info.
GetFlags().
Test(lldb::eLaunchFlagDebug))
469 [
options setObject:@YES forKey:kSimDeviceSpawnWaitForDebugger];
477 stringWithUTF8String:args.GetArgumentAtIndex(idx)]];
479 [
options setObject:args_array forKey:kSimDeviceSpawnArguments];
485 NSString *key_ns = [
NSString stringWithUTF8String:KV.first().str().c_str()];
486 NSString *value_ns = [
NSString stringWithUTF8String:KV.second.c_str()];
488 [
env_dict setValue:value_ns forKey:key_ns];
491 [
options setObject:env_dict forKey:kSimDeviceSpawnEnvironment];
498 STDIN_FILENO, stdin_file);
504 STDOUT_FILENO, stdout_file);
510 STDERR_FILENO, stderr_file);
515#undef kSimDeviceSpawnEnvironment
516#undef kSimDeviceSpawnStdin
517#undef kSimDeviceSpawnStdout
518#undef kSimDeviceSpawnStderr
519#undef kSimDeviceSpawnWaitForDebugger
520#undef kSimDeviceSpawnArguments
525 BOOL success = [m_dev
526 spawnWithPath:[
NSString stringWithUTF8String:launch_info
532 terminationHandler:nil
537 const char *nserror_string = [[
nserror description] UTF8String];
539 :
"unable to launch");
547 if (!developer_dir || !developer_dir[0])
550 Class SimServiceContextClass = NSClassFromString(
@"SimServiceContext");
551 NSString *dev_dir = @(developer_dir);
552 NSError *
error = nil;
560 return DeviceSet([[serviceContext defaultDeviceSetWithError:&
error] devices]);
565 const char *developer_dir) {
573 return [m_dev count];
586 for (NSUInteger i = 0; i < GetNumDevices(); i++) {
587 Device d(GetDeviceAtIndex(i));
589 [
array addObject:(id)d.m_dev];
596 std::function<
bool(
const Device &)> f) {
597 const size_t n = GetNumDevices();
598 for (NSUInteger i = 0; i < n; ++i) {
606 NSMutableArray *array = [[NSMutableArray alloc] init];
607 const size_t n = GetNumDevices();
608 for (NSUInteger i = 0; i < n; ++i) {
609 Device d(GetDeviceAtIndex(i));
610 if (d && d.GetDeviceType() &&
611 d.GetDeviceType().GetProductFamilyID() == dev_id)
612 [array addObject:(id)d.m_dev];
622 for (NSUInteger i = 0; i < GetNumDevices(); i++) {
623 Device d(GetDeviceAtIndex(i));
630 dev.GetDeviceType().GetModelIdentifier()) ||
632 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()
lldb_private::ConstString GetIdentifier()
lldb_private::ConstString GetProductFamily()
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.
A uniqued constant string class.
int GetActionArgument() const
const FileSpec & GetFileSpec() const
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()
PseudoTerminal & GetPTY()
const FileAction * GetFileActionForFD(int fd) const
llvm::Error OpenSecondary(int oflag)
Open the secondary for the current primary pseudo terminal.
int GetPrimaryFileDescriptor() const
The primary file descriptor accessor.
@ invalid_fd
Invalid file descriptor value.
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()