[Lldb-commits] [PATCH] D127895: [lldb] Don't overwrite quit and exit builtins in the interactive python interpreter
Jonas Devlieghere via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Jun 15 12:23:43 PDT 2022
JDevlieghere created this revision.
JDevlieghere added reviewers: labath, mib.
Herald added a project: All.
JDevlieghere requested review of this revision.
The interactive interpreter is overwriting the `exit` and `quit` builtins with an instance of `LLDBQuitter` in order to make `exit` and `quit` behave like `exit()` and `quit()`. It does that by overwriting the `__repr__` function to call itself. Despite being a neat trick, it has the unintentional side effect that printing these builtins now quits the interpreter:
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> print(exit)
(lldb)
You might consider the above example slightly convoluted, but a more realistic situation is calling `locals()`:
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> locals()
(lldb)
This patch keeps the existing behavior but without overwriting the builtins. Instead, it looks for `quit` and `exit` in the input and raises an appropriate exception. The previous implementation also used globals to differentiate between exit getting called from the interactive interpreter and from scripts. This patch makes use of a custom exception in order to do the same.
rdar://84095490
https://reviews.llvm.org/D127895
Files:
lldb/source/Interpreter/embedded_interpreter.py
lldb/test/Shell/ScriptInterpreter/Python/exit.test
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127895.437292.patch
Type: text/x-patch
Size: 4800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220615/d0ac572a/attachment.bin>
More information about the lldb-commits
mailing list