Merge "Show a warning if adb is not root before gdbclient.py" am: 84eeb1a8e6

Original change: https://android-review.googlesource.com/c/platform/development/+/1427154

Change-Id: Ifa7d06ba1e55f8dbff15b37a9a09bf1ac65c4b78
This commit is contained in:
Treehugger Robot
2020-09-15 20:24:56 +00:00
committed by Automerger Merge Worker

View File

@@ -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)
os.unlink(script_path)