Merge "Show a warning if adb is not root before gdbclient.py"

This commit is contained in:
Treehugger Robot
2020-09-15 20:03:43 +00:00
committed by Gerrit Code Review

View File

@@ -197,8 +197,20 @@ def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
stderr=gdbserver_output) 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): def forward_gdbserver_port(device, local, remote):
"""Forwards local TCP port `port` to `remote` via `adb forward`.""" """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) device.forward("tcp:{}".format(local), remote)
atexit.register(lambda: device.forward_remove("tcp:{}".format(local))) 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: except KeyboardInterrupt:
pass pass
os.unlink(script_path) os.unlink(script_path)