[lldb] Don't print script output twice in HandleCommand
authorJonas Devlieghere <jonas@devlieghere.com>
Tue, 8 Jun 2021 17:46:43 +0000 (10:46 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Tue, 8 Jun 2021 20:57:39 +0000 (13:57 -0700)
commit1a216fb15a188f9ac7de6d79267b3cfb2946f792
treea39dc57512ffff4f8c92b555b1c891d116cccee0
parent0178ae734ca33265fe051c39deff6d7d530f6239
[lldb] Don't print script output twice in HandleCommand

When executing a script command in HandleCommand(s) we currently print
its output twice
You can see this issue in action when adding a breakpoint command:

(lldb) b main
Breakpoint 1: where = main.out`main + 13 at main.cpp:2:3, address = 0x0000000100003fad
(lldb) break command add 1 -o "script print(\"Hey!\")"
(lldb) r
Process 76041 launched: '/tmp/main.out' (x86_64)
Hey!
(lldb)  script print("Hey!")
Hey!
Process 76041 stopped

The issue is caused by HandleCommands using a temporary
CommandReturnObject and one of the commands (`script` in this case)
setting an immediate output stream. This causes the result to be printed
twice: once directly to the immediate output stream and once when
printing the result of HandleCommands.

This patch fixes the issue by introducing a new option to suppress
immediate output for temporary CommandReturnObjects.

Differential revision: https://reviews.llvm.org/D103349
lldb/include/lldb/Interpreter/CommandReturnObject.h
lldb/lldb/test/Shell/Breakpoint/breakpoint-command.test [new file with mode: 0644]
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Interpreter/CommandReturnObject.cpp
lldb/test/Shell/Breakpoint/breakpoint-command.test [new file with mode: 0644]
lldb/test/Shell/ScriptInterpreter/Lua/nested_sessions.test