[Lldb-commits] [lldb] r154460 - in /lldb/branches/lldb-platform-work: include/lldb/Target/ source/Commands/ source/Plugins/Platform/MacOSX/ source/Plugins/Platform/gdb-server/ source/Plugins/Process/gdb-remote/ source/Utility/

Johnny Chen johnny.chen at apple.com
Tue Apr 10 17:28:16 PDT 2012


Author: johnny
Date: Tue Apr 10 19:28:16 2012
New Revision: 154460

URL: http://llvm.org/viewvc/llvm-project?rev=154460&view=rev
Log:
Add a simple packet to get the file size from the remote end, and a 'platform get-size /the/remote/file/path' command.

Modified:
    lldb/branches/lldb-platform-work/include/lldb/Target/Platform.h
    lldb/branches/lldb-platform-work/source/Commands/CommandObjectPlatform.cpp
    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/Platform/gdb-server/PlatformRemoteGDBServer.h
    lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
    lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
    lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
    lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp
    lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h

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=154460&r1=154459&r2=154460&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:28:16 2012
@@ -477,6 +477,12 @@
             return false;
         }
         
+        virtual lldb::user_id_t
+        GetFileSize (const FileSpec& file_spec)
+        {
+            return UINT64_MAX;
+        }
+
         virtual uint32_t
         ReadFile (lldb::user_id_t fd, uint64_t offset,
                   void *data_ptr, size_t len)

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=154460&r1=154459&r2=154460&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:28:16 2012
@@ -678,6 +678,14 @@
     virtual bool
     Execute (Args& args, CommandReturnObject &result)
     {
+        // If the number of arguments is incorrect, issue an error message.
+        if (args.GetArgumentCount() != 2)
+        {
+            result.GetErrorStream().Printf("error: required arguments missing; specify both the source and destination file paths\n");
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+        }
+
         PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
         if (platform_sp)
         {
@@ -707,6 +715,79 @@
 };
 
 //----------------------------------------------------------------------
+// "platform get-size remote-file-path"
+//----------------------------------------------------------------------
+class CommandObjectPlatformGetSize : public CommandObject
+{
+public:
+    CommandObjectPlatformGetSize (CommandInterpreter &interpreter) :
+    CommandObject (interpreter,
+                   "platform get-size",
+                   "Get the file size from the remote end.",
+                   NULL,
+                   0)
+    {
+        SetHelpLong(
+"Examples: \n\
+\n\
+    platform get-size /the/remote/file/path\n\
+    # Get the file size from the remote end with path /the/remote/file/path.\n");
+
+        CommandArgumentEntry arg1;
+        CommandArgumentData file_arg_remote;
+    
+        // Define the first (and only) variant of this arg.
+        file_arg_remote.arg_type = eArgTypeFilename;
+        file_arg_remote.arg_repetition = eArgRepeatPlain;
+        // There is only one variant this argument could be; put it into the argument entry.
+        arg1.push_back (file_arg_remote);
+        
+        // Push the data for the first argument into the m_arguments vector.
+        m_arguments.push_back (arg1);
+    }
+    
+    virtual
+    ~CommandObjectPlatformGetSize ()
+    {
+    }
+    
+    virtual bool
+    Execute (Args& args, CommandReturnObject &result)
+    {
+        // If the number of arguments is incorrect, issue an error message.
+        if (args.GetArgumentCount() != 1)
+        {
+            result.GetErrorStream().Printf("error: required argument missing; specify the source file path as the only argument\n");
+            result.SetStatus(eReturnStatusFailed);
+            return false;
+        }
+
+        PlatformSP platform_sp (m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform());
+        if (platform_sp)
+        {
+            std::string remote_file_path(args.GetArgumentAtIndex(0));
+            user_id_t size = platform_sp->GetFileSize(FileSpec(remote_file_path.c_str(), false));
+            if (size != UINT64_MAX)
+            {
+                result.AppendMessageWithFormat("File size of %s (remote): %llu\n", remote_file_path.c_str(), size);
+                result.SetStatus (eReturnStatusSuccessFinishResult);
+            }
+            else
+            {
+                result.AppendMessageWithFormat("Eroor getting file size of %s (remote)\n", remote_file_path.c_str());
+                result.SetStatus (eReturnStatusFailed);
+            }
+        }
+        else
+        {
+            result.AppendError ("no platform currently selected\n");
+            result.SetStatus (eReturnStatusFailed);
+        }
+        return result.Succeeded();
+    }
+};
+
+//----------------------------------------------------------------------
 // "platform put-file"
 //----------------------------------------------------------------------
 class CommandObjectPlatformPutFile : public CommandObject
@@ -1425,6 +1506,7 @@
     LoadSubCommand ("fread", CommandObjectSP (new CommandObjectPlatformFRead  (interpreter)));
     LoadSubCommand ("fwrite", CommandObjectSP (new CommandObjectPlatformFWrite  (interpreter)));
     LoadSubCommand ("get-file", CommandObjectSP (new CommandObjectPlatformGetFile  (interpreter)));
+    LoadSubCommand ("get-size", CommandObjectSP (new CommandObjectPlatformGetSize  (interpreter)));
     LoadSubCommand ("put-file", CommandObjectSP (new CommandObjectPlatformPutFile  (interpreter)));
 #endif
 }

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=154460&r1=154459&r2=154460&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:28:16 2012
@@ -206,6 +206,18 @@
     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)

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=154460&r1=154459&r2=154460&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:28:16 2012
@@ -106,6 +106,9 @@
     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);

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=154460&r1=154459&r2=154460&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:28:16 2012
@@ -432,6 +432,12 @@
     return m_gdb_client.CloseFile (fd);
 }
 
+lldb::user_id_t
+PlatformRemoteGDBServer::GetFileSize (const lldb_private::FileSpec& source)
+{
+    return m_gdb_client.GetFileSize(source);
+}
+
 uint32_t
 PlatformRemoteGDBServer::ReadFile (lldb::user_id_t fd, uint64_t offset,
                                    void *data_ptr, size_t len)

Modified: lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h?rev=154460&r1=154459&r2=154460&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h Tue Apr 10 19:28:16 2012
@@ -156,6 +156,9 @@
     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);

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=154460&r1=154459&r2=154460&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:28:16 2012
@@ -1982,6 +1982,34 @@
     return UINT64_MAX;
 }
 
+// Extension of host I/O packets to get the file size.
+lldb::user_id_t
+GDBRemoteCommunicationClient::GetFileSize (const lldb_private::FileSpec& file_spec)
+{
+    lldb_private::StreamString stream;
+    stream.PutCString("vFile:size:");
+    std::string path(512, ' ');
+    uint32_t len = file_spec.GetPath(&path[0], 512);
+    if (len >= 512)
+    {
+        path = std::string(len+1,' ');
+        len = file_spec.GetPath(&path[0], len);
+    }
+    stream.PutCStringAsRawHex8(path.c_str());
+    stream.PutChar(',');
+    const char* packet = stream.GetData();
+    int packet_len = stream.GetSize();
+    StringExtractorGDBRemote response;
+    if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+    {
+        if (response.GetChar() != 'F')
+            return UINT64_MAX;
+        uint32_t retcode = response.GetHexMaxU64(false, UINT64_MAX);
+        return retcode;
+    }
+    return UINT64_MAX;
+}
+
 uint32_t
 GDBRemoteCommunicationClient::ReadFile (lldb::user_id_t fd, uint64_t offset,
                                         void *data_ptr, size_t len)

Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=154460&r1=154459&r2=154460&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Tue Apr 10 19:28:16 2012
@@ -343,6 +343,9 @@
     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);

Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=154460&r1=154459&r2=154460&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Tue Apr 10 19:28:16 2012
@@ -179,6 +179,9 @@
                 
             case StringExtractorGDBRemote::eServerPacketType_vFile_pWrite:
                 return Handle_vFile_pWrite (packet);
+
+            case StringExtractorGDBRemote::eServerPacketType_vFile_Size:
+                return Handle_vFile_Size (packet);
         }
         return true;
     }
@@ -989,3 +992,26 @@
     SendPacket(response);
     return true;
 }
+
+bool
+GDBRemoteCommunicationServer::Handle_vFile_Size (StringExtractorGDBRemote &packet)
+{
+    packet.SetFilePos(::strlen("vFile:size:"));
+    std::string path;
+    packet.GetHexByteStringTerminatedBy(path,',');
+    if (path.size() == 0)
+        return false;
+    if (packet.GetChar() != ',')
+        return false;
+    lldb::user_id_t retcode = Host::GetFileSize(FileSpec(path.c_str(), false));
+    StreamString response;
+    response.PutChar('F');
+    response.PutHex64(retcode);
+    if (retcode == UINT64_MAX)
+    {
+        response.PutChar(',');
+        response.PutHex64(retcode); // TODO: replace with Host::GetSyswideErrorCode()
+    }
+    SendPacket(response);
+    return true;
+}

Modified: lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h?rev=154460&r1=154459&r2=154460&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h (original)
+++ lldb/branches/lldb-platform-work/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h Tue Apr 10 19:28:16 2012
@@ -154,6 +154,10 @@
 
     bool
     Handle_vFile_pWrite (StringExtractorGDBRemote &packet);
+
+    bool
+    Handle_vFile_Size (StringExtractorGDBRemote &packet);
+
 private:
     //------------------------------------------------------------------
     // For GDBRemoteCommunicationServer only

Modified: lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp?rev=154460&r1=154459&r2=154460&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp Tue Apr 10 19:28:16 2012
@@ -148,6 +148,7 @@
                 else if (PACKET_STARTS_WITH("vFile:close:"))         return eServerPacketType_vFile_Close;
                 else if (PACKET_STARTS_WITH("vFile:pread"))          return eServerPacketType_vFile_pRead;
                 else if (PACKET_STARTS_WITH("vFile:pwrite"))         return eServerPacketType_vFile_pWrite;
+                else if (PACKET_STARTS_WITH("vFile:size"))           return eServerPacketType_vFile_Size;
             }
             break;
     }

Modified: lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h?rev=154460&r1=154459&r2=154460&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h (original)
+++ lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h Tue Apr 10 19:28:16 2012
@@ -69,7 +69,8 @@
         eServerPacketType_vFile_Open,
         eServerPacketType_vFile_Close,
         eServerPacketType_vFile_pRead,
-        eServerPacketType_vFile_pWrite
+        eServerPacketType_vFile_pWrite,
+        eServerPacketType_vFile_Size
     };
     
     ServerPacketType





More information about the lldb-commits mailing list