[Lldb-commits] [lldb] Fix interactive use of "command script add". (PR #83350)

via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 28 17:23:04 PST 2024


https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/83350

>From 76eeb252b1f5fa71a68b439c84d13c8bcf042da7 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Wed, 28 Feb 2024 14:25:55 -0800
Subject: [PATCH 1/2] Fix interactive use of "command script add".

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.
---
 .../Python/ScriptInterpreterPython.cpp           |  2 +-
 .../commands/command/script/TestCommandScript.py | 16 ++++++++++++++++
 .../API/commands/command/script/cmd_file.lldb    |  4 ++++
 3 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 lldb/test/API/commands/command/script/cmd_file.lldb

diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index a1ad3f569ec71a..ce52f359524785 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -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;
 
diff --git a/lldb/test/API/commands/command/script/TestCommandScript.py b/lldb/test/API/commands/command/script/TestCommandScript.py
index 850552032902fd..21ebfce2f3c437 100644
--- a/lldb/test/API/commands/command/script/TestCommandScript.py
+++ b/lldb/test/API/commands/command/script/TestCommandScript.py
@@ -216,3 +216,19 @@ 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")
+        
+                        
diff --git a/lldb/test/API/commands/command/script/cmd_file.lldb b/lldb/test/API/commands/command/script/cmd_file.lldb
new file mode 100644
index 00000000000000..1589a7cfe0b8d9
--- /dev/null
+++ b/lldb/test/API/commands/command/script/cmd_file.lldb
@@ -0,0 +1,4 @@
+command script add my_cmd
+result.PutCString("My Command Result")
+result.SetStatus(lldb.eReturnStatusSuccessFinishResult)
+DONE

>From fe7964403557ea03a56458214984f12502689ab3 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Wed, 28 Feb 2024 17:22:45 -0800
Subject: [PATCH 2/2] Formatting.

---
 lldb/test/API/commands/command/script/TestCommandScript.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lldb/test/API/commands/command/script/TestCommandScript.py b/lldb/test/API/commands/command/script/TestCommandScript.py
index 21ebfce2f3c437..fdd5216a1c6cc5 100644
--- a/lldb/test/API/commands/command/script/TestCommandScript.py
+++ b/lldb/test/API/commands/command/script/TestCommandScript.py
@@ -230,5 +230,3 @@ def test_interactive(self):
         interp.HandleCommand("my_cmd", result)
         self.assertCommandReturn(result, "Running the command succeeds")
         self.assertIn("My Command Result", result.GetOutput(), "Command was correct")
-        
-                        



More information about the lldb-commits mailing list