[Lldb-commits] [lldb] r227288 - Changes in 226712 needed some fixing as a platform is almost always selected and even if platform options are specified when doing a "target create" they would get ignored if a platform was already selected.

Greg Clayton gclayton at apple.com
Tue Jan 27 17:33:37 PST 2015


Author: gclayton
Date: Tue Jan 27 19:33:37 2015
New Revision: 227288

URL: http://llvm.org/viewvc/llvm-project?rev=227288&view=rev
Log:
Changes in 226712 needed some fixing as a platform is almost always selected and even if platform options are specified when doing a "target create" they would get ignored if a platform was already selected.

The change was made so we could re-use a platform if one was already created instead of creating a new one, but it would fail in the above case. To fix this, if we have a selected platform, we verify that the platform matches the current platform before we try to re-use it. We do this by asking the OptionGroupPlatform if the platform matches. If so, it returns true and we don't create a new platform, else we do.


Modified:
    lldb/trunk/include/lldb/Interpreter/OptionGroupPlatform.h
    lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp
    lldb/trunk/source/Target/TargetList.cpp

Modified: lldb/trunk/include/lldb/Interpreter/OptionGroupPlatform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/OptionGroupPlatform.h?rev=227288&r1=227287&r2=227288&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/OptionGroupPlatform.h (original)
+++ lldb/trunk/include/lldb/Interpreter/OptionGroupPlatform.h Tue Jan 27 19:33:37 2015
@@ -102,8 +102,10 @@ public:
     SetSDKBuild (const ConstString &sdk_build)
     {
         m_sdk_build = sdk_build;
-    }    
-    
+    }
+
+    bool
+    PlatformMatches(const lldb::PlatformSP &platform_sp) const;
 
 protected:
     std::string m_platform_name;

Modified: lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp?rev=227288&r1=227287&r2=227288&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp Tue Jan 27 19:33:37 2015
@@ -147,3 +147,38 @@ OptionGroupPlatform::SetOptionValue (Com
     }
     return error;
 }
+
+bool
+OptionGroupPlatform::PlatformMatches(const lldb::PlatformSP &platform_sp) const
+{
+    if (platform_sp)
+    {
+        if (!m_platform_name.empty())
+        {
+            if (platform_sp->GetName() != ConstString(m_platform_name.c_str()))
+                return false;
+        }
+
+        if (m_sdk_build && m_sdk_build != platform_sp->GetSDKBuild())
+            return false;
+
+        if (m_sdk_sysroot && m_sdk_sysroot != platform_sp->GetSDKRootDirectory())
+            return false;
+
+        if (m_os_version_major != UINT32_MAX)
+        {
+            uint32_t major, minor, update;
+            if (platform_sp->GetOSVersion (major, minor, update))
+            {
+                if (m_os_version_major != major)
+                    return false;
+                if (m_os_version_minor != minor)
+                    return false;
+                if (m_os_version_update != update)
+                    return false;
+            }
+        }
+        return true;
+    }
+    return false;
+}

Modified: lldb/trunk/source/Target/TargetList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/TargetList.cpp?rev=227288&r1=227287&r2=227288&view=diff
==============================================================================
--- lldb/trunk/source/Target/TargetList.cpp (original)
+++ lldb/trunk/source/Target/TargetList.cpp Tue Jan 27 19:33:37 2015
@@ -130,16 +130,20 @@ TargetList::CreateTargetInternal (Debugg
     // let's see if there is already an existing plaform before we go creating another...
     platform_sp = debugger.GetPlatformList().GetSelectedPlatform();
 
-    if (!platform_sp && platform_options && platform_options->PlatformWasSpecified ())
+    if (platform_options && platform_options->PlatformWasSpecified ())
     {
-        const bool select_platform = true;
-        platform_sp = platform_options->CreatePlatformWithOptions (interpreter,
-                                                                   arch,
-                                                                   select_platform,
-                                                                   error,
-                                                                   platform_arch);
-        if (!platform_sp)
-            return error;
+        // Create a new platform if it doesn't match the selected platform
+        if (!platform_options->PlatformMatches(platform_sp))
+        {
+            const bool select_platform = true;
+            platform_sp = platform_options->CreatePlatformWithOptions (interpreter,
+                                                                       arch,
+                                                                       select_platform,
+                                                                       error,
+                                                                       platform_arch);
+            if (!platform_sp)
+                return error;
+        }
     }
     
     if (user_exe_path && user_exe_path[0])





More information about the lldb-commits mailing list