Merge "Strip more SymbolInfo from dump"
diff --git a/python-packages/gdbrunner/__init__.py b/python-packages/gdbrunner/__init__.py
index 2f142d6..e117816 100644
--- a/python-packages/gdbrunner/__init__.py
+++ b/python-packages/gdbrunner/__init__.py
@@ -79,17 +79,6 @@
return result
-def get_run_as_cmd(user, cmd):
- """Generate a run-as or su command depending on user."""
-
- if user is None:
- return cmd
- elif user == "root":
- return ["su", "0"] + cmd
- else:
- return ["run-as", user] + cmd
-
-
def get_processes(device):
"""Return a dict from process name to list of running PIDs on the device."""
@@ -146,7 +135,7 @@
def start_gdbserver(device, gdbserver_local_path, gdbserver_remote_path,
- target_pid, run_cmd, debug_socket, port, user=None):
+ target_pid, run_cmd, debug_socket, port, run_as_cmd=None):
"""Start gdbserver in the background and forward necessary ports.
Args:
@@ -157,7 +146,7 @@
run_cmd: Command to run on the device.
debug_socket: Device path to place gdbserver unix domain socket.
port: Host port to forward the debug_socket to.
- user: Device user to run gdbserver as.
+ run_as_cmd: run-as or su command to prepend to commands.
Returns:
Popen handle to the `adb shell` process gdbserver was started with.
@@ -181,7 +170,9 @@
device.forward("tcp:{}".format(port),
"localfilesystem:{}".format(debug_socket))
atexit.register(lambda: device.forward_remove("tcp:{}".format(port)))
- gdbserver_cmd = get_run_as_cmd(user, gdbserver_cmd)
+
+ if run_as_cmd:
+ gdbserver_cmd = run_as_cmd + gdbserver_cmd
gdbserver_output_path = os.path.join(tempfile.gettempdir(),
"gdbclient.log")
@@ -191,7 +182,7 @@
stderr=gdbserver_output)
-def find_file(device, executable_path, sysroot, user=None):
+def find_file(device, executable_path, sysroot, run_as_cmd=None):
"""Finds a device executable file.
This function first attempts to find the local file which will
@@ -202,7 +193,7 @@
device: the AndroidDevice object to use.
executable_path: absolute path to the executable or symlink.
sysroot: absolute path to the built symbol sysroot.
- user: if necessary, the user to download the file as.
+ run_as_cmd: if necessary, run-as or su command to prepend
Returns:
A tuple containing (<open file object>, <was found locally>).
@@ -231,8 +222,11 @@
file_name = "gdbclient-binary-{}".format(os.getppid())
remote_temp_path = "/data/local/tmp/{}".format(file_name)
local_path = os.path.join(tempfile.gettempdir(), file_name)
- cmd = get_run_as_cmd(user,
- ["cat", executable_path, ">", remote_temp_path])
+
+ cmd = ["cat", executable_path, ">", remote_temp_path]
+ if run_as_cmd:
+ cmd = run_as_cmd + cmd
+
try:
device.shell(cmd)
except adb.ShellError:
diff --git a/scripts/gdbclient.py b/scripts/gdbclient.py
index 4fb6c7e..d9334ca 100755
--- a/scripts/gdbclient.py
+++ b/scripts/gdbclient.py
@@ -123,6 +123,8 @@
pid = None
run_cmd = None
+ args.su_cmd = ["su", args.user] if args.user else []
+
if args.target_pid:
# Fetch the binary using the PID later.
pid = args.target_pid
@@ -136,12 +138,12 @@
sys.exit("commands passed to -r must use absolute paths")
run_cmd = args.run_cmd
binary_file, local = gdbrunner.find_file(device, run_cmd[0], sysroot,
- user=args.user)
+ run_as_cmd=args.su_cmd)
if binary_file is None:
assert pid is not None
try:
binary_file, local = gdbrunner.find_binary(device, pid, sysroot,
- user=args.user)
+ run_as_cmd=args.su_cmd)
except adb.ShellError:
sys.exit("failed to pull binary for PID {}".format(pid))
@@ -242,7 +244,7 @@
gdbrunner.start_gdbserver(
device, gdbserver_local_path, gdbserver_remote_path,
target_pid=pid, run_cmd=run_cmd, debug_socket=debug_socket,
- port=args.port, user=args.user)
+ port=args.port, run_as_cmd=args.su_cmd)
# Generate a gdb script.
gdb_commands = generate_gdb_script(sysroot=sysroot,