[Lldb-commits] [lldb] r155184 - in /lldb/trunk/source/Plugins/Platform/MacOSX: PlatformRemoteiOS.cpp PlatformRemoteiOS.h

Greg Clayton gclayton at apple.com
Thu Apr 19 19:02:02 PDT 2012


Author: gclayton
Date: Thu Apr 19 21:02:02 2012
New Revision: 155184

URL: http://llvm.org/viewvc/llvm-project?rev=155184&view=rev
Log:
<rdar://problem/11259893>

Fixed an issue where iOS debugging would trust the first file it found in the SDK regardless of the UUID not matching. Now we actually get smart and can find modules in ANY of the installed SDKs and remember which SDK is our fallback SDK.


Modified:
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
    lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp?rev=155184&r1=155183&r2=155184&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp Thu Apr 19 21:02:02 2012
@@ -135,7 +135,11 @@
 //------------------------------------------------------------------
 PlatformRemoteiOS::PlatformRemoteiOS () :
     PlatformDarwin (false),    // This is a remote platform
-    m_device_support_directory_for_os_version ()
+    m_sdk_directory_infos(),
+    m_device_support_directory(),
+    m_device_support_directory_for_os_version (),
+    m_build_update(),
+    m_last_module_sdk_idx(UINT32_MAX)
 {
 }
 
@@ -160,15 +164,15 @@
     else
         strm.PutCString ("  SDK Path: error: unable to locate SDK\n");
     
-//    const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
-//    for (uint32_t i=0; i<num_sdk_infos; ++i)
-//    {
-//        const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[i];
-//        strm.Printf (" SDK Roots: [%2u] \"%s/%s\"\n",
-//                     i,
-//                     sdk_dir_info.directory.GetDirectory().GetCString(),
-//                     sdk_dir_info.directory.GetFilename().GetCString());
-//    }
+    const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
+    for (uint32_t i=0; i<num_sdk_infos; ++i)
+    {
+        const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[i];
+        strm.Printf (" SDK Roots: [%2u] \"%s/%s\"\n",
+                     i,
+                     sdk_dir_info.directory.GetDirectory().GetCString(),
+                     sdk_dir_info.directory.GetFilename().GetCString());
+    }
 }
 
 
@@ -484,6 +488,97 @@
     return NULL;
 }
 
+uint32_t
+PlatformRemoteiOS::FindFileInAllSDKs (const char *platform_file_path,
+                                      FileSpecList &file_list)
+{
+    if (platform_file_path && platform_file_path[0] && UpdateSDKDirectoryInfosInNeeded())
+    {
+        const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
+        lldb_private::FileSpec local_file;
+        // First try for an exact match of major, minor and update
+        for (uint32_t sdk_idx=0; sdk_idx<num_sdk_infos; ++sdk_idx)
+        {
+            if (GetFileInSDK (platform_file_path,
+                              sdk_idx,
+                              local_file))
+            {
+                file_list.Append(local_file);
+            }
+        }
+    }
+    return file_list.GetSize();
+}
+
+bool
+PlatformRemoteiOS::GetFileInSDK (const char *platform_file_path,
+                                 uint32_t sdk_idx,
+                                 lldb_private::FileSpec &local_file)
+{
+    if (sdk_idx < m_sdk_directory_infos.size())
+    {
+        char sdkroot_path[PATH_MAX];
+        const SDKDirectoryInfo &sdk_dir_info = m_sdk_directory_infos[sdk_idx];
+        if (sdk_dir_info.directory.GetPath(sdkroot_path, sizeof(sdkroot_path)))
+        {
+            const bool symbols_dirs_only = true;
+
+            return GetFileInSDKRoot (platform_file_path,
+                                     sdkroot_path,
+                                     symbols_dirs_only,
+                                     local_file);
+        }
+    }
+    return false;
+}
+
+
+bool
+PlatformRemoteiOS::GetFileInSDKRoot (const char *platform_file_path,
+                                     const char *sdkroot_path,
+                                     bool symbols_dirs_only,
+                                     lldb_private::FileSpec &local_file)
+{
+    if (sdkroot_path && sdkroot_path[0] && platform_file_path && platform_file_path[0])
+    {
+        char resolved_path[PATH_MAX];
+        
+        if (!symbols_dirs_only)
+        {
+            ::snprintf (resolved_path, 
+                        sizeof(resolved_path), 
+                        "%s/%s", 
+                        sdkroot_path,
+                        platform_file_path);
+            
+            local_file.SetFile(resolved_path, true);
+            if (local_file.Exists())
+                return true;
+        }
+            
+        ::snprintf (resolved_path,
+                    sizeof(resolved_path), 
+                    "%s/Symbols.Internal/%s", 
+                    sdkroot_path,
+                    platform_file_path);
+        
+        local_file.SetFile(resolved_path, true);
+        if (local_file.Exists())
+            return true;
+        ::snprintf (resolved_path,
+                    sizeof(resolved_path), 
+                    "%s/Symbols/%s", 
+                    sdkroot_path, 
+                    platform_file_path);
+        
+        local_file.SetFile(resolved_path, true);
+        if (local_file.Exists())
+            return true;                
+    }
+    return false;
+}
+
+
 Error
 PlatformRemoteiOS::GetFile (const FileSpec &platform_file, 
                             const UUID *uuid_ptr,
@@ -557,22 +652,85 @@
     const FileSpec &platform_file = module_spec.GetFileSpec();
 
     FileSpec local_file;
-    Error error (GetFile (platform_file, module_spec.GetUUIDPtr(), local_file));
+    const UUID *module_uuid_ptr = module_spec.GetUUIDPtr();
+    Error error (GetFile (platform_file, module_uuid_ptr, local_file));
     if (error.Success())
     {
-        error = ResolveExecutable (local_file, module_spec.GetArchitecture(), module_sp, module_search_paths_ptr);
-    }
-    else
-    {
-        const bool always_create = false;
-        error = ModuleList::GetSharedModule (module_spec, 
-                                             module_sp,
-                                             module_search_paths_ptr,
-                                             old_module_sp_ptr,
-                                             did_create_ptr,
-                                             always_create);
+        error = ResolveExecutable (local_file, module_spec.GetArchitecture(), module_sp, NULL);
+        if (module_sp && ((module_uuid_ptr == NULL) || (module_sp->GetUUID() == *module_uuid_ptr)))
+        {
+            //printf ("found in user specified SDK\n");
+            error.Clear();
+            return error;
+        }
 
+        char platform_file_path[PATH_MAX];
+        if (platform_file.GetPath(platform_file_path, sizeof(platform_file_path)))
+        {
+            FileSpec local_file;
+            const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
+            // Try the last SDK index if it is set as most files from an SDK
+            // will tend to be valid in that same SDK.
+            if (m_last_module_sdk_idx < num_sdk_infos)
+            {
+                if (GetFileInSDK (platform_file_path, m_last_module_sdk_idx, local_file))
+                {
+                    //printf ("sdk[%u] last: '%s/%s'\n", m_last_module_sdk_idx, local_file.GetDirectory().GetCString(), local_file.GetFilename().GetCString());
+                    module_sp.reset();
+                    error = ResolveExecutable (local_file,
+                                               module_spec.GetArchitecture(),
+                                               module_sp,
+                                               NULL);
+                    if (module_sp && module_sp->GetUUID() == *module_uuid_ptr)
+                    {
+                        //printf ("sdk[%u] last found\n", m_last_module_sdk_idx);
+                        error.Clear();
+                        return error;
+                    }
+                }
+            }
+            
+            // First try for an exact match of major, minor and update
+            for (uint32_t sdk_idx=0; sdk_idx<num_sdk_infos; ++sdk_idx)
+            {
+                if (m_last_module_sdk_idx == sdk_idx)
+                {
+                    // Skip the last module SDK index if we already searched
+                    // it above
+                    continue;
+                }
+                if (GetFileInSDK (platform_file_path, sdk_idx, local_file))
+                {
+                    //printf ("sdk[%u]: '%s/%s'\n", sdk_idx, local_file.GetDirectory().GetCString(), local_file.GetFilename().GetCString());
+                    
+                    error = ResolveExecutable (local_file,
+                                               module_spec.GetArchitecture(),
+                                               module_sp,
+                                               NULL);
+                    if (module_sp && module_sp->GetUUID() == *module_uuid_ptr)
+                    {
+                        // Remember the index of the last SDK that we found a file
+                        // in in case the wrong SDK was selected.
+                        m_last_module_sdk_idx = sdk_idx;
+                        //printf ("sdk[%u]: found (setting last to %u)\n", sdk_idx, m_last_module_sdk_idx);
+                        error.Clear();
+                        return error;
+                    }
+                }
+            }
+        }
+        // Not the module we are looking for... Nothing to see here...
+        module_sp.reset();
     }
+
+    const bool always_create = false;
+    error = ModuleList::GetSharedModule (module_spec, 
+                                         module_sp,
+                                         module_search_paths_ptr,
+                                         old_module_sp_ptr,
+                                         did_create_ptr,
+                                         always_create);
+
     if (module_sp)
         module_sp->SetPlatformFileSpec(platform_file);
 

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h?rev=155184&r1=155183&r2=155184&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h Thu Apr 19 21:02:02 2012
@@ -126,11 +126,11 @@
         bool user_cached;
     };
     typedef std::vector<SDKDirectoryInfo> SDKDirectoryInfoCollection;
-    std::string m_device_support_directory;
     SDKDirectoryInfoCollection m_sdk_directory_infos;
+    std::string m_device_support_directory;
     std::string m_device_support_directory_for_os_version;
     std::string m_build_update;
-    //std::vector<FileSpec> m_device_support_os_dirs;
+    uint32_t m_last_module_sdk_idx;
 
     bool
     UpdateSDKDirectoryInfosInNeeded();
@@ -152,6 +152,25 @@
                                                   lldb_private::FileSpec::FileType file_type,
                                                   const lldb_private::FileSpec &file_spec);
 
+    uint32_t
+    FindFileInAllSDKs (const char *platform_file_path,
+                       lldb_private::FileSpecList &file_list);
+
+    bool
+    GetFileInSDK (const char *platform_file_path,
+                  uint32_t sdk_idx,
+                  lldb_private::FileSpec &local_file);
+
+    bool
+    GetFileInSDKRoot (const char *platform_file_path,
+                      const char *sdkroot_path,
+                      bool symbols_dirs_only,
+                      lldb_private::FileSpec &local_file);
+
+    uint32_t
+    FindFileInAllSDKs (const lldb_private::FileSpec &platform_file,
+                       lldb_private::FileSpecList &file_list);
+
 private:
     DISALLOW_COPY_AND_ASSIGN (PlatformRemoteiOS);
 





More information about the lldb-commits mailing list