Resolve gdbclient.py -r executable from target
gdbclient.py -r allows to provide an executable to be run on the target. Before this patch the absolute path of the executable had to be provided. This was inconvenient as the user has to first look up for the exe on the target before debuging it. With this patch, gdbclient.py will look for the executable on the target if an absolute path is not provided. Test: gdbserver -r ls Change-Id: I610fd0a57b034ba8864874eeb1f7345d4a7daad9 Signed-off-by: Kevin Rocard <krocard@google.com>
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)
|
||||
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|."""
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user