One way of using llvm-symbolizer is to interactively within a process write a line from a parent process to llvm-symbolizer's stdin, and then read the output, then write the next line, read, etc. This worked as long as all the lines were good. However, this didn't work prior to this patch if any of the inputs were bad inputs, because the output is not flushed after a bad input, meaning the parent process is sat waiting for output, whilst llvm-symbolizer is sat waiting for input. This patch flushes the output after every invocation of symbolizeInput when reading from stdin. It also removes unnecessary flushing when llvm-symbolizer is not reading addresses from stdin, which should give a slight performance boost in these situations. Reviewed by: ikudrin Differential Revision: https://reviews.llvm.org/D62371 llvm-svn: 362511
25 lines
694 B
Python
25 lines
694 B
Python
from __future__ import print_function
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import threading
|
|
|
|
def kill_subprocess(process):
|
|
process.kill()
|
|
os._exit(1)
|
|
|
|
# Pass -f=none and --output-style=GNU to get only one line of output per input.
|
|
cmd = subprocess.Popen([sys.argv[1],
|
|
'--obj=' + sys.argv[2],
|
|
'-f=none',
|
|
'--output-style=GNU'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
|
watchdog = threading.Timer(20, kill_subprocess, args=[cmd])
|
|
watchdog.start()
|
|
cmd.stdin.write(b'0\n')
|
|
cmd.stdin.flush()
|
|
print(cmd.stdout.readline())
|
|
cmd.stdin.write(b'bad\n')
|
|
cmd.stdin.flush()
|
|
print(cmd.stdout.readline())
|
|
watchdog.cancel()
|