summaryrefslogtreecommitdiff
path: root/source/Plugins/Platform/Android
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-05-16 19:47:58 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-05-16 19:47:58 +0000
commitb76161e41bc2c07cd47f9c61f875d1be95e26d10 (patch)
treed03c19ce10dec6419f97df1d4dac9d47eb88982f /source/Plugins/Platform/Android
parent8b4000f13b303cc154136abc74c55670673e2a96 (diff)
Notes
Diffstat (limited to 'source/Plugins/Platform/Android')
-rw-r--r--source/Plugins/Platform/Android/AdbClient.cpp189
-rw-r--r--source/Plugins/Platform/Android/AdbClient.h87
-rw-r--r--source/Plugins/Platform/Android/PlatformAndroid.cpp68
-rw-r--r--source/Plugins/Platform/Android/PlatformAndroid.h22
-rw-r--r--source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp31
-rw-r--r--source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h12
6 files changed, 207 insertions, 202 deletions
diff --git a/source/Plugins/Platform/Android/AdbClient.cpp b/source/Plugins/Platform/Android/AdbClient.cpp
index 2060bd1de7355..d3bcee6f487d7 100644
--- a/source/Plugins/Platform/Android/AdbClient.cpp
+++ b/source/Plugins/Platform/Android/AdbClient.cpp
@@ -46,7 +46,7 @@ using namespace std::chrono;
namespace {
-const seconds kReadTimeout(8);
+const seconds kReadTimeout(12);
const char *kOKAY = "OKAY";
const char *kFAIL = "FAIL";
const char *kDATA = "DATA";
@@ -65,9 +65,9 @@ const uint32_t kDefaultMode = 0100770; // S_IFREG | S_IRWXU | S_IRWXG
const char *kSocketNamespaceAbstract = "localabstract";
const char *kSocketNamespaceFileSystem = "localfilesystem";
-Error ReadAllBytes(Connection &conn, void *buffer, size_t size) {
+Status ReadAllBytes(Connection &conn, void *buffer, size_t size) {
- Error error;
+ Status error;
ConnectionStatus status;
char *read_buffer = static_cast<char *>(buffer);
@@ -86,7 +86,7 @@ Error ReadAllBytes(Connection &conn, void *buffer, size_t size) {
now = steady_clock::now();
}
if (total_read_bytes < size)
- error = Error(
+ error = Status(
"Unable to read requested number of bytes. Connection status: %d.",
status);
return error;
@@ -94,8 +94,8 @@ Error ReadAllBytes(Connection &conn, void *buffer, size_t size) {
} // namespace
-Error AdbClient::CreateByDeviceID(const std::string &device_id,
- AdbClient &adb) {
+Status AdbClient::CreateByDeviceID(const std::string &device_id,
+ AdbClient &adb) {
DeviceIDList connect_devices;
auto error = adb.GetDevices(connect_devices);
if (error.Fail())
@@ -109,15 +109,15 @@ Error AdbClient::CreateByDeviceID(const std::string &device_id,
if (android_serial.empty()) {
if (connect_devices.size() != 1)
- return Error("Expected a single connected device, got instead %zu - try "
- "setting 'ANDROID_SERIAL'",
- connect_devices.size());
+ return Status("Expected a single connected device, got instead %zu - try "
+ "setting 'ANDROID_SERIAL'",
+ connect_devices.size());
adb.SetDeviceID(connect_devices.front());
} else {
auto find_it = std::find(connect_devices.begin(), connect_devices.end(),
android_serial);
if (find_it == connect_devices.end())
- return Error("Device \"%s\" not found", android_serial.c_str());
+ return Status("Device \"%s\" not found", android_serial.c_str());
adb.SetDeviceID(*find_it);
}
@@ -136,15 +136,15 @@ void AdbClient::SetDeviceID(const std::string &device_id) {
const std::string &AdbClient::GetDeviceID() const { return m_device_id; }
-Error AdbClient::Connect() {
- Error error;
+Status AdbClient::Connect() {
+ Status error;
m_conn.reset(new ConnectionFileDescriptor);
m_conn->Connect("connect://localhost:5037", &error);
return error;
}
-Error AdbClient::GetDevices(DeviceIDList &device_list) {
+Status AdbClient::GetDevices(DeviceIDList &device_list) {
device_list.clear();
auto error = SendMessage("host:devices");
@@ -171,8 +171,8 @@ Error AdbClient::GetDevices(DeviceIDList &device_list) {
return error;
}
-Error AdbClient::SetPortForwarding(const uint16_t local_port,
- const uint16_t remote_port) {
+Status AdbClient::SetPortForwarding(const uint16_t local_port,
+ const uint16_t remote_port) {
char message[48];
snprintf(message, sizeof(message), "forward:tcp:%d;tcp:%d", local_port,
remote_port);
@@ -184,9 +184,10 @@ Error AdbClient::SetPortForwarding(const uint16_t local_port,
return ReadResponseStatus();
}
-Error AdbClient::SetPortForwarding(const uint16_t local_port,
- llvm::StringRef remote_socket_name,
- const UnixSocketNamespace socket_namespace) {
+Status
+AdbClient::SetPortForwarding(const uint16_t local_port,
+ llvm::StringRef remote_socket_name,
+ const UnixSocketNamespace socket_namespace) {
char message[PATH_MAX];
const char *sock_namespace_str =
(socket_namespace == UnixSocketNamespaceAbstract)
@@ -202,7 +203,7 @@ Error AdbClient::SetPortForwarding(const uint16_t local_port,
return ReadResponseStatus();
}
-Error AdbClient::DeletePortForwarding(const uint16_t local_port) {
+Status AdbClient::DeletePortForwarding(const uint16_t local_port) {
char message[32];
snprintf(message, sizeof(message), "killforward:tcp:%d", local_port);
@@ -213,8 +214,8 @@ Error AdbClient::DeletePortForwarding(const uint16_t local_port) {
return ReadResponseStatus();
}
-Error AdbClient::SendMessage(const std::string &packet, const bool reconnect) {
- Error error;
+Status AdbClient::SendMessage(const std::string &packet, const bool reconnect) {
+ Status error;
if (!m_conn || reconnect) {
error = Connect();
if (error.Fail())
@@ -235,13 +236,13 @@ Error AdbClient::SendMessage(const std::string &packet, const bool reconnect) {
return error;
}
-Error AdbClient::SendDeviceMessage(const std::string &packet) {
+Status AdbClient::SendDeviceMessage(const std::string &packet) {
std::ostringstream msg;
msg << "host-serial:" << m_device_id << ":" << packet;
return SendMessage(msg.str());
}
-Error AdbClient::ReadMessage(std::vector<char> &message) {
+Status AdbClient::ReadMessage(std::vector<char> &message) {
message.clear();
char buffer[5];
@@ -262,19 +263,19 @@ Error AdbClient::ReadMessage(std::vector<char> &message) {
return error;
}
-Error AdbClient::ReadMessageStream(std::vector<char> &message,
- milliseconds timeout) {
+Status AdbClient::ReadMessageStream(std::vector<char> &message,
+ milliseconds timeout) {
auto start = steady_clock::now();
message.clear();
- Error error;
+ Status error;
lldb::ConnectionStatus status = lldb::eConnectionStatusSuccess;
char buffer[1024];
while (error.Success() && status == lldb::eConnectionStatusSuccess) {
auto end = steady_clock::now();
auto elapsed = end - start;
if (elapsed >= timeout)
- return Error("Timed out");
+ return Status("Timed out");
size_t n = m_conn->Read(buffer, sizeof(buffer),
duration_cast<microseconds>(timeout - elapsed),
@@ -285,7 +286,7 @@ Error AdbClient::ReadMessageStream(std::vector<char> &message,
return error;
}
-Error AdbClient::ReadResponseStatus() {
+Status AdbClient::ReadResponseStatus() {
char response_id[5];
static const size_t packet_len = 4;
@@ -301,9 +302,9 @@ Error AdbClient::ReadResponseStatus() {
return error;
}
-Error AdbClient::GetResponseError(const char *response_id) {
+Status AdbClient::GetResponseError(const char *response_id) {
if (strcmp(response_id, kFAIL) != 0)
- return Error("Got unexpected response id from adb: \"%s\"", response_id);
+ return Status("Got unexpected response id from adb: \"%s\"", response_id);
std::vector<char> error_message;
auto error = ReadMessage(error_message);
@@ -314,7 +315,7 @@ Error AdbClient::GetResponseError(const char *response_id) {
return error;
}
-Error AdbClient::SwitchDeviceTransport() {
+Status AdbClient::SwitchDeviceTransport() {
std::ostringstream msg;
msg << "host:transport:" << m_device_id;
@@ -325,19 +326,20 @@ Error AdbClient::SwitchDeviceTransport() {
return ReadResponseStatus();
}
-Error AdbClient::StartSync() {
+Status AdbClient::StartSync() {
auto error = SwitchDeviceTransport();
if (error.Fail())
- return Error("Failed to switch to device transport: %s", error.AsCString());
+ return Status("Failed to switch to device transport: %s",
+ error.AsCString());
error = Sync();
if (error.Fail())
- return Error("Sync failed: %s", error.AsCString());
+ return Status("Sync failed: %s", error.AsCString());
return error;
}
-Error AdbClient::Sync() {
+Status AdbClient::Sync() {
auto error = SendMessage("sync:", false);
if (error.Fail())
return error;
@@ -345,17 +347,18 @@ Error AdbClient::Sync() {
return ReadResponseStatus();
}
-Error AdbClient::ReadAllBytes(void *buffer, size_t size) {
+Status AdbClient::ReadAllBytes(void *buffer, size_t size) {
return ::ReadAllBytes(*m_conn, buffer, size);
}
-Error AdbClient::internalShell(const char *command, milliseconds timeout,
- std::vector<char> &output_buf) {
+Status AdbClient::internalShell(const char *command, milliseconds timeout,
+ std::vector<char> &output_buf) {
output_buf.clear();
auto error = SwitchDeviceTransport();
if (error.Fail())
- return Error("Failed to switch to device transport: %s", error.AsCString());
+ return Status("Failed to switch to device transport: %s",
+ error.AsCString());
StreamString adb_command;
adb_command.Printf("shell:%s", command);
@@ -376,15 +379,15 @@ Error AdbClient::internalShell(const char *command, milliseconds timeout,
static const char *kShellPrefix = "/system/bin/sh:";
if (output_buf.size() > strlen(kShellPrefix)) {
if (!memcmp(&output_buf[0], kShellPrefix, strlen(kShellPrefix)))
- return Error("Shell command %s failed: %s", command,
- std::string(output_buf.begin(), output_buf.end()).c_str());
+ return Status("Shell command %s failed: %s", command,
+ std::string(output_buf.begin(), output_buf.end()).c_str());
}
- return Error();
+ return Status();
}
-Error AdbClient::Shell(const char *command, milliseconds timeout,
- std::string *output) {
+Status AdbClient::Shell(const char *command, milliseconds timeout,
+ std::string *output) {
std::vector<char> output_buffer;
auto error = internalShell(command, timeout, output_buffer);
if (error.Fail())
@@ -395,8 +398,8 @@ Error AdbClient::Shell(const char *command, milliseconds timeout,
return error;
}
-Error AdbClient::ShellToFile(const char *command, milliseconds timeout,
- const FileSpec &output_file_spec) {
+Status AdbClient::ShellToFile(const char *command, milliseconds timeout,
+ const FileSpec &output_file_spec) {
std::vector<char> output_buffer;
auto error = internalShell(command, timeout, output_buffer);
if (error.Fail())
@@ -406,17 +409,17 @@ Error AdbClient::ShellToFile(const char *command, milliseconds timeout,
std::error_code EC;
llvm::raw_fd_ostream dst(output_filename, EC, llvm::sys::fs::F_None);
if (EC)
- return Error("Unable to open local file %s", output_filename.c_str());
+ return Status("Unable to open local file %s", output_filename.c_str());
dst.write(&output_buffer[0], output_buffer.size());
dst.close();
if (dst.has_error())
- return Error("Failed to write file %s", output_filename.c_str());
- return Error();
+ return Status("Failed to write file %s", output_filename.c_str());
+ return Status();
}
std::unique_ptr<AdbClient::SyncService>
-AdbClient::GetSyncService(Error &error) {
+AdbClient::GetSyncService(Status &error) {
std::unique_ptr<SyncService> sync_service;
error = StartSync();
if (error.Success())
@@ -425,15 +428,15 @@ AdbClient::GetSyncService(Error &error) {
return sync_service;
}
-Error AdbClient::SyncService::internalPullFile(const FileSpec &remote_file,
- const FileSpec &local_file) {
+Status AdbClient::SyncService::internalPullFile(const FileSpec &remote_file,
+ const FileSpec &local_file) {
const auto local_file_path = local_file.GetPath();
llvm::FileRemover local_file_remover(local_file_path);
std::error_code EC;
llvm::raw_fd_ostream dst(local_file_path, EC, llvm::sys::fs::F_None);
if (EC)
- return Error("Unable to open local file %s", local_file_path.c_str());
+ return Status("Unable to open local file %s", local_file_path.c_str());
const auto remote_file_path = remote_file.GetPath(false);
auto error = SendSyncRequest(kRECV, remote_file_path.length(),
@@ -452,18 +455,18 @@ Error AdbClient::SyncService::internalPullFile(const FileSpec &remote_file,
}
dst.close();
if (dst.has_error())
- return Error("Failed to write file %s", local_file_path.c_str());
+ return Status("Failed to write file %s", local_file_path.c_str());
local_file_remover.releaseFile();
return error;
}
-Error AdbClient::SyncService::internalPushFile(const FileSpec &local_file,
- const FileSpec &remote_file) {
+Status AdbClient::SyncService::internalPushFile(const FileSpec &local_file,
+ const FileSpec &remote_file) {
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", local_file_path.c_str());
+ return Status("Unable to open local file %s", local_file_path.c_str());
std::stringstream file_description;
file_description << remote_file.GetPath(false).c_str() << "," << kDefaultMode;
@@ -478,7 +481,7 @@ Error AdbClient::SyncService::internalPushFile(const FileSpec &local_file,
size_t chunk_size = src.gcount();
error = SendSyncRequest(kDATA, chunk_size, chunk);
if (error.Fail())
- return Error("Failed to send file chunk: %s", error.AsCString());
+ return Status("Failed to send file chunk: %s", error.AsCString());
}
error = SendSyncRequest(
kDONE, llvm::sys::toTimeT(FileSystem::GetModificationTime(local_file)),
@@ -490,31 +493,31 @@ Error AdbClient::SyncService::internalPushFile(const FileSpec &local_file,
uint32_t data_len;
error = ReadSyncHeader(response_id, data_len);
if (error.Fail())
- return Error("Failed to read DONE response: %s", error.AsCString());
+ return Status("Failed to read DONE response: %s", error.AsCString());
if (response_id == kFAIL) {
std::string error_message(data_len, 0);
error = ReadAllBytes(&error_message[0], data_len);
if (error.Fail())
- return Error("Failed to read DONE error message: %s", error.AsCString());
- return Error("Failed to push file: %s", error_message.c_str());
+ return Status("Failed to read DONE error message: %s", error.AsCString());
+ return Status("Failed to push file: %s", error_message.c_str());
} else if (response_id != kOKAY)
- return Error("Got unexpected DONE response: %s", response_id.c_str());
+ return Status("Got unexpected DONE response: %s", response_id.c_str());
// 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", local_file_path.c_str());
+ return Status("Failed read on %s", local_file_path.c_str());
return error;
}
-Error AdbClient::SyncService::internalStat(const FileSpec &remote_file,
- uint32_t &mode, uint32_t &size,
- uint32_t &mtime) {
+Status AdbClient::SyncService::internalStat(const FileSpec &remote_file,
+ uint32_t &mode, uint32_t &size,
+ uint32_t &mtime) {
const std::string remote_file_path(remote_file.GetPath(false));
auto error = SendSyncRequest(kSTAT, remote_file_path.length(),
remote_file_path.c_str());
if (error.Fail())
- return Error("Failed to send request: %s", error.AsCString());
+ return Status("Failed to send request: %s", error.AsCString());
static const size_t stat_len = strlen(kSTAT);
static const size_t response_len = stat_len + (sizeof(uint32_t) * 3);
@@ -522,7 +525,7 @@ Error AdbClient::SyncService::internalStat(const FileSpec &remote_file,
std::vector<char> buffer(response_len);
error = ReadAllBytes(&buffer[0], buffer.size());
if (error.Fail())
- return Error("Failed to read response: %s", error.AsCString());
+ return Status("Failed to read response: %s", error.AsCString());
DataExtractor extractor(&buffer[0], buffer.size(), eByteOrderLittle,
sizeof(void *));
@@ -530,33 +533,33 @@ Error AdbClient::SyncService::internalStat(const FileSpec &remote_file,
const void *command = extractor.GetData(&offset, stat_len);
if (!command)
- return Error("Failed to get response command");
+ return Status("Failed to get response command");
const char *command_str = static_cast<const char *>(command);
if (strncmp(command_str, kSTAT, stat_len))
- return Error("Got invalid stat command: %s", command_str);
+ return Status("Got invalid stat command: %s", command_str);
mode = extractor.GetU32(&offset);
size = extractor.GetU32(&offset);
mtime = extractor.GetU32(&offset);
- return Error();
+ return Status();
}
-Error AdbClient::SyncService::PullFile(const FileSpec &remote_file,
- const FileSpec &local_file) {
+Status AdbClient::SyncService::PullFile(const FileSpec &remote_file,
+ const FileSpec &local_file) {
return executeCommand([this, &remote_file, &local_file]() {
return internalPullFile(remote_file, local_file);
});
}
-Error AdbClient::SyncService::PushFile(const FileSpec &local_file,
- const FileSpec &remote_file) {
+Status AdbClient::SyncService::PushFile(const FileSpec &local_file,
+ const FileSpec &remote_file) {
return executeCommand([this, &local_file, &remote_file]() {
return internalPushFile(local_file, remote_file);
});
}
-Error AdbClient::SyncService::Stat(const FileSpec &remote_file, uint32_t &mode,
- uint32_t &size, uint32_t &mtime) {
+Status AdbClient::SyncService::Stat(const FileSpec &remote_file, uint32_t &mode,
+ uint32_t &size, uint32_t &mtime) {
return executeCommand([this, &remote_file, &mode, &size, &mtime]() {
return internalStat(remote_file, mode, size, mtime);
});
@@ -569,10 +572,10 @@ bool AdbClient::SyncService::IsConnected() const {
AdbClient::SyncService::SyncService(std::unique_ptr<Connection> &&conn)
: m_conn(std::move(conn)) {}
-Error AdbClient::SyncService::executeCommand(
- const std::function<Error()> &cmd) {
+Status
+AdbClient::SyncService::executeCommand(const std::function<Status()> &cmd) {
if (!m_conn)
- return Error("SyncService is disconnected");
+ return Status("SyncService is disconnected");
const auto error = cmd();
if (error.Fail())
@@ -583,15 +586,15 @@ Error AdbClient::SyncService::executeCommand(
AdbClient::SyncService::~SyncService() {}
-Error AdbClient::SyncService::SendSyncRequest(const char *request_id,
- const uint32_t data_len,
- const void *data) {
+Status AdbClient::SyncService::SendSyncRequest(const char *request_id,
+ const uint32_t data_len,
+ const void *data) {
const DataBufferSP data_sp(new DataBufferHeap(kSyncPacketLen, 0));
DataEncoder encoder(data_sp, eByteOrderLittle, sizeof(void *));
auto offset = encoder.PutData(0, request_id, strlen(request_id));
encoder.PutU32(offset, data_len);
- Error error;
+ Status error;
ConnectionStatus status;
m_conn->Write(data_sp->GetBytes(), kSyncPacketLen, status, &error);
if (error.Fail())
@@ -602,8 +605,8 @@ Error AdbClient::SyncService::SendSyncRequest(const char *request_id,
return error;
}
-Error AdbClient::SyncService::ReadSyncHeader(std::string &response_id,
- uint32_t &data_len) {
+Status AdbClient::SyncService::ReadSyncHeader(std::string &response_id,
+ uint32_t &data_len) {
char buffer[kSyncPacketLen];
auto error = ReadAllBytes(buffer, kSyncPacketLen);
@@ -617,8 +620,8 @@ Error AdbClient::SyncService::ReadSyncHeader(std::string &response_id,
return error;
}
-Error AdbClient::SyncService::PullFileChunk(std::vector<char> &buffer,
- bool &eof) {
+Status AdbClient::SyncService::PullFileChunk(std::vector<char> &buffer,
+ bool &eof) {
buffer.clear();
std::string response_id;
@@ -638,14 +641,14 @@ Error AdbClient::SyncService::PullFileChunk(std::vector<char> &buffer,
std::string error_message(data_len, 0);
error = ReadAllBytes(&error_message[0], data_len);
if (error.Fail())
- return Error("Failed to read pull error message: %s", error.AsCString());
- return Error("Failed to pull file: %s", error_message.c_str());
+ return Status("Failed to read pull error message: %s", error.AsCString());
+ return Status("Failed to pull file: %s", error_message.c_str());
} else
- return Error("Pull failed with unknown response: %s", response_id.c_str());
+ return Status("Pull failed with unknown response: %s", response_id.c_str());
- return Error();
+ return Status();
}
-Error AdbClient::SyncService::ReadAllBytes(void *buffer, size_t size) {
+Status AdbClient::SyncService::ReadAllBytes(void *buffer, size_t size) {
return ::ReadAllBytes(*m_conn, buffer, size);
}
diff --git a/source/Plugins/Platform/Android/AdbClient.h b/source/Plugins/Platform/Android/AdbClient.h
index 9e8726c93b61e..0d2100fc5663b 100644
--- a/source/Plugins/Platform/Android/AdbClient.h
+++ b/source/Plugins/Platform/Android/AdbClient.h
@@ -10,7 +10,7 @@
#ifndef liblldb_AdbClient_h_
#define liblldb_AdbClient_h_
-#include "lldb/Utility/Error.h"
+#include "lldb/Utility/Status.h"
#include <chrono>
#include <functional>
#include <list>
@@ -39,42 +39,42 @@ public:
public:
~SyncService();
- Error PullFile(const FileSpec &remote_file, const FileSpec &local_file);
+ Status PullFile(const FileSpec &remote_file, const FileSpec &local_file);
- Error PushFile(const FileSpec &local_file, const FileSpec &remote_file);
+ Status PushFile(const FileSpec &local_file, const FileSpec &remote_file);
- Error Stat(const FileSpec &remote_file, uint32_t &mode, uint32_t &size,
- uint32_t &mtime);
+ Status Stat(const FileSpec &remote_file, uint32_t &mode, uint32_t &size,
+ uint32_t &mtime);
bool IsConnected() const;
private:
explicit SyncService(std::unique_ptr<Connection> &&conn);
- Error SendSyncRequest(const char *request_id, const uint32_t data_len,
- const void *data);
+ Status SendSyncRequest(const char *request_id, const uint32_t data_len,
+ const void *data);
- Error ReadSyncHeader(std::string &response_id, uint32_t &data_len);
+ Status ReadSyncHeader(std::string &response_id, uint32_t &data_len);
- Error PullFileChunk(std::vector<char> &buffer, bool &eof);
+ Status PullFileChunk(std::vector<char> &buffer, bool &eof);
- Error ReadAllBytes(void *buffer, size_t size);
+ Status ReadAllBytes(void *buffer, size_t size);
- Error internalPullFile(const FileSpec &remote_file,
- const FileSpec &local_file);
+ Status internalPullFile(const FileSpec &remote_file,
+ const FileSpec &local_file);
- Error internalPushFile(const FileSpec &local_file,
- const FileSpec &remote_file);
+ Status internalPushFile(const FileSpec &local_file,
+ const FileSpec &remote_file);
- Error internalStat(const FileSpec &remote_file, uint32_t &mode,
- uint32_t &size, uint32_t &mtime);
+ Status internalStat(const FileSpec &remote_file, uint32_t &mode,
+ uint32_t &size, uint32_t &mtime);
- Error executeCommand(const std::function<Error()> &cmd);
+ Status executeCommand(const std::function<Status()> &cmd);
std::unique_ptr<Connection> m_conn;
};
- static Error CreateByDeviceID(const std::string &device_id, AdbClient &adb);
+ static Status CreateByDeviceID(const std::string &device_id, AdbClient &adb);
AdbClient();
explicit AdbClient(const std::string &device_id);
@@ -83,52 +83,53 @@ public:
const std::string &GetDeviceID() const;
- Error GetDevices(DeviceIDList &device_list);
+ Status GetDevices(DeviceIDList &device_list);
- Error SetPortForwarding(const uint16_t local_port,
- const uint16_t remote_port);
+ Status SetPortForwarding(const uint16_t local_port,
+ const uint16_t remote_port);
- Error SetPortForwarding(const uint16_t local_port,
- llvm::StringRef remote_socket_name,
- const UnixSocketNamespace socket_namespace);
+ Status SetPortForwarding(const uint16_t local_port,
+ llvm::StringRef remote_socket_name,
+ const UnixSocketNamespace socket_namespace);
- Error DeletePortForwarding(const uint16_t local_port);
+ Status DeletePortForwarding(const uint16_t local_port);
- Error Shell(const char *command, std::chrono::milliseconds timeout,
- std::string *output);
+ Status Shell(const char *command, std::chrono::milliseconds timeout,
+ std::string *output);
- Error ShellToFile(const char *command, std::chrono::milliseconds timeout,
- const FileSpec &output_file_spec);
+ Status ShellToFile(const char *command, std::chrono::milliseconds timeout,
+ const FileSpec &output_file_spec);
- std::unique_ptr<SyncService> GetSyncService(Error &error);
+ std::unique_ptr<SyncService> GetSyncService(Status &error);
- Error SwitchDeviceTransport();
+ Status SwitchDeviceTransport();
private:
- Error Connect();
+ Status Connect();
void SetDeviceID(const std::string &device_id);
- Error SendMessage(const std::string &packet, const bool reconnect = true);
+ Status SendMessage(const std::string &packet, const bool reconnect = true);
- Error SendDeviceMessage(const std::string &packet);
+ Status SendDeviceMessage(const std::string &packet);
- Error ReadMessage(std::vector<char> &message);
+ Status ReadMessage(std::vector<char> &message);
- Error ReadMessageStream(std::vector<char> &message, std::chrono::milliseconds timeout);
+ Status ReadMessageStream(std::vector<char> &message,
+ std::chrono::milliseconds timeout);
- Error GetResponseError(const char *response_id);
+ Status GetResponseError(const char *response_id);
- Error ReadResponseStatus();
+ Status ReadResponseStatus();
- Error Sync();
+ Status Sync();
- Error StartSync();
+ Status StartSync();
- Error internalShell(const char *command, std::chrono::milliseconds timeout,
- std::vector<char> &output_buf);
+ Status internalShell(const char *command, std::chrono::milliseconds timeout,
+ std::vector<char> &output_buf);
- Error ReadAllBytes(void *buffer, size_t size);
+ Status ReadAllBytes(void *buffer, size_t size);
std::string m_device_id;
std::unique_ptr<Connection> m_conn;
diff --git a/source/Plugins/Platform/Android/PlatformAndroid.cpp b/source/Plugins/Platform/Android/PlatformAndroid.cpp
index ad3918d4e202b..d896a9f99e638 100644
--- a/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ b/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -154,12 +154,12 @@ ConstString PlatformAndroid::GetPluginName() {
return GetPluginNameStatic(IsHost());
}
-Error PlatformAndroid::ConnectRemote(Args &args) {
+Status PlatformAndroid::ConnectRemote(Args &args) {
m_device_id.clear();
if (IsHost()) {
- return Error("can't connect to the host platform '%s', always connected",
- GetPluginName().GetCString());
+ return Status("can't connect to the host platform '%s', always connected",
+ GetPluginName().GetCString());
}
if (!m_remote_platform_sp)
@@ -169,9 +169,9 @@ Error PlatformAndroid::ConnectRemote(Args &args) {
llvm::StringRef scheme, host, path;
const char *url = args.GetArgumentAtIndex(0);
if (!url)
- return Error("URL is null.");
+ return Status("URL is null.");
if (!UriParser::Parse(url, scheme, host, port, path))
- return Error("Invalid URL: %s", url);
+ return Status("Invalid URL: %s", url);
if (host != "localhost")
m_device_id = host;
@@ -187,8 +187,8 @@ Error PlatformAndroid::ConnectRemote(Args &args) {
return error;
}
-Error PlatformAndroid::GetFile(const FileSpec &source,
- const FileSpec &destination) {
+Status PlatformAndroid::GetFile(const FileSpec &source,
+ const FileSpec &destination) {
if (IsHost() || !m_remote_platform_sp)
return PlatformLinux::GetFile(source, destination);
@@ -198,7 +198,7 @@ Error PlatformAndroid::GetFile(const FileSpec &source,
source_spec = GetRemoteWorkingDirectory().CopyByAppendingPathComponent(
source_spec.GetCString(false));
- Error error;
+ Status error;
auto sync_service = GetSyncService(error);
if (error.Fail())
return error;
@@ -219,7 +219,7 @@ Error PlatformAndroid::GetFile(const FileSpec &source,
source_file);
if (strchr(source_file, '\'') != nullptr)
- return Error("Doesn't support single-quotes in filenames");
+ return Status("Doesn't support single-quotes in filenames");
// mode == 0 can signify that adbd cannot access the file
// due security constraints - try "cat ..." as a fallback.
@@ -231,9 +231,9 @@ Error PlatformAndroid::GetFile(const FileSpec &source,
return adb.ShellToFile(cmd, minutes(1), destination);
}
-Error PlatformAndroid::PutFile(const FileSpec &source,
- const FileSpec &destination, uint32_t uid,
- uint32_t gid) {
+Status PlatformAndroid::PutFile(const FileSpec &source,
+ const FileSpec &destination, uint32_t uid,
+ uint32_t gid) {
if (IsHost() || !m_remote_platform_sp)
return PlatformLinux::PutFile(source, destination, uid, gid);
@@ -244,7 +244,7 @@ Error PlatformAndroid::PutFile(const FileSpec &source,
destination_spec.GetCString(false));
// TODO: Set correct uid and gid on remote file.
- Error error;
+ Status error;
auto sync_service = GetSyncService(error);
if (error.Fail())
return error;
@@ -253,18 +253,18 @@ Error PlatformAndroid::PutFile(const FileSpec &source,
const char *PlatformAndroid::GetCacheHostname() { return m_device_id.c_str(); }
-Error PlatformAndroid::DownloadModuleSlice(const FileSpec &src_file_spec,
- const uint64_t src_offset,
- const uint64_t src_size,
- const FileSpec &dst_file_spec) {
+Status PlatformAndroid::DownloadModuleSlice(const FileSpec &src_file_spec,
+ const uint64_t src_offset,
+ const uint64_t src_size,
+ const FileSpec &dst_file_spec) {
if (src_offset != 0)
- return Error("Invalid offset - %" PRIu64, src_offset);
+ return Status("Invalid offset - %" PRIu64, src_offset);
return GetFile(src_file_spec, dst_file_spec);
}
-Error PlatformAndroid::DisconnectRemote() {
- Error error = PlatformLinux::DisconnectRemote();
+Status PlatformAndroid::DisconnectRemote() {
+ Status error = PlatformLinux::DisconnectRemote();
if (error.Success()) {
m_device_id.clear();
m_sdk_version = 0;
@@ -285,7 +285,7 @@ uint32_t PlatformAndroid::GetSdkVersion() {
std::string version_string;
AdbClient adb(m_device_id);
- Error error =
+ Status error =
adb.Shell("getprop ro.build.version.sdk", seconds(5), &version_string);
version_string = llvm::StringRef(version_string).trim().str();
@@ -301,34 +301,34 @@ uint32_t PlatformAndroid::GetSdkVersion() {
return m_sdk_version;
}
-Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
- const FileSpec &dst_file_spec) {
+Status PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
+ const FileSpec &dst_file_spec) {
// For oat file we can try to fetch additional debug info from the device
ConstString extension = module_sp->GetFileSpec().GetFileNameExtension();
if (extension != ConstString("oat") && extension != ConstString("odex"))
- return Error(
+ return Status(
"Symbol file downloading only supported for oat and odex files");
// If we have no information about the platform file we can't execute oatdump
if (!module_sp->GetPlatformFileSpec())
- return Error("No platform file specified");
+ return Status("No platform file specified");
// Symbolizer isn't available before SDK version 23
if (GetSdkVersion() < 23)
- return Error("Symbol file generation only supported on SDK 23+");
+ return Status("Symbol file generation only supported on SDK 23+");
// If we already have symtab then we don't have to try and generate one
if (module_sp->GetSectionList()->FindSectionByName(ConstString(".symtab")) !=
nullptr)
- return Error("Symtab already available in the module");
+ return Status("Symtab already available in the module");
AdbClient adb(m_device_id);
std::string tmpdir;
- Error error = adb.Shell("mktemp --directory --tmpdir /data/local/tmp",
- seconds(5), &tmpdir);
+ Status error = adb.Shell("mktemp --directory --tmpdir /data/local/tmp",
+ seconds(5), &tmpdir);
if (error.Fail() || tmpdir.empty())
- return Error("Failed to generate temporary directory on the device (%s)",
- error.AsCString());
+ return Status("Failed to generate temporary directory on the device (%s)",
+ error.AsCString());
tmpdir = llvm::StringRef(tmpdir).trim().str();
// Create file remover for the temporary directory created on the device
@@ -336,7 +336,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
tmpdir_remover(&tmpdir, [&adb](std::string *s) {
StreamString command;
command.Printf("rm -rf %s", s->c_str());
- Error error = adb.Shell(command.GetData(), seconds(5), nullptr);
+ Status error = adb.Shell(command.GetData(), seconds(5), nullptr);
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
if (log && error.Fail())
@@ -353,7 +353,7 @@ Error PlatformAndroid::DownloadSymbolFile(const lldb::ModuleSP &module_sp,
symfile_platform_filespec.GetCString(false));
error = adb.Shell(command.GetData(), minutes(1), nullptr);
if (error.Fail())
- return Error("Oatdump failed: %s", error.AsCString());
+ return Status("Oatdump failed: %s", error.AsCString());
// Download the symbolfile from the remote device
return GetFile(symfile_platform_filespec, dst_file_spec);
@@ -375,7 +375,7 @@ const char *PlatformAndroid::GetLibdlFunctionDeclarations() const {
)";
}
-AdbClient::SyncService *PlatformAndroid::GetSyncService(Error &error) {
+AdbClient::SyncService *PlatformAndroid::GetSyncService(Status &error) {
if (m_adb_sync_svc && m_adb_sync_svc->IsConnected())
return m_adb_sync_svc.get();
diff --git a/source/Plugins/Platform/Android/PlatformAndroid.h b/source/Plugins/Platform/Android/PlatformAndroid.h
index 8417055733f62..8fb4cc71a69fd 100644
--- a/source/Plugins/Platform/Android/PlatformAndroid.h
+++ b/source/Plugins/Platform/Android/PlatformAndroid.h
@@ -51,35 +51,35 @@ public:
// lldb_private::Platform functions
//------------------------------------------------------------
- Error ConnectRemote(Args &args) override;
+ Status ConnectRemote(Args &args) override;
- Error GetFile(const FileSpec &source, const FileSpec &destination) override;
+ Status 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;
+ Status PutFile(const FileSpec &source, const FileSpec &destination,
+ uint32_t uid = UINT32_MAX, uint32_t gid = UINT32_MAX) override;
uint32_t GetSdkVersion();
bool GetRemoteOSVersion() override;
- Error DisconnectRemote() override;
+ Status DisconnectRemote() override;
uint32_t GetDefaultMemoryCacheLineSize() override;
protected:
const char *GetCacheHostname() override;
- Error DownloadModuleSlice(const FileSpec &src_file_spec,
- const uint64_t src_offset, const uint64_t src_size,
- const FileSpec &dst_file_spec) override;
+ Status DownloadModuleSlice(const FileSpec &src_file_spec,
+ const uint64_t src_offset, const uint64_t src_size,
+ const FileSpec &dst_file_spec) override;
- Error DownloadSymbolFile(const lldb::ModuleSP &module_sp,
- const FileSpec &dst_file_spec) override;
+ Status DownloadSymbolFile(const lldb::ModuleSP &module_sp,
+ const FileSpec &dst_file_spec) override;
const char *GetLibdlFunctionDeclarations() const override;
private:
- AdbClient::SyncService *GetSyncService(Error &error);
+ AdbClient::SyncService *GetSyncService(Status &error);
std::unique_ptr<AdbClient::SyncService> m_adb_sync_svc;
std::string m_device_id;
diff --git a/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
index 034518c1d2e35..dbc74833e2870 100644
--- a/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ b/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -10,8 +10,8 @@
// Other libraries and framework includes
#include "lldb/Host/ConnectionFileDescriptor.h"
#include "lldb/Host/common/TCPSocket.h"
-#include "lldb/Utility/Error.h"
#include "lldb/Utility/Log.h"
+#include "lldb/Utility/Status.h"
#include "lldb/Utility/UriParser.h"
#include "PlatformAndroidRemoteGDBServer.h"
@@ -25,7 +25,7 @@ using namespace platform_android;
static const lldb::pid_t g_remote_platform_pid =
0; // Alias for the process id of lldb-platform
-static Error ForwardPortWithAdb(
+static Status ForwardPortWithAdb(
const uint16_t local_port, const uint16_t remote_port,
llvm::StringRef remote_socket_name,
const llvm::Optional<AdbClient::UnixSocketNamespace> &socket_namespace,
@@ -53,20 +53,20 @@ static Error ForwardPortWithAdb(
remote_socket_name.str().c_str(), local_port);
if (!socket_namespace)
- return Error("Invalid socket namespace");
+ return Status("Invalid socket namespace");
return adb.SetPortForwarding(local_port, remote_socket_name,
*socket_namespace);
}
-static Error DeleteForwardPortWithAdb(uint16_t local_port,
- const std::string &device_id) {
+static Status DeleteForwardPortWithAdb(uint16_t local_port,
+ const std::string &device_id) {
AdbClient adb(device_id);
return adb.DeletePortForwarding(local_port);
}
-static Error FindUnusedPort(uint16_t &port) {
- Error error;
+static Status FindUnusedPort(uint16_t &port) {
+ Status error;
std::unique_ptr<TCPSocket> tcp_socket(new TCPSocket(true, false));
if (error.Fail())
return error;
@@ -107,19 +107,20 @@ bool PlatformAndroidRemoteGDBServer::KillSpawnedProcess(lldb::pid_t pid) {
return m_gdb_client.KillSpawnedProcess(pid);
}
-Error PlatformAndroidRemoteGDBServer::ConnectRemote(Args &args) {
+Status PlatformAndroidRemoteGDBServer::ConnectRemote(Args &args) {
m_device_id.clear();
if (args.GetArgumentCount() != 1)
- return Error("\"platform connect\" takes a single argument: <connect-url>");
+ return Status(
+ "\"platform connect\" takes a single argument: <connect-url>");
int remote_port;
llvm::StringRef scheme, host, path;
const char *url = args.GetArgumentAtIndex(0);
if (!url)
- return Error("URL is null.");
+ return Status("URL is null.");
if (!UriParser::Parse(url, scheme, host, remote_port, path))
- return Error("Invalid URL: %s", url);
+ return Status("Invalid URL: %s", url);
if (host != "localhost")
m_device_id = host;
@@ -150,7 +151,7 @@ Error PlatformAndroidRemoteGDBServer::ConnectRemote(Args &args) {
return error;
}
-Error PlatformAndroidRemoteGDBServer::DisconnectRemote() {
+Status PlatformAndroidRemoteGDBServer::DisconnectRemote() {
DeleteForwardPort(g_remote_platform_pid);
return PlatformRemoteGDBServer::DisconnectRemote();
}
@@ -173,12 +174,12 @@ void PlatformAndroidRemoteGDBServer::DeleteForwardPort(lldb::pid_t pid) {
m_port_forwards.erase(it);
}
-Error PlatformAndroidRemoteGDBServer::MakeConnectURL(
+Status PlatformAndroidRemoteGDBServer::MakeConnectURL(
const lldb::pid_t pid, const uint16_t remote_port,
llvm::StringRef remote_socket_name, std::string &connect_url) {
static const int kAttempsNum = 5;
- Error error;
+ Status error;
// There is a race possibility that somebody will occupy
// a port while we're in between FindUnusedPort and ForwardPortWithAdb -
// adding the loop to mitigate such problem.
@@ -205,7 +206,7 @@ Error PlatformAndroidRemoteGDBServer::MakeConnectURL(
lldb::ProcessSP PlatformAndroidRemoteGDBServer::ConnectProcess(
llvm::StringRef connect_url, llvm::StringRef plugin_name,
lldb_private::Debugger &debugger, lldb_private::Target *target,
- lldb_private::Error &error) {
+ lldb_private::Status &error) {
// We don't have the pid of the remote gdbserver when it isn't started by us
// but we still want
// to store the list of port forwards we set up in our port forward map.
diff --git a/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h b/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
index 6d5bfecd99387..1bd13ffe89fea 100644
--- a/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
+++ b/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
@@ -33,15 +33,15 @@ public:
~PlatformAndroidRemoteGDBServer() override;
- Error ConnectRemote(Args &args) override;
+ Status ConnectRemote(Args &args) override;
- Error DisconnectRemote() override;
+ Status DisconnectRemote() override;
lldb::ProcessSP ConnectProcess(llvm::StringRef connect_url,
llvm::StringRef plugin_name,
lldb_private::Debugger &debugger,
lldb_private::Target *target,
- lldb_private::Error &error) override;
+ lldb_private::Status &error) override;
protected:
std::string m_device_id;
@@ -54,9 +54,9 @@ protected:
void DeleteForwardPort(lldb::pid_t pid);
- Error MakeConnectURL(const lldb::pid_t pid, const uint16_t remote_port,
- llvm::StringRef remote_socket_name,
- std::string &connect_url);
+ Status MakeConnectURL(const lldb::pid_t pid, const uint16_t remote_port,
+ llvm::StringRef remote_socket_name,
+ std::string &connect_url);
private:
DISALLOW_COPY_AND_ASSIGN(PlatformAndroidRemoteGDBServer);