diff --git a/lldb/source/Interpreter/embedded_interpreter.py b/lldb/source/Interpreter/embedded_interpreter.py --- a/lldb/source/Interpreter/embedded_interpreter.py +++ b/lldb/source/Interpreter/embedded_interpreter.py @@ -73,7 +73,12 @@ def readfunc_stdio(prompt): sys.stdout.write(prompt) sys.stdout.flush() - return sys.stdin.readline().rstrip() + line = sys.stdin.readline() + # Readline always includes a trailing newline character unless the file + # ends with an incomplete line. An empty line indicates EOF. + if not line: + raise EOFError + return line.rstrip() def run_python_interpreter(local_dict): diff --git a/lldb/test/Shell/ScriptInterpreter/Python/eof.test b/lldb/test/Shell/ScriptInterpreter/Python/eof.test new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/ScriptInterpreter/Python/eof.test @@ -0,0 +1,6 @@ +RUN: echo 'foo' | %lldb -o script | FileCheck %s + +# Check that the python interpreter detects the OF and the prompt is printed +# exactly once. +CHECK: >>> +CHECK-NOT: >>>