Skip to content

Commit 9e777a6

Browse files
committed
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 (cherry picked from commit 4eb694e)
1 parent 9a3cc16 commit 9e777a6

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

lldb/include/lldb/API/SBCommandInterpreter.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,34 @@ class SBCommandInterpreter {
4545

4646
bool IsValid() const;
4747

48+
/// Return whether a built-in command with the passed in
49+
/// name or command path exists.
50+
///
51+
/// \param[in] cmd
52+
/// The command or command path to search for.
53+
///
54+
/// \return
55+
/// \b true if the command exists, \b false otherwise.
4856
bool CommandExists(const char *cmd);
4957

58+
/// Return whether a user defined command with the passed in
59+
/// name or command path exists.
60+
///
61+
/// \param[in] cmd
62+
/// The command or command path to search for.
63+
///
64+
/// \return
65+
/// \b true if the command exists, \b false otherwise.
66+
bool UserCommandExists(const char *cmd);
67+
68+
/// Return whether the passed in name or command path
69+
/// exists and is an alias to some other command.
70+
///
71+
/// \param[in] cmd
72+
/// The command or command path to search for.
73+
///
74+
/// \return
75+
/// \b true if the command exists, \b false otherwise.
5076
bool AliasExists(const char *cmd);
5177

5278
lldb::SBBroadcaster GetBroadcaster();

lldb/source/API/SBCommandInterpreter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ bool SBCommandInterpreter::CommandExists(const char *cmd) {
117117
: false);
118118
}
119119

120+
bool SBCommandInterpreter::UserCommandExists(const char *cmd) {
121+
LLDB_INSTRUMENT_VA(this, cmd);
122+
123+
return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->UserCommandExists(cmd)
124+
: false);
125+
}
126+
120127
bool SBCommandInterpreter::AliasExists(const char *cmd) {
121128
LLDB_INSTRUMENT_VA(this, cmd);
122129

lldb/test/API/commands/command/script/TestCommandScript.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def test(self):
1919
def pycmd_tests(self):
2020
self.runCmd("command source py_import")
2121

22+
# Test that we did indeed add these commands as user commands:
23+
interp = self.dbg.GetCommandInterpreter()
24+
self.expectTrue(interp.UserCommandExists("foobar"), "foobar exists")
25+
self.expectFalse(interp.CommandExists("foobar"), "It is not a builtin.")
26+
2227
# Test a bunch of different kinds of python callables with
2328
# both 4 and 5 positional arguments.
2429
self.expect("foobar", substrs=["All good"])

0 commit comments

Comments
 (0)