diff options
author | Enrico Granata <egranata@apple.com> | 2015-05-27 05:04:35 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2015-05-27 05:04:35 +0000 |
commit | e87764f2470f6794e432506ebc8beb6ef78dd5fb (patch) | |
tree | 4bd62c58b76aeaf4d7c6155418838b9933caa56c /lldb/source/Interpreter/ScriptInterpreterPython.cpp | |
parent | 3273930d9acee986bc3d1bc24556354e26a797fd (diff) | |
download | bcm5719-llvm-e87764f2470f6794e432506ebc8beb6ef78dd5fb.tar.gz bcm5719-llvm-e87764f2470f6794e432506ebc8beb6ef78dd5fb.zip |
Add support for custom commands to set flags on themselves
This works for Python commands defined via a class (implement get_flags on your class) and C++ plugin commands (which can call SBCommand::GetFlags()/SetFlags())
Flags allow features such as not letting the command run if there's no target, or if the process is not stopped, ...
Commands could always check for these things themselves, but having these accessible via flags makes custom commands more consistent with built-in ones
llvm-svn: 238286
Diffstat (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp')
-rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index 1baf484cc79..1e16fd3bdc6 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -2878,6 +2878,78 @@ ScriptInterpreterPython::GetShortHelpForCommandObject (StructuredData::GenericSP return got_string; } +uint32_t +ScriptInterpreterPython::GetFlagsForCommandObject (StructuredData::GenericSP cmd_obj_sp) +{ + uint32_t result = 0; + + Locker py_lock (this, + Locker::AcquireLock | Locker::NoSTDIN, + Locker::FreeLock); + + static char callee_name[] = "get_flags"; + + if (!cmd_obj_sp) + return result; + + PyObject* implementor = (PyObject*)cmd_obj_sp->GetValue(); + + if (implementor == nullptr || implementor == Py_None) + return result; + + PyObject* pmeth = PyObject_GetAttrString(implementor, callee_name); + + if (PyErr_Occurred()) + { + PyErr_Clear(); + } + + if (pmeth == nullptr || pmeth == Py_None) + { + Py_XDECREF(pmeth); + return result; + } + + if (PyCallable_Check(pmeth) == 0) + { + if (PyErr_Occurred()) + { + PyErr_Clear(); + } + + Py_XDECREF(pmeth); + return result; + } + + if (PyErr_Occurred()) + { + PyErr_Clear(); + } + + Py_XDECREF(pmeth); + + // right now we know this function exists and is callable.. + PyObject* py_return = PyObject_CallMethod(implementor, callee_name, nullptr); + + // if it fails, print the error but otherwise go on + if (PyErr_Occurred()) + { + PyErr_Print(); + PyErr_Clear(); + } + + if (py_return != nullptr && py_return != Py_None) + { + if (PyInt_Check(py_return)) + result = (uint32_t)PyInt_AsLong(py_return); + else if (PyLong_Check(py_return)) + result = (uint32_t)PyLong_AsLong(py_return); + } + Py_XDECREF(py_return); + + return result; +} + bool ScriptInterpreterPython::GetLongHelpForCommandObject (StructuredData::GenericSP cmd_obj_sp, std::string& dest) |