Commit 105d8abd authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

Fix and tidy unstripped binary path resolution logic.

The code as checked in breaks on Swarming because it attempts to read
the stripped file, which is omitted on isolated builds.

This CL does the ELF check on the unstripped file instead, and
consolidates the logic within a function.

Bug: 792521
Change-Id: I0042bb9b234f34ebc65c6b3ab10c075771b777ef
Reviewed-on: https://chromium-review.googlesource.com/899677
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarScott Graham <scottmg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534112}
parent 7a07f735
...@@ -20,17 +20,32 @@ _BACKTRACE_ENTRY_RE = re.compile( ...@@ -20,17 +20,32 @@ _BACKTRACE_ENTRY_RE = re.compile(
def _GetUnstrippedPath(path): def _GetUnstrippedPath(path):
"""Computes the path to the unstripped binary stored at |path|.""" """If there is a binary located at |path|, returns a path to its unstripped
source.
Returns None if |path| isn't a binary or doesn't exist in the lib.unstripped
or exe.unstripped directories."""
if path.endswith('.so'): if path.endswith('.so'):
return os.path.normpath( maybe_unstripped_path = os.path.normpath(
os.path.join(path, os.path.pardir, 'lib.unstripped', os.path.join(path, os.path.pardir, 'lib.unstripped',
os.path.basename(path))) os.path.basename(path)))
else: else:
return os.path.normpath( maybe_unstripped_path = os.path.normpath(
os.path.join(path, os.path.pardir, 'exe.unstripped', os.path.join(path, os.path.pardir, 'exe.unstripped',
os.path.basename(path))) os.path.basename(path)))
if not os.path.exists(maybe_unstripped_path):
return None
with open(maybe_unstripped_path, 'rb') as f:
file_tag = f.read(4)
if file_tag != '\x7fELF':
logging.warn('Expected an ELF binary: ' + maybe_unstripped_path)
return None
return maybe_unstripped_path
def FilterStream(stream, manifest_path, output_dir): def FilterStream(stream, manifest_path, output_dir):
"""Looks for backtrace lines from an iterable |stream| and symbolizes them. """Looks for backtrace lines from an iterable |stream| and symbolizes them.
...@@ -48,23 +63,13 @@ class _SymbolizerFilter(object): ...@@ -48,23 +63,13 @@ class _SymbolizerFilter(object):
# Compute remote/local path mappings using the manifest data. # Compute remote/local path mappings using the manifest data.
for next_line in open(manifest_path): for next_line in open(manifest_path):
split = next_line.strip().split('=') target, source = next_line.strip().split('=')
stripped_binary_path = _GetUnstrippedPath(os.path.join(output_dir, source))
# Check that the file exists in the unstripped directories and if not stripped_binary_path:
# that it is an executable binary (indicated by the existence of
# an ELF header.)
target = split[0]
source = os.path.join(output_dir, split[1])
with open(source, 'rb') as f:
file_tag = f.read(4)
if file_tag != '\x7fELF':
continue continue
source = _GetUnstrippedPath(source)
if not os.path.exists(source):
raise Exception('Unstripped binary not found at %s' % source)
self._symbols_mapping[os.path.basename(target)] = source self._symbols_mapping[os.path.basename(target)] = stripped_binary_path
self._symbols_mapping[target] = source self._symbols_mapping[target] = stripped_binary_path
logging.debug('Symbols: %s -> %s' % (source, target)) logging.debug('Symbols: %s -> %s' % (source, target))
def _SymbolizeEntries(self, entries): def _SymbolizeEntries(self, entries):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment