[PATCH] D27404: Make asan_symbolize.py py3-compatible

NAKAMURA Takumi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 03:15:12 PST 2016


chapuni created this revision.
chapuni added a reviewer: samsonov.
chapuni added a subscriber: llvm-commits.
chapuni set the repository for this revision to rL LLVM.
Herald added a subscriber: kubabrecka.

This patch is squashed from my two private commits.

  asan_symbolize.py: [Py3] Get rid of "print" statement. Use print() or write() instead.

Let me know if style issues anything.

  asan_symbolize.py: [Py3] Use text mode with universal_newlines=True for Popen.
  
  With universal_newlines, readline() stalls to fill the buffer. Therefore, let the pipe unbuffered.
  
  FIXME: Use Popen.communicate()

ATM, I didn't touch their logic. I think they may be rewritten in future.

Tested both 2.7.6 and 3.4.3 on Ubuntu. Not tested on Windows yet.


Repository:
  rL LLVM

https://reviews.llvm.org/D27404

Files:
  compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py


Index: compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py
===================================================================
--- compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py
+++ compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py
@@ -84,10 +84,12 @@
       for hint in self.dsym_hints:
         cmd.append('--dsym-hint=%s' % hint)
     if DEBUG:
-      print ' '.join(cmd)
+      print(' '.join(cmd))
     try:
       result = subprocess.Popen(cmd, stdin=subprocess.PIPE,
-                                stdout=subprocess.PIPE)
+                                stdout=subprocess.PIPE,
+                                bufsize=0,
+                                universal_newlines=True)
     except OSError:
       result = None
     return result
@@ -100,8 +102,8 @@
     try:
       symbolizer_input = '"%s" %s' % (binary, offset)
       if DEBUG:
-        print symbolizer_input
-      print >> self.pipe.stdin, symbolizer_input
+        print(symbolizer_input)
+      self.pipe.stdin.write("%s\n" % symbolizer_input)
       while True:
         function_name = self.pipe.stdout.readline().rstrip()
         if not function_name:
@@ -146,18 +148,20 @@
       cmd += ['--demangle']
     cmd += ['-e', self.binary]
     if DEBUG:
-      print ' '.join(cmd)
+      print(' '.join(cmd))
     return subprocess.Popen(cmd,
-                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+                            stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+                            bufsize=0,
+                            universal_newlines=True)
 
   def symbolize(self, addr, binary, offset):
     """Overrides Symbolizer.symbolize."""
     if self.binary != binary:
       return None
     lines = []
     try:
-      print >> self.pipe.stdin, offset
-      print >> self.pipe.stdin, self.output_terminator
+      self.pipe.stdin.write("%s\n" % offset)
+      self.pipe.stdin.write("%s\n" % self.output_terminator)
       is_first_frame = True
       while True:
         function_name = self.pipe.stdout.readline().rstrip()
@@ -214,7 +218,7 @@
 
   def open_atos(self):
     if DEBUG:
-      print 'atos -o %s -arch %s' % (self.binary, self.arch)
+      print('atos -o %s -arch %s' % (self.binary, self.arch))
     cmdline = ['atos', '-o', self.binary, '-arch', self.arch]
     self.atos = UnbufferedLineConverter(cmdline, close_stderr=True)
 
@@ -229,7 +233,7 @@
     #   foo(type1, type2) (in object.name) (filename.cc:80)
     match = re.match('^(.*) \(in (.*)\) \((.*:\d*)\)$', atos_line)
     if DEBUG:
-      print 'atos_line: ', atos_line
+      print('atos_line: ', atos_line)
     if match:
       function_name = match.group(1)
       function_name = re.sub('\(.*?\)', '', function_name)
@@ -343,7 +347,7 @@
       function_name, file_name, line_no = res
       result = ['%s in %s %s:%d' % (
           addr, function_name, file_name, line_no)]
-      print result
+      print(result)
       return result
     else:
       return None
@@ -425,7 +429,7 @@
     self.frame_no = 0
     for line in logfile:
       processed = self.process_line(line)
-      print '\n'.join(processed)
+      print('\n'.join(processed))
 
   def process_line_echo(self, line):
     return [line.rstrip()]
@@ -439,7 +443,7 @@
     if not match:
       return [self.current_line]
     if DEBUG:
-      print line
+      print(line)
     _, frameno_str, addr, binary, offset = match.groups()
     if frameno_str == '0':
       # Assume that frame #0 is the first frame of new stack trace.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27404.80241.patch
Type: text/x-patch
Size: 3514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161205/2ea7f931/attachment.bin>


More information about the llvm-commits mailing list