[Lldb-commits] [lldb] r154520 - in /lldb/branches/lldb-platform-work/source/Plugins/Platform: MacOSX/PlatformMacOSX.cpp MacOSX/PlatformMacOSX.h MacOSX/PlatformRemoteiOS.cpp MacOSX/PlatformRemoteiOS.h MacOSX/PlatformiOSSimulator.cpp MacOSX/PlatformiOSSimulator.h POSIX/PlatformPOSIX.cpp POSIX/PlatformPOSIX.h

Johnny Chen johnny.chen at apple.com
Wed Apr 11 11:53:17 PDT 2012


Author: johnny
Date: Wed Apr 11 13:53:16 2012
New Revision: 154520

URL: http://llvm.org/viewvc/llvm-project?rev=154520&view=rev
Log:
Refactoring: move the PlatformMacOSX::GetFile()/GetFileSize() functions upward to PlatformPOSIX.

Modified:
    lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
    lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
    lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h
    lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp?rev=154520&r1=154519&r2=154520&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.cpp Wed Apr 11 13:53:16 2012
@@ -130,9 +130,9 @@
 }
 
 Error
-PlatformMacOSX::GetFile (const FileSpec &platform_file, 
-                         const UUID *uuid_ptr,
-                         FileSpec &local_file)
+PlatformMacOSX::GetSymbolFile (const FileSpec &platform_file, 
+                               const UUID *uuid_ptr,
+                               FileSpec &local_file)
 {
     if (IsRemote())
     {
@@ -155,82 +155,3 @@
 #endif
 }
 
-lldb::user_id_t
-PlatformMacOSX::GetFileSize (const FileSpec& file_spec)
-{
-    if (IsHost())
-    {
-        return Host::GetFileSize(file_spec);
-    }
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->GetFileSize(file_spec);
-    return Platform::GetFileSize(file_spec);
-}
-
-lldb_private::Error
-PlatformMacOSX::GetFile (const lldb_private::FileSpec& source /* remote file path */,
-                         const lldb_private::FileSpec& destination /* local file path */)
-{
-#define GETFILE_CHUNK_SIZE 1024
-    if (IsHost())
-    {
-        if (FileSpec::Equal(source, destination, true))
-            return Error("local scenario->source and destination are the same file path: no operation performed");
-        // cp src dst
-        char src_path[PATH_MAX];
-        char dst_path[PATH_MAX];
-        if (!source.GetPath(src_path, sizeof(src_path)) || !destination.GetPath(dst_path, sizeof(dst_path)))
-        {
-            return Error("max path length exceeded?");
-        }
-        std::stringstream cp_command("cp ");
-        cp_command << src_path << ' ' << dst_path;
-        if (RunShellCommand(cp_command.str()) != 0)
-            return Error("unable to perform copy");
-        return Error();
-    }
-    else if (IsRemote() && m_remote_platform_sp)
-    {
-        // open src and dst
-        // read, read, read, ...
-        // close src
-        // write dst
-        // close dst
-        user_id_t fd_src = OpenFile(source, File::eOpenOptionRead, File::ePermissionsDefault);
-        user_id_t fd_dst = Host::OpenFile(destination,
-                                          File::eOpenOptionCanCreate|File::eOpenOptionWrite,
-                                          File::ePermissionsDefault);
-        if (fd_src == UINT64_MAX)
-            return Error("unable to open source file");
-        if (fd_dst == UINT64_MAX)
-            return Error("unable to open destination file");
-
-        lldb::DataBufferSP buffer_sp(new DataBufferHeap(GETFILE_CHUNK_SIZE, 0));
-        uint8_t *cursor = buffer_sp->GetBytes();
-        Error err;
-        uint64_t offset = 0;
-        while (err.Success())
-        {
-            user_id_t n_read = ReadFile(fd_src, offset, cursor, GETFILE_CHUNK_SIZE);
-            if (n_read == UINT32_MAX)
-                return Error("error during read operation");
-            // Break out of the loop once we reach end of file.
-            if (n_read == 0)
-                break;
-
-            if (!Host::WriteFile(fd_dst, offset, cursor, n_read))
-                return Error("unable to write to destination file");
-
-            offset += n_read;
-            cursor += n_read;
-
-        }
-        // Ignore the close error of src.
-        CloseFile(fd_src);
-        // And close the dst file descriptot.
-        if (!Host::CloseFile(fd_dst))
-            return Error("unable to close destination file");
-        return Error();
-    }
-    return Platform::GetFile(source,destination);
-}

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h?rev=154520&r1=154519&r2=154520&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformMacOSX.h Wed Apr 11 13:53:16 2012
@@ -77,16 +77,9 @@
     }
 
     lldb_private::Error
-    GetFile (const lldb_private::FileSpec &platform_file, 
-             const lldb_private::UUID *uuid_ptr,
-             lldb_private::FileSpec &local_file);
-    
-    lldb::user_id_t
-    GetFileSize (const lldb_private::FileSpec& file_spec);
-
-    lldb_private::Error
-    GetFile (const lldb_private::FileSpec& source,
-             const lldb_private::FileSpec& destination);
+    GetSymbolFile (const lldb_private::FileSpec &platform_file, 
+                   const lldb_private::UUID *uuid_ptr,
+                   lldb_private::FileSpec &local_file);
     
     virtual bool
     GetSupportedArchitectureAtIndex (uint32_t idx, 

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp?rev=154520&r1=154519&r2=154520&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp Wed Apr 11 13:53:16 2012
@@ -320,9 +320,9 @@
 }
 
 Error
-PlatformRemoteiOS::GetFile (const FileSpec &platform_file, 
-                            const UUID *uuid_ptr,
-                            FileSpec &local_file)
+PlatformRemoteiOS::GetSymbolFile (const FileSpec &platform_file, 
+                                  const UUID *uuid_ptr,
+                                  FileSpec &local_file)
 {
     Error error;
     char platform_file_path[PATH_MAX];
@@ -392,7 +392,7 @@
     const FileSpec &platform_file = module_spec.GetFileSpec();
 
     FileSpec local_file;
-    Error error (GetFile (platform_file, module_spec.GetUUIDPtr(), local_file));
+    Error error (GetSymbolFile (platform_file, module_spec.GetUUIDPtr(), local_file));
     if (error.Success())
     {
         error = ResolveExecutable (local_file, module_spec.GetArchitecture(), module_sp, module_search_paths_ptr);

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h?rev=154520&r1=154519&r2=154520&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h Wed Apr 11 13:53:16 2012
@@ -89,9 +89,9 @@
     GetStatus (lldb_private::Stream &strm);
 
     virtual lldb_private::Error
-    GetFile (const lldb_private::FileSpec &platform_file, 
-             const lldb_private::UUID *uuid_ptr,
-             lldb_private::FileSpec &local_file);
+    GetSymbolFile (const lldb_private::FileSpec &platform_file, 
+                   const lldb_private::UUID *uuid_ptr,
+                   lldb_private::FileSpec &local_file);
 
     virtual lldb_private::Error
     GetSharedModule (const lldb_private::ModuleSpec &module_spec,

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp?rev=154520&r1=154519&r2=154520&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.cpp Wed Apr 11 13:53:16 2012
@@ -287,9 +287,9 @@
 }
 
 Error
-PlatformiOSSimulator::GetFile (const FileSpec &platform_file, 
-                               const UUID *uuid_ptr,
-                               FileSpec &local_file)
+PlatformiOSSimulator::GetSymbolFile (const FileSpec &platform_file, 
+                                     const UUID *uuid_ptr,
+                                     FileSpec &local_file)
 {
     Error error;
     char platform_file_path[PATH_MAX];
@@ -342,7 +342,7 @@
     Error error;
     FileSpec local_file;
     const FileSpec &platform_file = module_spec.GetFileSpec();
-    error = GetFile (platform_file, module_spec.GetUUIDPtr(), local_file);
+    error = GetSymbolFile (platform_file, module_spec.GetUUIDPtr(), local_file);
     if (error.Success())
     {
         error = ResolveExecutable (local_file, module_spec.GetArchitecture(), module_sp, module_search_paths_ptr);

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h?rev=154520&r1=154519&r2=154520&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformiOSSimulator.h Wed Apr 11 13:53:16 2012
@@ -89,9 +89,9 @@
     GetStatus (lldb_private::Stream &strm);
 
     virtual lldb_private::Error
-    GetFile (const lldb_private::FileSpec &platform_file, 
-             const lldb_private::UUID *uuid_ptr,
-             lldb_private::FileSpec &local_file);
+    GetSymbolFile (const lldb_private::FileSpec &platform_file, 
+                   const lldb_private::UUID *uuid_ptr,
+                   lldb_private::FileSpec &local_file);
 
     virtual lldb_private::Error
     GetSharedModule (const lldb_private::ModuleSpec &module_spec,

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=154520&r1=154519&r2=154520&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Wed Apr 11 13:53:16 2012
@@ -321,3 +321,83 @@
     }
     return Platform::PutFile(source,destination,uid,gid);
 }
+
+lldb::user_id_t
+PlatformPOSIX::GetFileSize (const FileSpec& file_spec)
+{
+    if (IsHost())
+    {
+        return Host::GetFileSize(file_spec);
+    }
+    if (IsRemote() && m_remote_platform_sp)
+        return m_remote_platform_sp->GetFileSize(file_spec);
+    return Platform::GetFileSize(file_spec);
+}
+
+lldb_private::Error
+PlatformPOSIX::GetFile (const lldb_private::FileSpec& source /* remote file path */,
+                         const lldb_private::FileSpec& destination /* local file path */)
+{
+#define GETFILE_CHUNK_SIZE 1024
+    if (IsHost())
+    {
+        if (FileSpec::Equal(source, destination, true))
+            return Error("local scenario->source and destination are the same file path: no operation performed");
+        // cp src dst
+        char src_path[PATH_MAX];
+        char dst_path[PATH_MAX];
+        if (!source.GetPath(src_path, sizeof(src_path)) || !destination.GetPath(dst_path, sizeof(dst_path)))
+        {
+            return Error("max path length exceeded?");
+        }
+        StreamString cp_command;
+        cp_command.Printf("cp %s %s", src_path, dst_path);
+        if (RunShellCommand(cp_command.GetData()) != 0)
+            return Error("unable to perform copy");
+        return Error();
+    }
+    else if (IsRemote() && m_remote_platform_sp)
+    {
+        // open src and dst
+        // read, read, read, ...
+        // close src
+        // write dst
+        // close dst
+        user_id_t fd_src = OpenFile(source, File::eOpenOptionRead, File::ePermissionsDefault);
+        user_id_t fd_dst = Host::OpenFile(destination,
+                                          File::eOpenOptionCanCreate|File::eOpenOptionWrite,
+                                          File::ePermissionsDefault);
+        if (fd_src == UINT64_MAX)
+            return Error("unable to open source file");
+        if (fd_dst == UINT64_MAX)
+            return Error("unable to open destination file");
+
+        lldb::DataBufferSP buffer_sp(new DataBufferHeap(GETFILE_CHUNK_SIZE, 0));
+        uint8_t *cursor = buffer_sp->GetBytes();
+        Error err;
+        uint64_t offset = 0;
+        while (err.Success())
+        {
+            user_id_t n_read = ReadFile(fd_src, offset, cursor, GETFILE_CHUNK_SIZE);
+            if (n_read == UINT32_MAX)
+                return Error("error during read operation");
+            // Break out of the loop once we reach end of file.
+            if (n_read == 0)
+                break;
+
+            if (!Host::WriteFile(fd_dst, offset, cursor, n_read))
+                return Error("unable to write to destination file");
+
+            offset += n_read;
+            cursor += n_read;
+
+        }
+        // Ignore the close error of src.
+        CloseFile(fd_src);
+        // And close the dst file descriptot.
+        if (!Host::CloseFile(fd_dst))
+            return Error("unable to close destination file");
+        return Error();
+    }
+    return Platform::GetFile(source,destination);
+}

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h?rev=154520&r1=154519&r2=154520&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h Wed Apr 11 13:53:16 2012
@@ -56,6 +56,13 @@
     WriteFile (lldb::user_id_t fd, uint64_t offset,
                void* data, size_t len);
     
+    virtual lldb::user_id_t
+    GetFileSize (const lldb_private::FileSpec& file_spec);
+
+    virtual lldb_private::Error
+    GetFile (const lldb_private::FileSpec& source,
+             const lldb_private::FileSpec& destination);
+    
     virtual uint32_t
     RunShellCommand (const std::string &command_line);
     





More information about the lldb-commits mailing list