[lldb/script] Migrate frame recognizers onto ScriptedPythonInterface (#209805)
Give `frame recognizer add -l` a formal ScriptedStackFrameRecognizerInterface, matching the architecture already used by ScriptedProcess, ScriptedBreakpoint, etc.: a C++ interface header, a Python-backed implementation built on ScriptedPythonInterface's CreatePluginObject/Dispatch machinery, PluginManager registration, and a generatable Python ABC template (scripted_stackframe_recognizer.py). get_recognized_arguments' documented contract returns a plain list of lldb.SBValue (not an lldb.SBValueList), so it bypasses the generic Dispatch<ValueObjectListSP>() extractor and calls the SWIG bridge directly, matching the legacy behavior exactly. ScriptedStackFrameRecognizer now holds a single interface object created once in its constructor and reused across every RecognizeFrame() call, same lifecycle as before. Signed-off-by: Med Ismail Bennani <ismail@bennani.ma> (cherry picked from commit a07b91d8243b8a8051dbbe5739eacc7942269c61)
This commit is contained in:
1 parent
694db4d296
commit
e28ea20ce0
23 files changed
+485
-212
No files matched your search
@@ -1624,92 +1624,6 @@ bool ScriptInterpreterPythonImpl::GenerateTypeSynthClass(
|
||||
return true;
|
||||
}
|
||||
|
||||
StructuredData::GenericSP
|
||||
ScriptInterpreterPythonImpl::CreateFrameRecognizer(const char *class_name) {
|
||||
if (class_name == nullptr || class_name[0] == '\0')
|
||||
return StructuredData::GenericSP();
|
||||
|
||||
Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
|
||||
PythonObject ret_val = SWIGBridge::LLDBSWIGPython_CreateFrameRecognizer(
|
||||
class_name, m_dictionary_name.c_str());
|
||||
|
||||
return StructuredData::GenericSP(
|
||||
new StructuredPythonObject(std::move(ret_val)));
|
||||
}
|
||||
|
||||
lldb::ValueObjectListSP ScriptInterpreterPythonImpl::GetRecognizedArguments(
|
||||
const StructuredData::ObjectSP &os_plugin_object_sp,
|
||||
lldb::StackFrameSP frame_sp) {
|
||||
Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
|
||||
|
||||
if (!os_plugin_object_sp)
|
||||
return ValueObjectListSP();
|
||||
|
||||
StructuredData::Generic *generic = os_plugin_object_sp->GetAsGeneric();
|
||||
if (!generic)
|
||||
return nullptr;
|
||||
|
||||
PythonObject implementor(PyRefType::Borrowed,
|
||||
(PyObject *)generic->GetValue());
|
||||
|
||||
if (!implementor.IsAllocated())
|
||||
return ValueObjectListSP();
|
||||
|
||||
PythonObject py_return(PyRefType::Owned,
|
||||
SWIGBridge::LLDBSwigPython_GetRecognizedArguments(
|
||||
implementor.get(), frame_sp));
|
||||
|
||||
// if it fails, print the error but otherwise go on
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (py_return.get()) {
|
||||
PythonList result_list(PyRefType::Borrowed, py_return.get());
|
||||
ValueObjectListSP result = std::make_shared<ValueObjectList>();
|
||||
for (size_t i = 0; i < result_list.GetSize(); i++) {
|
||||
PyObject *item = result_list.GetItemAtIndex(i).get();
|
||||
lldb::SBValue *sb_value_ptr =
|
||||
(lldb::SBValue *)LLDBSWIGPython_CastPyObjectToSBValue(item);
|
||||
auto valobj_sp =
|
||||
SWIGBridge::LLDBSWIGPython_GetValueObjectSPFromSBValue(sb_value_ptr);
|
||||
if (valobj_sp)
|
||||
result->Append(valobj_sp);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return ValueObjectListSP();
|
||||
}
|
||||
|
||||
bool ScriptInterpreterPythonImpl::ShouldHide(
|
||||
const StructuredData::ObjectSP &os_plugin_object_sp,
|
||||
lldb::StackFrameSP frame_sp) {
|
||||
Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
|
||||
|
||||
if (!os_plugin_object_sp)
|
||||
return false;
|
||||
|
||||
StructuredData::Generic *generic = os_plugin_object_sp->GetAsGeneric();
|
||||
if (!generic)
|
||||
return false;
|
||||
|
||||
PythonObject implementor(PyRefType::Borrowed,
|
||||
(PyObject *)generic->GetValue());
|
||||
|
||||
if (!implementor.IsAllocated())
|
||||
return false;
|
||||
|
||||
bool result =
|
||||
SWIGBridge::LLDBSwigPython_ShouldHide(implementor.get(), frame_sp);
|
||||
|
||||
// if it fails, print the error but otherwise go on
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ScriptedProcessInterfaceUP
|
||||
ScriptInterpreterPythonImpl::CreateScriptedProcessInterface() {
|
||||
return std::make_unique<ScriptedProcessPythonInterface>(*this);
|
||||
@@ -1725,6 +1639,11 @@ ScriptInterpreterPythonImpl::CreateScriptedBreakpointInterface() {
|
||||
return std::make_shared<ScriptedBreakpointPythonInterface>(*this);
|
||||
}
|
||||
|
||||
ScriptedStackFrameRecognizerInterfaceSP
|
||||
ScriptInterpreterPythonImpl::CreateScriptedStackFrameRecognizerInterface() {
|
||||
return std::make_shared<ScriptedStackFrameRecognizerPythonInterface>(*this);
|
||||
}
|
||||
|
||||
ScriptedThreadInterfaceSP
|
||||
ScriptInterpreterPythonImpl::CreateScriptedThreadInterface() {
|
||||
return std::make_shared<ScriptedThreadPythonInterface>(*this);
|
||||
|
||||
Reference in new issue
Block a user