Author: jmolenda
Date: Mon Jun 13 22:49:13 2016
New Revision: 272635

URL: http://llvm.org/viewvc/llvm-project?rev=272635&view=rev
Log:
Add support to PlatformRemoteiOS, PlatformRemoteAppleWatch, and
PlatformRemoteAppleTV to check the target.exec-search-paths 
directories for files after looking in the SDK.  An additional
wrinkle is that the remote file path may be something like
".../UIFoundation.framework/UIFoundation" and in 
target.exec-search-paths we will have "UIFoundation.framework".
Looking for just the filename of the path is not sufficient -
we need to also look for it by the parent directories because
this may be a darwin bundle/framework like the UIFoundation
example.

We really need to make a PlatformRemoteAppleDevice and have
PlatformRemoteiOS, PlatformRemoteAppleWatch, and PlatformRemoteAppleTV
inherit from it.  These three classes are 98% identical code.

<rdar://problem/25976619> 

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

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=272635&r1=272634&r2=272635&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp 
(original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp Mon Jun 
13 22:49:13 2016
@@ -880,6 +880,76 @@ PlatformRemoteAppleTV::GetSharedModule (
     if (error.Success())
         return error;
 
+    // See if the file is present in any of the module_search_paths_ptr 
directories.
+    if (!module_sp && module_search_paths_ptr && platform_file)
+    {
+        // create a vector of all the file / directory names in platform_file
+        // e.g. this might be 
/System/Library/PrivateFrameworks/UIFoundation.framework/UIFoundation
+        //
+        // We'll need to look in the module_search_paths_ptr directories for
+        // both "UIFoundation" and "UIFoundation.framework" -- most likely the
+        // latter will be the one we find there.
+
+        FileSpec platform_pull_apart (platform_file);
+        std::vector<std::string> path_parts;
+        ConstString unix_root_dir("/");
+        while (true)
+        {
+            ConstString part = platform_pull_apart.GetLastPathComponent();
+            platform_pull_apart.RemoveLastPathComponent();
+            if (part.IsEmpty() || part == unix_root_dir)
+                break;
+            path_parts.push_back (part.AsCString());
+        }
+        const size_t path_parts_size = path_parts.size(); 
+
+        size_t num_module_search_paths = module_search_paths_ptr->GetSize();
+        for (size_t i = 0; i < num_module_search_paths; ++i)
+        {
+            // Create a new FileSpec with this module_search_paths_ptr
+            // plus just the filename ("UIFoundation"), then the parent 
+            // dir plus filename ("UIFoundation.framework/UIFoundation")
+            // etc - up to four names (to handle 
"Foo.framework/Contents/MacOS/Foo")
+
+            for (size_t j = 0; j < 4 && j < path_parts_size - 1; ++j)
+            {
+                FileSpec path_to_try 
(module_search_paths_ptr->GetFileSpecAtIndex (i));
+
+                // Add the components backwards.  For 
.../PrivateFrameworks/UIFoundation.framework/UIFoundation
+                // path_parts is
+                //   [0] UIFoundation
+                //   [1] UIFoundation.framework
+                //   [2] PrivateFrameworks
+                //
+                // and if 'j' is 2, we want to append path_parts[1] and then 
path_parts[0], aka
+                // 'UIFoundation.framework/UIFoundation', to the 
module_search_paths_ptr path.
+
+                for (int k = j; k >= 0; --k)
+                {
+                    path_to_try.AppendPathComponent (path_parts[k]);
+                }
+
+                if (path_to_try.Exists())
+                {
+                    ModuleSpec new_module_spec (module_spec);
+                    new_module_spec.GetFileSpec() = path_to_try;
+                    Error new_error (Platform::GetSharedModule 
(new_module_spec,
+                                                                process,
+                                                                module_sp,
+                                                                NULL,
+                                                                
old_module_sp_ptr,
+                                                                
did_create_ptr));
+                    
+                    if (module_sp)
+                    {
+                        module_sp->SetPlatformFileSpec (path_to_try);
+                        return new_error;
+                    }
+                }
+            }
+        }
+    }
+
     const bool always_create = false;
     error = ModuleList::GetSharedModule (module_spec,
                                          module_sp,

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=272635&r1=272634&r2=272635&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp 
(original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp Mon 
Jun 13 22:49:13 2016
@@ -892,6 +892,76 @@ PlatformRemoteAppleWatch::GetSharedModul
     if (error.Success())
         return error;
 
+    // See if the file is present in any of the module_search_paths_ptr 
directories.
+    if (!module_sp && module_search_paths_ptr && platform_file)
+    {
+        // create a vector of all the file / directory names in platform_file
+        // e.g. this might be 
/System/Library/PrivateFrameworks/UIFoundation.framework/UIFoundation
+        //
+        // We'll need to look in the module_search_paths_ptr directories for
+        // both "UIFoundation" and "UIFoundation.framework" -- most likely the
+        // latter will be the one we find there.
+
+        FileSpec platform_pull_apart (platform_file);
+        std::vector<std::string> path_parts;
+        ConstString unix_root_dir("/");
+        while (true)
+        {
+            ConstString part = platform_pull_apart.GetLastPathComponent();
+            platform_pull_apart.RemoveLastPathComponent();
+            if (part.IsEmpty() || part == unix_root_dir)
+                break;
+            path_parts.push_back (part.AsCString());
+        }
+        const size_t path_parts_size = path_parts.size(); 
+
+        size_t num_module_search_paths = module_search_paths_ptr->GetSize();
+        for (size_t i = 0; i < num_module_search_paths; ++i)
+        {
+            // Create a new FileSpec with this module_search_paths_ptr
+            // plus just the filename ("UIFoundation"), then the parent 
+            // dir plus filename ("UIFoundation.framework/UIFoundation")
+            // etc - up to four names (to handle 
"Foo.framework/Contents/MacOS/Foo")
+
+            for (size_t j = 0; j < 4 && j < path_parts_size - 1; ++j)
+            {
+                FileSpec path_to_try 
(module_search_paths_ptr->GetFileSpecAtIndex (i));
+
+                // Add the components backwards.  For 
.../PrivateFrameworks/UIFoundation.framework/UIFoundation
+                // path_parts is
+                //   [0] UIFoundation
+                //   [1] UIFoundation.framework
+                //   [2] PrivateFrameworks
+                //
+                // and if 'j' is 2, we want to append path_parts[1] and then 
path_parts[0], aka
+                // 'UIFoundation.framework/UIFoundation', to the 
module_search_paths_ptr path.
+
+                for (int k = j; k >= 0; --k)
+                {
+                    path_to_try.AppendPathComponent (path_parts[k]);
+                }
+
+                if (path_to_try.Exists())
+                {
+                    ModuleSpec new_module_spec (module_spec);
+                    new_module_spec.GetFileSpec() = path_to_try;
+                    Error new_error (Platform::GetSharedModule 
(new_module_spec,
+                                                                process,
+                                                                module_sp,
+                                                                NULL,
+                                                                
old_module_sp_ptr,
+                                                                
did_create_ptr));
+                    
+                    if (module_sp)
+                    {
+                        module_sp->SetPlatformFileSpec (path_to_try);
+                        return new_error;
+                    }
+                }
+            }
+        }
+    }
+
     const bool always_create = false;
     error = ModuleList::GetSharedModule (module_spec,
                                          module_sp,

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=272635&r1=272634&r2=272635&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp Mon Jun 13 
22:49:13 2016
@@ -905,6 +905,76 @@ PlatformRemoteiOS::GetSharedModule (cons
     if (error.Success())
         return error;
 
+    // See if the file is present in any of the module_search_paths_ptr 
directories.
+    if (!module_sp && module_search_paths_ptr && platform_file)
+    {
+        // create a vector of all the file / directory names in platform_file
+        // e.g. this might be 
/System/Library/PrivateFrameworks/UIFoundation.framework/UIFoundation
+        //
+        // We'll need to look in the module_search_paths_ptr directories for
+        // both "UIFoundation" and "UIFoundation.framework" -- most likely the
+        // latter will be the one we find there.
+
+        FileSpec platform_pull_apart (platform_file);
+        std::vector<std::string> path_parts;
+        ConstString unix_root_dir("/");
+        while (true)
+        {
+            ConstString part = platform_pull_apart.GetLastPathComponent();
+            platform_pull_apart.RemoveLastPathComponent();
+            if (part.IsEmpty() || part == unix_root_dir)
+                break;
+            path_parts.push_back (part.AsCString());
+        }
+        const size_t path_parts_size = path_parts.size(); 
+
+        size_t num_module_search_paths = module_search_paths_ptr->GetSize();
+        for (size_t i = 0; i < num_module_search_paths; ++i)
+        {
+            // Create a new FileSpec with this module_search_paths_ptr
+            // plus just the filename ("UIFoundation"), then the parent 
+            // dir plus filename ("UIFoundation.framework/UIFoundation")
+            // etc - up to four names (to handle 
"Foo.framework/Contents/MacOS/Foo")
+
+            for (size_t j = 0; j < 4 && j < path_parts_size - 1; ++j)
+            {
+                FileSpec path_to_try 
(module_search_paths_ptr->GetFileSpecAtIndex (i));
+
+                // Add the components backwards.  For 
.../PrivateFrameworks/UIFoundation.framework/UIFoundation
+                // path_parts is
+                //   [0] UIFoundation
+                //   [1] UIFoundation.framework
+                //   [2] PrivateFrameworks
+                //
+                // and if 'j' is 2, we want to append path_parts[1] and then 
path_parts[0], aka
+                // 'UIFoundation.framework/UIFoundation', to the 
module_search_paths_ptr path.
+
+                for (int k = j; k >= 0; --k)
+                {
+                    path_to_try.AppendPathComponent (path_parts[k]);
+                }
+
+                if (path_to_try.Exists())
+                {
+                    ModuleSpec new_module_spec (module_spec);
+                    new_module_spec.GetFileSpec() = path_to_try;
+                    Error new_error (Platform::GetSharedModule 
(new_module_spec,
+                                                                process,
+                                                                module_sp,
+                                                                NULL,
+                                                                
old_module_sp_ptr,
+                                                                
did_create_ptr));
+                    
+                    if (module_sp)
+                    {
+                        module_sp->SetPlatformFileSpec (path_to_try);
+                        return new_error;
+                    }
+                }
+            }
+        }
+    }
+
     const bool always_create = false;
     error = ModuleList::GetSharedModule (module_spec,
                                          module_sp,


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to