[Lldb-commits] [lldb] r233202 - Use Android device serial number instead of hostname as a target identifier within module cache.

Oleksiy Vyalov ovyalov at google.com
Wed Mar 25 10:58:14 PDT 2015


Author: ovyalov
Date: Wed Mar 25 12:58:13 2015
New Revision: 233202

URL: http://llvm.org/viewvc/llvm-project?rev=233202&view=rev
Log:
Use Android device serial number instead of hostname as a target identifier within module cache.

http://reviews.llvm.org/D8597


Modified:
    lldb/trunk/include/lldb/Target/Platform.h
    lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
    lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
    lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
    lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
    lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
    lldb/trunk/source/Target/Platform.cpp

Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=233202&r1=233201&r2=233202&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Wed Mar 25 12:58:13 2015
@@ -1137,6 +1137,9 @@ class ModuleCache;
                              const uint64_t src_size,
                              const FileSpec& dst_file_spec);
 
+        virtual const char *
+        GetCacheHostname ();
+
     private:
         typedef std::function<Error (const ModuleSpec &)> ModuleResolver;
 

Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp?rev=233202&r1=233201&r2=233202&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp Wed Mar 25 12:58:13 2015
@@ -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::strin
     m_device_id = device_id;
 }
 
+const std::string&
+AdbClient::GetDeviceID() const
+{
+    return m_device_id;
+}
+
 Error
 AdbClient::Connect ()
 {

Modified: lldb/trunk/source/Plugins/Platform/Android/AdbClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/AdbClient.h?rev=233202&r1=233201&r2=233202&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.h (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.h Wed Mar 25 12:58:13 2015
@@ -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);
 

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp?rev=233202&r1=233201&r2=233202&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp Wed Mar 25 12:58:13 2015
@@ -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& ar
 
     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 ();
 }

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h?rev=233202&r1=233201&r2=233202&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h Wed Mar 25 12:58:13 2015
@@ -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

Modified: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp?rev=233202&r1=233201&r2=233202&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp Wed Mar 25 12:58:13 2015
@@ -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::
     // 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);
 }
 

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=233202&r1=233201&r2=233202&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Wed Mar 25 12:58:13 2015
@@ -1838,7 +1838,7 @@ Platform::GetCachedSharedModule (const M
 
     // 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 M
 
     // 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 M
     }
 
     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 ();
+}





More information about the lldb-commits mailing list