[PATCH] Make asan_symbolize.py not crash on Windows.

Nico Weber thakis at chromium.org
Wed Jan 28 08:46:04 PST 2015


Hi kcc, samsonov,

asan_symbolize.py isn't needed on Windows, but it's nice if asan has a unified UI on all platforms. So rather than have asan_symolize.py die on startup due to it importing modules that don't exist on Windows, let it peacefully early-exit.

While here, also fix the indent on the argument parsing code.

http://reviews.llvm.org/D7227

Files:
  lib/asan/scripts/asan_symbolize.py

Index: lib/asan/scripts/asan_symbolize.py
===================================================================
--- lib/asan/scripts/asan_symbolize.py
+++ lib/asan/scripts/asan_symbolize.py
@@ -11,11 +11,9 @@
 import bisect
 import getopt
 import os
-import pty
 import re
 import subprocess
 import sys
-import termios
 
 symbolizers = {}
 DEBUG = False
@@ -171,6 +169,8 @@
   output.  Uses pty to trick the child into providing unbuffered output.
   """
   def __init__(self, args, close_stderr=False):
+    import pty
+    import termios
     pid, fd = pty.fork()
     if pid == 0:
       # We're the child. Transfer control to command.
@@ -437,20 +437,28 @@
 
 
 if __name__ == '__main__':
-  parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
-  description='ASan symbolization script',
-  epilog='''Example of use:
-  asan_symbolize.py -c "$HOME/opt/cross/bin/arm-linux-gnueabi-" -s "$HOME/SymbolFiles" < asan.log''')
+  if sys.platform == 'win32':
+    # ASan on Windows uses dbghelp.dll to symbolize in-process, which works even
+    # in sandboxed processes.  This script isn't needed there.
+    sys.exit(0)
+
+  parser = argparse.ArgumentParser(
+      formatter_class=argparse.RawDescriptionHelpFormatter,
+      description='ASan symbolization script',
+      epilog='Example of use:\n'
+             'asan_symbolize.py -c "$HOME/opt/cross/bin/arm-linux-gnueabi-" '
+             '-s "$HOME/SymbolFiles" < asan.log')
   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',
-    help='demangle function names')
+                      help='demangle function names')
   parser.add_argument('-s', metavar='SYSROOT',
-    help='set path to sysroot for sanitized binaries')
+                      help='set path to sysroot for sanitized binaries')
   parser.add_argument('-c', metavar='CROSS_COMPILE',
-    help='set prefix for binutils')
-  parser.add_argument('-l','--logfile', default=sys.stdin, type=argparse.FileType('r'),
-    help='set log file name to parse, default is stdin')
+                      help='set prefix for binutils')
+  parser.add_argument('-l','--logfile', default=sys.stdin,
+                      type=argparse.FileType('r'),
+                      help='set log file name to parse, default is stdin')
   args = parser.parse_args()
   if args.path_to_cut:
     fix_filename_patterns = args.path_to_cut

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7227.18895.patch
Type: text/x-patch
Size: 2561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150128/3f9f5cb8/attachment.bin>


More information about the llvm-commits mailing list