Skip to content

Commit

Permalink
[libfuzzer] a utility to zip all source files referenced by a binary
Browse files Browse the repository at this point in the history
Will be used by libfuzzer bots to send sources to coverage tool.

BUG=539572

Review-Url: https://codereview.chromium.org/2026943002
Cr-Commit-Position: refs/heads/master@{#397301}
  • Loading branch information
aizatsky-chromium authored and Commit bot committed Jun 2, 2016
1 parent 332e203 commit d892de0
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions testing/libfuzzer/zip_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/python2
#
# Copyright 2016 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.

"""Archive all source files that are references in binary debug info.
Invoked by libfuzzer buildbots. Executes llvm-dwarfdump to parse debug info.
"""

from __future__ import print_function

import argparse
import os
import re
import subprocess
import zipfile

compile_unit_re = re.compile('.*DW_TAG_compile_unit.*')
at_name_re = re.compile('.*DW_AT_name.*debug_str\[.*\] = "(.*)".*')


def main():
parser = argparse.ArgumentParser(description="Zip binary sources.")
parser.add_argument('--binary', required=True,
help='binary file to read')
parser.add_argument('--workdir', required=True,
help='working directory to use to resolve relative paths')
parser.add_argument('--output', required=True,
help='output zip file name')
parser.add_argument('--llvm-dwarfdump', required=False,
default='llvm-dwarfdump', help='path to llvm-dwarfdump utility')
args = parser.parse_args()

# Dump .debug_info section.
out = subprocess.check_output(
[args.llvm_dwarfdump, '-debug-dump=info', args.binary])

looking_for_unit = True
compile_units = set()

# Look for DW_AT_name within DW_TAG_compile_unit
for line in out.splitlines():
if looking_for_unit and compile_unit_re.match(line):
looking_for_unit = False
elif not looking_for_unit:
match = at_name_re.match(line)
if match:
compile_units.add(match.group(1))
looking_for_unit = True

# Zip sources.
with zipfile.ZipFile(args.output, 'w') as z:
for compile_unit in sorted(compile_units):
src_file = os.path.abspath(os.path.join(args.workdir, compile_unit))
print(src_file)
z.write(src_file, compile_unit)


if __name__ == '__main__':
main()

0 comments on commit d892de0

Please sign in to comment.