<div dir="ltr">ping<br><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 5, 2016 at 8:15 PM NAKAMURA Takumi via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">chapuni created this revision.<br class="gmail_msg">
chapuni added a reviewer: samsonov.<br class="gmail_msg">
chapuni added a subscriber: llvm-commits.<br class="gmail_msg">
chapuni set the repository for this revision to rL LLVM.<br class="gmail_msg">
Herald added a subscriber: kubabrecka.<br class="gmail_msg">
<br class="gmail_msg">
This patch is squashed from my two private commits.<br class="gmail_msg">
<br class="gmail_msg">
asan_symbolize.py: [Py3] Get rid of "print" statement. Use print() or write() instead.<br class="gmail_msg">
<br class="gmail_msg">
Let me know if style issues anything.<br class="gmail_msg">
<br class="gmail_msg">
asan_symbolize.py: [Py3] Use text mode with universal_newlines=True for Popen.<br class="gmail_msg">
<br class="gmail_msg">
With universal_newlines, readline() stalls to fill the buffer. Therefore, let the pipe unbuffered.<br class="gmail_msg">
<br class="gmail_msg">
FIXME: Use Popen.communicate()<br class="gmail_msg">
<br class="gmail_msg">
ATM, I didn't touch their logic. I think they may be rewritten in future.<br class="gmail_msg">
<br class="gmail_msg">
Tested both 2.7.6 and 3.4.3 on Ubuntu. Not tested on Windows yet.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Repository:<br class="gmail_msg">
rL LLVM<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://reviews.llvm.org/D27404" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D27404</a><br class="gmail_msg">
<br class="gmail_msg">
Files:<br class="gmail_msg">
compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
Index: compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py<br class="gmail_msg">
===================================================================<br class="gmail_msg">
--- compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py<br class="gmail_msg">
+++ compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py<br class="gmail_msg">
@@ -84,10 +84,12 @@<br class="gmail_msg">
for hint in self.dsym_hints:<br class="gmail_msg">
cmd.append('--dsym-hint=%s' % hint)<br class="gmail_msg">
if DEBUG:<br class="gmail_msg">
- print ' '.join(cmd)<br class="gmail_msg">
+ print(' '.join(cmd))<br class="gmail_msg">
try:<br class="gmail_msg">
result = subprocess.Popen(cmd, stdin=subprocess.PIPE,<br class="gmail_msg">
- stdout=subprocess.PIPE)<br class="gmail_msg">
+ stdout=subprocess.PIPE,<br class="gmail_msg">
+ bufsize=0,<br class="gmail_msg">
+ universal_newlines=True)<br class="gmail_msg">
except OSError:<br class="gmail_msg">
result = None<br class="gmail_msg">
return result<br class="gmail_msg">
@@ -100,8 +102,8 @@<br class="gmail_msg">
try:<br class="gmail_msg">
symbolizer_input = '"%s" %s' % (binary, offset)<br class="gmail_msg">
if DEBUG:<br class="gmail_msg">
- print symbolizer_input<br class="gmail_msg">
- print >> self.pipe.stdin, symbolizer_input<br class="gmail_msg">
+ print(symbolizer_input)<br class="gmail_msg">
+ self.pipe.stdin.write("%s\n" % symbolizer_input)<br class="gmail_msg">
while True:<br class="gmail_msg">
function_name = self.pipe.stdout.readline().rstrip()<br class="gmail_msg">
if not function_name:<br class="gmail_msg">
@@ -146,18 +148,20 @@<br class="gmail_msg">
cmd += ['--demangle']<br class="gmail_msg">
cmd += ['-e', self.binary]<br class="gmail_msg">
if DEBUG:<br class="gmail_msg">
- print ' '.join(cmd)<br class="gmail_msg">
+ print(' '.join(cmd))<br class="gmail_msg">
return subprocess.Popen(cmd,<br class="gmail_msg">
- stdin=subprocess.PIPE, stdout=subprocess.PIPE)<br class="gmail_msg">
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,<br class="gmail_msg">
+ bufsize=0,<br class="gmail_msg">
+ universal_newlines=True)<br class="gmail_msg">
<br class="gmail_msg">
def symbolize(self, addr, binary, offset):<br class="gmail_msg">
"""Overrides Symbolizer.symbolize."""<br class="gmail_msg">
if self.binary != binary:<br class="gmail_msg">
return None<br class="gmail_msg">
lines = []<br class="gmail_msg">
try:<br class="gmail_msg">
- print >> self.pipe.stdin, offset<br class="gmail_msg">
- print >> self.pipe.stdin, self.output_terminator<br class="gmail_msg">
+ self.pipe.stdin.write("%s\n" % offset)<br class="gmail_msg">
+ self.pipe.stdin.write("%s\n" % self.output_terminator)<br class="gmail_msg">
is_first_frame = True<br class="gmail_msg">
while True:<br class="gmail_msg">
function_name = self.pipe.stdout.readline().rstrip()<br class="gmail_msg">
@@ -214,7 +218,7 @@<br class="gmail_msg">
<br class="gmail_msg">
def open_atos(self):<br class="gmail_msg">
if DEBUG:<br class="gmail_msg">
- print 'atos -o %s -arch %s' % (self.binary, self.arch)<br class="gmail_msg">
+ print('atos -o %s -arch %s' % (self.binary, self.arch))<br class="gmail_msg">
cmdline = ['atos', '-o', self.binary, '-arch', self.arch]<br class="gmail_msg">
self.atos = UnbufferedLineConverter(cmdline, close_stderr=True)<br class="gmail_msg">
<br class="gmail_msg">
@@ -229,7 +233,7 @@<br class="gmail_msg">
# foo(type1, type2) (in <a href="http://object.name" rel="noreferrer" class="gmail_msg" target="_blank">object.name</a>) (filename.cc:80)<br class="gmail_msg">
match = re.match('^(.*) \(in (.*)\) \((.*:\d*)\)$', atos_line)<br class="gmail_msg">
if DEBUG:<br class="gmail_msg">
- print 'atos_line: ', atos_line<br class="gmail_msg">
+ print('atos_line: ', atos_line)<br class="gmail_msg">
if match:<br class="gmail_msg">
function_name = match.group(1)<br class="gmail_msg">
function_name = re.sub('\(.*?\)', '', function_name)<br class="gmail_msg">
@@ -343,7 +347,7 @@<br class="gmail_msg">
function_name, file_name, line_no = res<br class="gmail_msg">
result = ['%s in %s %s:%d' % (<br class="gmail_msg">
addr, function_name, file_name, line_no)]<br class="gmail_msg">
- print result<br class="gmail_msg">
+ print(result)<br class="gmail_msg">
return result<br class="gmail_msg">
else:<br class="gmail_msg">
return None<br class="gmail_msg">
@@ -425,7 +429,7 @@<br class="gmail_msg">
self.frame_no = 0<br class="gmail_msg">
for line in logfile:<br class="gmail_msg">
processed = self.process_line(line)<br class="gmail_msg">
- print '\n'.join(processed)<br class="gmail_msg">
+ print('\n'.join(processed))<br class="gmail_msg">
<br class="gmail_msg">
def process_line_echo(self, line):<br class="gmail_msg">
return [line.rstrip()]<br class="gmail_msg">
@@ -439,7 +443,7 @@<br class="gmail_msg">
if not match:<br class="gmail_msg">
return [self.current_line]<br class="gmail_msg">
if DEBUG:<br class="gmail_msg">
- print line<br class="gmail_msg">
+ print(line)<br class="gmail_msg">
_, frameno_str, addr, binary, offset = match.groups()<br class="gmail_msg">
if frameno_str == '0':<br class="gmail_msg">
# Assume that frame #0 is the first frame of new stack trace.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>