aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/Shell/ScriptInterpreter/Python
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2022-06-15 14:47:41 -0700
committerJonas Devlieghere <jonas@devlieghere.com>2022-06-15 14:53:40 -0700
commit6cde6ac03c2c1851b1156dd334b87b38fff79f70 (patch)
treebd2d9d25e3422c8dcc87888ddd29912143c74f42 /lldb/test/Shell/ScriptInterpreter/Python
parentf4ad2039307df26fb8b217ee61391f00a85ea620 (diff)
downloadllvm-6cde6ac03c2c1851b1156dd334b87b38fff79f70.zip
llvm-6cde6ac03c2c1851b1156dd334b87b38fff79f70.tar.gz
llvm-6cde6ac03c2c1851b1156dd334b87b38fff79f70.tar.bz2
[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
Diffstat (limited to 'lldb/test/Shell/ScriptInterpreter/Python')
-rw-r--r--lldb/test/Shell/ScriptInterpreter/Python/exit.test27
1 files changed, 27 insertions, 0 deletions
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/exit.test b/lldb/test/Shell/ScriptInterpreter/Python/exit.test
new file mode 100644
index 0000000..9895dc1
--- /dev/null
+++ b/lldb/test/Shell/ScriptInterpreter/Python/exit.test
@@ -0,0 +1,27 @@
+# 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__