Index: source/Plugins/Platform/Android/AdbClient.h =================================================================== --- source/Plugins/Platform/Android/AdbClient.h +++ source/Plugins/Platform/Android/AdbClient.h @@ -25,6 +25,9 @@ #include "lldb/Host/ConnectionFileDescriptor.h" namespace lldb_private { + +class FileSpec; + namespace platform_android { class AdbClient @@ -51,10 +54,10 @@ 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 @@ Sync (); Error + StartSync (); + + Error PullFileChunk (std::vector &buffer, bool &eof); Error Index: source/Plugins/Platform/Android/AdbClient.cpp =================================================================== --- source/Plugins/Platform/Android/AdbClient.cpp +++ source/Plugins/Platform/Android/AdbClient.cpp @@ -250,23 +250,21 @@ } 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 @@ } 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 @@ 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; } Index: source/Plugins/Platform/Android/PlatformAndroid.h =================================================================== --- source/Plugins/Platform/Android/PlatformAndroid.h +++ source/Plugins/Platform/Android/PlatformAndroid.h @@ -64,9 +64,13 @@ 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; Index: source/Plugins/Platform/Android/PlatformAndroid.cpp =================================================================== --- source/Plugins/Platform/Android/PlatformAndroid.cpp +++ source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -207,9 +207,21 @@ 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 @@ 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); }