[Lldb-commits] [lldb] 7cff05a - Revert "[lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (#94518)"

Chelsea Cassanova via lldb-commits lldb-commits at lists.llvm.org
Tue Jun 11 15:29:33 PDT 2024


Author: Chelsea Cassanova
Date: 2024-06-11T15:27:10-07:00
New Revision: 7cff05ada05e87408966d56b4c1675033187ff5c

URL: https://github.com/llvm/llvm-project/commit/7cff05ada05e87408966d56b4c1675033187ff5c
DIFF: https://github.com/llvm/llvm-project/commit/7cff05ada05e87408966d56b4c1675033187ff5c.diff

LOG: Revert "[lldb][api-test] Add API test for SBCommandInterpreter::CommandOverrideCallback (#94518)"

This reverts commit 6fb6eba9304b63e86ebf039edcb9a0b32e4b39e7.
This test breaks due to an incorrect import in the test.

Added: 
    

Modified: 
    lldb/bindings/python/python-typemaps.swig
    lldb/bindings/python/python-wrapper.swig
    lldb/include/lldb/API/SBCommandInterpreter.h

Removed: 
    lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py


################################################################################
diff  --git a/lldb/bindings/python/python-typemaps.swig b/lldb/bindings/python/python-typemaps.swig
index c39594c7df041..8d4b740e5f35c 100644
--- a/lldb/bindings/python/python-typemaps.swig
+++ b/lldb/bindings/python/python-typemaps.swig
@@ -427,6 +427,7 @@ template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
   free($1);
 }
 
+
 // For Log::LogOutputCallback
 %typemap(in) (lldb::LogOutputCallback log_callback, void *baton) {
   if (!($input == Py_None ||
@@ -475,23 +476,6 @@ template <> bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
   $1 = $1 || PyCallable_Check(reinterpret_cast<PyObject *>($input));
 }
 
-%typemap(in) (lldb::CommandOverrideCallback callback, void *baton) {
-  if (!($input == Py_None ||
-        PyCallable_Check(reinterpret_cast<PyObject *>($input)))) {
-    PyErr_SetString(PyExc_TypeError, "Need a callable object or None!");
-    SWIG_fail;
-  }
-
-  // Don't lose the callback reference.
-  Py_INCREF($input);
-  $1 = LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback;
-  $2 = $input;
-}
-%typemap(typecheck) (lldb::CommandOverrideCallback callback, void *baton) {
-  $1 = $input == Py_None;
-  $1 = $1 || PyCallable_Check(reinterpret_cast<PyObject *>($input));
-}
-
 %typemap(in) lldb::FileSP {
   PythonFile py_file(PyRefType::Borrowed, $input);
   if (!py_file) {

diff  --git a/lldb/bindings/python/python-wrapper.swig b/lldb/bindings/python/python-wrapper.swig
index bd3de8ce5d46c..1370afc885d43 100644
--- a/lldb/bindings/python/python-wrapper.swig
+++ b/lldb/bindings/python/python-wrapper.swig
@@ -1099,28 +1099,6 @@ static void LLDBSwigPythonCallPythonSBDebuggerTerminateCallback(lldb::user_id_t
   }
 }
 
-static bool LLDBSwigPythonCallPythonSBCommandInterpreterSetCommandOverrideCallback(void *baton, const char **argv) {
-  bool ret_val = false;
-  if (baton != Py_None) {
-    SWIG_PYTHON_THREAD_BEGIN_BLOCK;
-    // Create a PyList of items since we're going to pass it to the callback as a tuple
-    // of arguments.
-    PyObject *py_argv = PyList_New(0);
-    for (const char **arg = argv; arg && *arg; arg++) {
-      std::string arg_string = *arg;
-      PyObject *py_string = PyUnicode_FromStringAndSize(arg_string.c_str(), arg_string.size());
-      PyList_Append(py_argv, py_string);
-    }
-
-    PyObject *result = PyObject_CallObject(
-        reinterpret_cast<PyObject *>(baton), PyList_AsTuple(py_argv));
-    ret_val = result ? PyObject_IsTrue(result) : false;
-    Py_XDECREF(result);
-    SWIG_PYTHON_THREAD_END_BLOCK;
-  }
-  return ret_val;
-}
-
 static SBError LLDBSwigPythonCallLocateModuleCallback(
     void *callback_baton, const SBModuleSpec &module_spec_sb,
     SBFileSpec &module_file_spec_sb, SBFileSpec &symbol_file_spec_sb) {

diff  --git a/lldb/include/lldb/API/SBCommandInterpreter.h b/lldb/include/lldb/API/SBCommandInterpreter.h
index b7e39b7858616..639309aa32bfc 100644
--- a/lldb/include/lldb/API/SBCommandInterpreter.h
+++ b/lldb/include/lldb/API/SBCommandInterpreter.h
@@ -265,9 +265,11 @@ class SBCommandInterpreter {
   // Catch commands before they execute by registering a callback that will get
   // called when the command gets executed. This allows GUI or command line
   // interfaces to intercept a command and stop it from happening
+#ifndef SWIG
   bool SetCommandOverrideCallback(const char *command_name,
                                   lldb::CommandOverrideCallback callback,
                                   void *baton);
+#endif
 
   /// Return true if the command interpreter is the active IO handler.
   ///

diff  --git a/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py b/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py
deleted file mode 100644
index a593feb0012d9..0000000000000
--- a/lldb/test/API/python_api/interpreter/TestCommandOverrideCallback.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from typing_extensions import override
-import lldb
-from lldbsuite.test.decorators import *
-from lldbsuite.test.lldbtest import *
-from lldbsuite.test import lldbutil
-
-
-class CommandOverrideCallback(TestBase):
-    def setUp(self):
-        TestBase.setUp(self)
-        self.line = line_number("main.c", "Hello world.")
-
-    def test_command_override_callback(self):
-        self.build()
-        exe = self.getBuildArtifact("a.out")
-
-        target = self.dbg.CreateTarget(exe)
-        self.assertTrue(target, VALID_TARGET)
-
-        ci = self.dbg.GetCommandInterpreter()
-        self.assertTrue(ci, VALID_COMMAND_INTERPRETER)
-
-        command_arg = ""
-
-        def foo(*command_args):
-            nonlocal command_arg
-            command_arg = command_args[0]
-
-        self.assertTrue(ci.SetCommandOverrideCallback("breakpoint set", foo))
-        self.expect("breakpoint set -n main")
-        self.assertTrue(command_arg == "breakpoint")


        


More information about the lldb-commits mailing list