Skip to content

Commit 5784bf8

Browse files
authored
Fix interactive use of "command script add". (#83350)
There was a think-o in a previous commit that made us only able to define 1 line commands when using command script add interactively. There was also no test for this feature, so I fixed the think-o and added a test.
1 parent 0fe4b9d commit 5784bf8

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ bool ScriptInterpreterPythonImpl::GenerateScriptAliasFunction(
14171417
sstr.Printf("def %s (debugger, args, exe_ctx, result, internal_dict):",
14181418
auto_generated_function_name.c_str());
14191419

1420-
if (!GenerateFunction(sstr.GetData(), user_input, /*is_callback=*/true)
1420+
if (!GenerateFunction(sstr.GetData(), user_input, /*is_callback=*/false)
14211421
.Success())
14221422
return false;
14231423

lldb/test/API/commands/command/script/TestCommandScript.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,17 @@ def test_persistence(self):
216216
# The result object will be replaced by an empty result object (in the
217217
# "Started" state).
218218
self.expect("script str(persistence.result_copy)", substrs=["Started"])
219+
220+
def test_interactive(self):
221+
"""
222+
Test that we can add multiple lines interactively.
223+
"""
224+
interp = self.dbg.GetCommandInterpreter()
225+
cmd_file = self.getSourcePath("cmd_file.lldb")
226+
result = lldb.SBCommandReturnObject()
227+
interp.HandleCommand(f"command source {cmd_file}", result)
228+
self.assertCommandReturn(result, "Sourcing the command should cause no errors.")
229+
self.assertTrue(interp.UserCommandExists("my_cmd"), "Command defined.")
230+
interp.HandleCommand("my_cmd", result)
231+
self.assertCommandReturn(result, "Running the command succeeds")
232+
self.assertIn("My Command Result", result.GetOutput(), "Command was correct")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
command script add my_cmd
2+
result.PutCString("My Command Result")
3+
result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
4+
DONE

0 commit comments

Comments
 (0)