[Lldb-commits] [lldb] [lldb] Add ScriptedSymbolLocator plugin for source file resolution (PR #181334)
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Fri Feb 13 19:32:51 PST 2026
================
@@ -311,4 +314,62 @@ ScriptedPythonInterface::ExtractValueFromPythonObject<lldb::ValueObjectListSP>(
return out;
}
+template <>
+FileSpec ScriptedPythonInterface::ExtractValueFromPythonObject<FileSpec>(
+ python::PythonObject &p, Status &error) {
+ if (lldb::SBFileSpec *sb_file_spec = reinterpret_cast<lldb::SBFileSpec *>(
+ python::LLDBSWIGPython_CastPyObjectToSBFileSpec(p.get())))
+ return m_interpreter.GetOpaqueTypeFromSBFileSpec(*sb_file_spec);
+ error = Status::FromErrorString(
+ "Couldn't cast lldb::SBFileSpec to lldb_private::FileSpec.");
+
+ return {};
+}
+
+template <>
+ModuleSpec ScriptedPythonInterface::ExtractValueFromPythonObject<ModuleSpec>(
+ python::PythonObject &p, Status &error) {
+ if (lldb::SBModuleSpec *sb_module_spec =
+ reinterpret_cast<lldb::SBModuleSpec *>(
+ python::LLDBSWIGPython_CastPyObjectToSBModuleSpec(p.get())))
+ return m_interpreter.GetOpaqueTypeFromSBModuleSpec(*sb_module_spec);
+ error = Status::FromErrorString(
+ "Couldn't cast lldb::SBModuleSpec to lldb_private::ModuleSpec.");
+
+ return {};
+}
+
+template <>
+FileSpecList
+ScriptedPythonInterface::ExtractValueFromPythonObject<FileSpecList>(
+ python::PythonObject &p, Status &error) {
+ FileSpecList result;
+ python::PythonList py_list(python::PyRefType::Borrowed, p.get());
+ if (!py_list.IsValid()) {
+ error = Status::FromErrorString(
+ "Couldn't cast Python object to a list for FileSpecList.");
+ return result;
+ }
+ for (uint32_t i = 0; i < py_list.GetSize(); i++) {
+ python::PythonObject item = py_list.GetItemAtIndex(i);
+ if (lldb::SBFileSpec *sb_file_spec = reinterpret_cast<lldb::SBFileSpec *>(
+ python::LLDBSWIGPython_CastPyObjectToSBFileSpec(item.get())))
+ result.Append(m_interpreter.GetOpaqueTypeFromSBFileSpec(*sb_file_spec));
+ }
+ return result;
+}
----------------
medismailben wrote:
This will produce a python `List[lldb.SBFileSpec]` instead of `lldb.SBFileSpecList`.
This means that the user won't be able to call SBFileSpecList methods like `AppendIfUnique` & `FindFileIndex`.
Note that SBFileSpecList has custom accessors to behave like a python list.
https://github.com/llvm/llvm-project/pull/181334
More information about the lldb-commits
mailing list