[Lldb-commits] [lldb] 4eb694e - Add SBCommandInterpreter::UserCommandExists parallel to CommandExists.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 28 16:00:28 PST 2023


Author: Jim Ingham
Date: 2023-02-28T15:58:14-08:00
New Revision: 4eb694e35dd514395819b375b31a80bd6d58378e

URL: https://github.com/llvm/llvm-project/commit/4eb694e35dd514395819b375b31a80bd6d58378e
DIFF: https://github.com/llvm/llvm-project/commit/4eb694e35dd514395819b375b31a80bd6d58378e.diff

LOG: Add SBCommandInterpreter::UserCommandExists parallel to CommandExists.

The latter only checks built-in commands.  I also added some docs to
make the distinction clear and a test.

Differential Revision: https://reviews.llvm.org/D144929

Added: 
    

Modified: 
    lldb/include/lldb/API/SBCommandInterpreter.h
    lldb/source/API/SBCommandInterpreter.cpp
    lldb/test/API/commands/command/script/TestCommandScript.py

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/API/SBCommandInterpreter.h b/lldb/include/lldb/API/SBCommandInterpreter.h
index 0830145bc2544..08ed989714d13 100644
--- a/lldb/include/lldb/API/SBCommandInterpreter.h
+++ b/lldb/include/lldb/API/SBCommandInterpreter.h
@@ -45,8 +45,34 @@ class SBCommandInterpreter {
 
   bool IsValid() const;
 
+  /// Return whether a built-in command with the passed in
+  /// name or command path exists.
+  ///
+  /// \param[in] cmd
+  ///   The command or command path to search for.
+  ///
+  /// \return
+  ///   \b true if the command exists, \b false otherwise.
   bool CommandExists(const char *cmd);
 
+  /// Return whether a user defined command with the passed in
+  /// name or command path exists.
+  ///
+  /// \param[in] cmd
+  ///   The command or command path to search for.
+  ///
+  /// \return
+  ///   \b true if the command exists, \b false otherwise.
+  bool UserCommandExists(const char *cmd);
+
+  /// Return whether the passed in name or command path
+  /// exists and is an alias to some other command.
+  ///
+  /// \param[in] cmd
+  ///   The command or command path to search for.
+  ///
+  /// \return
+  ///   \b true if the command exists, \b false otherwise.
   bool AliasExists(const char *cmd);
 
   lldb::SBBroadcaster GetBroadcaster();

diff  --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp
index cd6ef3b23fd41..35c55283855df 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -118,6 +118,13 @@ bool SBCommandInterpreter::CommandExists(const char *cmd) {
                                           : false);
 }
 
+bool SBCommandInterpreter::UserCommandExists(const char *cmd) {
+  LLDB_INSTRUMENT_VA(this, cmd);
+
+  return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->UserCommandExists(cmd)
+                                          : false);
+}
+
 bool SBCommandInterpreter::AliasExists(const char *cmd) {
   LLDB_INSTRUMENT_VA(this, cmd);
 

diff  --git a/lldb/test/API/commands/command/script/TestCommandScript.py b/lldb/test/API/commands/command/script/TestCommandScript.py
index 7e8206ca96a48..b81acef261067 100644
--- a/lldb/test/API/commands/command/script/TestCommandScript.py
+++ b/lldb/test/API/commands/command/script/TestCommandScript.py
@@ -19,6 +19,11 @@ def test(self):
     def pycmd_tests(self):
         self.runCmd("command source py_import")
 
+        # Test that we did indeed add these commands as user commands:
+        interp = self.dbg.GetCommandInterpreter()
+        self.expectTrue(interp.UserCommandExists("foobar"), "foobar exists")
+        self.expectFalse(interp.CommandExists("foobar"), "It is not a builtin.")
+
         # Test a bunch of 
diff erent kinds of python callables with
         # both 4 and 5 positional arguments.
         self.expect("foobar", substrs=["All good"])


        


More information about the lldb-commits mailing list