summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorOleksiy Vyalov <ovyalov@google.com>2015-03-25 17:58:13 +0000
committerOleksiy Vyalov <ovyalov@google.com>2015-03-25 17:58:13 +0000
commit6f001068d3263ce161ba0dd3b4b5cddbf555d09d (patch)
treef9516e27525d3a9633f149f1a985ac32d52b56f5 /lldb/source
parentff2a64cf1bedc3196f949848fcf8773b95484c60 (diff)
downloadbcm5719-llvm-6f001068d3263ce161ba0dd3b4b5cddbf555d09d.tar.gz
bcm5719-llvm-6f001068d3263ce161ba0dd3b4b5cddbf555d09d.zip
Use Android device serial number instead of hostname as a target identifier within module cache.
http://reviews.llvm.org/D8597 llvm-svn: 233202
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Plugins/Platform/Android/AdbClient.cpp34
-rw-r--r--lldb/source/Plugins/Platform/Android/AdbClient.h11
-rw-r--r--lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp24
-rw-r--r--lldb/source/Plugins/Platform/Android/PlatformAndroid.h8
-rw-r--r--lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp13
-rw-r--r--lldb/source/Target/Platform.cpp12
6 files changed, 84 insertions, 18 deletions
diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.cpp b/lldb/source/Plugins/Platform/Android/AdbClient.cpp
index eb094a17439..d3d5878380b 100644
--- a/lldb/source/Plugins/Platform/Android/AdbClient.cpp
+++ b/lldb/source/Plugins/Platform/Android/AdbClient.cpp
@@ -8,7 +8,6 @@
//===----------------------------------------------------------------------===//
// Other libraries and framework includes
-#include "lldb/Host/ConnectionFileDescriptor.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/STLExtras.h"
@@ -16,6 +15,7 @@
// Project includes
#include "AdbClient.h"
+#include <algorithm>
#include <sstream>
using namespace lldb;
@@ -29,6 +29,32 @@ const char * kFAIL = "FAIL";
} // namespace
+Error
+AdbClient::CreateByDeviceID (const char* device_id, AdbClient &adb)
+{
+ DeviceIDList connect_devices;
+ auto error = adb.GetDevices (connect_devices);
+ if (error.Fail ())
+ return error;
+
+ if (device_id)
+ {
+ auto find_it = std::find(connect_devices.begin (), connect_devices.end (), device_id);
+ if (find_it == connect_devices.end ())
+ return Error ("Device \"%s\" not found", device_id);
+
+ adb.SetDeviceID (*find_it);
+ }
+ else
+ {
+ if (connect_devices.size () != 1)
+ return Error ("Expected a single connected device, got instead %zu", connect_devices.size ());
+
+ adb.SetDeviceID (connect_devices.front ());
+ }
+ return error;
+}
+
AdbClient::AdbClient (const std::string &device_id)
: m_device_id (device_id)
{
@@ -40,6 +66,12 @@ AdbClient::SetDeviceID (const std::string& device_id)
m_device_id = device_id;
}
+const std::string&
+AdbClient::GetDeviceID() const
+{
+ return m_device_id;
+}
+
Error
AdbClient::Connect ()
{
diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.h b/lldb/source/Plugins/Platform/Android/AdbClient.h
index 382e30455da..f372b244021 100644
--- a/lldb/source/Plugins/Platform/Android/AdbClient.h
+++ b/lldb/source/Plugins/Platform/Android/AdbClient.h
@@ -21,6 +21,7 @@
// Project includes
#include "lldb/Core/Error.h"
+#include "lldb/Host/ConnectionFileDescriptor.h"
namespace lldb_private {
@@ -29,11 +30,14 @@ class AdbClient
public:
using DeviceIDList = std::list<std::string>;
+ static Error
+ CreateByDeviceID (const char* device_id, AdbClient &adb);
+
AdbClient () = default;
explicit AdbClient (const std::string &device_id);
- void
- SetDeviceID (const std::string& device_id);
+ const std::string&
+ GetDeviceID() const;
Error
GetDevices (DeviceIDList &device_list);
@@ -48,6 +52,9 @@ private:
Error
Connect ();
+ void
+ SetDeviceID (const std::string& device_id);
+
Error
SendMessage (const std::string &packet);
diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
index 02d283b1a51..e339e03db6d 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -15,6 +15,7 @@
#include "lldb/Host/HostInfo.h"
// Project includes
+#include "AdbClient.h"
#include "PlatformAndroid.h"
#include "PlatformAndroidRemoteGDBServer.h"
@@ -171,6 +172,8 @@ PlatformAndroid::GetPluginName()
Error
PlatformAndroid::ConnectRemote (Args& args)
{
+ m_device_id.clear ();
+
if (IsHost())
{
return Error ("can't connect to the host platform '%s', always connected", GetPluginName().GetCString());
@@ -178,5 +181,24 @@ PlatformAndroid::ConnectRemote (Args& args)
if (!m_remote_platform_sp)
m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
- return PlatformLinux::ConnectRemote (args);
+
+ auto error = PlatformLinux::ConnectRemote (args);
+ if (error.Success ())
+ {
+ // 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;
+ error = AdbClient::CreateByDeviceID (nullptr, adb);
+ if (error.Fail ())
+ return error;
+
+ m_device_id = adb.GetDeviceID ();
+ }
+ return error;
+}
+
+const char *
+PlatformAndroid::GetCacheHostname ()
+{
+ return m_device_id.c_str ();
}
diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.h b/lldb/source/Plugins/Platform/Android/PlatformAndroid.h
index eaba103c99b..08b3a027072 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.h
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.h
@@ -12,6 +12,9 @@
// C Includes
// C++ Includes
+
+#include <string>
+
// Other libraries and framework includes
// Project includes
#include "Plugins/Platform/Linux/PlatformLinux.h"
@@ -60,7 +63,12 @@ namespace lldb_private {
lldb_private::Error
ConnectRemote (lldb_private::Args& args) override;
+ protected:
+ const char *
+ GetCacheHostname () override;
+
private:
+ std::string m_device_id;
DISALLOW_COPY_AND_ASSIGN (PlatformAndroid);
};
} // namespace lldb_private
diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
index c32cdd4f1e5..b3c0ff4b12c 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -10,8 +10,6 @@
// Other libraries and framework includes
#include "lldb/Core/Error.h"
#include "lldb/Core/Log.h"
-#include "lldb/Host/ConnectionFileDescriptor.h"
-#include "llvm/ADT/StringRef.h"
// Project includes
#include "AdbClient.h"
@@ -31,20 +29,13 @@ ForwardPortWithAdb (uint16_t port, std::string& device_id)
// 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;
-
- AdbClient::DeviceIDList connect_devices;
- auto error = adb.GetDevices (connect_devices);
+ auto error = AdbClient::CreateByDeviceID (nullptr, adb);
if (error.Fail ())
return error;
- if (connect_devices.size () != 1)
- return Error ("Expected a single connected device, got instead %zu", connect_devices.size ());
-
- device_id = connect_devices.front ();
if (log)
- log->Printf("Connected to Android device \"%s\"", device_id.c_str ());
+ log->Printf("Connected to Android device \"%s\"", adb.GetDeviceID ().c_str ());
- adb.SetDeviceID (device_id);
return adb.SetPortForwarding (port);
}
diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index d5a61f0ecdb..6517d108cc9 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1838,7 +1838,7 @@ Platform::GetCachedSharedModule (const ModuleSpec &module_spec,
// Check local cache for a module.
auto error = m_module_cache->Get (GetModuleCacheRoot (),
- GetHostname (),
+ GetCacheHostname (),
module_spec,
module_sp,
did_create_ptr);
@@ -1880,7 +1880,7 @@ Platform::GetCachedSharedModule (const ModuleSpec &module_spec,
// Put downloaded file into local module cache.
error = m_module_cache->Put (GetModuleCacheRoot (),
- GetHostname (),
+ GetCacheHostname (),
module_spec,
tmp_download_file_spec);
if (error.Fail ())
@@ -1893,7 +1893,7 @@ Platform::GetCachedSharedModule (const ModuleSpec &module_spec,
}
error = m_module_cache->Get (GetModuleCacheRoot (),
- GetHostname (),
+ GetCacheHostname (),
module_spec,
module_sp,
did_create_ptr);
@@ -1958,3 +1958,9 @@ Platform::GetModuleCacheRoot ()
dir_spec.AppendPathComponent (GetName ().AsCString ());
return dir_spec;
}
+
+const char *
+Platform::GetCacheHostname ()
+{
+ return GetHostname ();
+}
OpenPOWER on IntegriCloud