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

Side by Side Diff: sky/tools/skydb

Issue 855663003: Add very basic support for symboled debugging on android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 from skypy.skyserver import SkyServer 6 from skypy.skyserver import SkyServer
7 import argparse 7 import argparse
8 import json 8 import json
9 import logging 9 import logging
10 import os 10 import os
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 def _connect_to_device(self): 131 def _connect_to_device(self):
132 device = android_commands.AndroidCommands( 132 device = android_commands.AndroidCommands(
133 android_commands.GetAttachedDevices()[0]) 133 android_commands.GetAttachedDevices()[0])
134 device.EnableAdbRoot() 134 device.EnableAdbRoot()
135 return device 135 return device
136 136
137 def sky_server_for_args(self, args): 137 def sky_server_for_args(self, args):
138 # FIXME: This is a hack. sky_server should just take a build_dir 138 # FIXME: This is a hack. sky_server should just take a build_dir
139 # not a magical "configuration" name. 139 # not a magical "configuration" name.
140 configuration = os.path.basename(os.path.normpath(args.build_dir)) 140 configuration = os.path.basename(os.path.normpath(self.paths.build_dir))
141 server_root = self._server_root_for_url(args.url_or_path) 141 server_root = self._server_root_for_url(args.url_or_path)
142 sky_server = SkyServer(self.paths, SKY_SERVER_PORT, 142 sky_server = SkyServer(self.paths, SKY_SERVER_PORT,
143 configuration, server_root) 143 configuration, server_root)
144 return sky_server 144 return sky_server
145 145
146 def _create_paths_for_build_dir(self, build_dir): 146 def _create_paths_for_build_dir(self, build_dir):
147 # skypy.paths.Paths takes a root-relative build_dir argument. :( 147 # skypy.paths.Paths takes a root-relative build_dir argument. :(
148 abs_build_dir = os.path.abspath(build_dir) 148 abs_build_dir = os.path.abspath(build_dir)
149 root_relative_build_dir = os.path.relpath(abs_build_dir, SRC_ROOT) 149 root_relative_build_dir = os.path.relpath(abs_build_dir, SRC_ROOT)
150 return skypy.paths.Paths(root_relative_build_dir) 150 return skypy.paths.Paths(root_relative_build_dir)
(...skipping 18 matching lines...) Expand all
169 self.stop_command(None) # Quit any existing process. 169 self.stop_command(None) # Quit any existing process.
170 170
171 if not os.path.exists(self.paths.mojo_shell_path): 171 if not os.path.exists(self.paths.mojo_shell_path):
172 print "mojo_shell not found in build_dir '%s'" % args.build_dir 172 print "mojo_shell not found in build_dir '%s'" % args.build_dir
173 print "Are you sure you sure that's a valid build_dir location?" 173 print "Are you sure you sure that's a valid build_dir location?"
174 print "See skydb start --help for more info" 174 print "See skydb start --help for more info"
175 sys.exit(2) 175 sys.exit(2)
176 176
177 # FIXME: This is probably not the right way to compute is_android 177 # FIXME: This is probably not the right way to compute is_android
178 # from the build directory? 178 # from the build directory?
179 gn_args = gn_args_from_build_dir(args.build_dir) 179 gn_args = gn_args_from_build_dir(self.paths.build_dir)
180 is_android = 'android_sdk_version' in gn_args 180 is_android = 'android_sdk_version' in gn_args
181 181
182 sky_server = self.sky_server_for_args(args) 182 sky_server = self.sky_server_for_args(args)
183 self.pids['sky_server_pid'] = sky_server.start() 183 self.pids['sky_server_pid'] = sky_server.start()
184 self.pids['sky_server_port'] = sky_server.port 184 self.pids['sky_server_port'] = sky_server.port
185 self.pids['sky_server_root'] = sky_server.root 185 self.pids['sky_server_root'] = sky_server.root
186 186
187 self.pids['build_dir'] = args.build_dir 187 self.pids['build_dir'] = self.paths.build_dir
188 self.pids['sky_command_port'] = args.command_port 188 self.pids['sky_command_port'] = args.command_port
189 189
190 if is_android: 190 if is_android:
191 # Pray to the build/android gods in their misspelled tongue. 191 # Pray to the build/android gods in their misspelled tongue.
192 constants.SetOutputDirectort(args.build_dir) 192 constants.SetOutputDirectort(self.paths.build_dir)
193 193
194 device = self._connect_to_device() 194 device = self._connect_to_device()
195 self.pids['device_serial'] = device.GetDevice() 195 self.pids['device_serial'] = device.GetDevice()
196 196
197 forwarder.Forwarder.Map([(0, sky_server.port)], device) 197 forwarder.Forwarder.Map([(0, sky_server.port)], device)
198 device_http_port = forwarder.Forwarder.DevicePortForHostPort( 198 device_http_port = forwarder.Forwarder.DevicePortForHostPort(
199 sky_server.port) 199 sky_server.port)
200 self.pids['remote_sky_server_port'] = device_http_port 200 self.pids['remote_sky_server_port'] = device_http_port
201 201
202 port_string = 'tcp:%s' % args.command_port 202 port_string = 'tcp:%s' % args.command_port
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 links_path, 402 links_path,
403 self.pids['build_dir'], 403 self.pids['build_dir'],
404 'http://localhost:%s' % self.pids['remote_sky_server_port'] 404 'http://localhost:%s' % self.pids['remote_sky_server_port']
405 ] 405 ]
406 self.pids['mojo_cache_linker_pid'] = \ 406 self.pids['mojo_cache_linker_pid'] = \
407 subprocess.Popen(cache_linker_cmd, stdin=logcat.stdout).pid 407 subprocess.Popen(cache_linker_cmd, stdin=logcat.stdout).pid
408 408
409 # Write out our pid file before we exec ourselves. 409 # Write out our pid file before we exec ourselves.
410 self._write_pid_file(PID_FILE_PATH, self.pids) 410 self._write_pid_file(PID_FILE_PATH, self.pids)
411 411
412 # Pull down the system libraries this pid has already mapped in.
413 # TODO(eseidel): This does not handle dynamic loads well.
414 system_libs_root = '/tmp/device_libs'
415 library_cacher_path = os.path.join(
416 self.paths.sky_tools_directory, 'android_library_cacher.py')
417 subprocess.call([
418 library_cacher_path, system_libs_root, self.pids['mojo_shell_pid']
419 ])
420
421 # TODO(eseidel): adb_gdb does, this, unclear why solib-absolute-prefix
422 # doesn't make this explicit listing not necessary?
423 system_lib_dirs = subprocess.check_output([
424 'find', system_libs_root,
425 '-mindepth', '1',
426 '-maxdepth', '4',
427 '-type', 'd',
428 ]).strip().split('\n')
429
412 # TODO(eseidel): Need to sync down system libraries into a directory. 430 # TODO(eseidel): Need to sync down system libraries into a directory.
413 symbol_search_paths = [ 431 symbol_search_paths = system_lib_dirs + [
414 links_path, 432 links_path,
415 self.pids['build_dir'], 433 self.pids['build_dir'],
416 ] 434 ]
417 # TODO(eseidel): We need to look up the toolchain somehow? 435 # TODO(eseidel): We need to look up the toolchain somehow?
418 gdb_path = os.path.join(SRC_ROOT, 'third_party/android_tools/ndk/' 436 gdb_path = os.path.join(SRC_ROOT, 'third_party/android_tools/ndk/'
419 'toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/' 437 'toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/'
420 'bin/arm-linux-androideabi-gdb') 438 'bin/arm-linux-androideabi-gdb')
421 gdb_command = [ 439 gdb_command = [
422 gdb_path, 440 gdb_path,
423 '--eval-command', 'file %s' % self.paths.mojo_shell_path, 441 '--eval-command', 'file %s' % self.paths.mojo_shell_path,
424 '--eval-command', 'directory %s' % self.paths.src_root, 442 '--eval-command', 'directory %s' % self.paths.src_root,
425 '--eval-command', 'target remote localhost:%s' % GDB_PORT, 443 '--eval-command', 'target remote localhost:%s' % GDB_PORT,
426 '--eval-command', 'set solib-search-path %s' % 444 '--eval-command', 'set solib-search-path %s' %
427 ':'.join(symbol_search_paths), 445 ':'.join(symbol_search_paths),
446 '--eval-command', 'set solib-absolute-prefix %s' % system_libs_root,
428 ] 447 ]
429 print " ".join(gdb_command) 448 print " ".join(gdb_command)
430 # We don't want python listening for signals or anything, so exec 449 # We don't want python listening for signals or anything, so exec
431 # gdb and let it take the entire process. 450 # gdb and let it take the entire process.
432 os.execv(gdb_command[0], gdb_command) 451 os.execv(gdb_command[0], gdb_command)
433 452
434 def print_crash_command(self, args): 453 def print_crash_command(self, args):
435 logcat_cmd = ['adb', 'logcat', '-d'] 454 logcat_cmd = ['adb', 'logcat', '-d']
436 logcat = subprocess.Popen(logcat_cmd, stdout=subprocess.PIPE) 455 logcat = subprocess.Popen(logcat_cmd, stdout=subprocess.PIPE)
437 456
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 load_parser.set_defaults(func=self.load_command) 516 load_parser.set_defaults(func=self.load_command)
498 517
499 args = parser.parse_args() 518 args = parser.parse_args()
500 args.func(args) 519 args.func(args)
501 520
502 self._write_pid_file(PID_FILE_PATH, self.pids) 521 self._write_pid_file(PID_FILE_PATH, self.pids)
503 522
504 523
505 if __name__ == '__main__': 524 if __name__ == '__main__':
506 SkyDebugger().main() 525 SkyDebugger().main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698