OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2015 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import argparse | |
7 import re | |
8 import sys | |
9 import os | |
10 import logging | |
11 import subprocess | |
12 | |
13 | |
14 # TODO(eseidel): This should be shared with adb_gdb | |
15 def main(): | |
16 logging.basicConfig(level=logging.INFO) | |
17 parser = argparse.ArgumentParser( | |
18 description='Pull all libraries used by a pid on android into a cache.') | |
19 parser.add_argument('cache_root', type=str) | |
20 parser.add_argument('pid', type=int) | |
21 args = parser.parse_args() | |
22 | |
23 if not os.path.exists(args.cache_root): | |
24 os.makedirs(args.cache_root) | |
25 | |
26 subprocess.check_call(['adb', 'root']) | |
27 | |
28 library_regexp = re.compile(r'(?P<library_path>/system/.*\.so)') | |
abarth-chromium
2015/01/16 21:17:20
lib?
| |
29 cat_maps_cmd = ['adb', 'shell', 'cat', '/proc/%s/maps' % args.pid] | |
30 maps_lines = subprocess.check_output(cat_maps_cmd).strip().split('\n') | |
31 # adb shell doesn't return the return code from the shell? | |
32 if not maps_lines or 'No such file or directory' in maps_lines[0]: | |
33 print 'Failed to get maps for pid %s on device.' % args.pid | |
34 sys.exit(1) | |
35 | |
36 def library_from_line(line): | |
37 result = library_regexp.search(line) | |
38 if not result: | |
39 return None | |
40 return result.group('library_path') | |
41 | |
42 to_pull = sorted(set(filter(None, map(library_from_line, maps_lines)))) | |
43 for library_path in to_pull: | |
44 # Not using os.path.join since library_path is absolute. | |
45 dest_file = os.path.normpath("%s/%s" % (args.cache_root, library_path)) | |
46 dest_dir = os.path.dirname(dest_file) | |
47 if not os.path.exists(dest_dir): | |
48 os.makedirs(dest_dir) | |
49 print '%s -> %s' % (library_path, dest_file) | |
50 pull_cmd = ['adb', 'pull', library_path, dest_file] | |
51 subprocess.check_call(pull_cmd) | |
52 | |
53 | |
54 if __name__ == '__main__': | |
55 main() | |
OLD | NEW |