Commit b0306a48 authored by thakis's avatar thakis Committed by Commit bot

Roll asan_symbolize.py to upstream r227327.

r227327 Fix indents on argument parsing code. No behavior change.
r227326 Make asan_symbolize.py not crash on Windows.

BUG=451741
TBR=glider@chromium.org

Review URL: https://codereview.chromium.org/884043004

Cr-Commit-Position: refs/heads/master@{#313554}
parent 57d8cee3
Name: asan_symbolize.py Name: asan_symbolize.py
License: University of Illinois Open Source License. License: University of Illinois Open Source License.
Version: 224710 Version: r227327
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py?view=co&content-type=text%2Fplain URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py?view=co&content-type=text%2Fplain
Security Critical: no Security Critical: no
......
...@@ -11,11 +11,9 @@ import argparse ...@@ -11,11 +11,9 @@ import argparse
import bisect import bisect
import getopt import getopt
import os import os
import pty
import re import re
import subprocess import subprocess
import sys import sys
import termios
symbolizers = {} symbolizers = {}
DEBUG = False DEBUG = False
...@@ -171,6 +169,9 @@ class UnbufferedLineConverter(object): ...@@ -171,6 +169,9 @@ class UnbufferedLineConverter(object):
output. Uses pty to trick the child into providing unbuffered output. output. Uses pty to trick the child into providing unbuffered output.
""" """
def __init__(self, args, close_stderr=False): def __init__(self, args, close_stderr=False):
# Local imports so that the script can start on Windows.
import pty
import termios
pid, fd = pty.fork() pid, fd = pty.fork()
if pid == 0: if pid == 0:
# We're the child. Transfer control to command. # We're the child. Transfer control to command.
...@@ -341,6 +342,11 @@ class BreakpadSymbolizer(Symbolizer): ...@@ -341,6 +342,11 @@ class BreakpadSymbolizer(Symbolizer):
class SymbolizationLoop(object): class SymbolizationLoop(object):
def __init__(self, binary_name_filter=None, dsym_hint_producer=None): def __init__(self, binary_name_filter=None, dsym_hint_producer=None):
if sys.platform == 'win32':
# ASan on Windows uses dbghelp.dll to symbolize in-process, which works
# even in sandboxed processes. Nothing needs to be done here.
self.process_line = self.process_line_echo
else:
# Used by clients who may want to supply a different binary name. # Used by clients who may want to supply a different binary name.
# E.g. in Chrome several binaries may share a single .dSYM. # E.g. in Chrome several binaries may share a single .dSYM.
self.binary_name_filter = binary_name_filter self.binary_name_filter = binary_name_filter
...@@ -352,6 +358,7 @@ class SymbolizationLoop(object): ...@@ -352,6 +358,7 @@ class SymbolizationLoop(object):
self.last_llvm_symbolizer = None self.last_llvm_symbolizer = None
self.dsym_hints = set([]) self.dsym_hints = set([])
self.frame_no = 0 self.frame_no = 0
self.process_line = self.process_line_posix
def symbolize_address(self, addr, binary, offset): def symbolize_address(self, addr, binary, offset):
# On non-Darwin (i.e. on platforms without .dSYM debug info) always use # On non-Darwin (i.e. on platforms without .dSYM debug info) always use
...@@ -405,14 +412,14 @@ class SymbolizationLoop(object): ...@@ -405,14 +412,14 @@ class SymbolizationLoop(object):
def process_logfile(self): def process_logfile(self):
self.frame_no = 0 self.frame_no = 0
while True: for line in logfile:
line = logfile.readline()
if not line:
break
processed = self.process_line(line) processed = self.process_line(line)
print '\n'.join(processed) print '\n'.join(processed)
def process_line(self, line): def process_line_echo(self, line):
return [line.rstrip()]
def process_line_posix(self, line):
self.current_line = line.rstrip() self.current_line = line.rstrip()
#0 0x7f6e35cf2e45 (/blah/foo.so+0x11fe45) #0 0x7f6e35cf2e45 (/blah/foo.so+0x11fe45)
stack_trace_line_format = ( stack_trace_line_format = (
...@@ -437,10 +444,12 @@ class SymbolizationLoop(object): ...@@ -437,10 +444,12 @@ class SymbolizationLoop(object):
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description='ASan symbolization script', description='ASan symbolization script',
epilog='''Example of use: epilog='Example of use:\n'
asan_symbolize.py -c "$HOME/opt/cross/bin/arm-linux-gnueabi-" -s "$HOME/SymbolFiles" < asan.log''') 'asan_symbolize.py -c "$HOME/opt/cross/bin/arm-linux-gnueabi-" '
'-s "$HOME/SymbolFiles" < asan.log')
parser.add_argument('path_to_cut', nargs='*', parser.add_argument('path_to_cut', nargs='*',
help='pattern to be cut from the result file path ') help='pattern to be cut from the result file path ')
parser.add_argument('-d','--demangle', action='store_true', parser.add_argument('-d','--demangle', action='store_true',
...@@ -449,7 +458,8 @@ if __name__ == '__main__': ...@@ -449,7 +458,8 @@ if __name__ == '__main__':
help='set path to sysroot for sanitized binaries') help='set path to sysroot for sanitized binaries')
parser.add_argument('-c', metavar='CROSS_COMPILE', parser.add_argument('-c', metavar='CROSS_COMPILE',
help='set prefix for binutils') help='set prefix for binutils')
parser.add_argument('-l','--logfile', default=sys.stdin, type=argparse.FileType('r'), parser.add_argument('-l','--logfile', default=sys.stdin,
type=argparse.FileType('r'),
help='set log file name to parse, default is stdin') help='set log file name to parse, default is stdin')
args = parser.parse_args() args = parser.parse_args()
if args.path_to_cut: if args.path_to_cut:
......
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