[Lldb-commits] [PATCH] D152494: [lldb][Android] Fix adb shell cat

Kazuki Sakamoto via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 8 21:58:11 PDT 2023


splhack created this revision.
splhack added a reviewer: clayborg.
Herald added a subscriber: danielkiss.
Herald added a project: All.
splhack edited the summary of this revision.
splhack added reviewers: labath, lanza.
splhack published this revision for review.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

When LLDB failed to pull a module file due to the security constraint,
it uses "adb shell cat" as a fallback for getting the file.
However when "adb pull path" fails, "adb shell cat path" also fails
with the same security reason.

Introduce ANDROID_PLATFORM_RUN_AS to grant permission to read the file
with "adb shell run-as package cat path" command line.
https://android.googlesource.com/platform/system/core.git/+/refs/heads/master/run-as/run-as.cpp#39


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152494

Files:
  lldb/docs/use/remote.rst
  lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp


Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
===================================================================
--- lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -204,7 +204,11 @@
   AdbClient adb(m_device_id);
 
   char cmd[PATH_MAX];
-  snprintf(cmd, sizeof(cmd), "cat '%s'", source_file.c_str());
+  if (const char *run_as = std::getenv("ANDROID_PLATFORM_RUN_AS"))
+    snprintf(cmd, sizeof(cmd), "run-as '%s' cat '%s'", run_as,
+             source_file.c_str());
+  else
+    snprintf(cmd, sizeof(cmd), "cat '%s'", source_file.c_str());
 
   return adb.ShellToFile(cmd, minutes(1), destination);
 }
Index: lldb/docs/use/remote.rst
===================================================================
--- lldb/docs/use/remote.rst
+++ lldb/docs/use/remote.rst
@@ -140,6 +140,10 @@
 The client ports are configurable through the environment variables
 ANDROID_PLATFORM_LOCAL_PORT and ANDROID_PLATFORM_LOCAL_GDB_PORT, respectively.
 
+The "remote-android" platform requires ANDROID_PLATFORM_RUN_AS when target
+application install path is not accessible with "adb pull". LLDB will use
+"adb shell run-as $ANDROID_PLATFORM_RUN_AS cat path" to get module file.
+
 Launching a locally built process on the remote machine
 -------------------------------------------------------
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152494.529821.patch
Type: text/x-patch
Size: 1372 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230609/990771a5/attachment.bin>


More information about the lldb-commits mailing list