[all-commits] [llvm/llvm-project] 6cde6a: [lldb] Don't overwrite quit and exit builtins in t...
Jonas Devlieghere via All-commits
all-commits at lists.llvm.org
Wed Jun 15 14:53:54 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 6cde6ac03c2c1851b1156dd334b87b38fff79f70
https://github.com/llvm/llvm-project/commit/6cde6ac03c2c1851b1156dd334b87b38fff79f70
Author: Jonas Devlieghere <jonas at devlieghere.com>
Date: 2022-06-15 (Wed, 15 Jun 2022)
Changed paths:
M lldb/source/Interpreter/embedded_interpreter.py
A lldb/test/Shell/ScriptInterpreter/Python/exit.test
Log Message:
-----------
[lldb] Don't overwrite quit and exit builtins in the Python interpreter
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. If they're
present, we exit the interpreter with the help of an exception.
The previous implementation also used globals to differentiate between
exit getting called from the interactive interpreter or from inside a
script. This patch achieves the same by using a different exception in
for the interpreter case.
rdar://84095490
Differential revision: https://reviews.llvm.org/D127895
More information about the All-commits
mailing list