kastiglione created this revision. kastiglione added reviewers: mib, JDevlieghere, jingham. Herald added a project: All. kastiglione requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Fix `script -lpython` to handle control flow in one-line commands. The fix is to append a newline to one-line of 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 Repository: rG LLVM Github Monorepo 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 @@ -129,6 +129,7 @@ try: repl = code.InteractiveConsole(local_dict) if input_string: + 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 @@ -129,6 +129,7 @@ try: repl = code.InteractiveConsole(local_dict) if input_string: + 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