[Lldb-commits] [lldb] r238442 - Refactor AdbClient and make PlatformAndroid::GetFile to use "adb pull".

Tamas Berghammer tberghammer at google.com
Fri May 29 08:20:21 PDT 2015


Hi Oleksiy,

This change caused some regression on android because in some case GetFile
is called with a remote path relative to the current working directory
selected through lldb and it isn't handled by adb. Please create a fix for
it or revert this CL.

Thanks,
Tamas

On Thu, May 28, 2015 at 6:42 PM, Oleksiy Vyalov <ovyalov at google.com> wrote:

> Author: ovyalov
> Date: Thu May 28 12:42:48 2015
> New Revision: 238442
>
> URL: http://llvm.org/viewvc/llvm-project?rev=238442&view=rev
> Log:
> Refactor AdbClient and make PlatformAndroid::GetFile to use "adb pull".
>
> http://reviews.llvm.org/D10082
>
>
> Modified:
>     lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
>     lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
>     lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
>     lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
>
> Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp?rev=238442&r1=238441&r2=238442&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp (original)
> +++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp Thu May 28
> 12:42:48 2015
> @@ -250,23 +250,21 @@ AdbClient::SwitchDeviceTransport ()
>  }
>
>  Error
> -AdbClient::PullFile (const char *remote_file, const char *local_file)
> +AdbClient::PullFile (const FileSpec &remote_file, const FileSpec
> &local_file)
>  {
> -    auto error = SwitchDeviceTransport ();
> +    auto error = StartSync ();
>      if (error.Fail ())
> -        return Error ("Failed to switch to device transport: %s",
> error.AsCString ());
> -
> -    error = Sync ();
> -    if (error.Fail ())
> -        return Error ("Sync failed: %s", error.AsCString ());
> +        return error;
>
> -    llvm::FileRemover local_file_remover (local_file);
> +    const auto local_file_path = local_file.GetPath ();
> +    llvm::FileRemover local_file_remover (local_file_path.c_str ());
>
> -    std::ofstream dst (local_file, std::ios::out | std::ios::binary);
> +    std::ofstream dst (local_file_path, std::ios::out | std::ios::binary);
>      if (!dst.is_open ())
> -        return Error ("Unable to open local file %s", local_file);
> +        return Error ("Unable to open local file %s",
> local_file_path.c_str());
>
> -    error = SendSyncRequest ("RECV", strlen(remote_file), remote_file);
> +    const auto remote_file_path = remote_file.GetPath (false);
> +    error = SendSyncRequest ("RECV", remote_file_path.length (),
> remote_file_path.c_str ());
>      if (error.Fail ())
>          return error;
>
> @@ -286,22 +284,19 @@ AdbClient::PullFile (const char *remote_
>  }
>
>  Error
> -AdbClient::PushFile (const lldb_private::FileSpec& source, const
> lldb_private::FileSpec& destination)
> +AdbClient::PushFile (const FileSpec &local_file, const FileSpec
> &remote_file)
>  {
> -    auto error = SwitchDeviceTransport ();
> +    auto error = StartSync ();
>      if (error.Fail ())
> -        return Error ("Failed to switch to device transport: %s",
> error.AsCString ());
> -
> -    error = Sync ();
> -    if (error.Fail ())
> -        return Error ("Sync failed: %s", error.AsCString ());
> +        return error;
>
> -    std::ifstream src (source.GetPath().c_str(), std::ios::in |
> std::ios::binary);
> +    const auto local_file_path (local_file.GetPath ());
> +    std::ifstream src (local_file_path.c_str(), std::ios::in |
> std::ios::binary);
>      if (!src.is_open ())
> -        return Error ("Unable to open local file %s",
> source.GetPath().c_str());
> +        return Error ("Unable to open local file %s",
> local_file_path.c_str());
>
>      std::stringstream file_description;
> -    file_description << destination.GetPath(false).c_str() << "," <<
> kDefaultMode;
> +    file_description << remote_file.GetPath(false).c_str() << "," <<
> kDefaultMode;
>      std::string file_description_str = file_description.str();
>      error = SendSyncRequest ("SEND", file_description_str.length(),
> file_description_str.c_str());
>      if (error.Fail ())
> @@ -315,14 +310,28 @@ AdbClient::PushFile (const lldb_private:
>          if (error.Fail ())
>              return Error ("Failed to send file chunk: %s",
> error.AsCString ());
>      }
> -    error = SendSyncRequest("DONE",
> source.GetModificationTime().seconds(), nullptr);
> +    error = SendSyncRequest("DONE",
> local_file.GetModificationTime().seconds(), nullptr);
>      if (error.Fail ())
>          return error;
>      error = ReadResponseStatus();
>      // If there was an error reading the source file, finish the adb file
>      // transfer first so that adb isn't expecting any more data.
>      if (src.bad())
> -        return Error ("Failed read on %s", source.GetPath().c_str());
> +        return Error ("Failed read on %s", local_file_path.c_str());
> +    return error;
> +}
> +
> +Error
> +AdbClient::StartSync ()
> +{
> +    auto error = SwitchDeviceTransport ();
> +    if (error.Fail ())
> +        return Error ("Failed to switch to device transport: %s",
> error.AsCString ());
> +
> +    error = Sync ();
> +    if (error.Fail ())
> +        return Error ("Sync failed: %s", error.AsCString ());
> +
>      return error;
>  }
>
>
> Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.h?rev=238442&r1=238441&r2=238442&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Plugins/Platform/Android/AdbClient.h (original)
> +++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.h Thu May 28
> 12:42:48 2015
> @@ -25,6 +25,9 @@
>  #include "lldb/Host/ConnectionFileDescriptor.h"
>
>  namespace lldb_private {
> +
> +class FileSpec;
> +
>  namespace platform_android {
>
>  class AdbClient
> @@ -51,10 +54,10 @@ public:
>      DeletePortForwarding (const uint16_t port);
>
>      Error
> -    PullFile (const char *remote_file, const char *local_file);
> +    PullFile (const FileSpec &remote_file, const FileSpec &local_file);
>
>      Error
> -    PushFile (const lldb_private::FileSpec& source, const
> lldb_private::FileSpec& destination);
> +    PushFile (const FileSpec &local_file, const FileSpec &remote_file);
>
>  private:
>      Error
> @@ -91,6 +94,9 @@ private:
>      Sync ();
>
>      Error
> +    StartSync ();
> +
> +    Error
>      PullFileChunk (std::vector<char> &buffer, bool &eof);
>
>      Error
>
> Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp?rev=238442&r1=238441&r2=238442&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
> (original)
> +++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp Thu May
> 28 12:42:48 2015
> @@ -207,9 +207,21 @@ PlatformAndroid::ConnectRemote(Args& arg
>      return error;
>  }
>
> -lldb_private::Error
> -PlatformAndroid::PutFile (const lldb_private::FileSpec& source,
> -                          const lldb_private::FileSpec& destination,
> +Error
> +PlatformAndroid::GetFile (const FileSpec& source,
> +                          const FileSpec& destination)
> +{
> +    if (!IsHost() && m_remote_platform_sp)
> +    {
> +        AdbClient adb (m_device_id);
> +        return adb.PullFile(source, destination);
> +    }
> +    return PlatformLinux::GetFile(source, destination);
> +}
> +
> +Error
> +PlatformAndroid::PutFile (const FileSpec& source,
> +                          const FileSpec& destination,
>                            uint32_t uid,
>                            uint32_t gid)
>  {
> @@ -237,6 +249,5 @@ PlatformAndroid::DownloadModuleSlice (co
>      if (src_offset != 0)
>          return Error ("Invalid offset - %" PRIu64, src_offset);
>
> -    AdbClient adb (m_device_id);
> -    return adb.PullFile (src_file_spec.GetPath (false).c_str (),
> dst_file_spec.GetPath ().c_str ());
> +    return GetFile (src_file_spec, dst_file_spec);
>  }
>
> Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
> URL:
> http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h?rev=238442&r1=238441&r2=238442&view=diff
>
> ==============================================================================
> --- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h (original)
> +++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h Thu May
> 28 12:42:48 2015
> @@ -64,9 +64,13 @@ namespace platform_android {
>          Error
>          ConnectRemote (Args& args) override;
>
> -        lldb_private::Error
> -        PutFile (const lldb_private::FileSpec& source,
> -                 const lldb_private::FileSpec& destination,
> +        Error
> +        GetFile (const FileSpec& source,
> +                 const FileSpec& destination) override;
> +
> +        Error
> +        PutFile (const FileSpec& source,
> +                 const FileSpec& destination,
>                   uint32_t uid = UINT32_MAX,
>                   uint32_t gid = UINT32_MAX) override;
>
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150529/628a2202/attachment.html>


More information about the lldb-commits mailing list