[Lldb-commits] [lldb] r278166 - Adjust LLDB's iOS simulator interface for changes in CoreSimulator

Enrico Granata via lldb-commits lldb-commits at lists.llvm.org
Tue Aug 9 14:16:59 PDT 2016


Author: enrico
Date: Tue Aug  9 16:16:58 2016
New Revision: 278166

URL: http://llvm.org/viewvc/llvm-project?rev=278166&view=rev
Log:
Adjust LLDB's iOS simulator interface for changes in CoreSimulator

rdar://27732333 and rdar://27732377


Modified:
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp?rev=278166&r1=278165&r2=278166&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp Tue Aug  9 16:16:58 2016
@@ -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 (Strea
     // 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 (A
         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::GetSimulatorDevi
     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())

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h?rev=278166&r1=278165&r2=278166&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h Tue Aug  9 16:16:58 2016
@@ -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;
     

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp?rev=278166&r1=278165&r2=278166&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp Tue Aug  9 16:16:58 2016
@@ -172,7 +172,9 @@ PlatformiOSSimulator::GetDescriptionStat
 //------------------------------------------------------------------
 PlatformiOSSimulator::PlatformiOSSimulator () :
 PlatformAppleSimulator (),
-m_sdk_directory ()
+m_sdk_dir_mutex (),
+m_sdk_directory (),
+m_build_update ()
 {
 }
 
@@ -308,7 +310,7 @@ EnumerateDirectoryCallback (void *baton,
 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();

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h?rev=278166&r1=278165&r2=278166&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h Tue Aug  9 16:16:58 2016
@@ -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;
     

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h?rev=278166&r1=278165&r2=278166&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.h Tue Aug  9 16:16:58 2016
@@ -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 ();

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm?rev=278166&r1=278165&r2=278166&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformiOSSimulatorCoreSimulatorSupport.mm Tue Aug  9 16:16:58 2016
@@ -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
- at interface SimDeviceSet
+ at 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 (Erro
         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 (Pro
 }
 
 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());
     });
 }




More information about the lldb-commits mailing list