[Lldb-commits] [lldb] r279688 - Rewrite the GetFileInSDK methods in PlatformRemoteiOS,

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 24 16:46:49 PDT 2016


Author: jmolenda
Date: Wed Aug 24 18:46:48 2016
New Revision: 279688

URL: http://llvm.org/viewvc/llvm-project?rev=279688&view=rev
Log:
Rewrite the GetFileInSDK methods in PlatformRemoteiOS,
PlatformRemoteAppleWatch, PlatformRemoteAppleTV and remove the 
GetFileInSDKRoot method from those classes.

The rewrite uses the more modern FileSpec etc API to simplify,
and handles the case where an SDK Root is given to lldb with
the "/Symbols" directory name already appended.  The new version
will try appending "/Symbols" and "/Symbols.Internal" to the 
sdk root directories, and will also try appending nothing to
the sdk root directory in case it's handed such an sdkroot.

<rdar://problem/28000054> 

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

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp?rev=279688&r1=279687&r2=279688&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp Wed Aug 24 18:46:48 2016
@@ -613,82 +613,33 @@ PlatformRemoteAppleTV::GetFileInSDK (con
                                  uint32_t sdk_idx,
                                  lldb_private::FileSpec &local_file)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     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)))
+        std::string sdkroot_path = m_sdk_directory_infos[sdk_idx].directory.GetPath();
+        if (!sdkroot_path.empty() && platform_file_path && platform_file_path[0])
         {
-            const bool symbols_dirs_only = true;
-
-            return GetFileInSDKRoot (platform_file_path,
-                                     sdkroot_path,
-                                     symbols_dirs_only,
-                                     local_file);
-        }
-    }
-    return false;
-}
+            // We may need to interpose "/Symbols/" or "/Symbols.Internal/" between the
+            // SDK root directory and the file path.
 
-bool
-PlatformRemoteAppleTV::GetFileInSDKRoot (const char *platform_file_path,
-                                     const char *sdkroot_path,
-                                     bool symbols_dirs_only,
-                                     lldb_private::FileSpec &local_file)
-{
-    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
-    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())
+            const char *paths_to_try[] = { "Symbols", "", "Symbols.Internal", nullptr };
+            for (size_t i = 0; paths_to_try[i] != nullptr; i++)
             {
-                if (log)
+                local_file.SetFile (sdkroot_path.c_str(), false);
+                if (paths_to_try[i][0] != '\0')
+                    local_file.AppendPathComponent (paths_to_try[i]);
+                local_file.AppendPathComponent (platform_file_path);
+                local_file.ResolvePath();
+                if (local_file.Exists())
                 {
-                    log->Printf ("Found a copy of %s in the SDK dir %s", platform_file_path, sdkroot_path);
+                    if (log)
+                        log->Printf ("Found a copy of %s in the SDK dir %s/%s", platform_file_path, 
+                                                                                sdkroot_path.c_str(), 
+                                                                                paths_to_try[i]);
+                    return true;
                 }
-                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())
-        {
-            if (log)
-            {
-                log->Printf ("Found a copy of %s in the SDK dir %s/Symbols.Internal", platform_file_path, sdkroot_path);
-            }
-            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())
-        {
-            if (log)
-            {
-                log->Printf ("Found a copy of %s in the SDK dir %s/Symbols", platform_file_path, sdkroot_path);
+                local_file.Clear();
             }
-            return true;                
         }
     }
     return false;

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h?rev=279688&r1=279687&r2=279688&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h Wed Aug 24 18:46:48 2016
@@ -151,12 +151,6 @@ protected:
                   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);

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp?rev=279688&r1=279687&r2=279688&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp Wed Aug 24 18:46:48 2016
@@ -624,82 +624,33 @@ PlatformRemoteAppleWatch::GetFileInSDK (
                                  uint32_t sdk_idx,
                                  lldb_private::FileSpec &local_file)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     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)))
+        std::string sdkroot_path = m_sdk_directory_infos[sdk_idx].directory.GetPath();
+        if (!sdkroot_path.empty() && platform_file_path && platform_file_path[0])
         {
-            const bool symbols_dirs_only = true;
-
-            return GetFileInSDKRoot (platform_file_path,
-                                     sdkroot_path,
-                                     symbols_dirs_only,
-                                     local_file);
-        }
-    }
-    return false;
-}
+            // We may need to interpose "/Symbols/" or "/Symbols.Internal/" between the
+            // SDK root directory and the file path.
 
-bool
-PlatformRemoteAppleWatch::GetFileInSDKRoot (const char *platform_file_path,
-                                     const char *sdkroot_path,
-                                     bool symbols_dirs_only,
-                                     lldb_private::FileSpec &local_file)
-{
-    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
-    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())
+            const char *paths_to_try[] = { "Symbols", "", "Symbols.Internal", nullptr };
+            for (size_t i = 0; paths_to_try[i] != nullptr; i++)
             {
-                if (log)
+                local_file.SetFile (sdkroot_path.c_str(), false);
+                if (paths_to_try[i][0] != '\0')
+                    local_file.AppendPathComponent (paths_to_try[i]);
+                local_file.AppendPathComponent (platform_file_path);
+                local_file.ResolvePath();
+                if (local_file.Exists())
                 {
-                    log->Printf ("Found a copy of %s in the SDK dir %s", platform_file_path, sdkroot_path);
+                    if (log)
+                        log->Printf ("Found a copy of %s in the SDK dir %s/%s", platform_file_path, 
+                                                                                sdkroot_path.c_str(), 
+                                                                                paths_to_try[i]);
+                    return true;
                 }
-                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())
-        {
-            if (log)
-            {
-                log->Printf ("Found a copy of %s in the SDK dir %s/Symbols.Internal", platform_file_path, sdkroot_path);
-            }
-            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())
-        {
-            if (log)
-            {
-                log->Printf ("Found a copy of %s in the SDK dir %s/Symbols", platform_file_path, sdkroot_path);
+                local_file.Clear();
             }
-            return true;                
         }
     }
     return false;

Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h?rev=279688&r1=279687&r2=279688&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h Wed Aug 24 18:46:48 2016
@@ -153,12 +153,6 @@ protected:
                   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);

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=279688&r1=279687&r2=279688&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp Wed Aug 24 18:46:48 2016
@@ -610,83 +610,33 @@ PlatformRemoteiOS::GetFileInSDK (const c
                                  uint32_t sdk_idx,
                                  lldb_private::FileSpec &local_file)
 {
+    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
     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;
-}
-
+        std::string sdkroot_path = m_sdk_directory_infos[sdk_idx].directory.GetPath();
+        local_file.Clear();
 
-bool
-PlatformRemoteiOS::GetFileInSDKRoot (const char *platform_file_path,
-                                     const char *sdkroot_path,
-                                     bool symbols_dirs_only,
-                                     lldb_private::FileSpec &local_file)
-{
-    Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST);
-    if (sdkroot_path && sdkroot_path[0] && platform_file_path && platform_file_path[0])
-    {
-        char resolved_path[PATH_MAX];
-        
-        if (!symbols_dirs_only)
+        if (!sdkroot_path.empty() && platform_file_path && platform_file_path[0])
         {
-            ::snprintf (resolved_path, 
-                        sizeof(resolved_path), 
-                        "%s%s",
-                        sdkroot_path,
-                        platform_file_path);
-            
-            local_file.SetFile(resolved_path, true);
-            if (local_file.Exists())
+            // We may need to interpose "/Symbols/" or "/Symbols.Internal/" between the
+            // SDK root directory and the file path.
+
+            const char *paths_to_try[] = { "Symbols", "", "Symbols.Internal", nullptr };
+            for (size_t i = 0; paths_to_try[i] != nullptr; i++)
             {
-                if (log)
+                local_file.SetFile (sdkroot_path.c_str(), false);
+                if (paths_to_try[i][0] != '\0')
+                    local_file.AppendPathComponent (paths_to_try[i]);
+                local_file.AppendPathComponent (platform_file_path);
+                local_file.ResolvePath();
+                if (local_file.Exists())
                 {
-                    log->Printf ("Found a copy of %s in the SDK dir %s", platform_file_path, sdkroot_path);
+                    if (log)
+                        log->Printf ("Found a copy of %s in the SDK dir %s/%s", platform_file_path, sdkroot_path.c_str(), paths_to_try[i]);
+                    return true;
                 }
-                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())
-        {
-            if (log)
-            {
-                log->Printf ("Found a copy of %s in the SDK dir %s/Symbols.Internal", platform_file_path, sdkroot_path);
-            }
-            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())
-        {
-            if (log)
-            {
-                log->Printf ("Found a copy of %s in the SDK dir %s/Symbols", platform_file_path, sdkroot_path);
+                local_file.Clear();
             }
-            return true;                
         }
     }
     return false;

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=279688&r1=279687&r2=279688&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h Wed Aug 24 18:46:48 2016
@@ -149,12 +149,6 @@ protected:
                   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);




More information about the lldb-commits mailing list