build/symbols.py

51 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Installs a provided symbol file into the symbols repository at the correct
subdirectory for `minidump_stackwalk` to automatically find.
"""
if __name__ == '__main__':
import argparse
import os
import shutil
import sys
def main():
default_dst = os.path.join(
os.path.dirname(
os.path.realpath(__file__)
),
"symbols"
)
parser = argparse.ArgumentParser()
parser.add_argument('--dst', dest='dst', type=str, required=False, default=default_dst)
parser.add_argument('src', type=str)
args = parser.parse_args()
with open(args.src) as f:
header = f.readline()
field, system, arch, id, name = header.strip().split(' ')
# HACK: Splitdebug binaries are currently named "foo" and "foo.debug".
# We need to run `dump_syms` over "foo.debug" to get the most
# information. But this lists the modulename as "foo.debug" rather
# than "foo".
#
# So we hardcode the removal of this suffix so that the symbol file
# gets placed in a location that `minidump_stackwalk` can find.
if name.endswith(".debug"):
name = name[:-len(".debug")]
print(f"Installing {name}: {id}", file=sys.stderr)
dst_dir = os.path.join(args.dst, name, id)
os.makedirs(dst_dir, exist_ok=True)
dst_path = os.path.join(dst_dir, f"{name}.sym")
shutil.copyfile(args.src, dst_path)
main()