diff options
6 files changed, 37 insertions, 21 deletions
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp index a5f165e1f92..296491ffeeb 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp @@ -52,7 +52,9 @@ PlatformAppleSimulator::Terminate () //------------------------------------------------------------------ PlatformAppleSimulator::PlatformAppleSimulator () : PlatformDarwin (true), - m_core_simulator_framework_path() + m_core_sim_path_mutex (), + m_core_simulator_framework_path(), + m_device () { } @@ -105,7 +107,7 @@ PlatformAppleSimulator::GetStatus (Stream &strm) // current simulator PlatformAppleSimulator::LoadCoreSimulator(); - CoreSimulatorSupport::DeviceSet devices = CoreSimulatorSupport::DeviceSet::GetAvailableDevices(); + CoreSimulatorSupport::DeviceSet devices = CoreSimulatorSupport::DeviceSet::GetAvailableDevices(GetDeveloperDirectory()); const size_t num_devices = devices.GetNumDevices(); if (num_devices) { @@ -155,7 +157,7 @@ PlatformAppleSimulator::ConnectRemote (Args& args) if (arg_cstr) { std::string arg_str(arg_cstr); - CoreSimulatorSupport::DeviceSet devices = CoreSimulatorSupport::DeviceSet::GetAvailableDevices(); + CoreSimulatorSupport::DeviceSet devices = CoreSimulatorSupport::DeviceSet::GetAvailableDevices(GetDeveloperDirectory()); devices.ForEach([this, &arg_str](const CoreSimulatorSupport::Device &device) -> bool { if (arg_str == device.GetUDID() || arg_str == device.GetName()) { @@ -252,7 +254,7 @@ FileSpec PlatformAppleSimulator::GetCoreSimulatorPath() { #if defined(__APPLE__) - std::lock_guard<std::mutex> guard(m_mutex); + std::lock_guard<std::mutex> guard(m_core_sim_path_mutex); if (!m_core_simulator_framework_path.hasValue()) { const char *developer_dir = GetDeveloperDirectory(); @@ -291,7 +293,7 @@ PlatformAppleSimulator::GetSimulatorDevice () if (!m_device.hasValue()) { const CoreSimulatorSupport::DeviceType::ProductFamilyID dev_id = CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone; - m_device = CoreSimulatorSupport::DeviceSet::GetAvailableDevices().GetFanciest(dev_id); + m_device = CoreSimulatorSupport::DeviceSet::GetAvailableDevices(GetDeveloperDirectory()).GetFanciest(dev_id); } if (m_device.hasValue()) diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h index de8673b2a2a..2806c787c70 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h @@ -12,6 +12,8 @@ // C Includes // C++ Includes +#include <mutex> + // Other libraries and framework includes // Project includes #include "lldb/Host/FileSpec.h" @@ -59,6 +61,7 @@ public: lldb_private::Error &error) override; protected: + std::mutex m_core_sim_path_mutex; llvm::Optional<lldb_private::FileSpec> m_core_simulator_framework_path; llvm::Optional<CoreSimulatorSupport::Device> m_device; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp index 99b9324417b..1df695ae48d 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp @@ -172,7 +172,9 @@ PlatformiOSSimulator::GetDescriptionStatic() //------------------------------------------------------------------ PlatformiOSSimulator::PlatformiOSSimulator () : PlatformAppleSimulator (), -m_sdk_directory () +m_sdk_dir_mutex (), +m_sdk_directory (), +m_build_update () { } @@ -308,7 +310,7 @@ EnumerateDirectoryCallback (void *baton, FileSpec::FileType file_type, const Fil const char * PlatformiOSSimulator::GetSDKDirectoryAsCString() { - std::lock_guard<std::mutex> guard(m_mutex); + std::lock_guard<std::mutex> guard(m_sdk_dir_mutex); if (m_sdk_directory.empty()) { const char *developer_dir = GetDeveloperDirectory(); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h index f84d04b9c48..ffd730e7252 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h @@ -12,6 +12,7 @@ // C Includes // C++ Includes +#include <mutex> #include <string> // Other libraries and framework includes @@ -103,6 +104,7 @@ public: } protected: + std::mutex m_sdk_dir_mutex; std::string m_sdk_directory; std::string m_build_update; diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h index 8393ea30490..ee6d3149fcf 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h @@ -280,10 +280,10 @@ namespace CoreSimulatorSupport { public: static DeviceSet - GetAllDevices (); + GetAllDevices (const char *developer_dir); static DeviceSet - GetAvailableDevices (); + GetAvailableDevices (const char *developer_dir); size_t GetNumDevices (); diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm index 7075de55252..035923859d5 100644 --- a/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm +++ b/lldb/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm @@ -24,14 +24,15 @@ using namespace lldb_private; using namespace lldb_utility; // CoreSimulator lives as part of Xcode, which means we can't really link against it, so we dlopen() // it at runtime, and error out nicely if that fails -@interface SimDeviceSet +@interface SimServiceContext {} -+ (id) defaultSet; ++ (id) sharedServiceContextForDeveloperDir:(NSString*)dir error:(NSError**)error; @end // However, the drawback is that the compiler will not know about the selectors we're trying to use // until runtime; to appease clang in this regard, define a fake protocol on NSObject that exposes // the needed interface names for us @protocol LLDBCoreSimulatorSupport <NSObject> +- (id) defaultDeviceSetWithError:(NSError**)error; - (NSArray *) devices; - (id) deviceType; - (NSString *) name; @@ -466,18 +467,13 @@ CoreSimulatorSupport::Device::Boot (Error &err) return false; } -#define kSimDeviceBootEnv @"env" /* An NSDictionary of "extra" environment key/values */ #define kSimDeviceBootPersist @"persist" /* An NSNumber (boolean) indicating whether or not the session should outlive the calling process (default false) */ -#define kSimDeviceBootDisabledJobs @"disabled_jobs" /* An NSDictionary of NSStrings -> NSNumbers, each string is the name of a job, and the value is the corresponding state (true if disabled) */ NSDictionary *options = @{ kSimDeviceBootPersist : @NO, - kSimDeviceBootDisabledJobs : @{@"com.apple.backboardd" : @YES} }; - -#undef kSimDeviceBootEnv + #undef kSimDeviceBootPersist -#undef kSimDeviceBootDisabledJobs NSError* nserror; if ([m_dev bootWithOptions:options error:&nserror]) @@ -677,15 +673,26 @@ CoreSimulatorSupport::Device::Spawn (ProcessLaunchInfo& launch_info) } CoreSimulatorSupport::DeviceSet -CoreSimulatorSupport::DeviceSet::GetAllDevices () +CoreSimulatorSupport::DeviceSet::GetAllDevices (const char *developer_dir) { - return DeviceSet([[NSClassFromString(@"SimDeviceSet") defaultSet] devices]); + if (!developer_dir || !developer_dir[0]) + return DeviceSet([NSArray new]); + + Class SimServiceContextClass = NSClassFromString(@"SimServiceContext"); + NSString *dev_dir = @(developer_dir); + NSError *error = nil; + + id serviceContext = [SimServiceContextClass sharedServiceContextForDeveloperDir:dev_dir error:&error]; + if (!serviceContext) + return DeviceSet([NSArray new]); + + return DeviceSet([[serviceContext defaultDeviceSetWithError:&error] devices]); } CoreSimulatorSupport::DeviceSet -CoreSimulatorSupport::DeviceSet::GetAvailableDevices () +CoreSimulatorSupport::DeviceSet::GetAvailableDevices (const char *developer_dir) { - return GetAllDevices().GetDevicesIf( [] (Device d) -> bool { + return GetAllDevices(developer_dir).GetDevicesIf( [] (Device d) -> bool { return (d && d.GetDeviceType() && d.GetDeviceRuntime() && d.GetDeviceRuntime().IsAvailable()); }); } |