From d6a73d08d5f4fe182d313b0ccff5249769bb9437 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Thu, 18 Dec 2025 23:20:38 +0100 Subject: [lldb] Add priority support to synthetic frame providers (#172848) This patch adds `get_priority()` support to synthetic frame providers to enable priority-based selection when multiple providers match a thread. This is the first step toward supporting frame provider chaining for visualizing coroutines, Swift async tasks, and et al. Priority ordering follows Unix nice convention where lower numbers indicate higher priority (0 = highest). Providers without explicit priority return `std::nullopt`, which maps to UINT32_MAX (lowest priority), ensuring backward compatibility with existing providers. The implementation adds `GetPriority()` as a virtual method to `SyntheticFrameProvider` base class, implements it through the scripting interface hierarchy (`ScriptedFrameProviderInterface` and `ScriptedFrameProviderPythonInterface`), and updates `Thread::GetStackFrameList()` to sort applicable providers by priority before attempting to load them. Python frame providers can now specify priority: ```python @staticmethod def get_priority(): return 10 # Or return None for default priority. ``` Signed-off-by: Med Ismail Bennani --- .../ScriptedFrameProviderPythonInterface.cpp | 18 ++++++++++++++++++ .../Interfaces/ScriptedFrameProviderPythonInterface.h | 2 ++ 2 files changed, 20 insertions(+) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/Interfaces') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp index 3dde5036453f..2d87c1b10bfe 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.cpp @@ -70,6 +70,24 @@ std::string ScriptedFrameProviderPythonInterface::GetDescription( return obj->GetStringValue().str(); } +std::optional +ScriptedFrameProviderPythonInterface::GetPriority(llvm::StringRef class_name) { + Status error; + StructuredData::ObjectSP obj = + CallStaticMethod(class_name, "get_priority", error); + + if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj, + error)) + return std::nullopt; + + // Try to extract as unsigned integer. Return nullopt if Python returned None + // or if extraction fails. + if (StructuredData::UnsignedInteger *int_obj = obj->GetAsUnsignedInteger()) + return static_cast(int_obj->GetValue()); + + return std::nullopt; +} + StructuredData::ObjectSP ScriptedFrameProviderPythonInterface::GetFrameAtIndex(uint32_t index) { Status error; diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.h b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.h index 97a5cc7c669e..884b0355a659 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedFrameProviderPythonInterface.h @@ -43,6 +43,8 @@ public: std::string GetDescription(llvm::StringRef class_name) override; + std::optional GetPriority(llvm::StringRef class_name) override; + StructuredData::ObjectSP GetFrameAtIndex(uint32_t index) override; static void Initialize(); -- cgit v1.2.3