diff --git a/lldb/include/lldb/API/SBCommandInterpreter.h b/lldb/include/lldb/API/SBCommandInterpreter.h --- a/lldb/include/lldb/API/SBCommandInterpreter.h +++ b/lldb/include/lldb/API/SBCommandInterpreter.h @@ -45,8 +45,34 @@ 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 --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -118,6 +118,13 @@ : 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 --- a/lldb/test/API/commands/command/script/TestCommandScript.py +++ b/lldb/test/API/commands/command/script/TestCommandScript.py @@ -19,6 +19,11 @@ 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 different kinds of python callables with # both 4 and 5 positional arguments. self.expect("foobar", substrs=["All good"])