Skip to content

Fix interactive use of "command script add". #83350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ bool ScriptInterpreterPythonImpl::GenerateScriptAliasFunction(
sstr.Printf("def %s (debugger, args, exe_ctx, result, internal_dict):",
auto_generated_function_name.c_str());

if (!GenerateFunction(sstr.GetData(), user_input, /*is_callback=*/true)
if (!GenerateFunction(sstr.GetData(), user_input, /*is_callback=*/false)
.Success())
return false;

Expand Down
14 changes: 14 additions & 0 deletions lldb/test/API/commands/command/script/TestCommandScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,17 @@ def test_persistence(self):
# The result object will be replaced by an empty result object (in the
# "Started" state).
self.expect("script str(persistence.result_copy)", substrs=["Started"])

def test_interactive(self):
"""
Test that we can add multiple lines interactively.
"""
interp = self.dbg.GetCommandInterpreter()
cmd_file = self.getSourcePath("cmd_file.lldb")
result = lldb.SBCommandReturnObject()
interp.HandleCommand(f"command source {cmd_file}", result)
self.assertCommandReturn(result, "Sourcing the command should cause no errors.")
self.assertTrue(interp.UserCommandExists("my_cmd"), "Command defined.")
interp.HandleCommand("my_cmd", result)
self.assertCommandReturn(result, "Running the command succeeds")
self.assertIn("My Command Result", result.GetOutput(), "Command was correct")
4 changes: 4 additions & 0 deletions lldb/test/API/commands/command/script/cmd_file.lldb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
command script add my_cmd
result.PutCString("My Command Result")
result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
DONE