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)
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)
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits