Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix build_id logic for fuchsia symbols #16397

Merged
merged 10 commits into from
Feb 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions tools/fuchsia/copy_debug_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import argparse
import errno
import json
import os
import re
Expand All @@ -26,10 +27,16 @@ def Touch(fname):


def GetBuildIdParts(exec_path, read_elf):
file_out = subprocess.check_output(
[read_elf, '--hex-dump=.note.gnu.build-id', exec_path])
second_line = file_out.splitlines()[-1].split()
build_id = second_line[1] + second_line[2]
sha1_pattern = re.compile(r'[0-9a-fA-F\-]+')
file_out = subprocess.check_output([read_elf, '-n', exec_path])
build_id_line = file_out.splitlines()[-1].split()
if (build_id_line[0] != 'Build' or
build_id_line[1] != 'ID:' or not
sha1_pattern.match(build_id_line[-1]) or not
len(build_id_line[-1]) > 2):
raise Exception('Expected the last line of llvm-readelf to match "Build ID <Hex String>" Got: %s' % file_out)

build_id = build_id_line[-1]
return {
'build_id': build_id,
'prefix_dir': build_id[:2],
Expand Down Expand Up @@ -86,19 +93,15 @@ def main():
parts = GetBuildIdParts(args.exec_path, args.read_elf)
dbg_prefix_base = os.path.join(args.dest, parts['prefix_dir'])

success = False
for _ in range(3):
try:
if not os.path.exists(dbg_prefix_base):
os.makedirs(dbg_prefix_base)
success = True
break
except OSError as error:
print 'Failed to create dir %s, error: %s. sleeping...' % (
dbg_prefix_base, error)
time.sleep(3)

if not success:
# Multiple processes may be trying to create the same directory.
# TODO(dnfield): use exist_ok when we upgrade to python 3, rather than try
try:
os.makedirs(dbg_prefix_base)
except OSError as e:
if e.errno != errno.EEXIST:
raise

if not os.path.exists(dbg_prefix_base):
print 'Unable to create directory: %s.' % dbg_prefix_base
return 1

Expand Down