Merge "Resolve gdbclient.py -r executable from target"

This commit is contained in:
Kevin Rocard
2017-07-13 18:35:57 +00:00
committed by Gerrit Code Review
2 changed files with 35 additions and 2 deletions

View File

@@ -244,6 +244,33 @@ def find_file(device, executable_path, sysroot, run_as_cmd=None):
return (open(path, "r"), found_locally)
raise RuntimeError('Could not find executable {}'.format(executable_path))
def find_executable_path(device, executable_name, run_as_cmd=None):
"""Find a device executable from its name
This function calls which on the device to retrieve the absolute path of
the executable.
Args:
device: the AndroidDevice object to use.
executable_name: the name of the executable to find.
run_as_cmd: if necessary, run-as or su command to prepend
Returns:
The absolute path of the executable.
Raises:
RuntimeError: could not find the executable.
"""
cmd = ["which", executable_name]
if run_as_cmd:
cmd = run_as_cmd + cmd
try:
output, _ = device.shell(cmd)
return output
except adb.ShellError:
raise RuntimeError("Could not find executable '{}' on "
"device".format(executable_name))
def find_binary(device, pid, sysroot, run_as_cmd=None):
"""Finds a device executable file corresponding to |pid|."""

View File

@@ -144,9 +144,15 @@ def handle_switches(args, sysroot):
elif args.run_cmd:
if not args.run_cmd[0]:
sys.exit("empty command passed to -r")
if not args.run_cmd[0].startswith("/"):
sys.exit("commands passed to -r must use absolute paths")
run_cmd = args.run_cmd
if not run_cmd[0].startswith("/"):
try:
run_cmd[0] = gdbrunner.find_executable_path(device, args.run_cmd[0],
run_as_cmd=args.su_cmd)
except RuntimeError:
sys.exit("Could not find executable '{}' passed to -r, "
"please provide an absolute path.".format(args.run_cmd[0]))
binary_file, local = gdbrunner.find_file(device, run_cmd[0], sysroot,
run_as_cmd=args.su_cmd)
if binary_file is None: