Skip to content

Commit a293232

Browse files
authored
Merge pull request #6428 from jimingham/UserCommandExists
Add an SB API to tell if a User command exists
2 parents 2f10ca6 + bb9a1ed commit a293232

File tree

6 files changed

+86
-0
lines changed

6 files changed

+86
-0
lines changed

lldb/bindings/interface/SBCommandInterpreter.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ public:
107107
bool
108108
CommandExists (const char *cmd);
109109

110+
bool
111+
UserCommandExists(const char *cmd);
112+
110113
bool
111114
AliasExists (const char *cmd);
112115

lldb/bindings/python/static-binding/LLDBWrapPython.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14886,6 +14886,43 @@ SWIGINTERN PyObject *_wrap_SBCommandInterpreter_CommandExists(PyObject *self, Py
1488614886
}
1488714887

1488814888

14889+
SWIGINTERN PyObject *_wrap_SBCommandInterpreter_UserCommandExists(PyObject *self, PyObject *args) {
14890+
PyObject *resultobj = 0;
14891+
lldb::SBCommandInterpreter *arg1 = (lldb::SBCommandInterpreter *) 0 ;
14892+
char *arg2 = (char *) 0 ;
14893+
void *argp1 = 0 ;
14894+
int res1 = 0 ;
14895+
int res2 ;
14896+
char *buf2 = 0 ;
14897+
int alloc2 = 0 ;
14898+
PyObject *swig_obj[2] ;
14899+
bool result;
14900+
14901+
if (!SWIG_Python_UnpackTuple(args, "SBCommandInterpreter_UserCommandExists", 2, 2, swig_obj)) SWIG_fail;
14902+
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_lldb__SBCommandInterpreter, 0 | 0 );
14903+
if (!SWIG_IsOK(res1)) {
14904+
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "SBCommandInterpreter_UserCommandExists" "', argument " "1"" of type '" "lldb::SBCommandInterpreter *""'");
14905+
}
14906+
arg1 = reinterpret_cast< lldb::SBCommandInterpreter * >(argp1);
14907+
res2 = SWIG_AsCharPtrAndSize(swig_obj[1], &buf2, NULL, &alloc2);
14908+
if (!SWIG_IsOK(res2)) {
14909+
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "SBCommandInterpreter_UserCommandExists" "', argument " "2"" of type '" "char const *""'");
14910+
}
14911+
arg2 = reinterpret_cast< char * >(buf2);
14912+
{
14913+
SWIG_PYTHON_THREAD_BEGIN_ALLOW;
14914+
result = (bool)(arg1)->UserCommandExists((char const *)arg2);
14915+
SWIG_PYTHON_THREAD_END_ALLOW;
14916+
}
14917+
resultobj = SWIG_From_bool(static_cast< bool >(result));
14918+
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
14919+
return resultobj;
14920+
fail:
14921+
if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
14922+
return NULL;
14923+
}
14924+
14925+
1488914926
SWIGINTERN PyObject *_wrap_SBCommandInterpreter_AliasExists(PyObject *self, PyObject *args) {
1489014927
PyObject *resultobj = 0;
1489114928
lldb::SBCommandInterpreter *arg1 = (lldb::SBCommandInterpreter *) 0 ;
@@ -84338,6 +84375,7 @@ static PyMethodDef SwigMethods[] = {
8433884375
{ "SBCommandInterpreter_GetQuitStatus", _wrap_SBCommandInterpreter_GetQuitStatus, METH_O, "SBCommandInterpreter_GetQuitStatus(SBCommandInterpreter self) -> int"},
8433984376
{ "SBCommandInterpreter_ResolveCommand", _wrap_SBCommandInterpreter_ResolveCommand, METH_VARARGS, "SBCommandInterpreter_ResolveCommand(SBCommandInterpreter self, char const * command_line, SBCommandReturnObject result)"},
8434084377
{ "SBCommandInterpreter_CommandExists", _wrap_SBCommandInterpreter_CommandExists, METH_VARARGS, "SBCommandInterpreter_CommandExists(SBCommandInterpreter self, char const * cmd) -> bool"},
84378+
{ "SBCommandInterpreter_UserCommandExists", _wrap_SBCommandInterpreter_UserCommandExists, METH_VARARGS, "SBCommandInterpreter_UserCommandExists(SBCommandInterpreter self, char const * cmd) -> bool"},
8434184379
{ "SBCommandInterpreter_AliasExists", _wrap_SBCommandInterpreter_AliasExists, METH_VARARGS, "SBCommandInterpreter_AliasExists(SBCommandInterpreter self, char const * cmd) -> bool"},
8434284380
{ "SBCommandInterpreter_GetBroadcaster", _wrap_SBCommandInterpreter_GetBroadcaster, METH_O, "SBCommandInterpreter_GetBroadcaster(SBCommandInterpreter self) -> SBBroadcaster"},
8434384381
{ "SBCommandInterpreter_GetBroadcasterClass", _wrap_SBCommandInterpreter_GetBroadcasterClass, METH_NOARGS, "SBCommandInterpreter_GetBroadcasterClass() -> char const *"},
@@ -90640,6 +90678,7 @@ SWIG_init(void) {
9064090678
SWIG_Python_SetConstant(d, "eTypeIsMetatype",SWIG_From_int(static_cast< int >(lldb::eTypeIsMetatype)));
9064190679
SWIG_Python_SetConstant(d, "eTypeHasUnboundGeneric",SWIG_From_int(static_cast< int >(lldb::eTypeHasUnboundGeneric)));
9064290680
SWIG_Python_SetConstant(d, "eTypeHasDynamicSelf",SWIG_From_int(static_cast< int >(lldb::eTypeHasDynamicSelf)));
90681+
SWIG_Python_SetConstant(d, "eTypeIsPack",SWIG_From_int(static_cast< int >(lldb::eTypeIsPack)));
9064390682
SWIG_Python_SetConstant(d, "eCommandRequiresTarget",SWIG_From_int(static_cast< int >(lldb::eCommandRequiresTarget)));
9064490683
SWIG_Python_SetConstant(d, "eCommandRequiresProcess",SWIG_From_int(static_cast< int >(lldb::eCommandRequiresProcess)));
9064590684
SWIG_Python_SetConstant(d, "eCommandRequiresThread",SWIG_From_int(static_cast< int >(lldb::eCommandRequiresThread)));

lldb/bindings/python/static-binding/lldb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,8 @@ def lldb_iter(obj, getsize, getelem):
15611561

15621562
eTypeHasDynamicSelf = _lldb.eTypeHasDynamicSelf
15631563

1564+
eTypeIsPack = _lldb.eTypeIsPack
1565+
15641566
eCommandRequiresTarget = _lldb.eCommandRequiresTarget
15651567

15661568
eCommandRequiresProcess = _lldb.eCommandRequiresProcess
@@ -3163,6 +3165,10 @@ def CommandExists(self, cmd):
31633165
r"""CommandExists(SBCommandInterpreter self, char const * cmd) -> bool"""
31643166
return _lldb.SBCommandInterpreter_CommandExists(self, cmd)
31653167

3168+
def UserCommandExists(self, cmd):
3169+
r"""UserCommandExists(SBCommandInterpreter self, char const * cmd) -> bool"""
3170+
return _lldb.SBCommandInterpreter_UserCommandExists(self, cmd)
3171+
31663172
def AliasExists(self, cmd):
31673173
r"""AliasExists(SBCommandInterpreter self, char const * cmd) -> bool"""
31683174
return _lldb.SBCommandInterpreter_AliasExists(self, cmd)

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.assertTrue(interp.UserCommandExists("foobar"), "foobar exists")
25+
self.assertFalse(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)