aboutsummaryrefslogtreecommitdiff
path: root/lldb/test/Shell/ScriptInterpreter/Python
diff options
context:
space:
mode:
authorDave Lee <davelee.com@gmail.com>2022-06-15 22:08:21 -0700
committerDave Lee <davelee.com@gmail.com>2022-06-15 22:20:48 -0700
commite9349ef9e6d83aa8900b5e534f1d15fb4d44a33c (patch)
tree80b670230970720fd3c87de45d8c47cfcd146971 /lldb/test/Shell/ScriptInterpreter/Python
parente30c493894c410825ad7467f4996aca7f613ce81 (diff)
downloadllvm-e9349ef9e6d83aa8900b5e534f1d15fb4d44a33c.zip
llvm-e9349ef9e6d83aa8900b5e534f1d15fb4d44a33c.tar.gz
llvm-e9349ef9e6d83aa8900b5e534f1d15fb4d44a33c.tar.bz2
Fix `script -lpython` to handle control flow in one-line commands.
The fix is to append a newline to the source being evaluated. Without this patch, the following commands **print no output, no errors**. ``` (lldb) script if "foo" in lldb.frame.name: print(lldb.thread) (lldb) script for f in lldb.thread: print(f.name) ``` The issue is with `code.InteractiveConsole.runsource()`. A trailing newline is needed for these expressions to be evaluated. I don't know why this is, the docs don't mention anything. From a python repl, the following samples show that a terminal newline allows statements containing flow control to fully execute. ``` >>> import code >>> repl = code.InteractiveConsole() >>> repl.runsource("if True: print(1)") True >>> repl.runsource("if True: print(1)\n") 1 False ``` Notes: From an interactive python repl, the output is not printed immediately. The user is required to enter a blank line following the first. ``` >>> if True: print(1) ... 1 ``` However, `python -c 'if True: print(1)'` works without needing a newline. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D127586
Diffstat (limited to 'lldb/test/Shell/ScriptInterpreter/Python')
-rw-r--r--lldb/test/Shell/ScriptInterpreter/Python/python.test1
1 files changed, 1 insertions, 0 deletions
diff --git a/lldb/test/Shell/ScriptInterpreter/Python/python.test b/lldb/test/Shell/ScriptInterpreter/Python/python.test
index f8f9abf..333afd9 100644
--- a/lldb/test/Shell/ScriptInterpreter/Python/python.test
+++ b/lldb/test/Shell/ScriptInterpreter/Python/python.test
@@ -5,6 +5,7 @@
# RUN: %lldb -o 'script -lpython -- print("{}".format(1000+100+10+1))' 2>&1 | FileCheck %s
# RUN: %lldb -o 'script --language python -- print("{}".format(1000+100+10+1))' 2>&1 | FileCheck %s
# RUN: %lldb -o 'script --language=python -- print("{}".format(1000+100+10+1))' 2>&1 | FileCheck %s
+# RUN: %lldb -o 'script -lpython -- if True: print("{}".format(1000+100+10+1))' 2>&1 | FileCheck %s
# CHECK: 1111
# RUN: %lldb -o 'script --language invalid -- print("{}".format(1000+100+10+1))' 2>&1 | FileCheck %s --check-prefix INVALID