From 3803ec7f07e13bdda454078c291a09ee89153e62 Mon Sep 17 00:00:00 2001 From: Nikita Putikhin Date: Wed, 19 Jul 2023 15:43:51 +0000 Subject: [PATCH] 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 --- .../gdbrunner/gdbrunner/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/python-packages/gdbrunner/gdbrunner/__init__.py b/python-packages/gdbrunner/gdbrunner/__init__.py index 14da6e9ef..ebbe9e0b5 100644 --- a/python-packages/gdbrunner/gdbrunner/__init__.py +++ b/python-packages/gdbrunner/gdbrunner/__init__.py @@ -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]