[Lldb-commits] [lldb] r274776 - Respect ANDROID_SERIAL environment variable used by ADB

Luke Drummond via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 7 11:02:44 PDT 2016


Author: ldrumm
Date: Thu Jul  7 13:02:44 2016
New Revision: 274776

URL: http://llvm.org/viewvc/llvm-project?rev=274776&view=rev
Log:
Respect ANDROID_SERIAL environment variable used by ADB

When multiple Android devices are attached, the default behaviour of ADB
is to resolve a device number based on the presence of ANDROID_SERIAL if
the serial number is not explicitly passed by the -s parameter. This patch
emulates that behaviour in lldb's ADB platform connector

Differential Revision: http://reviews.llvm.org/D22052

Modified:
    lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp

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=274776&r1=274775&r2=274776&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Android/AdbClient.cpp Thu Jul  7 13:02:44 2016
@@ -25,6 +25,7 @@
 
 #include <limits.h>
 
+#include <cstdlib>
 #include <algorithm>
 #include <fstream>
 #include <sstream>
@@ -99,19 +100,24 @@ AdbClient::CreateByDeviceID(const std::s
     if (error.Fail())
         return error;
 
-    if (device_id.empty())
+    std::string android_serial;
+    if (!device_id.empty())
+        android_serial = device_id;
+    else if (const char *env_serial = std::getenv("ANDROID_SERIAL"))
+        android_serial = env_serial;
+
+    if (android_serial.empty())
     {
         if (connect_devices.size() != 1)
-            return Error("Expected a single connected device, got instead %" PRIu64,
-                    static_cast<uint64_t>(connect_devices.size()));
-
+            return Error("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(), device_id);
+        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", device_id.c_str());
+            return Error("Device \"%s\" not found", android_serial.c_str());
 
         adb.SetDeviceID(*find_it);
     }




More information about the lldb-commits mailing list