Merge "Resolve gdbclient.py -r executable from target"
This commit is contained in:
@@ -244,6 +244,33 @@ def find_file(device, executable_path, sysroot, run_as_cmd=None):
|
|||||||
return (open(path, "r"), found_locally)
|
return (open(path, "r"), found_locally)
|
||||||
raise RuntimeError('Could not find executable {}'.format(executable_path))
|
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):
|
def find_binary(device, pid, sysroot, run_as_cmd=None):
|
||||||
"""Finds a device executable file corresponding to |pid|."""
|
"""Finds a device executable file corresponding to |pid|."""
|
||||||
|
|||||||
@@ -144,9 +144,15 @@ def handle_switches(args, sysroot):
|
|||||||
elif args.run_cmd:
|
elif args.run_cmd:
|
||||||
if not args.run_cmd[0]:
|
if not args.run_cmd[0]:
|
||||||
sys.exit("empty command passed to -r")
|
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
|
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,
|
binary_file, local = gdbrunner.find_file(device, run_cmd[0], sysroot,
|
||||||
run_as_cmd=args.su_cmd)
|
run_as_cmd=args.su_cmd)
|
||||||
if binary_file is None:
|
if binary_file is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user