diff options
4 files changed, 63 insertions, 33 deletions
diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.cpp b/lldb/source/Plugins/Platform/Android/AdbClient.cpp index 27e21695be8..3c154463c7b 100644 --- a/lldb/source/Plugins/Platform/Android/AdbClient.cpp +++ b/lldb/source/Plugins/Platform/Android/AdbClient.cpp @@ -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_file, const char *local_file) } 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::FileSpec& source, const lldb_private::F 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; } diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.h b/lldb/source/Plugins/Platform/Android/AdbClient.h index d307b6a298a..82ce84c80f0 100644 --- a/lldb/source/Plugins/Platform/Android/AdbClient.h +++ b/lldb/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 @@ 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 diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp index 7a6e85cc333..7249fac4d43 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -207,9 +207,21 @@ PlatformAndroid::ConnectRemote(Args& args) 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 (const FileSpec &src_file_spec, 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); } diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.h b/lldb/source/Plugins/Platform/Android/PlatformAndroid.h index f1d34e64eb0..b02a1b5b5f7 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.h +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.h @@ -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; |