Print adb output if pushing gdbserver fails

Right now the raised exception only shows the command and return code.
Printing the output should make the error more clear.

Test: adb root, then in adb shell touch the server and make immutable
  touch /data/local/tmp/x86_64-lldb-server
  chattr +i /data/local/tmp/x86_64-lldb-server
  Then on host lldbclient.py -r test
  Fails as expected with with "operation not permitted"

Change-Id: Ie22f41bb90809c2f9bafaee0be6a151d9b017502
This commit is contained in:
Nikita Putikhin
2023-07-19 15:43:51 +00:00
parent eea06cf609
commit 3803ec7f07

View File

@@ -21,6 +21,7 @@ import argparse
import atexit
import os
import re
import shlex
import subprocess
import sys
import tempfile
@@ -170,11 +171,18 @@ def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
# Push gdbserver to the target.
if gdbserver_local_path is not None:
device.push(gdbserver_local_path, chroot + gdbserver_remote_path)
# If the user here is potentially on Windows, adb cannot inspect execute
# permissions. Since we don't know where the users are, chmod
# gdbserver_remote_path on device regardless.
device.shell(["chmod", "+x", gdbserver_remote_path])
try:
device.push(gdbserver_local_path, chroot + gdbserver_remote_path)
# If the user here is potentially on Windows, adb cannot inspect execute
# permissions. Since we don't know where the users are, chmod
# gdbserver_remote_path on device regardless.
device.shell(["chmod", "+x", gdbserver_remote_path])
except subprocess.CalledProcessError as err:
print("Command failed:")
print(shlex.join(err.cmd))
print("Output:")
print(err.output.decode("utf-8"))
raise
# Run gdbserver.
gdbserver_cmd = [gdbserver_remote_path]