gdbclient.py: Implement --chroot argument.
This allows executables to be debugged inside a chroot (such as the ART testing chroot). Change-Id: I1b790c3c2307e240d37ed0afb9a930d00957acec
This commit is contained in:
@@ -142,8 +142,8 @@ def get_pids(device, process_name):
|
|||||||
|
|
||||||
|
|
||||||
def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
|
def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
|
||||||
target_pid, run_cmd, debug_socket, port, run_as_cmd=None,
|
target_pid, run_cmd, debug_socket, port, run_as_cmd=[],
|
||||||
lldb=False):
|
lldb=False, chroot=""):
|
||||||
"""Start gdbserver in the background and forward necessary ports.
|
"""Start gdbserver in the background and forward necessary ports.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -162,15 +162,15 @@ def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
|
|||||||
|
|
||||||
assert target_pid is None or run_cmd is None
|
assert target_pid is None or run_cmd is None
|
||||||
|
|
||||||
|
if chroot:
|
||||||
|
run_as_cmd = ["chroot", chroot] + run_as_cmd
|
||||||
|
|
||||||
# Remove the old socket file.
|
# Remove the old socket file.
|
||||||
rm_cmd = ["rm", debug_socket]
|
device.shell_nocheck(run_as_cmd + ["rm", debug_socket])
|
||||||
if run_as_cmd:
|
|
||||||
rm_cmd = run_as_cmd + rm_cmd
|
|
||||||
device.shell_nocheck(rm_cmd)
|
|
||||||
|
|
||||||
# Push gdbserver to the target.
|
# Push gdbserver to the target.
|
||||||
if gdbserver_local_path is not None:
|
if gdbserver_local_path is not None:
|
||||||
device.push(gdbserver_local_path, gdbserver_remote_path)
|
device.push(gdbserver_local_path, chroot + gdbserver_remote_path)
|
||||||
|
|
||||||
# Run gdbserver.
|
# Run gdbserver.
|
||||||
gdbserver_cmd = [gdbserver_remote_path]
|
gdbserver_cmd = [gdbserver_remote_path]
|
||||||
@@ -184,9 +184,8 @@ def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
|
|||||||
else:
|
else:
|
||||||
gdbserver_cmd += ["--"] + run_cmd
|
gdbserver_cmd += ["--"] + run_cmd
|
||||||
|
|
||||||
forward_gdbserver_port(device, local=port, remote="localfilesystem:{}".format(debug_socket))
|
forward_gdbserver_port(device, local=port, remote="localfilesystem:{}".format(chroot + debug_socket))
|
||||||
|
|
||||||
if run_as_cmd:
|
|
||||||
gdbserver_cmd = run_as_cmd + gdbserver_cmd
|
gdbserver_cmd = run_as_cmd + gdbserver_cmd
|
||||||
|
|
||||||
if lldb:
|
if lldb:
|
||||||
|
|||||||
@@ -102,6 +102,9 @@ def parse_args():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--env", nargs=1, action="append", metavar="VAR=VALUE",
|
"--env", nargs=1, action="append", metavar="VAR=VALUE",
|
||||||
help="set environment variable when running a binary")
|
help="set environment variable when running a binary")
|
||||||
|
parser.add_argument(
|
||||||
|
"--chroot", nargs='?', default="", metavar="PATH",
|
||||||
|
help="run command in a chroot in the given directory")
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@@ -315,6 +318,9 @@ def do_main():
|
|||||||
sysroot = os.path.join(os.environ["ANDROID_PRODUCT_OUT"], "symbols")
|
sysroot = os.path.join(os.environ["ANDROID_PRODUCT_OUT"], "symbols")
|
||||||
|
|
||||||
# Make sure the environment matches the attached device.
|
# Make sure the environment matches the attached device.
|
||||||
|
# Skip when running in a chroot because the chroot lunch target may not
|
||||||
|
# match the device's lunch target.
|
||||||
|
if not args.chroot:
|
||||||
verify_device(root, device)
|
verify_device(root, device)
|
||||||
|
|
||||||
debug_socket = "/data/local/tmp/debug_socket"
|
debug_socket = "/data/local/tmp/debug_socket"
|
||||||
@@ -356,7 +362,7 @@ def do_main():
|
|||||||
gdbrunner.start_gdbserver(
|
gdbrunner.start_gdbserver(
|
||||||
device, server_local_path, server_remote_path,
|
device, server_local_path, server_remote_path,
|
||||||
target_pid=pid, run_cmd=run_cmd, debug_socket=debug_socket,
|
target_pid=pid, run_cmd=run_cmd, debug_socket=debug_socket,
|
||||||
port=args.port, run_as_cmd=cmd_prefix, lldb=True)
|
port=args.port, run_as_cmd=cmd_prefix, lldb=True, chroot=args.chroot)
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
"Connecting to tracing pid {} using local port {}".format(
|
"Connecting to tracing pid {} using local port {}".format(
|
||||||
|
|||||||
Reference in New Issue
Block a user