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
28 lines
1005 B
Plaintext
28 lines
1005 B
Plaintext
# RUN: %lldb -o 'script quit' | FileCheck %s --check-prefix SILENT
|
|
# RUN: %lldb -o 'script quit()' | FileCheck %s --check-prefix SILENT
|
|
|
|
# RUN: %lldb -o 'script exit' | FileCheck %s --check-prefix SILENT
|
|
# RUN: %lldb -o 'script exit()' | FileCheck %s --check-prefix SILENT
|
|
|
|
# RUN: echo -e 'script\nquit' > %t
|
|
# RUN: cat %t | %lldb | FileCheck %s --check-prefix SILENT
|
|
|
|
# RUN: echo -e 'script\nexit' > %t
|
|
# RUN: cat %t | %lldb | FileCheck %s --check-prefix SILENT
|
|
|
|
# SILENT-NOT: Script exited with code
|
|
|
|
# RUN: %lldb -o 'script quit(100+23)' | FileCheck %s --check-prefix VERBOSE
|
|
# RUN: %lldb -o 'script exit(100+23)' | FileCheck %s --check-prefix VERBOSE
|
|
|
|
# RUN: echo -e 'script\nexit(100+23)' > %t
|
|
# RUN: cat %t | %lldb | FileCheck %s --check-prefix VERBOSE
|
|
|
|
# RUN: echo -e 'script\nquit(100+23)' > %t
|
|
# RUN: cat %t | %lldb | FileCheck %s --check-prefix VERBOSE
|
|
|
|
# VERBOSE: Script exited with code 123
|
|
|
|
# RUN: %lldb -o 'script print(locals())' | FileCheck %s --check-prefix LOCALS
|
|
# LOCALS: __builtins__
|