[Lldb-commits] [lldb] r154577 - in /lldb/branches/lldb-platform-work: include/lldb/Host/ source/Host/common/ source/Plugins/Platform/gdb-server/ source/Plugins/Process/gdb-remote/ source/Utility/

Enrico Granata egranata at apple.com
Wed Apr 11 18:26:32 PDT 2012


Author: enrico
Date: Wed Apr 11 20:26:32 2012
New Revision: 154577

URL: http://llvm.org/viewvc/llvm-project?rev=154577&view=rev
Log:
Added the ability to check whether a remote file exists or not. This makes our remote target creation at least check that a file is there before letting us launch it. Attaching still seems to fail, however, but that is unrelated. One can now create a remote target, launch and debug it. Next step is to have LLDB copy over the file to an appropriate remote location if necessary (target installation). Ideally target installation will do the right thing when fed an OSX .app bundle

Modified:
    lldb/branches/lldb-platform-work/include/lldb/Host/Host.h
    lldb/branches/lldb-platform-work/source/Host/common/FileSpec.cpp
    lldb/branches/lldb-platform-work/source/Host/common/Host.cpp
    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/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/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/include/lldb/Host/Host.h?rev=154577&r1=154576&r2=154577&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/include/lldb/Host/Host.h (original)
+++ lldb/branches/lldb-platform-work/include/lldb/Host/Host.h Wed Apr 11 20:26:32 2012
@@ -474,6 +474,10 @@
 
     static lldb::user_id_t
     GetFileSize (const FileSpec& file_spec);
+    
+    static bool
+    GetFileExists (const FileSpec& file_spec);
+
 };
 
 } // namespace lldb_private

Modified: lldb/branches/lldb-platform-work/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/source/Host/common/FileSpec.cpp?rev=154577&r1=154576&r2=154577&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Host/common/FileSpec.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Host/common/FileSpec.cpp Wed Apr 11 20:26:32 2012
@@ -682,7 +682,7 @@
     const char *dirname = m_directory.GetCString();
     const char *filename = m_filename.GetCString();
     
-    uint32_t max_len = strlen(dirname) + strlen(filename) + 2;
+    uint32_t max_len = (dirname ? strlen(dirname) : 0) + (filename ? strlen(filename) : 0) + 2;
     
     path.resize(max_len);
         

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=154577&r1=154576&r2=154577&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Host/common/Host.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Host/common/Host.cpp Wed Apr 11 20:26:32 2012
@@ -1367,3 +1367,9 @@
     return file_spec.GetByteSize();
 }
 
+bool
+Host::GetFileExists (const FileSpec& file_spec)
+{
+    return file_spec.Exists();
+}
+

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=154577&r1=154576&r2=154577&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 Wed Apr 11 20:26:32 2012
@@ -97,6 +97,10 @@
 {
     Error error;
     //error.SetErrorString ("PlatformRemoteGDBServer::ResolveExecutable() is unimplemented");
+    if (m_gdb_client.FileExists(exe_file))
+        return error;
+    // TODO: get the remote end to somehow resolve this file
+    error.SetErrorString("file not found on remote end");
     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=154577&r1=154576&r2=154577&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 Wed Apr 11 20:26:32 2012
@@ -1981,13 +1981,8 @@
 {
     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);
-    }
+    std::string path;
+    file_spec.GetPath(path);
     stream.PutCStringAsRawHex8(path.c_str());
     stream.PutChar(',');
     const char* packet = stream.GetData();
@@ -2066,3 +2061,27 @@
     return UINT32_MAX;
 }
 
+// Extension of host I/O packets to get whether a file exists.
+bool
+GDBRemoteCommunicationClient::FileExists (const lldb_private::FileSpec& file_spec)
+{
+    lldb_private::StreamString stream;
+    stream.PutCString("vFile:exists:");
+    std::string path;
+    file_spec.GetPath(path);
+    stream.PutCStringAsRawHex8(path.c_str());
+    const char* packet = stream.GetData();
+    int packet_len = stream.GetSize();
+    StringExtractorGDBRemote response;
+    if (SendPacketAndWaitForResponse(packet, packet_len, response, false))
+    {
+        if (response.GetChar() != 'F')
+            return false;
+        if (response.GetChar() != ',')
+            return false;
+        bool retcode = (response.GetChar() != '0');
+        return retcode;
+    }
+    return false;
+}
+

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=154577&r1=154576&r2=154577&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 Wed Apr 11 20:26:32 2012
@@ -363,7 +363,10 @@
     virtual uint32_t
     MakeDirectory (const std::string &path,
                    mode_t mode);
-
+    
+    virtual bool
+    FileExists (const lldb_private::FileSpec& file_spec);
+    
 protected:
 
     //------------------------------------------------------------------

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=154577&r1=154576&r2=154577&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 Wed Apr 11 20:26:32 2012
@@ -182,6 +182,9 @@
 
             case StringExtractorGDBRemote::eServerPacketType_vFile_Size:
                 return Handle_vFile_Size (packet);
+                
+            case StringExtractorGDBRemote::eServerPacketType_vFile_Exists:
+                return Handle_vFile_Exists (packet);
         }
         return true;
     }
@@ -1015,3 +1018,23 @@
     SendPacketNoLock(response.GetData(), response.GetSize());
     return true;
 }
+
+bool
+GDBRemoteCommunicationServer::Handle_vFile_Exists (StringExtractorGDBRemote &packet)
+{
+    packet.SetFilePos(::strlen("vFile:exists:"));
+    std::string path;
+    packet.GetHexByteString(path);
+    if (path.size() == 0)
+        return false;
+    bool retcode = Host::GetFileExists(FileSpec(path.c_str(), false));
+    StreamString response;
+    response.PutChar('F');
+    response.PutChar(',');
+    if (retcode)
+        response.PutChar('1');
+    else
+        response.PutChar('0');
+    SendPacketNoLock(response.GetData(), response.GetSize());
+    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=154577&r1=154576&r2=154577&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 Wed Apr 11 20:26:32 2012
@@ -158,6 +158,9 @@
     bool
     Handle_vFile_Size (StringExtractorGDBRemote &packet);
 
+    bool
+    Handle_vFile_Exists (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=154577&r1=154576&r2=154577&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp (original)
+++ lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.cpp Wed Apr 11 20:26:32 2012
@@ -149,6 +149,7 @@
                 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;
+                else if (PACKET_STARTS_WITH("vFile:exists"))         return eServerPacketType_vFile_Exists;
             }
             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=154577&r1=154576&r2=154577&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h (original)
+++ lldb/branches/lldb-platform-work/source/Utility/StringExtractorGDBRemote.h Wed Apr 11 20:26:32 2012
@@ -70,7 +70,8 @@
         eServerPacketType_vFile_Close,
         eServerPacketType_vFile_pRead,
         eServerPacketType_vFile_pWrite,
-        eServerPacketType_vFile_Size
+        eServerPacketType_vFile_Size,
+        eServerPacketType_vFile_Exists,
     };
     
     ServerPacketType





More information about the lldb-commits mailing list