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 logging |
| 8 import os |
| 9 import sys |
| 10 import subprocess |
| 11 import shutil |
| 12 |
| 13 DEVNULL = open(os.devnull, 'w') |
| 14 |
| 15 def build_id_for_file(path): |
| 16 # example output: |
| 17 # 0+0x85e00 0ed038fdb09b296634d98e25f1f598bc4aa8fca8@0x178 png_viewer.mojo - |
| 18 try: |
| 19 eu_unstrip_cmd = ['eu-unstrip', '-n', '-e', path] |
| 20 output = subprocess.check_output(eu_unstrip_cmd, stderr=DEVNULL) |
| 21 return output.split(' ')[1].split('@')[0] |
| 22 except subprocess.CalledProcessError, e: |
| 23 return None |
| 24 |
| 25 |
| 26 # TODO(eseidel): This belongs as part of of the build system! |
| 27 def main(): |
| 28 logging.basicConfig(level=logging.INFO) |
| 29 parser = argparse.ArgumentParser( |
| 30 description='Populates a .build-id lookup tree for gdb') |
| 31 parser.add_argument('build_dir', type=str) |
| 32 args = parser.parse_args() |
| 33 |
| 34 build_dir = os.path.realpath(args.build_dir) |
| 35 if not os.path.isdir(build_dir): |
| 36 logging.fatal('build_dir: %s is not a directory' % args.build_dir) |
| 37 sys.exit(1) |
| 38 |
| 39 build_id_dir = os.path.join(build_dir, '.build-id') |
| 40 if os.path.exists(build_id_dir): |
| 41 shutil.rmtree(build_id_dir) |
| 42 |
| 43 for name in os.listdir(build_dir): |
| 44 path = os.path.join(build_dir, name) |
| 45 _, ext = os.path.splitext(name) |
| 46 # Don't try to link both .mojo and .so as they have the same build-id. |
| 47 if ext not in ('', '.so'): |
| 48 continue |
| 49 build_id = build_id_for_file(path) |
| 50 if not build_id: |
| 51 continue |
| 52 # Expected location for binary with for build-id adbcdef123456 is: |
| 53 # $BUILD/.build_id/ab/cdef123456.debug: |
| 54 # https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html |
| 55 build_id_path = os.path.join(build_id_dir, |
| 56 build_id[:2], '%s.debug' % build_id[2:]) |
| 57 print build_id, build_id_path |
| 58 print "%s -> %s" % (build_id_path, path) |
| 59 shard_dir = os.path.dirname(build_id_path) |
| 60 if not os.path.exists(shard_dir): |
| 61 os.makedirs(shard_dir) |
| 62 os.symlink(path, build_id_path) |
| 63 |
| 64 |
| 65 if __name__ == '__main__': |
| 66 main() |
OLD | NEW |