From 0cb1c9b4e5bbb803b7fb89968a7f8c5b21bf7851 Mon Sep 17 00:00:00 2001 From: Haibo Huang Date: Mon, 14 Sep 2020 17:55:55 -0700 Subject: [PATCH] Show a warning if adb is not root before gdbclient.py Bug: 168278173 Change-Id: I0e60c4036b611e31ffd3436ae2389780e9cda0e3 --- python-packages/gdbrunner/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/python-packages/gdbrunner/__init__.py b/python-packages/gdbrunner/__init__.py index f399d732f..d2a557feb 100644 --- a/python-packages/gdbrunner/__init__.py +++ b/python-packages/gdbrunner/__init__.py @@ -197,8 +197,20 @@ def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path, stderr=gdbserver_output) +def get_uid(device): + """Gets the uid adbd runs as.""" + line, _ = device.shell(["id", "-u"]) + return int(line.strip()) + + def forward_gdbserver_port(device, local, remote): """Forwards local TCP port `port` to `remote` via `adb forward`.""" + if get_uid(device) != 0: + WARNING = '\033[93m' + ENDC = '\033[0m' + print(WARNING + + "Port forwarding may not work because adbd is not running as root. " + + " Run `adb root` to fix." + ENDC) device.forward("tcp:{}".format(local), remote) atexit.register(lambda: device.forward_remove("tcp:{}".format(local))) @@ -370,4 +382,4 @@ def start_gdb(gdb_path, gdb_commands, gdb_flags=None, lldb=False): except KeyboardInterrupt: pass - os.unlink(script_path) \ No newline at end of file + os.unlink(script_path)