This is an archive of the discontinued LLVM Phabricator instance.

[lldb/Python] Fix the infinitely looping prompt bug
ClosedPublic

Authored by JDevlieghere on Jun 15 2020, 5:16 PM.

Details

Summary

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

Diff Detail

Event Timeline

JDevlieghere created this revision.Jun 15 2020, 5:16 PM
teemperor accepted this revision.Jun 16 2020, 10:29 AM

LGTM, but some documentation would be nice.

lldb/source/Interpreter/embedded_interpreter.py
77

# Empty line from readline indicates EOF

lldb/test/Shell/ScriptInterpreter/Python/eof.test
3

I think this should have a comment that ">>>" is the python interpreter prompt and why we check for it.

This revision is now accepted and ready to land.Jun 16 2020, 10:29 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2020, 11:33 AM