[Lldb-commits] [PATCH] D11935: Fetch SDK version from PlatformAndroid

Tamas Berghammer via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 12 04:11:01 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL244737: Fetch SDK version from PlatformAndroid (authored by tberghammer).

Changed prior to commit:
  http://reviews.llvm.org/D11935?vs=31822&id=31921#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D11935

Files:
  lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
  lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h

Index: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
===================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.h
@@ -73,6 +73,12 @@
                  const FileSpec& destination,
                  uint32_t uid = UINT32_MAX,
                  uint32_t gid = UINT32_MAX) override;
+        
+        uint32_t
+        GetSdkVersion();
+        
+        Error
+        DisconnectRemote () override;
 
      protected:
         const char *
@@ -86,6 +92,8 @@
 
     private:
         std::string m_device_id;
+        uint32_t m_sdk_version;
+
         DISALLOW_COPY_AND_ASSIGN (PlatformAndroid);
     };
 
Index: lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
===================================================================
--- lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ lldb/trunk/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -13,6 +13,7 @@
 #include "lldb/Core/Log.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Host/HostInfo.h"
+#include "lldb/Host/StringConvert.h"
 #include "Utility/UriParser.h"
 
 // Project includes
@@ -133,7 +134,8 @@
 }
 
 PlatformAndroid::PlatformAndroid (bool is_host) :
-    PlatformLinux(is_host)
+    PlatformLinux(is_host),
+    m_sdk_version(0)
 {
 }
 
@@ -257,3 +259,46 @@
 
     return GetFile (src_file_spec, dst_file_spec);
 }
+
+Error
+PlatformAndroid::DisconnectRemote()
+{
+    Error error = PlatformLinux::DisconnectRemote();
+    if (error.Success())
+    {
+        m_device_id.clear();
+        m_sdk_version = 0;
+    }
+    return error;
+}
+
+uint32_t
+PlatformAndroid::GetSdkVersion()
+{
+    if (!IsConnected())
+        return 0;
+
+    if (m_sdk_version != 0)
+        return m_sdk_version;
+
+    int status = 0;
+    std::string version_string;
+    Error error = RunShellCommand("getprop ro.build.version.sdk",
+                                  GetWorkingDirectory(),
+                                  &status,
+                                  nullptr,
+                                  &version_string,
+                                  1);
+    if (error.Fail() || status != 0 || version_string.empty())
+    {
+        Log* log = GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM);
+        if (log)
+            log->Printf("Get SDK version failed. (status: %d, error: %s, output: %s)",
+                        status, error.AsCString(), version_string.c_str());
+        return 0;
+    }
+    version_string.erase(version_string.size() - 1); // Remove trailing new line
+
+    m_sdk_version = StringConvert::ToUInt32(version_string.c_str());
+    return m_sdk_version;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11935.31921.patch
Type: text/x-patch
Size: 2750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150812/667d1548/attachment-0001.bin>


More information about the lldb-commits mailing list