[Lldb-commits] [lldb] r154465 - in /lldb/branches/lldb-platform-work: include/lldb/Target/ lldb.xcodeproj/ source/Commands/ source/Host/common/ source/Host/macosx/ source/Plugins/Platform/MacOSX/ source/Plugins/Platform/POSIX/ source/Plugins/Platform/gdb-server/ source/Plugins/Process/gdb-remote/ source/Target/

Enrico Granata egranata at apple.com
Tue Apr 10 17:55:26 PDT 2012


Author: enrico
Date: Tue Apr 10 19:55:26 2012
New Revision: 154465

URL: http://llvm.org/viewvc/llvm-project?rev=154465&view=rev
Log:
Some architectural changes to support passing connection options to platforms - implementation of rsync support to copy files over a remote connection (should be faster than the chunk-read,write algorithm in most cases - basic SSH support to run shell commands (not hooked up yet - WIP)

Added:
    lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/
    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/include/lldb/Target/Platform.h
    lldb/branches/lldb-platform-work/lldb.xcodeproj/project.pbxproj
    lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp
    lldb/branches/lldb-platform-work/source/Host/common/Host.cpp
    lldb/branches/lldb-platform-work/source/Host/macosx/Host.mm
    lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.h
    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/gdb-server/PlatformRemoteGDBServer.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/branches/lldb-platform-work/source/Target/Platform.cpp

Modified: lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h (original)
+++ lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h Tue Apr 10 19:55:26 2012
@@ -506,6 +506,60 @@
         virtual Error
         GetFile (const FileSpec& source,
                  const FileSpec& destination);
+        
+        virtual bool
+        GetSupportsRSync ()
+        {
+            return m_supports_rsync;
+        }
+        
+        virtual void
+        SetSupportsRSync(bool rsync)
+        {
+            m_supports_rsync = rsync;
+        }
+        
+        virtual const char*
+        GetRSyncArgs ()
+        {
+            return m_rsync_args.c_str();
+        }
+        
+        virtual void
+        SetRSyncArgs (const char* args)
+        {
+            m_rsync_args.assign(args);
+        }
+        
+        virtual bool
+        GetSupportsSSH ()
+        {
+            return m_supports_ssh;
+        }
+        
+        virtual void
+        SetSupportsSSH(bool rsync)
+        {
+            m_supports_ssh = rsync;
+        }
+        
+        virtual const char*
+        GetSSHArgs ()
+        {
+            return m_ssh_args.c_str();
+        }
+        
+        virtual void
+        SetSSHArgs (const char* args)
+        {
+            m_ssh_args.assign(args);
+        }
+        
+        virtual Options *
+        GetConnectionOptions (CommandInterpreter& interpreter)
+        {
+            return NULL;
+        }
                 
     protected:
         bool m_is_host;
@@ -531,7 +585,11 @@
         IDToNameMap m_gid_map;
         uint32_t m_max_uid_name_len;
         uint32_t m_max_gid_name_len;
-        
+        bool m_supports_rsync;
+        std::string m_rsync_args;
+        bool m_supports_ssh;
+        std::string m_ssh_args;
+
         const char *
         GetCachedUserName (uint32_t uid)
         {

Modified: lldb/branches/lldb-platform-work/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/lldb.xcodeproj/project.pbxproj?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/branches/lldb-platform-work/lldb.xcodeproj/project.pbxproj Tue Apr 10 19:55:26 2012
@@ -469,7 +469,8 @@
 		941BCC8214E48C4000BB969C /* SBTypeSynthetic.h in Headers */ = {isa = PBXBuildFile; fileRef = 9461568914E355F2003A195C /* SBTypeSynthetic.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		9443B122140C18C40013457C /* SBData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9443B121140C18C10013457C /* SBData.cpp */; };
 		9443B123140C26AB0013457C /* SBData.h in Headers */ = {isa = PBXBuildFile; fileRef = 9443B120140C18A90013457C /* SBData.h */; settings = {ATTRIBUTES = (Public, ); }; };
-		945E8D7E152F6AA80019BCCD /* StreamGDBRemote.h in Headers */ = {isa = PBXBuildFile; fileRef = 945E8D7D152F6AA80019BCCD /* StreamGDBRemote.h */; };
+		945759671534941F005A9070 /* PlatformPOSIX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 945759651534941F005A9070 /* PlatformPOSIX.cpp */; };
+		945759681534941F005A9070 /* PlatformPOSIX.h in Headers */ = {isa = PBXBuildFile; fileRef = 945759661534941F005A9070 /* PlatformPOSIX.h */; };
 		945E8D80152F6AB40019BCCD /* StreamGDBRemote.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 945E8D7F152F6AB40019BCCD /* StreamGDBRemote.cpp */; };
 		94611EB213CCA4A4003A22AF /* RefCounter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94611EB113CCA4A4003A22AF /* RefCounter.cpp */; };
 		9461569A14E358A6003A195C /* SBTypeFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9461568A14E35621003A195C /* SBTypeFilter.cpp */; };
@@ -517,7 +518,6 @@
 		B299580B14F2FA1400050A04 /* DisassemblerLLVMC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B299580A14F2FA1400050A04 /* DisassemblerLLVMC.cpp */; };
 		B2A58722143119810092BFBA /* SBWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = B2A58721143119810092BFBA /* SBWatchpoint.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		B2A58724143119D50092BFBA /* SBWatchpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B2A58723143119D50092BFBA /* SBWatchpoint.cpp */; };
-		B2FA4F84152FBB0F005535AB /* lldb-platform in Resources */ = {isa = PBXBuildFile; fileRef = 26DC6A101337FE6900FF7998 /* lldb-platform */; };
 		ED236E0814F84F6800153F6F /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDB919B414F6F10D008FF64B /* Security.framework */; };
 		ED88244E15114A9200BC98B9 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EDB919B414F6F10D008FF64B /* Security.framework */; };
 		ED88245015114CA200BC98B9 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED88244F15114CA200BC98B9 /* main.mm */; };
@@ -626,13 +626,6 @@
 			remoteGlobalIDString = 2689FFC913353D7A00698AC0;
 			remoteInfo = "lldb-core";
 		};
-		B2FA4F82152FBAF2005535AB /* PBXContainerItemProxy */ = {
-			isa = PBXContainerItemProxy;
-			containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
-			proxyType = 1;
-			remoteGlobalIDString = 26DC6A0F1337FE6900FF7998;
-			remoteInfo = "lldb-platform";
-		};
 		94E829C8152D33B4006F96A3 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
 			containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */;
@@ -1419,6 +1412,8 @@
 		9415F61713B2C0EF00A52B36 /* FormatManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = FormatManager.cpp; path = source/Core/FormatManager.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
 		9443B120140C18A90013457C /* SBData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SBData.h; path = include/lldb/API/SBData.h; sourceTree = "<group>"; };
 		9443B121140C18C10013457C /* SBData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBData.cpp; path = source/API/SBData.cpp; sourceTree = "<group>"; };
+		945759651534941F005A9070 /* PlatformPOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformPOSIX.cpp; path = POSIX/PlatformPOSIX.cpp; sourceTree = "<group>"; };
+		945759661534941F005A9070 /* PlatformPOSIX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformPOSIX.h; path = POSIX/PlatformPOSIX.h; sourceTree = "<group>"; };
 		945E8D7D152F6AA80019BCCD /* StreamGDBRemote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StreamGDBRemote.h; path = include/lldb/Core/StreamGDBRemote.h; sourceTree = "<group>"; };
 		945E8D7F152F6AB40019BCCD /* StreamGDBRemote.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StreamGDBRemote.cpp; path = source/Core/StreamGDBRemote.cpp; sourceTree = "<group>"; };
 		94611EAF13CCA363003A22AF /* RefCounter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RefCounter.h; path = include/lldb/Utility/RefCounter.h; sourceTree = "<group>"; };
@@ -2884,6 +2879,7 @@
 		26C5577E132575B6008FD8FE /* Platform */ = {
 			isa = PBXGroup;
 			children = (
+				9457596415349416005A9070 /* POSIX */,
 				2694E99814FC0BB30076DE67 /* FreeBSD */,
 				264A97BC133918A30017F0BE /* GDB Server */,
 				2694E99F14FC0BBD0076DE67 /* Linux */,
@@ -3126,6 +3122,15 @@
 			path = source/Host/common;
 			sourceTree = "<group>";
 		};
+		9457596415349416005A9070 /* POSIX */ = {
+			isa = PBXGroup;
+			children = (
+				945759651534941F005A9070 /* PlatformPOSIX.cpp */,
+				945759661534941F005A9070 /* PlatformPOSIX.h */,
+			);
+			name = POSIX;
+			sourceTree = "<group>";
+		};
 		EDC6D49114E5C15C001B75F8 /* launcherXPCService */ = {
 			isa = PBXGroup;
 			children = (
@@ -3217,6 +3222,7 @@
 				2694E99E14FC0BB30076DE67 /* PlatformFreeBSD.h in Headers */,
 				2694E9A514FC0BBD0076DE67 /* PlatformLinux.h in Headers */,
 				2663E379152BD1890091EC22 /* ReadWriteLock.h in Headers */,
+				945759681534941F005A9070 /* PlatformPOSIX.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -3932,6 +3938,7 @@
 				2694E99D14FC0BB30076DE67 /* PlatformFreeBSD.cpp in Sources */,
 				2694E9A414FC0BBD0076DE67 /* PlatformLinux.cpp in Sources */,
 				945E8D80152F6AB40019BCCD /* StreamGDBRemote.cpp in Sources */,
+				945759671534941F005A9070 /* PlatformPOSIX.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -4039,11 +4046,6 @@
 			target = 2689FFC913353D7A00698AC0 /* lldb-core */;
 			targetProxy = 26DC6A151337FE7300FF7998 /* PBXContainerItemProxy */;
 		};
-		B2FA4F83152FBAF2005535AB /* PBXTargetDependency */ = {
-			isa = PBXTargetDependency;
-			target = 26DC6A0F1337FE6900FF7998 /* lldb-platform */;
-			targetProxy = B2FA4F82152FBAF2005535AB /* PBXContainerItemProxy */;
-		};
 		94E829C9152D33B4006F96A3 /* PBXTargetDependency */ = {
 			isa = PBXTargetDependency;
 			target = 26DC6A0F1337FE6900FF7998 /* lldb-platform */;

Modified: lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp Tue Apr 10 19:55:26 2012
@@ -872,11 +872,21 @@
         }
         else
         {
-            result.AppendError ("no platform us currently selected\n");
+            result.AppendError ("no platform is currently selected\n");
             result.SetStatus (eReturnStatusFailed);            
         }
         return result.Succeeded();
     }
+    
+    virtual Options *
+    GetOptions ()
+    {
+        PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
+        if (platform_sp)
+            return platform_sp->GetConnectionOptions(m_interpreter);
+        return NULL;
+    }
+
 };
 
 //----------------------------------------------------------------------

Modified: lldb/branches/lldb-platform-work/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Host/common/Host.cpp?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Host/common/Host.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Host/common/Host.cpp Tue Apr 10 19:55:26 2012
@@ -1287,13 +1287,9 @@
                 uint32_t flags,
                 mode_t mode)
 {
-    std::string path(512, 0);
-    uint32_t len = file_spec.GetPath(&path[0], 512);
-    if (len >= 512)
-    {
-        path = std::string(len+1,' ');
-        len = file_spec.GetPath(&path[0], len);
-    }
+    std::string path;
+    if (file_spec.GetPath(path) == 0)
+        return UINT64_MAX;
     FileSP file_sp(new File(path.c_str(),flags,mode));
     if (file_sp->IsValid() == false)
         return UINT64_MAX;

Modified: lldb/branches/lldb-platform-work/source/Host/macosx/Host.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Host/macosx/Host.mm?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Host/macosx/Host.mm (original)
+++ lldb/branches/lldb-platform-work/source/Host/macosx/Host.mm Tue Apr 10 19:55:26 2012
@@ -1847,13 +1847,9 @@
 uint32_t
 Host::RunProgramAndGetExitCode (const FileSpec& file_spec)
 {
-    std::string path(512, 0);
-    uint32_t len = file_spec.GetPath(&path[0], 512);
-    if (len >= 512)
-    {
-        path = std::string(len+1,' ');
-        len = file_spec.GetPath(&path[0], len);
-    }
+    std::string path;
+    if (file_spec.GetPath(path) == 0)
+        return UINT32_MAX;
     return ::system(path.c_str());
 }
 

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Tue Apr 10 19:55:26 2012
@@ -27,8 +27,7 @@
 /// Default Constructor
 //------------------------------------------------------------------
 PlatformDarwin::PlatformDarwin (bool is_host) :
-    Platform(is_host),  // This is the local host platform
-    m_remote_platform_sp (),
+    PlatformPOSIX(is_host),  // This is the local host platform
     m_developer_directory ()
 {
 }
@@ -388,26 +387,27 @@
         if (!m_remote_platform_sp)
             m_remote_platform_sp = Platform::Create ("remote-gdb-server", error);
 
-        if (m_remote_platform_sp)
-        {
-            if (error.Success())
-            {
-                if (m_remote_platform_sp)
-                {
-                    error = m_remote_platform_sp->ConnectRemote (args);
-                }
-                else
-                {
-                    error.SetErrorString ("\"platform connect\" takes a single argument: <connect-url>");
-                }
-            }
-        }
+        if (m_remote_platform_sp && error.Success())
+            error = m_remote_platform_sp->ConnectRemote (args);
         else
             error.SetErrorString ("failed to create a 'remote-gdb-server' platform");
         
         if (error.Fail())
             m_remote_platform_sp.reset();
     }
+    
+    if (error.Success() && m_remote_platform_sp)
+    {
+        if (m_options.get())
+        {
+            PlatformPOSIX::POSIXPlatformConnectionOptions* posix_options = (PlatformPOSIX::POSIXPlatformConnectionOptions*)m_options.get();
+            if (posix_options->m_rsync)
+            {
+                SetSupportsRSync(true);
+                SetRSyncArgs(posix_options->m_rsync_args.c_str());
+            }
+        }
+    }
 
     return error;
 }

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.h?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/MacOSX/PlatformDarwin.h Tue Apr 10 19:55:26 2012
@@ -14,9 +14,9 @@
 // C++ Includes
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Target/Platform.h"
+#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
 
-class PlatformDarwin : public lldb_private::Platform
+class PlatformDarwin : public PlatformPOSIX
 {
 public:
     PlatformDarwin (bool is_host);
@@ -103,11 +103,14 @@
     x86GetSupportedArchitectureAtIndex (uint32_t idx, lldb_private::ArchSpec &arch);
 
 protected:
-    lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a remote darwin OS
     std::string m_developer_directory;
     
     const char *
     GetDeveloperDirectory();
+    
+    class CommandOptions
+    {
+    };
 
 private:
     DISALLOW_COPY_AND_ASSIGN (PlatformDarwin);

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=154465&r1=154464&r2=154465&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 Tue Apr 10 19:55:26 2012
@@ -155,184 +155,6 @@
 #endif
 }
 
-uint32_t
-PlatformMacOSX::RunShellCommand (const std::string &command_line)
-{
-    if (IsHost())
-    {
-        return Host::RunProgramAndGetExitCode(FileSpec(command_line.c_str(),false));
-    }
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->RunShellCommand(command_line);
-    return Platform::RunShellCommand(command_line);
-}
-
-uint32_t
-PlatformMacOSX::MakeDirectory (const std::string &path,
-                               mode_t mode)
-{
-    if (IsHost())
-    {
-        return Host::MakeDirectory (path.c_str(), mode);
-    }
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->MakeDirectory(path, mode);
-    return Platform::MakeDirectory(path,mode);
-}
-
-lldb::user_id_t
-PlatformMacOSX::OpenFile (const FileSpec& file_spec,
-          uint32_t flags,
-          mode_t mode)
-{
-    if (IsHost())
-    {
-        return Host::OpenFile(file_spec, flags, mode);
-    }
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->OpenFile(file_spec, flags, mode);
-    return Platform::OpenFile(file_spec, flags, mode);
-}
-
-bool
-PlatformMacOSX::CloseFile (lldb::user_id_t fd)
-{
-    if (IsHost())
-    {
-        return Host::CloseFile(fd);
-    }
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->CloseFile(fd);
-    return Platform::CloseFile(fd);
-}
-
-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);
-}
-
-uint32_t
-PlatformMacOSX::ReadFile (lldb::user_id_t fd, uint64_t offset,
-                          void *data_ptr, size_t len)
-{
-    if (IsHost())
-    {
-        return Host::ReadFile(fd, offset, data_ptr, len);
-    }
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->ReadFile(fd, offset, data_ptr, len);
-    return Platform::ReadFile(fd, offset, data_ptr, len);
-}
-
-uint32_t
-PlatformMacOSX::WriteFile (lldb::user_id_t fd, uint64_t offset,
-                           void* data, size_t len)
-{
-    if (IsHost())
-    {
-        return Host::WriteFile(fd, offset, data, len);
-    }
-    if (IsRemote() && m_remote_platform_sp)
-        return m_remote_platform_sp->WriteFile(fd, offset, data, len);
-    return Platform::WriteFile(fd, offset, data, len);
-}
-
-lldb_private::Error
-PlatformMacOSX::PutFile (const lldb_private::FileSpec& source,
-                         const lldb_private::FileSpec& destination,
-                         uint32_t uid,
-                         uint32_t gid)
-{
-#define PUTFILE_CHUNK_SIZE 1024
-    if (IsHost())
-    {
-        if (FileSpec::Equal(source, destination, true))
-            return Error();
-        // cp src dst
-        // chown uid:gid dst
-        std::string src_path(512, 0);
-        uint32_t len = source.GetPath(&src_path[0], 512);
-        if (len >= 512)
-        {
-            src_path = std::string(len+1,0);
-            len = source.GetPath(&src_path[0], len);
-        }
-        std::string dst_path(512, 0);
-        len = destination.GetPath(&dst_path[0], 512);
-        if (len >= 512)
-        {
-            src_path = std::string(len+1,0);
-            len = destination.GetPath(&dst_path[0], len);
-        }
-        std::stringstream cp_command("cp ");
-        cp_command << src_path << ' ' << dst_path;
-        if (RunShellCommand(cp_command.str()) != 0)
-            return Error("unable to perform copy");
-        if (uid == UINT32_MAX && gid == UINT32_MAX)
-            return Error();
-        std::stringstream chown_command("chown ");
-        if (uid != UINT32_MAX)
-            chown_command << uid;
-        if (gid != UINT32_MAX)
-            chown_command << ':' << gid;
-        chown_command << ' ' << dst_path;
-        if (RunShellCommand(chown_command.str()) != 0)
-            return Error("unable to perform chown");
-        return Error();
-    }
-    if (IsRemote() && m_remote_platform_sp)
-    {
-        // open
-        // read, write, read, write, ...
-        // close
-        // chown uid:gid dst
-        File source_file(source, File::eOpenOptionRead, File::ePermissionsUserRW);
-        if (!source_file.IsValid())
-            return Error("unable to open source file");
-        lldb::user_id_t dest_file = OpenFile(destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite | File::eOpenOptionTruncate,
-            File::ePermissionsUserRWX | File::ePermissionsGroupRX | File::ePermissionsWorldRX);
-        if (dest_file == UINT64_MAX)
-            return Error("unable to open target file");
-        lldb::DataBufferSP buffer_sp(new DataBufferHeap(PUTFILE_CHUNK_SIZE, 0));
-        Error err;
-        uint64_t offset = 0;
-        while (err.Success())
-        {
-            size_t read_data = PUTFILE_CHUNK_SIZE;
-            err = source_file.Read(buffer_sp->GetBytes(), read_data);
-            if (read_data)
-            {
-                WriteFile(dest_file, offset, buffer_sp->GetBytes(), read_data);
-                offset += read_data;
-            }
-            else
-                break;
-        }
-        CloseFile(dest_file);
-        if (uid == UINT32_MAX && gid == UINT32_MAX)
-            return Error();
-        std::string dst_path;
-        destination.GetPath(dst_path);
-        std::stringstream chown_command("chown ");
-        if (uid != UINT32_MAX)
-            chown_command << uid;
-        if (gid != UINT32_MAX)
-            chown_command << ':' << gid;
-        chown_command << ' ' << dst_path;
-        if (RunShellCommand(chown_command.str()) != 0)
-            return Error("unable to perform chown");
-        return Error();
-    }
-    return Platform::PutFile(source,destination,uid,gid);
-}
-
 lldb_private::Error
 PlatformMacOSX::GetFile (const lldb_private::FileSpec& source /* remote file path */,
                          const lldb_private::FileSpec& destination /* local file path */)

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=154465&r1=154464&r2=154465&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 Tue Apr 10 19:55:26 2012
@@ -81,42 +81,6 @@
              const lldb_private::UUID *uuid_ptr,
              lldb_private::FileSpec &local_file);
     
-    virtual uint32_t
-    RunShellCommand (const std::string &command_line);
-    
-    virtual uint32_t
-    MakeDirectory (const std::string &path,
-                   mode_t mode);
-    
-    virtual lldb_private::Error
-    PutFile (const lldb_private::FileSpec& source,
-             const lldb_private::FileSpec& destination,
-             uint32_t uid = UINT32_MAX,
-             uint32_t gid = UINT32_MAX);
-    
-    virtual lldb_private::Error
-    GetFile (const lldb_private::FileSpec& source,
-             const lldb_private::FileSpec& destination);
-                
-    virtual lldb::user_id_t
-    OpenFile (const lldb_private::FileSpec& file_spec,
-              uint32_t flags,
-              mode_t mode);
-    
-    virtual bool
-    CloseFile (lldb::user_id_t fd);
-    
-    virtual lldb::user_id_t
-    GetFileSize (const lldb_private::FileSpec& file_spec);
-
-    virtual uint32_t
-    ReadFile (lldb::user_id_t fd, uint64_t offset,
-              void *data_ptr, size_t len);
-    
-    virtual uint32_t
-    WriteFile (lldb::user_id_t fd, uint64_t offset,
-               void* data, size_t len);
-
     virtual bool
     GetSupportedArchitectureAtIndex (uint32_t idx, 
                                      lldb_private::ArchSpec &arch);

Added: 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=154465&view=auto
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (added)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Tue Apr 10 19:55:26 2012
@@ -0,0 +1,314 @@
+//===-- PlatformPOSIX.cpp ---------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "PlatformPOSIX.h"
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+
+#include "lldb/Core/DataBufferHeap.h"
+#include "lldb/Core/StreamString.h"
+#include "lldb/Host/FileSpec.h"
+#include "lldb/Host/Host.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+
+//------------------------------------------------------------------
+/// Default Constructor
+//------------------------------------------------------------------
+PlatformPOSIX::PlatformPOSIX (bool is_host) :
+Platform(is_host),  // This is the local host platform
+m_remote_platform_sp ()
+{
+}
+
+//------------------------------------------------------------------
+/// Destructor.
+///
+/// The destructor is virtual since this class is designed to be
+/// inherited from by the plug-in instance.
+//------------------------------------------------------------------
+PlatformPOSIX::~PlatformPOSIX()
+{
+}
+
+PlatformPOSIX::POSIXPlatformConnectionOptions::POSIXPlatformConnectionOptions (CommandInterpreter &interpreter) :
+Options (interpreter),
+m_rsync (false),
+m_rsync_args()
+{
+}
+
+PlatformPOSIX::POSIXPlatformConnectionOptions::~POSIXPlatformConnectionOptions ()
+{
+}
+
+Error
+PlatformPOSIX::POSIXPlatformConnectionOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
+{
+    Error error;
+    char short_option = (char) m_getopt_table[option_idx].val;
+    
+    switch (short_option)
+    {
+        case 'r':
+            m_rsync = true;
+            break;
+            
+        case 'R':
+            m_rsync_args.assign(option_arg);
+            break;
+            
+        default:
+            error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
+            break;
+    }
+    
+    return error;
+}
+
+void
+PlatformPOSIX::POSIXPlatformConnectionOptions::OptionParsingStarting ()
+{
+    m_rsync = false;
+    m_rsync_args.clear();
+}
+
+const OptionDefinition*
+PlatformPOSIX::POSIXPlatformConnectionOptions::GetDefinitions ()
+{
+    return g_option_table;
+}
+
+OptionDefinition
+PlatformPOSIX::POSIXPlatformConnectionOptions::g_option_table[] =
+{
+    {   LLDB_OPT_SET_ALL, false, "rsync"            , 'r', no_argument,       NULL, 0, eArgTypeNone         , "Enable rsync." },
+    {   LLDB_OPT_SET_ALL, false, "rsync-args"       , 'R', required_argument, NULL, 0, eArgTypeCommandName  , "Platform-specific arguments required for rsync to work." },
+    {   LLDB_OPT_SET_ALL, false, "ssh"              , 's', no_argument,       NULL, 0, eArgTypeNone         , "Enable SSH." },
+    {   LLDB_OPT_SET_ALL, false, "ssh-args"         , 'S', required_argument, NULL, 0, eArgTypeCommandName  , "Platform-specific arguments required for SSH to work." },
+    {  0              , false, NULL               ,  0 , 0                , NULL, 0, eArgTypeNone         , NULL }
+};
+
+Options *
+PlatformPOSIX::GetConnectionOptions (lldb_private::CommandInterpreter& interpreter)
+{
+    if (m_options.get() == NULL)
+        m_options.reset(new POSIXPlatformConnectionOptions(interpreter));
+    return m_options.get();
+}
+
+uint32_t
+PlatformPOSIX::RunShellCommand (const std::string &command_line)
+{
+    if (IsHost())
+    {
+        return Host::RunProgramAndGetExitCode(FileSpec(command_line.c_str(),false));
+    }
+    if (IsRemote())
+    {
+        if (GetSupportsSSH())
+        {
+            // run the command over SSH
+            StreamString command;
+            command.Printf("ssh %s %s",
+                           GetSSHArgs(),
+                           command_line.c_str());
+            return m_remote_platform_sp->RunShellCommand(command.GetData());
+        }
+        else if (m_remote_platform_sp)
+        {
+            // plain run the command
+            return m_remote_platform_sp->RunShellCommand(command_line);
+        }
+    }
+    return Platform::RunShellCommand(command_line);
+}
+
+uint32_t
+PlatformPOSIX::MakeDirectory (const std::string &path,
+                               mode_t mode)
+{
+    if (IsHost())
+    {
+        return Host::MakeDirectory (path.c_str(), mode);
+    }
+    if (IsRemote() && m_remote_platform_sp)
+        return m_remote_platform_sp->MakeDirectory(path, mode);
+    return Platform::MakeDirectory(path,mode);
+}
+
+lldb::user_id_t
+PlatformPOSIX::OpenFile (const FileSpec& file_spec,
+                          uint32_t flags,
+                          mode_t mode)
+{
+    if (IsHost())
+    {
+        return Host::OpenFile(file_spec, flags, mode);
+    }
+    if (IsRemote() && m_remote_platform_sp)
+        return m_remote_platform_sp->OpenFile(file_spec, flags, mode);
+    return Platform::OpenFile(file_spec, flags, mode);
+}
+
+bool
+PlatformPOSIX::CloseFile (lldb::user_id_t fd)
+{
+    if (IsHost())
+    {
+        return Host::CloseFile(fd);
+    }
+    if (IsRemote() && m_remote_platform_sp)
+        return m_remote_platform_sp->CloseFile(fd);
+    return Platform::CloseFile(fd);
+}
+
+uint32_t
+PlatformPOSIX::ReadFile (lldb::user_id_t fd, uint64_t offset,
+                          void *data_ptr, size_t len)
+{
+    if (IsHost())
+    {
+        return Host::ReadFile(fd, offset, data_ptr, len);
+    }
+    if (IsRemote() && m_remote_platform_sp)
+        return m_remote_platform_sp->ReadFile(fd, offset, data_ptr, len);
+    return Platform::ReadFile(fd, offset, data_ptr, len);
+}
+
+uint32_t
+PlatformPOSIX::WriteFile (lldb::user_id_t fd, uint64_t offset,
+                           void* data, size_t len)
+{
+    if (IsHost())
+    {
+        return Host::WriteFile(fd, offset, data, len);
+    }
+    if (IsRemote() && m_remote_platform_sp)
+        return m_remote_platform_sp->WriteFile(fd, offset, data, len);
+    return Platform::WriteFile(fd, offset, data, len);
+}
+
+static uint32_t
+chown_file(Platform *platform,
+           const char* path,
+           uint32_t uid = UINT32_MAX,
+           uint32_t gid = UINT32_MAX)
+{
+    if (!platform || !path || *path == 0)
+        return UINT32_MAX;
+    
+    if (uid == UINT32_MAX && gid == UINT32_MAX)
+        return 0;   // pretend I did chown correctly - actually I just didn't care
+    
+    StreamString command;
+    command.PutCString("chown ");
+    if (uid != UINT32_MAX)
+        command.Printf("%d",uid);
+    if (gid != UINT32_MAX)
+        command.Printf(":%d",gid);
+    command.Printf("%s",path);
+    return platform->RunShellCommand(command.GetData());
+}
+
+lldb_private::Error
+PlatformPOSIX::PutFile (const lldb_private::FileSpec& source,
+                         const lldb_private::FileSpec& destination,
+                         uint32_t uid,
+                         uint32_t gid)
+{
+#define PUTFILE_CHUNK_SIZE 1024
+    if (IsHost())
+    {
+        if (FileSpec::Equal(source, destination, true))
+            return Error();
+        // cp src dst
+        // chown uid:gid dst
+        std::string src_path;
+        if (source.GetPath(src_path) == 0)
+            return Error("unable to get file path for source");
+        std::string dst_path;
+        if (destination.GetPath(dst_path) == 0)
+            return Error("unable to get file path for destination");
+        StreamString command;
+        command.Printf("cp %s %s", src_path.c_str(), dst_path.c_str());
+        if (RunShellCommand(command.GetData()) != 0)
+            return Error("unable to perform copy");
+        if (uid == UINT32_MAX && gid == UINT32_MAX)
+            return Error();
+        if (chown_file(this,dst_path.c_str(),uid,gid) != 0)
+            return Error("unable to perform chown");
+        return Error();
+    }
+    if (IsRemote() && m_remote_platform_sp)
+    {
+        if (GetSupportsRSync())
+        {
+            std::string src_path;
+            if (source.GetPath(src_path) == 0)
+                return Error("unable to get file path for source");
+            std::string dst_path;
+            if (destination.GetPath(dst_path) == 0)
+                return Error("unable to get file path for destination");
+            StreamString command;
+            command.Printf("rsync %s %s %s:%s",
+                           GetRSyncArgs(),
+                           src_path.c_str(),
+                           GetHostname(),
+                           dst_path.c_str());
+            if (RunShellCommand(command.GetData()) == 0)
+            {
+                if (chown_file(this,dst_path.c_str(),uid,gid) != 0)
+                    return Error("unable to perform chown");
+                return Error();
+            }
+            // if we are still here rsync has failed - let's try the slow way before giving up
+        }
+        // open
+        // read, write, read, write, ...
+        // close
+        // chown uid:gid dst
+        File source_file(source, File::eOpenOptionRead, File::ePermissionsUserRW);
+        if (!source_file.IsValid())
+            return Error("unable to open source file");
+        lldb::user_id_t dest_file = OpenFile(destination, File::eOpenOptionCanCreate | File::eOpenOptionWrite | File::eOpenOptionTruncate,
+                                             File::ePermissionsUserRWX | File::ePermissionsGroupRX | File::ePermissionsWorldRX);
+        if (dest_file == UINT64_MAX)
+            return Error("unable to open target file");
+        lldb::DataBufferSP buffer_sp(new DataBufferHeap(PUTFILE_CHUNK_SIZE, 0));
+        Error err;
+        uint64_t offset = 0;
+        while (err.Success())
+        {
+            size_t read_data = PUTFILE_CHUNK_SIZE;
+            err = source_file.Read(buffer_sp->GetBytes(), read_data);
+            if (read_data)
+            {
+                WriteFile(dest_file, offset, buffer_sp->GetBytes(), read_data);
+                offset += read_data;
+            }
+            else
+                break;
+        }
+        CloseFile(dest_file);
+        if (uid == UINT32_MAX && gid == UINT32_MAX)
+            return Error();
+        std::string dst_path;
+        destination.GetPath(dst_path);
+        if (chown_file(this,dst_path.c_str(),uid,gid) != 0)
+            return Error("unable to perform chown");
+        return Error();
+    }
+    return Platform::PutFile(source,destination,uid,gid);
+}

Added: 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=154465&view=auto
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h (added)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/POSIX/PlatformPOSIX.h Tue Apr 10 19:55:26 2012
@@ -0,0 +1,105 @@
+//===-- PlatformPOSIX.h -----------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_PlatformPOSIX_h_
+#define liblldb_PlatformPOSIX_h_
+
+// C Includes
+// C++ Includes
+
+#include <memory>
+
+// Other libraries and framework includes
+// Project includes
+#include "lldb/Interpreter/Options.h"
+#include "lldb/Target/Platform.h"
+
+class PlatformPOSIX : public lldb_private::Platform
+{
+public:
+    PlatformPOSIX (bool is_host);
+    
+    virtual
+    ~PlatformPOSIX();
+    
+    //------------------------------------------------------------
+    // lldb_private::Platform functions
+    //------------------------------------------------------------
+    virtual lldb_private::Options *
+    GetConnectionOptions (lldb_private::CommandInterpreter& interpreter);
+    
+    virtual lldb_private::Error
+    PutFile (const lldb_private::FileSpec& source,
+             const lldb_private::FileSpec& destination,
+             uint32_t uid = UINT32_MAX,
+             uint32_t gid = UINT32_MAX);
+    
+    virtual lldb::user_id_t
+    OpenFile (const lldb_private::FileSpec& file_spec,
+              uint32_t flags,
+              mode_t mode);
+    
+    virtual bool
+    CloseFile (lldb::user_id_t fd);
+    
+    virtual uint32_t
+    ReadFile (lldb::user_id_t fd, uint64_t offset,
+              void *data_ptr, size_t len);
+    
+    virtual uint32_t
+    WriteFile (lldb::user_id_t fd, uint64_t offset,
+               void* data, size_t len);
+    
+    virtual uint32_t
+    RunShellCommand (const std::string &command_line);
+    
+    virtual uint32_t
+    MakeDirectory (const std::string &path,
+                   mode_t mode);
+    
+protected:
+    std::auto_ptr<lldb_private::Options> m_options;
+    
+    class POSIXPlatformConnectionOptions : public lldb_private::Options
+    {
+    public:
+        POSIXPlatformConnectionOptions (lldb_private::CommandInterpreter &interpreter);
+        
+        virtual
+        ~POSIXPlatformConnectionOptions ();
+        
+        virtual lldb_private::Error
+        SetOptionValue (uint32_t option_idx, const char *option_arg);
+        
+        void
+        OptionParsingStarting ();
+        
+        const lldb_private::OptionDefinition*
+        GetDefinitions ();
+        
+        // Options table: Required for subclasses of Options.
+        
+        static lldb_private::OptionDefinition g_option_table[];
+        
+        // Instance variables to hold the values for command options.
+        
+        bool m_rsync;
+        std::string m_rsync_args;
+        bool m_ssh;
+        std::string m_ssh_args;
+    };
+    
+    lldb::PlatformSP m_remote_platform_sp; // Allow multiple ways to connect to a remote POSIX-compliant OS
+    
+private:
+    DISALLOW_COPY_AND_ASSIGN (PlatformPOSIX);
+    
+};
+
+#endif  // liblldb_PlatformPOSIX_h_

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp Tue Apr 10 19:55:26 2012
@@ -219,6 +219,11 @@
             error.SetErrorString ("\"platform connect\" takes a single argument: <connect-url>");
         }
     }
+    
+    if (error.Success())
+    {
+        
+    }
 
     return error;
 }

Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Tue Apr 10 19:55:26 2012
@@ -1939,13 +1939,9 @@
 {
     lldb_private::StreamString stream;
     stream.PutCString("vFile:open:");
-    std::string path(512, 0);
-    uint32_t len = file_spec.GetPath(&path[0], 512);
-    if (len >= 512)
-    {
-        path = std::string(len+1,' ');
-        len = file_spec.GetPath(&path[0], len);
-    }
+    std::string path;
+    if (file_spec.GetPath(path) == 0)
+        return UINT64_MAX;
     stream.PutCStringAsRawHex8(path.c_str());
     stream.PutChar(',');
     stream.PutHex32(flags);

Modified: lldb/branches/lldb-platform-work/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Target/Platform.cpp?rev=154465&r1=154464&r2=154465&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Target/Platform.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Target/Platform.cpp Tue Apr 10 19:55:26 2012
@@ -188,7 +188,8 @@
     m_uid_map(),
     m_gid_map(),
     m_max_uid_name_len (0),
-    m_max_gid_name_len (0)
+    m_max_gid_name_len (0),
+    m_supports_rsync(false)
 {
     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
     if (log)





More information about the lldb-commits mailing list