From ce255ff26af9d7ca4fd7810724e60b0e8d05cd6f Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Thu, 24 Nov 2016 14:11:47 +0000 Subject: [PATCH] Use more chrono in AdbClient This refactors AdbClient interface in terms of std::chrono. llvm-svn: 287880 --- lldb/source/Plugins/Platform/Android/AdbClient.cpp | 8 ++++---- lldb/source/Plugins/Platform/Android/AdbClient.h | 5 +++-- .../Plugins/Platform/Android/PlatformAndroid.cpp | 11 ++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.cpp b/lldb/source/Plugins/Platform/Android/AdbClient.cpp index d9e27d94f74e..05004406c04b 100644 --- a/lldb/source/Plugins/Platform/Android/AdbClient.cpp +++ b/lldb/source/Plugins/Platform/Android/AdbClient.cpp @@ -383,10 +383,10 @@ Error AdbClient::internalShell(const char *command, milliseconds timeout, return Error(); } -Error AdbClient::Shell(const char *command, uint32_t timeout_ms, +Error AdbClient::Shell(const char *command, milliseconds timeout, std::string *output) { std::vector output_buffer; - auto error = internalShell(command, milliseconds(timeout_ms), output_buffer); + auto error = internalShell(command, timeout, output_buffer); if (error.Fail()) return error; @@ -395,10 +395,10 @@ Error AdbClient::Shell(const char *command, uint32_t timeout_ms, return error; } -Error AdbClient::ShellToFile(const char *command, uint32_t timeout_ms, +Error AdbClient::ShellToFile(const char *command, milliseconds timeout, const FileSpec &output_file_spec) { std::vector output_buffer; - auto error = internalShell(command, milliseconds(timeout_ms), output_buffer); + auto error = internalShell(command, timeout, output_buffer); if (error.Fail()) return error; diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.h b/lldb/source/Plugins/Platform/Android/AdbClient.h index f1d72aae8b81..169a0b5a4e3e 100644 --- a/lldb/source/Plugins/Platform/Android/AdbClient.h +++ b/lldb/source/Plugins/Platform/Android/AdbClient.h @@ -94,9 +94,10 @@ public: Error DeletePortForwarding(const uint16_t local_port); - Error Shell(const char *command, uint32_t timeout_ms, std::string *output); + Error Shell(const char *command, std::chrono::milliseconds timeout, + std::string *output); - Error ShellToFile(const char *command, uint32_t timeout_ms, + Error ShellToFile(const char *command, std::chrono::milliseconds timeout, const FileSpec &output_file_spec); std::unique_ptr GetSyncService(Error &error); diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp index 7d7017286351..64a320f8c3fc 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp @@ -28,6 +28,7 @@ using namespace lldb; using namespace lldb_private; using namespace lldb_private::platform_android; +using namespace std::chrono; static uint32_t g_initialize_count = 0; static const unsigned int g_android_default_cache_size = @@ -230,7 +231,7 @@ Error PlatformAndroid::GetFile(const FileSpec &source, char cmd[PATH_MAX]; snprintf(cmd, sizeof(cmd), "cat '%s'", source_file); - return adb.ShellToFile(cmd, 60000 /* ms */, destination); + return adb.ShellToFile(cmd, minutes(1), destination); } Error PlatformAndroid::PutFile(const FileSpec &source, @@ -288,7 +289,7 @@ uint32_t PlatformAndroid::GetSdkVersion() { std::string version_string; AdbClient adb(m_device_id); Error error = - adb.Shell("getprop ro.build.version.sdk", 5000 /* ms */, &version_string); + adb.Shell("getprop ro.build.version.sdk", seconds(5), &version_string); version_string = llvm::StringRef(version_string).trim().str(); if (error.Fail() || version_string.empty()) { @@ -327,7 +328,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp, AdbClient adb(m_device_id); std::string tmpdir; Error error = adb.Shell("mktemp --directory --tmpdir /data/local/tmp", - 5000 /* ms */, &tmpdir); + seconds(5), &tmpdir); if (error.Fail() || tmpdir.empty()) return Error("Failed to generate temporary directory on the device (%s)", error.AsCString()); @@ -338,7 +339,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp, tmpdir_remover(&tmpdir, [this, &adb](std::string *s) { StreamString command; command.Printf("rm -rf %s", s->c_str()); - Error error = adb.Shell(command.GetData(), 5000 /* ms */, nullptr); + Error error = adb.Shell(command.GetData(), seconds(5), nullptr); Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM)); if (log && error.Fail()) @@ -353,7 +354,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp, command.Printf("oatdump --symbolize=%s --output=%s", module_sp->GetPlatformFileSpec().GetCString(false), symfile_platform_filespec.GetCString(false)); - error = adb.Shell(command.GetData(), 60000 /* ms */, nullptr); + error = adb.Shell(command.GetData(), minutes(1), nullptr); if (error.Fail()) return Error("Oatdump failed: %s", error.AsCString());