Executing commands below will get you bombarded by a wall of Python
command prompts (>>> ).
$ echo 'foo' | ./bin/lldb -o script
$ cat /tmp/script
script
print("foo")
$ lldb --source /tmp/script
The issue is that our custom input reader doesn't handle EOF. According
to the Python documentation, file.readline always includes a trailing
newline character unless the file ends with an incomplete line. An empty
string signals EOF. This patch raises an EOFError when that happens.
[1] https://docs.python.org/2/library/stdtypes.html#file.readline
Differential revision: https://reviews.llvm.org/D81898
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):
--- /dev/null
+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: >>>