Index: sky/tools/update_build_id_tree.py |
diff --git a/sky/tools/update_build_id_tree.py b/sky/tools/update_build_id_tree.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..20ec3078f74006faec741d6c063c39d90599f1c2 |
--- /dev/null |
+++ b/sky/tools/update_build_id_tree.py |
@@ -0,0 +1,66 @@ |
+#!/usr/bin/env python |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import argparse |
+import logging |
+import os |
+import sys |
+import subprocess |
+import shutil |
+ |
+DEVNULL = open(os.devnull, 'w') |
+ |
+def build_id_for_file(path): |
+ # example output: |
+ # 0+0x85e00 0ed038fdb09b296634d98e25f1f598bc4aa8fca8@0x178 png_viewer.mojo - |
+ try: |
+ eu_unstrip_cmd = ['eu-unstrip', '-n', '-e', path] |
+ output = subprocess.check_output(eu_unstrip_cmd, stderr=DEVNULL) |
+ return output.split(' ')[1].split('@')[0] |
+ except subprocess.CalledProcessError, e: |
+ return None |
+ |
+ |
+# TODO(eseidel): This belongs as part of of the build system! |
+def main(): |
+ logging.basicConfig(level=logging.INFO) |
+ parser = argparse.ArgumentParser( |
+ description='Populates a .build-id lookup tree for gdb') |
+ parser.add_argument('build_dir', type=str) |
+ args = parser.parse_args() |
+ |
+ build_dir = os.path.realpath(args.build_dir) |
+ if not os.path.isdir(build_dir): |
+ logging.fatal('build_dir: %s is not a directory' % args.build_dir) |
+ sys.exit(1) |
+ |
+ build_id_dir = os.path.join(build_dir, '.build-id') |
+ if os.path.exists(build_id_dir): |
+ shutil.rmtree(build_id_dir) |
+ |
+ for name in os.listdir(build_dir): |
+ path = os.path.join(build_dir, name) |
+ _, ext = os.path.splitext(name) |
+ # Don't try to link both .mojo and .so as they have the same build-id. |
+ if ext not in ('', '.so'): |
+ continue |
+ build_id = build_id_for_file(path) |
+ if not build_id: |
+ continue |
+ # Expected location for binary with for build-id adbcdef123456 is: |
+ # $BUILD/.build_id/ab/cdef123456.debug: |
+ # https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html |
+ build_id_path = os.path.join(build_id_dir, |
+ build_id[:2], '%s.debug' % build_id[2:]) |
+ print build_id, build_id_path |
+ print "%s -> %s" % (build_id_path, path) |
+ shard_dir = os.path.dirname(build_id_path) |
+ if not os.path.exists(shard_dir): |
+ os.makedirs(shard_dir) |
+ os.symlink(path, build_id_path) |
+ |
+ |
+if __name__ == '__main__': |
+ main() |