aboutsummaryrefslogtreecommitdiff
path: root/ndk-gdb.py
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2015-09-08 13:42:41 -0700
committerJosh Gao <jmgao@google.com>2015-09-08 18:19:53 -0700
commit70af7d0e196c7e5da787bf548d0422855635d193 (patch)
tree1a4de2fe08cc497b7928a4dde8a3417f67a8dd57 /ndk-gdb.py
parentce64ba12a3d45907d98cdcfe02065a179ef3bc54 (diff)
downloadndk-70af7d0e196c7e5da787bf548d0422855635d193.tar.gz
[ndk-gdb.py] Select which ps command to run on the device.
Saves an adb roundtrip. Bug: http://b/23793246 Change-Id: Iffce325f7576102cdbf8d2ca7530c77c049b1503
Diffstat (limited to 'ndk-gdb.py')
-rwxr-xr-xndk-gdb.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/ndk-gdb.py b/ndk-gdb.py
index e206dcdc1..7010a5d34 100755
--- a/ndk-gdb.py
+++ b/ndk-gdb.py
@@ -451,13 +451,22 @@ def get_pid_of(package_name):
package names like com.exampleisverylongtoolongbyfar.plasma
exceed the limit.
'''
- ps_command = 'ps'
- retcode,output = adb_cmd(False, ['shell', 'readlink $(which ps)'])
- if output:
- output = output.replace('\r', '').splitlines()[0]
- if output == 'busybox':
- ps_command = 'ps -w'
- retcode,output = adb_cmd(False,['shell', ps_command])
+
+ # Perform the check on the device to avoid an adb roundtrip
+ # Some devices might not have readlink or which, so we need to check for
+ # them.
+ ps_script = '''
+ if [ ! -x /system/bin/readlink -o ! -x /system/bin/which ]; then
+ ps;
+ elif [ $(readlink $(which ps)) == "toolbox" ]; then
+ ps;
+ else
+ ps -w;
+ fi
+ '''
+ ps_script = " ".join([line.strip() for line in ps_script.splitlines()])
+
+ retcode, output = adb_cmd(False, ['shell', ps_script])
output = output.replace('\r', '').splitlines()
columns = output.pop(0).split()
try: