[Lldb-commits] [PATCH] D127586: [lldb][Interpreter] Add newline terminal to one-line script calls

Dave Lee via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 15 22:23:11 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe9349ef9e6d8: Fix `script -lpython` to handle control flow in one-line commands. (authored by kastiglione).

Changed prior to commit:
  https://reviews.llvm.org/D127586?vs=436191&id=437446#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127586/new/

https://reviews.llvm.org/D127586

Files:
  lldb/source/Interpreter/embedded_interpreter.py
  lldb/test/Shell/ScriptInterpreter/Python/python.test


Index: lldb/test/Shell/ScriptInterpreter/Python/python.test
===================================================================
--- lldb/test/Shell/ScriptInterpreter/Python/python.test
+++ 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
Index: lldb/source/Interpreter/embedded_interpreter.py
===================================================================
--- lldb/source/Interpreter/embedded_interpreter.py
+++ lldb/source/Interpreter/embedded_interpreter.py
@@ -116,6 +116,10 @@
         input_string = strip_and_check_exit(input_string)
         repl = code.InteractiveConsole(local_dict)
         if input_string:
+            # A newline is appended to support one-line statements containing
+            # control flow. For example "if True: print(1)" silently does
+            # nothing, but works with a newline: "if True: print(1)\n".
+            input_string += "\n"
             repl.runsource(input_string)
         elif g_run_one_line_str:
             repl.runsource(g_run_one_line_str)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127586.437446.patch
Type: text/x-patch
Size: 1565 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220616/083a22f9/attachment-0001.bin>


More information about the lldb-commits mailing list