[Lldb-commits] [PATCH] D81898: [lldb/Python] Fix the infinitely looping prompt bug

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 15 17:42:10 PDT 2020


JDevlieghere created this revision.
JDevlieghere added reviewers: labath, teemperor.
JDevlieghere updated this revision to Diff 270924.
JDevlieghere added a comment.

Add test


This bug has been bothering me for a while. When you do something like the commands below, you'd get 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. Therefore, checking for the empty string before stripping it tells us if we've read EOF.

[1] https://docs.python.org/2/library/stdtypes.html#file.readline


https://reviews.llvm.org/D81898

Files:
  lldb/source/Interpreter/embedded_interpreter.py
  lldb/test/Shell/ScriptInterpreter/Python/eof.test


Index: lldb/test/Shell/ScriptInterpreter/Python/eof.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/ScriptInterpreter/Python/eof.test
@@ -0,0 +1,4 @@
+RUN: echo 'foo' | %lldb -o script | FileCheck %s
+
+CHECK: >>>
+CHECK-NOT: >>>
Index: lldb/source/Interpreter/embedded_interpreter.py
===================================================================
--- lldb/source/Interpreter/embedded_interpreter.py
+++ lldb/source/Interpreter/embedded_interpreter.py
@@ -73,7 +73,10 @@
 def readfunc_stdio(prompt):
     sys.stdout.write(prompt)
     sys.stdout.flush()
-    return sys.stdin.readline().rstrip()
+    line = sys.stdin.readline()
+    if not line:
+        raise EOFError
+    return line.rstrip()
 
 
 def run_python_interpreter(local_dict):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81898.270924.patch
Type: text/x-patch
Size: 806 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200616/46294d37/attachment.bin>


More information about the lldb-commits mailing list