Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(981)

Unified Diff: mojo/devtools/common/debugger

Issue 1209593002: GDB support for Android in devtools' debugger. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/devtools/common/debugger
diff --git a/mojo/devtools/common/debugger b/mojo/devtools/common/debugger
index b323f4ac6b2f1221cd9658f81716b46dc235dca1..9bd313ecc4e85b6c9086b9ec4219408881647678 100755
--- a/mojo/devtools/common/debugger
+++ b/mojo/devtools/common/debugger
@@ -8,10 +8,22 @@ import os.path
import requests
import subprocess
import sys
+import tempfile
ppi 2015/06/24 15:14:08 add a blank line
etiennej 2015/06/29 15:41:43 Done.
+from android_gdb.install_remote_file_reader import install_binary
_MOJO_DEBUGGER_PORT = 7777
+def _GetDirAbove(dirname):
+ """Returns the directory "above" this file containing |dirname|."""
+ path = os.path.abspath(__file__)
+ while True:
+ path, _ = os.path.split(path)
+ assert path
+ if dirname in os.listdir(path):
+ return path
+
+
def _send_request(request, payload=None):
"""Sends a request to mojo:debugger."""
try:
@@ -132,24 +144,86 @@ def _device_stack(args):
return 0
+def _device_gdb(args):
+ """Run GDB on an instance of Mojo Shell on an android device."""
+ if args.ndk_dir:
+ ndk_dir = args.ndk_dir
+ else:
+ ndk_dir = os.path.join(_GetDirAbove('third_party'), 'third_party',
ppi 2015/06/24 15:14:08 We already have similar logic in devtools, in `sta
etiennej 2015/06/29 15:41:42 Added a TODO.
+ 'android_tools', 'ndk')
+ install_args = {}
+ if args.gsutil_dir:
+ install_args['gsutil'] = os.path.join(args.gsutil_dir, 'gsutil')
+ else:
+ install_args['gsutil'] = os.path.join(
+ _GetDirAbove('depot_tools'), 'depot_tools', 'third_party', 'gsutil',
+ 'gsutil')
+ if args.adb_path:
+ install_args['adb'] = args.adb_path
+ install_binary(**install_args)
+
+ gdb_path = os.path.join(
+ ndk_dir,
+ 'toolchains',
+ # TODO(etiennej): Always select the most recent toolchain?
+ 'arm-linux-androideabi-4.9',
+ 'prebuilt',
+ # TODO(etiennej): DEPS mac NDK and use it on macs.
+ 'linux-x86_64',
+ 'bin',
+ 'arm-linux-androideabi-gdb')
+ python_gdb_script_path = os.path.join(os.path.dirname(__file__),
+ 'android_gdb', 'session.py')
+ # We need to pass some commands to GDB at startup
ppi 2015/06/24 15:14:08 End with a period.
etiennej 2015/06/29 15:41:43 Done.
+ gdb_setup_commands = tempfile.NamedTemporaryFile()
+ gdb_setup_commands.write('source ' + python_gdb_script_path + '\n')
+ debug_session_arguments = {}
+ if args.build_dir:
+ debug_session_arguments["build_directory"] = args.build_dir
+ if args.package_name:
+ debug_session_arguments["package_name"] = args.package_name
+ if args.third_party_dir:
+ debug_session_arguments["third_party_dir"] = args.third_party_dir
+ debug_session_arguments = ', '.join([k + '=' + string_escape(v) for
ppi 2015/06/24 15:14:08 Where string_escape is defined or imported?
etiennej 2015/06/29 15:41:43 Done.
+ k, v in debug_session_arguments.items()])
+ gdb_setup_commands.write('py d = DebugSession('+debug_session_arguments+')\n')
ppi 2015/06/24 15:14:08 Add spaced around "+"es.
etiennej 2015/06/29 15:41:43 Done.
+ gdb_setup_commands.write('py d.start_debug()\n')
+ gdb_setup_commands.flush()
+ gdb_proc = subprocess.Popen([gdb_path, '-x', gdb_setup_commands.name],
+ stdin=sys.stdin,
+ stdout=sys.stdout,
+ stderr=sys.stderr)
+ gdb_proc.wait()
+
+
def _add_device_command(subparsers):
"""Sets up the parser for the 'device' command."""
device_parser = subparsers.add_parser('device',
help='interact with the Android device (requires adb in PATH or passing '
'--adb-path)')
device_parser.add_argument('--adb-path', type=str,
- help='path to the adb tool from the Android SDK')
+ help='path to the adb tool from the Android SDK (optional)')
+ device_parser.add_argument('--ndk-dir', type=str,
+ help='path to the directory containing the Android NDK')
+ device_parser.add_argument('--build-dir', type=str,
+ help='path to the build directory')
device_subparser = device_parser.add_subparsers(
help='the command to run')
device_stack_parser = device_subparser.add_parser('stack',
help='symbolize the crash stacktraces from the device log')
- device_stack_parser.add_argument('--build-dir', type=str,
- help='path to the build directory')
- device_stack_parser.add_argument('--ndk-dir', type=str,
- help='path to the directory containing the Android NDK')
device_stack_parser.set_defaults(func=_device_stack)
+ device_gdb_parser = device_subparser.add_parser('gdb',
+ help='debug a shell instance currently running on a device')
ppi 2015/06/24 15:14:08 "debug" doesn't say much. Please clarify that we a
etiennej 2015/06/29 15:41:43 Done.
+ device_gdb_parser.add_argument('--third_party_dir', type=str,
+ help='Path to a directory containing third party libraries')
+ device_gdb_parser.add_argument('--gsutil_dir', type=str,
+ help='Path to a directory containing gsutil')
+ device_gdb_parser.add_argument('--package_name', type=str,
+ help='Name of the Mojo Shell android package to debug')
+ device_gdb_parser.set_defaults(func=_device_gdb)
qsr 2015/06/24 15:29:01 Hum. It would be good if that worked also for desk
etiennej 2015/06/29 15:41:43 My understanding is that ppi@ wanted to have all a
+
def main():
parser = argparse.ArgumentParser(description='Command-line interface for '
« mojo/devtools/common/android_gdb/session.py ('K') | « mojo/devtools/common/android_gdb/session.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698