diff options
| author | Med Ismail Bennani <ismail@bennani.ma> | 2025-12-18 23:20:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-18 23:20:38 +0100 |
| commit | d6a73d08d5f4fe182d313b0ccff5249769bb9437 (patch) | |
| tree | 3dd9a0f283224d97c625ad1137cb23dc1aa9d1bf /lldb/source/Plugins/ScriptInterpreter/Python/Interfaces | |
| parent | a9b62e8324ad36d04b22d8be2436ad7c83fc712f (diff) | |
| download | llvm-d6a73d08d5f4fe182d313b0ccff5249769bb9437.tar.gz llvm-d6a73d08d5f4fe182d313b0ccff5249769bb9437.tar.bz2 llvm-d6a73d08d5f4fe182d313b0ccff5249769bb9437.zip | |
[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 <ismail@bennani.ma>
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/Interfaces')
2 files changed, 20 insertions, 0 deletions
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<uint32_t> +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<uint32_t>(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<uint32_t> GetPriority(llvm::StringRef class_name) override; + StructuredData::ObjectSP GetFrameAtIndex(uint32_t index) override; static void Initialize(); |
