summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
diff options
context:
space:
mode:
authorChaoren Lin <chaorenl@google.com>2015-05-01 16:49:28 +0000
committerChaoren Lin <chaorenl@google.com>2015-05-01 16:49:28 +0000
commit3ea689b313d43355faa0e5ab68b26367ee30de83 (patch)
tree66b135a8d1e48bd7155a47c2f725ead721816df9 /lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
parentec53482aeff13b47672f2a19e499e43daf272f77 (diff)
downloadbcm5719-llvm-3ea689b313d43355faa0e5ab68b26367ee30de83.tar.gz
bcm5719-llvm-3ea689b313d43355faa0e5ab68b26367ee30de83.zip
Support remote-android with multiple connected devices.
Summary: This change introduces a new URL scheme for `platform connect`: ``` adb://device-id:port ``` Reviewers: vharron, tberghammer, clayborg, ovyalov Reviewed By: ovyalov Subscribers: tberghammer, lldb-commits Differential Revision: http://reviews.llvm.org/D9358 llvm-svn: 236321
Diffstat (limited to 'lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp')
-rw-r--r--lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp58
1 files changed, 29 insertions, 29 deletions
diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
index 2cb487ad181..213c3b27c6e 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -27,18 +27,16 @@ ForwardPortWithAdb (uint16_t port, std::string& device_id)
{
Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
- // Fetch the device list from ADB and if only 1 device found then use that device
- // TODO: Handle the case when more device is available
AdbClient adb;
- auto error = AdbClient::CreateByDeviceID (nullptr, adb);
+ auto error = AdbClient::CreateByDeviceID(device_id, adb);
if (error.Fail ())
return error;
- device_id = adb.GetDeviceID ();
+ device_id = adb.GetDeviceID();
if (log)
log->Printf("Connected to Android device \"%s\"", device_id.c_str ());
- return adb.SetPortForwarding (port);
+ return adb.SetPortForwarding(port);
}
static Error
@@ -55,9 +53,7 @@ PlatformAndroidRemoteGDBServer::PlatformAndroidRemoteGDBServer ()
PlatformAndroidRemoteGDBServer::~PlatformAndroidRemoteGDBServer ()
{
for (const auto& it : m_port_forwards)
- {
- DeleteForwardPortWithAdb (it.second.first, it.second.second);
- }
+ DeleteForwardPortWithAdb(it.second, m_device_id);
}
uint16_t
@@ -67,12 +63,11 @@ PlatformAndroidRemoteGDBServer::LaunchGDBserverAndGetPort (lldb::pid_t &pid)
if (port == 0)
return port;
- std::string device_id;
- Error error = ForwardPortWithAdb (port, device_id);
+ Error error = ForwardPortWithAdb(port, m_device_id);
if (error.Fail ())
return 0;
- m_port_forwards[pid] = std::make_pair (port, device_id);
+ m_port_forwards[pid] = port;
return port;
}
@@ -87,23 +82,28 @@ PlatformAndroidRemoteGDBServer::KillSpawnedProcess (lldb::pid_t pid)
Error
PlatformAndroidRemoteGDBServer::ConnectRemote (Args& args)
{
- if (args.GetArgumentCount () != 1)
- return Error ("\"platform connect\" takes a single argument: <connect-url>");
-
+ m_device_id.clear();
+
+ if (args.GetArgumentCount() != 1)
+ return Error("\"platform connect\" takes a single argument: <connect-url>");
+
int port;
std::string scheme, host, path;
const char *url = args.GetArgumentAtIndex (0);
+ if (!url)
+ return Error("URL is null.");
if (!UriParser::Parse (url, scheme, host, port, path))
- return Error ("invalid uri");
+ return Error("Invalid URL: %s", url);
+ if (scheme == "adb")
+ m_device_id = host;
- std::string device_id;
- Error error = ForwardPortWithAdb (port, device_id);
- if (error.Fail ())
+ Error error = ForwardPortWithAdb(port, m_device_id);
+ if (error.Fail())
return error;
- m_port_forwards[g_remote_platform_pid] = std::make_pair (port, device_id);
+ m_port_forwards[g_remote_platform_pid] = port;
- error = PlatformRemoteGDBServer::ConnectRemote (args);
+ error = PlatformRemoteGDBServer::ConnectRemote(args);
if (error.Fail ())
DeleteForwardPort (g_remote_platform_pid);
@@ -120,18 +120,18 @@ PlatformAndroidRemoteGDBServer::DisconnectRemote ()
void
PlatformAndroidRemoteGDBServer::DeleteForwardPort (lldb::pid_t pid)
{
- Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_PLATFORM));
+ Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
- auto it = m_port_forwards.find (pid);
- if (it == m_port_forwards.end ())
+ auto it = m_port_forwards.find(pid);
+ if (it == m_port_forwards.end())
return;
- const auto& forward_val = it->second;
- const auto error = DeleteForwardPortWithAdb (forward_val.first, forward_val.second);
- if (error.Fail ()) {
+ const auto port = it->second;
+ const auto error = DeleteForwardPortWithAdb(port, m_device_id);
+ if (error.Fail()) {
if (log)
- log->Printf ("Failed to delete port forwarding (pid=%" PRIu64 ", port=%d, device=%s): %s",
- pid, forward_val.first, forward_val.second.c_str (), error.AsCString ());
+ log->Printf("Failed to delete port forwarding (pid=%" PRIu64 ", port=%d, device=%s): %s",
+ pid, port, m_device_id.c_str(), error.AsCString());
}
- m_port_forwards.erase (it);
+ m_port_forwards.erase(it);
}
OpenPOWER on IntegriCloud