Skip to content

Commit

Permalink
valgrind/asan: update asan_symbolize.py
Browse files Browse the repository at this point in the history
We need to update this for https://reviews.llvm.org/D60529

Bug: 1288169
Change-Id: I3c8f5b3f173be0ce5771e279f6a402deaafb9501
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3301851
Auto-Submit: Takuto Ikuta <tikuta@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#964541}
  • Loading branch information
Takuto Ikuta authored and Chromium LUCI CQ committed Jan 28, 2022
1 parent d18700c commit a6a7b65
Show file tree
Hide file tree
Showing 4 changed files with 683 additions and 138 deletions.
1 change: 1 addition & 0 deletions .yapfignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Third-party code.
third_party/blink/tools/blinkpy/third_party/*
third_party/blink/web_tests/external/wpt/*
tools/valgrind/asan/third_party/asan_symbolize.py

# TODO(crbug.com/1116155): Enable this for formatting by yapf.
tools/json_schema_compiler/*
86 changes: 46 additions & 40 deletions tools/valgrind/asan/asan_symbolize.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,6 @@ def find_inode_at_path(inode, path):
return ret


# Create a binary name filter that works around https://crbug.com/444835.
# When running tests on OSX swarming servers, ASan sometimes prints paths to
# files in cache (ending with SHA1 filenames) instead of paths to hardlinks to
# those files in the product dir.
# For a given |binary_path| chrome_osx_binary_name_filter() returns one of the
# hardlinks to the same inode in |product_dir_path|.
def make_chrome_osx_binary_name_filter(product_dir_path=''):
def chrome_osx_binary_name_filter(binary_path):
basename = os.path.basename(binary_path)
if is_hash_name(basename) and product_dir_path:
inode = os.stat(binary_path).st_ino
new_binary_path = find_inode_at_path(inode, product_dir_path)
if new_binary_path:
return new_binary_path
return binary_path
return chrome_osx_binary_name_filter


def make_sysroot_filter(sysroot):
"""Creates a binary name filter for a symbol tree of a remote system."""

return lambda binary_path: sysroot + binary_path


# Construct a path to the .dSYM bundle for the given binary.
# There are three possible cases for binary location in Chromium:
# 1. The binary is a standalone executable or dynamic library in the product
Expand Down Expand Up @@ -182,6 +158,11 @@ def symbolize_snippet(self, snippet):
def symbolize(self, test_run):
original_snippet = base64.b64decode(
test_run['output_snippet_base64']).decode('utf-8', 'replace')

# replace non-ascii character with '?'.
original_snippet = ''.join(i if i <= u'~' else u'?'
for i in original_snippet)

symbolized_snippet = self.symbolize_snippet(original_snippet)
if symbolized_snippet == original_snippet:
# No sanitizer reports in snippet.
Expand Down Expand Up @@ -211,6 +192,26 @@ def symbolize_snippets_in_json(filename, symbolization_loop):
json.dump(json_data, f, indent=3, sort_keys=True)


class macOSBinaryNameFilterPlugin(asan_symbolize.AsanSymbolizerPlugIn):
def __init__(self):
self.product_dir_path = ''

def filter_binary_path(self, binary_path):
# Create a binary name filter that works around https://crbug.com/444835.
# When running tests on OSX swarming servers, ASan sometimes prints paths to
# files in cache (ending with SHA1 filenames) instead of paths to hardlinks
# to those files in the product dir.
# For a given |binary_path| macOSBinaryNameFilterPlugin returns one of the
# hardlinks to the same inode in |product_dir_path|.
basename = os.path.basename(binary_path)
if is_hash_name(basename) and self.product_dir_path:
inode = os.stat(binary_path).st_ino
new_binary_path = find_inode_at_path(inode, self.product_dir_path)
if new_binary_path:
return new_binary_path
return binary_path


def main():
parser = argparse.ArgumentParser(description='Symbolize sanitizer reports.')
parser.add_argument('--test-summary-json-file',
Expand All @@ -234,22 +235,27 @@ def main():
# Most source paths for Chromium binaries start with
# /path/to/src/out/Release/../../
asan_symbolize.fix_filename_patterns.append('Release/../../')
binary_name_filter = None
if args.sysroot:
binary_name_filter = make_sysroot_filter(args.sysroot)
elif platform.uname()[0] == 'Darwin':
binary_name_filter = make_chrome_osx_binary_name_filter(
chrome_product_dir_path(args.executable_path))
loop = asan_symbolize.SymbolizationLoop(
binary_name_filter=binary_name_filter,
dsym_hint_producer=chrome_dsym_hints)

if args.test_summary_json_file:
symbolize_snippets_in_json(args.test_summary_json_file, loop)
else:
# Process stdin.
asan_symbolize.logfile = sys.stdin
loop.process_logfile()

with asan_symbolize.AsanSymbolizerPlugInProxy() as plugin_proxy:
if args.sysroot:
sysroot_filter = asan_symbolize.SysRootFilterPlugIn()
sysroot_filter.sysroot_path = args.sysroot
plugin_proxy.add_plugin(sysroot_filter)
elif platform.uname()[0] == 'Darwin':
macos_filter = macOSBinaryNameFilterPlugin()
macos_filter.product_dir_path = args.executable_path
plugin_proxy.add_plugin(macos_filter)

loop = asan_symbolize.SymbolizationLoop(
plugin_proxy=plugin_proxy, dsym_hint_producer=chrome_dsym_hints)

if args.test_summary_json_file:
symbolize_snippets_in_json(args.test_summary_json_file, loop)
else:
# Process stdin.
asan_symbolize.logfile = sys.stdin
loop.process_logfile()


if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions tools/valgrind/asan/third_party/README.chromium
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Name: asan_symbolize.py
License: University of Illinois Open Source License.
Version: r227327
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py?view=co&content-type=text%2Fplain
License: Apache-2.0 WITH LLVM-exception
Version: a81e45b8bcb8eb274ad73357e10e2cdf8a314a8c
URL: https://github.com/llvm/llvm-project/blob/a81e45b8bcb8eb274ad73357e10e2cdf8a314a8c/compiler-rt/lib/asan/scripts/asan_symbolize.py
Security Critical: no

asan_symbolize.py is a verbatim copy of asan_symbolize.py in the LLVM trunk.
Loading

0 comments on commit a6a7b65

Please sign in to comment.